@@ -16,108 +16,108 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | class Wordlift_Publisher_Service { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * Counts the number of potential publishers. |
|
| 21 | - * |
|
| 22 | - * @since 3.11.0 |
|
| 23 | - * |
|
| 24 | - * @return int The number of potential publishers. |
|
| 25 | - */ |
|
| 26 | - public function count() { |
|
| 19 | + /** |
|
| 20 | + * Counts the number of potential publishers. |
|
| 21 | + * |
|
| 22 | + * @since 3.11.0 |
|
| 23 | + * |
|
| 24 | + * @return int The number of potential publishers. |
|
| 25 | + */ |
|
| 26 | + public function count() { |
|
| 27 | 27 | |
| 28 | - // Get the global `wpdb` instance. |
|
| 29 | - global $wpdb; |
|
| 28 | + // Get the global `wpdb` instance. |
|
| 29 | + global $wpdb; |
|
| 30 | 30 | |
| 31 | - // Run the query and get the count. |
|
| 32 | - $count = $wpdb->get_var( $wpdb->prepare( |
|
| 33 | - 'SELECT COUNT( p.id )' . |
|
| 34 | - " FROM $wpdb->posts p" . |
|
| 35 | - " LEFT JOIN $wpdb->term_relationships tr" . |
|
| 36 | - ' ON tr.object_id = p.id' . |
|
| 37 | - " LEFT JOIN $wpdb->term_taxonomy tt" . |
|
| 38 | - ' ON tt.term_taxonomy_id = tr.term_taxonomy_id' . |
|
| 39 | - " LEFT JOIN $wpdb->terms t" . |
|
| 40 | - ' ON t.term_id = tt.term_id' . |
|
| 41 | - " LEFT JOIN $wpdb->postmeta m" . |
|
| 42 | - " ON m.post_id = p.id AND m.meta_key = '_thumbnail_id'" . |
|
| 43 | - ' WHERE p.post_type = %s' . |
|
| 44 | - " AND t.name IN ( 'Organization', 'Person' )" . |
|
| 45 | - ' AND tt.taxonomy = %s' . |
|
| 46 | - ' ORDER BY p.post_title', |
|
| 47 | - Wordlift_Entity_Service::TYPE_NAME, |
|
| 48 | - Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME |
|
| 49 | - ) ); |
|
| 31 | + // Run the query and get the count. |
|
| 32 | + $count = $wpdb->get_var( $wpdb->prepare( |
|
| 33 | + 'SELECT COUNT( p.id )' . |
|
| 34 | + " FROM $wpdb->posts p" . |
|
| 35 | + " LEFT JOIN $wpdb->term_relationships tr" . |
|
| 36 | + ' ON tr.object_id = p.id' . |
|
| 37 | + " LEFT JOIN $wpdb->term_taxonomy tt" . |
|
| 38 | + ' ON tt.term_taxonomy_id = tr.term_taxonomy_id' . |
|
| 39 | + " LEFT JOIN $wpdb->terms t" . |
|
| 40 | + ' ON t.term_id = tt.term_id' . |
|
| 41 | + " LEFT JOIN $wpdb->postmeta m" . |
|
| 42 | + " ON m.post_id = p.id AND m.meta_key = '_thumbnail_id'" . |
|
| 43 | + ' WHERE p.post_type = %s' . |
|
| 44 | + " AND t.name IN ( 'Organization', 'Person' )" . |
|
| 45 | + ' AND tt.taxonomy = %s' . |
|
| 46 | + ' ORDER BY p.post_title', |
|
| 47 | + Wordlift_Entity_Service::TYPE_NAME, |
|
| 48 | + Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME |
|
| 49 | + ) ); |
|
| 50 | 50 | |
| 51 | - // Finally return the count. |
|
| 52 | - return (int) $count; |
|
| 53 | - } |
|
| 51 | + // Finally return the count. |
|
| 52 | + return (int) $count; |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * Query WP for potential publishers, i.e. {@link WP_Post}s of type `entity` |
|
| 57 | - * and of `wl_entity_type` (taxonomy) `Organization` or `Person`. |
|
| 58 | - * |
|
| 59 | - * @since 3.11.0 |
|
| 60 | - * |
|
| 61 | - * @param string $filter The title filter. |
|
| 62 | - * |
|
| 63 | - * @return array An array of results. |
|
| 64 | - */ |
|
| 65 | - public function query( $filter = '' ) { |
|
| 55 | + /** |
|
| 56 | + * Query WP for potential publishers, i.e. {@link WP_Post}s of type `entity` |
|
| 57 | + * and of `wl_entity_type` (taxonomy) `Organization` or `Person`. |
|
| 58 | + * |
|
| 59 | + * @since 3.11.0 |
|
| 60 | + * |
|
| 61 | + * @param string $filter The title filter. |
|
| 62 | + * |
|
| 63 | + * @return array An array of results. |
|
| 64 | + */ |
|
| 65 | + public function query( $filter = '' ) { |
|
| 66 | 66 | |
| 67 | - // Get the global `wpdb` instance. |
|
| 68 | - global $wpdb; |
|
| 67 | + // Get the global `wpdb` instance. |
|
| 68 | + global $wpdb; |
|
| 69 | 69 | |
| 70 | - // Run the query and get the results. |
|
| 71 | - $results = $wpdb->get_results( $wpdb->prepare( |
|
| 72 | - 'SELECT p.id, p.post_title, t.name AS type, m.meta_value AS thumbnail_id' . |
|
| 73 | - " FROM $wpdb->posts p" . |
|
| 74 | - " LEFT JOIN $wpdb->term_relationships tr" . |
|
| 75 | - ' ON tr.object_id = p.id' . |
|
| 76 | - " LEFT JOIN $wpdb->term_taxonomy tt" . |
|
| 77 | - ' ON tt.term_taxonomy_id = tr.term_taxonomy_id' . |
|
| 78 | - " LEFT JOIN $wpdb->terms t" . |
|
| 79 | - ' ON t.term_id = tt.term_id' . |
|
| 80 | - " LEFT JOIN $wpdb->postmeta m" . |
|
| 81 | - " ON m.post_id = p.id AND m.meta_key = '_thumbnail_id'" . |
|
| 82 | - ' WHERE p.post_type = %s' . |
|
| 83 | - " AND t.name IN ( 'Organization', 'Person' )" . |
|
| 84 | - ' AND tt.taxonomy = %s' . |
|
| 85 | - ' AND p.post_title LIKE %s' . |
|
| 86 | - ' ORDER BY p.post_title', |
|
| 87 | - Wordlift_Entity_Service::TYPE_NAME, |
|
| 88 | - Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, |
|
| 89 | - '%' . $wpdb->esc_like( $filter ) . '%' |
|
| 90 | - ) ); |
|
| 70 | + // Run the query and get the results. |
|
| 71 | + $results = $wpdb->get_results( $wpdb->prepare( |
|
| 72 | + 'SELECT p.id, p.post_title, t.name AS type, m.meta_value AS thumbnail_id' . |
|
| 73 | + " FROM $wpdb->posts p" . |
|
| 74 | + " LEFT JOIN $wpdb->term_relationships tr" . |
|
| 75 | + ' ON tr.object_id = p.id' . |
|
| 76 | + " LEFT JOIN $wpdb->term_taxonomy tt" . |
|
| 77 | + ' ON tt.term_taxonomy_id = tr.term_taxonomy_id' . |
|
| 78 | + " LEFT JOIN $wpdb->terms t" . |
|
| 79 | + ' ON t.term_id = tt.term_id' . |
|
| 80 | + " LEFT JOIN $wpdb->postmeta m" . |
|
| 81 | + " ON m.post_id = p.id AND m.meta_key = '_thumbnail_id'" . |
|
| 82 | + ' WHERE p.post_type = %s' . |
|
| 83 | + " AND t.name IN ( 'Organization', 'Person' )" . |
|
| 84 | + ' AND tt.taxonomy = %s' . |
|
| 85 | + ' AND p.post_title LIKE %s' . |
|
| 86 | + ' ORDER BY p.post_title', |
|
| 87 | + Wordlift_Entity_Service::TYPE_NAME, |
|
| 88 | + Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, |
|
| 89 | + '%' . $wpdb->esc_like( $filter ) . '%' |
|
| 90 | + ) ); |
|
| 91 | 91 | |
| 92 | - // Set a reference to ourselves to pass to the closure. |
|
| 93 | - $publisher_service = $this; |
|
| 92 | + // Set a reference to ourselves to pass to the closure. |
|
| 93 | + $publisher_service = $this; |
|
| 94 | 94 | |
| 95 | - // Map the results in a `Select2` compatible array. |
|
| 96 | - return array_map( function ( $item ) use ( $publisher_service ) { |
|
| 97 | - return array( |
|
| 98 | - 'id' => $item->id, |
|
| 99 | - 'text' => $item->post_title, |
|
| 100 | - 'type' => $item->type, |
|
| 101 | - 'thumbnail_url' => $publisher_service->get_attachment_image_url( $item->thumbnail_id ), |
|
| 102 | - ); |
|
| 103 | - }, $results ); |
|
| 104 | - } |
|
| 95 | + // Map the results in a `Select2` compatible array. |
|
| 96 | + return array_map( function ( $item ) use ( $publisher_service ) { |
|
| 97 | + return array( |
|
| 98 | + 'id' => $item->id, |
|
| 99 | + 'text' => $item->post_title, |
|
| 100 | + 'type' => $item->type, |
|
| 101 | + 'thumbnail_url' => $publisher_service->get_attachment_image_url( $item->thumbnail_id ), |
|
| 102 | + ); |
|
| 103 | + }, $results ); |
|
| 104 | + } |
|
| 105 | 105 | |
| 106 | - /** |
|
| 107 | - * Get the thumbnail's URL. |
|
| 108 | - * |
|
| 109 | - * @since 3.11.0 |
|
| 110 | - * |
|
| 111 | - * @param int $attachment_id The attachment id. |
|
| 112 | - * @param string $size The attachment size (default = 'thumbnail'). |
|
| 113 | - * |
|
| 114 | - * @return string|bool The image URL or false if not found. |
|
| 115 | - */ |
|
| 116 | - public function get_attachment_image_url( $attachment_id, $size = 'thumbnail' ) { |
|
| 106 | + /** |
|
| 107 | + * Get the thumbnail's URL. |
|
| 108 | + * |
|
| 109 | + * @since 3.11.0 |
|
| 110 | + * |
|
| 111 | + * @param int $attachment_id The attachment id. |
|
| 112 | + * @param string $size The attachment size (default = 'thumbnail'). |
|
| 113 | + * |
|
| 114 | + * @return string|bool The image URL or false if not found. |
|
| 115 | + */ |
|
| 116 | + public function get_attachment_image_url( $attachment_id, $size = 'thumbnail' ) { |
|
| 117 | 117 | |
| 118 | - $image = wp_get_attachment_image_src( $attachment_id, $size ); |
|
| 118 | + $image = wp_get_attachment_image_src( $attachment_id, $size ); |
|
| 119 | 119 | |
| 120 | - return isset( $image['0'] ) ? $image['0'] : false; |
|
| 121 | - } |
|
| 120 | + return isset( $image['0'] ) ? $image['0'] : false; |
|
| 121 | + } |
|
| 122 | 122 | |
| 123 | 123 | } |
@@ -29,24 +29,24 @@ discard block |
||
| 29 | 29 | global $wpdb; |
| 30 | 30 | |
| 31 | 31 | // Run the query and get the count. |
| 32 | - $count = $wpdb->get_var( $wpdb->prepare( |
|
| 33 | - 'SELECT COUNT( p.id )' . |
|
| 34 | - " FROM $wpdb->posts p" . |
|
| 35 | - " LEFT JOIN $wpdb->term_relationships tr" . |
|
| 36 | - ' ON tr.object_id = p.id' . |
|
| 37 | - " LEFT JOIN $wpdb->term_taxonomy tt" . |
|
| 38 | - ' ON tt.term_taxonomy_id = tr.term_taxonomy_id' . |
|
| 39 | - " LEFT JOIN $wpdb->terms t" . |
|
| 40 | - ' ON t.term_id = tt.term_id' . |
|
| 41 | - " LEFT JOIN $wpdb->postmeta m" . |
|
| 42 | - " ON m.post_id = p.id AND m.meta_key = '_thumbnail_id'" . |
|
| 43 | - ' WHERE p.post_type = %s' . |
|
| 44 | - " AND t.name IN ( 'Organization', 'Person' )" . |
|
| 45 | - ' AND tt.taxonomy = %s' . |
|
| 32 | + $count = $wpdb->get_var($wpdb->prepare( |
|
| 33 | + 'SELECT COUNT( p.id )'. |
|
| 34 | + " FROM $wpdb->posts p". |
|
| 35 | + " LEFT JOIN $wpdb->term_relationships tr". |
|
| 36 | + ' ON tr.object_id = p.id'. |
|
| 37 | + " LEFT JOIN $wpdb->term_taxonomy tt". |
|
| 38 | + ' ON tt.term_taxonomy_id = tr.term_taxonomy_id'. |
|
| 39 | + " LEFT JOIN $wpdb->terms t". |
|
| 40 | + ' ON t.term_id = tt.term_id'. |
|
| 41 | + " LEFT JOIN $wpdb->postmeta m". |
|
| 42 | + " ON m.post_id = p.id AND m.meta_key = '_thumbnail_id'". |
|
| 43 | + ' WHERE p.post_type = %s'. |
|
| 44 | + " AND t.name IN ( 'Organization', 'Person' )". |
|
| 45 | + ' AND tt.taxonomy = %s'. |
|
| 46 | 46 | ' ORDER BY p.post_title', |
| 47 | 47 | Wordlift_Entity_Service::TYPE_NAME, |
| 48 | 48 | Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME |
| 49 | - ) ); |
|
| 49 | + )); |
|
| 50 | 50 | |
| 51 | 51 | // Finally return the count. |
| 52 | 52 | return (int) $count; |
@@ -62,45 +62,45 @@ discard block |
||
| 62 | 62 | * |
| 63 | 63 | * @return array An array of results. |
| 64 | 64 | */ |
| 65 | - public function query( $filter = '' ) { |
|
| 65 | + public function query($filter = '') { |
|
| 66 | 66 | |
| 67 | 67 | // Get the global `wpdb` instance. |
| 68 | 68 | global $wpdb; |
| 69 | 69 | |
| 70 | 70 | // Run the query and get the results. |
| 71 | - $results = $wpdb->get_results( $wpdb->prepare( |
|
| 72 | - 'SELECT p.id, p.post_title, t.name AS type, m.meta_value AS thumbnail_id' . |
|
| 73 | - " FROM $wpdb->posts p" . |
|
| 74 | - " LEFT JOIN $wpdb->term_relationships tr" . |
|
| 75 | - ' ON tr.object_id = p.id' . |
|
| 76 | - " LEFT JOIN $wpdb->term_taxonomy tt" . |
|
| 77 | - ' ON tt.term_taxonomy_id = tr.term_taxonomy_id' . |
|
| 78 | - " LEFT JOIN $wpdb->terms t" . |
|
| 79 | - ' ON t.term_id = tt.term_id' . |
|
| 80 | - " LEFT JOIN $wpdb->postmeta m" . |
|
| 81 | - " ON m.post_id = p.id AND m.meta_key = '_thumbnail_id'" . |
|
| 82 | - ' WHERE p.post_type = %s' . |
|
| 83 | - " AND t.name IN ( 'Organization', 'Person' )" . |
|
| 84 | - ' AND tt.taxonomy = %s' . |
|
| 85 | - ' AND p.post_title LIKE %s' . |
|
| 71 | + $results = $wpdb->get_results($wpdb->prepare( |
|
| 72 | + 'SELECT p.id, p.post_title, t.name AS type, m.meta_value AS thumbnail_id'. |
|
| 73 | + " FROM $wpdb->posts p". |
|
| 74 | + " LEFT JOIN $wpdb->term_relationships tr". |
|
| 75 | + ' ON tr.object_id = p.id'. |
|
| 76 | + " LEFT JOIN $wpdb->term_taxonomy tt". |
|
| 77 | + ' ON tt.term_taxonomy_id = tr.term_taxonomy_id'. |
|
| 78 | + " LEFT JOIN $wpdb->terms t". |
|
| 79 | + ' ON t.term_id = tt.term_id'. |
|
| 80 | + " LEFT JOIN $wpdb->postmeta m". |
|
| 81 | + " ON m.post_id = p.id AND m.meta_key = '_thumbnail_id'". |
|
| 82 | + ' WHERE p.post_type = %s'. |
|
| 83 | + " AND t.name IN ( 'Organization', 'Person' )". |
|
| 84 | + ' AND tt.taxonomy = %s'. |
|
| 85 | + ' AND p.post_title LIKE %s'. |
|
| 86 | 86 | ' ORDER BY p.post_title', |
| 87 | 87 | Wordlift_Entity_Service::TYPE_NAME, |
| 88 | 88 | Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, |
| 89 | - '%' . $wpdb->esc_like( $filter ) . '%' |
|
| 90 | - ) ); |
|
| 89 | + '%'.$wpdb->esc_like($filter).'%' |
|
| 90 | + )); |
|
| 91 | 91 | |
| 92 | 92 | // Set a reference to ourselves to pass to the closure. |
| 93 | 93 | $publisher_service = $this; |
| 94 | 94 | |
| 95 | 95 | // Map the results in a `Select2` compatible array. |
| 96 | - return array_map( function ( $item ) use ( $publisher_service ) { |
|
| 96 | + return array_map(function($item) use ($publisher_service) { |
|
| 97 | 97 | return array( |
| 98 | 98 | 'id' => $item->id, |
| 99 | 99 | 'text' => $item->post_title, |
| 100 | 100 | 'type' => $item->type, |
| 101 | - 'thumbnail_url' => $publisher_service->get_attachment_image_url( $item->thumbnail_id ), |
|
| 101 | + 'thumbnail_url' => $publisher_service->get_attachment_image_url($item->thumbnail_id), |
|
| 102 | 102 | ); |
| 103 | - }, $results ); |
|
| 103 | + }, $results); |
|
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | /** |
@@ -113,11 +113,11 @@ discard block |
||
| 113 | 113 | * |
| 114 | 114 | * @return string|bool The image URL or false if not found. |
| 115 | 115 | */ |
| 116 | - public function get_attachment_image_url( $attachment_id, $size = 'thumbnail' ) { |
|
| 116 | + public function get_attachment_image_url($attachment_id, $size = 'thumbnail') { |
|
| 117 | 117 | |
| 118 | - $image = wp_get_attachment_image_src( $attachment_id, $size ); |
|
| 118 | + $image = wp_get_attachment_image_src($attachment_id, $size); |
|
| 119 | 119 | |
| 120 | - return isset( $image['0'] ) ? $image['0'] : false; |
|
| 120 | + return isset($image['0']) ? $image['0'] : false; |
|
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | } |
@@ -25,15 +25,15 @@ discard block |
||
| 25 | 25 | */ |
| 26 | 26 | |
| 27 | 27 | // If this file is called directly, abort. |
| 28 | -if ( ! defined( 'WPINC' ) ) { |
|
| 28 | +if ( ! defined('WPINC')) { |
|
| 29 | 29 | die; |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | // Include WordLift constants. |
| 33 | -require_once( 'wordlift_constants.php' ); |
|
| 33 | +require_once('wordlift_constants.php'); |
|
| 34 | 34 | |
| 35 | 35 | // Load modules |
| 36 | -require_once( 'modules/core/wordlift_core.php' ); |
|
| 36 | +require_once('modules/core/wordlift_core.php'); |
|
| 37 | 37 | |
| 38 | 38 | /** |
| 39 | 39 | * Log to the debug.log file. |
@@ -46,9 +46,9 @@ discard block |
||
| 46 | 46 | * |
| 47 | 47 | * @param string|mixed $log The log data. |
| 48 | 48 | */ |
| 49 | -function wl_write_log( $log ) { |
|
| 49 | +function wl_write_log($log) { |
|
| 50 | 50 | |
| 51 | - Wordlift_Log_Service::get_instance()->info( $log ); |
|
| 51 | + Wordlift_Log_Service::get_instance()->info($log); |
|
| 52 | 52 | |
| 53 | 53 | // $handler = apply_filters( 'wl_write_log_handler', null ); |
| 54 | 54 | // |
@@ -74,19 +74,19 @@ discard block |
||
| 74 | 74 | * @param string|array $log The log data. |
| 75 | 75 | * @param string $caller The calling function. |
| 76 | 76 | */ |
| 77 | -function wl_write_log_handler( $log, $caller = null ) { |
|
| 77 | +function wl_write_log_handler($log, $caller = null) { |
|
| 78 | 78 | |
| 79 | 79 | global $wl_logger; |
| 80 | 80 | |
| 81 | - if ( true === WP_DEBUG ) { |
|
| 81 | + if (true === WP_DEBUG) { |
|
| 82 | 82 | |
| 83 | - $message = ( isset( $caller ) ? sprintf( '[%-40.40s] ', $caller ) : '' ) . |
|
| 84 | - ( is_array( $log ) || is_object( $log ) ? print_r( $log, true ) : wl_write_log_hide_key( $log ) ); |
|
| 83 | + $message = (isset($caller) ? sprintf('[%-40.40s] ', $caller) : ''). |
|
| 84 | + (is_array($log) || is_object($log) ? print_r($log, true) : wl_write_log_hide_key($log)); |
|
| 85 | 85 | |
| 86 | - if ( isset( $wl_logger ) ) { |
|
| 87 | - $wl_logger->info( $message ); |
|
| 86 | + if (isset($wl_logger)) { |
|
| 87 | + $wl_logger->info($message); |
|
| 88 | 88 | } else { |
| 89 | - error_log( $message ); |
|
| 89 | + error_log($message); |
|
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | } |
@@ -104,9 +104,9 @@ discard block |
||
| 104 | 104 | * |
| 105 | 105 | * @return string A text with the key hidden. |
| 106 | 106 | */ |
| 107 | -function wl_write_log_hide_key( $text ) { |
|
| 107 | +function wl_write_log_hide_key($text) { |
|
| 108 | 108 | |
| 109 | - return str_ireplace( wl_configuration_get_key(), '<hidden>', $text ); |
|
| 109 | + return str_ireplace(wl_configuration_get_key(), '<hidden>', $text); |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | /** |
@@ -116,12 +116,12 @@ discard block |
||
| 116 | 116 | * |
| 117 | 117 | * @param string $query A SPARQL query. |
| 118 | 118 | */ |
| 119 | -function wl_queue_sparql_update_query( $query ) { |
|
| 119 | +function wl_queue_sparql_update_query($query) { |
|
| 120 | 120 | |
| 121 | - $filename = WL_TEMP_DIR . WL_REQUEST_ID . '.sparql'; |
|
| 122 | - file_put_contents( $filename, $query . "\n", FILE_APPEND ); |
|
| 121 | + $filename = WL_TEMP_DIR.WL_REQUEST_ID.'.sparql'; |
|
| 122 | + file_put_contents($filename, $query."\n", FILE_APPEND); |
|
| 123 | 123 | |
| 124 | - wl_write_log( "wl_queue_sparql_update_query [ filename :: $filename ]" ); |
|
| 124 | + wl_write_log("wl_queue_sparql_update_query [ filename :: $filename ]"); |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | /** |
@@ -129,33 +129,33 @@ discard block |
||
| 129 | 129 | * |
| 130 | 130 | * @param int $request_id The request ID. |
| 131 | 131 | */ |
| 132 | -function wl_execute_saved_sparql_update_query( $request_id ) { |
|
| 132 | +function wl_execute_saved_sparql_update_query($request_id) { |
|
| 133 | 133 | |
| 134 | - $filename = WL_TEMP_DIR . $request_id . '.sparql'; |
|
| 134 | + $filename = WL_TEMP_DIR.$request_id.'.sparql'; |
|
| 135 | 135 | |
| 136 | 136 | // If the file doesn't exist, exit. |
| 137 | - if ( ! file_exists( $filename ) ) { |
|
| 138 | - wl_write_log( "wl_execute_saved_sparql_update_query : file doesn't exist [ filename :: $filename ]" ); |
|
| 137 | + if ( ! file_exists($filename)) { |
|
| 138 | + wl_write_log("wl_execute_saved_sparql_update_query : file doesn't exist [ filename :: $filename ]"); |
|
| 139 | 139 | |
| 140 | 140 | return; |
| 141 | 141 | } |
| 142 | 142 | |
| 143 | - wl_write_log( "wl_execute_saved_sparql_update_query [ filename :: $filename ]" ); |
|
| 143 | + wl_write_log("wl_execute_saved_sparql_update_query [ filename :: $filename ]"); |
|
| 144 | 144 | |
| 145 | 145 | // Get the query saved in the file. |
| 146 | - $query = file_get_contents( $filename ); |
|
| 146 | + $query = file_get_contents($filename); |
|
| 147 | 147 | |
| 148 | 148 | // Execute the SPARQL query. |
| 149 | - rl_execute_sparql_update_query( $query, false ); |
|
| 149 | + rl_execute_sparql_update_query($query, false); |
|
| 150 | 150 | |
| 151 | 151 | // Reindex the triple store. |
| 152 | 152 | wordlift_reindex_triple_store(); |
| 153 | 153 | |
| 154 | 154 | // Delete the temporary file. |
| 155 | - unlink( $filename ); |
|
| 155 | + unlink($filename); |
|
| 156 | 156 | } |
| 157 | 157 | |
| 158 | -add_action( 'wl_execute_saved_sparql_update_query', 'wl_execute_saved_sparql_update_query', 10, 1 ); |
|
| 158 | +add_action('wl_execute_saved_sparql_update_query', 'wl_execute_saved_sparql_update_query', 10, 1); |
|
| 159 | 159 | |
| 160 | 160 | /** |
| 161 | 161 | * Add buttons hook for the TinyMCE editor. This method is called by the WP init hook. |
@@ -163,8 +163,8 @@ discard block |
||
| 163 | 163 | function wordlift_buttonhooks() { |
| 164 | 164 | |
| 165 | 165 | // Only add hooks when the current user has permissions AND is in Rich Text editor mode |
| 166 | - if ( ( current_user_can( 'edit_posts' ) || current_user_can( 'edit_pages' ) ) && get_user_option( 'rich_editing' ) ) { |
|
| 167 | - add_filter( 'mce_external_plugins', 'wordlift_register_tinymce_javascript' ); |
|
| 166 | + if ((current_user_can('edit_posts') || current_user_can('edit_pages')) && get_user_option('rich_editing')) { |
|
| 167 | + add_filter('mce_external_plugins', 'wordlift_register_tinymce_javascript'); |
|
| 168 | 168 | } |
| 169 | 169 | } |
| 170 | 170 | |
@@ -175,11 +175,11 @@ discard block |
||
| 175 | 175 | * |
| 176 | 176 | * @return array The modified plugins array. |
| 177 | 177 | */ |
| 178 | -function wordlift_register_tinymce_javascript( $plugin_array ) { |
|
| 178 | +function wordlift_register_tinymce_javascript($plugin_array) { |
|
| 179 | 179 | |
| 180 | 180 | // add the wordlift plugin. |
| 181 | 181 | // We can't use the minified version here. |
| 182 | - $plugin_array['wordlift'] = plugin_dir_url( __FILE__ ) . 'js/wordlift-reloaded.js'; |
|
| 182 | + $plugin_array['wordlift'] = plugin_dir_url(__FILE__).'js/wordlift-reloaded.js'; |
|
| 183 | 183 | |
| 184 | 184 | return $plugin_array; |
| 185 | 185 | } |
@@ -191,7 +191,7 @@ discard block |
||
| 191 | 191 | function wordlift_allowed_post_tags() { |
| 192 | 192 | global $allowedposttags; |
| 193 | 193 | |
| 194 | - $tags = array( 'span' ); |
|
| 194 | + $tags = array('span'); |
|
| 195 | 195 | $new_attributes = array( |
| 196 | 196 | 'itemscope' => array(), |
| 197 | 197 | 'itemtype' => array(), |
@@ -199,17 +199,17 @@ discard block |
||
| 199 | 199 | 'itemid' => array(), |
| 200 | 200 | ); |
| 201 | 201 | |
| 202 | - foreach ( $tags as $tag ) { |
|
| 203 | - if ( isset( $allowedposttags[ $tag ] ) && is_array( $allowedposttags[ $tag ] ) ) { |
|
| 204 | - $allowedposttags[ $tag ] = array_merge( $allowedposttags[ $tag ], $new_attributes ); |
|
| 202 | + foreach ($tags as $tag) { |
|
| 203 | + if (isset($allowedposttags[$tag]) && is_array($allowedposttags[$tag])) { |
|
| 204 | + $allowedposttags[$tag] = array_merge($allowedposttags[$tag], $new_attributes); |
|
| 205 | 205 | } |
| 206 | 206 | } |
| 207 | 207 | } |
| 208 | 208 | |
| 209 | 209 | // init process for button control |
| 210 | -add_action( 'init', 'wordlift_buttonhooks' ); |
|
| 210 | +add_action('init', 'wordlift_buttonhooks'); |
|
| 211 | 211 | // add allowed post tags. |
| 212 | -add_action( 'init', 'wordlift_allowed_post_tags' ); |
|
| 212 | +add_action('init', 'wordlift_allowed_post_tags'); |
|
| 213 | 213 | |
| 214 | 214 | |
| 215 | 215 | /** |
@@ -218,30 +218,30 @@ discard block |
||
| 218 | 218 | function wordlift_admin_enqueue_scripts() { |
| 219 | 219 | |
| 220 | 220 | // Added for compatibility with WordPress 3.9 (see http://make.wordpress.org/core/2014/04/16/jquery-ui-and-wpdialogs-in-wordpress-3-9/) |
| 221 | - wp_enqueue_script( 'wpdialogs' ); |
|
| 222 | - wp_enqueue_style( 'wp-jquery-ui-dialog' ); |
|
| 221 | + wp_enqueue_script('wpdialogs'); |
|
| 222 | + wp_enqueue_style('wp-jquery-ui-dialog'); |
|
| 223 | 223 | |
| 224 | - wp_enqueue_style( 'wordlift-reloaded', plugin_dir_url( __FILE__ ) . 'css/wordlift-reloaded.min.css' ); |
|
| 224 | + wp_enqueue_style('wordlift-reloaded', plugin_dir_url(__FILE__).'css/wordlift-reloaded.min.css'); |
|
| 225 | 225 | |
| 226 | - wp_enqueue_script( 'jquery-ui-autocomplete' ); |
|
| 227 | - wp_enqueue_script( 'angularjs', 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.11/angular.min.js' ); |
|
| 228 | - wp_enqueue_script( 'angularjs-geolocation', plugin_dir_url( __FILE__ ) . '/bower_components/angularjs-geolocation/dist/angularjs-geolocation.min.js' ); |
|
| 229 | - wp_enqueue_script( 'angularjs-touch', 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.11/angular-touch.min.js' ); |
|
| 230 | - wp_enqueue_script( 'angularjs-animate', 'https://code.angularjs.org/1.3.11/angular-animate.min.js' ); |
|
| 226 | + wp_enqueue_script('jquery-ui-autocomplete'); |
|
| 227 | + wp_enqueue_script('angularjs', 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.11/angular.min.js'); |
|
| 228 | + wp_enqueue_script('angularjs-geolocation', plugin_dir_url(__FILE__).'/bower_components/angularjs-geolocation/dist/angularjs-geolocation.min.js'); |
|
| 229 | + wp_enqueue_script('angularjs-touch', 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.11/angular-touch.min.js'); |
|
| 230 | + wp_enqueue_script('angularjs-animate', 'https://code.angularjs.org/1.3.11/angular-animate.min.js'); |
|
| 231 | 231 | |
| 232 | 232 | // Disable auto-save for custom entity posts only |
| 233 | - if ( Wordlift_Entity_Service::TYPE_NAME === get_post_type() ) { |
|
| 234 | - wp_dequeue_script( 'autosave' ); |
|
| 233 | + if (Wordlift_Entity_Service::TYPE_NAME === get_post_type()) { |
|
| 234 | + wp_dequeue_script('autosave'); |
|
| 235 | 235 | } |
| 236 | 236 | } |
| 237 | 237 | |
| 238 | -add_action( 'admin_enqueue_scripts', 'wordlift_admin_enqueue_scripts' ); |
|
| 238 | +add_action('admin_enqueue_scripts', 'wordlift_admin_enqueue_scripts'); |
|
| 239 | 239 | |
| 240 | 240 | function wl_enqueue_scripts() { |
| 241 | - wp_enqueue_style( 'wordlift-ui', plugin_dir_url( __FILE__ ) . 'css/wordlift-ui.min.css' ); |
|
| 241 | + wp_enqueue_style('wordlift-ui', plugin_dir_url(__FILE__).'css/wordlift-ui.min.css'); |
|
| 242 | 242 | } |
| 243 | 243 | |
| 244 | -add_action( 'wp_enqueue_scripts', 'wl_enqueue_scripts' ); |
|
| 244 | +add_action('wp_enqueue_scripts', 'wl_enqueue_scripts'); |
|
| 245 | 245 | |
| 246 | 246 | /** |
| 247 | 247 | * Hooked to *wp_kses_allowed_html* filter, adds microdata attributes. |
@@ -251,23 +251,23 @@ discard block |
||
| 251 | 251 | * |
| 252 | 252 | * @return array An array which contains allowed microdata attributes. |
| 253 | 253 | */ |
| 254 | -function wordlift_allowed_html( $allowedtags, $context ) { |
|
| 254 | +function wordlift_allowed_html($allowedtags, $context) { |
|
| 255 | 255 | |
| 256 | - if ( 'post' !== $context ) { |
|
| 256 | + if ('post' !== $context) { |
|
| 257 | 257 | return $allowedtags; |
| 258 | 258 | } |
| 259 | 259 | |
| 260 | - return array_merge_recursive( $allowedtags, array( |
|
| 260 | + return array_merge_recursive($allowedtags, array( |
|
| 261 | 261 | 'span' => array( |
| 262 | 262 | 'itemscope' => true, |
| 263 | 263 | 'itemtype' => true, |
| 264 | 264 | 'itemid' => true, |
| 265 | 265 | 'itemprop' => true, |
| 266 | 266 | ), |
| 267 | - ) ); |
|
| 267 | + )); |
|
| 268 | 268 | } |
| 269 | 269 | |
| 270 | -add_filter( 'wp_kses_allowed_html', 'wordlift_allowed_html', 10, 2 ); |
|
| 270 | +add_filter('wp_kses_allowed_html', 'wordlift_allowed_html', 10, 2); |
|
| 271 | 271 | |
| 272 | 272 | /** |
| 273 | 273 | * Get the coordinates for the specified post ID. |
@@ -276,16 +276,16 @@ discard block |
||
| 276 | 276 | * |
| 277 | 277 | * @return array|null An array of coordinates or null. |
| 278 | 278 | */ |
| 279 | -function wl_get_coordinates( $post_id ) { |
|
| 279 | +function wl_get_coordinates($post_id) { |
|
| 280 | 280 | |
| 281 | - $latitude = wl_schema_get_value( $post_id, 'latitude' ); |
|
| 282 | - $longitude = wl_schema_get_value( $post_id, 'longitude' ); |
|
| 281 | + $latitude = wl_schema_get_value($post_id, 'latitude'); |
|
| 282 | + $longitude = wl_schema_get_value($post_id, 'longitude'); |
|
| 283 | 283 | |
| 284 | 284 | // DO NOT set latitude/longitude to 0/0 as default values. It's a specific place on the globe: |
| 285 | 285 | // "The zero/zero point of this system is located in the Gulf of Guinea about 625 km (390 mi) south of Tema, Ghana." |
| 286 | 286 | return array( |
| 287 | - 'latitude' => isset( $latitude[0] ) && is_numeric( $latitude[0] ) ? $latitude[0] : '', |
|
| 288 | - 'longitude' => isset( $longitude[0] ) && is_numeric( $longitude[0] ) ? $longitude[0] : '', |
|
| 287 | + 'latitude' => isset($latitude[0]) && is_numeric($latitude[0]) ? $latitude[0] : '', |
|
| 288 | + 'longitude' => isset($longitude[0]) && is_numeric($longitude[0]) ? $longitude[0] : '', |
|
| 289 | 289 | ); |
| 290 | 290 | } |
| 291 | 291 | |
@@ -296,12 +296,12 @@ discard block |
||
| 296 | 296 | * |
| 297 | 297 | * @return string A datetime. |
| 298 | 298 | */ |
| 299 | -function wl_get_post_modified_time( $post ) { |
|
| 299 | +function wl_get_post_modified_time($post) { |
|
| 300 | 300 | |
| 301 | - $date_modified = get_post_modified_time( 'c', true, $post ); |
|
| 301 | + $date_modified = get_post_modified_time('c', true, $post); |
|
| 302 | 302 | |
| 303 | - if ( '-' === substr( $date_modified, 0, 1 ) ) { |
|
| 304 | - return get_the_time( 'c', $post ); |
|
| 303 | + if ('-' === substr($date_modified, 0, 1)) { |
|
| 304 | + return get_the_time('c', $post); |
|
| 305 | 305 | } |
| 306 | 306 | |
| 307 | 307 | return $date_modified; |
@@ -314,27 +314,27 @@ discard block |
||
| 314 | 314 | * |
| 315 | 315 | * @return array An array of image URLs. |
| 316 | 316 | */ |
| 317 | -function wl_get_image_urls( $post_id ) { |
|
| 317 | +function wl_get_image_urls($post_id) { |
|
| 318 | 318 | |
| 319 | 319 | |
| 320 | 320 | // If there is a featured image it has the priority |
| 321 | - $featured_image_id = get_post_thumbnail_id( $post_id ); |
|
| 322 | - if ( is_numeric( $featured_image_id ) ) { |
|
| 323 | - $image_url = wp_get_attachment_url( $featured_image_id ); |
|
| 321 | + $featured_image_id = get_post_thumbnail_id($post_id); |
|
| 322 | + if (is_numeric($featured_image_id)) { |
|
| 323 | + $image_url = wp_get_attachment_url($featured_image_id); |
|
| 324 | 324 | |
| 325 | - return array( $image_url ); |
|
| 325 | + return array($image_url); |
|
| 326 | 326 | } |
| 327 | 327 | |
| 328 | 328 | // wl_write_log( "wl_get_image_urls [ post id :: $post_id ]" ); |
| 329 | 329 | |
| 330 | - $images = get_children( array( |
|
| 330 | + $images = get_children(array( |
|
| 331 | 331 | 'post_parent' => $post_id, |
| 332 | 332 | 'post_type' => 'attachment', |
| 333 | 333 | 'post_mime_type' => 'image', |
| 334 | - ) ); |
|
| 334 | + )); |
|
| 335 | 335 | |
| 336 | 336 | // Return an empty array if no image is found. |
| 337 | - if ( empty( $images ) ) { |
|
| 337 | + if (empty($images)) { |
|
| 338 | 338 | return array(); |
| 339 | 339 | } |
| 340 | 340 | |
@@ -342,11 +342,11 @@ discard block |
||
| 342 | 342 | $image_urls = array(); |
| 343 | 343 | |
| 344 | 344 | // Collect the URLs. |
| 345 | - foreach ( $images as $attachment_id => $attachment ) { |
|
| 346 | - $image_url = wp_get_attachment_url( $attachment_id ); |
|
| 345 | + foreach ($images as $attachment_id => $attachment) { |
|
| 346 | + $image_url = wp_get_attachment_url($attachment_id); |
|
| 347 | 347 | // Ensure the URL isn't collected already. |
| 348 | - if ( ! in_array( $image_url, $image_urls ) ) { |
|
| 349 | - array_push( $image_urls, $image_url ); |
|
| 348 | + if ( ! in_array($image_url, $image_urls)) { |
|
| 349 | + array_push($image_urls, $image_url); |
|
| 350 | 350 | } |
| 351 | 351 | } |
| 352 | 352 | |
@@ -363,17 +363,17 @@ discard block |
||
| 363 | 363 | * |
| 364 | 364 | * @return string The SPARQL fragment. |
| 365 | 365 | */ |
| 366 | -function wl_get_sparql_images( $uri, $post_id ) { |
|
| 366 | +function wl_get_sparql_images($uri, $post_id) { |
|
| 367 | 367 | |
| 368 | 368 | $sparql = ''; |
| 369 | 369 | |
| 370 | 370 | // Get the escaped URI. |
| 371 | - $uri_e = esc_html( $uri ); |
|
| 371 | + $uri_e = esc_html($uri); |
|
| 372 | 372 | |
| 373 | 373 | // Add SPARQL stmts to write the schema:image. |
| 374 | - $image_urls = wl_get_image_urls( $post_id ); |
|
| 375 | - foreach ( $image_urls as $image_url ) { |
|
| 376 | - $image_url_esc = wl_sparql_escape_uri( $image_url ); |
|
| 374 | + $image_urls = wl_get_image_urls($post_id); |
|
| 375 | + foreach ($image_urls as $image_url) { |
|
| 376 | + $image_url_esc = wl_sparql_escape_uri($image_url); |
|
| 377 | 377 | $sparql .= " <$uri_e> schema:image <$image_url_esc> . \n"; |
| 378 | 378 | } |
| 379 | 379 | |
@@ -388,21 +388,21 @@ discard block |
||
| 388 | 388 | * |
| 389 | 389 | * @return WP_Post|null A post instance or null if not found. |
| 390 | 390 | */ |
| 391 | -function wl_get_attachment_for_source_url( $parent_post_id, $source_url ) { |
|
| 391 | +function wl_get_attachment_for_source_url($parent_post_id, $source_url) { |
|
| 392 | 392 | |
| 393 | 393 | // wl_write_log( "wl_get_attachment_for_source_url [ parent post id :: $parent_post_id ][ source url :: $source_url ]" ); |
| 394 | 394 | |
| 395 | - $posts = get_posts( array( |
|
| 395 | + $posts = get_posts(array( |
|
| 396 | 396 | 'post_type' => 'attachment', |
| 397 | 397 | 'posts_per_page' => 1, |
| 398 | 398 | 'post_status' => 'any', |
| 399 | 399 | 'post_parent' => $parent_post_id, |
| 400 | 400 | 'meta_key' => 'wl_source_url', |
| 401 | 401 | 'meta_value' => $source_url, |
| 402 | - ) ); |
|
| 402 | + )); |
|
| 403 | 403 | |
| 404 | 404 | // Return the found post. |
| 405 | - if ( 1 === count( $posts ) ) { |
|
| 405 | + if (1 === count($posts)) { |
|
| 406 | 406 | return $posts[0]; |
| 407 | 407 | } |
| 408 | 408 | |
@@ -416,10 +416,10 @@ discard block |
||
| 416 | 416 | * @param int $post_id The post ID. |
| 417 | 417 | * @param string $source_url The source URL. |
| 418 | 418 | */ |
| 419 | -function wl_set_source_url( $post_id, $source_url ) { |
|
| 419 | +function wl_set_source_url($post_id, $source_url) { |
|
| 420 | 420 | |
| 421 | - delete_post_meta( $post_id, 'wl_source_url' ); |
|
| 422 | - add_post_meta( $post_id, 'wl_source_url', $source_url ); |
|
| 421 | + delete_post_meta($post_id, 'wl_source_url'); |
|
| 422 | + add_post_meta($post_id, 'wl_source_url', $source_url); |
|
| 423 | 423 | } |
| 424 | 424 | |
| 425 | 425 | |
@@ -435,10 +435,10 @@ discard block |
||
| 435 | 435 | * |
| 436 | 436 | * @param bool $hard True if the rewrite involves configuration updates in Apache/IIS. |
| 437 | 437 | */ |
| 438 | -function wl_flush_rewrite_rules_hard( $hard ) { |
|
| 438 | +function wl_flush_rewrite_rules_hard($hard) { |
|
| 439 | 439 | |
| 440 | 440 | // If WL is not yet configured, we cannot perform any update, so we exit. |
| 441 | - if ( '' === wl_configuration_get_key() ) { |
|
| 441 | + if ('' === wl_configuration_get_key()) { |
|
| 442 | 442 | return; |
| 443 | 443 | } |
| 444 | 444 | |
@@ -447,13 +447,13 @@ discard block |
||
| 447 | 447 | $limit = 100; |
| 448 | 448 | |
| 449 | 449 | // Get more posts if the number of returned posts matches the limit. |
| 450 | - while ( $limit === ( $posts = get_posts( array( |
|
| 450 | + while ($limit === ($posts = get_posts(array( |
|
| 451 | 451 | 'offset' => $offset, |
| 452 | 452 | 'numberposts' => $limit, |
| 453 | 453 | 'orderby' => 'ID', |
| 454 | 454 | 'post_type' => 'any', |
| 455 | 455 | 'post_status' => 'publish', |
| 456 | - ) ) ) ) { |
|
| 456 | + )))) { |
|
| 457 | 457 | |
| 458 | 458 | // Holds the delete part of the query. |
| 459 | 459 | $delete_query = rl_sparql_prefixes(); |
@@ -462,16 +462,16 @@ discard block |
||
| 462 | 462 | $insert_query = ''; |
| 463 | 463 | |
| 464 | 464 | // Cycle in each post to build the query. |
| 465 | - foreach ( $posts as $post ) { |
|
| 465 | + foreach ($posts as $post) { |
|
| 466 | 466 | |
| 467 | 467 | // Ignore revisions. |
| 468 | - if ( wp_is_post_revision( $post->ID ) ) { |
|
| 468 | + if (wp_is_post_revision($post->ID)) { |
|
| 469 | 469 | continue; |
| 470 | 470 | } |
| 471 | 471 | |
| 472 | 472 | // Get the entity URI. |
| 473 | - $s = Wordlift_Sparql_Service::escape_uri( Wordlift_Entity_Service::get_instance() |
|
| 474 | - ->get_uri( $post->ID ) ); |
|
| 473 | + $s = Wordlift_Sparql_Service::escape_uri(Wordlift_Entity_Service::get_instance() |
|
| 474 | + ->get_uri($post->ID)); |
|
| 475 | 475 | |
| 476 | 476 | // Get the post URL. |
| 477 | 477 | // $url = wl_sparql_escape_uri( get_permalink( $post->ID ) ); |
@@ -480,13 +480,13 @@ discard block |
||
| 480 | 480 | $delete_query .= "DELETE { <$s> schema:url ?u . } WHERE { <$s> schema:url ?u . };\n"; |
| 481 | 481 | |
| 482 | 482 | $insert_query .= Wordlift_Schema_Url_Property_Service::get_instance() |
| 483 | - ->get_insert_query( $s, $post->ID ); |
|
| 483 | + ->get_insert_query($s, $post->ID); |
|
| 484 | 484 | |
| 485 | 485 | } |
| 486 | 486 | |
| 487 | 487 | |
| 488 | 488 | // Execute the query. |
| 489 | - rl_execute_sparql_update_query( $delete_query . $insert_query ); |
|
| 489 | + rl_execute_sparql_update_query($delete_query.$insert_query); |
|
| 490 | 490 | |
| 491 | 491 | // Advance to the next posts. |
| 492 | 492 | $offset += $limit; |
@@ -502,7 +502,7 @@ discard block |
||
| 502 | 502 | |
| 503 | 503 | } |
| 504 | 504 | |
| 505 | -add_filter( 'flush_rewrite_rules_hard', 'wl_flush_rewrite_rules_hard', 10, 1 ); |
|
| 505 | +add_filter('flush_rewrite_rules_hard', 'wl_flush_rewrite_rules_hard', 10, 1); |
|
| 506 | 506 | |
| 507 | 507 | /** |
| 508 | 508 | * Sanitizes an URI path by replacing the non allowed characters with an underscore. |
@@ -515,9 +515,9 @@ discard block |
||
| 515 | 515 | * |
| 516 | 516 | * @return string The sanitized path. |
| 517 | 517 | */ |
| 518 | -function wl_sanitize_uri_path( $path, $char = '_' ) { |
|
| 518 | +function wl_sanitize_uri_path($path, $char = '_') { |
|
| 519 | 519 | |
| 520 | - return Wordlift_Uri_Service::get_instance()->sanitize_path( $path, $char ); |
|
| 520 | + return Wordlift_Uri_Service::get_instance()->sanitize_path($path, $char); |
|
| 521 | 521 | } |
| 522 | 522 | |
| 523 | 523 | /** |
@@ -527,10 +527,10 @@ discard block |
||
| 527 | 527 | * |
| 528 | 528 | * @return array Array containing $value (if $value was not an array) |
| 529 | 529 | */ |
| 530 | -function wl_force_to_array( $value ) { |
|
| 530 | +function wl_force_to_array($value) { |
|
| 531 | 531 | |
| 532 | - if ( ! is_array( $value ) ) { |
|
| 533 | - return array( $value ); |
|
| 532 | + if ( ! is_array($value)) { |
|
| 533 | + return array($value); |
|
| 534 | 534 | } |
| 535 | 535 | |
| 536 | 536 | return $value; |
@@ -542,28 +542,28 @@ discard block |
||
| 542 | 542 | function wl_shutdown() { |
| 543 | 543 | |
| 544 | 544 | // Get the filename to the temporary SPARQL file. |
| 545 | - $filename = WL_TEMP_DIR . WL_REQUEST_ID . '.sparql'; |
|
| 545 | + $filename = WL_TEMP_DIR.WL_REQUEST_ID.'.sparql'; |
|
| 546 | 546 | |
| 547 | 547 | // If WordLift is buffering SPARQL queries, we're admins and a buffer exists, then schedule it. |
| 548 | - if ( WL_ENABLE_SPARQL_UPDATE_QUERIES_BUFFERING && is_admin() && file_exists( $filename ) ) { |
|
| 548 | + if (WL_ENABLE_SPARQL_UPDATE_QUERIES_BUFFERING && is_admin() && file_exists($filename)) { |
|
| 549 | 549 | |
| 550 | 550 | // The request ID. |
| 551 | - $args = array( WL_REQUEST_ID ); |
|
| 551 | + $args = array(WL_REQUEST_ID); |
|
| 552 | 552 | |
| 553 | 553 | // Schedule the execution of the SPARQL query with the request ID. |
| 554 | - wp_schedule_single_event( time(), 'wl_execute_saved_sparql_update_query', $args ); |
|
| 554 | + wp_schedule_single_event(time(), 'wl_execute_saved_sparql_update_query', $args); |
|
| 555 | 555 | |
| 556 | 556 | // Check that the request is scheduled. |
| 557 | - $timestamp = wp_next_scheduled( 'wl_execute_saved_sparql_update_query', $args ); |
|
| 557 | + $timestamp = wp_next_scheduled('wl_execute_saved_sparql_update_query', $args); |
|
| 558 | 558 | |
| 559 | 559 | // Spawn the cron. |
| 560 | 560 | spawn_cron(); |
| 561 | 561 | |
| 562 | - wl_write_log( "wl_shutdown [ request id :: " . WL_REQUEST_ID . " ][ timestamp :: $timestamp ]" ); |
|
| 562 | + wl_write_log("wl_shutdown [ request id :: ".WL_REQUEST_ID." ][ timestamp :: $timestamp ]"); |
|
| 563 | 563 | } |
| 564 | 564 | } |
| 565 | 565 | |
| 566 | -add_action( 'shutdown', 'wl_shutdown' ); |
|
| 566 | +add_action('shutdown', 'wl_shutdown'); |
|
| 567 | 567 | |
| 568 | 568 | /** |
| 569 | 569 | * Replaces the *itemid* attributes URIs with the WordLift URIs. |
@@ -572,113 +572,113 @@ discard block |
||
| 572 | 572 | * |
| 573 | 573 | * @return string The updated post content. |
| 574 | 574 | */ |
| 575 | -function wl_replace_item_id_with_uri( $content ) { |
|
| 575 | +function wl_replace_item_id_with_uri($content) { |
|
| 576 | 576 | |
| 577 | 577 | // wl_write_log( "wl_replace_item_id_with_uri" ); |
| 578 | 578 | |
| 579 | 579 | // Strip slashes, see https://core.trac.wordpress.org/ticket/21767 |
| 580 | - $content = stripslashes( $content ); |
|
| 580 | + $content = stripslashes($content); |
|
| 581 | 581 | |
| 582 | 582 | // If any match are found. |
| 583 | 583 | $matches = array(); |
| 584 | - if ( 0 < preg_match_all( '/ itemid="([^"]+)"/i', $content, $matches, PREG_SET_ORDER ) ) { |
|
| 584 | + if (0 < preg_match_all('/ itemid="([^"]+)"/i', $content, $matches, PREG_SET_ORDER)) { |
|
| 585 | 585 | |
| 586 | - foreach ( $matches as $match ) { |
|
| 586 | + foreach ($matches as $match) { |
|
| 587 | 587 | |
| 588 | 588 | // Get the item ID. |
| 589 | 589 | $item_id = $match[1]; |
| 590 | 590 | |
| 591 | 591 | // Get the post bound to that item ID (looking both in the 'official' URI and in the 'same-as' . |
| 592 | 592 | $post = Wordlift_Entity_Service::get_instance() |
| 593 | - ->get_entity_post_by_uri( $item_id ); |
|
| 593 | + ->get_entity_post_by_uri($item_id); |
|
| 594 | 594 | |
| 595 | 595 | // If no entity is found, continue to the next one. |
| 596 | - if ( null === $post ) { |
|
| 596 | + if (null === $post) { |
|
| 597 | 597 | continue; |
| 598 | 598 | } |
| 599 | 599 | |
| 600 | 600 | // Get the URI for that post. |
| 601 | - $uri = wl_get_entity_uri( $post->ID ); |
|
| 601 | + $uri = wl_get_entity_uri($post->ID); |
|
| 602 | 602 | |
| 603 | 603 | // wl_write_log( "wl_replace_item_id_with_uri [ item id :: $item_id ][ uri :: $uri ]" ); |
| 604 | 604 | |
| 605 | 605 | // If the item ID and the URI differ, replace the item ID with the URI saved in WordPress. |
| 606 | - if ( $item_id !== $uri ) { |
|
| 607 | - $uri_e = esc_html( $uri ); |
|
| 608 | - $content = str_replace( " itemid=\"$item_id\"", " itemid=\"$uri_e\"", $content ); |
|
| 606 | + if ($item_id !== $uri) { |
|
| 607 | + $uri_e = esc_html($uri); |
|
| 608 | + $content = str_replace(" itemid=\"$item_id\"", " itemid=\"$uri_e\"", $content); |
|
| 609 | 609 | } |
| 610 | 610 | } |
| 611 | 611 | } |
| 612 | 612 | |
| 613 | 613 | // Reapply slashes. |
| 614 | - $content = addslashes( $content ); |
|
| 614 | + $content = addslashes($content); |
|
| 615 | 615 | |
| 616 | 616 | return $content; |
| 617 | 617 | } |
| 618 | 618 | |
| 619 | -add_filter( 'content_save_pre', 'wl_replace_item_id_with_uri', 1, 1 ); |
|
| 619 | +add_filter('content_save_pre', 'wl_replace_item_id_with_uri', 1, 1); |
|
| 620 | 620 | |
| 621 | -require_once( 'wordlift_entity_functions.php' ); |
|
| 621 | +require_once('wordlift_entity_functions.php'); |
|
| 622 | 622 | |
| 623 | 623 | // add editor related methods. |
| 624 | -require_once( 'wordlift_editor.php' ); |
|
| 624 | +require_once('wordlift_editor.php'); |
|
| 625 | 625 | |
| 626 | 626 | // add the WordLift entity custom type. |
| 627 | -require_once( 'wordlift_entity_type.php' ); |
|
| 628 | -require_once( 'wordlift_entity_type_taxonomy.php' ); |
|
| 627 | +require_once('wordlift_entity_type.php'); |
|
| 628 | +require_once('wordlift_entity_type_taxonomy.php'); |
|
| 629 | 629 | |
| 630 | 630 | // add callbacks on post save to notify data changes from wp to redlink triple store |
| 631 | -require_once( 'wordlift_to_redlink_data_push_callbacks.php' ); |
|
| 631 | +require_once('wordlift_to_redlink_data_push_callbacks.php'); |
|
| 632 | 632 | |
| 633 | -require_once( 'modules/configuration/wordlift_configuration_settings.php' ); |
|
| 633 | +require_once('modules/configuration/wordlift_configuration_settings.php'); |
|
| 634 | 634 | |
| 635 | 635 | // Load modules |
| 636 | -require_once( 'modules/analyzer/wordlift_analyzer.php' ); |
|
| 637 | -require_once( 'modules/linked_data/wordlift_linked_data.php' ); |
|
| 638 | -require_once( 'modules/prefixes/wordlift_prefixes.php' ); |
|
| 639 | -require_once( 'modules/redirector/wordlift_redirector.php' ); |
|
| 636 | +require_once('modules/analyzer/wordlift_analyzer.php'); |
|
| 637 | +require_once('modules/linked_data/wordlift_linked_data.php'); |
|
| 638 | +require_once('modules/prefixes/wordlift_prefixes.php'); |
|
| 639 | +require_once('modules/redirector/wordlift_redirector.php'); |
|
| 640 | 640 | |
| 641 | 641 | // Shortcodes |
| 642 | 642 | |
| 643 | -require_once( 'modules/geo_widget/wordlift_geo_widget.php' ); |
|
| 644 | -require_once( 'shortcodes/wordlift_shortcode_chord.php' ); |
|
| 645 | -require_once( 'shortcodes/wordlift_shortcode_geomap.php' ); |
|
| 646 | -require_once( 'shortcodes/wordlift_shortcode_field.php' ); |
|
| 647 | -require_once( 'shortcodes/wordlift_shortcode_faceted_search.php' ); |
|
| 648 | -require_once( 'shortcodes/wordlift_shortcode_navigator.php' ); |
|
| 643 | +require_once('modules/geo_widget/wordlift_geo_widget.php'); |
|
| 644 | +require_once('shortcodes/wordlift_shortcode_chord.php'); |
|
| 645 | +require_once('shortcodes/wordlift_shortcode_geomap.php'); |
|
| 646 | +require_once('shortcodes/wordlift_shortcode_field.php'); |
|
| 647 | +require_once('shortcodes/wordlift_shortcode_faceted_search.php'); |
|
| 648 | +require_once('shortcodes/wordlift_shortcode_navigator.php'); |
|
| 649 | 649 | |
| 650 | -require_once( 'widgets/wordlift_widget_geo.php' ); |
|
| 651 | -require_once( 'widgets/wordlift_widget_chord.php' ); |
|
| 652 | -require_once( 'widgets/wordlift_widget_timeline.php' ); |
|
| 650 | +require_once('widgets/wordlift_widget_geo.php'); |
|
| 651 | +require_once('widgets/wordlift_widget_chord.php'); |
|
| 652 | +require_once('widgets/wordlift_widget_timeline.php'); |
|
| 653 | 653 | |
| 654 | -require_once( 'wordlift_sparql.php' ); |
|
| 655 | -require_once( 'wordlift_redlink.php' ); |
|
| 654 | +require_once('wordlift_sparql.php'); |
|
| 655 | +require_once('wordlift_redlink.php'); |
|
| 656 | 656 | |
| 657 | 657 | // Add admin functions. |
| 658 | 658 | // TODO: find a way to make 'admin' UI tests work. |
| 659 | 659 | //if ( is_admin() ) { |
| 660 | 660 | |
| 661 | -require_once( 'admin/wordlift_admin.php' ); |
|
| 662 | -require_once( 'admin/wordlift_admin_edit_post.php' ); |
|
| 663 | -require_once( 'admin/wordlift_admin_save_post.php' ); |
|
| 661 | +require_once('admin/wordlift_admin.php'); |
|
| 662 | +require_once('admin/wordlift_admin_edit_post.php'); |
|
| 663 | +require_once('admin/wordlift_admin_save_post.php'); |
|
| 664 | 664 | |
| 665 | 665 | // add the entities meta box. |
| 666 | -require_once( 'admin/wordlift_admin_meta_box_entities.php' ); |
|
| 666 | +require_once('admin/wordlift_admin_meta_box_entities.php'); |
|
| 667 | 667 | |
| 668 | 668 | // add the entity creation AJAX. |
| 669 | -require_once( 'admin/wordlift_admin_ajax_related_posts.php' ); |
|
| 669 | +require_once('admin/wordlift_admin_ajax_related_posts.php'); |
|
| 670 | 670 | |
| 671 | 671 | // Load the wl_chord TinyMCE button and configuration dialog. |
| 672 | -require_once( 'admin/wordlift_admin_shortcodes.php' ); |
|
| 672 | +require_once('admin/wordlift_admin_shortcodes.php'); |
|
| 673 | 673 | |
| 674 | 674 | // Provide syncing features. |
| 675 | -require_once( 'admin/wordlift_admin_sync.php' ); |
|
| 675 | +require_once('admin/wordlift_admin_sync.php'); |
|
| 676 | 676 | //} |
| 677 | 677 | |
| 678 | 678 | // load languages. |
| 679 | 679 | // TODO: the following call gives for granted that the plugin is in the wordlift directory, |
| 680 | 680 | // we're currently doing this because wordlift is symbolic linked. |
| 681 | -load_plugin_textdomain( 'wordlift', false, '/wordlift/languages' ); |
|
| 681 | +load_plugin_textdomain('wordlift', false, '/wordlift/languages'); |
|
| 682 | 682 | |
| 683 | 683 | |
| 684 | 684 | /** |
@@ -686,7 +686,7 @@ discard block |
||
| 686 | 686 | * This action is documented in includes/class-wordlift-activator.php |
| 687 | 687 | */ |
| 688 | 688 | function activate_wordlift() { |
| 689 | - require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-activator.php'; |
|
| 689 | + require_once plugin_dir_path(__FILE__).'includes/class-wordlift-activator.php'; |
|
| 690 | 690 | Wordlift_Activator::activate(); |
| 691 | 691 | } |
| 692 | 692 | |
@@ -695,18 +695,18 @@ discard block |
||
| 695 | 695 | * This action is documented in includes/class-wordlift-deactivator.php |
| 696 | 696 | */ |
| 697 | 697 | function deactivate_wordlift() { |
| 698 | - require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-deactivator.php'; |
|
| 698 | + require_once plugin_dir_path(__FILE__).'includes/class-wordlift-deactivator.php'; |
|
| 699 | 699 | Wordlift_Deactivator::deactivate(); |
| 700 | 700 | } |
| 701 | 701 | |
| 702 | -register_activation_hook( __FILE__, 'activate_wordlift' ); |
|
| 703 | -register_deactivation_hook( __FILE__, 'deactivate_wordlift' ); |
|
| 702 | +register_activation_hook(__FILE__, 'activate_wordlift'); |
|
| 703 | +register_deactivation_hook(__FILE__, 'deactivate_wordlift'); |
|
| 704 | 704 | |
| 705 | 705 | /** |
| 706 | 706 | * The core plugin class that is used to define internationalization, |
| 707 | 707 | * admin-specific hooks, and public-facing site hooks. |
| 708 | 708 | */ |
| 709 | -require plugin_dir_path( __FILE__ ) . 'includes/class-wordlift.php'; |
|
| 709 | +require plugin_dir_path(__FILE__).'includes/class-wordlift.php'; |
|
| 710 | 710 | |
| 711 | 711 | /** |
| 712 | 712 | * Begins execution of the plugin. |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | */ |
| 27 | 27 | |
| 28 | 28 | // If uninstall not called from WordPress, then exit. |
| 29 | -if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) { |
|
| 29 | +if ( ! defined('WP_UNINSTALL_PLUGIN')) { |
|
| 30 | 30 | exit; |
| 31 | 31 | } |
| 32 | 32 | |
@@ -39,53 +39,53 @@ discard block |
||
| 39 | 39 | */ |
| 40 | 40 | |
| 41 | 41 | // Do a db search for posts of type entity |
| 42 | -$args = array( |
|
| 43 | - 'posts_per_page' => - 1, |
|
| 42 | +$args = array( |
|
| 43 | + 'posts_per_page' => -1, |
|
| 44 | 44 | 'post_type' => Wordlift_Entity_Service::TYPE_NAME, |
| 45 | - 'post_status' => array( 'publish', 'pending', 'draft', 'auto-draft', 'future', 'private', 'inherit', 'trash' ), |
|
| 45 | + 'post_status' => array('publish', 'pending', 'draft', 'auto-draft', 'future', 'private', 'inherit', 'trash'), |
|
| 46 | 46 | 'fields' => 'ids' |
| 47 | 47 | ); |
| 48 | -$entities_array = get_posts( $args ); |
|
| 48 | +$entities_array = get_posts($args); |
|
| 49 | 49 | |
| 50 | 50 | // Loop over entities and delete them. |
| 51 | 51 | // TODO: thumbnails? |
| 52 | -wl_write_log( 'Deleting entities and their meta... ' ); |
|
| 53 | -wl_write_log( $entities_array ); |
|
| 54 | -foreach ( $entities_array as $entity_id ) { |
|
| 52 | +wl_write_log('Deleting entities and their meta... '); |
|
| 53 | +wl_write_log($entities_array); |
|
| 54 | +foreach ($entities_array as $entity_id) { |
|
| 55 | 55 | // Delete the whole entity and its metas. |
| 56 | - wp_delete_post( $entity_id, true ); |
|
| 56 | + wp_delete_post($entity_id, true); |
|
| 57 | 57 | } |
| 58 | -wl_write_log( 'Done.' ); |
|
| 58 | +wl_write_log('Done.'); |
|
| 59 | 59 | |
| 60 | 60 | /* |
| 61 | 61 | * Delete post-entity relationships |
| 62 | 62 | */ |
| 63 | -wl_write_log( 'Deleting post-entity relationships... ' ); |
|
| 64 | -$sql = 'DROP TABLE IF EXISTS ' . wl_core_get_relation_instances_table_name() . ';'; |
|
| 65 | -$wpdb->query( $sql ); |
|
| 66 | -delete_option( 'wl_db_version' ); |
|
| 67 | -wl_write_log( 'Done.' ); |
|
| 63 | +wl_write_log('Deleting post-entity relationships... '); |
|
| 64 | +$sql = 'DROP TABLE IF EXISTS '.wl_core_get_relation_instances_table_name().';'; |
|
| 65 | +$wpdb->query($sql); |
|
| 66 | +delete_option('wl_db_version'); |
|
| 67 | +wl_write_log('Done.'); |
|
| 68 | 68 | |
| 69 | 69 | /* |
| 70 | 70 | * Delete taxonomy |
| 71 | 71 | */ |
| 72 | -wl_write_log( 'Cleaning entities taxonomy... ' ); |
|
| 72 | +wl_write_log('Cleaning entities taxonomy... '); |
|
| 73 | 73 | // Delte custom taxonomy terms. |
| 74 | 74 | // We loop over terms in this rude way because in the uninstall script |
| 75 | 75 | // is not possible to call WP custom taxonomy functions. |
| 76 | -foreach ( range( 0, 100 ) as $index ) { |
|
| 77 | - delete_option( Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME . '_' . $index ); |
|
| 78 | - wp_delete_term( $index, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME ); |
|
| 76 | +foreach (range(0, 100) as $index) { |
|
| 77 | + delete_option(Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME.'_'.$index); |
|
| 78 | + wp_delete_term($index, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME); |
|
| 79 | 79 | } |
| 80 | -delete_option( Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME . '_children' ); // it's a hierarchical taxonomy |
|
| 81 | -wl_write_log( 'Done.' ); |
|
| 80 | +delete_option(Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME.'_children'); // it's a hierarchical taxonomy |
|
| 81 | +wl_write_log('Done.'); |
|
| 82 | 82 | |
| 83 | 83 | /** |
| 84 | 84 | * Delete options |
| 85 | 85 | */ |
| 86 | -wl_write_log( 'Cleaning WordLift options... ' ); |
|
| 86 | +wl_write_log('Cleaning WordLift options... '); |
|
| 87 | 87 | // delete_option( WL_OPTIONS_NAME ); |
| 88 | -delete_option( 'wl_option_prefixes' ); |
|
| 89 | -delete_option( 'wl_general_settings' ); |
|
| 90 | -delete_option( 'wl_advanced_settings' ); |
|
| 91 | -wl_write_log( 'Done. WordLift successfully uninstalled.' ); |
|
| 88 | +delete_option('wl_option_prefixes'); |
|
| 89 | +delete_option('wl_general_settings'); |
|
| 90 | +delete_option('wl_advanced_settings'); |
|
| 91 | +wl_write_log('Done. WordLift successfully uninstalled.'); |
|
@@ -4,35 +4,35 @@ discard block |
||
| 4 | 4 | */ |
| 5 | 5 | |
| 6 | 6 | // Define the basic options for HTTP calls to REDLINK. |
| 7 | -define( 'WL_REDLINK_API_HTTP_OPTIONS', serialize( array( |
|
| 7 | +define('WL_REDLINK_API_HTTP_OPTIONS', serialize(array( |
|
| 8 | 8 | 'timeout' => 300, |
| 9 | 9 | 'redirection' => 5, |
| 10 | 10 | 'httpversion' => '1.1', |
| 11 | 11 | 'blocking' => true, |
| 12 | 12 | 'cookies' => array(), |
| 13 | - 'sslverify' => ( 'false' === getenv( 'WL_SSL_VERIFY_ENABLED' ) ) ? false : true, |
|
| 14 | - 'sslcertificates' => dirname( __FILE__ ) . '/ssl/ca-bundle.crt', |
|
| 13 | + 'sslverify' => ('false' === getenv('WL_SSL_VERIFY_ENABLED')) ? false : true, |
|
| 14 | + 'sslcertificates' => dirname(__FILE__).'/ssl/ca-bundle.crt', |
|
| 15 | 15 | 'decompress' => false |
| 16 | -) ) ); |
|
| 16 | +))); |
|
| 17 | 17 | |
| 18 | 18 | // Create a unique ID for this request, useful to hook async HTTP requests. |
| 19 | -define( 'WL_REQUEST_ID', uniqid() ); |
|
| 19 | +define('WL_REQUEST_ID', uniqid()); |
|
| 20 | 20 | |
| 21 | 21 | // Set the temporary files folder. |
| 22 | -defined( 'WL_TEMP_DIR' ) || define( 'WL_TEMP_DIR', get_temp_dir() ); |
|
| 22 | +defined('WL_TEMP_DIR') || define('WL_TEMP_DIR', get_temp_dir()); |
|
| 23 | 23 | |
| 24 | -define( 'WL_ENABLE_SPARQL_UPDATE_QUERIES_BUFFERING', 'true' !== getenv( 'WL_DISABLE_SPARQL_UPDATE_QUERIES_BUFFERING' ) ); |
|
| 24 | +define('WL_ENABLE_SPARQL_UPDATE_QUERIES_BUFFERING', 'true' !== getenv('WL_DISABLE_SPARQL_UPDATE_QUERIES_BUFFERING')); |
|
| 25 | 25 | |
| 26 | 26 | // Define the meta name used to store the entity URL. |
| 27 | -define( 'WL_ENTITY_URL_META_NAME', 'entity_url' ); |
|
| 27 | +define('WL_ENTITY_URL_META_NAME', 'entity_url'); |
|
| 28 | 28 | |
| 29 | 29 | // Max number of recursions when printing microdata |
| 30 | -define( 'WL_RECURSION_DEPTH_ON_ENTITY_METADATA_PRINTING', 3 ); |
|
| 30 | +define('WL_RECURSION_DEPTH_ON_ENTITY_METADATA_PRINTING', 3); |
|
| 31 | 31 | |
| 32 | 32 | |
| 33 | -define( 'WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE', defined( 'WORDLIFT_API_URL' ) ? WORDLIFT_API_URL . '/' : 'https://api.wordlift.it/' ); |
|
| 33 | +define('WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE', defined('WORDLIFT_API_URL') ? WORDLIFT_API_URL.'/' : 'https://api.wordlift.it/'); |
|
| 34 | 34 | |
| 35 | -define( 'WL_CONFIG_TEST_GOOGLE_RICH_SNIPPETS_URL', 'https://developers.google.com/structured-data/testing-tool/?url=' ); |
|
| 35 | +define('WL_CONFIG_TEST_GOOGLE_RICH_SNIPPETS_URL', 'https://developers.google.com/structured-data/testing-tool/?url='); |
|
| 36 | 36 | |
| 37 | 37 | |
| 38 | 38 | /** |
@@ -45,8 +45,8 @@ discard block |
||
| 45 | 45 | $items = wl_prefixes_list(); |
| 46 | 46 | $prefixes = array(); |
| 47 | 47 | |
| 48 | - foreach ( $items as $item ) { |
|
| 49 | - $prefixes[ $item['prefix'] ] = $item['namespace']; |
|
| 48 | + foreach ($items as $item) { |
|
| 49 | + $prefixes[$item['prefix']] = $item['namespace']; |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | return $prefixes; |
@@ -9,12 +9,12 @@ discard block |
||
| 9 | 9 | */ |
| 10 | 10 | function wl_core_check_relation_predicate_is_supported( $predicate ) { |
| 11 | 11 | |
| 12 | - return in_array( $predicate, array( |
|
| 13 | - WL_WHAT_RELATION, |
|
| 14 | - WL_WHEN_RELATION, |
|
| 15 | - WL_WHERE_RELATION, |
|
| 16 | - WL_WHO_RELATION, |
|
| 17 | - ) ); |
|
| 12 | + return in_array( $predicate, array( |
|
| 13 | + WL_WHAT_RELATION, |
|
| 14 | + WL_WHEN_RELATION, |
|
| 15 | + WL_WHERE_RELATION, |
|
| 16 | + WL_WHO_RELATION, |
|
| 17 | + ) ); |
|
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | /** |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | */ |
| 25 | 25 | function wl_core_get_validation_rules() { |
| 26 | 26 | |
| 27 | - return unserialize( WL_CORE_GET_POSTS_VALIDATION_RULES ); |
|
| 27 | + return unserialize( WL_CORE_GET_POSTS_VALIDATION_RULES ); |
|
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | /** |
@@ -34,10 +34,10 @@ discard block |
||
| 34 | 34 | */ |
| 35 | 35 | function wl_core_get_relation_instances_table_name() { |
| 36 | 36 | |
| 37 | - global $wpdb; |
|
| 38 | - $table_name = $wpdb->prefix . WL_DB_RELATION_INSTANCES_TABLE_NAME; |
|
| 37 | + global $wpdb; |
|
| 38 | + $table_name = $wpdb->prefix . WL_DB_RELATION_INSTANCES_TABLE_NAME; |
|
| 39 | 39 | |
| 40 | - return $table_name; |
|
| 40 | + return $table_name; |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | /** |
@@ -52,33 +52,33 @@ discard block |
||
| 52 | 52 | */ |
| 53 | 53 | function wl_core_add_relation_instance( $subject_id, $predicate, $object_id ) { |
| 54 | 54 | |
| 55 | - // Checks on subject and object |
|
| 56 | - if ( ! is_numeric( $subject_id ) || ! is_numeric( $object_id ) ) { |
|
| 57 | - return false; |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - // Checks on the given relation |
|
| 61 | - if ( ! wl_core_check_relation_predicate_is_supported( $predicate ) ) { |
|
| 62 | - return false; |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - // Prepare interaction with db |
|
| 66 | - global $wpdb; |
|
| 67 | - |
|
| 68 | - // Checks passed. Add relation if not exists: |
|
| 69 | - // See https://codex.wordpress.org/Class_Reference/wpdb#REPLACE_row |
|
| 70 | - $wpdb->replace( |
|
| 71 | - wl_core_get_relation_instances_table_name(), |
|
| 72 | - array( |
|
| 73 | - 'subject_id' => $subject_id, |
|
| 74 | - 'predicate' => $predicate, |
|
| 75 | - 'object_id' => $object_id, |
|
| 76 | - ), |
|
| 77 | - array( '%d', '%s', '%d' ) |
|
| 78 | - ); |
|
| 79 | - |
|
| 80 | - // Return record id |
|
| 81 | - return $wpdb->insert_id; |
|
| 55 | + // Checks on subject and object |
|
| 56 | + if ( ! is_numeric( $subject_id ) || ! is_numeric( $object_id ) ) { |
|
| 57 | + return false; |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + // Checks on the given relation |
|
| 61 | + if ( ! wl_core_check_relation_predicate_is_supported( $predicate ) ) { |
|
| 62 | + return false; |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + // Prepare interaction with db |
|
| 66 | + global $wpdb; |
|
| 67 | + |
|
| 68 | + // Checks passed. Add relation if not exists: |
|
| 69 | + // See https://codex.wordpress.org/Class_Reference/wpdb#REPLACE_row |
|
| 70 | + $wpdb->replace( |
|
| 71 | + wl_core_get_relation_instances_table_name(), |
|
| 72 | + array( |
|
| 73 | + 'subject_id' => $subject_id, |
|
| 74 | + 'predicate' => $predicate, |
|
| 75 | + 'object_id' => $object_id, |
|
| 76 | + ), |
|
| 77 | + array( '%d', '%s', '%d' ) |
|
| 78 | + ); |
|
| 79 | + |
|
| 80 | + // Return record id |
|
| 81 | + return $wpdb->insert_id; |
|
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | /** |
@@ -93,33 +93,33 @@ discard block |
||
| 93 | 93 | */ |
| 94 | 94 | function wl_core_delete_relation_instance( $subject_id, $predicate, $object_id ) { |
| 95 | 95 | |
| 96 | - // Checks on subject and object |
|
| 97 | - if ( ! is_numeric( $subject_id ) || ! is_numeric( $object_id ) ) { |
|
| 98 | - return false; |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - // Checks on the given relation |
|
| 102 | - if ( ! wl_core_check_relation_predicate_is_supported( $predicate ) ) { |
|
| 103 | - return false; |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - // Prepare interaction with db |
|
| 107 | - global $wpdb; |
|
| 108 | - |
|
| 109 | - wl_write_log( "Going to delete relation instace [ subject_id :: $subject_id ] [ object_id :: $object_id ] [ predicate :: $predicate ]" ); |
|
| 110 | - |
|
| 111 | - // @see ttps://codex.wordpress.org/it:Riferimento_classi/wpdb#DELETE_di_righe |
|
| 112 | - $wpdb->delete( |
|
| 113 | - wl_core_get_relation_instances_table_name(), |
|
| 114 | - array( |
|
| 115 | - 'subject_id' => $subject_id, |
|
| 116 | - 'predicate' => $predicate, |
|
| 117 | - 'object_id' => $object_id, |
|
| 118 | - ), |
|
| 119 | - array( '%d', '%s', '%d' ) |
|
| 120 | - ); |
|
| 121 | - |
|
| 122 | - return true; |
|
| 96 | + // Checks on subject and object |
|
| 97 | + if ( ! is_numeric( $subject_id ) || ! is_numeric( $object_id ) ) { |
|
| 98 | + return false; |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + // Checks on the given relation |
|
| 102 | + if ( ! wl_core_check_relation_predicate_is_supported( $predicate ) ) { |
|
| 103 | + return false; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + // Prepare interaction with db |
|
| 107 | + global $wpdb; |
|
| 108 | + |
|
| 109 | + wl_write_log( "Going to delete relation instace [ subject_id :: $subject_id ] [ object_id :: $object_id ] [ predicate :: $predicate ]" ); |
|
| 110 | + |
|
| 111 | + // @see ttps://codex.wordpress.org/it:Riferimento_classi/wpdb#DELETE_di_righe |
|
| 112 | + $wpdb->delete( |
|
| 113 | + wl_core_get_relation_instances_table_name(), |
|
| 114 | + array( |
|
| 115 | + 'subject_id' => $subject_id, |
|
| 116 | + 'predicate' => $predicate, |
|
| 117 | + 'object_id' => $object_id, |
|
| 118 | + ), |
|
| 119 | + array( '%d', '%s', '%d' ) |
|
| 120 | + ); |
|
| 121 | + |
|
| 122 | + return true; |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | /** |
@@ -134,29 +134,29 @@ discard block |
||
| 134 | 134 | */ |
| 135 | 135 | function wl_core_add_relation_instances( $subject_id, $predicate, $object_ids ) { |
| 136 | 136 | |
| 137 | - // Checks on subject and object |
|
| 138 | - if ( ! is_numeric( $subject_id ) ) { |
|
| 139 | - return false; |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - // Checks on the given relation |
|
| 143 | - if ( ! wl_core_check_relation_predicate_is_supported( $predicate ) ) { |
|
| 144 | - return false; |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - // Check $object_ids is an array |
|
| 148 | - if ( ! is_array( $object_ids ) || empty( $object_ids ) ) { |
|
| 149 | - return false; |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - // Call method to check and add each single relation |
|
| 153 | - $inserted_records_ids = array(); |
|
| 154 | - foreach ( $object_ids as $object_id ) { |
|
| 155 | - $new_record_id = wl_core_add_relation_instance( $subject_id, $predicate, $object_id ); |
|
| 156 | - $inserted_records_ids[] = $new_record_id; |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - return $inserted_records_ids; |
|
| 137 | + // Checks on subject and object |
|
| 138 | + if ( ! is_numeric( $subject_id ) ) { |
|
| 139 | + return false; |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + // Checks on the given relation |
|
| 143 | + if ( ! wl_core_check_relation_predicate_is_supported( $predicate ) ) { |
|
| 144 | + return false; |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + // Check $object_ids is an array |
|
| 148 | + if ( ! is_array( $object_ids ) || empty( $object_ids ) ) { |
|
| 149 | + return false; |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + // Call method to check and add each single relation |
|
| 153 | + $inserted_records_ids = array(); |
|
| 154 | + foreach ( $object_ids as $object_id ) { |
|
| 155 | + $new_record_id = wl_core_add_relation_instance( $subject_id, $predicate, $object_id ); |
|
| 156 | + $inserted_records_ids[] = $new_record_id; |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + return $inserted_records_ids; |
|
| 160 | 160 | } |
| 161 | 161 | |
| 162 | 162 | /** |
@@ -169,26 +169,26 @@ discard block |
||
| 169 | 169 | */ |
| 170 | 170 | function wl_core_delete_relation_instances( $subject_id ) { |
| 171 | 171 | |
| 172 | - // Checks on subject and object |
|
| 173 | - if ( ! is_numeric( $subject_id ) ) { |
|
| 174 | - return false; |
|
| 175 | - } |
|
| 172 | + // Checks on subject and object |
|
| 173 | + if ( ! is_numeric( $subject_id ) ) { |
|
| 174 | + return false; |
|
| 175 | + } |
|
| 176 | 176 | |
| 177 | - // Prepare interaction with db |
|
| 178 | - global $wpdb; |
|
| 177 | + // Prepare interaction with db |
|
| 178 | + global $wpdb; |
|
| 179 | 179 | |
| 180 | - // wl_write_log( "Going to delete relation instances [ subject_id :: $subject_id ]"); |
|
| 180 | + // wl_write_log( "Going to delete relation instances [ subject_id :: $subject_id ]"); |
|
| 181 | 181 | |
| 182 | - // @see ttps://codex.wordpress.org/it:Riferimento_classi/wpdb#DELETE_di_righe |
|
| 183 | - $wpdb->delete( |
|
| 184 | - wl_core_get_relation_instances_table_name(), |
|
| 185 | - array( |
|
| 186 | - 'subject_id' => $subject_id, |
|
| 187 | - ), |
|
| 188 | - array( '%d' ) |
|
| 189 | - ); |
|
| 182 | + // @see ttps://codex.wordpress.org/it:Riferimento_classi/wpdb#DELETE_di_righe |
|
| 183 | + $wpdb->delete( |
|
| 184 | + wl_core_get_relation_instances_table_name(), |
|
| 185 | + array( |
|
| 186 | + 'subject_id' => $subject_id, |
|
| 187 | + ), |
|
| 188 | + array( '%d' ) |
|
| 189 | + ); |
|
| 190 | 190 | |
| 191 | - return true; |
|
| 191 | + return true; |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | /** |
@@ -204,18 +204,18 @@ discard block |
||
| 204 | 204 | */ |
| 205 | 205 | function wl_core_validate_filters_for_related( $filters ) { |
| 206 | 206 | |
| 207 | - if ( ! is_array( $filters ) ) { |
|
| 208 | - $filters = array(); |
|
| 209 | - } |
|
| 207 | + if ( ! is_array( $filters ) ) { |
|
| 208 | + $filters = array(); |
|
| 209 | + } |
|
| 210 | 210 | |
| 211 | - if ( ! isset( $filters['predicate'] ) ) { |
|
| 212 | - $filters['predicate'] = null; |
|
| 213 | - } |
|
| 214 | - if ( ! isset( $filters['status'] ) ) { |
|
| 215 | - $filters['status'] = null; |
|
| 216 | - } |
|
| 211 | + if ( ! isset( $filters['predicate'] ) ) { |
|
| 212 | + $filters['predicate'] = null; |
|
| 213 | + } |
|
| 214 | + if ( ! isset( $filters['status'] ) ) { |
|
| 215 | + $filters['status'] = null; |
|
| 216 | + } |
|
| 217 | 217 | |
| 218 | - return $filters; |
|
| 218 | + return $filters; |
|
| 219 | 219 | } |
| 220 | 220 | |
| 221 | 221 | /** |
@@ -236,9 +236,9 @@ discard block |
||
| 236 | 236 | */ |
| 237 | 237 | function wl_core_get_related_entities( $subject_id, $filters = array() ) { |
| 238 | 238 | |
| 239 | - $filters = wl_core_validate_filters_for_related( $filters ); |
|
| 239 | + $filters = wl_core_validate_filters_for_related( $filters ); |
|
| 240 | 240 | |
| 241 | - return wl_core_inner_get_related_entities( "posts", $subject_id, $filters['predicate'], $filters['status'] ); |
|
| 241 | + return wl_core_inner_get_related_entities( "posts", $subject_id, $filters['predicate'], $filters['status'] ); |
|
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | /** |
@@ -259,9 +259,9 @@ discard block |
||
| 259 | 259 | */ |
| 260 | 260 | function wl_core_get_related_entity_ids( $subject_id, $filters = array() ) { |
| 261 | 261 | |
| 262 | - $filters = wl_core_validate_filters_for_related( $filters ); |
|
| 262 | + $filters = wl_core_validate_filters_for_related( $filters ); |
|
| 263 | 263 | |
| 264 | - return wl_core_inner_get_related_entities( "post_ids", $subject_id, $filters['predicate'], $filters['status'] ); |
|
| 264 | + return wl_core_inner_get_related_entities( "post_ids", $subject_id, $filters['predicate'], $filters['status'] ); |
|
| 265 | 265 | } |
| 266 | 266 | |
| 267 | 267 | /** |
@@ -278,20 +278,20 @@ discard block |
||
| 278 | 278 | */ |
| 279 | 279 | function wl_core_inner_get_related_entities( $get, $item_id, $predicate = null, $post_status = null ) { |
| 280 | 280 | |
| 281 | - if ( $results = wl_core_get_posts( array( |
|
| 282 | - 'get' => $get, |
|
| 283 | - 'post_type' => 'entity', |
|
| 284 | - 'post_status' => $post_status, |
|
| 285 | - 'related_to' => $item_id, |
|
| 286 | - 'as' => 'object', |
|
| 287 | - 'with_predicate' => $predicate, |
|
| 288 | - ) ) |
|
| 289 | - ) { |
|
| 290 | - return $results; |
|
| 291 | - } |
|
| 292 | - |
|
| 293 | - // If wl_core_get_posts return false then an empty array is returned |
|
| 294 | - return array(); |
|
| 281 | + if ( $results = wl_core_get_posts( array( |
|
| 282 | + 'get' => $get, |
|
| 283 | + 'post_type' => 'entity', |
|
| 284 | + 'post_status' => $post_status, |
|
| 285 | + 'related_to' => $item_id, |
|
| 286 | + 'as' => 'object', |
|
| 287 | + 'with_predicate' => $predicate, |
|
| 288 | + ) ) |
|
| 289 | + ) { |
|
| 290 | + return $results; |
|
| 291 | + } |
|
| 292 | + |
|
| 293 | + // If wl_core_get_posts return false then an empty array is returned |
|
| 294 | + return array(); |
|
| 295 | 295 | } |
| 296 | 296 | |
| 297 | 297 | /** |
@@ -312,9 +312,9 @@ discard block |
||
| 312 | 312 | */ |
| 313 | 313 | function wl_core_get_related_posts( $object_id, $filters = array() ) { |
| 314 | 314 | |
| 315 | - $filters = wl_core_validate_filters_for_related( $filters ); |
|
| 315 | + $filters = wl_core_validate_filters_for_related( $filters ); |
|
| 316 | 316 | |
| 317 | - return wl_core_inner_get_related_posts( "posts", $object_id, $filters['predicate'], $filters['status'] ); |
|
| 317 | + return wl_core_inner_get_related_posts( "posts", $object_id, $filters['predicate'], $filters['status'] ); |
|
| 318 | 318 | } |
| 319 | 319 | |
| 320 | 320 | /** |
@@ -335,9 +335,9 @@ discard block |
||
| 335 | 335 | */ |
| 336 | 336 | function wl_core_get_related_post_ids( $object_id, $filters = array() ) { |
| 337 | 337 | |
| 338 | - $filters = wl_core_validate_filters_for_related( $filters ); |
|
| 338 | + $filters = wl_core_validate_filters_for_related( $filters ); |
|
| 339 | 339 | |
| 340 | - return wl_core_inner_get_related_posts( "post_ids", $object_id, $filters['predicate'], $filters['status'] ); |
|
| 340 | + return wl_core_inner_get_related_posts( "post_ids", $object_id, $filters['predicate'], $filters['status'] ); |
|
| 341 | 341 | } |
| 342 | 342 | |
| 343 | 343 | /** |
@@ -353,41 +353,41 @@ discard block |
||
| 353 | 353 | */ |
| 354 | 354 | function wl_core_inner_get_related_posts( $get, $item_id, $predicate = null, $post_status = null ) { |
| 355 | 355 | |
| 356 | - // Retrieve the post object |
|
| 357 | - $post = get_post( $item_id ); |
|
| 358 | - if ( null === $post ) { |
|
| 359 | - return array(); |
|
| 360 | - } |
|
| 361 | - |
|
| 362 | - if ( "entity" === $post->post_type ) { |
|
| 363 | - if ( $results = wl_core_get_posts( array( |
|
| 364 | - 'get' => $get, |
|
| 365 | - 'post_type' => 'post', |
|
| 366 | - 'post_status' => $post_status, |
|
| 367 | - 'related_to' => $item_id, |
|
| 368 | - 'as' => 'subject', |
|
| 369 | - 'with_predicate' => $predicate, |
|
| 370 | - ) ) |
|
| 371 | - ) { |
|
| 372 | - return $results; |
|
| 373 | - } |
|
| 374 | - } else { |
|
| 375 | - if ( $results = wl_core_get_posts( array( |
|
| 376 | - 'get' => $get, |
|
| 377 | - 'post_type' => 'post', |
|
| 378 | - 'post_status' => $post_status, |
|
| 379 | - 'post__not_in' => array( $item_id ), |
|
| 380 | - 'related_to__in' => wl_core_get_related_entity_ids( $post->ID ), |
|
| 381 | - 'as' => 'subject', |
|
| 382 | - 'with_predicate' => $predicate, |
|
| 383 | - ) ) |
|
| 384 | - ) { |
|
| 385 | - return $results; |
|
| 386 | - } |
|
| 387 | - } |
|
| 388 | - |
|
| 389 | - // If wl_core_get_posts return false then an empty array is returned |
|
| 390 | - return array(); |
|
| 356 | + // Retrieve the post object |
|
| 357 | + $post = get_post( $item_id ); |
|
| 358 | + if ( null === $post ) { |
|
| 359 | + return array(); |
|
| 360 | + } |
|
| 361 | + |
|
| 362 | + if ( "entity" === $post->post_type ) { |
|
| 363 | + if ( $results = wl_core_get_posts( array( |
|
| 364 | + 'get' => $get, |
|
| 365 | + 'post_type' => 'post', |
|
| 366 | + 'post_status' => $post_status, |
|
| 367 | + 'related_to' => $item_id, |
|
| 368 | + 'as' => 'subject', |
|
| 369 | + 'with_predicate' => $predicate, |
|
| 370 | + ) ) |
|
| 371 | + ) { |
|
| 372 | + return $results; |
|
| 373 | + } |
|
| 374 | + } else { |
|
| 375 | + if ( $results = wl_core_get_posts( array( |
|
| 376 | + 'get' => $get, |
|
| 377 | + 'post_type' => 'post', |
|
| 378 | + 'post_status' => $post_status, |
|
| 379 | + 'post__not_in' => array( $item_id ), |
|
| 380 | + 'related_to__in' => wl_core_get_related_entity_ids( $post->ID ), |
|
| 381 | + 'as' => 'subject', |
|
| 382 | + 'with_predicate' => $predicate, |
|
| 383 | + ) ) |
|
| 384 | + ) { |
|
| 385 | + return $results; |
|
| 386 | + } |
|
| 387 | + } |
|
| 388 | + |
|
| 389 | + // If wl_core_get_posts return false then an empty array is returned |
|
| 390 | + return array(); |
|
| 391 | 391 | } |
| 392 | 392 | |
| 393 | 393 | /** |
@@ -417,77 +417,77 @@ discard block |
||
| 417 | 417 | */ |
| 418 | 418 | function wl_core_sql_query_builder( $args ) { |
| 419 | 419 | |
| 420 | - // Prepare interaction with db |
|
| 421 | - global $wpdb; |
|
| 422 | - // Retrieve Wordlift relation instances table name |
|
| 423 | - $table_name = wl_core_get_relation_instances_table_name(); |
|
| 424 | - |
|
| 425 | - // Sql Action |
|
| 426 | - $sql = "SELECT "; |
|
| 427 | - // Determine what has to be returned depending on 'get' argument value |
|
| 428 | - switch ( $args['get'] ) { |
|
| 429 | - case 'posts': |
|
| 430 | - $sql .= "p.*"; |
|
| 431 | - break; |
|
| 432 | - case 'post_ids': |
|
| 433 | - $sql .= "p.id"; |
|
| 434 | - break; |
|
| 435 | - } |
|
| 436 | - |
|
| 437 | - // If we look for posts related as objects the JOIN has to be done with the object_id column and viceversa |
|
| 438 | - $join_column = $args['as'] . "_id"; |
|
| 439 | - |
|
| 440 | - $sql .= " FROM $wpdb->posts as p JOIN $table_name as r ON p.id = r.$join_column"; |
|
| 441 | - |
|
| 442 | - // Sql add post type filter |
|
| 443 | - $sql .= $wpdb->prepare( " AND p.post_type = %s AND", $args['post_type'] ); |
|
| 444 | - |
|
| 445 | - // Sql add post status filter |
|
| 446 | - if ( isset( $args['post_status'] ) && ! is_null( $args['post_status'] ) ) { |
|
| 447 | - $sql .= $wpdb->prepare( " p.post_status = %s AND", $args['post_status'] ); |
|
| 448 | - } |
|
| 449 | - |
|
| 450 | - // Add filtering conditions |
|
| 451 | - // If we look for posts related as objects this means that |
|
| 452 | - // related_to is a reference for a subject: subject_id is the filtering column |
|
| 453 | - // If we look for posts related as subject this means that |
|
| 454 | - // related_to is reference for an object: object_id is the filtering column |
|
| 455 | - |
|
| 456 | - $filtering_column = ( 'object' == $args['as'] ) ? "subject_id" : "object_id"; |
|
| 457 | - |
|
| 458 | - if ( isset( $args['related_to'] ) ) { |
|
| 459 | - $sql .= $wpdb->prepare( " r.$filtering_column = %d", $args['related_to'] ); |
|
| 460 | - } |
|
| 461 | - if ( isset( $args['related_to'] ) && isset( $args['related_to__in'] ) ) { |
|
| 462 | - $sql .= " AND"; |
|
| 463 | - } |
|
| 464 | - if ( isset( $args['related_to__in'] ) ) { |
|
| 465 | - $sql .= " r.$filtering_column IN (" . implode( ",", $args['related_to__in'] ) . ")"; |
|
| 466 | - } |
|
| 467 | - if ( isset( $args['post__not_in'] ) ) { |
|
| 468 | - $sql .= " AND r." . $args['as'] . "_id NOT IN (" . implode( ",", $args['post__not_in'] ) . ")"; |
|
| 469 | - } |
|
| 470 | - if ( isset( $args['post__in'] ) ) { |
|
| 471 | - $sql .= " AND r." . $args['as'] . "_id IN (" . implode( ",", $args['post__in'] ) . ")"; |
|
| 472 | - } |
|
| 473 | - // Add predicate filter if required |
|
| 474 | - if ( isset( $args['with_predicate'] ) ) { |
|
| 475 | - // Sql Inner Join clausole |
|
| 476 | - $sql .= $wpdb->prepare( " AND r.predicate = %s", $args['with_predicate'] ); |
|
| 477 | - } |
|
| 478 | - // Add a group by clause to avoid duplicated rows |
|
| 479 | - // @todo: isn't a distinct a better choice? |
|
| 480 | - $sql .= " GROUP BY p.id"; |
|
| 481 | - |
|
| 482 | - // @todo: how does `first` represent the limit? |
|
| 483 | - if ( isset( $args['first'] ) && is_numeric( $args['first'] ) ) { |
|
| 484 | - // Sql Inner Join clause. |
|
| 485 | - $sql .= $wpdb->prepare( " LIMIT %d", $args['first'] ); |
|
| 486 | - } |
|
| 487 | - // Close sql statement |
|
| 488 | - $sql .= ";"; |
|
| 489 | - |
|
| 490 | - return $sql; |
|
| 420 | + // Prepare interaction with db |
|
| 421 | + global $wpdb; |
|
| 422 | + // Retrieve Wordlift relation instances table name |
|
| 423 | + $table_name = wl_core_get_relation_instances_table_name(); |
|
| 424 | + |
|
| 425 | + // Sql Action |
|
| 426 | + $sql = "SELECT "; |
|
| 427 | + // Determine what has to be returned depending on 'get' argument value |
|
| 428 | + switch ( $args['get'] ) { |
|
| 429 | + case 'posts': |
|
| 430 | + $sql .= "p.*"; |
|
| 431 | + break; |
|
| 432 | + case 'post_ids': |
|
| 433 | + $sql .= "p.id"; |
|
| 434 | + break; |
|
| 435 | + } |
|
| 436 | + |
|
| 437 | + // If we look for posts related as objects the JOIN has to be done with the object_id column and viceversa |
|
| 438 | + $join_column = $args['as'] . "_id"; |
|
| 439 | + |
|
| 440 | + $sql .= " FROM $wpdb->posts as p JOIN $table_name as r ON p.id = r.$join_column"; |
|
| 441 | + |
|
| 442 | + // Sql add post type filter |
|
| 443 | + $sql .= $wpdb->prepare( " AND p.post_type = %s AND", $args['post_type'] ); |
|
| 444 | + |
|
| 445 | + // Sql add post status filter |
|
| 446 | + if ( isset( $args['post_status'] ) && ! is_null( $args['post_status'] ) ) { |
|
| 447 | + $sql .= $wpdb->prepare( " p.post_status = %s AND", $args['post_status'] ); |
|
| 448 | + } |
|
| 449 | + |
|
| 450 | + // Add filtering conditions |
|
| 451 | + // If we look for posts related as objects this means that |
|
| 452 | + // related_to is a reference for a subject: subject_id is the filtering column |
|
| 453 | + // If we look for posts related as subject this means that |
|
| 454 | + // related_to is reference for an object: object_id is the filtering column |
|
| 455 | + |
|
| 456 | + $filtering_column = ( 'object' == $args['as'] ) ? "subject_id" : "object_id"; |
|
| 457 | + |
|
| 458 | + if ( isset( $args['related_to'] ) ) { |
|
| 459 | + $sql .= $wpdb->prepare( " r.$filtering_column = %d", $args['related_to'] ); |
|
| 460 | + } |
|
| 461 | + if ( isset( $args['related_to'] ) && isset( $args['related_to__in'] ) ) { |
|
| 462 | + $sql .= " AND"; |
|
| 463 | + } |
|
| 464 | + if ( isset( $args['related_to__in'] ) ) { |
|
| 465 | + $sql .= " r.$filtering_column IN (" . implode( ",", $args['related_to__in'] ) . ")"; |
|
| 466 | + } |
|
| 467 | + if ( isset( $args['post__not_in'] ) ) { |
|
| 468 | + $sql .= " AND r." . $args['as'] . "_id NOT IN (" . implode( ",", $args['post__not_in'] ) . ")"; |
|
| 469 | + } |
|
| 470 | + if ( isset( $args['post__in'] ) ) { |
|
| 471 | + $sql .= " AND r." . $args['as'] . "_id IN (" . implode( ",", $args['post__in'] ) . ")"; |
|
| 472 | + } |
|
| 473 | + // Add predicate filter if required |
|
| 474 | + if ( isset( $args['with_predicate'] ) ) { |
|
| 475 | + // Sql Inner Join clausole |
|
| 476 | + $sql .= $wpdb->prepare( " AND r.predicate = %s", $args['with_predicate'] ); |
|
| 477 | + } |
|
| 478 | + // Add a group by clause to avoid duplicated rows |
|
| 479 | + // @todo: isn't a distinct a better choice? |
|
| 480 | + $sql .= " GROUP BY p.id"; |
|
| 481 | + |
|
| 482 | + // @todo: how does `first` represent the limit? |
|
| 483 | + if ( isset( $args['first'] ) && is_numeric( $args['first'] ) ) { |
|
| 484 | + // Sql Inner Join clause. |
|
| 485 | + $sql .= $wpdb->prepare( " LIMIT %d", $args['first'] ); |
|
| 486 | + } |
|
| 487 | + // Close sql statement |
|
| 488 | + $sql .= ";"; |
|
| 489 | + |
|
| 490 | + return $sql; |
|
| 491 | 491 | |
| 492 | 492 | } |
| 493 | 493 | |
@@ -503,73 +503,73 @@ discard block |
||
| 503 | 503 | */ |
| 504 | 504 | function wl_core_get_posts( $args, $returned_type = OBJECT ) { |
| 505 | 505 | |
| 506 | - // Merge given args with defaults args value |
|
| 507 | - $args = array_merge( array( |
|
| 508 | - 'with_predicate' => null, |
|
| 509 | - 'as' => 'subject', |
|
| 510 | - 'post_type' => 'post', |
|
| 511 | - 'get' => 'posts', |
|
| 512 | - 'post_status' => null, |
|
| 513 | - ), $args ); |
|
| 514 | - |
|
| 515 | - // Arguments validation rules |
|
| 516 | - // At least one between related_to and related_to__in has to be set |
|
| 517 | - if ( ! isset( $args['related_to'] ) && ! isset( $args['related_to__in'] ) ) { |
|
| 518 | - return false; |
|
| 519 | - } |
|
| 520 | - if ( isset( $args['related_to'] ) && ! is_numeric( $args['related_to'] ) ) { |
|
| 521 | - return false; |
|
| 522 | - } |
|
| 523 | - |
|
| 524 | - // The same check is applied to post_in, post__not_in and related_to__in options |
|
| 525 | - // Only arrays with at least one numeric value are considerad valid |
|
| 526 | - // The argument value is further sanitized in order to clean up not numeric values |
|
| 527 | - foreach ( |
|
| 528 | - array( |
|
| 529 | - 'post__in', |
|
| 530 | - 'post__not_in', |
|
| 531 | - 'related_to__in', |
|
| 532 | - ) as $option_name |
|
| 533 | - ) { |
|
| 534 | - if ( isset( $args[ $option_name ] ) ) { |
|
| 535 | - if ( ! is_array( $args[ $option_name ] ) || 0 == count( array_filter( $args[ $option_name ], "is_numeric" ) ) ) { |
|
| 536 | - return false; |
|
| 537 | - } |
|
| 538 | - // Sanitize value removing non numeric values from the array |
|
| 539 | - $args[ $option_name ] = array_filter( $args[ $option_name ], "is_numeric" ); |
|
| 540 | - } |
|
| 541 | - } |
|
| 542 | - // Performing validation rules |
|
| 543 | - foreach ( wl_core_get_validation_rules() as $option_name => $accepeted_values ) { |
|
| 544 | - if ( isset( $args[ $option_name ] ) && ! is_null( $args[ $option_name ] ) ) { |
|
| 545 | - if ( ! in_array( $args[ $option_name ], $accepeted_values ) ) { |
|
| 546 | - return false; |
|
| 547 | - } |
|
| 548 | - } |
|
| 549 | - } |
|
| 550 | - |
|
| 551 | - // Prepare interaction with db |
|
| 552 | - global $wpdb; |
|
| 553 | - |
|
| 554 | - // Build sql statement with given arguments |
|
| 555 | - $sql_statement = wl_core_sql_query_builder( $args ); |
|
| 556 | - |
|
| 557 | - // wl_write_log( "Going to execute sql statement: $sql_statement " ); |
|
| 558 | - // $results = array(); |
|
| 559 | - |
|
| 560 | - // If ids are required, returns a one-dimensional array containing ids. |
|
| 561 | - // Otherwise an array of associative arrays representing the post | relation object |
|
| 562 | - if ( 'post_ids' == $args['get'] ) { |
|
| 563 | - # See https://codex.wordpress.org/Class_Reference/wpdb#SELECT_a_Column |
|
| 564 | - $results = $wpdb->get_col( $sql_statement ); |
|
| 565 | - } else { |
|
| 566 | - $results = $wpdb->get_results( $sql_statement, $returned_type ); |
|
| 567 | - } |
|
| 568 | - // If there were an error performing the query then false is returned |
|
| 569 | - if ( ! empty( $wpdb->last_error ) ) { |
|
| 570 | - return false; |
|
| 571 | - } |
|
| 572 | - |
|
| 573 | - // Finally |
|
| 574 | - return $results; |
|
| 506 | + // Merge given args with defaults args value |
|
| 507 | + $args = array_merge( array( |
|
| 508 | + 'with_predicate' => null, |
|
| 509 | + 'as' => 'subject', |
|
| 510 | + 'post_type' => 'post', |
|
| 511 | + 'get' => 'posts', |
|
| 512 | + 'post_status' => null, |
|
| 513 | + ), $args ); |
|
| 514 | + |
|
| 515 | + // Arguments validation rules |
|
| 516 | + // At least one between related_to and related_to__in has to be set |
|
| 517 | + if ( ! isset( $args['related_to'] ) && ! isset( $args['related_to__in'] ) ) { |
|
| 518 | + return false; |
|
| 519 | + } |
|
| 520 | + if ( isset( $args['related_to'] ) && ! is_numeric( $args['related_to'] ) ) { |
|
| 521 | + return false; |
|
| 522 | + } |
|
| 523 | + |
|
| 524 | + // The same check is applied to post_in, post__not_in and related_to__in options |
|
| 525 | + // Only arrays with at least one numeric value are considerad valid |
|
| 526 | + // The argument value is further sanitized in order to clean up not numeric values |
|
| 527 | + foreach ( |
|
| 528 | + array( |
|
| 529 | + 'post__in', |
|
| 530 | + 'post__not_in', |
|
| 531 | + 'related_to__in', |
|
| 532 | + ) as $option_name |
|
| 533 | + ) { |
|
| 534 | + if ( isset( $args[ $option_name ] ) ) { |
|
| 535 | + if ( ! is_array( $args[ $option_name ] ) || 0 == count( array_filter( $args[ $option_name ], "is_numeric" ) ) ) { |
|
| 536 | + return false; |
|
| 537 | + } |
|
| 538 | + // Sanitize value removing non numeric values from the array |
|
| 539 | + $args[ $option_name ] = array_filter( $args[ $option_name ], "is_numeric" ); |
|
| 540 | + } |
|
| 541 | + } |
|
| 542 | + // Performing validation rules |
|
| 543 | + foreach ( wl_core_get_validation_rules() as $option_name => $accepeted_values ) { |
|
| 544 | + if ( isset( $args[ $option_name ] ) && ! is_null( $args[ $option_name ] ) ) { |
|
| 545 | + if ( ! in_array( $args[ $option_name ], $accepeted_values ) ) { |
|
| 546 | + return false; |
|
| 547 | + } |
|
| 548 | + } |
|
| 549 | + } |
|
| 550 | + |
|
| 551 | + // Prepare interaction with db |
|
| 552 | + global $wpdb; |
|
| 553 | + |
|
| 554 | + // Build sql statement with given arguments |
|
| 555 | + $sql_statement = wl_core_sql_query_builder( $args ); |
|
| 556 | + |
|
| 557 | + // wl_write_log( "Going to execute sql statement: $sql_statement " ); |
|
| 558 | + // $results = array(); |
|
| 559 | + |
|
| 560 | + // If ids are required, returns a one-dimensional array containing ids. |
|
| 561 | + // Otherwise an array of associative arrays representing the post | relation object |
|
| 562 | + if ( 'post_ids' == $args['get'] ) { |
|
| 563 | + # See https://codex.wordpress.org/Class_Reference/wpdb#SELECT_a_Column |
|
| 564 | + $results = $wpdb->get_col( $sql_statement ); |
|
| 565 | + } else { |
|
| 566 | + $results = $wpdb->get_results( $sql_statement, $returned_type ); |
|
| 567 | + } |
|
| 568 | + // If there were an error performing the query then false is returned |
|
| 569 | + if ( ! empty( $wpdb->last_error ) ) { |
|
| 570 | + return false; |
|
| 571 | + } |
|
| 572 | + |
|
| 573 | + // Finally |
|
| 574 | + return $results; |
|
| 575 | 575 | } |
@@ -7,14 +7,14 @@ discard block |
||
| 7 | 7 | * |
| 8 | 8 | * @return boolean Return true if supported, false otherwise |
| 9 | 9 | */ |
| 10 | -function wl_core_check_relation_predicate_is_supported( $predicate ) { |
|
| 10 | +function wl_core_check_relation_predicate_is_supported($predicate) { |
|
| 11 | 11 | |
| 12 | - return in_array( $predicate, array( |
|
| 12 | + return in_array($predicate, array( |
|
| 13 | 13 | WL_WHAT_RELATION, |
| 14 | 14 | WL_WHEN_RELATION, |
| 15 | 15 | WL_WHERE_RELATION, |
| 16 | 16 | WL_WHO_RELATION, |
| 17 | - ) ); |
|
| 17 | + )); |
|
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | /** |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | */ |
| 25 | 25 | function wl_core_get_validation_rules() { |
| 26 | 26 | |
| 27 | - return unserialize( WL_CORE_GET_POSTS_VALIDATION_RULES ); |
|
| 27 | + return unserialize(WL_CORE_GET_POSTS_VALIDATION_RULES); |
|
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | /** |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | function wl_core_get_relation_instances_table_name() { |
| 36 | 36 | |
| 37 | 37 | global $wpdb; |
| 38 | - $table_name = $wpdb->prefix . WL_DB_RELATION_INSTANCES_TABLE_NAME; |
|
| 38 | + $table_name = $wpdb->prefix.WL_DB_RELATION_INSTANCES_TABLE_NAME; |
|
| 39 | 39 | |
| 40 | 40 | return $table_name; |
| 41 | 41 | } |
@@ -50,15 +50,15 @@ discard block |
||
| 50 | 50 | * @uses $wpdb->replace() to perform the query |
| 51 | 51 | * @return (integer|boolean) Return then relation instance ID or false |
| 52 | 52 | */ |
| 53 | -function wl_core_add_relation_instance( $subject_id, $predicate, $object_id ) { |
|
| 53 | +function wl_core_add_relation_instance($subject_id, $predicate, $object_id) { |
|
| 54 | 54 | |
| 55 | 55 | // Checks on subject and object |
| 56 | - if ( ! is_numeric( $subject_id ) || ! is_numeric( $object_id ) ) { |
|
| 56 | + if ( ! is_numeric($subject_id) || ! is_numeric($object_id)) { |
|
| 57 | 57 | return false; |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | // Checks on the given relation |
| 61 | - if ( ! wl_core_check_relation_predicate_is_supported( $predicate ) ) { |
|
| 61 | + if ( ! wl_core_check_relation_predicate_is_supported($predicate)) { |
|
| 62 | 62 | return false; |
| 63 | 63 | } |
| 64 | 64 | |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | 'predicate' => $predicate, |
| 75 | 75 | 'object_id' => $object_id, |
| 76 | 76 | ), |
| 77 | - array( '%d', '%s', '%d' ) |
|
| 77 | + array('%d', '%s', '%d') |
|
| 78 | 78 | ); |
| 79 | 79 | |
| 80 | 80 | // Return record id |
@@ -91,22 +91,22 @@ discard block |
||
| 91 | 91 | * |
| 92 | 92 | * @return (boolean) False for failure. True for success. |
| 93 | 93 | */ |
| 94 | -function wl_core_delete_relation_instance( $subject_id, $predicate, $object_id ) { |
|
| 94 | +function wl_core_delete_relation_instance($subject_id, $predicate, $object_id) { |
|
| 95 | 95 | |
| 96 | 96 | // Checks on subject and object |
| 97 | - if ( ! is_numeric( $subject_id ) || ! is_numeric( $object_id ) ) { |
|
| 97 | + if ( ! is_numeric($subject_id) || ! is_numeric($object_id)) { |
|
| 98 | 98 | return false; |
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | // Checks on the given relation |
| 102 | - if ( ! wl_core_check_relation_predicate_is_supported( $predicate ) ) { |
|
| 102 | + if ( ! wl_core_check_relation_predicate_is_supported($predicate)) { |
|
| 103 | 103 | return false; |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | // Prepare interaction with db |
| 107 | 107 | global $wpdb; |
| 108 | 108 | |
| 109 | - wl_write_log( "Going to delete relation instace [ subject_id :: $subject_id ] [ object_id :: $object_id ] [ predicate :: $predicate ]" ); |
|
| 109 | + wl_write_log("Going to delete relation instace [ subject_id :: $subject_id ] [ object_id :: $object_id ] [ predicate :: $predicate ]"); |
|
| 110 | 110 | |
| 111 | 111 | // @see ttps://codex.wordpress.org/it:Riferimento_classi/wpdb#DELETE_di_righe |
| 112 | 112 | $wpdb->delete( |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | 'predicate' => $predicate, |
| 117 | 117 | 'object_id' => $object_id, |
| 118 | 118 | ), |
| 119 | - array( '%d', '%s', '%d' ) |
|
| 119 | + array('%d', '%s', '%d') |
|
| 120 | 120 | ); |
| 121 | 121 | |
| 122 | 122 | return true; |
@@ -132,27 +132,27 @@ discard block |
||
| 132 | 132 | * |
| 133 | 133 | * @return (integer|boolean) Return the relation instances IDs or false |
| 134 | 134 | */ |
| 135 | -function wl_core_add_relation_instances( $subject_id, $predicate, $object_ids ) { |
|
| 135 | +function wl_core_add_relation_instances($subject_id, $predicate, $object_ids) { |
|
| 136 | 136 | |
| 137 | 137 | // Checks on subject and object |
| 138 | - if ( ! is_numeric( $subject_id ) ) { |
|
| 138 | + if ( ! is_numeric($subject_id)) { |
|
| 139 | 139 | return false; |
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | // Checks on the given relation |
| 143 | - if ( ! wl_core_check_relation_predicate_is_supported( $predicate ) ) { |
|
| 143 | + if ( ! wl_core_check_relation_predicate_is_supported($predicate)) { |
|
| 144 | 144 | return false; |
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | // Check $object_ids is an array |
| 148 | - if ( ! is_array( $object_ids ) || empty( $object_ids ) ) { |
|
| 148 | + if ( ! is_array($object_ids) || empty($object_ids)) { |
|
| 149 | 149 | return false; |
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | // Call method to check and add each single relation |
| 153 | 153 | $inserted_records_ids = array(); |
| 154 | - foreach ( $object_ids as $object_id ) { |
|
| 155 | - $new_record_id = wl_core_add_relation_instance( $subject_id, $predicate, $object_id ); |
|
| 154 | + foreach ($object_ids as $object_id) { |
|
| 155 | + $new_record_id = wl_core_add_relation_instance($subject_id, $predicate, $object_id); |
|
| 156 | 156 | $inserted_records_ids[] = $new_record_id; |
| 157 | 157 | } |
| 158 | 158 | |
@@ -167,10 +167,10 @@ discard block |
||
| 167 | 167 | * |
| 168 | 168 | * @return (boolean) False for failure. True for success. |
| 169 | 169 | */ |
| 170 | -function wl_core_delete_relation_instances( $subject_id ) { |
|
| 170 | +function wl_core_delete_relation_instances($subject_id) { |
|
| 171 | 171 | |
| 172 | 172 | // Checks on subject and object |
| 173 | - if ( ! is_numeric( $subject_id ) ) { |
|
| 173 | + if ( ! is_numeric($subject_id)) { |
|
| 174 | 174 | return false; |
| 175 | 175 | } |
| 176 | 176 | |
@@ -185,7 +185,7 @@ discard block |
||
| 185 | 185 | array( |
| 186 | 186 | 'subject_id' => $subject_id, |
| 187 | 187 | ), |
| 188 | - array( '%d' ) |
|
| 188 | + array('%d') |
|
| 189 | 189 | ); |
| 190 | 190 | |
| 191 | 191 | return true; |
@@ -202,16 +202,16 @@ discard block |
||
| 202 | 202 | * 'status' => null |
| 203 | 203 | * ); |
| 204 | 204 | */ |
| 205 | -function wl_core_validate_filters_for_related( $filters ) { |
|
| 205 | +function wl_core_validate_filters_for_related($filters) { |
|
| 206 | 206 | |
| 207 | - if ( ! is_array( $filters ) ) { |
|
| 207 | + if ( ! is_array($filters)) { |
|
| 208 | 208 | $filters = array(); |
| 209 | 209 | } |
| 210 | 210 | |
| 211 | - if ( ! isset( $filters['predicate'] ) ) { |
|
| 211 | + if ( ! isset($filters['predicate'])) { |
|
| 212 | 212 | $filters['predicate'] = null; |
| 213 | 213 | } |
| 214 | - if ( ! isset( $filters['status'] ) ) { |
|
| 214 | + if ( ! isset($filters['status'])) { |
|
| 215 | 215 | $filters['status'] = null; |
| 216 | 216 | } |
| 217 | 217 | |
@@ -234,11 +234,11 @@ discard block |
||
| 234 | 234 | * |
| 235 | 235 | * @return array Array of post entity objects. |
| 236 | 236 | */ |
| 237 | -function wl_core_get_related_entities( $subject_id, $filters = array() ) { |
|
| 237 | +function wl_core_get_related_entities($subject_id, $filters = array()) { |
|
| 238 | 238 | |
| 239 | - $filters = wl_core_validate_filters_for_related( $filters ); |
|
| 239 | + $filters = wl_core_validate_filters_for_related($filters); |
|
| 240 | 240 | |
| 241 | - return wl_core_inner_get_related_entities( "posts", $subject_id, $filters['predicate'], $filters['status'] ); |
|
| 241 | + return wl_core_inner_get_related_entities("posts", $subject_id, $filters['predicate'], $filters['status']); |
|
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | /** |
@@ -257,11 +257,11 @@ discard block |
||
| 257 | 257 | * |
| 258 | 258 | * @return array Array of post entity objects. |
| 259 | 259 | */ |
| 260 | -function wl_core_get_related_entity_ids( $subject_id, $filters = array() ) { |
|
| 260 | +function wl_core_get_related_entity_ids($subject_id, $filters = array()) { |
|
| 261 | 261 | |
| 262 | - $filters = wl_core_validate_filters_for_related( $filters ); |
|
| 262 | + $filters = wl_core_validate_filters_for_related($filters); |
|
| 263 | 263 | |
| 264 | - return wl_core_inner_get_related_entities( "post_ids", $subject_id, $filters['predicate'], $filters['status'] ); |
|
| 264 | + return wl_core_inner_get_related_entities("post_ids", $subject_id, $filters['predicate'], $filters['status']); |
|
| 265 | 265 | } |
| 266 | 266 | |
| 267 | 267 | /** |
@@ -276,16 +276,16 @@ discard block |
||
| 276 | 276 | * |
| 277 | 277 | * @return array Array of ids. |
| 278 | 278 | */ |
| 279 | -function wl_core_inner_get_related_entities( $get, $item_id, $predicate = null, $post_status = null ) { |
|
| 279 | +function wl_core_inner_get_related_entities($get, $item_id, $predicate = null, $post_status = null) { |
|
| 280 | 280 | |
| 281 | - if ( $results = wl_core_get_posts( array( |
|
| 281 | + if ($results = wl_core_get_posts(array( |
|
| 282 | 282 | 'get' => $get, |
| 283 | 283 | 'post_type' => 'entity', |
| 284 | 284 | 'post_status' => $post_status, |
| 285 | 285 | 'related_to' => $item_id, |
| 286 | 286 | 'as' => 'object', |
| 287 | 287 | 'with_predicate' => $predicate, |
| 288 | - ) ) |
|
| 288 | + )) |
|
| 289 | 289 | ) { |
| 290 | 290 | return $results; |
| 291 | 291 | } |
@@ -310,11 +310,11 @@ discard block |
||
| 310 | 310 | * |
| 311 | 311 | * @return array Array of objects. |
| 312 | 312 | */ |
| 313 | -function wl_core_get_related_posts( $object_id, $filters = array() ) { |
|
| 313 | +function wl_core_get_related_posts($object_id, $filters = array()) { |
|
| 314 | 314 | |
| 315 | - $filters = wl_core_validate_filters_for_related( $filters ); |
|
| 315 | + $filters = wl_core_validate_filters_for_related($filters); |
|
| 316 | 316 | |
| 317 | - return wl_core_inner_get_related_posts( "posts", $object_id, $filters['predicate'], $filters['status'] ); |
|
| 317 | + return wl_core_inner_get_related_posts("posts", $object_id, $filters['predicate'], $filters['status']); |
|
| 318 | 318 | } |
| 319 | 319 | |
| 320 | 320 | /** |
@@ -333,11 +333,11 @@ discard block |
||
| 333 | 333 | * |
| 334 | 334 | * @return array Array of objects. |
| 335 | 335 | */ |
| 336 | -function wl_core_get_related_post_ids( $object_id, $filters = array() ) { |
|
| 336 | +function wl_core_get_related_post_ids($object_id, $filters = array()) { |
|
| 337 | 337 | |
| 338 | - $filters = wl_core_validate_filters_for_related( $filters ); |
|
| 338 | + $filters = wl_core_validate_filters_for_related($filters); |
|
| 339 | 339 | |
| 340 | - return wl_core_inner_get_related_posts( "post_ids", $object_id, $filters['predicate'], $filters['status'] ); |
|
| 340 | + return wl_core_inner_get_related_posts("post_ids", $object_id, $filters['predicate'], $filters['status']); |
|
| 341 | 341 | } |
| 342 | 342 | |
| 343 | 343 | /** |
@@ -351,36 +351,36 @@ discard block |
||
| 351 | 351 | * |
| 352 | 352 | * @return array Array of objects. |
| 353 | 353 | */ |
| 354 | -function wl_core_inner_get_related_posts( $get, $item_id, $predicate = null, $post_status = null ) { |
|
| 354 | +function wl_core_inner_get_related_posts($get, $item_id, $predicate = null, $post_status = null) { |
|
| 355 | 355 | |
| 356 | 356 | // Retrieve the post object |
| 357 | - $post = get_post( $item_id ); |
|
| 358 | - if ( null === $post ) { |
|
| 357 | + $post = get_post($item_id); |
|
| 358 | + if (null === $post) { |
|
| 359 | 359 | return array(); |
| 360 | 360 | } |
| 361 | 361 | |
| 362 | - if ( "entity" === $post->post_type ) { |
|
| 363 | - if ( $results = wl_core_get_posts( array( |
|
| 362 | + if ("entity" === $post->post_type) { |
|
| 363 | + if ($results = wl_core_get_posts(array( |
|
| 364 | 364 | 'get' => $get, |
| 365 | 365 | 'post_type' => 'post', |
| 366 | 366 | 'post_status' => $post_status, |
| 367 | 367 | 'related_to' => $item_id, |
| 368 | 368 | 'as' => 'subject', |
| 369 | 369 | 'with_predicate' => $predicate, |
| 370 | - ) ) |
|
| 370 | + )) |
|
| 371 | 371 | ) { |
| 372 | 372 | return $results; |
| 373 | 373 | } |
| 374 | 374 | } else { |
| 375 | - if ( $results = wl_core_get_posts( array( |
|
| 375 | + if ($results = wl_core_get_posts(array( |
|
| 376 | 376 | 'get' => $get, |
| 377 | 377 | 'post_type' => 'post', |
| 378 | 378 | 'post_status' => $post_status, |
| 379 | - 'post__not_in' => array( $item_id ), |
|
| 380 | - 'related_to__in' => wl_core_get_related_entity_ids( $post->ID ), |
|
| 379 | + 'post__not_in' => array($item_id), |
|
| 380 | + 'related_to__in' => wl_core_get_related_entity_ids($post->ID), |
|
| 381 | 381 | 'as' => 'subject', |
| 382 | 382 | 'with_predicate' => $predicate, |
| 383 | - ) ) |
|
| 383 | + )) |
|
| 384 | 384 | ) { |
| 385 | 385 | return $results; |
| 386 | 386 | } |
@@ -415,7 +415,7 @@ discard block |
||
| 415 | 415 | * |
| 416 | 416 | * @return string | false String representing a sql statement, or false in case of error |
| 417 | 417 | */ |
| 418 | -function wl_core_sql_query_builder( $args ) { |
|
| 418 | +function wl_core_sql_query_builder($args) { |
|
| 419 | 419 | |
| 420 | 420 | // Prepare interaction with db |
| 421 | 421 | global $wpdb; |
@@ -425,7 +425,7 @@ discard block |
||
| 425 | 425 | // Sql Action |
| 426 | 426 | $sql = "SELECT "; |
| 427 | 427 | // Determine what has to be returned depending on 'get' argument value |
| 428 | - switch ( $args['get'] ) { |
|
| 428 | + switch ($args['get']) { |
|
| 429 | 429 | case 'posts': |
| 430 | 430 | $sql .= "p.*"; |
| 431 | 431 | break; |
@@ -435,16 +435,16 @@ discard block |
||
| 435 | 435 | } |
| 436 | 436 | |
| 437 | 437 | // If we look for posts related as objects the JOIN has to be done with the object_id column and viceversa |
| 438 | - $join_column = $args['as'] . "_id"; |
|
| 438 | + $join_column = $args['as']."_id"; |
|
| 439 | 439 | |
| 440 | 440 | $sql .= " FROM $wpdb->posts as p JOIN $table_name as r ON p.id = r.$join_column"; |
| 441 | 441 | |
| 442 | 442 | // Sql add post type filter |
| 443 | - $sql .= $wpdb->prepare( " AND p.post_type = %s AND", $args['post_type'] ); |
|
| 443 | + $sql .= $wpdb->prepare(" AND p.post_type = %s AND", $args['post_type']); |
|
| 444 | 444 | |
| 445 | 445 | // Sql add post status filter |
| 446 | - if ( isset( $args['post_status'] ) && ! is_null( $args['post_status'] ) ) { |
|
| 447 | - $sql .= $wpdb->prepare( " p.post_status = %s AND", $args['post_status'] ); |
|
| 446 | + if (isset($args['post_status']) && ! is_null($args['post_status'])) { |
|
| 447 | + $sql .= $wpdb->prepare(" p.post_status = %s AND", $args['post_status']); |
|
| 448 | 448 | } |
| 449 | 449 | |
| 450 | 450 | // Add filtering conditions |
@@ -453,36 +453,36 @@ discard block |
||
| 453 | 453 | // If we look for posts related as subject this means that |
| 454 | 454 | // related_to is reference for an object: object_id is the filtering column |
| 455 | 455 | |
| 456 | - $filtering_column = ( 'object' == $args['as'] ) ? "subject_id" : "object_id"; |
|
| 456 | + $filtering_column = ('object' == $args['as']) ? "subject_id" : "object_id"; |
|
| 457 | 457 | |
| 458 | - if ( isset( $args['related_to'] ) ) { |
|
| 459 | - $sql .= $wpdb->prepare( " r.$filtering_column = %d", $args['related_to'] ); |
|
| 458 | + if (isset($args['related_to'])) { |
|
| 459 | + $sql .= $wpdb->prepare(" r.$filtering_column = %d", $args['related_to']); |
|
| 460 | 460 | } |
| 461 | - if ( isset( $args['related_to'] ) && isset( $args['related_to__in'] ) ) { |
|
| 461 | + if (isset($args['related_to']) && isset($args['related_to__in'])) { |
|
| 462 | 462 | $sql .= " AND"; |
| 463 | 463 | } |
| 464 | - if ( isset( $args['related_to__in'] ) ) { |
|
| 465 | - $sql .= " r.$filtering_column IN (" . implode( ",", $args['related_to__in'] ) . ")"; |
|
| 464 | + if (isset($args['related_to__in'])) { |
|
| 465 | + $sql .= " r.$filtering_column IN (".implode(",", $args['related_to__in']).")"; |
|
| 466 | 466 | } |
| 467 | - if ( isset( $args['post__not_in'] ) ) { |
|
| 468 | - $sql .= " AND r." . $args['as'] . "_id NOT IN (" . implode( ",", $args['post__not_in'] ) . ")"; |
|
| 467 | + if (isset($args['post__not_in'])) { |
|
| 468 | + $sql .= " AND r.".$args['as']."_id NOT IN (".implode(",", $args['post__not_in']).")"; |
|
| 469 | 469 | } |
| 470 | - if ( isset( $args['post__in'] ) ) { |
|
| 471 | - $sql .= " AND r." . $args['as'] . "_id IN (" . implode( ",", $args['post__in'] ) . ")"; |
|
| 470 | + if (isset($args['post__in'])) { |
|
| 471 | + $sql .= " AND r.".$args['as']."_id IN (".implode(",", $args['post__in']).")"; |
|
| 472 | 472 | } |
| 473 | 473 | // Add predicate filter if required |
| 474 | - if ( isset( $args['with_predicate'] ) ) { |
|
| 474 | + if (isset($args['with_predicate'])) { |
|
| 475 | 475 | // Sql Inner Join clausole |
| 476 | - $sql .= $wpdb->prepare( " AND r.predicate = %s", $args['with_predicate'] ); |
|
| 476 | + $sql .= $wpdb->prepare(" AND r.predicate = %s", $args['with_predicate']); |
|
| 477 | 477 | } |
| 478 | 478 | // Add a group by clause to avoid duplicated rows |
| 479 | 479 | // @todo: isn't a distinct a better choice? |
| 480 | 480 | $sql .= " GROUP BY p.id"; |
| 481 | 481 | |
| 482 | 482 | // @todo: how does `first` represent the limit? |
| 483 | - if ( isset( $args['first'] ) && is_numeric( $args['first'] ) ) { |
|
| 483 | + if (isset($args['first']) && is_numeric($args['first'])) { |
|
| 484 | 484 | // Sql Inner Join clause. |
| 485 | - $sql .= $wpdb->prepare( " LIMIT %d", $args['first'] ); |
|
| 485 | + $sql .= $wpdb->prepare(" LIMIT %d", $args['first']); |
|
| 486 | 486 | } |
| 487 | 487 | // Close sql statement |
| 488 | 488 | $sql .= ";"; |
@@ -501,23 +501,23 @@ discard block |
||
| 501 | 501 | * |
| 502 | 502 | * @return array|false List of WP_Post objects or list of WP_Post ids. False in case of error or invalid params |
| 503 | 503 | */ |
| 504 | -function wl_core_get_posts( $args, $returned_type = OBJECT ) { |
|
| 504 | +function wl_core_get_posts($args, $returned_type = OBJECT) { |
|
| 505 | 505 | |
| 506 | 506 | // Merge given args with defaults args value |
| 507 | - $args = array_merge( array( |
|
| 507 | + $args = array_merge(array( |
|
| 508 | 508 | 'with_predicate' => null, |
| 509 | 509 | 'as' => 'subject', |
| 510 | 510 | 'post_type' => 'post', |
| 511 | 511 | 'get' => 'posts', |
| 512 | 512 | 'post_status' => null, |
| 513 | - ), $args ); |
|
| 513 | + ), $args); |
|
| 514 | 514 | |
| 515 | 515 | // Arguments validation rules |
| 516 | 516 | // At least one between related_to and related_to__in has to be set |
| 517 | - if ( ! isset( $args['related_to'] ) && ! isset( $args['related_to__in'] ) ) { |
|
| 517 | + if ( ! isset($args['related_to']) && ! isset($args['related_to__in'])) { |
|
| 518 | 518 | return false; |
| 519 | 519 | } |
| 520 | - if ( isset( $args['related_to'] ) && ! is_numeric( $args['related_to'] ) ) { |
|
| 520 | + if (isset($args['related_to']) && ! is_numeric($args['related_to'])) { |
|
| 521 | 521 | return false; |
| 522 | 522 | } |
| 523 | 523 | |
@@ -531,18 +531,18 @@ discard block |
||
| 531 | 531 | 'related_to__in', |
| 532 | 532 | ) as $option_name |
| 533 | 533 | ) { |
| 534 | - if ( isset( $args[ $option_name ] ) ) { |
|
| 535 | - if ( ! is_array( $args[ $option_name ] ) || 0 == count( array_filter( $args[ $option_name ], "is_numeric" ) ) ) { |
|
| 534 | + if (isset($args[$option_name])) { |
|
| 535 | + if ( ! is_array($args[$option_name]) || 0 == count(array_filter($args[$option_name], "is_numeric"))) { |
|
| 536 | 536 | return false; |
| 537 | 537 | } |
| 538 | 538 | // Sanitize value removing non numeric values from the array |
| 539 | - $args[ $option_name ] = array_filter( $args[ $option_name ], "is_numeric" ); |
|
| 539 | + $args[$option_name] = array_filter($args[$option_name], "is_numeric"); |
|
| 540 | 540 | } |
| 541 | 541 | } |
| 542 | 542 | // Performing validation rules |
| 543 | - foreach ( wl_core_get_validation_rules() as $option_name => $accepeted_values ) { |
|
| 544 | - if ( isset( $args[ $option_name ] ) && ! is_null( $args[ $option_name ] ) ) { |
|
| 545 | - if ( ! in_array( $args[ $option_name ], $accepeted_values ) ) { |
|
| 543 | + foreach (wl_core_get_validation_rules() as $option_name => $accepeted_values) { |
|
| 544 | + if (isset($args[$option_name]) && ! is_null($args[$option_name])) { |
|
| 545 | + if ( ! in_array($args[$option_name], $accepeted_values)) { |
|
| 546 | 546 | return false; |
| 547 | 547 | } |
| 548 | 548 | } |
@@ -552,21 +552,21 @@ discard block |
||
| 552 | 552 | global $wpdb; |
| 553 | 553 | |
| 554 | 554 | // Build sql statement with given arguments |
| 555 | - $sql_statement = wl_core_sql_query_builder( $args ); |
|
| 555 | + $sql_statement = wl_core_sql_query_builder($args); |
|
| 556 | 556 | |
| 557 | 557 | // wl_write_log( "Going to execute sql statement: $sql_statement " ); |
| 558 | 558 | // $results = array(); |
| 559 | 559 | |
| 560 | 560 | // If ids are required, returns a one-dimensional array containing ids. |
| 561 | 561 | // Otherwise an array of associative arrays representing the post | relation object |
| 562 | - if ( 'post_ids' == $args['get'] ) { |
|
| 562 | + if ('post_ids' == $args['get']) { |
|
| 563 | 563 | # See https://codex.wordpress.org/Class_Reference/wpdb#SELECT_a_Column |
| 564 | - $results = $wpdb->get_col( $sql_statement ); |
|
| 564 | + $results = $wpdb->get_col($sql_statement); |
|
| 565 | 565 | } else { |
| 566 | - $results = $wpdb->get_results( $sql_statement, $returned_type ); |
|
| 566 | + $results = $wpdb->get_results($sql_statement, $returned_type); |
|
| 567 | 567 | } |
| 568 | 568 | // If there were an error performing the query then false is returned |
| 569 | - if ( ! empty( $wpdb->last_error ) ) { |
|
| 569 | + if ( ! empty($wpdb->last_error)) { |
|
| 570 | 570 | return false; |
| 571 | 571 | } |
| 572 | 572 | |
@@ -10,10 +10,10 @@ discard block |
||
| 10 | 10 | */ |
| 11 | 11 | function wl_configuration_set( $settings, $key, $value ) { |
| 12 | 12 | |
| 13 | - $options = get_option( $settings ); |
|
| 14 | - $options = isset( $options ) ? $options : array(); |
|
| 15 | - $options[ $key ] = $value; |
|
| 16 | - update_option( $settings, $options ); |
|
| 13 | + $options = get_option( $settings ); |
|
| 14 | + $options = isset( $options ) ? $options : array(); |
|
| 15 | + $options[ $key ] = $value; |
|
| 16 | + update_option( $settings, $options ); |
|
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | */ |
| 29 | 29 | function wl_configuration_get_key() { |
| 30 | 30 | |
| 31 | - return Wordlift_Configuration_Service::get_instance()->get_key(); |
|
| 31 | + return Wordlift_Configuration_Service::get_instance()->get_key(); |
|
| 32 | 32 | |
| 33 | 33 | // $options = get_option( 'wl_general_settings' ); |
| 34 | 34 | // |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | */ |
| 51 | 51 | function wl_configuration_set_key( $value ) { |
| 52 | 52 | |
| 53 | - Wordlift_Configuration_Service::get_instance()->set_key( $value ); |
|
| 53 | + Wordlift_Configuration_Service::get_instance()->set_key( $value ); |
|
| 54 | 54 | |
| 55 | 55 | // wl_configuration_set( 'wl_general_settings', 'key', $value ); |
| 56 | 56 | |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | */ |
| 68 | 68 | function wl_configuration_get_site_language() { |
| 69 | 69 | |
| 70 | - return Wordlift_Configuration_Service::get_instance()->get_language_code(); |
|
| 70 | + return Wordlift_Configuration_Service::get_instance()->get_language_code(); |
|
| 71 | 71 | |
| 72 | 72 | // $options = get_option( 'wl_general_settings' ); |
| 73 | 73 | // |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | */ |
| 86 | 86 | function wl_configuration_set_site_language( $value ) { |
| 87 | 87 | |
| 88 | - Wordlift_Configuration_Service::get_instance()->set_language_code( $value ); |
|
| 88 | + Wordlift_Configuration_Service::get_instance()->set_language_code( $value ); |
|
| 89 | 89 | |
| 90 | 90 | // wl_configuration_set( 'wl_general_settings', 'site_language', $value ); |
| 91 | 91 | } |
@@ -99,9 +99,9 @@ discard block |
||
| 99 | 99 | */ |
| 100 | 100 | function wl_configuration_get_api_url() { |
| 101 | 101 | |
| 102 | - $options = get_option( 'wl_advanced_settings', '' ); |
|
| 102 | + $options = get_option( 'wl_advanced_settings', '' ); |
|
| 103 | 103 | |
| 104 | - return ( empty( $options['api_url'] ) ? '' : $options['api_url'] ); |
|
| 104 | + return ( empty( $options['api_url'] ) ? '' : $options['api_url'] ); |
|
| 105 | 105 | |
| 106 | 106 | } |
| 107 | 107 | |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | */ |
| 117 | 117 | function wl_configuration_set_api_url( $value ) { |
| 118 | 118 | |
| 119 | - wl_configuration_set( 'wl_advanced_settings', 'api_url', $value ); |
|
| 119 | + wl_configuration_set( 'wl_advanced_settings', 'api_url', $value ); |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | /** |
@@ -128,9 +128,9 @@ discard block |
||
| 128 | 128 | */ |
| 129 | 129 | function wl_configuration_get_redlink_key() { |
| 130 | 130 | |
| 131 | - $options = get_option( 'wl_advanced_settings', '' ); |
|
| 131 | + $options = get_option( 'wl_advanced_settings', '' ); |
|
| 132 | 132 | |
| 133 | - return ( empty( $options['redlink_key'] ) ? '' : $options['redlink_key'] ); |
|
| 133 | + return ( empty( $options['redlink_key'] ) ? '' : $options['redlink_key'] ); |
|
| 134 | 134 | |
| 135 | 135 | } |
| 136 | 136 | |
@@ -145,7 +145,7 @@ discard block |
||
| 145 | 145 | */ |
| 146 | 146 | function wl_configuration_set_redlink_key( $value ) { |
| 147 | 147 | |
| 148 | - wl_configuration_set( 'wl_advanced_settings', 'redlink_key', $value ); |
|
| 148 | + wl_configuration_set( 'wl_advanced_settings', 'redlink_key', $value ); |
|
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | /** |
@@ -157,9 +157,9 @@ discard block |
||
| 157 | 157 | */ |
| 158 | 158 | function wl_configuration_get_redlink_user_id() { |
| 159 | 159 | |
| 160 | - $options = get_option( 'wl_advanced_settings', '' ); |
|
| 160 | + $options = get_option( 'wl_advanced_settings', '' ); |
|
| 161 | 161 | |
| 162 | - return ( empty( $options['redlink_user_id'] ) ? '' : $options['redlink_user_id'] ); |
|
| 162 | + return ( empty( $options['redlink_user_id'] ) ? '' : $options['redlink_user_id'] ); |
|
| 163 | 163 | |
| 164 | 164 | } |
| 165 | 165 | |
@@ -174,7 +174,7 @@ discard block |
||
| 174 | 174 | */ |
| 175 | 175 | function wl_configuration_set_redlink_user_id( $value ) { |
| 176 | 176 | |
| 177 | - wl_configuration_set( 'wl_advanced_settings', 'redlink_user_id', $value ); |
|
| 177 | + wl_configuration_set( 'wl_advanced_settings', 'redlink_user_id', $value ); |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | /** |
@@ -186,9 +186,9 @@ discard block |
||
| 186 | 186 | */ |
| 187 | 187 | function wl_configuration_get_redlink_dataset_name() { |
| 188 | 188 | |
| 189 | - $options = get_option( 'wl_advanced_settings', '' ); |
|
| 189 | + $options = get_option( 'wl_advanced_settings', '' ); |
|
| 190 | 190 | |
| 191 | - return ( empty( $options['redlink_dataset_name'] ) ? '' : $options['redlink_dataset_name'] ); |
|
| 191 | + return ( empty( $options['redlink_dataset_name'] ) ? '' : $options['redlink_dataset_name'] ); |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | |
@@ -203,7 +203,7 @@ discard block |
||
| 203 | 203 | */ |
| 204 | 204 | function wl_configuration_set_redlink_dataset_name( $value ) { |
| 205 | 205 | |
| 206 | - wl_configuration_set( 'wl_advanced_settings', 'redlink_dataset_name', $value ); |
|
| 206 | + wl_configuration_set( 'wl_advanced_settings', 'redlink_dataset_name', $value ); |
|
| 207 | 207 | } |
| 208 | 208 | |
| 209 | 209 | /** |
@@ -218,7 +218,7 @@ discard block |
||
| 218 | 218 | */ |
| 219 | 219 | function wl_configuration_get_redlink_dataset_uri() { |
| 220 | 220 | |
| 221 | - return Wordlift_Configuration_Service::get_instance()->get_dataset_uri(); |
|
| 221 | + return Wordlift_Configuration_Service::get_instance()->get_dataset_uri(); |
|
| 222 | 222 | } |
| 223 | 223 | |
| 224 | 224 | /** |
@@ -233,7 +233,7 @@ discard block |
||
| 233 | 233 | */ |
| 234 | 234 | function wl_configuration_set_redlink_dataset_uri( $value ) { |
| 235 | 235 | |
| 236 | - Wordlift_Configuration_Service::get_instance()->set_dataset_uri( $value ); |
|
| 236 | + Wordlift_Configuration_Service::get_instance()->set_dataset_uri( $value ); |
|
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | /** |
@@ -245,9 +245,9 @@ discard block |
||
| 245 | 245 | */ |
| 246 | 246 | function wl_configuration_get_redlink_application_name() { |
| 247 | 247 | |
| 248 | - $options = get_option( 'wl_advanced_settings', '' ); |
|
| 248 | + $options = get_option( 'wl_advanced_settings', '' ); |
|
| 249 | 249 | |
| 250 | - return ( empty( $options['redlink_application_name'] ) ? '' : $options['redlink_application_name'] ); |
|
| 250 | + return ( empty( $options['redlink_application_name'] ) ? '' : $options['redlink_application_name'] ); |
|
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | |
@@ -260,7 +260,7 @@ discard block |
||
| 260 | 260 | */ |
| 261 | 261 | function wl_configuration_set_redlink_application_name( $value ) { |
| 262 | 262 | |
| 263 | - wl_configuration_set( 'wl_advanced_settings', 'redlink_application_name', $value ); |
|
| 263 | + wl_configuration_set( 'wl_advanced_settings', 'redlink_application_name', $value ); |
|
| 264 | 264 | } |
| 265 | 265 | |
| 266 | 266 | /** |
@@ -277,18 +277,18 @@ discard block |
||
| 277 | 277 | */ |
| 278 | 278 | function wl_configuration_get_analyzer_url() { |
| 279 | 279 | |
| 280 | - // If the WordLift Key is set, we use WordLift. |
|
| 281 | - $key = wl_configuration_get_key(); |
|
| 282 | - if ( ! empty( $key ) ) { |
|
| 283 | - return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . "analyses?key=$key" |
|
| 284 | - . ( defined( 'WL_EXCLUDE_IMAGES_REGEX' ) ? '&exclimage=' . urlencode( WL_EXCLUDE_IMAGES_REGEX ) : '' ); |
|
| 285 | - } |
|
| 280 | + // If the WordLift Key is set, we use WordLift. |
|
| 281 | + $key = wl_configuration_get_key(); |
|
| 282 | + if ( ! empty( $key ) ) { |
|
| 283 | + return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . "analyses?key=$key" |
|
| 284 | + . ( defined( 'WL_EXCLUDE_IMAGES_REGEX' ) ? '&exclimage=' . urlencode( WL_EXCLUDE_IMAGES_REGEX ) : '' ); |
|
| 285 | + } |
|
| 286 | 286 | |
| 287 | - // Otherwise use Redlink. |
|
| 288 | - $app_key = wl_configuration_get_redlink_key(); |
|
| 289 | - $analysis_name = wl_configuration_get_redlink_application_name(); |
|
| 287 | + // Otherwise use Redlink. |
|
| 288 | + $app_key = wl_configuration_get_redlink_key(); |
|
| 289 | + $analysis_name = wl_configuration_get_redlink_application_name(); |
|
| 290 | 290 | |
| 291 | - $ldpath = <<<EOF |
|
| 291 | + $ldpath = <<<EOF |
|
| 292 | 292 | @prefix ex: <http://example.org/>; |
| 293 | 293 | @prefix cal: <http://www.w3.org/2002/12/cal#>; |
| 294 | 294 | @prefix gn: <http://www.geonames.org/ontology#>; |
@@ -297,8 +297,8 @@ discard block |
||
| 297 | 297 | vcard:locality = lode:atPlace/gn:name :: xsd:string; |
| 298 | 298 | EOF; |
| 299 | 299 | |
| 300 | - return wl_configuration_get_api_url() . "/analysis/$analysis_name/enhance?key=$app_key" . |
|
| 301 | - '&enhancer.engines.dereference.ldpath=' . urlencode( $ldpath ); |
|
| 300 | + return wl_configuration_get_api_url() . "/analysis/$analysis_name/enhance?key=$app_key" . |
|
| 301 | + '&enhancer.engines.dereference.ldpath=' . urlencode( $ldpath ); |
|
| 302 | 302 | |
| 303 | 303 | } |
| 304 | 304 | |
@@ -316,9 +316,9 @@ discard block |
||
| 316 | 316 | */ |
| 317 | 317 | function wl_configuration_get_accounts_by_key_dataset_uri( $key ) { |
| 318 | 318 | |
| 319 | - return Wordlift_Configuration_Service::get_instance()->get_accounts_by_key_dataset_uri( $key ); |
|
| 319 | + return Wordlift_Configuration_Service::get_instance()->get_accounts_by_key_dataset_uri( $key ); |
|
| 320 | 320 | |
| 321 | - //return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . "accounts/key=$key/dataset_uri"; |
|
| 321 | + //return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . "accounts/key=$key/dataset_uri"; |
|
| 322 | 322 | } |
| 323 | 323 | |
| 324 | 324 | |
@@ -334,19 +334,19 @@ discard block |
||
| 334 | 334 | */ |
| 335 | 335 | function wl_configuration_get_query_select_url( $output, $dataset = null ) { |
| 336 | 336 | |
| 337 | - // If the WordLift Key is set, we use WordLift. |
|
| 338 | - $key = wl_configuration_get_key(); |
|
| 339 | - if ( ! empty( $key ) ) { |
|
| 340 | - // TODO: handle the output format for WordLift. |
|
| 341 | - return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . "datasets/key=$key/queries?q="; |
|
| 342 | - } |
|
| 337 | + // If the WordLift Key is set, we use WordLift. |
|
| 338 | + $key = wl_configuration_get_key(); |
|
| 339 | + if ( ! empty( $key ) ) { |
|
| 340 | + // TODO: handle the output format for WordLift. |
|
| 341 | + return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . "datasets/key=$key/queries?q="; |
|
| 342 | + } |
|
| 343 | 343 | |
| 344 | - // If no dataset has been specified then use the default configured, otherwise use the one provided. |
|
| 345 | - $redlink_dataset = ( empty( $dataset ) ? wl_configuration_get_redlink_dataset_name() : $dataset ); |
|
| 346 | - $redlink_key = wl_configuration_get_redlink_key(); |
|
| 344 | + // If no dataset has been specified then use the default configured, otherwise use the one provided. |
|
| 345 | + $redlink_dataset = ( empty( $dataset ) ? wl_configuration_get_redlink_dataset_name() : $dataset ); |
|
| 346 | + $redlink_key = wl_configuration_get_redlink_key(); |
|
| 347 | 347 | |
| 348 | - // construct the API URL. |
|
| 349 | - return wl_configuration_get_api_url() . "/data/$redlink_dataset/sparql/select?key=$redlink_key&out=$output&query="; |
|
| 348 | + // construct the API URL. |
|
| 349 | + return wl_configuration_get_api_url() . "/data/$redlink_dataset/sparql/select?key=$redlink_key&out=$output&query="; |
|
| 350 | 350 | |
| 351 | 351 | } |
| 352 | 352 | |
@@ -359,18 +359,18 @@ discard block |
||
| 359 | 359 | */ |
| 360 | 360 | function wl_configuration_get_query_update_url() { |
| 361 | 361 | |
| 362 | - // If the WordLift Key is set, we use WordLift. |
|
| 363 | - $key = wl_configuration_get_key(); |
|
| 364 | - if ( ! empty( $key ) ) { |
|
| 365 | - return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . "datasets/key=$key/queries"; |
|
| 366 | - } |
|
| 362 | + // If the WordLift Key is set, we use WordLift. |
|
| 363 | + $key = wl_configuration_get_key(); |
|
| 364 | + if ( ! empty( $key ) ) { |
|
| 365 | + return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . "datasets/key=$key/queries"; |
|
| 366 | + } |
|
| 367 | 367 | |
| 368 | - // get the configuration. |
|
| 369 | - $redlink_dataset = wl_configuration_get_redlink_dataset_name(); |
|
| 370 | - $redlink_key = wl_configuration_get_redlink_key(); |
|
| 368 | + // get the configuration. |
|
| 369 | + $redlink_dataset = wl_configuration_get_redlink_dataset_name(); |
|
| 370 | + $redlink_key = wl_configuration_get_redlink_key(); |
|
| 371 | 371 | |
| 372 | - // construct the API URL. |
|
| 373 | - return wl_configuration_get_api_url() . "/data/$redlink_dataset/sparql/update?key=$redlink_key"; |
|
| 372 | + // construct the API URL. |
|
| 373 | + return wl_configuration_get_api_url() . "/data/$redlink_dataset/sparql/update?key=$redlink_key"; |
|
| 374 | 374 | |
| 375 | 375 | } |
| 376 | 376 | |
@@ -384,17 +384,17 @@ discard block |
||
| 384 | 384 | */ |
| 385 | 385 | function wl_configuration_get_dataset_index_url() { |
| 386 | 386 | |
| 387 | - // If the WordLift Key is set, we use WordLift. |
|
| 388 | - $key = wl_configuration_get_key(); |
|
| 389 | - if ( ! empty( $key ) ) { |
|
| 390 | - return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . "datasets/key=$key/index"; |
|
| 391 | - } |
|
| 387 | + // If the WordLift Key is set, we use WordLift. |
|
| 388 | + $key = wl_configuration_get_key(); |
|
| 389 | + if ( ! empty( $key ) ) { |
|
| 390 | + return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . "datasets/key=$key/index"; |
|
| 391 | + } |
|
| 392 | 392 | |
| 393 | - // get the configuration. |
|
| 394 | - $redlink_dataset = wl_configuration_get_redlink_dataset_name(); |
|
| 395 | - $redlink_key = wl_configuration_get_redlink_key(); |
|
| 393 | + // get the configuration. |
|
| 394 | + $redlink_dataset = wl_configuration_get_redlink_dataset_name(); |
|
| 395 | + $redlink_key = wl_configuration_get_redlink_key(); |
|
| 396 | 396 | |
| 397 | - // construct the API URL. |
|
| 398 | - return wl_configuration_get_api_url() . "/data/$redlink_dataset/release?key=$redlink_key"; |
|
| 397 | + // construct the API URL. |
|
| 398 | + return wl_configuration_get_api_url() . "/data/$redlink_dataset/release?key=$redlink_key"; |
|
| 399 | 399 | |
| 400 | 400 | } |
| 401 | 401 | \ No newline at end of file |
@@ -8,12 +8,12 @@ discard block |
||
| 8 | 8 | * @param string $key The setting name. |
| 9 | 9 | * @param string $value The setting value. |
| 10 | 10 | */ |
| 11 | -function wl_configuration_set( $settings, $key, $value ) { |
|
| 11 | +function wl_configuration_set($settings, $key, $value) { |
|
| 12 | 12 | |
| 13 | - $options = get_option( $settings ); |
|
| 14 | - $options = isset( $options ) ? $options : array(); |
|
| 15 | - $options[ $key ] = $value; |
|
| 16 | - update_option( $settings, $options ); |
|
| 13 | + $options = get_option($settings); |
|
| 14 | + $options = isset($options) ? $options : array(); |
|
| 15 | + $options[$key] = $value; |
|
| 16 | + update_option($settings, $options); |
|
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | |
@@ -48,9 +48,9 @@ discard block |
||
| 48 | 48 | * |
| 49 | 49 | * @param string $value The WordLift key. |
| 50 | 50 | */ |
| 51 | -function wl_configuration_set_key( $value ) { |
|
| 51 | +function wl_configuration_set_key($value) { |
|
| 52 | 52 | |
| 53 | - Wordlift_Configuration_Service::get_instance()->set_key( $value ); |
|
| 53 | + Wordlift_Configuration_Service::get_instance()->set_key($value); |
|
| 54 | 54 | |
| 55 | 55 | // wl_configuration_set( 'wl_general_settings', 'key', $value ); |
| 56 | 56 | |
@@ -83,9 +83,9 @@ discard block |
||
| 83 | 83 | * |
| 84 | 84 | * @param string $value The two-letter language code. |
| 85 | 85 | */ |
| 86 | -function wl_configuration_set_site_language( $value ) { |
|
| 86 | +function wl_configuration_set_site_language($value) { |
|
| 87 | 87 | |
| 88 | - Wordlift_Configuration_Service::get_instance()->set_language_code( $value ); |
|
| 88 | + Wordlift_Configuration_Service::get_instance()->set_language_code($value); |
|
| 89 | 89 | |
| 90 | 90 | // wl_configuration_set( 'wl_general_settings', 'site_language', $value ); |
| 91 | 91 | } |
@@ -99,9 +99,9 @@ discard block |
||
| 99 | 99 | */ |
| 100 | 100 | function wl_configuration_get_api_url() { |
| 101 | 101 | |
| 102 | - $options = get_option( 'wl_advanced_settings', '' ); |
|
| 102 | + $options = get_option('wl_advanced_settings', ''); |
|
| 103 | 103 | |
| 104 | - return ( empty( $options['api_url'] ) ? '' : $options['api_url'] ); |
|
| 104 | + return (empty($options['api_url']) ? '' : $options['api_url']); |
|
| 105 | 105 | |
| 106 | 106 | } |
| 107 | 107 | |
@@ -114,9 +114,9 @@ discard block |
||
| 114 | 114 | * |
| 115 | 115 | * @param string $value The API URL. |
| 116 | 116 | */ |
| 117 | -function wl_configuration_set_api_url( $value ) { |
|
| 117 | +function wl_configuration_set_api_url($value) { |
|
| 118 | 118 | |
| 119 | - wl_configuration_set( 'wl_advanced_settings', 'api_url', $value ); |
|
| 119 | + wl_configuration_set('wl_advanced_settings', 'api_url', $value); |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | /** |
@@ -128,9 +128,9 @@ discard block |
||
| 128 | 128 | */ |
| 129 | 129 | function wl_configuration_get_redlink_key() { |
| 130 | 130 | |
| 131 | - $options = get_option( 'wl_advanced_settings', '' ); |
|
| 131 | + $options = get_option('wl_advanced_settings', ''); |
|
| 132 | 132 | |
| 133 | - return ( empty( $options['redlink_key'] ) ? '' : $options['redlink_key'] ); |
|
| 133 | + return (empty($options['redlink_key']) ? '' : $options['redlink_key']); |
|
| 134 | 134 | |
| 135 | 135 | } |
| 136 | 136 | |
@@ -143,9 +143,9 @@ discard block |
||
| 143 | 143 | * |
| 144 | 144 | * @param string $value The Redlink application key. |
| 145 | 145 | */ |
| 146 | -function wl_configuration_set_redlink_key( $value ) { |
|
| 146 | +function wl_configuration_set_redlink_key($value) { |
|
| 147 | 147 | |
| 148 | - wl_configuration_set( 'wl_advanced_settings', 'redlink_key', $value ); |
|
| 148 | + wl_configuration_set('wl_advanced_settings', 'redlink_key', $value); |
|
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | /** |
@@ -157,9 +157,9 @@ discard block |
||
| 157 | 157 | */ |
| 158 | 158 | function wl_configuration_get_redlink_user_id() { |
| 159 | 159 | |
| 160 | - $options = get_option( 'wl_advanced_settings', '' ); |
|
| 160 | + $options = get_option('wl_advanced_settings', ''); |
|
| 161 | 161 | |
| 162 | - return ( empty( $options['redlink_user_id'] ) ? '' : $options['redlink_user_id'] ); |
|
| 162 | + return (empty($options['redlink_user_id']) ? '' : $options['redlink_user_id']); |
|
| 163 | 163 | |
| 164 | 164 | } |
| 165 | 165 | |
@@ -172,9 +172,9 @@ discard block |
||
| 172 | 172 | * |
| 173 | 173 | * @param string $value The Redlink user id. |
| 174 | 174 | */ |
| 175 | -function wl_configuration_set_redlink_user_id( $value ) { |
|
| 175 | +function wl_configuration_set_redlink_user_id($value) { |
|
| 176 | 176 | |
| 177 | - wl_configuration_set( 'wl_advanced_settings', 'redlink_user_id', $value ); |
|
| 177 | + wl_configuration_set('wl_advanced_settings', 'redlink_user_id', $value); |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | /** |
@@ -186,9 +186,9 @@ discard block |
||
| 186 | 186 | */ |
| 187 | 187 | function wl_configuration_get_redlink_dataset_name() { |
| 188 | 188 | |
| 189 | - $options = get_option( 'wl_advanced_settings', '' ); |
|
| 189 | + $options = get_option('wl_advanced_settings', ''); |
|
| 190 | 190 | |
| 191 | - return ( empty( $options['redlink_dataset_name'] ) ? '' : $options['redlink_dataset_name'] ); |
|
| 191 | + return (empty($options['redlink_dataset_name']) ? '' : $options['redlink_dataset_name']); |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | |
@@ -201,9 +201,9 @@ discard block |
||
| 201 | 201 | * |
| 202 | 202 | * @param string $value The Redlink dataset name. |
| 203 | 203 | */ |
| 204 | -function wl_configuration_set_redlink_dataset_name( $value ) { |
|
| 204 | +function wl_configuration_set_redlink_dataset_name($value) { |
|
| 205 | 205 | |
| 206 | - wl_configuration_set( 'wl_advanced_settings', 'redlink_dataset_name', $value ); |
|
| 206 | + wl_configuration_set('wl_advanced_settings', 'redlink_dataset_name', $value); |
|
| 207 | 207 | } |
| 208 | 208 | |
| 209 | 209 | /** |
@@ -231,9 +231,9 @@ discard block |
||
| 231 | 231 | * |
| 232 | 232 | * @param string $value The Redlink dataset URI. |
| 233 | 233 | */ |
| 234 | -function wl_configuration_set_redlink_dataset_uri( $value ) { |
|
| 234 | +function wl_configuration_set_redlink_dataset_uri($value) { |
|
| 235 | 235 | |
| 236 | - Wordlift_Configuration_Service::get_instance()->set_dataset_uri( $value ); |
|
| 236 | + Wordlift_Configuration_Service::get_instance()->set_dataset_uri($value); |
|
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | /** |
@@ -245,9 +245,9 @@ discard block |
||
| 245 | 245 | */ |
| 246 | 246 | function wl_configuration_get_redlink_application_name() { |
| 247 | 247 | |
| 248 | - $options = get_option( 'wl_advanced_settings', '' ); |
|
| 248 | + $options = get_option('wl_advanced_settings', ''); |
|
| 249 | 249 | |
| 250 | - return ( empty( $options['redlink_application_name'] ) ? '' : $options['redlink_application_name'] ); |
|
| 250 | + return (empty($options['redlink_application_name']) ? '' : $options['redlink_application_name']); |
|
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | |
@@ -258,9 +258,9 @@ discard block |
||
| 258 | 258 | * |
| 259 | 259 | * @param string $value The Redlink application name. |
| 260 | 260 | */ |
| 261 | -function wl_configuration_set_redlink_application_name( $value ) { |
|
| 261 | +function wl_configuration_set_redlink_application_name($value) { |
|
| 262 | 262 | |
| 263 | - wl_configuration_set( 'wl_advanced_settings', 'redlink_application_name', $value ); |
|
| 263 | + wl_configuration_set('wl_advanced_settings', 'redlink_application_name', $value); |
|
| 264 | 264 | } |
| 265 | 265 | |
| 266 | 266 | /** |
@@ -279,9 +279,9 @@ discard block |
||
| 279 | 279 | |
| 280 | 280 | // If the WordLift Key is set, we use WordLift. |
| 281 | 281 | $key = wl_configuration_get_key(); |
| 282 | - if ( ! empty( $key ) ) { |
|
| 283 | - return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . "analyses?key=$key" |
|
| 284 | - . ( defined( 'WL_EXCLUDE_IMAGES_REGEX' ) ? '&exclimage=' . urlencode( WL_EXCLUDE_IMAGES_REGEX ) : '' ); |
|
| 282 | + if ( ! empty($key)) { |
|
| 283 | + return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE."analyses?key=$key" |
|
| 284 | + . (defined('WL_EXCLUDE_IMAGES_REGEX') ? '&exclimage='.urlencode(WL_EXCLUDE_IMAGES_REGEX) : ''); |
|
| 285 | 285 | } |
| 286 | 286 | |
| 287 | 287 | // Otherwise use Redlink. |
@@ -297,8 +297,8 @@ discard block |
||
| 297 | 297 | vcard:locality = lode:atPlace/gn:name :: xsd:string; |
| 298 | 298 | EOF; |
| 299 | 299 | |
| 300 | - return wl_configuration_get_api_url() . "/analysis/$analysis_name/enhance?key=$app_key" . |
|
| 301 | - '&enhancer.engines.dereference.ldpath=' . urlencode( $ldpath ); |
|
| 300 | + return wl_configuration_get_api_url()."/analysis/$analysis_name/enhance?key=$app_key". |
|
| 301 | + '&enhancer.engines.dereference.ldpath='.urlencode($ldpath); |
|
| 302 | 302 | |
| 303 | 303 | } |
| 304 | 304 | |
@@ -314,9 +314,9 @@ discard block |
||
| 314 | 314 | * |
| 315 | 315 | * @return string The API URI. |
| 316 | 316 | */ |
| 317 | -function wl_configuration_get_accounts_by_key_dataset_uri( $key ) { |
|
| 317 | +function wl_configuration_get_accounts_by_key_dataset_uri($key) { |
|
| 318 | 318 | |
| 319 | - return Wordlift_Configuration_Service::get_instance()->get_accounts_by_key_dataset_uri( $key ); |
|
| 319 | + return Wordlift_Configuration_Service::get_instance()->get_accounts_by_key_dataset_uri($key); |
|
| 320 | 320 | |
| 321 | 321 | //return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . "accounts/key=$key/dataset_uri"; |
| 322 | 322 | } |
@@ -332,21 +332,21 @@ discard block |
||
| 332 | 332 | * |
| 333 | 333 | * @return string The URL to call to perform the SELECT query. |
| 334 | 334 | */ |
| 335 | -function wl_configuration_get_query_select_url( $output, $dataset = null ) { |
|
| 335 | +function wl_configuration_get_query_select_url($output, $dataset = null) { |
|
| 336 | 336 | |
| 337 | 337 | // If the WordLift Key is set, we use WordLift. |
| 338 | 338 | $key = wl_configuration_get_key(); |
| 339 | - if ( ! empty( $key ) ) { |
|
| 339 | + if ( ! empty($key)) { |
|
| 340 | 340 | // TODO: handle the output format for WordLift. |
| 341 | - return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . "datasets/key=$key/queries?q="; |
|
| 341 | + return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE."datasets/key=$key/queries?q="; |
|
| 342 | 342 | } |
| 343 | 343 | |
| 344 | 344 | // If no dataset has been specified then use the default configured, otherwise use the one provided. |
| 345 | - $redlink_dataset = ( empty( $dataset ) ? wl_configuration_get_redlink_dataset_name() : $dataset ); |
|
| 345 | + $redlink_dataset = (empty($dataset) ? wl_configuration_get_redlink_dataset_name() : $dataset); |
|
| 346 | 346 | $redlink_key = wl_configuration_get_redlink_key(); |
| 347 | 347 | |
| 348 | 348 | // construct the API URL. |
| 349 | - return wl_configuration_get_api_url() . "/data/$redlink_dataset/sparql/select?key=$redlink_key&out=$output&query="; |
|
| 349 | + return wl_configuration_get_api_url()."/data/$redlink_dataset/sparql/select?key=$redlink_key&out=$output&query="; |
|
| 350 | 350 | |
| 351 | 351 | } |
| 352 | 352 | |
@@ -361,8 +361,8 @@ discard block |
||
| 361 | 361 | |
| 362 | 362 | // If the WordLift Key is set, we use WordLift. |
| 363 | 363 | $key = wl_configuration_get_key(); |
| 364 | - if ( ! empty( $key ) ) { |
|
| 365 | - return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . "datasets/key=$key/queries"; |
|
| 364 | + if ( ! empty($key)) { |
|
| 365 | + return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE."datasets/key=$key/queries"; |
|
| 366 | 366 | } |
| 367 | 367 | |
| 368 | 368 | // get the configuration. |
@@ -370,7 +370,7 @@ discard block |
||
| 370 | 370 | $redlink_key = wl_configuration_get_redlink_key(); |
| 371 | 371 | |
| 372 | 372 | // construct the API URL. |
| 373 | - return wl_configuration_get_api_url() . "/data/$redlink_dataset/sparql/update?key=$redlink_key"; |
|
| 373 | + return wl_configuration_get_api_url()."/data/$redlink_dataset/sparql/update?key=$redlink_key"; |
|
| 374 | 374 | |
| 375 | 375 | } |
| 376 | 376 | |
@@ -386,8 +386,8 @@ discard block |
||
| 386 | 386 | |
| 387 | 387 | // If the WordLift Key is set, we use WordLift. |
| 388 | 388 | $key = wl_configuration_get_key(); |
| 389 | - if ( ! empty( $key ) ) { |
|
| 390 | - return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . "datasets/key=$key/index"; |
|
| 389 | + if ( ! empty($key)) { |
|
| 390 | + return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE."datasets/key=$key/index"; |
|
| 391 | 391 | } |
| 392 | 392 | |
| 393 | 393 | // get the configuration. |
@@ -395,6 +395,6 @@ discard block |
||
| 395 | 395 | $redlink_key = wl_configuration_get_redlink_key(); |
| 396 | 396 | |
| 397 | 397 | // construct the API URL. |
| 398 | - return wl_configuration_get_api_url() . "/data/$redlink_dataset/release?key=$redlink_key"; |
|
| 398 | + return wl_configuration_get_api_url()."/data/$redlink_dataset/release?key=$redlink_key"; |
|
| 399 | 399 | |
| 400 | 400 | } |
| 401 | 401 | \ No newline at end of file |
@@ -18,48 +18,48 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | class Wordlift_Admin_Language_Select_Element implements Wordlift_Admin_Element { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * @inheritdoc |
|
| 23 | - */ |
|
| 24 | - public function render( $args ) { |
|
| 21 | + /** |
|
| 22 | + * @inheritdoc |
|
| 23 | + */ |
|
| 24 | + public function render( $args ) { |
|
| 25 | 25 | |
| 26 | - // Parse the arguments and merge with default values. |
|
| 27 | - $params = wp_parse_args( $args, array( |
|
| 28 | - 'id' => uniqid( 'wl-input-' ), |
|
| 29 | - 'name' => uniqid( 'wl-input-' ), |
|
| 30 | - 'value' => '', |
|
| 31 | - 'description' => false, |
|
| 32 | - ) ); |
|
| 26 | + // Parse the arguments and merge with default values. |
|
| 27 | + $params = wp_parse_args( $args, array( |
|
| 28 | + 'id' => uniqid( 'wl-input-' ), |
|
| 29 | + 'name' => uniqid( 'wl-input-' ), |
|
| 30 | + 'value' => '', |
|
| 31 | + 'description' => false, |
|
| 32 | + ) ); |
|
| 33 | 33 | |
| 34 | - $description = $params['description'] ? '<p>' . wp_kses( $params['description'], array( 'a' => array( 'href' => array() ) ) ) . '</p>' : ''; |
|
| 34 | + $description = $params['description'] ? '<p>' . wp_kses( $params['description'], array( 'a' => array( 'href' => array() ) ) ) . '</p>' : ''; |
|
| 35 | 35 | |
| 36 | - ?> |
|
| 36 | + ?> |
|
| 37 | 37 | <select id="<?php echo esc_attr( $params['id'] ); ?>" |
| 38 | 38 | name="<?php echo esc_attr( $params['name'] ); ?>"> |
| 39 | 39 | <?php |
| 40 | - // Print all the supported language, preselecting the one configured |
|
| 41 | - // in WP (or English if not supported). We now use the `Wordlift_Languages` |
|
| 42 | - // class which provides the list of languages supported by WordLift. |
|
| 43 | - // |
|
| 44 | - // See https://github.com/insideout10/wordlift-plugin/issues/349 |
|
| 40 | + // Print all the supported language, preselecting the one configured |
|
| 41 | + // in WP (or English if not supported). We now use the `Wordlift_Languages` |
|
| 42 | + // class which provides the list of languages supported by WordLift. |
|
| 43 | + // |
|
| 44 | + // See https://github.com/insideout10/wordlift-plugin/issues/349 |
|
| 45 | 45 | |
| 46 | - // Get WordLift's supported languages. |
|
| 47 | - $languages = Wordlift_Languages::get_languages(); |
|
| 46 | + // Get WordLift's supported languages. |
|
| 47 | + $languages = Wordlift_Languages::get_languages(); |
|
| 48 | 48 | |
| 49 | - // If we support WP's configured language, then use that, otherwise use English by default. |
|
| 50 | - $language = isset( $languages[ $params['value'] ] ) ? $params['value'] : 'en'; |
|
| 49 | + // If we support WP's configured language, then use that, otherwise use English by default. |
|
| 50 | + $language = isset( $languages[ $params['value'] ] ) ? $params['value'] : 'en'; |
|
| 51 | 51 | |
| 52 | - foreach ( $languages as $code => $label ) { ?> |
|
| 52 | + foreach ( $languages as $code => $label ) { ?> |
|
| 53 | 53 | <option value="<?php echo esc_attr( $code ); ?>" |
| 54 | 54 | <?php echo selected( $code, $language, false ) ?>><?php |
| 55 | - echo esc_html( $label ) ?></option> |
|
| 55 | + echo esc_html( $label ) ?></option> |
|
| 56 | 56 | <?php } ?> |
| 57 | 57 | </select> |
| 58 | 58 | <?php echo $description; ?> |
| 59 | 59 | |
| 60 | 60 | <?php |
| 61 | 61 | |
| 62 | - return $this; |
|
| 63 | - } |
|
| 62 | + return $this; |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | 65 | } |
@@ -21,21 +21,21 @@ discard block |
||
| 21 | 21 | /** |
| 22 | 22 | * @inheritdoc |
| 23 | 23 | */ |
| 24 | - public function render( $args ) { |
|
| 24 | + public function render($args) { |
|
| 25 | 25 | |
| 26 | 26 | // Parse the arguments and merge with default values. |
| 27 | - $params = wp_parse_args( $args, array( |
|
| 28 | - 'id' => uniqid( 'wl-input-' ), |
|
| 29 | - 'name' => uniqid( 'wl-input-' ), |
|
| 27 | + $params = wp_parse_args($args, array( |
|
| 28 | + 'id' => uniqid('wl-input-'), |
|
| 29 | + 'name' => uniqid('wl-input-'), |
|
| 30 | 30 | 'value' => '', |
| 31 | 31 | 'description' => false, |
| 32 | - ) ); |
|
| 32 | + )); |
|
| 33 | 33 | |
| 34 | - $description = $params['description'] ? '<p>' . wp_kses( $params['description'], array( 'a' => array( 'href' => array() ) ) ) . '</p>' : ''; |
|
| 34 | + $description = $params['description'] ? '<p>'.wp_kses($params['description'], array('a' => array('href' => array()))).'</p>' : ''; |
|
| 35 | 35 | |
| 36 | 36 | ?> |
| 37 | - <select id="<?php echo esc_attr( $params['id'] ); ?>" |
|
| 38 | - name="<?php echo esc_attr( $params['name'] ); ?>"> |
|
| 37 | + <select id="<?php echo esc_attr($params['id']); ?>" |
|
| 38 | + name="<?php echo esc_attr($params['name']); ?>"> |
|
| 39 | 39 | <?php |
| 40 | 40 | // Print all the supported language, preselecting the one configured |
| 41 | 41 | // in WP (or English if not supported). We now use the `Wordlift_Languages` |
@@ -47,12 +47,12 @@ discard block |
||
| 47 | 47 | $languages = Wordlift_Languages::get_languages(); |
| 48 | 48 | |
| 49 | 49 | // If we support WP's configured language, then use that, otherwise use English by default. |
| 50 | - $language = isset( $languages[ $params['value'] ] ) ? $params['value'] : 'en'; |
|
| 50 | + $language = isset($languages[$params['value']]) ? $params['value'] : 'en'; |
|
| 51 | 51 | |
| 52 | - foreach ( $languages as $code => $label ) { ?> |
|
| 53 | - <option value="<?php echo esc_attr( $code ); ?>" |
|
| 54 | - <?php echo selected( $code, $language, false ) ?>><?php |
|
| 55 | - echo esc_html( $label ) ?></option> |
|
| 52 | + foreach ($languages as $code => $label) { ?> |
|
| 53 | + <option value="<?php echo esc_attr($code); ?>" |
|
| 54 | + <?php echo selected($code, $language, false) ?>><?php |
|
| 55 | + echo esc_html($label) ?></option> |
|
| 56 | 56 | <?php } ?> |
| 57 | 57 | </select> |
| 58 | 58 | <?php echo $description; ?> |
@@ -13,7 +13,7 @@ discard block |
||
| 13 | 13 | */ |
| 14 | 14 | |
| 15 | 15 | if ( ! defined( 'ABSPATH' ) ) { |
| 16 | - exit; |
|
| 16 | + exit; |
|
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | /** |
@@ -30,188 +30,188 @@ discard block |
||
| 30 | 30 | */ |
| 31 | 31 | class Wordlift_Admin_Entity_Type_Settings { |
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * Handle menu registration. |
|
| 35 | - * |
|
| 36 | - * The registration is required, although we do not want to actually to add |
|
| 37 | - * an item to the menu, in order to "whitelist" the access to the settings page in |
|
| 38 | - * the admin. |
|
| 39 | - * |
|
| 40 | - * @since 3.11.0 |
|
| 41 | - */ |
|
| 42 | - public function admin_menu() { |
|
| 43 | - |
|
| 44 | - /* |
|
| 33 | + /** |
|
| 34 | + * Handle menu registration. |
|
| 35 | + * |
|
| 36 | + * The registration is required, although we do not want to actually to add |
|
| 37 | + * an item to the menu, in order to "whitelist" the access to the settings page in |
|
| 38 | + * the admin. |
|
| 39 | + * |
|
| 40 | + * @since 3.11.0 |
|
| 41 | + */ |
|
| 42 | + public function admin_menu() { |
|
| 43 | + |
|
| 44 | + /* |
|
| 45 | 45 | * Before anything else check if an settings form was submitted. |
| 46 | 46 | * This has to be done before any output happens in order to be able to |
| 47 | 47 | * display proper "die" error messages and redirect. |
| 48 | 48 | */ |
| 49 | - if ( isset( $_GET['page'] ) && ( 'wl_entity_type_settings' === $_GET['page'] ) ) { |
|
| 49 | + if ( isset( $_GET['page'] ) && ( 'wl_entity_type_settings' === $_GET['page'] ) ) { |
|
| 50 | 50 | |
| 51 | - // Validate inputs. Do not return on invalid parameters or capabilities. |
|
| 52 | - $this->validate_proper_term(); |
|
| 51 | + // Validate inputs. Do not return on invalid parameters or capabilities. |
|
| 52 | + $this->validate_proper_term(); |
|
| 53 | 53 | |
| 54 | - // If proper form submission, handle it and redirect back to the settings page. |
|
| 55 | - if ( isset( $_POST['action'] ) && ( 'wl_edit_entity_type_term' === $_POST['action'] ) ) { |
|
| 56 | - $this->handle_form_submission(); |
|
| 57 | - } |
|
| 54 | + // If proper form submission, handle it and redirect back to the settings page. |
|
| 55 | + if ( isset( $_POST['action'] ) && ( 'wl_edit_entity_type_term' === $_POST['action'] ) ) { |
|
| 56 | + $this->handle_form_submission(); |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - // Register admin notices handler. |
|
| 60 | - add_action( 'admin_notices', array( $this, 'admin_notice' ) ); |
|
| 59 | + // Register admin notices handler. |
|
| 60 | + add_action( 'admin_notices', array( $this, 'admin_notice' ) ); |
|
| 61 | 61 | |
| 62 | - } |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - /* |
|
| 64 | + /* |
|
| 65 | 65 | * Use a null parent slug to prevent the menu from actually appearing |
| 66 | 66 | * in the admin menu. |
| 67 | 67 | */ |
| 68 | - // @todo: use the new {@link Wordlift_Admin_Page}. |
|
| 69 | - add_submenu_page( |
|
| 70 | - null, |
|
| 71 | - __( 'Edit Entity term', 'wordlift' ), |
|
| 72 | - __( 'Edit Entity term', 'wordlift' ), |
|
| 73 | - 'manage_options', |
|
| 74 | - 'wl_entity_type_settings', |
|
| 75 | - array( $this, 'render' ) |
|
| 76 | - ); |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * Output admin notices if needed, based on the message url parameter. |
|
| 81 | - * A value of 1 indicates that a successful save was done. |
|
| 82 | - * |
|
| 83 | - * @since 3.11.0 |
|
| 84 | - */ |
|
| 85 | - function admin_notice() { |
|
| 86 | - if ( isset( $_GET['message'] ) && ( '1' === $_GET['message'] ) ) { |
|
| 87 | - ?> |
|
| 68 | + // @todo: use the new {@link Wordlift_Admin_Page}. |
|
| 69 | + add_submenu_page( |
|
| 70 | + null, |
|
| 71 | + __( 'Edit Entity term', 'wordlift' ), |
|
| 72 | + __( 'Edit Entity term', 'wordlift' ), |
|
| 73 | + 'manage_options', |
|
| 74 | + 'wl_entity_type_settings', |
|
| 75 | + array( $this, 'render' ) |
|
| 76 | + ); |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * Output admin notices if needed, based on the message url parameter. |
|
| 81 | + * A value of 1 indicates that a successful save was done. |
|
| 82 | + * |
|
| 83 | + * @since 3.11.0 |
|
| 84 | + */ |
|
| 85 | + function admin_notice() { |
|
| 86 | + if ( isset( $_GET['message'] ) && ( '1' === $_GET['message'] ) ) { |
|
| 87 | + ?> |
|
| 88 | 88 | <div class="notice notice-success is-dismissible"> |
| 89 | 89 | <p><?php esc_html_e( 'Settings saved', 'wordlift' ) ?></p> |
| 90 | 90 | </div> |
| 91 | 91 | <?php |
| 92 | - } |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * Validate the existence of the entity type indicated by the tag_ID url |
|
| 97 | - * parameter before doing any processing. Done before any output to mimic |
|
| 98 | - * the way WordPress handles same situation with "normal" term editing screens. |
|
| 99 | - * |
|
| 100 | - * @since 3.11.0 |
|
| 101 | - */ |
|
| 102 | - function validate_proper_term() { |
|
| 103 | - |
|
| 104 | - // Validate capabilities. |
|
| 105 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
| 106 | - wp_die( |
|
| 107 | - '<h1>' . __( 'Cheatin’ uh?' ) . '</h1>' . |
|
| 108 | - '<p>' . __( 'Sorry, you are not allowed to edit this item.' ) . '</p>', |
|
| 109 | - 403 |
|
| 110 | - ); |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - // Get the term id and the actual term. |
|
| 114 | - $term_id = (int) $_REQUEST['tag_ID']; |
|
| 115 | - $term = get_term( $term_id, 'wl_entity_type' ); |
|
| 116 | - |
|
| 117 | - if ( ! $term instanceof WP_Term ) { |
|
| 118 | - wp_die( __( 'You attempted to edit an entity type term that doesn’t exist.', 'wordlift' ) ); |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * Handle the form submission of the settings form. On successful |
|
| 125 | - * handling redirect tp the setting edit page. |
|
| 126 | - * |
|
| 127 | - * @since 3.11.0 |
|
| 128 | - */ |
|
| 129 | - function handle_form_submission() { |
|
| 130 | - |
|
| 131 | - $term_id = (int) $_POST['tag_ID']; |
|
| 132 | - |
|
| 133 | - // Check the nonce. |
|
| 134 | - check_admin_referer( 'update-entity_type_term_' . $term_id ); |
|
| 135 | - |
|
| 136 | - $term = get_term( $term_id, 'wl_entity_type' ); |
|
| 137 | - |
|
| 138 | - $this->set_setting( |
|
| 139 | - $term_id, |
|
| 140 | - trim( wp_unslash( $_POST['title'] ) ), |
|
| 141 | - wp_unslash( $_POST['description'] ) |
|
| 142 | - ); |
|
| 143 | - |
|
| 144 | - // Redirect back to the term settings page and indicate a save was done. |
|
| 145 | - $url = admin_url( "admin.php?page=wl_entity_type_settings&tag_ID=$term->term_id&message=1" ); |
|
| 146 | - |
|
| 147 | - wp_redirect( $url ); |
|
| 148 | - exit; |
|
| 149 | - |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - /** |
|
| 153 | - * Render the settings page for the term. |
|
| 154 | - * |
|
| 155 | - * Access and parameter validity is assumed to be done earlier. |
|
| 156 | - * |
|
| 157 | - * @since 3.11.0 |
|
| 158 | - */ |
|
| 159 | - function render() { |
|
| 160 | - |
|
| 161 | - // Set variables used by the partial |
|
| 162 | - $term_id = absint( $_REQUEST['tag_ID'] ); |
|
| 163 | - $settings = $this->get_setting( $term_id ); |
|
| 164 | - |
|
| 165 | - include plugin_dir_path( dirname( __FILE__ ) ) . 'admin/partials/wordlift-admin-entity-type-settings.php'; |
|
| 166 | - |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - /** |
|
| 170 | - * Store the entity type term settings in the DB |
|
| 171 | - * |
|
| 172 | - * @since 3.11.0 |
|
| 173 | - * |
|
| 174 | - * @param integer $term_id The ID of the entity type term |
|
| 175 | - * @param string $title The override for the terms title. |
|
| 176 | - * @param string $description The override for the terms description. |
|
| 177 | - * |
|
| 178 | - */ |
|
| 179 | - function set_setting( $term_id, $title, $description ) { |
|
| 180 | - |
|
| 181 | - $settings = get_option( 'wl_entity_type_settings', array() ); |
|
| 182 | - $settings[ $term_id ] = array( |
|
| 183 | - 'title' => $title, |
|
| 184 | - 'description' => $description, |
|
| 185 | - ); |
|
| 186 | - update_option( 'wl_entity_type_settings', $settings ); |
|
| 187 | - |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - /** |
|
| 191 | - * Retrieve the entity type term settings from the DB |
|
| 192 | - * |
|
| 193 | - * @since 3.11.0 |
|
| 194 | - * |
|
| 195 | - * @param integer $term_id The ID of the entity type term |
|
| 196 | - * |
|
| 197 | - * @return null|array { |
|
| 198 | - * null is returned when there are no settings otherwise |
|
| 199 | - * an array is returned with following fields |
|
| 200 | - * |
|
| 201 | - * @type string title The overriding title for the term |
|
| 202 | - * @type string description The overriding description for the term |
|
| 203 | - * } |
|
| 204 | - */ |
|
| 205 | - function get_setting( $term_id ) { |
|
| 206 | - |
|
| 207 | - $settings = get_option( 'wl_entity_type_settings', array() ); |
|
| 208 | - |
|
| 209 | - if ( isset( $settings[ $term_id ] ) ) { |
|
| 210 | - return $settings[ $term_id ]; |
|
| 211 | - } else { |
|
| 212 | - null; |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - } |
|
| 92 | + } |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * Validate the existence of the entity type indicated by the tag_ID url |
|
| 97 | + * parameter before doing any processing. Done before any output to mimic |
|
| 98 | + * the way WordPress handles same situation with "normal" term editing screens. |
|
| 99 | + * |
|
| 100 | + * @since 3.11.0 |
|
| 101 | + */ |
|
| 102 | + function validate_proper_term() { |
|
| 103 | + |
|
| 104 | + // Validate capabilities. |
|
| 105 | + if ( ! current_user_can( 'manage_options' ) ) { |
|
| 106 | + wp_die( |
|
| 107 | + '<h1>' . __( 'Cheatin’ uh?' ) . '</h1>' . |
|
| 108 | + '<p>' . __( 'Sorry, you are not allowed to edit this item.' ) . '</p>', |
|
| 109 | + 403 |
|
| 110 | + ); |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + // Get the term id and the actual term. |
|
| 114 | + $term_id = (int) $_REQUEST['tag_ID']; |
|
| 115 | + $term = get_term( $term_id, 'wl_entity_type' ); |
|
| 116 | + |
|
| 117 | + if ( ! $term instanceof WP_Term ) { |
|
| 118 | + wp_die( __( 'You attempted to edit an entity type term that doesn’t exist.', 'wordlift' ) ); |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * Handle the form submission of the settings form. On successful |
|
| 125 | + * handling redirect tp the setting edit page. |
|
| 126 | + * |
|
| 127 | + * @since 3.11.0 |
|
| 128 | + */ |
|
| 129 | + function handle_form_submission() { |
|
| 130 | + |
|
| 131 | + $term_id = (int) $_POST['tag_ID']; |
|
| 132 | + |
|
| 133 | + // Check the nonce. |
|
| 134 | + check_admin_referer( 'update-entity_type_term_' . $term_id ); |
|
| 135 | + |
|
| 136 | + $term = get_term( $term_id, 'wl_entity_type' ); |
|
| 137 | + |
|
| 138 | + $this->set_setting( |
|
| 139 | + $term_id, |
|
| 140 | + trim( wp_unslash( $_POST['title'] ) ), |
|
| 141 | + wp_unslash( $_POST['description'] ) |
|
| 142 | + ); |
|
| 143 | + |
|
| 144 | + // Redirect back to the term settings page and indicate a save was done. |
|
| 145 | + $url = admin_url( "admin.php?page=wl_entity_type_settings&tag_ID=$term->term_id&message=1" ); |
|
| 146 | + |
|
| 147 | + wp_redirect( $url ); |
|
| 148 | + exit; |
|
| 149 | + |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + /** |
|
| 153 | + * Render the settings page for the term. |
|
| 154 | + * |
|
| 155 | + * Access and parameter validity is assumed to be done earlier. |
|
| 156 | + * |
|
| 157 | + * @since 3.11.0 |
|
| 158 | + */ |
|
| 159 | + function render() { |
|
| 160 | + |
|
| 161 | + // Set variables used by the partial |
|
| 162 | + $term_id = absint( $_REQUEST['tag_ID'] ); |
|
| 163 | + $settings = $this->get_setting( $term_id ); |
|
| 164 | + |
|
| 165 | + include plugin_dir_path( dirname( __FILE__ ) ) . 'admin/partials/wordlift-admin-entity-type-settings.php'; |
|
| 166 | + |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + /** |
|
| 170 | + * Store the entity type term settings in the DB |
|
| 171 | + * |
|
| 172 | + * @since 3.11.0 |
|
| 173 | + * |
|
| 174 | + * @param integer $term_id The ID of the entity type term |
|
| 175 | + * @param string $title The override for the terms title. |
|
| 176 | + * @param string $description The override for the terms description. |
|
| 177 | + * |
|
| 178 | + */ |
|
| 179 | + function set_setting( $term_id, $title, $description ) { |
|
| 180 | + |
|
| 181 | + $settings = get_option( 'wl_entity_type_settings', array() ); |
|
| 182 | + $settings[ $term_id ] = array( |
|
| 183 | + 'title' => $title, |
|
| 184 | + 'description' => $description, |
|
| 185 | + ); |
|
| 186 | + update_option( 'wl_entity_type_settings', $settings ); |
|
| 187 | + |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + /** |
|
| 191 | + * Retrieve the entity type term settings from the DB |
|
| 192 | + * |
|
| 193 | + * @since 3.11.0 |
|
| 194 | + * |
|
| 195 | + * @param integer $term_id The ID of the entity type term |
|
| 196 | + * |
|
| 197 | + * @return null|array { |
|
| 198 | + * null is returned when there are no settings otherwise |
|
| 199 | + * an array is returned with following fields |
|
| 200 | + * |
|
| 201 | + * @type string title The overriding title for the term |
|
| 202 | + * @type string description The overriding description for the term |
|
| 203 | + * } |
|
| 204 | + */ |
|
| 205 | + function get_setting( $term_id ) { |
|
| 206 | + |
|
| 207 | + $settings = get_option( 'wl_entity_type_settings', array() ); |
|
| 208 | + |
|
| 209 | + if ( isset( $settings[ $term_id ] ) ) { |
|
| 210 | + return $settings[ $term_id ]; |
|
| 211 | + } else { |
|
| 212 | + null; |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + } |
|
| 216 | 216 | |
| 217 | 217 | } |
@@ -12,7 +12,7 @@ discard block |
||
| 12 | 12 | * @since 3.11.0 |
| 13 | 13 | */ |
| 14 | 14 | |
| 15 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 15 | +if ( ! defined('ABSPATH')) { |
|
| 16 | 16 | exit; |
| 17 | 17 | } |
| 18 | 18 | |
@@ -46,18 +46,18 @@ discard block |
||
| 46 | 46 | * This has to be done before any output happens in order to be able to |
| 47 | 47 | * display proper "die" error messages and redirect. |
| 48 | 48 | */ |
| 49 | - if ( isset( $_GET['page'] ) && ( 'wl_entity_type_settings' === $_GET['page'] ) ) { |
|
| 49 | + if (isset($_GET['page']) && ('wl_entity_type_settings' === $_GET['page'])) { |
|
| 50 | 50 | |
| 51 | 51 | // Validate inputs. Do not return on invalid parameters or capabilities. |
| 52 | 52 | $this->validate_proper_term(); |
| 53 | 53 | |
| 54 | 54 | // If proper form submission, handle it and redirect back to the settings page. |
| 55 | - if ( isset( $_POST['action'] ) && ( 'wl_edit_entity_type_term' === $_POST['action'] ) ) { |
|
| 55 | + if (isset($_POST['action']) && ('wl_edit_entity_type_term' === $_POST['action'])) { |
|
| 56 | 56 | $this->handle_form_submission(); |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | // Register admin notices handler. |
| 60 | - add_action( 'admin_notices', array( $this, 'admin_notice' ) ); |
|
| 60 | + add_action('admin_notices', array($this, 'admin_notice')); |
|
| 61 | 61 | |
| 62 | 62 | } |
| 63 | 63 | |
@@ -68,11 +68,11 @@ discard block |
||
| 68 | 68 | // @todo: use the new {@link Wordlift_Admin_Page}. |
| 69 | 69 | add_submenu_page( |
| 70 | 70 | null, |
| 71 | - __( 'Edit Entity term', 'wordlift' ), |
|
| 72 | - __( 'Edit Entity term', 'wordlift' ), |
|
| 71 | + __('Edit Entity term', 'wordlift'), |
|
| 72 | + __('Edit Entity term', 'wordlift'), |
|
| 73 | 73 | 'manage_options', |
| 74 | 74 | 'wl_entity_type_settings', |
| 75 | - array( $this, 'render' ) |
|
| 75 | + array($this, 'render') |
|
| 76 | 76 | ); |
| 77 | 77 | } |
| 78 | 78 | |
@@ -83,10 +83,10 @@ discard block |
||
| 83 | 83 | * @since 3.11.0 |
| 84 | 84 | */ |
| 85 | 85 | function admin_notice() { |
| 86 | - if ( isset( $_GET['message'] ) && ( '1' === $_GET['message'] ) ) { |
|
| 86 | + if (isset($_GET['message']) && ('1' === $_GET['message'])) { |
|
| 87 | 87 | ?> |
| 88 | 88 | <div class="notice notice-success is-dismissible"> |
| 89 | - <p><?php esc_html_e( 'Settings saved', 'wordlift' ) ?></p> |
|
| 89 | + <p><?php esc_html_e('Settings saved', 'wordlift') ?></p> |
|
| 90 | 90 | </div> |
| 91 | 91 | <?php |
| 92 | 92 | } |
@@ -102,20 +102,20 @@ discard block |
||
| 102 | 102 | function validate_proper_term() { |
| 103 | 103 | |
| 104 | 104 | // Validate capabilities. |
| 105 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
| 105 | + if ( ! current_user_can('manage_options')) { |
|
| 106 | 106 | wp_die( |
| 107 | - '<h1>' . __( 'Cheatin’ uh?' ) . '</h1>' . |
|
| 108 | - '<p>' . __( 'Sorry, you are not allowed to edit this item.' ) . '</p>', |
|
| 107 | + '<h1>'.__('Cheatin’ uh?').'</h1>'. |
|
| 108 | + '<p>'.__('Sorry, you are not allowed to edit this item.').'</p>', |
|
| 109 | 109 | 403 |
| 110 | 110 | ); |
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | // Get the term id and the actual term. |
| 114 | 114 | $term_id = (int) $_REQUEST['tag_ID']; |
| 115 | - $term = get_term( $term_id, 'wl_entity_type' ); |
|
| 115 | + $term = get_term($term_id, 'wl_entity_type'); |
|
| 116 | 116 | |
| 117 | - if ( ! $term instanceof WP_Term ) { |
|
| 118 | - wp_die( __( 'You attempted to edit an entity type term that doesn’t exist.', 'wordlift' ) ); |
|
| 117 | + if ( ! $term instanceof WP_Term) { |
|
| 118 | + wp_die(__('You attempted to edit an entity type term that doesn’t exist.', 'wordlift')); |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | } |
@@ -131,20 +131,20 @@ discard block |
||
| 131 | 131 | $term_id = (int) $_POST['tag_ID']; |
| 132 | 132 | |
| 133 | 133 | // Check the nonce. |
| 134 | - check_admin_referer( 'update-entity_type_term_' . $term_id ); |
|
| 134 | + check_admin_referer('update-entity_type_term_'.$term_id); |
|
| 135 | 135 | |
| 136 | - $term = get_term( $term_id, 'wl_entity_type' ); |
|
| 136 | + $term = get_term($term_id, 'wl_entity_type'); |
|
| 137 | 137 | |
| 138 | 138 | $this->set_setting( |
| 139 | 139 | $term_id, |
| 140 | - trim( wp_unslash( $_POST['title'] ) ), |
|
| 141 | - wp_unslash( $_POST['description'] ) |
|
| 140 | + trim(wp_unslash($_POST['title'])), |
|
| 141 | + wp_unslash($_POST['description']) |
|
| 142 | 142 | ); |
| 143 | 143 | |
| 144 | 144 | // Redirect back to the term settings page and indicate a save was done. |
| 145 | - $url = admin_url( "admin.php?page=wl_entity_type_settings&tag_ID=$term->term_id&message=1" ); |
|
| 145 | + $url = admin_url("admin.php?page=wl_entity_type_settings&tag_ID=$term->term_id&message=1"); |
|
| 146 | 146 | |
| 147 | - wp_redirect( $url ); |
|
| 147 | + wp_redirect($url); |
|
| 148 | 148 | exit; |
| 149 | 149 | |
| 150 | 150 | } |
@@ -159,10 +159,10 @@ discard block |
||
| 159 | 159 | function render() { |
| 160 | 160 | |
| 161 | 161 | // Set variables used by the partial |
| 162 | - $term_id = absint( $_REQUEST['tag_ID'] ); |
|
| 163 | - $settings = $this->get_setting( $term_id ); |
|
| 162 | + $term_id = absint($_REQUEST['tag_ID']); |
|
| 163 | + $settings = $this->get_setting($term_id); |
|
| 164 | 164 | |
| 165 | - include plugin_dir_path( dirname( __FILE__ ) ) . 'admin/partials/wordlift-admin-entity-type-settings.php'; |
|
| 165 | + include plugin_dir_path(dirname(__FILE__)).'admin/partials/wordlift-admin-entity-type-settings.php'; |
|
| 166 | 166 | |
| 167 | 167 | } |
| 168 | 168 | |
@@ -176,14 +176,14 @@ discard block |
||
| 176 | 176 | * @param string $description The override for the terms description. |
| 177 | 177 | * |
| 178 | 178 | */ |
| 179 | - function set_setting( $term_id, $title, $description ) { |
|
| 179 | + function set_setting($term_id, $title, $description) { |
|
| 180 | 180 | |
| 181 | - $settings = get_option( 'wl_entity_type_settings', array() ); |
|
| 182 | - $settings[ $term_id ] = array( |
|
| 181 | + $settings = get_option('wl_entity_type_settings', array()); |
|
| 182 | + $settings[$term_id] = array( |
|
| 183 | 183 | 'title' => $title, |
| 184 | 184 | 'description' => $description, |
| 185 | 185 | ); |
| 186 | - update_option( 'wl_entity_type_settings', $settings ); |
|
| 186 | + update_option('wl_entity_type_settings', $settings); |
|
| 187 | 187 | |
| 188 | 188 | } |
| 189 | 189 | |
@@ -202,12 +202,12 @@ discard block |
||
| 202 | 202 | * @type string description The overriding description for the term |
| 203 | 203 | * } |
| 204 | 204 | */ |
| 205 | - function get_setting( $term_id ) { |
|
| 205 | + function get_setting($term_id) { |
|
| 206 | 206 | |
| 207 | - $settings = get_option( 'wl_entity_type_settings', array() ); |
|
| 207 | + $settings = get_option('wl_entity_type_settings', array()); |
|
| 208 | 208 | |
| 209 | - if ( isset( $settings[ $term_id ] ) ) { |
|
| 210 | - return $settings[ $term_id ]; |
|
| 209 | + if (isset($settings[$term_id])) { |
|
| 210 | + return $settings[$term_id]; |
|
| 211 | 211 | } else { |
| 212 | 212 | null; |
| 213 | 213 | } |
@@ -15,21 +15,21 @@ discard block |
||
| 15 | 15 | */ |
| 16 | 16 | function wl_serialize_entity( $entity ) { |
| 17 | 17 | |
| 18 | - $entity = ( is_numeric( $entity ) ) ? get_post( $entity ) : $entity; |
|
| 18 | + $entity = ( is_numeric( $entity ) ) ? get_post( $entity ) : $entity; |
|
| 19 | 19 | |
| 20 | - $type = wl_entity_type_taxonomy_get_type( $entity->ID ); |
|
| 21 | - $images = wl_get_image_urls( $entity->ID ); |
|
| 20 | + $type = wl_entity_type_taxonomy_get_type( $entity->ID ); |
|
| 21 | + $images = wl_get_image_urls( $entity->ID ); |
|
| 22 | 22 | |
| 23 | - return array( |
|
| 24 | - 'id' => wl_get_entity_uri( $entity->ID ), |
|
| 25 | - 'label' => $entity->post_title, |
|
| 26 | - 'description' => $entity->post_content, |
|
| 27 | - 'sameAs' => wl_schema_get_value( $entity->ID, 'sameAs' ), |
|
| 28 | - 'mainType' => str_replace( 'wl-', '', $type['css_class'] ), |
|
| 29 | - 'types' => wl_get_entity_rdf_types( $entity->ID ), |
|
| 30 | - 'images' => $images, |
|
| 23 | + return array( |
|
| 24 | + 'id' => wl_get_entity_uri( $entity->ID ), |
|
| 25 | + 'label' => $entity->post_title, |
|
| 26 | + 'description' => $entity->post_content, |
|
| 27 | + 'sameAs' => wl_schema_get_value( $entity->ID, 'sameAs' ), |
|
| 28 | + 'mainType' => str_replace( 'wl-', '', $type['css_class'] ), |
|
| 29 | + 'types' => wl_get_entity_rdf_types( $entity->ID ), |
|
| 30 | + 'images' => $images, |
|
| 31 | 31 | |
| 32 | - ); |
|
| 32 | + ); |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | /** |
@@ -43,22 +43,22 @@ discard block |
||
| 43 | 43 | */ |
| 44 | 44 | function wl_remove_text_annotations( $data ) { |
| 45 | 45 | |
| 46 | - // Remove blank elements that can interfere with annoataions removing |
|
| 47 | - // See https://github.com/insideout10/wordlift-plugin/issues/234 |
|
| 48 | - // Just blank attributes without any attribtues are cleaned up |
|
| 49 | - $pattern = '/<(\w+)><\/\1>/im'; |
|
| 50 | - // Remove the pattern while it is found (match nested annotations). |
|
| 51 | - while ( 1 === preg_match( $pattern, $data['post_content'] ) ) { |
|
| 52 | - $data['post_content'] = preg_replace( $pattern, '$2', $data['post_content'], -1, $count ); |
|
| 53 | - } |
|
| 54 | - // Remove text annotations |
|
| 55 | - // <span class="textannotation" id="urn:enhancement-777cbed4-b131-00fb-54a4-ed9b26ae57ea"> |
|
| 56 | - $pattern = '/<(\w+)[^>]*\sclass=\\\"textannotation(?![^\\"]*\sdisambiguated)[^\\"]*\\\"[^>]*>([^<]+)<\/\1>/im'; |
|
| 57 | - // Remove the pattern while it is found (match nested annotations). |
|
| 58 | - while ( 1 === preg_match( $pattern, $data['post_content'] ) ) { |
|
| 59 | - $data['post_content'] = preg_replace( $pattern, '$2', $data['post_content'], -1, $count ); |
|
| 60 | - } |
|
| 61 | - return $data; |
|
| 46 | + // Remove blank elements that can interfere with annoataions removing |
|
| 47 | + // See https://github.com/insideout10/wordlift-plugin/issues/234 |
|
| 48 | + // Just blank attributes without any attribtues are cleaned up |
|
| 49 | + $pattern = '/<(\w+)><\/\1>/im'; |
|
| 50 | + // Remove the pattern while it is found (match nested annotations). |
|
| 51 | + while ( 1 === preg_match( $pattern, $data['post_content'] ) ) { |
|
| 52 | + $data['post_content'] = preg_replace( $pattern, '$2', $data['post_content'], -1, $count ); |
|
| 53 | + } |
|
| 54 | + // Remove text annotations |
|
| 55 | + // <span class="textannotation" id="urn:enhancement-777cbed4-b131-00fb-54a4-ed9b26ae57ea"> |
|
| 56 | + $pattern = '/<(\w+)[^>]*\sclass=\\\"textannotation(?![^\\"]*\sdisambiguated)[^\\"]*\\\"[^>]*>([^<]+)<\/\1>/im'; |
|
| 57 | + // Remove the pattern while it is found (match nested annotations). |
|
| 58 | + while ( 1 === preg_match( $pattern, $data['post_content'] ) ) { |
|
| 59 | + $data['post_content'] = preg_replace( $pattern, '$2', $data['post_content'], -1, $count ); |
|
| 60 | + } |
|
| 61 | + return $data; |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | add_filter( 'wp_insert_post_data', 'wl_remove_text_annotations', '98', 1 ); |
@@ -74,5 +74,5 @@ discard block |
||
| 74 | 74 | */ |
| 75 | 75 | function wl_admin_metaboxes_add_css_class( $classes = array() ){ |
| 76 | 76 | |
| 77 | - return array_merge( $classes, array( 'wl-metabox' ) ); |
|
| 77 | + return array_merge( $classes, array( 'wl-metabox' ) ); |
|
| 78 | 78 | } |
@@ -4,7 +4,7 @@ discard block |
||
| 4 | 4 | */ |
| 5 | 5 | |
| 6 | 6 | // Add the Admin menu. |
| 7 | -require_once( 'wordlift_admin_menu.php' ); |
|
| 7 | +require_once('wordlift_admin_menu.php'); |
|
| 8 | 8 | |
| 9 | 9 | /** |
| 10 | 10 | * Serialize an entity post. |
@@ -13,20 +13,20 @@ discard block |
||
| 13 | 13 | * |
| 14 | 14 | * @return array mixed The entity data array. |
| 15 | 15 | */ |
| 16 | -function wl_serialize_entity( $entity ) { |
|
| 16 | +function wl_serialize_entity($entity) { |
|
| 17 | 17 | |
| 18 | - $entity = ( is_numeric( $entity ) ) ? get_post( $entity ) : $entity; |
|
| 18 | + $entity = (is_numeric($entity)) ? get_post($entity) : $entity; |
|
| 19 | 19 | |
| 20 | - $type = wl_entity_type_taxonomy_get_type( $entity->ID ); |
|
| 21 | - $images = wl_get_image_urls( $entity->ID ); |
|
| 20 | + $type = wl_entity_type_taxonomy_get_type($entity->ID); |
|
| 21 | + $images = wl_get_image_urls($entity->ID); |
|
| 22 | 22 | |
| 23 | 23 | return array( |
| 24 | - 'id' => wl_get_entity_uri( $entity->ID ), |
|
| 24 | + 'id' => wl_get_entity_uri($entity->ID), |
|
| 25 | 25 | 'label' => $entity->post_title, |
| 26 | 26 | 'description' => $entity->post_content, |
| 27 | - 'sameAs' => wl_schema_get_value( $entity->ID, 'sameAs' ), |
|
| 28 | - 'mainType' => str_replace( 'wl-', '', $type['css_class'] ), |
|
| 29 | - 'types' => wl_get_entity_rdf_types( $entity->ID ), |
|
| 27 | + 'sameAs' => wl_schema_get_value($entity->ID, 'sameAs'), |
|
| 28 | + 'mainType' => str_replace('wl-', '', $type['css_class']), |
|
| 29 | + 'types' => wl_get_entity_rdf_types($entity->ID), |
|
| 30 | 30 | 'images' => $images, |
| 31 | 31 | |
| 32 | 32 | ); |
@@ -41,27 +41,27 @@ discard block |
||
| 41 | 41 | * |
| 42 | 42 | * @return array mixed The post data array. |
| 43 | 43 | */ |
| 44 | -function wl_remove_text_annotations( $data ) { |
|
| 44 | +function wl_remove_text_annotations($data) { |
|
| 45 | 45 | |
| 46 | 46 | // Remove blank elements that can interfere with annoataions removing |
| 47 | 47 | // See https://github.com/insideout10/wordlift-plugin/issues/234 |
| 48 | 48 | // Just blank attributes without any attribtues are cleaned up |
| 49 | 49 | $pattern = '/<(\w+)><\/\1>/im'; |
| 50 | 50 | // Remove the pattern while it is found (match nested annotations). |
| 51 | - while ( 1 === preg_match( $pattern, $data['post_content'] ) ) { |
|
| 52 | - $data['post_content'] = preg_replace( $pattern, '$2', $data['post_content'], -1, $count ); |
|
| 51 | + while (1 === preg_match($pattern, $data['post_content'])) { |
|
| 52 | + $data['post_content'] = preg_replace($pattern, '$2', $data['post_content'], -1, $count); |
|
| 53 | 53 | } |
| 54 | 54 | // Remove text annotations |
| 55 | 55 | // <span class="textannotation" id="urn:enhancement-777cbed4-b131-00fb-54a4-ed9b26ae57ea"> |
| 56 | 56 | $pattern = '/<(\w+)[^>]*\sclass=\\\"textannotation(?![^\\"]*\sdisambiguated)[^\\"]*\\\"[^>]*>([^<]+)<\/\1>/im'; |
| 57 | 57 | // Remove the pattern while it is found (match nested annotations). |
| 58 | - while ( 1 === preg_match( $pattern, $data['post_content'] ) ) { |
|
| 59 | - $data['post_content'] = preg_replace( $pattern, '$2', $data['post_content'], -1, $count ); |
|
| 58 | + while (1 === preg_match($pattern, $data['post_content'])) { |
|
| 59 | + $data['post_content'] = preg_replace($pattern, '$2', $data['post_content'], -1, $count); |
|
| 60 | 60 | } |
| 61 | 61 | return $data; |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | -add_filter( 'wp_insert_post_data', 'wl_remove_text_annotations', '98', 1 ); |
|
| 64 | +add_filter('wp_insert_post_data', 'wl_remove_text_annotations', '98', 1); |
|
| 65 | 65 | |
| 66 | 66 | /** |
| 67 | 67 | * Adds wl-metabox CSS class to a metabox. |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | * |
| 73 | 73 | * @return array The updated list of CSS classes. |
| 74 | 74 | */ |
| 75 | -function wl_admin_metaboxes_add_css_class( $classes = array() ){ |
|
| 75 | +function wl_admin_metaboxes_add_css_class($classes = array()) { |
|
| 76 | 76 | |
| 77 | - return array_merge( $classes, array( 'wl-metabox' ) ); |
|
| 77 | + return array_merge($classes, array('wl-metabox')); |
|
| 78 | 78 | } |