@@ -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 | /** |
@@ -28,113 +28,113 @@ discard block |
||
| 28 | 28 | */ |
| 29 | 29 | class Wordlift_Admin_Entity_Taxonomy_List_Page { |
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * Hook to `wl_entity_type_row_actions` to add an "action" link to Thread |
|
| 33 | - * SEO related settings for the term. |
|
| 34 | - * |
|
| 35 | - * @see https://developer.wordpress.org/reference/hooks/taxonomy_row_actions/ |
|
| 36 | - * |
|
| 37 | - * @since 3.11.0 |
|
| 38 | - * |
|
| 39 | - * @param array $actions An array of action links to be displayed. Default |
|
| 40 | - * 'Edit', 'Quick Edit', 'Delete', and 'View'. |
|
| 41 | - * @param object $term Term object. |
|
| 42 | - * |
|
| 43 | - * @return array $actions An array of action links to be displayed. Default |
|
| 44 | - * 'Edit', 'Quick Edit', 'Delete', and 'View'. |
|
| 45 | - */ |
|
| 46 | - function wl_entity_type_row_actions( $actions, $term ) { |
|
| 47 | - |
|
| 48 | - $url = admin_url( "admin.php?page=wl_entity_type_settings&tag_ID=$term->term_id" ); |
|
| 49 | - $actions['wl-seo'] = '<a href="' . esc_url( $url ) . '">' . __( 'SEO Settings', 'wordlift' ) . '</a>'; |
|
| 50 | - |
|
| 51 | - // Hacks for pre 4.7 compatibility: |
|
| 52 | - // * remove the quick edit. |
|
| 53 | - unset( $actions['inline hide-if-no-js'] ); |
|
| 54 | - // * remove the edit link. |
|
| 55 | - unset( $actions['edit'] ); |
|
| 56 | - |
|
| 57 | - return $actions; |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * Override the capabilities related to managing the entity type terms |
|
| 62 | - * for multisite super admin to prevent it from manipulating it in any |
|
| 63 | - * way. |
|
| 64 | - * |
|
| 65 | - * @since 3.12.0 |
|
| 66 | - * |
|
| 67 | - * @param array $caps The user's current capabilities. |
|
| 68 | - * @param string $cap Capability name. |
|
| 69 | - * @param int $user_id The user ID. |
|
| 70 | - * @param array $args Adds the context to the cap. Typically the object ID. |
|
| 71 | - * |
|
| 72 | - * @return array Array containing the do_not_allow capability for super admin |
|
| 73 | - * when editing and deleting entity type terms capabilities |
|
| 74 | - * are being "approved" |
|
| 75 | - */ |
|
| 76 | - function restrict_super_admin( $caps, $cap, $user_id, $args ) { |
|
| 77 | - |
|
| 78 | - switch ( $cap ) { |
|
| 79 | - case 'wl_entity_type_edit_term': |
|
| 80 | - case 'wl_entity_type_delete_term': |
|
| 81 | - $caps[] = 'do_not_allow'; |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - return $caps; |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * Override the capabilities related to managing the entity type terms |
|
| 89 | - * required for WordPress < 4.7 to get access to the admin page. |
|
| 90 | - * |
|
| 91 | - * Before 4.7, WordPress checks whether the user has permission to access |
|
| 92 | - * the `edit-tags.php` page. So we need to provide temporary the permission |
|
| 93 | - * otherwise the user will get an `access not allowed` when trying to access |
|
| 94 | - * the page. |
|
| 95 | - * |
|
| 96 | - * @see https://github.com/insideout10/wordlift-plugin/issues/512 |
|
| 97 | - * |
|
| 98 | - * @since 3.12.0 |
|
| 99 | - * |
|
| 100 | - * @param array $caps The user's current capabilities. |
|
| 101 | - * @param string $cap Capability name. |
|
| 102 | - * @param int $user_id The user ID. |
|
| 103 | - * @param array $args Adds the context to the cap. Typically the object ID. |
|
| 104 | - * |
|
| 105 | - * @return array Array containing the manage_options capability |
|
| 106 | - */ |
|
| 107 | - function enable_admin_access_pre_47( $caps, $cap, $user_id, $args ) { |
|
| 108 | - |
|
| 109 | - // Bail out if we're not dealing with the `wl_entity_type_edit_term` |
|
| 110 | - // capability. |
|
| 111 | - if ( 'wl_entity_type_edit_term' !== $cap ) { |
|
| 112 | - return $caps; |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - $path = parse_url( $_SERVER['REQUEST_URI'], PHP_URL_PATH ); |
|
| 116 | - |
|
| 117 | - // Bail out if the `path` cannot be determined. |
|
| 118 | - if ( null === $path ) { |
|
| 119 | - return $caps; |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - // Bail out if a specific term is being handled. |
|
| 123 | - if ( isset( $_REQUEST['action'] ) ) { |
|
| 124 | - return $caps; |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - // Split the path and check if the page is the `edit-tags.php`. We can't |
|
| 128 | - // use WP's own function because this is called very early. |
|
| 129 | - $components = explode( '/', $path ); |
|
| 130 | - if ( 'edit-tags.php' !== $components[ count( $components ) - 1 ] ) { |
|
| 131 | - return $caps; |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - // Give permission to the user. |
|
| 135 | - $mapped[] = 'manage_options'; |
|
| 136 | - |
|
| 137 | - return $mapped; |
|
| 138 | - } |
|
| 31 | + /** |
|
| 32 | + * Hook to `wl_entity_type_row_actions` to add an "action" link to Thread |
|
| 33 | + * SEO related settings for the term. |
|
| 34 | + * |
|
| 35 | + * @see https://developer.wordpress.org/reference/hooks/taxonomy_row_actions/ |
|
| 36 | + * |
|
| 37 | + * @since 3.11.0 |
|
| 38 | + * |
|
| 39 | + * @param array $actions An array of action links to be displayed. Default |
|
| 40 | + * 'Edit', 'Quick Edit', 'Delete', and 'View'. |
|
| 41 | + * @param object $term Term object. |
|
| 42 | + * |
|
| 43 | + * @return array $actions An array of action links to be displayed. Default |
|
| 44 | + * 'Edit', 'Quick Edit', 'Delete', and 'View'. |
|
| 45 | + */ |
|
| 46 | + function wl_entity_type_row_actions( $actions, $term ) { |
|
| 47 | + |
|
| 48 | + $url = admin_url( "admin.php?page=wl_entity_type_settings&tag_ID=$term->term_id" ); |
|
| 49 | + $actions['wl-seo'] = '<a href="' . esc_url( $url ) . '">' . __( 'SEO Settings', 'wordlift' ) . '</a>'; |
|
| 50 | + |
|
| 51 | + // Hacks for pre 4.7 compatibility: |
|
| 52 | + // * remove the quick edit. |
|
| 53 | + unset( $actions['inline hide-if-no-js'] ); |
|
| 54 | + // * remove the edit link. |
|
| 55 | + unset( $actions['edit'] ); |
|
| 56 | + |
|
| 57 | + return $actions; |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * Override the capabilities related to managing the entity type terms |
|
| 62 | + * for multisite super admin to prevent it from manipulating it in any |
|
| 63 | + * way. |
|
| 64 | + * |
|
| 65 | + * @since 3.12.0 |
|
| 66 | + * |
|
| 67 | + * @param array $caps The user's current capabilities. |
|
| 68 | + * @param string $cap Capability name. |
|
| 69 | + * @param int $user_id The user ID. |
|
| 70 | + * @param array $args Adds the context to the cap. Typically the object ID. |
|
| 71 | + * |
|
| 72 | + * @return array Array containing the do_not_allow capability for super admin |
|
| 73 | + * when editing and deleting entity type terms capabilities |
|
| 74 | + * are being "approved" |
|
| 75 | + */ |
|
| 76 | + function restrict_super_admin( $caps, $cap, $user_id, $args ) { |
|
| 77 | + |
|
| 78 | + switch ( $cap ) { |
|
| 79 | + case 'wl_entity_type_edit_term': |
|
| 80 | + case 'wl_entity_type_delete_term': |
|
| 81 | + $caps[] = 'do_not_allow'; |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + return $caps; |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * Override the capabilities related to managing the entity type terms |
|
| 89 | + * required for WordPress < 4.7 to get access to the admin page. |
|
| 90 | + * |
|
| 91 | + * Before 4.7, WordPress checks whether the user has permission to access |
|
| 92 | + * the `edit-tags.php` page. So we need to provide temporary the permission |
|
| 93 | + * otherwise the user will get an `access not allowed` when trying to access |
|
| 94 | + * the page. |
|
| 95 | + * |
|
| 96 | + * @see https://github.com/insideout10/wordlift-plugin/issues/512 |
|
| 97 | + * |
|
| 98 | + * @since 3.12.0 |
|
| 99 | + * |
|
| 100 | + * @param array $caps The user's current capabilities. |
|
| 101 | + * @param string $cap Capability name. |
|
| 102 | + * @param int $user_id The user ID. |
|
| 103 | + * @param array $args Adds the context to the cap. Typically the object ID. |
|
| 104 | + * |
|
| 105 | + * @return array Array containing the manage_options capability |
|
| 106 | + */ |
|
| 107 | + function enable_admin_access_pre_47( $caps, $cap, $user_id, $args ) { |
|
| 108 | + |
|
| 109 | + // Bail out if we're not dealing with the `wl_entity_type_edit_term` |
|
| 110 | + // capability. |
|
| 111 | + if ( 'wl_entity_type_edit_term' !== $cap ) { |
|
| 112 | + return $caps; |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + $path = parse_url( $_SERVER['REQUEST_URI'], PHP_URL_PATH ); |
|
| 116 | + |
|
| 117 | + // Bail out if the `path` cannot be determined. |
|
| 118 | + if ( null === $path ) { |
|
| 119 | + return $caps; |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + // Bail out if a specific term is being handled. |
|
| 123 | + if ( isset( $_REQUEST['action'] ) ) { |
|
| 124 | + return $caps; |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + // Split the path and check if the page is the `edit-tags.php`. We can't |
|
| 128 | + // use WP's own function because this is called very early. |
|
| 129 | + $components = explode( '/', $path ); |
|
| 130 | + if ( 'edit-tags.php' !== $components[ count( $components ) - 1 ] ) { |
|
| 131 | + return $caps; |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + // Give permission to the user. |
|
| 135 | + $mapped[] = 'manage_options'; |
|
| 136 | + |
|
| 137 | + return $mapped; |
|
| 138 | + } |
|
| 139 | 139 | |
| 140 | 140 | } |
@@ -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 | |
@@ -43,16 +43,16 @@ discard block |
||
| 43 | 43 | * @return array $actions An array of action links to be displayed. Default |
| 44 | 44 | * 'Edit', 'Quick Edit', 'Delete', and 'View'. |
| 45 | 45 | */ |
| 46 | - function wl_entity_type_row_actions( $actions, $term ) { |
|
| 46 | + function wl_entity_type_row_actions($actions, $term) { |
|
| 47 | 47 | |
| 48 | - $url = admin_url( "admin.php?page=wl_entity_type_settings&tag_ID=$term->term_id" ); |
|
| 49 | - $actions['wl-seo'] = '<a href="' . esc_url( $url ) . '">' . __( 'SEO Settings', 'wordlift' ) . '</a>'; |
|
| 48 | + $url = admin_url("admin.php?page=wl_entity_type_settings&tag_ID=$term->term_id"); |
|
| 49 | + $actions['wl-seo'] = '<a href="'.esc_url($url).'">'.__('SEO Settings', 'wordlift').'</a>'; |
|
| 50 | 50 | |
| 51 | 51 | // Hacks for pre 4.7 compatibility: |
| 52 | 52 | // * remove the quick edit. |
| 53 | - unset( $actions['inline hide-if-no-js'] ); |
|
| 53 | + unset($actions['inline hide-if-no-js']); |
|
| 54 | 54 | // * remove the edit link. |
| 55 | - unset( $actions['edit'] ); |
|
| 55 | + unset($actions['edit']); |
|
| 56 | 56 | |
| 57 | 57 | return $actions; |
| 58 | 58 | } |
@@ -73,9 +73,9 @@ discard block |
||
| 73 | 73 | * when editing and deleting entity type terms capabilities |
| 74 | 74 | * are being "approved" |
| 75 | 75 | */ |
| 76 | - function restrict_super_admin( $caps, $cap, $user_id, $args ) { |
|
| 76 | + function restrict_super_admin($caps, $cap, $user_id, $args) { |
|
| 77 | 77 | |
| 78 | - switch ( $cap ) { |
|
| 78 | + switch ($cap) { |
|
| 79 | 79 | case 'wl_entity_type_edit_term': |
| 80 | 80 | case 'wl_entity_type_delete_term': |
| 81 | 81 | $caps[] = 'do_not_allow'; |
@@ -104,30 +104,30 @@ discard block |
||
| 104 | 104 | * |
| 105 | 105 | * @return array Array containing the manage_options capability |
| 106 | 106 | */ |
| 107 | - function enable_admin_access_pre_47( $caps, $cap, $user_id, $args ) { |
|
| 107 | + function enable_admin_access_pre_47($caps, $cap, $user_id, $args) { |
|
| 108 | 108 | |
| 109 | 109 | // Bail out if we're not dealing with the `wl_entity_type_edit_term` |
| 110 | 110 | // capability. |
| 111 | - if ( 'wl_entity_type_edit_term' !== $cap ) { |
|
| 111 | + if ('wl_entity_type_edit_term' !== $cap) { |
|
| 112 | 112 | return $caps; |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | - $path = parse_url( $_SERVER['REQUEST_URI'], PHP_URL_PATH ); |
|
| 115 | + $path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH); |
|
| 116 | 116 | |
| 117 | 117 | // Bail out if the `path` cannot be determined. |
| 118 | - if ( null === $path ) { |
|
| 118 | + if (null === $path) { |
|
| 119 | 119 | return $caps; |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | // Bail out if a specific term is being handled. |
| 123 | - if ( isset( $_REQUEST['action'] ) ) { |
|
| 123 | + if (isset($_REQUEST['action'])) { |
|
| 124 | 124 | return $caps; |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | // Split the path and check if the page is the `edit-tags.php`. We can't |
| 128 | 128 | // use WP's own function because this is called very early. |
| 129 | - $components = explode( '/', $path ); |
|
| 130 | - if ( 'edit-tags.php' !== $components[ count( $components ) - 1 ] ) { |
|
| 129 | + $components = explode('/', $path); |
|
| 130 | + if ('edit-tags.php' !== $components[count($components) - 1]) { |
|
| 131 | 131 | return $caps; |
| 132 | 132 | } |
| 133 | 133 | |
@@ -15,34 +15,34 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | function wl_prefixes_list() { |
| 17 | 17 | |
| 18 | - // If the parameter is false, default prefixes have never been installed. |
|
| 19 | - if ( false === ( $prefixes = get_option( 'wl_option_prefixes' ) ) ) { |
|
| 18 | + // If the parameter is false, default prefixes have never been installed. |
|
| 19 | + if ( false === ( $prefixes = get_option( 'wl_option_prefixes' ) ) ) { |
|
| 20 | 20 | |
| 21 | - $prefixes = array( |
|
| 22 | - array( |
|
| 23 | - 'prefix' => 'geo', |
|
| 24 | - 'namespace' => 'http://www.w3.org/2003/01/geo/wgs84_pos#', |
|
| 25 | - ), |
|
| 26 | - array( |
|
| 27 | - 'prefix' => 'dct', |
|
| 28 | - 'namespace' => 'http://purl.org/dc/terms/', |
|
| 29 | - ), |
|
| 30 | - array( |
|
| 31 | - 'prefix' => 'rdfs', |
|
| 32 | - 'namespace' => 'http://www.w3.org/2000/01/rdf-schema#', |
|
| 33 | - ), |
|
| 34 | - array( |
|
| 35 | - 'prefix' => 'owl', |
|
| 36 | - 'namespace' => 'http://www.w3.org/2002/07/owl#', |
|
| 37 | - ), |
|
| 38 | - array( 'prefix' => 'schema', 'namespace' => 'http://schema.org/' ), |
|
| 39 | - array( |
|
| 40 | - 'prefix' => 'xsd', |
|
| 41 | - 'namespace' => 'http://www.w3.org/2001/XMLSchema#', |
|
| 42 | - ), |
|
| 43 | - ); |
|
| 44 | - add_option( 'wl_option_prefixes', $prefixes ); |
|
| 45 | - } |
|
| 21 | + $prefixes = array( |
|
| 22 | + array( |
|
| 23 | + 'prefix' => 'geo', |
|
| 24 | + 'namespace' => 'http://www.w3.org/2003/01/geo/wgs84_pos#', |
|
| 25 | + ), |
|
| 26 | + array( |
|
| 27 | + 'prefix' => 'dct', |
|
| 28 | + 'namespace' => 'http://purl.org/dc/terms/', |
|
| 29 | + ), |
|
| 30 | + array( |
|
| 31 | + 'prefix' => 'rdfs', |
|
| 32 | + 'namespace' => 'http://www.w3.org/2000/01/rdf-schema#', |
|
| 33 | + ), |
|
| 34 | + array( |
|
| 35 | + 'prefix' => 'owl', |
|
| 36 | + 'namespace' => 'http://www.w3.org/2002/07/owl#', |
|
| 37 | + ), |
|
| 38 | + array( 'prefix' => 'schema', 'namespace' => 'http://schema.org/' ), |
|
| 39 | + array( |
|
| 40 | + 'prefix' => 'xsd', |
|
| 41 | + 'namespace' => 'http://www.w3.org/2001/XMLSchema#', |
|
| 42 | + ), |
|
| 43 | + ); |
|
| 44 | + add_option( 'wl_option_prefixes', $prefixes ); |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - return $prefixes; |
|
| 47 | + return $prefixes; |
|
| 48 | 48 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | function wl_prefixes_list() { |
| 17 | 17 | |
| 18 | 18 | // If the parameter is false, default prefixes have never been installed. |
| 19 | - if ( false === ( $prefixes = get_option( 'wl_option_prefixes' ) ) ) { |
|
| 19 | + if (false === ($prefixes = get_option('wl_option_prefixes'))) { |
|
| 20 | 20 | |
| 21 | 21 | $prefixes = array( |
| 22 | 22 | array( |
@@ -35,13 +35,13 @@ discard block |
||
| 35 | 35 | 'prefix' => 'owl', |
| 36 | 36 | 'namespace' => 'http://www.w3.org/2002/07/owl#', |
| 37 | 37 | ), |
| 38 | - array( 'prefix' => 'schema', 'namespace' => 'http://schema.org/' ), |
|
| 38 | + array('prefix' => 'schema', 'namespace' => 'http://schema.org/'), |
|
| 39 | 39 | array( |
| 40 | 40 | 'prefix' => 'xsd', |
| 41 | 41 | 'namespace' => 'http://www.w3.org/2001/XMLSchema#', |
| 42 | 42 | ), |
| 43 | 43 | ); |
| 44 | - add_option( 'wl_option_prefixes', $prefixes ); |
|
| 44 | + add_option('wl_option_prefixes', $prefixes); |
|
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | return $prefixes; |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | |
| 27 | 27 | // If this file is called directly, abort. |
| 28 | 28 | if ( ! defined( 'WPINC' ) ) { |
| 29 | - die; |
|
| 29 | + die; |
|
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | // Include WordLift constants. |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | */ |
| 49 | 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 | } |
| 54 | 54 | |
@@ -64,20 +64,20 @@ discard block |
||
| 64 | 64 | */ |
| 65 | 65 | function wl_write_log_handler( $log, $caller = null ) { |
| 66 | 66 | |
| 67 | - global $wl_logger; |
|
| 67 | + global $wl_logger; |
|
| 68 | 68 | |
| 69 | - if ( true === WP_DEBUG ) { |
|
| 69 | + if ( true === WP_DEBUG ) { |
|
| 70 | 70 | |
| 71 | - $message = ( isset( $caller ) ? sprintf( '[%-40.40s] ', $caller ) : '' ) . |
|
| 72 | - ( is_array( $log ) || is_object( $log ) ? print_r( $log, true ) : wl_write_log_hide_key( $log ) ); |
|
| 71 | + $message = ( isset( $caller ) ? sprintf( '[%-40.40s] ', $caller ) : '' ) . |
|
| 72 | + ( is_array( $log ) || is_object( $log ) ? print_r( $log, true ) : wl_write_log_hide_key( $log ) ); |
|
| 73 | 73 | |
| 74 | - if ( isset( $wl_logger ) ) { |
|
| 75 | - $wl_logger->info( $message ); |
|
| 76 | - } else { |
|
| 77 | - error_log( $message ); |
|
| 78 | - } |
|
| 74 | + if ( isset( $wl_logger ) ) { |
|
| 75 | + $wl_logger->info( $message ); |
|
| 76 | + } else { |
|
| 77 | + error_log( $message ); |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - } |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | 82 | } |
| 83 | 83 | |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | */ |
| 95 | 95 | function wl_write_log_hide_key( $text ) { |
| 96 | 96 | |
| 97 | - return str_ireplace( wl_configuration_get_key(), '<hidden>', $text ); |
|
| 97 | + return str_ireplace( wl_configuration_get_key(), '<hidden>', $text ); |
|
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | /** |
@@ -106,10 +106,10 @@ discard block |
||
| 106 | 106 | */ |
| 107 | 107 | function wl_queue_sparql_update_query( $query ) { |
| 108 | 108 | |
| 109 | - $filename = WL_TEMP_DIR . WL_REQUEST_ID . '.sparql'; |
|
| 110 | - file_put_contents( $filename, $query . "\n", FILE_APPEND ); |
|
| 109 | + $filename = WL_TEMP_DIR . WL_REQUEST_ID . '.sparql'; |
|
| 110 | + file_put_contents( $filename, $query . "\n", FILE_APPEND ); |
|
| 111 | 111 | |
| 112 | - wl_write_log( "wl_queue_sparql_update_query [ filename :: $filename ]" ); |
|
| 112 | + wl_write_log( "wl_queue_sparql_update_query [ filename :: $filename ]" ); |
|
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | /** |
@@ -119,28 +119,28 @@ discard block |
||
| 119 | 119 | */ |
| 120 | 120 | function wl_execute_saved_sparql_update_query( $request_id ) { |
| 121 | 121 | |
| 122 | - $filename = WL_TEMP_DIR . $request_id . '.sparql'; |
|
| 122 | + $filename = WL_TEMP_DIR . $request_id . '.sparql'; |
|
| 123 | 123 | |
| 124 | - // If the file doesn't exist, exit. |
|
| 125 | - if ( ! file_exists( $filename ) ) { |
|
| 126 | - wl_write_log( "wl_execute_saved_sparql_update_query : file doesn't exist [ filename :: $filename ]" ); |
|
| 124 | + // If the file doesn't exist, exit. |
|
| 125 | + if ( ! file_exists( $filename ) ) { |
|
| 126 | + wl_write_log( "wl_execute_saved_sparql_update_query : file doesn't exist [ filename :: $filename ]" ); |
|
| 127 | 127 | |
| 128 | - return; |
|
| 129 | - } |
|
| 128 | + return; |
|
| 129 | + } |
|
| 130 | 130 | |
| 131 | - wl_write_log( "wl_execute_saved_sparql_update_query [ filename :: $filename ]" ); |
|
| 131 | + wl_write_log( "wl_execute_saved_sparql_update_query [ filename :: $filename ]" ); |
|
| 132 | 132 | |
| 133 | - // Get the query saved in the file. |
|
| 134 | - $query = file_get_contents( $filename ); |
|
| 133 | + // Get the query saved in the file. |
|
| 134 | + $query = file_get_contents( $filename ); |
|
| 135 | 135 | |
| 136 | - // Execute the SPARQL query. |
|
| 137 | - rl_execute_sparql_update_query( $query, false ); |
|
| 136 | + // Execute the SPARQL query. |
|
| 137 | + rl_execute_sparql_update_query( $query, false ); |
|
| 138 | 138 | |
| 139 | - // Reindex the triple store. |
|
| 140 | - wordlift_reindex_triple_store(); |
|
| 139 | + // Reindex the triple store. |
|
| 140 | + wordlift_reindex_triple_store(); |
|
| 141 | 141 | |
| 142 | - // Delete the temporary file. |
|
| 143 | - unlink( $filename ); |
|
| 142 | + // Delete the temporary file. |
|
| 143 | + unlink( $filename ); |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | add_action( 'wl_execute_saved_sparql_update_query', 'wl_execute_saved_sparql_update_query', 10, 1 ); |
@@ -150,21 +150,21 @@ discard block |
||
| 150 | 150 | * see http://vip.wordpress.com/documentation/register-additional-html-attributes-for-tinymce-and-wp-kses/ |
| 151 | 151 | */ |
| 152 | 152 | function wordlift_allowed_post_tags() { |
| 153 | - global $allowedposttags; |
|
| 154 | - |
|
| 155 | - $tags = array( 'span' ); |
|
| 156 | - $new_attributes = array( |
|
| 157 | - 'itemscope' => array(), |
|
| 158 | - 'itemtype' => array(), |
|
| 159 | - 'itemprop' => array(), |
|
| 160 | - 'itemid' => array(), |
|
| 161 | - ); |
|
| 162 | - |
|
| 163 | - foreach ( $tags as $tag ) { |
|
| 164 | - if ( isset( $allowedposttags[ $tag ] ) && is_array( $allowedposttags[ $tag ] ) ) { |
|
| 165 | - $allowedposttags[ $tag ] = array_merge( $allowedposttags[ $tag ], $new_attributes ); |
|
| 166 | - } |
|
| 167 | - } |
|
| 153 | + global $allowedposttags; |
|
| 154 | + |
|
| 155 | + $tags = array( 'span' ); |
|
| 156 | + $new_attributes = array( |
|
| 157 | + 'itemscope' => array(), |
|
| 158 | + 'itemtype' => array(), |
|
| 159 | + 'itemprop' => array(), |
|
| 160 | + 'itemid' => array(), |
|
| 161 | + ); |
|
| 162 | + |
|
| 163 | + foreach ( $tags as $tag ) { |
|
| 164 | + if ( isset( $allowedposttags[ $tag ] ) && is_array( $allowedposttags[ $tag ] ) ) { |
|
| 165 | + $allowedposttags[ $tag ] = array_merge( $allowedposttags[ $tag ], $new_attributes ); |
|
| 166 | + } |
|
| 167 | + } |
|
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | // init process for button control |
@@ -179,28 +179,28 @@ discard block |
||
| 179 | 179 | */ |
| 180 | 180 | function wordlift_admin_enqueue_scripts() { |
| 181 | 181 | |
| 182 | - // Added for compatibility with WordPress 3.9 (see http://make.wordpress.org/core/2014/04/16/jquery-ui-and-wpdialogs-in-wordpress-3-9/) |
|
| 183 | - wp_enqueue_script( 'wpdialogs' ); |
|
| 184 | - wp_enqueue_style( 'wp-jquery-ui-dialog' ); |
|
| 182 | + // Added for compatibility with WordPress 3.9 (see http://make.wordpress.org/core/2014/04/16/jquery-ui-and-wpdialogs-in-wordpress-3-9/) |
|
| 183 | + wp_enqueue_script( 'wpdialogs' ); |
|
| 184 | + wp_enqueue_style( 'wp-jquery-ui-dialog' ); |
|
| 185 | 185 | |
| 186 | - wp_enqueue_style( 'wordlift-reloaded', plugin_dir_url( __FILE__ ) . 'css/wordlift-reloaded.min.css' ); |
|
| 186 | + wp_enqueue_style( 'wordlift-reloaded', plugin_dir_url( __FILE__ ) . 'css/wordlift-reloaded.min.css' ); |
|
| 187 | 187 | |
| 188 | - wp_enqueue_script( 'jquery-ui-autocomplete' ); |
|
| 189 | - wp_enqueue_script( 'angularjs', 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.11/angular.min.js' ); |
|
| 190 | - wp_enqueue_script( 'angularjs-geolocation', plugin_dir_url( __FILE__ ) . '/bower_components/angularjs-geolocation/dist/angularjs-geolocation.min.js' ); |
|
| 191 | - wp_enqueue_script( 'angularjs-touch', 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.11/angular-touch.min.js' ); |
|
| 192 | - wp_enqueue_script( 'angularjs-animate', 'https://code.angularjs.org/1.3.11/angular-animate.min.js' ); |
|
| 188 | + wp_enqueue_script( 'jquery-ui-autocomplete' ); |
|
| 189 | + wp_enqueue_script( 'angularjs', 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.11/angular.min.js' ); |
|
| 190 | + wp_enqueue_script( 'angularjs-geolocation', plugin_dir_url( __FILE__ ) . '/bower_components/angularjs-geolocation/dist/angularjs-geolocation.min.js' ); |
|
| 191 | + wp_enqueue_script( 'angularjs-touch', 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.11/angular-touch.min.js' ); |
|
| 192 | + wp_enqueue_script( 'angularjs-animate', 'https://code.angularjs.org/1.3.11/angular-animate.min.js' ); |
|
| 193 | 193 | |
| 194 | - // Disable auto-save for custom entity posts only |
|
| 195 | - if ( Wordlift_Entity_Service::TYPE_NAME === get_post_type() ) { |
|
| 196 | - wp_dequeue_script( 'autosave' ); |
|
| 197 | - } |
|
| 194 | + // Disable auto-save for custom entity posts only |
|
| 195 | + if ( Wordlift_Entity_Service::TYPE_NAME === get_post_type() ) { |
|
| 196 | + wp_dequeue_script( 'autosave' ); |
|
| 197 | + } |
|
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | add_action( 'admin_enqueue_scripts', 'wordlift_admin_enqueue_scripts' ); |
| 201 | 201 | |
| 202 | 202 | function wl_enqueue_scripts() { |
| 203 | - wp_enqueue_style( 'wordlift-ui', plugin_dir_url( __FILE__ ) . 'css/wordlift-ui.min.css' ); |
|
| 203 | + wp_enqueue_style( 'wordlift-ui', plugin_dir_url( __FILE__ ) . 'css/wordlift-ui.min.css' ); |
|
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | add_action( 'wp_enqueue_scripts', 'wl_enqueue_scripts' ); |
@@ -215,18 +215,18 @@ discard block |
||
| 215 | 215 | */ |
| 216 | 216 | function wordlift_allowed_html( $allowedtags, $context ) { |
| 217 | 217 | |
| 218 | - if ( 'post' !== $context ) { |
|
| 219 | - return $allowedtags; |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - return array_merge_recursive( $allowedtags, array( |
|
| 223 | - 'span' => array( |
|
| 224 | - 'itemscope' => true, |
|
| 225 | - 'itemtype' => true, |
|
| 226 | - 'itemid' => true, |
|
| 227 | - 'itemprop' => true, |
|
| 228 | - ), |
|
| 229 | - ) ); |
|
| 218 | + if ( 'post' !== $context ) { |
|
| 219 | + return $allowedtags; |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + return array_merge_recursive( $allowedtags, array( |
|
| 223 | + 'span' => array( |
|
| 224 | + 'itemscope' => true, |
|
| 225 | + 'itemtype' => true, |
|
| 226 | + 'itemid' => true, |
|
| 227 | + 'itemprop' => true, |
|
| 228 | + ), |
|
| 229 | + ) ); |
|
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | add_filter( 'wp_kses_allowed_html', 'wordlift_allowed_html', 10, 2 ); |
@@ -240,16 +240,16 @@ discard block |
||
| 240 | 240 | */ |
| 241 | 241 | function wl_get_coordinates( $post_id ) { |
| 242 | 242 | |
| 243 | - $latitude = wl_schema_get_value( $post_id, 'latitude' ); |
|
| 244 | - $longitude = wl_schema_get_value( $post_id, 'longitude' ); |
|
| 243 | + $latitude = wl_schema_get_value( $post_id, 'latitude' ); |
|
| 244 | + $longitude = wl_schema_get_value( $post_id, 'longitude' ); |
|
| 245 | 245 | |
| 246 | - // DO NOT set latitude/longitude to 0/0 as default values. It's a specific |
|
| 247 | - // place on the globe:"The zero/zero point of this system is located in the |
|
| 248 | - // Gulf of Guinea about 625 km (390 mi) south of Tema, Ghana." |
|
| 249 | - return array( |
|
| 250 | - 'latitude' => isset( $latitude[0] ) && is_numeric( $latitude[0] ) ? $latitude[0] : '', |
|
| 251 | - 'longitude' => isset( $longitude[0] ) && is_numeric( $longitude[0] ) ? $longitude[0] : '', |
|
| 252 | - ); |
|
| 246 | + // DO NOT set latitude/longitude to 0/0 as default values. It's a specific |
|
| 247 | + // place on the globe:"The zero/zero point of this system is located in the |
|
| 248 | + // Gulf of Guinea about 625 km (390 mi) south of Tema, Ghana." |
|
| 249 | + return array( |
|
| 250 | + 'latitude' => isset( $latitude[0] ) && is_numeric( $latitude[0] ) ? $latitude[0] : '', |
|
| 251 | + 'longitude' => isset( $longitude[0] ) && is_numeric( $longitude[0] ) ? $longitude[0] : '', |
|
| 252 | + ); |
|
| 253 | 253 | } |
| 254 | 254 | |
| 255 | 255 | /** |
@@ -261,13 +261,13 @@ discard block |
||
| 261 | 261 | */ |
| 262 | 262 | function wl_get_post_modified_time( $post ) { |
| 263 | 263 | |
| 264 | - $date_modified = get_post_modified_time( 'c', true, $post ); |
|
| 264 | + $date_modified = get_post_modified_time( 'c', true, $post ); |
|
| 265 | 265 | |
| 266 | - if ( '-' === substr( $date_modified, 0, 1 ) ) { |
|
| 267 | - return get_the_time( 'c', $post ); |
|
| 268 | - } |
|
| 266 | + if ( '-' === substr( $date_modified, 0, 1 ) ) { |
|
| 267 | + return get_the_time( 'c', $post ); |
|
| 268 | + } |
|
| 269 | 269 | |
| 270 | - return $date_modified; |
|
| 270 | + return $date_modified; |
|
| 271 | 271 | } |
| 272 | 272 | |
| 273 | 273 | /** |
@@ -279,40 +279,40 @@ discard block |
||
| 279 | 279 | */ |
| 280 | 280 | function wl_get_image_urls( $post_id ) { |
| 281 | 281 | |
| 282 | - // If there is a featured image it has the priority. |
|
| 283 | - $featured_image_id = get_post_thumbnail_id( $post_id ); |
|
| 284 | - if ( is_numeric( $featured_image_id ) ) { |
|
| 285 | - $image_url = wp_get_attachment_url( $featured_image_id ); |
|
| 282 | + // If there is a featured image it has the priority. |
|
| 283 | + $featured_image_id = get_post_thumbnail_id( $post_id ); |
|
| 284 | + if ( is_numeric( $featured_image_id ) ) { |
|
| 285 | + $image_url = wp_get_attachment_url( $featured_image_id ); |
|
| 286 | 286 | |
| 287 | - return array( $image_url ); |
|
| 288 | - } |
|
| 287 | + return array( $image_url ); |
|
| 288 | + } |
|
| 289 | 289 | |
| 290 | - $images = get_children( array( |
|
| 291 | - 'post_parent' => $post_id, |
|
| 292 | - 'post_type' => 'attachment', |
|
| 293 | - 'post_mime_type' => 'image', |
|
| 294 | - ) ); |
|
| 290 | + $images = get_children( array( |
|
| 291 | + 'post_parent' => $post_id, |
|
| 292 | + 'post_type' => 'attachment', |
|
| 293 | + 'post_mime_type' => 'image', |
|
| 294 | + ) ); |
|
| 295 | 295 | |
| 296 | - // Return an empty array if no image is found. |
|
| 297 | - if ( empty( $images ) ) { |
|
| 298 | - return array(); |
|
| 299 | - } |
|
| 296 | + // Return an empty array if no image is found. |
|
| 297 | + if ( empty( $images ) ) { |
|
| 298 | + return array(); |
|
| 299 | + } |
|
| 300 | 300 | |
| 301 | - // Prepare the return array. |
|
| 302 | - $image_urls = array(); |
|
| 301 | + // Prepare the return array. |
|
| 302 | + $image_urls = array(); |
|
| 303 | 303 | |
| 304 | - // Collect the URLs. |
|
| 305 | - foreach ( $images as $attachment_id => $attachment ) { |
|
| 306 | - $image_url = wp_get_attachment_url( $attachment_id ); |
|
| 307 | - // Ensure the URL isn't collected already. |
|
| 308 | - if ( ! in_array( $image_url, $image_urls ) ) { |
|
| 309 | - array_push( $image_urls, $image_url ); |
|
| 310 | - } |
|
| 311 | - } |
|
| 304 | + // Collect the URLs. |
|
| 305 | + foreach ( $images as $attachment_id => $attachment ) { |
|
| 306 | + $image_url = wp_get_attachment_url( $attachment_id ); |
|
| 307 | + // Ensure the URL isn't collected already. |
|
| 308 | + if ( ! in_array( $image_url, $image_urls ) ) { |
|
| 309 | + array_push( $image_urls, $image_url ); |
|
| 310 | + } |
|
| 311 | + } |
|
| 312 | 312 | |
| 313 | - // wl_write_log( "wl_get_image_urls [ post id :: $post_id ][ image urls count :: " . count( $image_urls ) . " ]" ); |
|
| 313 | + // wl_write_log( "wl_get_image_urls [ post id :: $post_id ][ image urls count :: " . count( $image_urls ) . " ]" ); |
|
| 314 | 314 | |
| 315 | - return $image_urls; |
|
| 315 | + return $image_urls; |
|
| 316 | 316 | } |
| 317 | 317 | |
| 318 | 318 | /** |
@@ -325,19 +325,19 @@ discard block |
||
| 325 | 325 | */ |
| 326 | 326 | function wl_get_sparql_images( $uri, $post_id ) { |
| 327 | 327 | |
| 328 | - $sparql = ''; |
|
| 328 | + $sparql = ''; |
|
| 329 | 329 | |
| 330 | - // Get the escaped URI. |
|
| 331 | - $uri_e = esc_html( $uri ); |
|
| 330 | + // Get the escaped URI. |
|
| 331 | + $uri_e = esc_html( $uri ); |
|
| 332 | 332 | |
| 333 | - // Add SPARQL stmts to write the schema:image. |
|
| 334 | - $image_urls = wl_get_image_urls( $post_id ); |
|
| 335 | - foreach ( $image_urls as $image_url ) { |
|
| 336 | - $image_url_esc = wl_sparql_escape_uri( $image_url ); |
|
| 337 | - $sparql .= " <$uri_e> schema:image <$image_url_esc> . \n"; |
|
| 338 | - } |
|
| 333 | + // Add SPARQL stmts to write the schema:image. |
|
| 334 | + $image_urls = wl_get_image_urls( $post_id ); |
|
| 335 | + foreach ( $image_urls as $image_url ) { |
|
| 336 | + $image_url_esc = wl_sparql_escape_uri( $image_url ); |
|
| 337 | + $sparql .= " <$uri_e> schema:image <$image_url_esc> . \n"; |
|
| 338 | + } |
|
| 339 | 339 | |
| 340 | - return $sparql; |
|
| 340 | + return $sparql; |
|
| 341 | 341 | } |
| 342 | 342 | |
| 343 | 343 | /** |
@@ -350,24 +350,24 @@ discard block |
||
| 350 | 350 | */ |
| 351 | 351 | function wl_get_attachment_for_source_url( $parent_post_id, $source_url ) { |
| 352 | 352 | |
| 353 | - // wl_write_log( "wl_get_attachment_for_source_url [ parent post id :: $parent_post_id ][ source url :: $source_url ]" ); |
|
| 353 | + // wl_write_log( "wl_get_attachment_for_source_url [ parent post id :: $parent_post_id ][ source url :: $source_url ]" ); |
|
| 354 | 354 | |
| 355 | - $posts = get_posts( array( |
|
| 356 | - 'post_type' => 'attachment', |
|
| 357 | - 'posts_per_page' => 1, |
|
| 358 | - 'post_status' => 'any', |
|
| 359 | - 'post_parent' => $parent_post_id, |
|
| 360 | - 'meta_key' => 'wl_source_url', |
|
| 361 | - 'meta_value' => $source_url, |
|
| 362 | - ) ); |
|
| 355 | + $posts = get_posts( array( |
|
| 356 | + 'post_type' => 'attachment', |
|
| 357 | + 'posts_per_page' => 1, |
|
| 358 | + 'post_status' => 'any', |
|
| 359 | + 'post_parent' => $parent_post_id, |
|
| 360 | + 'meta_key' => 'wl_source_url', |
|
| 361 | + 'meta_value' => $source_url, |
|
| 362 | + ) ); |
|
| 363 | 363 | |
| 364 | - // Return the found post. |
|
| 365 | - if ( 1 === count( $posts ) ) { |
|
| 366 | - return $posts[0]; |
|
| 367 | - } |
|
| 364 | + // Return the found post. |
|
| 365 | + if ( 1 === count( $posts ) ) { |
|
| 366 | + return $posts[0]; |
|
| 367 | + } |
|
| 368 | 368 | |
| 369 | - // Return null. |
|
| 370 | - return null; |
|
| 369 | + // Return null. |
|
| 370 | + return null; |
|
| 371 | 371 | } |
| 372 | 372 | |
| 373 | 373 | /** |
@@ -378,8 +378,8 @@ discard block |
||
| 378 | 378 | */ |
| 379 | 379 | function wl_set_source_url( $post_id, $source_url ) { |
| 380 | 380 | |
| 381 | - delete_post_meta( $post_id, 'wl_source_url' ); |
|
| 382 | - add_post_meta( $post_id, 'wl_source_url', $source_url ); |
|
| 381 | + delete_post_meta( $post_id, 'wl_source_url' ); |
|
| 382 | + add_post_meta( $post_id, 'wl_source_url', $source_url ); |
|
| 383 | 383 | } |
| 384 | 384 | |
| 385 | 385 | |
@@ -397,61 +397,61 @@ discard block |
||
| 397 | 397 | */ |
| 398 | 398 | function wl_flush_rewrite_rules_hard( $hard ) { |
| 399 | 399 | |
| 400 | - // If WL is not yet configured, we cannot perform any update, so we exit. |
|
| 401 | - if ( '' === wl_configuration_get_key() ) { |
|
| 402 | - return; |
|
| 403 | - } |
|
| 400 | + // If WL is not yet configured, we cannot perform any update, so we exit. |
|
| 401 | + if ( '' === wl_configuration_get_key() ) { |
|
| 402 | + return; |
|
| 403 | + } |
|
| 404 | 404 | |
| 405 | - // Set the initial offset and limit each call to 100 posts to avoid memory errors. |
|
| 406 | - $offset = 0; |
|
| 407 | - $limit = 100; |
|
| 405 | + // Set the initial offset and limit each call to 100 posts to avoid memory errors. |
|
| 406 | + $offset = 0; |
|
| 407 | + $limit = 100; |
|
| 408 | 408 | |
| 409 | - // Get more posts if the number of returned posts matches the limit. |
|
| 410 | - while ( $limit === ( $posts = get_posts( array( |
|
| 411 | - 'offset' => $offset, |
|
| 412 | - 'numberposts' => $limit, |
|
| 413 | - 'orderby' => 'ID', |
|
| 414 | - 'post_type' => 'any', |
|
| 415 | - 'post_status' => 'publish', |
|
| 416 | - ) ) ) ) { |
|
| 409 | + // Get more posts if the number of returned posts matches the limit. |
|
| 410 | + while ( $limit === ( $posts = get_posts( array( |
|
| 411 | + 'offset' => $offset, |
|
| 412 | + 'numberposts' => $limit, |
|
| 413 | + 'orderby' => 'ID', |
|
| 414 | + 'post_type' => 'any', |
|
| 415 | + 'post_status' => 'publish', |
|
| 416 | + ) ) ) ) { |
|
| 417 | 417 | |
| 418 | - // Holds the delete part of the query. |
|
| 419 | - $delete_query = rl_sparql_prefixes(); |
|
| 418 | + // Holds the delete part of the query. |
|
| 419 | + $delete_query = rl_sparql_prefixes(); |
|
| 420 | 420 | |
| 421 | - // Holds the insert part of the query. |
|
| 422 | - $insert_query = ''; |
|
| 421 | + // Holds the insert part of the query. |
|
| 422 | + $insert_query = ''; |
|
| 423 | 423 | |
| 424 | - // Cycle in each post to build the query. |
|
| 425 | - foreach ( $posts as $post ) { |
|
| 424 | + // Cycle in each post to build the query. |
|
| 425 | + foreach ( $posts as $post ) { |
|
| 426 | 426 | |
| 427 | - // Ignore revisions. |
|
| 428 | - if ( wp_is_post_revision( $post->ID ) ) { |
|
| 429 | - continue; |
|
| 430 | - } |
|
| 427 | + // Ignore revisions. |
|
| 428 | + if ( wp_is_post_revision( $post->ID ) ) { |
|
| 429 | + continue; |
|
| 430 | + } |
|
| 431 | 431 | |
| 432 | - // Get the entity URI. |
|
| 433 | - $s = Wordlift_Sparql_Service::escape_uri( Wordlift_Entity_Service::get_instance() |
|
| 434 | - ->get_uri( $post->ID ) ); |
|
| 432 | + // Get the entity URI. |
|
| 433 | + $s = Wordlift_Sparql_Service::escape_uri( Wordlift_Entity_Service::get_instance() |
|
| 434 | + ->get_uri( $post->ID ) ); |
|
| 435 | 435 | |
| 436 | - // Get the post URL. |
|
| 437 | - // $url = wl_sparql_escape_uri( get_permalink( $post->ID ) ); |
|
| 436 | + // Get the post URL. |
|
| 437 | + // $url = wl_sparql_escape_uri( get_permalink( $post->ID ) ); |
|
| 438 | 438 | |
| 439 | - // Prepare the DELETE and INSERT commands. |
|
| 440 | - $delete_query .= "DELETE { <$s> schema:url ?u . } WHERE { <$s> schema:url ?u . };\n"; |
|
| 439 | + // Prepare the DELETE and INSERT commands. |
|
| 440 | + $delete_query .= "DELETE { <$s> schema:url ?u . } WHERE { <$s> schema:url ?u . };\n"; |
|
| 441 | 441 | |
| 442 | - $insert_query .= Wordlift_Schema_Url_Property_Service::get_instance() |
|
| 443 | - ->get_insert_query( $s, $post->ID ); |
|
| 442 | + $insert_query .= Wordlift_Schema_Url_Property_Service::get_instance() |
|
| 443 | + ->get_insert_query( $s, $post->ID ); |
|
| 444 | 444 | |
| 445 | - } |
|
| 445 | + } |
|
| 446 | 446 | |
| 447 | 447 | |
| 448 | - // Execute the query. |
|
| 449 | - rl_execute_sparql_update_query( $delete_query . $insert_query ); |
|
| 448 | + // Execute the query. |
|
| 449 | + rl_execute_sparql_update_query( $delete_query . $insert_query ); |
|
| 450 | 450 | |
| 451 | - // Advance to the next posts. |
|
| 452 | - $offset += $limit; |
|
| 451 | + // Advance to the next posts. |
|
| 452 | + $offset += $limit; |
|
| 453 | 453 | |
| 454 | - } |
|
| 454 | + } |
|
| 455 | 455 | |
| 456 | 456 | // // Get all published posts. |
| 457 | 457 | // $posts = get_posts( array( |
@@ -477,7 +477,7 @@ discard block |
||
| 477 | 477 | */ |
| 478 | 478 | function wl_sanitize_uri_path( $path, $char = '_' ) { |
| 479 | 479 | |
| 480 | - return Wordlift_Uri_Service::get_instance()->sanitize_path( $path, $char ); |
|
| 480 | + return Wordlift_Uri_Service::get_instance()->sanitize_path( $path, $char ); |
|
| 481 | 481 | } |
| 482 | 482 | |
| 483 | 483 | /** |
@@ -489,11 +489,11 @@ discard block |
||
| 489 | 489 | */ |
| 490 | 490 | function wl_force_to_array( $value ) { |
| 491 | 491 | |
| 492 | - if ( ! is_array( $value ) ) { |
|
| 493 | - return array( $value ); |
|
| 494 | - } |
|
| 492 | + if ( ! is_array( $value ) ) { |
|
| 493 | + return array( $value ); |
|
| 494 | + } |
|
| 495 | 495 | |
| 496 | - return $value; |
|
| 496 | + return $value; |
|
| 497 | 497 | } |
| 498 | 498 | |
| 499 | 499 | /** |
@@ -501,26 +501,26 @@ discard block |
||
| 501 | 501 | */ |
| 502 | 502 | function wl_shutdown() { |
| 503 | 503 | |
| 504 | - // Get the filename to the temporary SPARQL file. |
|
| 505 | - $filename = WL_TEMP_DIR . WL_REQUEST_ID . '.sparql'; |
|
| 504 | + // Get the filename to the temporary SPARQL file. |
|
| 505 | + $filename = WL_TEMP_DIR . WL_REQUEST_ID . '.sparql'; |
|
| 506 | 506 | |
| 507 | - // If WordLift is buffering SPARQL queries, we're admins and a buffer exists, then schedule it. |
|
| 508 | - if ( WL_ENABLE_SPARQL_UPDATE_QUERIES_BUFFERING && is_admin() && file_exists( $filename ) ) { |
|
| 507 | + // If WordLift is buffering SPARQL queries, we're admins and a buffer exists, then schedule it. |
|
| 508 | + if ( WL_ENABLE_SPARQL_UPDATE_QUERIES_BUFFERING && is_admin() && file_exists( $filename ) ) { |
|
| 509 | 509 | |
| 510 | - // The request ID. |
|
| 511 | - $args = array( WL_REQUEST_ID ); |
|
| 510 | + // The request ID. |
|
| 511 | + $args = array( WL_REQUEST_ID ); |
|
| 512 | 512 | |
| 513 | - // Schedule the execution of the SPARQL query with the request ID. |
|
| 514 | - wp_schedule_single_event( time(), 'wl_execute_saved_sparql_update_query', $args ); |
|
| 513 | + // Schedule the execution of the SPARQL query with the request ID. |
|
| 514 | + wp_schedule_single_event( time(), 'wl_execute_saved_sparql_update_query', $args ); |
|
| 515 | 515 | |
| 516 | - // Check that the request is scheduled. |
|
| 517 | - $timestamp = wp_next_scheduled( 'wl_execute_saved_sparql_update_query', $args ); |
|
| 516 | + // Check that the request is scheduled. |
|
| 517 | + $timestamp = wp_next_scheduled( 'wl_execute_saved_sparql_update_query', $args ); |
|
| 518 | 518 | |
| 519 | - // Spawn the cron. |
|
| 520 | - spawn_cron(); |
|
| 519 | + // Spawn the cron. |
|
| 520 | + spawn_cron(); |
|
| 521 | 521 | |
| 522 | - wl_write_log( "wl_shutdown [ request id :: " . WL_REQUEST_ID . " ][ timestamp :: $timestamp ]" ); |
|
| 523 | - } |
|
| 522 | + wl_write_log( "wl_shutdown [ request id :: " . WL_REQUEST_ID . " ][ timestamp :: $timestamp ]" ); |
|
| 523 | + } |
|
| 524 | 524 | } |
| 525 | 525 | |
| 526 | 526 | add_action( 'shutdown', 'wl_shutdown' ); |
@@ -534,46 +534,46 @@ discard block |
||
| 534 | 534 | */ |
| 535 | 535 | function wl_replace_item_id_with_uri( $content ) { |
| 536 | 536 | |
| 537 | - // wl_write_log( "wl_replace_item_id_with_uri" ); |
|
| 537 | + // wl_write_log( "wl_replace_item_id_with_uri" ); |
|
| 538 | 538 | |
| 539 | - // Strip slashes, see https://core.trac.wordpress.org/ticket/21767 |
|
| 540 | - $content = stripslashes( $content ); |
|
| 539 | + // Strip slashes, see https://core.trac.wordpress.org/ticket/21767 |
|
| 540 | + $content = stripslashes( $content ); |
|
| 541 | 541 | |
| 542 | - // If any match are found. |
|
| 543 | - $matches = array(); |
|
| 544 | - if ( 0 < preg_match_all( '/ itemid="([^"]+)"/i', $content, $matches, PREG_SET_ORDER ) ) { |
|
| 542 | + // If any match are found. |
|
| 543 | + $matches = array(); |
|
| 544 | + if ( 0 < preg_match_all( '/ itemid="([^"]+)"/i', $content, $matches, PREG_SET_ORDER ) ) { |
|
| 545 | 545 | |
| 546 | - foreach ( $matches as $match ) { |
|
| 546 | + foreach ( $matches as $match ) { |
|
| 547 | 547 | |
| 548 | - // Get the item ID. |
|
| 549 | - $item_id = $match[1]; |
|
| 548 | + // Get the item ID. |
|
| 549 | + $item_id = $match[1]; |
|
| 550 | 550 | |
| 551 | - // Get the post bound to that item ID (looking both in the 'official' URI and in the 'same-as' . |
|
| 552 | - $post = Wordlift_Entity_Service::get_instance() |
|
| 553 | - ->get_entity_post_by_uri( $item_id ); |
|
| 551 | + // Get the post bound to that item ID (looking both in the 'official' URI and in the 'same-as' . |
|
| 552 | + $post = Wordlift_Entity_Service::get_instance() |
|
| 553 | + ->get_entity_post_by_uri( $item_id ); |
|
| 554 | 554 | |
| 555 | - // If no entity is found, continue to the next one. |
|
| 556 | - if ( null === $post ) { |
|
| 557 | - continue; |
|
| 558 | - } |
|
| 555 | + // If no entity is found, continue to the next one. |
|
| 556 | + if ( null === $post ) { |
|
| 557 | + continue; |
|
| 558 | + } |
|
| 559 | 559 | |
| 560 | - // Get the URI for that post. |
|
| 561 | - $uri = wl_get_entity_uri( $post->ID ); |
|
| 560 | + // Get the URI for that post. |
|
| 561 | + $uri = wl_get_entity_uri( $post->ID ); |
|
| 562 | 562 | |
| 563 | - // wl_write_log( "wl_replace_item_id_with_uri [ item id :: $item_id ][ uri :: $uri ]" ); |
|
| 563 | + // wl_write_log( "wl_replace_item_id_with_uri [ item id :: $item_id ][ uri :: $uri ]" ); |
|
| 564 | 564 | |
| 565 | - // If the item ID and the URI differ, replace the item ID with the URI saved in WordPress. |
|
| 566 | - if ( $item_id !== $uri ) { |
|
| 567 | - $uri_e = esc_html( $uri ); |
|
| 568 | - $content = str_replace( " itemid=\"$item_id\"", " itemid=\"$uri_e\"", $content ); |
|
| 569 | - } |
|
| 570 | - } |
|
| 571 | - } |
|
| 565 | + // If the item ID and the URI differ, replace the item ID with the URI saved in WordPress. |
|
| 566 | + if ( $item_id !== $uri ) { |
|
| 567 | + $uri_e = esc_html( $uri ); |
|
| 568 | + $content = str_replace( " itemid=\"$item_id\"", " itemid=\"$uri_e\"", $content ); |
|
| 569 | + } |
|
| 570 | + } |
|
| 571 | + } |
|
| 572 | 572 | |
| 573 | - // Reapply slashes. |
|
| 574 | - $content = addslashes( $content ); |
|
| 573 | + // Reapply slashes. |
|
| 574 | + $content = addslashes( $content ); |
|
| 575 | 575 | |
| 576 | - return $content; |
|
| 576 | + return $content; |
|
| 577 | 577 | } |
| 578 | 578 | |
| 579 | 579 | add_filter( 'content_save_pre', 'wl_replace_item_id_with_uri', 1, 1 ); |
@@ -646,8 +646,8 @@ discard block |
||
| 646 | 646 | * This action is documented in includes/class-wordlift-activator.php |
| 647 | 647 | */ |
| 648 | 648 | function activate_wordlift() { |
| 649 | - require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-activator.php'; |
|
| 650 | - Wordlift_Activator::activate(); |
|
| 649 | + require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-activator.php'; |
|
| 650 | + Wordlift_Activator::activate(); |
|
| 651 | 651 | } |
| 652 | 652 | |
| 653 | 653 | /** |
@@ -655,8 +655,8 @@ discard block |
||
| 655 | 655 | * This action is documented in includes/class-wordlift-deactivator.php |
| 656 | 656 | */ |
| 657 | 657 | function deactivate_wordlift() { |
| 658 | - require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-deactivator.php'; |
|
| 659 | - Wordlift_Deactivator::deactivate(); |
|
| 658 | + require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-deactivator.php'; |
|
| 659 | + Wordlift_Deactivator::deactivate(); |
|
| 660 | 660 | } |
| 661 | 661 | |
| 662 | 662 | register_activation_hook( __FILE__, 'activate_wordlift' ); |
@@ -679,8 +679,8 @@ discard block |
||
| 679 | 679 | */ |
| 680 | 680 | function run_wordlift() { |
| 681 | 681 | |
| 682 | - $plugin = new Wordlift(); |
|
| 683 | - $plugin->run(); |
|
| 682 | + $plugin = new Wordlift(); |
|
| 683 | + $plugin->run(); |
|
| 684 | 684 | |
| 685 | 685 | } |
| 686 | 686 | |
@@ -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 | } |
| 54 | 54 | |
@@ -62,19 +62,19 @@ discard block |
||
| 62 | 62 | * @param string|array $log The log data. |
| 63 | 63 | * @param string $caller The calling function. |
| 64 | 64 | */ |
| 65 | -function wl_write_log_handler( $log, $caller = null ) { |
|
| 65 | +function wl_write_log_handler($log, $caller = null) { |
|
| 66 | 66 | |
| 67 | 67 | global $wl_logger; |
| 68 | 68 | |
| 69 | - if ( true === WP_DEBUG ) { |
|
| 69 | + if (true === WP_DEBUG) { |
|
| 70 | 70 | |
| 71 | - $message = ( isset( $caller ) ? sprintf( '[%-40.40s] ', $caller ) : '' ) . |
|
| 72 | - ( is_array( $log ) || is_object( $log ) ? print_r( $log, true ) : wl_write_log_hide_key( $log ) ); |
|
| 71 | + $message = (isset($caller) ? sprintf('[%-40.40s] ', $caller) : ''). |
|
| 72 | + (is_array($log) || is_object($log) ? print_r($log, true) : wl_write_log_hide_key($log)); |
|
| 73 | 73 | |
| 74 | - if ( isset( $wl_logger ) ) { |
|
| 75 | - $wl_logger->info( $message ); |
|
| 74 | + if (isset($wl_logger)) { |
|
| 75 | + $wl_logger->info($message); |
|
| 76 | 76 | } else { |
| 77 | - error_log( $message ); |
|
| 77 | + error_log($message); |
|
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | } |
@@ -92,9 +92,9 @@ discard block |
||
| 92 | 92 | * |
| 93 | 93 | * @return string A text with the key hidden. |
| 94 | 94 | */ |
| 95 | -function wl_write_log_hide_key( $text ) { |
|
| 95 | +function wl_write_log_hide_key($text) { |
|
| 96 | 96 | |
| 97 | - return str_ireplace( wl_configuration_get_key(), '<hidden>', $text ); |
|
| 97 | + return str_ireplace(wl_configuration_get_key(), '<hidden>', $text); |
|
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | /** |
@@ -104,12 +104,12 @@ discard block |
||
| 104 | 104 | * |
| 105 | 105 | * @param string $query A SPARQL query. |
| 106 | 106 | */ |
| 107 | -function wl_queue_sparql_update_query( $query ) { |
|
| 107 | +function wl_queue_sparql_update_query($query) { |
|
| 108 | 108 | |
| 109 | - $filename = WL_TEMP_DIR . WL_REQUEST_ID . '.sparql'; |
|
| 110 | - file_put_contents( $filename, $query . "\n", FILE_APPEND ); |
|
| 109 | + $filename = WL_TEMP_DIR.WL_REQUEST_ID.'.sparql'; |
|
| 110 | + file_put_contents($filename, $query."\n", FILE_APPEND); |
|
| 111 | 111 | |
| 112 | - wl_write_log( "wl_queue_sparql_update_query [ filename :: $filename ]" ); |
|
| 112 | + wl_write_log("wl_queue_sparql_update_query [ filename :: $filename ]"); |
|
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | /** |
@@ -117,33 +117,33 @@ discard block |
||
| 117 | 117 | * |
| 118 | 118 | * @param int $request_id The request ID. |
| 119 | 119 | */ |
| 120 | -function wl_execute_saved_sparql_update_query( $request_id ) { |
|
| 120 | +function wl_execute_saved_sparql_update_query($request_id) { |
|
| 121 | 121 | |
| 122 | - $filename = WL_TEMP_DIR . $request_id . '.sparql'; |
|
| 122 | + $filename = WL_TEMP_DIR.$request_id.'.sparql'; |
|
| 123 | 123 | |
| 124 | 124 | // If the file doesn't exist, exit. |
| 125 | - if ( ! file_exists( $filename ) ) { |
|
| 126 | - wl_write_log( "wl_execute_saved_sparql_update_query : file doesn't exist [ filename :: $filename ]" ); |
|
| 125 | + if ( ! file_exists($filename)) { |
|
| 126 | + wl_write_log("wl_execute_saved_sparql_update_query : file doesn't exist [ filename :: $filename ]"); |
|
| 127 | 127 | |
| 128 | 128 | return; |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | - wl_write_log( "wl_execute_saved_sparql_update_query [ filename :: $filename ]" ); |
|
| 131 | + wl_write_log("wl_execute_saved_sparql_update_query [ filename :: $filename ]"); |
|
| 132 | 132 | |
| 133 | 133 | // Get the query saved in the file. |
| 134 | - $query = file_get_contents( $filename ); |
|
| 134 | + $query = file_get_contents($filename); |
|
| 135 | 135 | |
| 136 | 136 | // Execute the SPARQL query. |
| 137 | - rl_execute_sparql_update_query( $query, false ); |
|
| 137 | + rl_execute_sparql_update_query($query, false); |
|
| 138 | 138 | |
| 139 | 139 | // Reindex the triple store. |
| 140 | 140 | wordlift_reindex_triple_store(); |
| 141 | 141 | |
| 142 | 142 | // Delete the temporary file. |
| 143 | - unlink( $filename ); |
|
| 143 | + unlink($filename); |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | -add_action( 'wl_execute_saved_sparql_update_query', 'wl_execute_saved_sparql_update_query', 10, 1 ); |
|
| 146 | +add_action('wl_execute_saved_sparql_update_query', 'wl_execute_saved_sparql_update_query', 10, 1); |
|
| 147 | 147 | |
| 148 | 148 | /** |
| 149 | 149 | * Enable microdata schema.org tagging. |
@@ -152,7 +152,7 @@ discard block |
||
| 152 | 152 | function wordlift_allowed_post_tags() { |
| 153 | 153 | global $allowedposttags; |
| 154 | 154 | |
| 155 | - $tags = array( 'span' ); |
|
| 155 | + $tags = array('span'); |
|
| 156 | 156 | $new_attributes = array( |
| 157 | 157 | 'itemscope' => array(), |
| 158 | 158 | 'itemtype' => array(), |
@@ -160,9 +160,9 @@ discard block |
||
| 160 | 160 | 'itemid' => array(), |
| 161 | 161 | ); |
| 162 | 162 | |
| 163 | - foreach ( $tags as $tag ) { |
|
| 164 | - if ( isset( $allowedposttags[ $tag ] ) && is_array( $allowedposttags[ $tag ] ) ) { |
|
| 165 | - $allowedposttags[ $tag ] = array_merge( $allowedposttags[ $tag ], $new_attributes ); |
|
| 163 | + foreach ($tags as $tag) { |
|
| 164 | + if (isset($allowedposttags[$tag]) && is_array($allowedposttags[$tag])) { |
|
| 165 | + $allowedposttags[$tag] = array_merge($allowedposttags[$tag], $new_attributes); |
|
| 166 | 166 | } |
| 167 | 167 | } |
| 168 | 168 | } |
@@ -171,7 +171,7 @@ discard block |
||
| 171 | 171 | //add_action( 'init', 'wordlift_buttonhooks' ); |
| 172 | 172 | |
| 173 | 173 | // add allowed post tags. |
| 174 | -add_action( 'init', 'wordlift_allowed_post_tags' ); |
|
| 174 | +add_action('init', 'wordlift_allowed_post_tags'); |
|
| 175 | 175 | |
| 176 | 176 | |
| 177 | 177 | /** |
@@ -180,30 +180,30 @@ discard block |
||
| 180 | 180 | function wordlift_admin_enqueue_scripts() { |
| 181 | 181 | |
| 182 | 182 | // Added for compatibility with WordPress 3.9 (see http://make.wordpress.org/core/2014/04/16/jquery-ui-and-wpdialogs-in-wordpress-3-9/) |
| 183 | - wp_enqueue_script( 'wpdialogs' ); |
|
| 184 | - wp_enqueue_style( 'wp-jquery-ui-dialog' ); |
|
| 183 | + wp_enqueue_script('wpdialogs'); |
|
| 184 | + wp_enqueue_style('wp-jquery-ui-dialog'); |
|
| 185 | 185 | |
| 186 | - wp_enqueue_style( 'wordlift-reloaded', plugin_dir_url( __FILE__ ) . 'css/wordlift-reloaded.min.css' ); |
|
| 186 | + wp_enqueue_style('wordlift-reloaded', plugin_dir_url(__FILE__).'css/wordlift-reloaded.min.css'); |
|
| 187 | 187 | |
| 188 | - wp_enqueue_script( 'jquery-ui-autocomplete' ); |
|
| 189 | - wp_enqueue_script( 'angularjs', 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.11/angular.min.js' ); |
|
| 190 | - wp_enqueue_script( 'angularjs-geolocation', plugin_dir_url( __FILE__ ) . '/bower_components/angularjs-geolocation/dist/angularjs-geolocation.min.js' ); |
|
| 191 | - wp_enqueue_script( 'angularjs-touch', 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.11/angular-touch.min.js' ); |
|
| 192 | - wp_enqueue_script( 'angularjs-animate', 'https://code.angularjs.org/1.3.11/angular-animate.min.js' ); |
|
| 188 | + wp_enqueue_script('jquery-ui-autocomplete'); |
|
| 189 | + wp_enqueue_script('angularjs', 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.11/angular.min.js'); |
|
| 190 | + wp_enqueue_script('angularjs-geolocation', plugin_dir_url(__FILE__).'/bower_components/angularjs-geolocation/dist/angularjs-geolocation.min.js'); |
|
| 191 | + wp_enqueue_script('angularjs-touch', 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.11/angular-touch.min.js'); |
|
| 192 | + wp_enqueue_script('angularjs-animate', 'https://code.angularjs.org/1.3.11/angular-animate.min.js'); |
|
| 193 | 193 | |
| 194 | 194 | // Disable auto-save for custom entity posts only |
| 195 | - if ( Wordlift_Entity_Service::TYPE_NAME === get_post_type() ) { |
|
| 196 | - wp_dequeue_script( 'autosave' ); |
|
| 195 | + if (Wordlift_Entity_Service::TYPE_NAME === get_post_type()) { |
|
| 196 | + wp_dequeue_script('autosave'); |
|
| 197 | 197 | } |
| 198 | 198 | } |
| 199 | 199 | |
| 200 | -add_action( 'admin_enqueue_scripts', 'wordlift_admin_enqueue_scripts' ); |
|
| 200 | +add_action('admin_enqueue_scripts', 'wordlift_admin_enqueue_scripts'); |
|
| 201 | 201 | |
| 202 | 202 | function wl_enqueue_scripts() { |
| 203 | - wp_enqueue_style( 'wordlift-ui', plugin_dir_url( __FILE__ ) . 'css/wordlift-ui.min.css' ); |
|
| 203 | + wp_enqueue_style('wordlift-ui', plugin_dir_url(__FILE__).'css/wordlift-ui.min.css'); |
|
| 204 | 204 | } |
| 205 | 205 | |
| 206 | -add_action( 'wp_enqueue_scripts', 'wl_enqueue_scripts' ); |
|
| 206 | +add_action('wp_enqueue_scripts', 'wl_enqueue_scripts'); |
|
| 207 | 207 | |
| 208 | 208 | /** |
| 209 | 209 | * Hooked to *wp_kses_allowed_html* filter, adds microdata attributes. |
@@ -213,23 +213,23 @@ discard block |
||
| 213 | 213 | * |
| 214 | 214 | * @return array An array which contains allowed microdata attributes. |
| 215 | 215 | */ |
| 216 | -function wordlift_allowed_html( $allowedtags, $context ) { |
|
| 216 | +function wordlift_allowed_html($allowedtags, $context) { |
|
| 217 | 217 | |
| 218 | - if ( 'post' !== $context ) { |
|
| 218 | + if ('post' !== $context) { |
|
| 219 | 219 | return $allowedtags; |
| 220 | 220 | } |
| 221 | 221 | |
| 222 | - return array_merge_recursive( $allowedtags, array( |
|
| 222 | + return array_merge_recursive($allowedtags, array( |
|
| 223 | 223 | 'span' => array( |
| 224 | 224 | 'itemscope' => true, |
| 225 | 225 | 'itemtype' => true, |
| 226 | 226 | 'itemid' => true, |
| 227 | 227 | 'itemprop' => true, |
| 228 | 228 | ), |
| 229 | - ) ); |
|
| 229 | + )); |
|
| 230 | 230 | } |
| 231 | 231 | |
| 232 | -add_filter( 'wp_kses_allowed_html', 'wordlift_allowed_html', 10, 2 ); |
|
| 232 | +add_filter('wp_kses_allowed_html', 'wordlift_allowed_html', 10, 2); |
|
| 233 | 233 | |
| 234 | 234 | /** |
| 235 | 235 | * Get the coordinates for the specified post ID. |
@@ -238,17 +238,17 @@ discard block |
||
| 238 | 238 | * |
| 239 | 239 | * @return array|null An array of coordinates or null. |
| 240 | 240 | */ |
| 241 | -function wl_get_coordinates( $post_id ) { |
|
| 241 | +function wl_get_coordinates($post_id) { |
|
| 242 | 242 | |
| 243 | - $latitude = wl_schema_get_value( $post_id, 'latitude' ); |
|
| 244 | - $longitude = wl_schema_get_value( $post_id, 'longitude' ); |
|
| 243 | + $latitude = wl_schema_get_value($post_id, 'latitude'); |
|
| 244 | + $longitude = wl_schema_get_value($post_id, 'longitude'); |
|
| 245 | 245 | |
| 246 | 246 | // DO NOT set latitude/longitude to 0/0 as default values. It's a specific |
| 247 | 247 | // place on the globe:"The zero/zero point of this system is located in the |
| 248 | 248 | // Gulf of Guinea about 625 km (390 mi) south of Tema, Ghana." |
| 249 | 249 | return array( |
| 250 | - 'latitude' => isset( $latitude[0] ) && is_numeric( $latitude[0] ) ? $latitude[0] : '', |
|
| 251 | - 'longitude' => isset( $longitude[0] ) && is_numeric( $longitude[0] ) ? $longitude[0] : '', |
|
| 250 | + 'latitude' => isset($latitude[0]) && is_numeric($latitude[0]) ? $latitude[0] : '', |
|
| 251 | + 'longitude' => isset($longitude[0]) && is_numeric($longitude[0]) ? $longitude[0] : '', |
|
| 252 | 252 | ); |
| 253 | 253 | } |
| 254 | 254 | |
@@ -259,12 +259,12 @@ discard block |
||
| 259 | 259 | * |
| 260 | 260 | * @return string A datetime. |
| 261 | 261 | */ |
| 262 | -function wl_get_post_modified_time( $post ) { |
|
| 262 | +function wl_get_post_modified_time($post) { |
|
| 263 | 263 | |
| 264 | - $date_modified = get_post_modified_time( 'c', true, $post ); |
|
| 264 | + $date_modified = get_post_modified_time('c', true, $post); |
|
| 265 | 265 | |
| 266 | - if ( '-' === substr( $date_modified, 0, 1 ) ) { |
|
| 267 | - return get_the_time( 'c', $post ); |
|
| 266 | + if ('-' === substr($date_modified, 0, 1)) { |
|
| 267 | + return get_the_time('c', $post); |
|
| 268 | 268 | } |
| 269 | 269 | |
| 270 | 270 | return $date_modified; |
@@ -277,24 +277,24 @@ discard block |
||
| 277 | 277 | * |
| 278 | 278 | * @return array An array of image URLs. |
| 279 | 279 | */ |
| 280 | -function wl_get_image_urls( $post_id ) { |
|
| 280 | +function wl_get_image_urls($post_id) { |
|
| 281 | 281 | |
| 282 | 282 | // If there is a featured image it has the priority. |
| 283 | - $featured_image_id = get_post_thumbnail_id( $post_id ); |
|
| 284 | - if ( is_numeric( $featured_image_id ) ) { |
|
| 285 | - $image_url = wp_get_attachment_url( $featured_image_id ); |
|
| 283 | + $featured_image_id = get_post_thumbnail_id($post_id); |
|
| 284 | + if (is_numeric($featured_image_id)) { |
|
| 285 | + $image_url = wp_get_attachment_url($featured_image_id); |
|
| 286 | 286 | |
| 287 | - return array( $image_url ); |
|
| 287 | + return array($image_url); |
|
| 288 | 288 | } |
| 289 | 289 | |
| 290 | - $images = get_children( array( |
|
| 290 | + $images = get_children(array( |
|
| 291 | 291 | 'post_parent' => $post_id, |
| 292 | 292 | 'post_type' => 'attachment', |
| 293 | 293 | 'post_mime_type' => 'image', |
| 294 | - ) ); |
|
| 294 | + )); |
|
| 295 | 295 | |
| 296 | 296 | // Return an empty array if no image is found. |
| 297 | - if ( empty( $images ) ) { |
|
| 297 | + if (empty($images)) { |
|
| 298 | 298 | return array(); |
| 299 | 299 | } |
| 300 | 300 | |
@@ -302,11 +302,11 @@ discard block |
||
| 302 | 302 | $image_urls = array(); |
| 303 | 303 | |
| 304 | 304 | // Collect the URLs. |
| 305 | - foreach ( $images as $attachment_id => $attachment ) { |
|
| 306 | - $image_url = wp_get_attachment_url( $attachment_id ); |
|
| 305 | + foreach ($images as $attachment_id => $attachment) { |
|
| 306 | + $image_url = wp_get_attachment_url($attachment_id); |
|
| 307 | 307 | // Ensure the URL isn't collected already. |
| 308 | - if ( ! in_array( $image_url, $image_urls ) ) { |
|
| 309 | - array_push( $image_urls, $image_url ); |
|
| 308 | + if ( ! in_array($image_url, $image_urls)) { |
|
| 309 | + array_push($image_urls, $image_url); |
|
| 310 | 310 | } |
| 311 | 311 | } |
| 312 | 312 | |
@@ -323,18 +323,18 @@ discard block |
||
| 323 | 323 | * |
| 324 | 324 | * @return string The SPARQL fragment. |
| 325 | 325 | */ |
| 326 | -function wl_get_sparql_images( $uri, $post_id ) { |
|
| 326 | +function wl_get_sparql_images($uri, $post_id) { |
|
| 327 | 327 | |
| 328 | 328 | $sparql = ''; |
| 329 | 329 | |
| 330 | 330 | // Get the escaped URI. |
| 331 | - $uri_e = esc_html( $uri ); |
|
| 331 | + $uri_e = esc_html($uri); |
|
| 332 | 332 | |
| 333 | 333 | // Add SPARQL stmts to write the schema:image. |
| 334 | - $image_urls = wl_get_image_urls( $post_id ); |
|
| 335 | - foreach ( $image_urls as $image_url ) { |
|
| 336 | - $image_url_esc = wl_sparql_escape_uri( $image_url ); |
|
| 337 | - $sparql .= " <$uri_e> schema:image <$image_url_esc> . \n"; |
|
| 334 | + $image_urls = wl_get_image_urls($post_id); |
|
| 335 | + foreach ($image_urls as $image_url) { |
|
| 336 | + $image_url_esc = wl_sparql_escape_uri($image_url); |
|
| 337 | + $sparql .= " <$uri_e> schema:image <$image_url_esc> . \n"; |
|
| 338 | 338 | } |
| 339 | 339 | |
| 340 | 340 | return $sparql; |
@@ -348,21 +348,21 @@ discard block |
||
| 348 | 348 | * |
| 349 | 349 | * @return WP_Post|null A post instance or null if not found. |
| 350 | 350 | */ |
| 351 | -function wl_get_attachment_for_source_url( $parent_post_id, $source_url ) { |
|
| 351 | +function wl_get_attachment_for_source_url($parent_post_id, $source_url) { |
|
| 352 | 352 | |
| 353 | 353 | // wl_write_log( "wl_get_attachment_for_source_url [ parent post id :: $parent_post_id ][ source url :: $source_url ]" ); |
| 354 | 354 | |
| 355 | - $posts = get_posts( array( |
|
| 355 | + $posts = get_posts(array( |
|
| 356 | 356 | 'post_type' => 'attachment', |
| 357 | 357 | 'posts_per_page' => 1, |
| 358 | 358 | 'post_status' => 'any', |
| 359 | 359 | 'post_parent' => $parent_post_id, |
| 360 | 360 | 'meta_key' => 'wl_source_url', |
| 361 | 361 | 'meta_value' => $source_url, |
| 362 | - ) ); |
|
| 362 | + )); |
|
| 363 | 363 | |
| 364 | 364 | // Return the found post. |
| 365 | - if ( 1 === count( $posts ) ) { |
|
| 365 | + if (1 === count($posts)) { |
|
| 366 | 366 | return $posts[0]; |
| 367 | 367 | } |
| 368 | 368 | |
@@ -376,10 +376,10 @@ discard block |
||
| 376 | 376 | * @param int $post_id The post ID. |
| 377 | 377 | * @param string $source_url The source URL. |
| 378 | 378 | */ |
| 379 | -function wl_set_source_url( $post_id, $source_url ) { |
|
| 379 | +function wl_set_source_url($post_id, $source_url) { |
|
| 380 | 380 | |
| 381 | - delete_post_meta( $post_id, 'wl_source_url' ); |
|
| 382 | - add_post_meta( $post_id, 'wl_source_url', $source_url ); |
|
| 381 | + delete_post_meta($post_id, 'wl_source_url'); |
|
| 382 | + add_post_meta($post_id, 'wl_source_url', $source_url); |
|
| 383 | 383 | } |
| 384 | 384 | |
| 385 | 385 | |
@@ -395,10 +395,10 @@ discard block |
||
| 395 | 395 | * |
| 396 | 396 | * @param bool $hard True if the rewrite involves configuration updates in Apache/IIS. |
| 397 | 397 | */ |
| 398 | -function wl_flush_rewrite_rules_hard( $hard ) { |
|
| 398 | +function wl_flush_rewrite_rules_hard($hard) { |
|
| 399 | 399 | |
| 400 | 400 | // If WL is not yet configured, we cannot perform any update, so we exit. |
| 401 | - if ( '' === wl_configuration_get_key() ) { |
|
| 401 | + if ('' === wl_configuration_get_key()) { |
|
| 402 | 402 | return; |
| 403 | 403 | } |
| 404 | 404 | |
@@ -407,13 +407,13 @@ discard block |
||
| 407 | 407 | $limit = 100; |
| 408 | 408 | |
| 409 | 409 | // Get more posts if the number of returned posts matches the limit. |
| 410 | - while ( $limit === ( $posts = get_posts( array( |
|
| 410 | + while ($limit === ($posts = get_posts(array( |
|
| 411 | 411 | 'offset' => $offset, |
| 412 | 412 | 'numberposts' => $limit, |
| 413 | 413 | 'orderby' => 'ID', |
| 414 | 414 | 'post_type' => 'any', |
| 415 | 415 | 'post_status' => 'publish', |
| 416 | - ) ) ) ) { |
|
| 416 | + )))) { |
|
| 417 | 417 | |
| 418 | 418 | // Holds the delete part of the query. |
| 419 | 419 | $delete_query = rl_sparql_prefixes(); |
@@ -422,16 +422,16 @@ discard block |
||
| 422 | 422 | $insert_query = ''; |
| 423 | 423 | |
| 424 | 424 | // Cycle in each post to build the query. |
| 425 | - foreach ( $posts as $post ) { |
|
| 425 | + foreach ($posts as $post) { |
|
| 426 | 426 | |
| 427 | 427 | // Ignore revisions. |
| 428 | - if ( wp_is_post_revision( $post->ID ) ) { |
|
| 428 | + if (wp_is_post_revision($post->ID)) { |
|
| 429 | 429 | continue; |
| 430 | 430 | } |
| 431 | 431 | |
| 432 | 432 | // Get the entity URI. |
| 433 | - $s = Wordlift_Sparql_Service::escape_uri( Wordlift_Entity_Service::get_instance() |
|
| 434 | - ->get_uri( $post->ID ) ); |
|
| 433 | + $s = Wordlift_Sparql_Service::escape_uri(Wordlift_Entity_Service::get_instance() |
|
| 434 | + ->get_uri($post->ID)); |
|
| 435 | 435 | |
| 436 | 436 | // Get the post URL. |
| 437 | 437 | // $url = wl_sparql_escape_uri( get_permalink( $post->ID ) ); |
@@ -440,13 +440,13 @@ discard block |
||
| 440 | 440 | $delete_query .= "DELETE { <$s> schema:url ?u . } WHERE { <$s> schema:url ?u . };\n"; |
| 441 | 441 | |
| 442 | 442 | $insert_query .= Wordlift_Schema_Url_Property_Service::get_instance() |
| 443 | - ->get_insert_query( $s, $post->ID ); |
|
| 443 | + ->get_insert_query($s, $post->ID); |
|
| 444 | 444 | |
| 445 | 445 | } |
| 446 | 446 | |
| 447 | 447 | |
| 448 | 448 | // Execute the query. |
| 449 | - rl_execute_sparql_update_query( $delete_query . $insert_query ); |
|
| 449 | + rl_execute_sparql_update_query($delete_query.$insert_query); |
|
| 450 | 450 | |
| 451 | 451 | // Advance to the next posts. |
| 452 | 452 | $offset += $limit; |
@@ -462,7 +462,7 @@ discard block |
||
| 462 | 462 | |
| 463 | 463 | } |
| 464 | 464 | |
| 465 | -add_filter( 'flush_rewrite_rules_hard', 'wl_flush_rewrite_rules_hard', 10, 1 ); |
|
| 465 | +add_filter('flush_rewrite_rules_hard', 'wl_flush_rewrite_rules_hard', 10, 1); |
|
| 466 | 466 | |
| 467 | 467 | /** |
| 468 | 468 | * Sanitizes an URI path by replacing the non allowed characters with an underscore. |
@@ -475,9 +475,9 @@ discard block |
||
| 475 | 475 | * |
| 476 | 476 | * @return string The sanitized path. |
| 477 | 477 | */ |
| 478 | -function wl_sanitize_uri_path( $path, $char = '_' ) { |
|
| 478 | +function wl_sanitize_uri_path($path, $char = '_') { |
|
| 479 | 479 | |
| 480 | - return Wordlift_Uri_Service::get_instance()->sanitize_path( $path, $char ); |
|
| 480 | + return Wordlift_Uri_Service::get_instance()->sanitize_path($path, $char); |
|
| 481 | 481 | } |
| 482 | 482 | |
| 483 | 483 | /** |
@@ -487,10 +487,10 @@ discard block |
||
| 487 | 487 | * |
| 488 | 488 | * @return array Array containing $value (if $value was not an array) |
| 489 | 489 | */ |
| 490 | -function wl_force_to_array( $value ) { |
|
| 490 | +function wl_force_to_array($value) { |
|
| 491 | 491 | |
| 492 | - if ( ! is_array( $value ) ) { |
|
| 493 | - return array( $value ); |
|
| 492 | + if ( ! is_array($value)) { |
|
| 493 | + return array($value); |
|
| 494 | 494 | } |
| 495 | 495 | |
| 496 | 496 | return $value; |
@@ -502,28 +502,28 @@ discard block |
||
| 502 | 502 | function wl_shutdown() { |
| 503 | 503 | |
| 504 | 504 | // Get the filename to the temporary SPARQL file. |
| 505 | - $filename = WL_TEMP_DIR . WL_REQUEST_ID . '.sparql'; |
|
| 505 | + $filename = WL_TEMP_DIR.WL_REQUEST_ID.'.sparql'; |
|
| 506 | 506 | |
| 507 | 507 | // If WordLift is buffering SPARQL queries, we're admins and a buffer exists, then schedule it. |
| 508 | - if ( WL_ENABLE_SPARQL_UPDATE_QUERIES_BUFFERING && is_admin() && file_exists( $filename ) ) { |
|
| 508 | + if (WL_ENABLE_SPARQL_UPDATE_QUERIES_BUFFERING && is_admin() && file_exists($filename)) { |
|
| 509 | 509 | |
| 510 | 510 | // The request ID. |
| 511 | - $args = array( WL_REQUEST_ID ); |
|
| 511 | + $args = array(WL_REQUEST_ID); |
|
| 512 | 512 | |
| 513 | 513 | // Schedule the execution of the SPARQL query with the request ID. |
| 514 | - wp_schedule_single_event( time(), 'wl_execute_saved_sparql_update_query', $args ); |
|
| 514 | + wp_schedule_single_event(time(), 'wl_execute_saved_sparql_update_query', $args); |
|
| 515 | 515 | |
| 516 | 516 | // Check that the request is scheduled. |
| 517 | - $timestamp = wp_next_scheduled( 'wl_execute_saved_sparql_update_query', $args ); |
|
| 517 | + $timestamp = wp_next_scheduled('wl_execute_saved_sparql_update_query', $args); |
|
| 518 | 518 | |
| 519 | 519 | // Spawn the cron. |
| 520 | 520 | spawn_cron(); |
| 521 | 521 | |
| 522 | - wl_write_log( "wl_shutdown [ request id :: " . WL_REQUEST_ID . " ][ timestamp :: $timestamp ]" ); |
|
| 522 | + wl_write_log("wl_shutdown [ request id :: ".WL_REQUEST_ID." ][ timestamp :: $timestamp ]"); |
|
| 523 | 523 | } |
| 524 | 524 | } |
| 525 | 525 | |
| 526 | -add_action( 'shutdown', 'wl_shutdown' ); |
|
| 526 | +add_action('shutdown', 'wl_shutdown'); |
|
| 527 | 527 | |
| 528 | 528 | /** |
| 529 | 529 | * Replaces the *itemid* attributes URIs with the WordLift URIs. |
@@ -532,113 +532,113 @@ discard block |
||
| 532 | 532 | * |
| 533 | 533 | * @return string The updated post content. |
| 534 | 534 | */ |
| 535 | -function wl_replace_item_id_with_uri( $content ) { |
|
| 535 | +function wl_replace_item_id_with_uri($content) { |
|
| 536 | 536 | |
| 537 | 537 | // wl_write_log( "wl_replace_item_id_with_uri" ); |
| 538 | 538 | |
| 539 | 539 | // Strip slashes, see https://core.trac.wordpress.org/ticket/21767 |
| 540 | - $content = stripslashes( $content ); |
|
| 540 | + $content = stripslashes($content); |
|
| 541 | 541 | |
| 542 | 542 | // If any match are found. |
| 543 | 543 | $matches = array(); |
| 544 | - if ( 0 < preg_match_all( '/ itemid="([^"]+)"/i', $content, $matches, PREG_SET_ORDER ) ) { |
|
| 544 | + if (0 < preg_match_all('/ itemid="([^"]+)"/i', $content, $matches, PREG_SET_ORDER)) { |
|
| 545 | 545 | |
| 546 | - foreach ( $matches as $match ) { |
|
| 546 | + foreach ($matches as $match) { |
|
| 547 | 547 | |
| 548 | 548 | // Get the item ID. |
| 549 | 549 | $item_id = $match[1]; |
| 550 | 550 | |
| 551 | 551 | // Get the post bound to that item ID (looking both in the 'official' URI and in the 'same-as' . |
| 552 | 552 | $post = Wordlift_Entity_Service::get_instance() |
| 553 | - ->get_entity_post_by_uri( $item_id ); |
|
| 553 | + ->get_entity_post_by_uri($item_id); |
|
| 554 | 554 | |
| 555 | 555 | // If no entity is found, continue to the next one. |
| 556 | - if ( null === $post ) { |
|
| 556 | + if (null === $post) { |
|
| 557 | 557 | continue; |
| 558 | 558 | } |
| 559 | 559 | |
| 560 | 560 | // Get the URI for that post. |
| 561 | - $uri = wl_get_entity_uri( $post->ID ); |
|
| 561 | + $uri = wl_get_entity_uri($post->ID); |
|
| 562 | 562 | |
| 563 | 563 | // wl_write_log( "wl_replace_item_id_with_uri [ item id :: $item_id ][ uri :: $uri ]" ); |
| 564 | 564 | |
| 565 | 565 | // If the item ID and the URI differ, replace the item ID with the URI saved in WordPress. |
| 566 | - if ( $item_id !== $uri ) { |
|
| 567 | - $uri_e = esc_html( $uri ); |
|
| 568 | - $content = str_replace( " itemid=\"$item_id\"", " itemid=\"$uri_e\"", $content ); |
|
| 566 | + if ($item_id !== $uri) { |
|
| 567 | + $uri_e = esc_html($uri); |
|
| 568 | + $content = str_replace(" itemid=\"$item_id\"", " itemid=\"$uri_e\"", $content); |
|
| 569 | 569 | } |
| 570 | 570 | } |
| 571 | 571 | } |
| 572 | 572 | |
| 573 | 573 | // Reapply slashes. |
| 574 | - $content = addslashes( $content ); |
|
| 574 | + $content = addslashes($content); |
|
| 575 | 575 | |
| 576 | 576 | return $content; |
| 577 | 577 | } |
| 578 | 578 | |
| 579 | -add_filter( 'content_save_pre', 'wl_replace_item_id_with_uri', 1, 1 ); |
|
| 579 | +add_filter('content_save_pre', 'wl_replace_item_id_with_uri', 1, 1); |
|
| 580 | 580 | |
| 581 | -require_once( 'wordlift_entity_functions.php' ); |
|
| 581 | +require_once('wordlift_entity_functions.php'); |
|
| 582 | 582 | |
| 583 | 583 | // add editor related methods. |
| 584 | -require_once( 'wordlift_editor.php' ); |
|
| 584 | +require_once('wordlift_editor.php'); |
|
| 585 | 585 | |
| 586 | 586 | // add the WordLift entity custom type. |
| 587 | -require_once( 'wordlift_entity_type.php' ); |
|
| 588 | -require_once( 'wordlift_entity_type_taxonomy.php' ); |
|
| 587 | +require_once('wordlift_entity_type.php'); |
|
| 588 | +require_once('wordlift_entity_type_taxonomy.php'); |
|
| 589 | 589 | |
| 590 | 590 | // add callbacks on post save to notify data changes from wp to redlink triple store |
| 591 | -require_once( 'wordlift_to_redlink_data_push_callbacks.php' ); |
|
| 591 | +require_once('wordlift_to_redlink_data_push_callbacks.php'); |
|
| 592 | 592 | |
| 593 | -require_once( 'modules/configuration/wordlift_configuration_settings.php' ); |
|
| 593 | +require_once('modules/configuration/wordlift_configuration_settings.php'); |
|
| 594 | 594 | |
| 595 | 595 | // Load modules |
| 596 | -require_once( 'modules/analyzer/wordlift_analyzer.php' ); |
|
| 597 | -require_once( 'modules/linked_data/wordlift_linked_data.php' ); |
|
| 598 | -require_once( 'modules/prefixes/wordlift_prefixes.php' ); |
|
| 599 | -require_once( 'modules/redirector/wordlift_redirector.php' ); |
|
| 596 | +require_once('modules/analyzer/wordlift_analyzer.php'); |
|
| 597 | +require_once('modules/linked_data/wordlift_linked_data.php'); |
|
| 598 | +require_once('modules/prefixes/wordlift_prefixes.php'); |
|
| 599 | +require_once('modules/redirector/wordlift_redirector.php'); |
|
| 600 | 600 | |
| 601 | 601 | // Shortcodes |
| 602 | 602 | |
| 603 | -require_once( 'modules/geo_widget/wordlift_geo_widget.php' ); |
|
| 604 | -require_once( 'shortcodes/wordlift_shortcode_chord.php' ); |
|
| 605 | -require_once( 'shortcodes/wordlift_shortcode_geomap.php' ); |
|
| 606 | -require_once( 'shortcodes/wordlift_shortcode_field.php' ); |
|
| 607 | -require_once( 'shortcodes/wordlift_shortcode_faceted_search.php' ); |
|
| 608 | -require_once( 'shortcodes/wordlift_shortcode_navigator.php' ); |
|
| 603 | +require_once('modules/geo_widget/wordlift_geo_widget.php'); |
|
| 604 | +require_once('shortcodes/wordlift_shortcode_chord.php'); |
|
| 605 | +require_once('shortcodes/wordlift_shortcode_geomap.php'); |
|
| 606 | +require_once('shortcodes/wordlift_shortcode_field.php'); |
|
| 607 | +require_once('shortcodes/wordlift_shortcode_faceted_search.php'); |
|
| 608 | +require_once('shortcodes/wordlift_shortcode_navigator.php'); |
|
| 609 | 609 | |
| 610 | -require_once( 'widgets/wordlift_widget_geo.php' ); |
|
| 611 | -require_once( 'widgets/wordlift_widget_chord.php' ); |
|
| 612 | -require_once( 'widgets/wordlift_widget_timeline.php' ); |
|
| 610 | +require_once('widgets/wordlift_widget_geo.php'); |
|
| 611 | +require_once('widgets/wordlift_widget_chord.php'); |
|
| 612 | +require_once('widgets/wordlift_widget_timeline.php'); |
|
| 613 | 613 | |
| 614 | -require_once( 'wordlift_sparql.php' ); |
|
| 615 | -require_once( 'wordlift_redlink.php' ); |
|
| 614 | +require_once('wordlift_sparql.php'); |
|
| 615 | +require_once('wordlift_redlink.php'); |
|
| 616 | 616 | |
| 617 | 617 | // Add admin functions. |
| 618 | 618 | // TODO: find a way to make 'admin' UI tests work. |
| 619 | 619 | //if ( is_admin() ) { |
| 620 | 620 | |
| 621 | -require_once( 'admin/wordlift_admin.php' ); |
|
| 622 | -require_once( 'admin/wordlift_admin_edit_post.php' ); |
|
| 623 | -require_once( 'admin/wordlift_admin_save_post.php' ); |
|
| 621 | +require_once('admin/wordlift_admin.php'); |
|
| 622 | +require_once('admin/wordlift_admin_edit_post.php'); |
|
| 623 | +require_once('admin/wordlift_admin_save_post.php'); |
|
| 624 | 624 | |
| 625 | 625 | // add the entities meta box. |
| 626 | -require_once( 'admin/wordlift_admin_meta_box_entities.php' ); |
|
| 626 | +require_once('admin/wordlift_admin_meta_box_entities.php'); |
|
| 627 | 627 | |
| 628 | 628 | // add the entity creation AJAX. |
| 629 | -require_once( 'admin/wordlift_admin_ajax_related_posts.php' ); |
|
| 629 | +require_once('admin/wordlift_admin_ajax_related_posts.php'); |
|
| 630 | 630 | |
| 631 | 631 | // Load the wl_chord TinyMCE button and configuration dialog. |
| 632 | -require_once( 'admin/wordlift_admin_shortcodes.php' ); |
|
| 632 | +require_once('admin/wordlift_admin_shortcodes.php'); |
|
| 633 | 633 | |
| 634 | 634 | // Provide syncing features. |
| 635 | -require_once( 'admin/wordlift_admin_sync.php' ); |
|
| 635 | +require_once('admin/wordlift_admin_sync.php'); |
|
| 636 | 636 | //} |
| 637 | 637 | |
| 638 | 638 | // load languages. |
| 639 | 639 | // TODO: the following call gives for granted that the plugin is in the wordlift directory, |
| 640 | 640 | // we're currently doing this because wordlift is symbolic linked. |
| 641 | -load_plugin_textdomain( 'wordlift', false, '/wordlift/languages' ); |
|
| 641 | +load_plugin_textdomain('wordlift', false, '/wordlift/languages'); |
|
| 642 | 642 | |
| 643 | 643 | |
| 644 | 644 | /** |
@@ -646,7 +646,7 @@ discard block |
||
| 646 | 646 | * This action is documented in includes/class-wordlift-activator.php |
| 647 | 647 | */ |
| 648 | 648 | function activate_wordlift() { |
| 649 | - require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-activator.php'; |
|
| 649 | + require_once plugin_dir_path(__FILE__).'includes/class-wordlift-activator.php'; |
|
| 650 | 650 | Wordlift_Activator::activate(); |
| 651 | 651 | } |
| 652 | 652 | |
@@ -655,18 +655,18 @@ discard block |
||
| 655 | 655 | * This action is documented in includes/class-wordlift-deactivator.php |
| 656 | 656 | */ |
| 657 | 657 | function deactivate_wordlift() { |
| 658 | - require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-deactivator.php'; |
|
| 658 | + require_once plugin_dir_path(__FILE__).'includes/class-wordlift-deactivator.php'; |
|
| 659 | 659 | Wordlift_Deactivator::deactivate(); |
| 660 | 660 | } |
| 661 | 661 | |
| 662 | -register_activation_hook( __FILE__, 'activate_wordlift' ); |
|
| 663 | -register_deactivation_hook( __FILE__, 'deactivate_wordlift' ); |
|
| 662 | +register_activation_hook(__FILE__, 'activate_wordlift'); |
|
| 663 | +register_deactivation_hook(__FILE__, 'deactivate_wordlift'); |
|
| 664 | 664 | |
| 665 | 665 | /** |
| 666 | 666 | * The core plugin class that is used to define internationalization, |
| 667 | 667 | * admin-specific hooks, and public-facing site hooks. |
| 668 | 668 | */ |
| 669 | -require plugin_dir_path( __FILE__ ) . 'includes/class-wordlift.php'; |
|
| 669 | +require plugin_dir_path(__FILE__).'includes/class-wordlift.php'; |
|
| 670 | 670 | |
| 671 | 671 | /** |
| 672 | 672 | * Begins execution of the plugin. |
@@ -5,71 +5,71 @@ discard block |
||
| 5 | 5 | */ |
| 6 | 6 | function wl_shortcode_faceted_search( $atts ) { |
| 7 | 7 | |
| 8 | - // Extract attributes and set default values. |
|
| 9 | - $shortcode_atts = shortcode_atts( array( |
|
| 10 | - 'title' => __( 'Related articles', 'wordlift' ), |
|
| 11 | - 'show_facets' => true, |
|
| 12 | - 'with_carousel' => true, |
|
| 13 | - 'squared_thumbs' => false, |
|
| 14 | - |
|
| 15 | - ), $atts ); |
|
| 16 | - |
|
| 17 | - foreach ( |
|
| 18 | - array( |
|
| 19 | - 'show_facets', |
|
| 20 | - 'with_carousel', |
|
| 21 | - 'squared_thumbs', |
|
| 22 | - ) as $att |
|
| 23 | - ) { |
|
| 24 | - |
|
| 25 | - // See http://wordpress.stackexchange.com/questions/119294/pass-boolean-value-in-shortcode |
|
| 26 | - $shortcode_atts[ $att ] = filter_var( |
|
| 27 | - $shortcode_atts[ $att ], FILTER_VALIDATE_BOOLEAN |
|
| 28 | - ); |
|
| 29 | - } |
|
| 30 | - |
|
| 31 | - |
|
| 32 | - // If the current post is not an entity and has no related entities |
|
| 33 | - // than the shortcode cannot be rendered |
|
| 34 | - // TODO Add an alert visibile only for connected admin users |
|
| 35 | - $current_post = get_post(); |
|
| 36 | - |
|
| 37 | - $entity_ids = ( Wordlift_Entity_Service::TYPE_NAME === $current_post->post_type ) ? |
|
| 38 | - $current_post->ID : |
|
| 39 | - wl_core_get_related_entity_ids( $current_post->ID ); |
|
| 40 | - |
|
| 41 | - if ( 0 === count( $entity_ids ) ) { |
|
| 42 | - return ''; |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - $div_id = 'wordlift-faceted-entity-search-widget'; |
|
| 46 | - |
|
| 47 | - wp_enqueue_style( 'wordlift-faceted-search', dirname( plugin_dir_url( __FILE__ ) ) . '/css/wordlift-faceted-entity-search-widget.min.css' ); |
|
| 48 | - wp_enqueue_script( 'angularjs', 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.11/angular.min.js' ); |
|
| 49 | - wp_enqueue_script( 'angularjs-touch', 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.11/angular-touch.min.js' ); |
|
| 50 | - |
|
| 51 | - wp_enqueue_script( 'wordlift-faceted-search', dirname( plugin_dir_url( __FILE__ ) ) . '/js/wordlift-faceted-entity-search-widget.min.js' ); |
|
| 52 | - |
|
| 53 | - wp_localize_script( |
|
| 54 | - 'wordlift-faceted-search', |
|
| 55 | - 'wl_faceted_search_params', array( |
|
| 56 | - 'ajax_url' => admin_url( 'admin-ajax.php' ), |
|
| 57 | - 'action' => 'wl_faceted_search', |
|
| 58 | - 'post_id' => $current_post->ID, |
|
| 59 | - 'entity_ids' => $entity_ids, |
|
| 60 | - 'div_id' => $div_id, |
|
| 61 | - 'defaultThumbnailPath' => WL_DEFAULT_THUMBNAIL_PATH, |
|
| 62 | - 'attrs' => $shortcode_atts, |
|
| 63 | - 'l10n' => array( |
|
| 64 | - 'what' => _x( 'What', 'Faceted Search Widget', 'wordlift' ), |
|
| 65 | - 'who' => _x( 'Who', 'Faceted Search Widget', 'wordlift' ), |
|
| 66 | - 'where' => _x( 'Where', 'Faceted Search Widget', 'wordlift' ), |
|
| 67 | - 'when' => _x( 'When', 'Faceted Search Widget', 'wordlift' ), |
|
| 68 | - ), |
|
| 69 | - ) |
|
| 70 | - ); |
|
| 71 | - |
|
| 72 | - return '<div id="' . $div_id . '" style="width:100%"></div>'; |
|
| 8 | + // Extract attributes and set default values. |
|
| 9 | + $shortcode_atts = shortcode_atts( array( |
|
| 10 | + 'title' => __( 'Related articles', 'wordlift' ), |
|
| 11 | + 'show_facets' => true, |
|
| 12 | + 'with_carousel' => true, |
|
| 13 | + 'squared_thumbs' => false, |
|
| 14 | + |
|
| 15 | + ), $atts ); |
|
| 16 | + |
|
| 17 | + foreach ( |
|
| 18 | + array( |
|
| 19 | + 'show_facets', |
|
| 20 | + 'with_carousel', |
|
| 21 | + 'squared_thumbs', |
|
| 22 | + ) as $att |
|
| 23 | + ) { |
|
| 24 | + |
|
| 25 | + // See http://wordpress.stackexchange.com/questions/119294/pass-boolean-value-in-shortcode |
|
| 26 | + $shortcode_atts[ $att ] = filter_var( |
|
| 27 | + $shortcode_atts[ $att ], FILTER_VALIDATE_BOOLEAN |
|
| 28 | + ); |
|
| 29 | + } |
|
| 30 | + |
|
| 31 | + |
|
| 32 | + // If the current post is not an entity and has no related entities |
|
| 33 | + // than the shortcode cannot be rendered |
|
| 34 | + // TODO Add an alert visibile only for connected admin users |
|
| 35 | + $current_post = get_post(); |
|
| 36 | + |
|
| 37 | + $entity_ids = ( Wordlift_Entity_Service::TYPE_NAME === $current_post->post_type ) ? |
|
| 38 | + $current_post->ID : |
|
| 39 | + wl_core_get_related_entity_ids( $current_post->ID ); |
|
| 40 | + |
|
| 41 | + if ( 0 === count( $entity_ids ) ) { |
|
| 42 | + return ''; |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + $div_id = 'wordlift-faceted-entity-search-widget'; |
|
| 46 | + |
|
| 47 | + wp_enqueue_style( 'wordlift-faceted-search', dirname( plugin_dir_url( __FILE__ ) ) . '/css/wordlift-faceted-entity-search-widget.min.css' ); |
|
| 48 | + wp_enqueue_script( 'angularjs', 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.11/angular.min.js' ); |
|
| 49 | + wp_enqueue_script( 'angularjs-touch', 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.11/angular-touch.min.js' ); |
|
| 50 | + |
|
| 51 | + wp_enqueue_script( 'wordlift-faceted-search', dirname( plugin_dir_url( __FILE__ ) ) . '/js/wordlift-faceted-entity-search-widget.min.js' ); |
|
| 52 | + |
|
| 53 | + wp_localize_script( |
|
| 54 | + 'wordlift-faceted-search', |
|
| 55 | + 'wl_faceted_search_params', array( |
|
| 56 | + 'ajax_url' => admin_url( 'admin-ajax.php' ), |
|
| 57 | + 'action' => 'wl_faceted_search', |
|
| 58 | + 'post_id' => $current_post->ID, |
|
| 59 | + 'entity_ids' => $entity_ids, |
|
| 60 | + 'div_id' => $div_id, |
|
| 61 | + 'defaultThumbnailPath' => WL_DEFAULT_THUMBNAIL_PATH, |
|
| 62 | + 'attrs' => $shortcode_atts, |
|
| 63 | + 'l10n' => array( |
|
| 64 | + 'what' => _x( 'What', 'Faceted Search Widget', 'wordlift' ), |
|
| 65 | + 'who' => _x( 'Who', 'Faceted Search Widget', 'wordlift' ), |
|
| 66 | + 'where' => _x( 'Where', 'Faceted Search Widget', 'wordlift' ), |
|
| 67 | + 'when' => _x( 'When', 'Faceted Search Widget', 'wordlift' ), |
|
| 68 | + ), |
|
| 69 | + ) |
|
| 70 | + ); |
|
| 71 | + |
|
| 72 | + return '<div id="' . $div_id . '" style="width:100%"></div>'; |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | add_shortcode( 'wl_faceted_search', 'wl_shortcode_faceted_search' ); |
@@ -80,125 +80,125 @@ discard block |
||
| 80 | 80 | */ |
| 81 | 81 | function wl_shortcode_faceted_search_ajax( $http_raw_data = null ) { |
| 82 | 82 | |
| 83 | - // Post ID must be defined |
|
| 84 | - if ( ! isset( $_GET['post_id'] ) ) { |
|
| 85 | - wp_die( 'No post_id given' ); |
|
| 83 | + // Post ID must be defined |
|
| 84 | + if ( ! isset( $_GET['post_id'] ) ) { |
|
| 85 | + wp_die( 'No post_id given' ); |
|
| 86 | 86 | |
| 87 | - return; |
|
| 88 | - } |
|
| 87 | + return; |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | - // Extract filtering conditions |
|
| 91 | - $filtering_entity_uris = ( null == $http_raw_data ) ? file_get_contents( "php://input" ) : $http_raw_data; |
|
| 92 | - $filtering_entity_uris = json_decode( $filtering_entity_uris ); |
|
| 90 | + // Extract filtering conditions |
|
| 91 | + $filtering_entity_uris = ( null == $http_raw_data ) ? file_get_contents( "php://input" ) : $http_raw_data; |
|
| 92 | + $filtering_entity_uris = json_decode( $filtering_entity_uris ); |
|
| 93 | 93 | |
| 94 | - $current_post_id = $_GET['post_id']; |
|
| 95 | - $current_post = get_post( $current_post_id ); |
|
| 94 | + $current_post_id = $_GET['post_id']; |
|
| 95 | + $current_post = get_post( $current_post_id ); |
|
| 96 | 96 | |
| 97 | - // Post ID has to match an existing item |
|
| 98 | - if ( null === $current_post ) { |
|
| 99 | - wp_die( 'No valid post_id given' ); |
|
| 97 | + // Post ID has to match an existing item |
|
| 98 | + if ( null === $current_post ) { |
|
| 99 | + wp_die( 'No valid post_id given' ); |
|
| 100 | 100 | |
| 101 | - return; |
|
| 102 | - } |
|
| 101 | + return; |
|
| 102 | + } |
|
| 103 | 103 | |
| 104 | - // If the current post is an entity, |
|
| 105 | - // the current post is used as main entity. |
|
| 106 | - // Otherwise, current post related entities are used. |
|
| 107 | - $entity_ids = ( Wordlift_Entity_Service::TYPE_NAME === $current_post->post_type ) ? |
|
| 108 | - array( $current_post->ID ) : |
|
| 109 | - wl_core_get_related_entity_ids( $current_post->ID ); |
|
| 104 | + // If the current post is an entity, |
|
| 105 | + // the current post is used as main entity. |
|
| 106 | + // Otherwise, current post related entities are used. |
|
| 107 | + $entity_ids = ( Wordlift_Entity_Service::TYPE_NAME === $current_post->post_type ) ? |
|
| 108 | + array( $current_post->ID ) : |
|
| 109 | + wl_core_get_related_entity_ids( $current_post->ID ); |
|
| 110 | 110 | |
| 111 | - // If there are no entities we cannot render the widget |
|
| 112 | - if ( 0 === count( $entity_ids ) ) { |
|
| 113 | - wp_die( 'No entities available' ); |
|
| 111 | + // If there are no entities we cannot render the widget |
|
| 112 | + if ( 0 === count( $entity_ids ) ) { |
|
| 113 | + wp_die( 'No entities available' ); |
|
| 114 | 114 | |
| 115 | - return; |
|
| 116 | - } |
|
| 115 | + return; |
|
| 116 | + } |
|
| 117 | 117 | |
| 118 | - // Retrieve requested type |
|
| 119 | - $required_type = ( isset( $_GET['type'] ) ) ? $_GET['type'] : null; |
|
| 118 | + // Retrieve requested type |
|
| 119 | + $required_type = ( isset( $_GET['type'] ) ) ? $_GET['type'] : null; |
|
| 120 | 120 | |
| 121 | - // Set up data structures |
|
| 122 | - $referencing_posts = wl_core_get_posts( array( |
|
| 123 | - 'get' => 'posts', |
|
| 124 | - 'post__not_in' => array( $current_post_id ), |
|
| 125 | - 'related_to__in' => $entity_ids, |
|
| 126 | - 'post_type' => 'post', |
|
| 127 | - 'as' => 'subject', |
|
| 128 | - 'post_status' => 'publish', |
|
| 129 | - ) ); |
|
| 121 | + // Set up data structures |
|
| 122 | + $referencing_posts = wl_core_get_posts( array( |
|
| 123 | + 'get' => 'posts', |
|
| 124 | + 'post__not_in' => array( $current_post_id ), |
|
| 125 | + 'related_to__in' => $entity_ids, |
|
| 126 | + 'post_type' => 'post', |
|
| 127 | + 'as' => 'subject', |
|
| 128 | + 'post_status' => 'publish', |
|
| 129 | + ) ); |
|
| 130 | 130 | |
| 131 | - $referencing_post_ids = array_map( function ( $p ) { |
|
| 132 | - return $p->ID; |
|
| 133 | - }, $referencing_posts ); |
|
| 134 | - $results = array(); |
|
| 131 | + $referencing_post_ids = array_map( function ( $p ) { |
|
| 132 | + return $p->ID; |
|
| 133 | + }, $referencing_posts ); |
|
| 134 | + $results = array(); |
|
| 135 | 135 | |
| 136 | - if ( 'posts' === $required_type ) { |
|
| 136 | + if ( 'posts' === $required_type ) { |
|
| 137 | 137 | |
| 138 | - // Required filtered posts. |
|
| 139 | - wl_write_log( "Going to find related posts for the current post [ post ID :: $current_post_id ]" ); |
|
| 138 | + // Required filtered posts. |
|
| 139 | + wl_write_log( "Going to find related posts for the current post [ post ID :: $current_post_id ]" ); |
|
| 140 | 140 | |
| 141 | - $filtered_posts = ( empty( $filtering_entity_uris ) ) ? |
|
| 142 | - $referencing_posts : |
|
| 143 | - wl_core_get_posts( array( |
|
| 144 | - 'get' => 'posts', |
|
| 145 | - 'post__in' => $referencing_post_ids, |
|
| 146 | - 'related_to__in' => wl_get_entity_post_ids_by_uris( $filtering_entity_uris ), |
|
| 147 | - 'post_type' => 'post', |
|
| 148 | - 'as' => 'subject', |
|
| 149 | - ) ); |
|
| 141 | + $filtered_posts = ( empty( $filtering_entity_uris ) ) ? |
|
| 142 | + $referencing_posts : |
|
| 143 | + wl_core_get_posts( array( |
|
| 144 | + 'get' => 'posts', |
|
| 145 | + 'post__in' => $referencing_post_ids, |
|
| 146 | + 'related_to__in' => wl_get_entity_post_ids_by_uris( $filtering_entity_uris ), |
|
| 147 | + 'post_type' => 'post', |
|
| 148 | + 'as' => 'subject', |
|
| 149 | + ) ); |
|
| 150 | 150 | |
| 151 | - if ( $filtered_posts ) { |
|
| 152 | - foreach ( $filtered_posts as $post_obj ) { |
|
| 151 | + if ( $filtered_posts ) { |
|
| 152 | + foreach ( $filtered_posts as $post_obj ) { |
|
| 153 | 153 | |
| 154 | - $thumbnail = wp_get_attachment_url( get_post_thumbnail_id( $post_obj->ID, 'thumbnail' ) ); |
|
| 155 | - $post_obj->thumbnail = ( $thumbnail ) ? |
|
| 156 | - $thumbnail : WL_DEFAULT_THUMBNAIL_PATH; |
|
| 157 | - $post_obj->permalink = get_post_permalink( $post_obj->ID ); |
|
| 154 | + $thumbnail = wp_get_attachment_url( get_post_thumbnail_id( $post_obj->ID, 'thumbnail' ) ); |
|
| 155 | + $post_obj->thumbnail = ( $thumbnail ) ? |
|
| 156 | + $thumbnail : WL_DEFAULT_THUMBNAIL_PATH; |
|
| 157 | + $post_obj->permalink = get_post_permalink( $post_obj->ID ); |
|
| 158 | 158 | |
| 159 | - $results[] = $post_obj; |
|
| 160 | - } |
|
| 161 | - } |
|
| 162 | - } else { |
|
| 159 | + $results[] = $post_obj; |
|
| 160 | + } |
|
| 161 | + } |
|
| 162 | + } else { |
|
| 163 | 163 | |
| 164 | - global $wpdb; |
|
| 164 | + global $wpdb; |
|
| 165 | 165 | |
| 166 | - wl_write_log( "Going to find related entities for the current post [ post ID :: $current_post_id ]" ); |
|
| 166 | + wl_write_log( "Going to find related entities for the current post [ post ID :: $current_post_id ]" ); |
|
| 167 | 167 | |
| 168 | - // Retrieve Wordlift relation instances table name |
|
| 169 | - $table_name = wl_core_get_relation_instances_table_name(); |
|
| 168 | + // Retrieve Wordlift relation instances table name |
|
| 169 | + $table_name = wl_core_get_relation_instances_table_name(); |
|
| 170 | 170 | |
| 171 | - $subject_ids = implode( ',', $referencing_post_ids ); |
|
| 171 | + $subject_ids = implode( ',', $referencing_post_ids ); |
|
| 172 | 172 | |
| 173 | - $query = <<<EOF |
|
| 173 | + $query = <<<EOF |
|
| 174 | 174 | SELECT object_id as ID, count( object_id ) as counter |
| 175 | 175 | FROM $table_name |
| 176 | 176 | WHERE subject_id IN ($subject_ids) and object_id != ($current_post_id) |
| 177 | 177 | GROUP BY object_id; |
| 178 | 178 | EOF; |
| 179 | - wl_write_log( "Going to find related entities for the current post [ post ID :: $current_post_id ] [ query :: $query ]" ); |
|
| 179 | + wl_write_log( "Going to find related entities for the current post [ post ID :: $current_post_id ] [ query :: $query ]" ); |
|
| 180 | 180 | |
| 181 | - $entities = $wpdb->get_results( $query, OBJECT ); |
|
| 181 | + $entities = $wpdb->get_results( $query, OBJECT ); |
|
| 182 | 182 | |
| 183 | - wl_write_log( "Entities found " . count( $entities ) ); |
|
| 183 | + wl_write_log( "Entities found " . count( $entities ) ); |
|
| 184 | 184 | |
| 185 | - foreach ( $entities as $obj ) { |
|
| 185 | + foreach ( $entities as $obj ) { |
|
| 186 | 186 | |
| 187 | - $entity = get_post( $obj->ID ); |
|
| 188 | - // Ensure only valid and published entities are returned |
|
| 189 | - if ( ( null !== $entity ) && ( 'publish' === $entity->post_status ) ) { |
|
| 187 | + $entity = get_post( $obj->ID ); |
|
| 188 | + // Ensure only valid and published entities are returned |
|
| 189 | + if ( ( null !== $entity ) && ( 'publish' === $entity->post_status ) ) { |
|
| 190 | 190 | |
| 191 | - $serialized_entity = wl_serialize_entity( $entity ); |
|
| 192 | - $serialized_entity['counter'] = $obj->counter; |
|
| 193 | - $serialized_entity['createdAt'] = $entity->post_date; |
|
| 191 | + $serialized_entity = wl_serialize_entity( $entity ); |
|
| 192 | + $serialized_entity['counter'] = $obj->counter; |
|
| 193 | + $serialized_entity['createdAt'] = $entity->post_date; |
|
| 194 | 194 | |
| 195 | - $results[] = $serialized_entity; |
|
| 196 | - } |
|
| 197 | - } |
|
| 195 | + $results[] = $serialized_entity; |
|
| 196 | + } |
|
| 197 | + } |
|
| 198 | 198 | |
| 199 | - } |
|
| 199 | + } |
|
| 200 | 200 | |
| 201 | - wl_core_send_json( $results ); |
|
| 201 | + wl_core_send_json( $results ); |
|
| 202 | 202 | |
| 203 | 203 | } |
| 204 | 204 | |
@@ -3,16 +3,16 @@ discard block |
||
| 3 | 3 | /** |
| 4 | 4 | * Function in charge of diplaying the [wl-faceted-search] |
| 5 | 5 | */ |
| 6 | -function wl_shortcode_faceted_search( $atts ) { |
|
| 6 | +function wl_shortcode_faceted_search($atts) { |
|
| 7 | 7 | |
| 8 | 8 | // Extract attributes and set default values. |
| 9 | - $shortcode_atts = shortcode_atts( array( |
|
| 10 | - 'title' => __( 'Related articles', 'wordlift' ), |
|
| 9 | + $shortcode_atts = shortcode_atts(array( |
|
| 10 | + 'title' => __('Related articles', 'wordlift'), |
|
| 11 | 11 | 'show_facets' => true, |
| 12 | 12 | 'with_carousel' => true, |
| 13 | 13 | 'squared_thumbs' => false, |
| 14 | 14 | |
| 15 | - ), $atts ); |
|
| 15 | + ), $atts); |
|
| 16 | 16 | |
| 17 | 17 | foreach ( |
| 18 | 18 | array( |
@@ -23,8 +23,8 @@ discard block |
||
| 23 | 23 | ) { |
| 24 | 24 | |
| 25 | 25 | // See http://wordpress.stackexchange.com/questions/119294/pass-boolean-value-in-shortcode |
| 26 | - $shortcode_atts[ $att ] = filter_var( |
|
| 27 | - $shortcode_atts[ $att ], FILTER_VALIDATE_BOOLEAN |
|
| 26 | + $shortcode_atts[$att] = filter_var( |
|
| 27 | + $shortcode_atts[$att], FILTER_VALIDATE_BOOLEAN |
|
| 28 | 28 | ); |
| 29 | 29 | } |
| 30 | 30 | |
@@ -34,26 +34,25 @@ discard block |
||
| 34 | 34 | // TODO Add an alert visibile only for connected admin users |
| 35 | 35 | $current_post = get_post(); |
| 36 | 36 | |
| 37 | - $entity_ids = ( Wordlift_Entity_Service::TYPE_NAME === $current_post->post_type ) ? |
|
| 38 | - $current_post->ID : |
|
| 39 | - wl_core_get_related_entity_ids( $current_post->ID ); |
|
| 37 | + $entity_ids = (Wordlift_Entity_Service::TYPE_NAME === $current_post->post_type) ? |
|
| 38 | + $current_post->ID : wl_core_get_related_entity_ids($current_post->ID); |
|
| 40 | 39 | |
| 41 | - if ( 0 === count( $entity_ids ) ) { |
|
| 40 | + if (0 === count($entity_ids)) { |
|
| 42 | 41 | return ''; |
| 43 | 42 | } |
| 44 | 43 | |
| 45 | 44 | $div_id = 'wordlift-faceted-entity-search-widget'; |
| 46 | 45 | |
| 47 | - wp_enqueue_style( 'wordlift-faceted-search', dirname( plugin_dir_url( __FILE__ ) ) . '/css/wordlift-faceted-entity-search-widget.min.css' ); |
|
| 48 | - wp_enqueue_script( 'angularjs', 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.11/angular.min.js' ); |
|
| 49 | - wp_enqueue_script( 'angularjs-touch', 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.11/angular-touch.min.js' ); |
|
| 46 | + wp_enqueue_style('wordlift-faceted-search', dirname(plugin_dir_url(__FILE__)).'/css/wordlift-faceted-entity-search-widget.min.css'); |
|
| 47 | + wp_enqueue_script('angularjs', 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.11/angular.min.js'); |
|
| 48 | + wp_enqueue_script('angularjs-touch', 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.11/angular-touch.min.js'); |
|
| 50 | 49 | |
| 51 | - wp_enqueue_script( 'wordlift-faceted-search', dirname( plugin_dir_url( __FILE__ ) ) . '/js/wordlift-faceted-entity-search-widget.min.js' ); |
|
| 50 | + wp_enqueue_script('wordlift-faceted-search', dirname(plugin_dir_url(__FILE__)).'/js/wordlift-faceted-entity-search-widget.min.js'); |
|
| 52 | 51 | |
| 53 | 52 | wp_localize_script( |
| 54 | 53 | 'wordlift-faceted-search', |
| 55 | 54 | 'wl_faceted_search_params', array( |
| 56 | - 'ajax_url' => admin_url( 'admin-ajax.php' ), |
|
| 55 | + 'ajax_url' => admin_url('admin-ajax.php'), |
|
| 57 | 56 | 'action' => 'wl_faceted_search', |
| 58 | 57 | 'post_id' => $current_post->ID, |
| 59 | 58 | 'entity_ids' => $entity_ids, |
@@ -61,42 +60,42 @@ discard block |
||
| 61 | 60 | 'defaultThumbnailPath' => WL_DEFAULT_THUMBNAIL_PATH, |
| 62 | 61 | 'attrs' => $shortcode_atts, |
| 63 | 62 | 'l10n' => array( |
| 64 | - 'what' => _x( 'What', 'Faceted Search Widget', 'wordlift' ), |
|
| 65 | - 'who' => _x( 'Who', 'Faceted Search Widget', 'wordlift' ), |
|
| 66 | - 'where' => _x( 'Where', 'Faceted Search Widget', 'wordlift' ), |
|
| 67 | - 'when' => _x( 'When', 'Faceted Search Widget', 'wordlift' ), |
|
| 63 | + 'what' => _x('What', 'Faceted Search Widget', 'wordlift'), |
|
| 64 | + 'who' => _x('Who', 'Faceted Search Widget', 'wordlift'), |
|
| 65 | + 'where' => _x('Where', 'Faceted Search Widget', 'wordlift'), |
|
| 66 | + 'when' => _x('When', 'Faceted Search Widget', 'wordlift'), |
|
| 68 | 67 | ), |
| 69 | 68 | ) |
| 70 | 69 | ); |
| 71 | 70 | |
| 72 | - return '<div id="' . $div_id . '" style="width:100%"></div>'; |
|
| 71 | + return '<div id="'.$div_id.'" style="width:100%"></div>'; |
|
| 73 | 72 | } |
| 74 | 73 | |
| 75 | -add_shortcode( 'wl_faceted_search', 'wl_shortcode_faceted_search' ); |
|
| 74 | +add_shortcode('wl_faceted_search', 'wl_shortcode_faceted_search'); |
|
| 76 | 75 | |
| 77 | 76 | |
| 78 | 77 | /* |
| 79 | 78 | * Ajax call for the faceted search widget |
| 80 | 79 | */ |
| 81 | -function wl_shortcode_faceted_search_ajax( $http_raw_data = null ) { |
|
| 80 | +function wl_shortcode_faceted_search_ajax($http_raw_data = null) { |
|
| 82 | 81 | |
| 83 | 82 | // Post ID must be defined |
| 84 | - if ( ! isset( $_GET['post_id'] ) ) { |
|
| 85 | - wp_die( 'No post_id given' ); |
|
| 83 | + if ( ! isset($_GET['post_id'])) { |
|
| 84 | + wp_die('No post_id given'); |
|
| 86 | 85 | |
| 87 | 86 | return; |
| 88 | 87 | } |
| 89 | 88 | |
| 90 | 89 | // Extract filtering conditions |
| 91 | - $filtering_entity_uris = ( null == $http_raw_data ) ? file_get_contents( "php://input" ) : $http_raw_data; |
|
| 92 | - $filtering_entity_uris = json_decode( $filtering_entity_uris ); |
|
| 90 | + $filtering_entity_uris = (null == $http_raw_data) ? file_get_contents("php://input") : $http_raw_data; |
|
| 91 | + $filtering_entity_uris = json_decode($filtering_entity_uris); |
|
| 93 | 92 | |
| 94 | 93 | $current_post_id = $_GET['post_id']; |
| 95 | - $current_post = get_post( $current_post_id ); |
|
| 94 | + $current_post = get_post($current_post_id); |
|
| 96 | 95 | |
| 97 | 96 | // Post ID has to match an existing item |
| 98 | - if ( null === $current_post ) { |
|
| 99 | - wp_die( 'No valid post_id given' ); |
|
| 97 | + if (null === $current_post) { |
|
| 98 | + wp_die('No valid post_id given'); |
|
| 100 | 99 | |
| 101 | 100 | return; |
| 102 | 101 | } |
@@ -104,57 +103,55 @@ discard block |
||
| 104 | 103 | // If the current post is an entity, |
| 105 | 104 | // the current post is used as main entity. |
| 106 | 105 | // Otherwise, current post related entities are used. |
| 107 | - $entity_ids = ( Wordlift_Entity_Service::TYPE_NAME === $current_post->post_type ) ? |
|
| 108 | - array( $current_post->ID ) : |
|
| 109 | - wl_core_get_related_entity_ids( $current_post->ID ); |
|
| 106 | + $entity_ids = (Wordlift_Entity_Service::TYPE_NAME === $current_post->post_type) ? |
|
| 107 | + array($current_post->ID) : wl_core_get_related_entity_ids($current_post->ID); |
|
| 110 | 108 | |
| 111 | 109 | // If there are no entities we cannot render the widget |
| 112 | - if ( 0 === count( $entity_ids ) ) { |
|
| 113 | - wp_die( 'No entities available' ); |
|
| 110 | + if (0 === count($entity_ids)) { |
|
| 111 | + wp_die('No entities available'); |
|
| 114 | 112 | |
| 115 | 113 | return; |
| 116 | 114 | } |
| 117 | 115 | |
| 118 | 116 | // Retrieve requested type |
| 119 | - $required_type = ( isset( $_GET['type'] ) ) ? $_GET['type'] : null; |
|
| 117 | + $required_type = (isset($_GET['type'])) ? $_GET['type'] : null; |
|
| 120 | 118 | |
| 121 | 119 | // Set up data structures |
| 122 | - $referencing_posts = wl_core_get_posts( array( |
|
| 120 | + $referencing_posts = wl_core_get_posts(array( |
|
| 123 | 121 | 'get' => 'posts', |
| 124 | - 'post__not_in' => array( $current_post_id ), |
|
| 122 | + 'post__not_in' => array($current_post_id), |
|
| 125 | 123 | 'related_to__in' => $entity_ids, |
| 126 | 124 | 'post_type' => 'post', |
| 127 | 125 | 'as' => 'subject', |
| 128 | 126 | 'post_status' => 'publish', |
| 129 | - ) ); |
|
| 127 | + )); |
|
| 130 | 128 | |
| 131 | - $referencing_post_ids = array_map( function ( $p ) { |
|
| 129 | + $referencing_post_ids = array_map(function($p) { |
|
| 132 | 130 | return $p->ID; |
| 133 | - }, $referencing_posts ); |
|
| 131 | + }, $referencing_posts); |
|
| 134 | 132 | $results = array(); |
| 135 | 133 | |
| 136 | - if ( 'posts' === $required_type ) { |
|
| 134 | + if ('posts' === $required_type) { |
|
| 137 | 135 | |
| 138 | 136 | // Required filtered posts. |
| 139 | - wl_write_log( "Going to find related posts for the current post [ post ID :: $current_post_id ]" ); |
|
| 137 | + wl_write_log("Going to find related posts for the current post [ post ID :: $current_post_id ]"); |
|
| 140 | 138 | |
| 141 | - $filtered_posts = ( empty( $filtering_entity_uris ) ) ? |
|
| 142 | - $referencing_posts : |
|
| 143 | - wl_core_get_posts( array( |
|
| 139 | + $filtered_posts = (empty($filtering_entity_uris)) ? |
|
| 140 | + $referencing_posts : wl_core_get_posts(array( |
|
| 144 | 141 | 'get' => 'posts', |
| 145 | 142 | 'post__in' => $referencing_post_ids, |
| 146 | - 'related_to__in' => wl_get_entity_post_ids_by_uris( $filtering_entity_uris ), |
|
| 143 | + 'related_to__in' => wl_get_entity_post_ids_by_uris($filtering_entity_uris), |
|
| 147 | 144 | 'post_type' => 'post', |
| 148 | 145 | 'as' => 'subject', |
| 149 | - ) ); |
|
| 146 | + )); |
|
| 150 | 147 | |
| 151 | - if ( $filtered_posts ) { |
|
| 152 | - foreach ( $filtered_posts as $post_obj ) { |
|
| 148 | + if ($filtered_posts) { |
|
| 149 | + foreach ($filtered_posts as $post_obj) { |
|
| 153 | 150 | |
| 154 | - $thumbnail = wp_get_attachment_url( get_post_thumbnail_id( $post_obj->ID, 'thumbnail' ) ); |
|
| 155 | - $post_obj->thumbnail = ( $thumbnail ) ? |
|
| 151 | + $thumbnail = wp_get_attachment_url(get_post_thumbnail_id($post_obj->ID, 'thumbnail')); |
|
| 152 | + $post_obj->thumbnail = ($thumbnail) ? |
|
| 156 | 153 | $thumbnail : WL_DEFAULT_THUMBNAIL_PATH; |
| 157 | - $post_obj->permalink = get_post_permalink( $post_obj->ID ); |
|
| 154 | + $post_obj->permalink = get_post_permalink($post_obj->ID); |
|
| 158 | 155 | |
| 159 | 156 | $results[] = $post_obj; |
| 160 | 157 | } |
@@ -163,12 +160,12 @@ discard block |
||
| 163 | 160 | |
| 164 | 161 | global $wpdb; |
| 165 | 162 | |
| 166 | - wl_write_log( "Going to find related entities for the current post [ post ID :: $current_post_id ]" ); |
|
| 163 | + wl_write_log("Going to find related entities for the current post [ post ID :: $current_post_id ]"); |
|
| 167 | 164 | |
| 168 | 165 | // Retrieve Wordlift relation instances table name |
| 169 | 166 | $table_name = wl_core_get_relation_instances_table_name(); |
| 170 | 167 | |
| 171 | - $subject_ids = implode( ',', $referencing_post_ids ); |
|
| 168 | + $subject_ids = implode(',', $referencing_post_ids); |
|
| 172 | 169 | |
| 173 | 170 | $query = <<<EOF |
| 174 | 171 | SELECT object_id as ID, count( object_id ) as counter |
@@ -176,19 +173,19 @@ discard block |
||
| 176 | 173 | WHERE subject_id IN ($subject_ids) and object_id != ($current_post_id) |
| 177 | 174 | GROUP BY object_id; |
| 178 | 175 | EOF; |
| 179 | - wl_write_log( "Going to find related entities for the current post [ post ID :: $current_post_id ] [ query :: $query ]" ); |
|
| 176 | + wl_write_log("Going to find related entities for the current post [ post ID :: $current_post_id ] [ query :: $query ]"); |
|
| 180 | 177 | |
| 181 | - $entities = $wpdb->get_results( $query, OBJECT ); |
|
| 178 | + $entities = $wpdb->get_results($query, OBJECT); |
|
| 182 | 179 | |
| 183 | - wl_write_log( "Entities found " . count( $entities ) ); |
|
| 180 | + wl_write_log("Entities found ".count($entities)); |
|
| 184 | 181 | |
| 185 | - foreach ( $entities as $obj ) { |
|
| 182 | + foreach ($entities as $obj) { |
|
| 186 | 183 | |
| 187 | - $entity = get_post( $obj->ID ); |
|
| 184 | + $entity = get_post($obj->ID); |
|
| 188 | 185 | // Ensure only valid and published entities are returned |
| 189 | - if ( ( null !== $entity ) && ( 'publish' === $entity->post_status ) ) { |
|
| 186 | + if ((null !== $entity) && ('publish' === $entity->post_status)) { |
|
| 190 | 187 | |
| 191 | - $serialized_entity = wl_serialize_entity( $entity ); |
|
| 188 | + $serialized_entity = wl_serialize_entity($entity); |
|
| 192 | 189 | $serialized_entity['counter'] = $obj->counter; |
| 193 | 190 | $serialized_entity['createdAt'] = $entity->post_date; |
| 194 | 191 | |
@@ -198,10 +195,10 @@ discard block |
||
| 198 | 195 | |
| 199 | 196 | } |
| 200 | 197 | |
| 201 | - wl_core_send_json( $results ); |
|
| 198 | + wl_core_send_json($results); |
|
| 202 | 199 | |
| 203 | 200 | } |
| 204 | 201 | |
| 205 | -add_action( 'wp_ajax_wl_faceted_search', 'wl_shortcode_faceted_search_ajax' ); |
|
| 206 | -add_action( 'wp_ajax_nopriv_wl_faceted_search', 'wl_shortcode_faceted_search_ajax' ); |
|
| 202 | +add_action('wp_ajax_wl_faceted_search', 'wl_shortcode_faceted_search_ajax'); |
|
| 203 | +add_action('wp_ajax_nopriv_wl_faceted_search', 'wl_shortcode_faceted_search_ajax'); |
|
| 207 | 204 | |
@@ -22,136 +22,136 @@ |
||
| 22 | 22 | */ |
| 23 | 23 | class Wordlift_Admin { |
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * The ID of this plugin. |
|
| 27 | - * |
|
| 28 | - * @since 1.0.0 |
|
| 29 | - * @access private |
|
| 30 | - * @var string $plugin_name The ID of this plugin. |
|
| 31 | - */ |
|
| 32 | - private $plugin_name; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * The version of this plugin. |
|
| 36 | - * |
|
| 37 | - * @since 1.0.0 |
|
| 38 | - * @access private |
|
| 39 | - * @var string $version The current version of this plugin. |
|
| 40 | - */ |
|
| 41 | - private $version; |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * Initialize the class and set its properties. |
|
| 45 | - * |
|
| 46 | - * @since 1.0.0 |
|
| 47 | - * |
|
| 48 | - * @param string $plugin_name The name of this plugin. |
|
| 49 | - * @param string $version The version of this plugin. |
|
| 50 | - * @param \Wordlift_Configuration_Service $configuration_service The configuration service. |
|
| 51 | - * @param \Wordlift_Notice_Service $notice_service The notice service. |
|
| 52 | - */ |
|
| 53 | - public function __construct( $plugin_name, $version, $configuration_service, $notice_service ) { |
|
| 54 | - |
|
| 55 | - $this->plugin_name = $plugin_name; |
|
| 56 | - $this->version = $version; |
|
| 57 | - |
|
| 58 | - $dataset_uri = $configuration_service->get_dataset_uri(); |
|
| 59 | - $key = $configuration_service->get_key(); |
|
| 60 | - |
|
| 61 | - if ( empty( $dataset_uri ) ) { |
|
| 62 | - if ( empty( $key ) ) { |
|
| 63 | - $error = __( 'WordLift\'s key is unset: WordLift requires a key.', 'wordlift' ); |
|
| 64 | - } else { |
|
| 65 | - $error = __( 'WordLift\'s dataset URI is unset: please retry WordLift\'s configuration.', 'wordlift' ); |
|
| 66 | - } |
|
| 67 | - $notice_service->add_error( $error ); |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * Register the stylesheets for the admin area. |
|
| 74 | - * |
|
| 75 | - * @since 1.0.0 |
|
| 76 | - */ |
|
| 77 | - public function enqueue_styles() { |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * This function is provided for demonstration purposes only. |
|
| 81 | - * |
|
| 82 | - * An instance of this class should be passed to the run() function |
|
| 83 | - * defined in Wordlift_Loader as all of the hooks are defined |
|
| 84 | - * in that particular class. |
|
| 85 | - * |
|
| 86 | - * The Wordlift_Loader will then create the relationship |
|
| 87 | - * between the defined hooks and the functions defined in this |
|
| 88 | - * class. |
|
| 89 | - */ |
|
| 90 | - |
|
| 91 | - wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/wordlift-admin.css', array(), $this->version, 'all' ); |
|
| 92 | - |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * Register the JavaScript for the admin area. |
|
| 97 | - * |
|
| 98 | - * @since 1.0.0 |
|
| 99 | - */ |
|
| 100 | - public function enqueue_scripts() { |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * This function is provided for demonstration purposes only. |
|
| 104 | - * |
|
| 105 | - * An instance of this class should be passed to the run() function |
|
| 106 | - * defined in Wordlift_Loader as all of the hooks are defined |
|
| 107 | - * in that particular class. |
|
| 108 | - * |
|
| 109 | - * The Wordlift_Loader will then create the relationship |
|
| 110 | - * between the defined hooks and the functions defined in this |
|
| 111 | - * class. |
|
| 112 | - */ |
|
| 113 | - |
|
| 114 | - $configuration_service = Wordlift_Configuration_Service::get_instance(); |
|
| 115 | - |
|
| 116 | - // Enqueue the admin scripts. |
|
| 117 | - wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/wordlift-admin.bundle.js', array( |
|
| 118 | - 'jquery', |
|
| 119 | - 'underscore', |
|
| 120 | - 'backbone', |
|
| 121 | - ), $this->version, false ); |
|
| 122 | - |
|
| 123 | - // Set the basic params. |
|
| 124 | - $params = array( |
|
| 125 | - // @todo scripts in admin should use wp.post. |
|
| 126 | - 'ajax_url' => admin_url( 'admin-ajax.php' ), |
|
| 127 | - // @todo remove specific actions from settings. |
|
| 128 | - 'action' => 'entity_by_title', |
|
| 129 | - 'datasetUri' => $configuration_service->get_dataset_uri(), |
|
| 130 | - 'language' => $configuration_service->get_language_code(), |
|
| 131 | - 'link_by_default' => $configuration_service->is_link_by_default(), |
|
| 132 | - 'l10n' => array( |
|
| 133 | - 'You already published an entity with the same name' => __( 'You already published an entity with the same name: ', 'wordlift' ), |
|
| 134 | - 'logo_selection_title' => __( 'WordLift Choose Logo', 'wordlift' ), |
|
| 135 | - 'logo_selection_button' => array( 'text' => __( 'Choose Logo', 'wordlift' ) ), |
|
| 136 | - ), |
|
| 137 | - ); |
|
| 138 | - |
|
| 139 | - // Set post-related values if there's a current post. |
|
| 140 | - if ( null !== $post = $entity_being_edited = get_post() ) { |
|
| 141 | - |
|
| 142 | - $params['post_id'] = $entity_being_edited->ID; |
|
| 143 | - $params['entityBeingEdited'] = isset( $entity_being_edited->post_type ) && Wordlift_Entity_Service::TYPE_NAME == $entity_being_edited->post_type && is_numeric( get_the_ID() ); |
|
| 144 | - // We add the `itemId` here to give a chance to the analysis to use it in order to tell WLS to exclude it |
|
| 145 | - // from the results, since we don't want the current entity to be discovered by the analysis. |
|
| 146 | - // |
|
| 147 | - // See https://github.com/insideout10/wordlift-plugin/issues/345 |
|
| 148 | - $params['itemId'] = Wordlift_Entity_Service::get_instance()->get_uri( $entity_being_edited->ID ); |
|
| 149 | - |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - // Finally output the params as `wlSettings` for JavaScript code. |
|
| 153 | - wp_localize_script( $this->plugin_name, 'wlSettings', $params ); |
|
| 154 | - |
|
| 155 | - } |
|
| 25 | + /** |
|
| 26 | + * The ID of this plugin. |
|
| 27 | + * |
|
| 28 | + * @since 1.0.0 |
|
| 29 | + * @access private |
|
| 30 | + * @var string $plugin_name The ID of this plugin. |
|
| 31 | + */ |
|
| 32 | + private $plugin_name; |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * The version of this plugin. |
|
| 36 | + * |
|
| 37 | + * @since 1.0.0 |
|
| 38 | + * @access private |
|
| 39 | + * @var string $version The current version of this plugin. |
|
| 40 | + */ |
|
| 41 | + private $version; |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * Initialize the class and set its properties. |
|
| 45 | + * |
|
| 46 | + * @since 1.0.0 |
|
| 47 | + * |
|
| 48 | + * @param string $plugin_name The name of this plugin. |
|
| 49 | + * @param string $version The version of this plugin. |
|
| 50 | + * @param \Wordlift_Configuration_Service $configuration_service The configuration service. |
|
| 51 | + * @param \Wordlift_Notice_Service $notice_service The notice service. |
|
| 52 | + */ |
|
| 53 | + public function __construct( $plugin_name, $version, $configuration_service, $notice_service ) { |
|
| 54 | + |
|
| 55 | + $this->plugin_name = $plugin_name; |
|
| 56 | + $this->version = $version; |
|
| 57 | + |
|
| 58 | + $dataset_uri = $configuration_service->get_dataset_uri(); |
|
| 59 | + $key = $configuration_service->get_key(); |
|
| 60 | + |
|
| 61 | + if ( empty( $dataset_uri ) ) { |
|
| 62 | + if ( empty( $key ) ) { |
|
| 63 | + $error = __( 'WordLift\'s key is unset: WordLift requires a key.', 'wordlift' ); |
|
| 64 | + } else { |
|
| 65 | + $error = __( 'WordLift\'s dataset URI is unset: please retry WordLift\'s configuration.', 'wordlift' ); |
|
| 66 | + } |
|
| 67 | + $notice_service->add_error( $error ); |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * Register the stylesheets for the admin area. |
|
| 74 | + * |
|
| 75 | + * @since 1.0.0 |
|
| 76 | + */ |
|
| 77 | + public function enqueue_styles() { |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * This function is provided for demonstration purposes only. |
|
| 81 | + * |
|
| 82 | + * An instance of this class should be passed to the run() function |
|
| 83 | + * defined in Wordlift_Loader as all of the hooks are defined |
|
| 84 | + * in that particular class. |
|
| 85 | + * |
|
| 86 | + * The Wordlift_Loader will then create the relationship |
|
| 87 | + * between the defined hooks and the functions defined in this |
|
| 88 | + * class. |
|
| 89 | + */ |
|
| 90 | + |
|
| 91 | + wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/wordlift-admin.css', array(), $this->version, 'all' ); |
|
| 92 | + |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * Register the JavaScript for the admin area. |
|
| 97 | + * |
|
| 98 | + * @since 1.0.0 |
|
| 99 | + */ |
|
| 100 | + public function enqueue_scripts() { |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * This function is provided for demonstration purposes only. |
|
| 104 | + * |
|
| 105 | + * An instance of this class should be passed to the run() function |
|
| 106 | + * defined in Wordlift_Loader as all of the hooks are defined |
|
| 107 | + * in that particular class. |
|
| 108 | + * |
|
| 109 | + * The Wordlift_Loader will then create the relationship |
|
| 110 | + * between the defined hooks and the functions defined in this |
|
| 111 | + * class. |
|
| 112 | + */ |
|
| 113 | + |
|
| 114 | + $configuration_service = Wordlift_Configuration_Service::get_instance(); |
|
| 115 | + |
|
| 116 | + // Enqueue the admin scripts. |
|
| 117 | + wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/wordlift-admin.bundle.js', array( |
|
| 118 | + 'jquery', |
|
| 119 | + 'underscore', |
|
| 120 | + 'backbone', |
|
| 121 | + ), $this->version, false ); |
|
| 122 | + |
|
| 123 | + // Set the basic params. |
|
| 124 | + $params = array( |
|
| 125 | + // @todo scripts in admin should use wp.post. |
|
| 126 | + 'ajax_url' => admin_url( 'admin-ajax.php' ), |
|
| 127 | + // @todo remove specific actions from settings. |
|
| 128 | + 'action' => 'entity_by_title', |
|
| 129 | + 'datasetUri' => $configuration_service->get_dataset_uri(), |
|
| 130 | + 'language' => $configuration_service->get_language_code(), |
|
| 131 | + 'link_by_default' => $configuration_service->is_link_by_default(), |
|
| 132 | + 'l10n' => array( |
|
| 133 | + 'You already published an entity with the same name' => __( 'You already published an entity with the same name: ', 'wordlift' ), |
|
| 134 | + 'logo_selection_title' => __( 'WordLift Choose Logo', 'wordlift' ), |
|
| 135 | + 'logo_selection_button' => array( 'text' => __( 'Choose Logo', 'wordlift' ) ), |
|
| 136 | + ), |
|
| 137 | + ); |
|
| 138 | + |
|
| 139 | + // Set post-related values if there's a current post. |
|
| 140 | + if ( null !== $post = $entity_being_edited = get_post() ) { |
|
| 141 | + |
|
| 142 | + $params['post_id'] = $entity_being_edited->ID; |
|
| 143 | + $params['entityBeingEdited'] = isset( $entity_being_edited->post_type ) && Wordlift_Entity_Service::TYPE_NAME == $entity_being_edited->post_type && is_numeric( get_the_ID() ); |
|
| 144 | + // We add the `itemId` here to give a chance to the analysis to use it in order to tell WLS to exclude it |
|
| 145 | + // from the results, since we don't want the current entity to be discovered by the analysis. |
|
| 146 | + // |
|
| 147 | + // See https://github.com/insideout10/wordlift-plugin/issues/345 |
|
| 148 | + $params['itemId'] = Wordlift_Entity_Service::get_instance()->get_uri( $entity_being_edited->ID ); |
|
| 149 | + |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + // Finally output the params as `wlSettings` for JavaScript code. |
|
| 153 | + wp_localize_script( $this->plugin_name, 'wlSettings', $params ); |
|
| 154 | + |
|
| 155 | + } |
|
| 156 | 156 | |
| 157 | 157 | } |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | * @param \Wordlift_Configuration_Service $configuration_service The configuration service. |
| 51 | 51 | * @param \Wordlift_Notice_Service $notice_service The notice service. |
| 52 | 52 | */ |
| 53 | - public function __construct( $plugin_name, $version, $configuration_service, $notice_service ) { |
|
| 53 | + public function __construct($plugin_name, $version, $configuration_service, $notice_service) { |
|
| 54 | 54 | |
| 55 | 55 | $this->plugin_name = $plugin_name; |
| 56 | 56 | $this->version = $version; |
@@ -58,13 +58,13 @@ discard block |
||
| 58 | 58 | $dataset_uri = $configuration_service->get_dataset_uri(); |
| 59 | 59 | $key = $configuration_service->get_key(); |
| 60 | 60 | |
| 61 | - if ( empty( $dataset_uri ) ) { |
|
| 62 | - if ( empty( $key ) ) { |
|
| 63 | - $error = __( 'WordLift\'s key is unset: WordLift requires a key.', 'wordlift' ); |
|
| 61 | + if (empty($dataset_uri)) { |
|
| 62 | + if (empty($key)) { |
|
| 63 | + $error = __('WordLift\'s key is unset: WordLift requires a key.', 'wordlift'); |
|
| 64 | 64 | } else { |
| 65 | - $error = __( 'WordLift\'s dataset URI is unset: please retry WordLift\'s configuration.', 'wordlift' ); |
|
| 65 | + $error = __('WordLift\'s dataset URI is unset: please retry WordLift\'s configuration.', 'wordlift'); |
|
| 66 | 66 | } |
| 67 | - $notice_service->add_error( $error ); |
|
| 67 | + $notice_service->add_error($error); |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | } |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | * class. |
| 89 | 89 | */ |
| 90 | 90 | |
| 91 | - wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/wordlift-admin.css', array(), $this->version, 'all' ); |
|
| 91 | + wp_enqueue_style($this->plugin_name, plugin_dir_url(__FILE__).'css/wordlift-admin.css', array(), $this->version, 'all'); |
|
| 92 | 92 | |
| 93 | 93 | } |
| 94 | 94 | |
@@ -114,43 +114,43 @@ discard block |
||
| 114 | 114 | $configuration_service = Wordlift_Configuration_Service::get_instance(); |
| 115 | 115 | |
| 116 | 116 | // Enqueue the admin scripts. |
| 117 | - wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/wordlift-admin.bundle.js', array( |
|
| 117 | + wp_enqueue_script($this->plugin_name, plugin_dir_url(__FILE__).'js/wordlift-admin.bundle.js', array( |
|
| 118 | 118 | 'jquery', |
| 119 | 119 | 'underscore', |
| 120 | 120 | 'backbone', |
| 121 | - ), $this->version, false ); |
|
| 121 | + ), $this->version, false); |
|
| 122 | 122 | |
| 123 | 123 | // Set the basic params. |
| 124 | 124 | $params = array( |
| 125 | 125 | // @todo scripts in admin should use wp.post. |
| 126 | - 'ajax_url' => admin_url( 'admin-ajax.php' ), |
|
| 126 | + 'ajax_url' => admin_url('admin-ajax.php'), |
|
| 127 | 127 | // @todo remove specific actions from settings. |
| 128 | 128 | 'action' => 'entity_by_title', |
| 129 | 129 | 'datasetUri' => $configuration_service->get_dataset_uri(), |
| 130 | 130 | 'language' => $configuration_service->get_language_code(), |
| 131 | 131 | 'link_by_default' => $configuration_service->is_link_by_default(), |
| 132 | 132 | 'l10n' => array( |
| 133 | - 'You already published an entity with the same name' => __( 'You already published an entity with the same name: ', 'wordlift' ), |
|
| 134 | - 'logo_selection_title' => __( 'WordLift Choose Logo', 'wordlift' ), |
|
| 135 | - 'logo_selection_button' => array( 'text' => __( 'Choose Logo', 'wordlift' ) ), |
|
| 133 | + 'You already published an entity with the same name' => __('You already published an entity with the same name: ', 'wordlift'), |
|
| 134 | + 'logo_selection_title' => __('WordLift Choose Logo', 'wordlift'), |
|
| 135 | + 'logo_selection_button' => array('text' => __('Choose Logo', 'wordlift')), |
|
| 136 | 136 | ), |
| 137 | 137 | ); |
| 138 | 138 | |
| 139 | 139 | // Set post-related values if there's a current post. |
| 140 | - if ( null !== $post = $entity_being_edited = get_post() ) { |
|
| 140 | + if (null !== $post = $entity_being_edited = get_post()) { |
|
| 141 | 141 | |
| 142 | 142 | $params['post_id'] = $entity_being_edited->ID; |
| 143 | - $params['entityBeingEdited'] = isset( $entity_being_edited->post_type ) && Wordlift_Entity_Service::TYPE_NAME == $entity_being_edited->post_type && is_numeric( get_the_ID() ); |
|
| 143 | + $params['entityBeingEdited'] = isset($entity_being_edited->post_type) && Wordlift_Entity_Service::TYPE_NAME == $entity_being_edited->post_type && is_numeric(get_the_ID()); |
|
| 144 | 144 | // We add the `itemId` here to give a chance to the analysis to use it in order to tell WLS to exclude it |
| 145 | 145 | // from the results, since we don't want the current entity to be discovered by the analysis. |
| 146 | 146 | // |
| 147 | 147 | // See https://github.com/insideout10/wordlift-plugin/issues/345 |
| 148 | - $params['itemId'] = Wordlift_Entity_Service::get_instance()->get_uri( $entity_being_edited->ID ); |
|
| 148 | + $params['itemId'] = Wordlift_Entity_Service::get_instance()->get_uri($entity_being_edited->ID); |
|
| 149 | 149 | |
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | // Finally output the params as `wlSettings` for JavaScript code. |
| 153 | - wp_localize_script( $this->plugin_name, 'wlSettings', $params ); |
|
| 153 | + wp_localize_script($this->plugin_name, 'wlSettings', $params); |
|
| 154 | 154 | |
| 155 | 155 | } |
| 156 | 156 | |
@@ -18,49 +18,49 @@ discard block |
||
| 18 | 18 | */ |
| 19 | 19 | class Wordlift_Admin_Radio_Input_Element implements Wordlift_Admin_Element { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * Output the HTML for an input box type settings_page. |
|
| 23 | - * |
|
| 24 | - * @since 3.13.0 |
|
| 25 | - * |
|
| 26 | - * @param array $args { |
|
| 27 | - * An array of arguments. |
|
| 28 | - * |
|
| 29 | - * @type string $name The name attribute of the input element. Mandatory. |
|
| 30 | - * @type string $id The id attribute of the input element. Optional, |
|
| 31 | - * randomly generated one is used if not supplied. |
|
| 32 | - * @type string $value The value of the input element. Optional, defaults |
|
| 33 | - * to empty string. |
|
| 34 | - * @type string $css_class The class attribute for the input element. If empty |
|
| 35 | - * string no class attribute will be added. Optional, |
|
| 36 | - * defaults to empty string. |
|
| 37 | - * @type string $description The description text to be displayed below the element. |
|
| 38 | - * Can include some HTML element. If empty string no |
|
| 39 | - * description will be displayed. Optional, defaults to |
|
| 40 | - * empty string. |
|
| 41 | - * } |
|
| 42 | - * @return $this|Wordlift_Admin_Element |
|
| 43 | - */ |
|
| 44 | - public function render( $args ) { |
|
| 21 | + /** |
|
| 22 | + * Output the HTML for an input box type settings_page. |
|
| 23 | + * |
|
| 24 | + * @since 3.13.0 |
|
| 25 | + * |
|
| 26 | + * @param array $args { |
|
| 27 | + * An array of arguments. |
|
| 28 | + * |
|
| 29 | + * @type string $name The name attribute of the input element. Mandatory. |
|
| 30 | + * @type string $id The id attribute of the input element. Optional, |
|
| 31 | + * randomly generated one is used if not supplied. |
|
| 32 | + * @type string $value The value of the input element. Optional, defaults |
|
| 33 | + * to empty string. |
|
| 34 | + * @type string $css_class The class attribute for the input element. If empty |
|
| 35 | + * string no class attribute will be added. Optional, |
|
| 36 | + * defaults to empty string. |
|
| 37 | + * @type string $description The description text to be displayed below the element. |
|
| 38 | + * Can include some HTML element. If empty string no |
|
| 39 | + * description will be displayed. Optional, defaults to |
|
| 40 | + * empty string. |
|
| 41 | + * } |
|
| 42 | + * @return $this|Wordlift_Admin_Element |
|
| 43 | + */ |
|
| 44 | + public function render( $args ) { |
|
| 45 | 45 | |
| 46 | - /* |
|
| 46 | + /* |
|
| 47 | 47 | * Parse the arguments and merge with default values. |
| 48 | 48 | * Name intentionally do not have a default as it has to be in SyncEvent |
| 49 | 49 | * with form handling code |
| 50 | 50 | */ |
| 51 | - $params = wp_parse_args( $args, array( |
|
| 52 | - 'id' => uniqid( 'wl-input-' ), |
|
| 53 | - 'value' => '', |
|
| 54 | - 'css_class' => '', |
|
| 55 | - 'description' => '', |
|
| 56 | - ) ); |
|
| 51 | + $params = wp_parse_args( $args, array( |
|
| 52 | + 'id' => uniqid( 'wl-input-' ), |
|
| 53 | + 'value' => '', |
|
| 54 | + 'css_class' => '', |
|
| 55 | + 'description' => '', |
|
| 56 | + ) ); |
|
| 57 | 57 | |
| 58 | - // Set the readonly and class attributes and the description. |
|
| 59 | - $value = $params['value']; |
|
| 60 | - $css_class = ! empty( $params['css_class'] ) ? ' class="' . esc_attr( $params['css_class'] ) . '"' : ''; |
|
| 61 | - $description = ! empty( $params['description'] ) ? '<p>' . wp_kses( $params['description'], array( 'a' => array( 'href' => array() ) ) ) . '</p>' : ''; |
|
| 58 | + // Set the readonly and class attributes and the description. |
|
| 59 | + $value = $params['value']; |
|
| 60 | + $css_class = ! empty( $params['css_class'] ) ? ' class="' . esc_attr( $params['css_class'] ) . '"' : ''; |
|
| 61 | + $description = ! empty( $params['description'] ) ? '<p>' . wp_kses( $params['description'], array( 'a' => array( 'href' => array() ) ) ) . '</p>' : ''; |
|
| 62 | 62 | |
| 63 | - ?> |
|
| 63 | + ?> |
|
| 64 | 64 | |
| 65 | 65 | <input type="radio" id="<?php echo esc_attr( $params['id'] ); ?>" |
| 66 | 66 | name="<?php echo esc_attr( $params['name'] ); ?>" |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | <?php echo $description; ?> |
| 75 | 75 | |
| 76 | 76 | <?php |
| 77 | - return $this; |
|
| 78 | - } |
|
| 77 | + return $this; |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | 80 | } |
@@ -41,35 +41,35 @@ |
||
| 41 | 41 | * } |
| 42 | 42 | * @return $this|Wordlift_Admin_Element |
| 43 | 43 | */ |
| 44 | - public function render( $args ) { |
|
| 44 | + public function render($args) { |
|
| 45 | 45 | |
| 46 | 46 | /* |
| 47 | 47 | * Parse the arguments and merge with default values. |
| 48 | 48 | * Name intentionally do not have a default as it has to be in SyncEvent |
| 49 | 49 | * with form handling code |
| 50 | 50 | */ |
| 51 | - $params = wp_parse_args( $args, array( |
|
| 52 | - 'id' => uniqid( 'wl-input-' ), |
|
| 51 | + $params = wp_parse_args($args, array( |
|
| 52 | + 'id' => uniqid('wl-input-'), |
|
| 53 | 53 | 'value' => '', |
| 54 | 54 | 'css_class' => '', |
| 55 | 55 | 'description' => '', |
| 56 | - ) ); |
|
| 56 | + )); |
|
| 57 | 57 | |
| 58 | 58 | // Set the readonly and class attributes and the description. |
| 59 | 59 | $value = $params['value']; |
| 60 | - $css_class = ! empty( $params['css_class'] ) ? ' class="' . esc_attr( $params['css_class'] ) . '"' : ''; |
|
| 61 | - $description = ! empty( $params['description'] ) ? '<p>' . wp_kses( $params['description'], array( 'a' => array( 'href' => array() ) ) ) . '</p>' : ''; |
|
| 60 | + $css_class = ! empty($params['css_class']) ? ' class="'.esc_attr($params['css_class']).'"' : ''; |
|
| 61 | + $description = ! empty($params['description']) ? '<p>'.wp_kses($params['description'], array('a' => array('href' => array()))).'</p>' : ''; |
|
| 62 | 62 | |
| 63 | 63 | ?> |
| 64 | 64 | |
| 65 | - <input type="radio" id="<?php echo esc_attr( $params['id'] ); ?>" |
|
| 66 | - name="<?php echo esc_attr( $params['name'] ); ?>" |
|
| 65 | + <input type="radio" id="<?php echo esc_attr($params['id']); ?>" |
|
| 66 | + name="<?php echo esc_attr($params['name']); ?>" |
|
| 67 | 67 | value="yes" <?php echo $css_class; ?> |
| 68 | - <?php checked( $value, 'yes' ); ?> /> Yes |
|
| 69 | - <input type="radio" id="<?php echo esc_attr( $params['id'] ); ?>" |
|
| 70 | - name="<?php echo esc_attr( $params['name'] ); ?>" |
|
| 68 | + <?php checked($value, 'yes'); ?> /> Yes |
|
| 69 | + <input type="radio" id="<?php echo esc_attr($params['id']); ?>" |
|
| 70 | + name="<?php echo esc_attr($params['name']); ?>" |
|
| 71 | 71 | value="no" <?php echo $css_class; ?> |
| 72 | - <?php checked( $value, 'no' ); ?>/> No |
|
| 72 | + <?php checked($value, 'no'); ?>/> No |
|
| 73 | 73 | |
| 74 | 74 | <?php echo $description; ?> |
| 75 | 75 | |
@@ -18,300 +18,300 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | class Wordlift_Admin_Settings_Page extends Wordlift_Admin_Page { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * A {@link Wordlift_Entity_Service} instance. |
|
| 23 | - * |
|
| 24 | - * @since 3.11.0 |
|
| 25 | - * @access private |
|
| 26 | - * @var \Wordlift_Entity_Service $entity_service A {@link Wordlift_Entity_Service} instance. |
|
| 27 | - */ |
|
| 28 | - private $entity_service; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * A {@link Wordlift_Configuration_Service} instance. |
|
| 32 | - * |
|
| 33 | - * @since 3.11.0 |
|
| 34 | - * @access private |
|
| 35 | - * @var \Wordlift_Configuration_Service $configuration_service A {@link Wordlift_Configuration_Service} instance. |
|
| 36 | - */ |
|
| 37 | - private $configuration_service; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * A {@link Wordlift_Admin_Input_Element} element renderer. |
|
| 41 | - * |
|
| 42 | - * @since 3.11.0 |
|
| 43 | - * @access private |
|
| 44 | - * @var \Wordlift_Admin_Input_Element $input_element An {@link Wordlift_Admin_Input_Element} element renderer. |
|
| 45 | - */ |
|
| 46 | - private $input_element; |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * A {@link Wordlift_Admin_Radio_Input_Element} element renderer. |
|
| 50 | - * |
|
| 51 | - * @since 3.13.0 |
|
| 52 | - * @access protected |
|
| 53 | - * @var \Wordlift_Admin_Radio_Input_Element $radio_input_element A {@link Wordlift_Admin_Radio_Input_Element} element renderer. |
|
| 54 | - */ |
|
| 55 | - private $radio_input_element; |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * A {@link Wordlift_Admin_Language_Select_Element} element renderer. |
|
| 59 | - * |
|
| 60 | - * @since 3.11.0 |
|
| 61 | - * @access private |
|
| 62 | - * @var \Wordlift_Admin_Language_Select_Element $language_select_element A {@link Wordlift_Admin_Language_Select_Element} element renderer. |
|
| 63 | - */ |
|
| 64 | - private $language_select_element; |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * A {@link Wordlift_Admin_Publisher_Element} element renderer. |
|
| 68 | - * |
|
| 69 | - * @since 3.11.0 |
|
| 70 | - * @access private |
|
| 71 | - * @var \Wordlift_Admin_Publisher_Element $publisher_element A {@link Wordlift_Admin_Publisher_Element} element renderer. |
|
| 72 | - */ |
|
| 73 | - private $publisher_element; |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * Create a {@link Wordlift_Admin_Settings_Page} instance. |
|
| 77 | - * |
|
| 78 | - * @since 3.11.0 |
|
| 79 | - * |
|
| 80 | - * @param \Wordlift_Configuration_Service $configuration_service |
|
| 81 | - * @param \Wordlift_Entity_Service $entity_service |
|
| 82 | - * @param \Wordlift_Admin_Input_Element $input_element |
|
| 83 | - * @param \Wordlift_Admin_Language_Select_Element $language_select_element |
|
| 84 | - * @param \Wordlift_Admin_Publisher_Element $publisher_element |
|
| 85 | - * @param \Wordlift_Admin_Radio_Input_Element $radio_input_element |
|
| 86 | - */ |
|
| 87 | - function __construct( $configuration_service, $entity_service, $input_element, $language_select_element, $publisher_element, $radio_input_element ) { |
|
| 88 | - |
|
| 89 | - $this->configuration_service = $configuration_service; |
|
| 90 | - $this->entity_service = $entity_service; |
|
| 91 | - |
|
| 92 | - // Set a reference to the UI elements. |
|
| 93 | - $this->input_element = $input_element; |
|
| 94 | - $this->radio_input_element = $radio_input_element; |
|
| 95 | - $this->language_select_element = $language_select_element; |
|
| 96 | - $this->publisher_element = $publisher_element; |
|
| 97 | - |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * @inheritdoc |
|
| 102 | - */ |
|
| 103 | - function get_parent_slug() { |
|
| 104 | - |
|
| 105 | - return 'wl_admin_menu'; |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * @inheritdoc |
|
| 110 | - */ |
|
| 111 | - function get_capability() { |
|
| 112 | - |
|
| 113 | - return 'manage_options'; |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * @inheritdoc |
|
| 118 | - */ |
|
| 119 | - function get_page_title() { |
|
| 120 | - |
|
| 121 | - return 'WorldLift Settings'; |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - /** |
|
| 125 | - * @inheritdoc |
|
| 126 | - */ |
|
| 127 | - function get_menu_title() { |
|
| 128 | - |
|
| 129 | - return 'Settings'; |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - /** |
|
| 133 | - * @inheritdoc |
|
| 134 | - */ |
|
| 135 | - function get_menu_slug() { |
|
| 136 | - |
|
| 137 | - return 'wl_configuration_admin_menu'; |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * @inheritdoc |
|
| 142 | - */ |
|
| 143 | - function get_partial_name() { |
|
| 144 | - |
|
| 145 | - return 'wordlift-admin-settings-page.php'; |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - /** |
|
| 149 | - * @inheritdoc |
|
| 150 | - */ |
|
| 151 | - public function enqueue_scripts() { |
|
| 152 | - |
|
| 153 | - // Enqueue the media scripts to be used for the publisher's logo selection. |
|
| 154 | - wp_enqueue_media(); |
|
| 155 | - |
|
| 156 | - // JavaScript required for the settings page. |
|
| 157 | - // @todo: try to move to the `wordlift-admin.bundle.js`. |
|
| 158 | - wp_enqueue_script( 'wordlift-admin-settings-page', plugin_dir_url( dirname( __FILE__ ) ) . 'admin/js/wordlift-admin-settings-page.bundle.js', array( 'wp-util' ) ); |
|
| 159 | - |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * Configure all the configuration parameters. |
|
| 164 | - * |
|
| 165 | - * Called by the *admin_init* hook. |
|
| 166 | - * |
|
| 167 | - * @since 3.11.0 |
|
| 168 | - */ |
|
| 169 | - function admin_init() { |
|
| 170 | - |
|
| 171 | - // Register WordLift's general settings, providing our own sanitize callback |
|
| 172 | - // which will also check whether the user filled the WL Publisher form. |
|
| 173 | - register_setting( |
|
| 174 | - 'wl_general_settings', |
|
| 175 | - 'wl_general_settings', |
|
| 176 | - array( $this, 'sanitize_callback', ) |
|
| 177 | - ); |
|
| 178 | - |
|
| 179 | - // Add the general settings section. |
|
| 180 | - add_settings_section( |
|
| 181 | - 'wl_general_settings_section', // ID used to identify this section and with which to register options. |
|
| 182 | - '', // Section header. |
|
| 183 | - '', // Callback used to render the description of the section. |
|
| 184 | - 'wl_general_settings' // Page on which to add this section of options. |
|
| 185 | - ); |
|
| 186 | - |
|
| 187 | - $key_args = array( |
|
| 188 | - 'id' => 'wl-key', |
|
| 189 | - 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::KEY . ']', |
|
| 190 | - 'value' => $this->configuration_service->get_key(), |
|
| 191 | - 'description' => _x( 'Insert the <a href="https://www.wordlift.io/blogger">WordLift Key</a> you received via email.', 'wordlift' ), |
|
| 192 | - ); |
|
| 193 | - |
|
| 194 | - // Set the class for the key field based on the validity of the key. |
|
| 195 | - // Class should be "untouched" for an empty (virgin) value, "valid" |
|
| 196 | - // if the key is valid, or "invalid" otherwise. |
|
| 197 | - $validation_service = new Wordlift_Key_Validation_Service(); |
|
| 198 | - |
|
| 199 | - if ( empty( $key_args['value'] ) ) { |
|
| 200 | - $key_args['css_class'] = 'untouched'; |
|
| 201 | - } elseif ( $validation_service->is_valid( $key_args['value'] ) ) { |
|
| 202 | - $key_args['css_class'] = 'valid'; |
|
| 203 | - } else { |
|
| 204 | - $key_args['css_class'] = 'invalid'; |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - // Add the `key` field. |
|
| 208 | - add_settings_field( |
|
| 209 | - 'wl-key', // Element id used to identify the field throughout the theme. |
|
| 210 | - _x( 'WordLift Key', 'wordlift' ), // The label to the left of the option interface element. |
|
| 211 | - // The name of the function responsible for rendering the option interface. |
|
| 212 | - array( $this->input_element, 'render', ), |
|
| 213 | - 'wl_general_settings', // The page on which this option will be displayed. |
|
| 214 | - 'wl_general_settings_section', // The name of the section to which this field belongs. |
|
| 215 | - $key_args // The array of arguments to pass to the callback. In this case, just a description. |
|
| 216 | - ); |
|
| 217 | - |
|
| 218 | - // Entity Base Path input. |
|
| 219 | - $entity_base_path_args = array( |
|
| 220 | - // The array of arguments to pass to the callback. In this case, just a description. |
|
| 221 | - 'id' => 'wl-entity-base-path', |
|
| 222 | - 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::ENTITY_BASE_PATH_KEY . ']', |
|
| 223 | - 'value' => $this->configuration_service->get_entity_base_path(), |
|
| 224 | - 'description' => sprintf( _x( 'All new pages created with WordLift, will be stored inside your internal vocabulary. You can customize the url pattern of these pages in the field above. Check our <a href="%s">FAQs</a> if you need more info.', 'wordlift' ), 'https://wordlift.io/wordlift-user-faqs/#10-why-and-how-should-i-customize-the-url-of-the-entity-pages-created-in-my-vocabulary' ), |
|
| 225 | - ); |
|
| 226 | - |
|
| 227 | - $entity_base_path_args['readonly'] = 0 < $this->entity_service->count(); |
|
| 228 | - |
|
| 229 | - // Add the `wl_entity_base_path` field. |
|
| 230 | - add_settings_field( |
|
| 231 | - 'wl-entity-base-path', // ID used to identify the field throughout the theme |
|
| 232 | - _x( 'Entity Base Path', 'wordlift' ), // The label to the left of the option interface element |
|
| 233 | - // The name of the function responsible for rendering the option interface |
|
| 234 | - array( $this->input_element, 'render', ), |
|
| 235 | - 'wl_general_settings', // The page on which this option will be displayed |
|
| 236 | - 'wl_general_settings_section', // The name of the section to which this field belongs |
|
| 237 | - $entity_base_path_args |
|
| 238 | - ); |
|
| 239 | - |
|
| 240 | - // Add the `language_name` field. |
|
| 241 | - add_settings_field( |
|
| 242 | - 'wl-site-language', |
|
| 243 | - _x( 'Site Language', 'wordlift' ), |
|
| 244 | - array( $this->language_select_element, 'render' ), |
|
| 245 | - 'wl_general_settings', |
|
| 246 | - 'wl_general_settings_section', |
|
| 247 | - array( |
|
| 248 | - // The array of arguments to pass to the callback. In this case, just a description. |
|
| 249 | - 'id' => 'wl-site-language', |
|
| 250 | - 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::LANGUAGE . ']', |
|
| 251 | - 'value' => $this->configuration_service->get_language_code(), |
|
| 252 | - 'description' => __( 'Each WordLift Key can be used only in one language. Pick yours.', 'wordlift' ), |
|
| 253 | - ) |
|
| 254 | - ); |
|
| 255 | - |
|
| 256 | - // Add the `publisher` field. |
|
| 257 | - add_settings_field( |
|
| 258 | - 'wl-publisher-id', |
|
| 259 | - _x( 'Publisher', 'wordlift' ), |
|
| 260 | - array( $this->publisher_element, 'render' ), |
|
| 261 | - 'wl_general_settings', |
|
| 262 | - 'wl_general_settings_section', |
|
| 263 | - array( |
|
| 264 | - 'id' => 'wl-publisher-id', |
|
| 265 | - 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::PUBLISHER_ID . ']', |
|
| 266 | - ) |
|
| 267 | - ); |
|
| 268 | - |
|
| 269 | - // Add the `link by default` field. |
|
| 270 | - add_settings_field( |
|
| 271 | - 'wl-link-by-default', |
|
| 272 | - _x( 'Link by Default', 'wordlift' ), |
|
| 273 | - array( $this->radio_input_element, 'render' ), |
|
| 274 | - 'wl_general_settings', |
|
| 275 | - 'wl_general_settings_section', |
|
| 276 | - array( |
|
| 277 | - 'id' => 'wl-link-by-default', |
|
| 278 | - 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::LINK_BY_DEFAULT . ']', |
|
| 279 | - 'value' => $this->configuration_service->is_link_by_default() ? 'yes' : 'no', |
|
| 280 | - 'description' => _x( 'Whether to link entities by default or not. This setting applies to all the entities.', 'wordlift' ), |
|
| 281 | - ) |
|
| 282 | - ); |
|
| 283 | - |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - /** |
|
| 287 | - * Sanitize the configuration settings to be stored. |
|
| 288 | - * |
|
| 289 | - * If a new entity is being created for the publisher, create it and set The |
|
| 290 | - * publisher setting. |
|
| 291 | - * |
|
| 292 | - * @since 3.11.0 |
|
| 293 | - * |
|
| 294 | - * @param array $input The configuration settings array. |
|
| 295 | - * |
|
| 296 | - * @return array The sanitized input array. |
|
| 297 | - */ |
|
| 298 | - function sanitize_callback( $input ) { |
|
| 299 | - |
|
| 300 | - // Check whether a publisher name has been set. |
|
| 301 | - if ( isset( $_POST['wl_publisher'] ) && ! empty( $_POST['wl_publisher']['name'] ) ) { |
|
| 302 | - $name = $_POST['wl_publisher']['name']; |
|
| 303 | - $type = $_POST['wl_publisher']['type']; |
|
| 304 | - $thumbnail_id = $_POST['wl_publisher']['thumbnail_id'] ?: null; |
|
| 305 | - |
|
| 306 | - // Set the type URI, either http://schema.org/Person or http://schema.org/Organization. |
|
| 307 | - $type_uri = sprintf( 'http://schema.org/%s', 'organization' === $type ? 'Organization' : 'Person' ); |
|
| 308 | - |
|
| 309 | - // Create an entity for the publisher and assign it to the input |
|
| 310 | - // parameter which WordPress automatically saves into the settings. |
|
| 311 | - $input['publisher_id'] = $this->entity_service->create( $name, $type_uri, $thumbnail_id, 'publish' ); |
|
| 312 | - } |
|
| 313 | - |
|
| 314 | - return $input; |
|
| 315 | - } |
|
| 21 | + /** |
|
| 22 | + * A {@link Wordlift_Entity_Service} instance. |
|
| 23 | + * |
|
| 24 | + * @since 3.11.0 |
|
| 25 | + * @access private |
|
| 26 | + * @var \Wordlift_Entity_Service $entity_service A {@link Wordlift_Entity_Service} instance. |
|
| 27 | + */ |
|
| 28 | + private $entity_service; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * A {@link Wordlift_Configuration_Service} instance. |
|
| 32 | + * |
|
| 33 | + * @since 3.11.0 |
|
| 34 | + * @access private |
|
| 35 | + * @var \Wordlift_Configuration_Service $configuration_service A {@link Wordlift_Configuration_Service} instance. |
|
| 36 | + */ |
|
| 37 | + private $configuration_service; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * A {@link Wordlift_Admin_Input_Element} element renderer. |
|
| 41 | + * |
|
| 42 | + * @since 3.11.0 |
|
| 43 | + * @access private |
|
| 44 | + * @var \Wordlift_Admin_Input_Element $input_element An {@link Wordlift_Admin_Input_Element} element renderer. |
|
| 45 | + */ |
|
| 46 | + private $input_element; |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * A {@link Wordlift_Admin_Radio_Input_Element} element renderer. |
|
| 50 | + * |
|
| 51 | + * @since 3.13.0 |
|
| 52 | + * @access protected |
|
| 53 | + * @var \Wordlift_Admin_Radio_Input_Element $radio_input_element A {@link Wordlift_Admin_Radio_Input_Element} element renderer. |
|
| 54 | + */ |
|
| 55 | + private $radio_input_element; |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * A {@link Wordlift_Admin_Language_Select_Element} element renderer. |
|
| 59 | + * |
|
| 60 | + * @since 3.11.0 |
|
| 61 | + * @access private |
|
| 62 | + * @var \Wordlift_Admin_Language_Select_Element $language_select_element A {@link Wordlift_Admin_Language_Select_Element} element renderer. |
|
| 63 | + */ |
|
| 64 | + private $language_select_element; |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * A {@link Wordlift_Admin_Publisher_Element} element renderer. |
|
| 68 | + * |
|
| 69 | + * @since 3.11.0 |
|
| 70 | + * @access private |
|
| 71 | + * @var \Wordlift_Admin_Publisher_Element $publisher_element A {@link Wordlift_Admin_Publisher_Element} element renderer. |
|
| 72 | + */ |
|
| 73 | + private $publisher_element; |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * Create a {@link Wordlift_Admin_Settings_Page} instance. |
|
| 77 | + * |
|
| 78 | + * @since 3.11.0 |
|
| 79 | + * |
|
| 80 | + * @param \Wordlift_Configuration_Service $configuration_service |
|
| 81 | + * @param \Wordlift_Entity_Service $entity_service |
|
| 82 | + * @param \Wordlift_Admin_Input_Element $input_element |
|
| 83 | + * @param \Wordlift_Admin_Language_Select_Element $language_select_element |
|
| 84 | + * @param \Wordlift_Admin_Publisher_Element $publisher_element |
|
| 85 | + * @param \Wordlift_Admin_Radio_Input_Element $radio_input_element |
|
| 86 | + */ |
|
| 87 | + function __construct( $configuration_service, $entity_service, $input_element, $language_select_element, $publisher_element, $radio_input_element ) { |
|
| 88 | + |
|
| 89 | + $this->configuration_service = $configuration_service; |
|
| 90 | + $this->entity_service = $entity_service; |
|
| 91 | + |
|
| 92 | + // Set a reference to the UI elements. |
|
| 93 | + $this->input_element = $input_element; |
|
| 94 | + $this->radio_input_element = $radio_input_element; |
|
| 95 | + $this->language_select_element = $language_select_element; |
|
| 96 | + $this->publisher_element = $publisher_element; |
|
| 97 | + |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * @inheritdoc |
|
| 102 | + */ |
|
| 103 | + function get_parent_slug() { |
|
| 104 | + |
|
| 105 | + return 'wl_admin_menu'; |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * @inheritdoc |
|
| 110 | + */ |
|
| 111 | + function get_capability() { |
|
| 112 | + |
|
| 113 | + return 'manage_options'; |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * @inheritdoc |
|
| 118 | + */ |
|
| 119 | + function get_page_title() { |
|
| 120 | + |
|
| 121 | + return 'WorldLift Settings'; |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + /** |
|
| 125 | + * @inheritdoc |
|
| 126 | + */ |
|
| 127 | + function get_menu_title() { |
|
| 128 | + |
|
| 129 | + return 'Settings'; |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + /** |
|
| 133 | + * @inheritdoc |
|
| 134 | + */ |
|
| 135 | + function get_menu_slug() { |
|
| 136 | + |
|
| 137 | + return 'wl_configuration_admin_menu'; |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * @inheritdoc |
|
| 142 | + */ |
|
| 143 | + function get_partial_name() { |
|
| 144 | + |
|
| 145 | + return 'wordlift-admin-settings-page.php'; |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + /** |
|
| 149 | + * @inheritdoc |
|
| 150 | + */ |
|
| 151 | + public function enqueue_scripts() { |
|
| 152 | + |
|
| 153 | + // Enqueue the media scripts to be used for the publisher's logo selection. |
|
| 154 | + wp_enqueue_media(); |
|
| 155 | + |
|
| 156 | + // JavaScript required for the settings page. |
|
| 157 | + // @todo: try to move to the `wordlift-admin.bundle.js`. |
|
| 158 | + wp_enqueue_script( 'wordlift-admin-settings-page', plugin_dir_url( dirname( __FILE__ ) ) . 'admin/js/wordlift-admin-settings-page.bundle.js', array( 'wp-util' ) ); |
|
| 159 | + |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * Configure all the configuration parameters. |
|
| 164 | + * |
|
| 165 | + * Called by the *admin_init* hook. |
|
| 166 | + * |
|
| 167 | + * @since 3.11.0 |
|
| 168 | + */ |
|
| 169 | + function admin_init() { |
|
| 170 | + |
|
| 171 | + // Register WordLift's general settings, providing our own sanitize callback |
|
| 172 | + // which will also check whether the user filled the WL Publisher form. |
|
| 173 | + register_setting( |
|
| 174 | + 'wl_general_settings', |
|
| 175 | + 'wl_general_settings', |
|
| 176 | + array( $this, 'sanitize_callback', ) |
|
| 177 | + ); |
|
| 178 | + |
|
| 179 | + // Add the general settings section. |
|
| 180 | + add_settings_section( |
|
| 181 | + 'wl_general_settings_section', // ID used to identify this section and with which to register options. |
|
| 182 | + '', // Section header. |
|
| 183 | + '', // Callback used to render the description of the section. |
|
| 184 | + 'wl_general_settings' // Page on which to add this section of options. |
|
| 185 | + ); |
|
| 186 | + |
|
| 187 | + $key_args = array( |
|
| 188 | + 'id' => 'wl-key', |
|
| 189 | + 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::KEY . ']', |
|
| 190 | + 'value' => $this->configuration_service->get_key(), |
|
| 191 | + 'description' => _x( 'Insert the <a href="https://www.wordlift.io/blogger">WordLift Key</a> you received via email.', 'wordlift' ), |
|
| 192 | + ); |
|
| 193 | + |
|
| 194 | + // Set the class for the key field based on the validity of the key. |
|
| 195 | + // Class should be "untouched" for an empty (virgin) value, "valid" |
|
| 196 | + // if the key is valid, or "invalid" otherwise. |
|
| 197 | + $validation_service = new Wordlift_Key_Validation_Service(); |
|
| 198 | + |
|
| 199 | + if ( empty( $key_args['value'] ) ) { |
|
| 200 | + $key_args['css_class'] = 'untouched'; |
|
| 201 | + } elseif ( $validation_service->is_valid( $key_args['value'] ) ) { |
|
| 202 | + $key_args['css_class'] = 'valid'; |
|
| 203 | + } else { |
|
| 204 | + $key_args['css_class'] = 'invalid'; |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + // Add the `key` field. |
|
| 208 | + add_settings_field( |
|
| 209 | + 'wl-key', // Element id used to identify the field throughout the theme. |
|
| 210 | + _x( 'WordLift Key', 'wordlift' ), // The label to the left of the option interface element. |
|
| 211 | + // The name of the function responsible for rendering the option interface. |
|
| 212 | + array( $this->input_element, 'render', ), |
|
| 213 | + 'wl_general_settings', // The page on which this option will be displayed. |
|
| 214 | + 'wl_general_settings_section', // The name of the section to which this field belongs. |
|
| 215 | + $key_args // The array of arguments to pass to the callback. In this case, just a description. |
|
| 216 | + ); |
|
| 217 | + |
|
| 218 | + // Entity Base Path input. |
|
| 219 | + $entity_base_path_args = array( |
|
| 220 | + // The array of arguments to pass to the callback. In this case, just a description. |
|
| 221 | + 'id' => 'wl-entity-base-path', |
|
| 222 | + 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::ENTITY_BASE_PATH_KEY . ']', |
|
| 223 | + 'value' => $this->configuration_service->get_entity_base_path(), |
|
| 224 | + 'description' => sprintf( _x( 'All new pages created with WordLift, will be stored inside your internal vocabulary. You can customize the url pattern of these pages in the field above. Check our <a href="%s">FAQs</a> if you need more info.', 'wordlift' ), 'https://wordlift.io/wordlift-user-faqs/#10-why-and-how-should-i-customize-the-url-of-the-entity-pages-created-in-my-vocabulary' ), |
|
| 225 | + ); |
|
| 226 | + |
|
| 227 | + $entity_base_path_args['readonly'] = 0 < $this->entity_service->count(); |
|
| 228 | + |
|
| 229 | + // Add the `wl_entity_base_path` field. |
|
| 230 | + add_settings_field( |
|
| 231 | + 'wl-entity-base-path', // ID used to identify the field throughout the theme |
|
| 232 | + _x( 'Entity Base Path', 'wordlift' ), // The label to the left of the option interface element |
|
| 233 | + // The name of the function responsible for rendering the option interface |
|
| 234 | + array( $this->input_element, 'render', ), |
|
| 235 | + 'wl_general_settings', // The page on which this option will be displayed |
|
| 236 | + 'wl_general_settings_section', // The name of the section to which this field belongs |
|
| 237 | + $entity_base_path_args |
|
| 238 | + ); |
|
| 239 | + |
|
| 240 | + // Add the `language_name` field. |
|
| 241 | + add_settings_field( |
|
| 242 | + 'wl-site-language', |
|
| 243 | + _x( 'Site Language', 'wordlift' ), |
|
| 244 | + array( $this->language_select_element, 'render' ), |
|
| 245 | + 'wl_general_settings', |
|
| 246 | + 'wl_general_settings_section', |
|
| 247 | + array( |
|
| 248 | + // The array of arguments to pass to the callback. In this case, just a description. |
|
| 249 | + 'id' => 'wl-site-language', |
|
| 250 | + 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::LANGUAGE . ']', |
|
| 251 | + 'value' => $this->configuration_service->get_language_code(), |
|
| 252 | + 'description' => __( 'Each WordLift Key can be used only in one language. Pick yours.', 'wordlift' ), |
|
| 253 | + ) |
|
| 254 | + ); |
|
| 255 | + |
|
| 256 | + // Add the `publisher` field. |
|
| 257 | + add_settings_field( |
|
| 258 | + 'wl-publisher-id', |
|
| 259 | + _x( 'Publisher', 'wordlift' ), |
|
| 260 | + array( $this->publisher_element, 'render' ), |
|
| 261 | + 'wl_general_settings', |
|
| 262 | + 'wl_general_settings_section', |
|
| 263 | + array( |
|
| 264 | + 'id' => 'wl-publisher-id', |
|
| 265 | + 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::PUBLISHER_ID . ']', |
|
| 266 | + ) |
|
| 267 | + ); |
|
| 268 | + |
|
| 269 | + // Add the `link by default` field. |
|
| 270 | + add_settings_field( |
|
| 271 | + 'wl-link-by-default', |
|
| 272 | + _x( 'Link by Default', 'wordlift' ), |
|
| 273 | + array( $this->radio_input_element, 'render' ), |
|
| 274 | + 'wl_general_settings', |
|
| 275 | + 'wl_general_settings_section', |
|
| 276 | + array( |
|
| 277 | + 'id' => 'wl-link-by-default', |
|
| 278 | + 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::LINK_BY_DEFAULT . ']', |
|
| 279 | + 'value' => $this->configuration_service->is_link_by_default() ? 'yes' : 'no', |
|
| 280 | + 'description' => _x( 'Whether to link entities by default or not. This setting applies to all the entities.', 'wordlift' ), |
|
| 281 | + ) |
|
| 282 | + ); |
|
| 283 | + |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + /** |
|
| 287 | + * Sanitize the configuration settings to be stored. |
|
| 288 | + * |
|
| 289 | + * If a new entity is being created for the publisher, create it and set The |
|
| 290 | + * publisher setting. |
|
| 291 | + * |
|
| 292 | + * @since 3.11.0 |
|
| 293 | + * |
|
| 294 | + * @param array $input The configuration settings array. |
|
| 295 | + * |
|
| 296 | + * @return array The sanitized input array. |
|
| 297 | + */ |
|
| 298 | + function sanitize_callback( $input ) { |
|
| 299 | + |
|
| 300 | + // Check whether a publisher name has been set. |
|
| 301 | + if ( isset( $_POST['wl_publisher'] ) && ! empty( $_POST['wl_publisher']['name'] ) ) { |
|
| 302 | + $name = $_POST['wl_publisher']['name']; |
|
| 303 | + $type = $_POST['wl_publisher']['type']; |
|
| 304 | + $thumbnail_id = $_POST['wl_publisher']['thumbnail_id'] ?: null; |
|
| 305 | + |
|
| 306 | + // Set the type URI, either http://schema.org/Person or http://schema.org/Organization. |
|
| 307 | + $type_uri = sprintf( 'http://schema.org/%s', 'organization' === $type ? 'Organization' : 'Person' ); |
|
| 308 | + |
|
| 309 | + // Create an entity for the publisher and assign it to the input |
|
| 310 | + // parameter which WordPress automatically saves into the settings. |
|
| 311 | + $input['publisher_id'] = $this->entity_service->create( $name, $type_uri, $thumbnail_id, 'publish' ); |
|
| 312 | + } |
|
| 313 | + |
|
| 314 | + return $input; |
|
| 315 | + } |
|
| 316 | 316 | |
| 317 | 317 | } |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | * @param \Wordlift_Admin_Publisher_Element $publisher_element |
| 85 | 85 | * @param \Wordlift_Admin_Radio_Input_Element $radio_input_element |
| 86 | 86 | */ |
| 87 | - function __construct( $configuration_service, $entity_service, $input_element, $language_select_element, $publisher_element, $radio_input_element ) { |
|
| 87 | + function __construct($configuration_service, $entity_service, $input_element, $language_select_element, $publisher_element, $radio_input_element) { |
|
| 88 | 88 | |
| 89 | 89 | $this->configuration_service = $configuration_service; |
| 90 | 90 | $this->entity_service = $entity_service; |
@@ -155,7 +155,7 @@ discard block |
||
| 155 | 155 | |
| 156 | 156 | // JavaScript required for the settings page. |
| 157 | 157 | // @todo: try to move to the `wordlift-admin.bundle.js`. |
| 158 | - wp_enqueue_script( 'wordlift-admin-settings-page', plugin_dir_url( dirname( __FILE__ ) ) . 'admin/js/wordlift-admin-settings-page.bundle.js', array( 'wp-util' ) ); |
|
| 158 | + wp_enqueue_script('wordlift-admin-settings-page', plugin_dir_url(dirname(__FILE__)).'admin/js/wordlift-admin-settings-page.bundle.js', array('wp-util')); |
|
| 159 | 159 | |
| 160 | 160 | } |
| 161 | 161 | |
@@ -173,22 +173,22 @@ discard block |
||
| 173 | 173 | register_setting( |
| 174 | 174 | 'wl_general_settings', |
| 175 | 175 | 'wl_general_settings', |
| 176 | - array( $this, 'sanitize_callback', ) |
|
| 176 | + array($this, 'sanitize_callback',) |
|
| 177 | 177 | ); |
| 178 | 178 | |
| 179 | 179 | // Add the general settings section. |
| 180 | 180 | add_settings_section( |
| 181 | 181 | 'wl_general_settings_section', // ID used to identify this section and with which to register options. |
| 182 | - '', // Section header. |
|
| 183 | - '', // Callback used to render the description of the section. |
|
| 182 | + '', // Section header. |
|
| 183 | + '', // Callback used to render the description of the section. |
|
| 184 | 184 | 'wl_general_settings' // Page on which to add this section of options. |
| 185 | 185 | ); |
| 186 | 186 | |
| 187 | 187 | $key_args = array( |
| 188 | 188 | 'id' => 'wl-key', |
| 189 | - 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::KEY . ']', |
|
| 189 | + 'name' => 'wl_general_settings['.Wordlift_Configuration_Service::KEY.']', |
|
| 190 | 190 | 'value' => $this->configuration_service->get_key(), |
| 191 | - 'description' => _x( 'Insert the <a href="https://www.wordlift.io/blogger">WordLift Key</a> you received via email.', 'wordlift' ), |
|
| 191 | + 'description' => _x('Insert the <a href="https://www.wordlift.io/blogger">WordLift Key</a> you received via email.', 'wordlift'), |
|
| 192 | 192 | ); |
| 193 | 193 | |
| 194 | 194 | // Set the class for the key field based on the validity of the key. |
@@ -196,9 +196,9 @@ discard block |
||
| 196 | 196 | // if the key is valid, or "invalid" otherwise. |
| 197 | 197 | $validation_service = new Wordlift_Key_Validation_Service(); |
| 198 | 198 | |
| 199 | - if ( empty( $key_args['value'] ) ) { |
|
| 199 | + if (empty($key_args['value'])) { |
|
| 200 | 200 | $key_args['css_class'] = 'untouched'; |
| 201 | - } elseif ( $validation_service->is_valid( $key_args['value'] ) ) { |
|
| 201 | + } elseif ($validation_service->is_valid($key_args['value'])) { |
|
| 202 | 202 | $key_args['css_class'] = 'valid'; |
| 203 | 203 | } else { |
| 204 | 204 | $key_args['css_class'] = 'invalid'; |
@@ -206,12 +206,12 @@ discard block |
||
| 206 | 206 | |
| 207 | 207 | // Add the `key` field. |
| 208 | 208 | add_settings_field( |
| 209 | - 'wl-key', // Element id used to identify the field throughout the theme. |
|
| 210 | - _x( 'WordLift Key', 'wordlift' ), // The label to the left of the option interface element. |
|
| 209 | + 'wl-key', // Element id used to identify the field throughout the theme. |
|
| 210 | + _x('WordLift Key', 'wordlift'), // The label to the left of the option interface element. |
|
| 211 | 211 | // The name of the function responsible for rendering the option interface. |
| 212 | - array( $this->input_element, 'render', ), |
|
| 213 | - 'wl_general_settings', // The page on which this option will be displayed. |
|
| 214 | - 'wl_general_settings_section', // The name of the section to which this field belongs. |
|
| 212 | + array($this->input_element, 'render',), |
|
| 213 | + 'wl_general_settings', // The page on which this option will be displayed. |
|
| 214 | + 'wl_general_settings_section', // The name of the section to which this field belongs. |
|
| 215 | 215 | $key_args // The array of arguments to pass to the callback. In this case, just a description. |
| 216 | 216 | ); |
| 217 | 217 | |
@@ -219,65 +219,65 @@ discard block |
||
| 219 | 219 | $entity_base_path_args = array( |
| 220 | 220 | // The array of arguments to pass to the callback. In this case, just a description. |
| 221 | 221 | 'id' => 'wl-entity-base-path', |
| 222 | - 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::ENTITY_BASE_PATH_KEY . ']', |
|
| 222 | + 'name' => 'wl_general_settings['.Wordlift_Configuration_Service::ENTITY_BASE_PATH_KEY.']', |
|
| 223 | 223 | 'value' => $this->configuration_service->get_entity_base_path(), |
| 224 | - 'description' => sprintf( _x( 'All new pages created with WordLift, will be stored inside your internal vocabulary. You can customize the url pattern of these pages in the field above. Check our <a href="%s">FAQs</a> if you need more info.', 'wordlift' ), 'https://wordlift.io/wordlift-user-faqs/#10-why-and-how-should-i-customize-the-url-of-the-entity-pages-created-in-my-vocabulary' ), |
|
| 224 | + 'description' => sprintf(_x('All new pages created with WordLift, will be stored inside your internal vocabulary. You can customize the url pattern of these pages in the field above. Check our <a href="%s">FAQs</a> if you need more info.', 'wordlift'), 'https://wordlift.io/wordlift-user-faqs/#10-why-and-how-should-i-customize-the-url-of-the-entity-pages-created-in-my-vocabulary'), |
|
| 225 | 225 | ); |
| 226 | 226 | |
| 227 | 227 | $entity_base_path_args['readonly'] = 0 < $this->entity_service->count(); |
| 228 | 228 | |
| 229 | 229 | // Add the `wl_entity_base_path` field. |
| 230 | 230 | add_settings_field( |
| 231 | - 'wl-entity-base-path', // ID used to identify the field throughout the theme |
|
| 232 | - _x( 'Entity Base Path', 'wordlift' ), // The label to the left of the option interface element |
|
| 231 | + 'wl-entity-base-path', // ID used to identify the field throughout the theme |
|
| 232 | + _x('Entity Base Path', 'wordlift'), // The label to the left of the option interface element |
|
| 233 | 233 | // The name of the function responsible for rendering the option interface |
| 234 | - array( $this->input_element, 'render', ), |
|
| 235 | - 'wl_general_settings', // The page on which this option will be displayed |
|
| 236 | - 'wl_general_settings_section', // The name of the section to which this field belongs |
|
| 234 | + array($this->input_element, 'render',), |
|
| 235 | + 'wl_general_settings', // The page on which this option will be displayed |
|
| 236 | + 'wl_general_settings_section', // The name of the section to which this field belongs |
|
| 237 | 237 | $entity_base_path_args |
| 238 | 238 | ); |
| 239 | 239 | |
| 240 | 240 | // Add the `language_name` field. |
| 241 | 241 | add_settings_field( |
| 242 | 242 | 'wl-site-language', |
| 243 | - _x( 'Site Language', 'wordlift' ), |
|
| 244 | - array( $this->language_select_element, 'render' ), |
|
| 243 | + _x('Site Language', 'wordlift'), |
|
| 244 | + array($this->language_select_element, 'render'), |
|
| 245 | 245 | 'wl_general_settings', |
| 246 | 246 | 'wl_general_settings_section', |
| 247 | 247 | array( |
| 248 | 248 | // The array of arguments to pass to the callback. In this case, just a description. |
| 249 | 249 | 'id' => 'wl-site-language', |
| 250 | - 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::LANGUAGE . ']', |
|
| 250 | + 'name' => 'wl_general_settings['.Wordlift_Configuration_Service::LANGUAGE.']', |
|
| 251 | 251 | 'value' => $this->configuration_service->get_language_code(), |
| 252 | - 'description' => __( 'Each WordLift Key can be used only in one language. Pick yours.', 'wordlift' ), |
|
| 252 | + 'description' => __('Each WordLift Key can be used only in one language. Pick yours.', 'wordlift'), |
|
| 253 | 253 | ) |
| 254 | 254 | ); |
| 255 | 255 | |
| 256 | 256 | // Add the `publisher` field. |
| 257 | 257 | add_settings_field( |
| 258 | 258 | 'wl-publisher-id', |
| 259 | - _x( 'Publisher', 'wordlift' ), |
|
| 260 | - array( $this->publisher_element, 'render' ), |
|
| 259 | + _x('Publisher', 'wordlift'), |
|
| 260 | + array($this->publisher_element, 'render'), |
|
| 261 | 261 | 'wl_general_settings', |
| 262 | 262 | 'wl_general_settings_section', |
| 263 | 263 | array( |
| 264 | 264 | 'id' => 'wl-publisher-id', |
| 265 | - 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::PUBLISHER_ID . ']', |
|
| 265 | + 'name' => 'wl_general_settings['.Wordlift_Configuration_Service::PUBLISHER_ID.']', |
|
| 266 | 266 | ) |
| 267 | 267 | ); |
| 268 | 268 | |
| 269 | 269 | // Add the `link by default` field. |
| 270 | 270 | add_settings_field( |
| 271 | 271 | 'wl-link-by-default', |
| 272 | - _x( 'Link by Default', 'wordlift' ), |
|
| 273 | - array( $this->radio_input_element, 'render' ), |
|
| 272 | + _x('Link by Default', 'wordlift'), |
|
| 273 | + array($this->radio_input_element, 'render'), |
|
| 274 | 274 | 'wl_general_settings', |
| 275 | 275 | 'wl_general_settings_section', |
| 276 | 276 | array( |
| 277 | 277 | 'id' => 'wl-link-by-default', |
| 278 | - 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::LINK_BY_DEFAULT . ']', |
|
| 278 | + 'name' => 'wl_general_settings['.Wordlift_Configuration_Service::LINK_BY_DEFAULT.']', |
|
| 279 | 279 | 'value' => $this->configuration_service->is_link_by_default() ? 'yes' : 'no', |
| 280 | - 'description' => _x( 'Whether to link entities by default or not. This setting applies to all the entities.', 'wordlift' ), |
|
| 280 | + 'description' => _x('Whether to link entities by default or not. This setting applies to all the entities.', 'wordlift'), |
|
| 281 | 281 | ) |
| 282 | 282 | ); |
| 283 | 283 | |
@@ -295,20 +295,20 @@ discard block |
||
| 295 | 295 | * |
| 296 | 296 | * @return array The sanitized input array. |
| 297 | 297 | */ |
| 298 | - function sanitize_callback( $input ) { |
|
| 298 | + function sanitize_callback($input) { |
|
| 299 | 299 | |
| 300 | 300 | // Check whether a publisher name has been set. |
| 301 | - if ( isset( $_POST['wl_publisher'] ) && ! empty( $_POST['wl_publisher']['name'] ) ) { |
|
| 301 | + if (isset($_POST['wl_publisher']) && ! empty($_POST['wl_publisher']['name'])) { |
|
| 302 | 302 | $name = $_POST['wl_publisher']['name']; |
| 303 | 303 | $type = $_POST['wl_publisher']['type']; |
| 304 | 304 | $thumbnail_id = $_POST['wl_publisher']['thumbnail_id'] ?: null; |
| 305 | 305 | |
| 306 | 306 | // Set the type URI, either http://schema.org/Person or http://schema.org/Organization. |
| 307 | - $type_uri = sprintf( 'http://schema.org/%s', 'organization' === $type ? 'Organization' : 'Person' ); |
|
| 307 | + $type_uri = sprintf('http://schema.org/%s', 'organization' === $type ? 'Organization' : 'Person'); |
|
| 308 | 308 | |
| 309 | 309 | // Create an entity for the publisher and assign it to the input |
| 310 | 310 | // parameter which WordPress automatically saves into the settings. |
| 311 | - $input['publisher_id'] = $this->entity_service->create( $name, $type_uri, $thumbnail_id, 'publish' ); |
|
| 311 | + $input['publisher_id'] = $this->entity_service->create($name, $type_uri, $thumbnail_id, 'publish'); |
|
| 312 | 312 | } |
| 313 | 313 | |
| 314 | 314 | return $input; |
@@ -18,52 +18,52 @@ discard block |
||
| 18 | 18 | */ |
| 19 | 19 | class Wordlift_Admin_Input_Element implements Wordlift_Admin_Element { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * Output the HTML for an input box type settings_page |
|
| 23 | - * |
|
| 24 | - * @param array $args An array with the following keys: |
|
| 25 | - * Parameters controlling the result. |
|
| 26 | - * |
|
| 27 | - * @type string name The name attribute of the input element. Mandatory. |
|
| 28 | - * |
|
| 29 | - * @type string id The id attribute of the input element. Optional. |
|
| 30 | - * @type string id The id attribute of the input element. |
|
| 31 | - * Optional, randomly generated one is used if not supplied. |
|
| 32 | - * @type string value The value of the input element. |
|
| 33 | - * Optional, defaults to empty string. |
|
| 34 | - * @type bool readonly Indicates whether the input is read only. |
|
| 35 | - * Optional, defaults to read-write |
|
| 36 | - * @type string css_class The class attribute for the input element. |
|
| 37 | - * If empty string no class attribute will be added. |
|
| 38 | - * Optional, defaults to empty string. |
|
| 39 | - * @type string description The descriptio text to be displayed below the element. |
|
| 40 | - * Can include some HTML element. |
|
| 41 | - * If empty string no description will be displayed. |
|
| 42 | - * Optional, defaults to empty string. |
|
| 43 | - * |
|
| 44 | - * @return $this|Wordlift_Admin_Element |
|
| 45 | - */ |
|
| 46 | - public function render( $args ) { |
|
| 21 | + /** |
|
| 22 | + * Output the HTML for an input box type settings_page |
|
| 23 | + * |
|
| 24 | + * @param array $args An array with the following keys: |
|
| 25 | + * Parameters controlling the result. |
|
| 26 | + * |
|
| 27 | + * @type string name The name attribute of the input element. Mandatory. |
|
| 28 | + * |
|
| 29 | + * @type string id The id attribute of the input element. Optional. |
|
| 30 | + * @type string id The id attribute of the input element. |
|
| 31 | + * Optional, randomly generated one is used if not supplied. |
|
| 32 | + * @type string value The value of the input element. |
|
| 33 | + * Optional, defaults to empty string. |
|
| 34 | + * @type bool readonly Indicates whether the input is read only. |
|
| 35 | + * Optional, defaults to read-write |
|
| 36 | + * @type string css_class The class attribute for the input element. |
|
| 37 | + * If empty string no class attribute will be added. |
|
| 38 | + * Optional, defaults to empty string. |
|
| 39 | + * @type string description The descriptio text to be displayed below the element. |
|
| 40 | + * Can include some HTML element. |
|
| 41 | + * If empty string no description will be displayed. |
|
| 42 | + * Optional, defaults to empty string. |
|
| 43 | + * |
|
| 44 | + * @return $this|Wordlift_Admin_Element |
|
| 45 | + */ |
|
| 46 | + public function render( $args ) { |
|
| 47 | 47 | |
| 48 | - /* |
|
| 48 | + /* |
|
| 49 | 49 | * Parse the arguments and merge with default values. |
| 50 | 50 | * Name intentionally do not have a default as it has to be in SyncEvent |
| 51 | 51 | * with form handling code |
| 52 | 52 | */ |
| 53 | - $params = wp_parse_args( $args, array( |
|
| 54 | - 'id' => uniqid( 'wl-input-' ), |
|
| 55 | - 'value' => '', |
|
| 56 | - 'readonly' => false, |
|
| 57 | - 'css_class' => '', |
|
| 58 | - 'description' => '', |
|
| 59 | - ) ); |
|
| 53 | + $params = wp_parse_args( $args, array( |
|
| 54 | + 'id' => uniqid( 'wl-input-' ), |
|
| 55 | + 'value' => '', |
|
| 56 | + 'readonly' => false, |
|
| 57 | + 'css_class' => '', |
|
| 58 | + 'description' => '', |
|
| 59 | + ) ); |
|
| 60 | 60 | |
| 61 | - // Set the readonly and class attributes and the description. |
|
| 62 | - $readonly = $params['readonly'] ? ' readonly="readonly"' : ''; |
|
| 63 | - $css_class = ! empty( $params['css_class'] ) ? ' class="' . esc_attr( $params['css_class'] ) . '"' : ''; |
|
| 64 | - $description = ! empty( $params['description'] ) ? '<p>' . wp_kses( $params['description'], array( 'a' => array( 'href' => array() ) ) ) . '</p>' : ''; |
|
| 61 | + // Set the readonly and class attributes and the description. |
|
| 62 | + $readonly = $params['readonly'] ? ' readonly="readonly"' : ''; |
|
| 63 | + $css_class = ! empty( $params['css_class'] ) ? ' class="' . esc_attr( $params['css_class'] ) . '"' : ''; |
|
| 64 | + $description = ! empty( $params['description'] ) ? '<p>' . wp_kses( $params['description'], array( 'a' => array( 'href' => array() ) ) ) . '</p>' : ''; |
|
| 65 | 65 | |
| 66 | - ?> |
|
| 66 | + ?> |
|
| 67 | 67 | |
| 68 | 68 | <input type="text" |
| 69 | 69 | id="<?php echo esc_attr( $params['id'] ); ?>" |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | |
| 77 | 77 | <?php |
| 78 | 78 | |
| 79 | - return $this; |
|
| 80 | - } |
|
| 79 | + return $this; |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | 82 | } |
@@ -43,32 +43,32 @@ |
||
| 43 | 43 | * |
| 44 | 44 | * @return $this|Wordlift_Admin_Element |
| 45 | 45 | */ |
| 46 | - public function render( $args ) { |
|
| 46 | + public function render($args) { |
|
| 47 | 47 | |
| 48 | 48 | /* |
| 49 | 49 | * Parse the arguments and merge with default values. |
| 50 | 50 | * Name intentionally do not have a default as it has to be in SyncEvent |
| 51 | 51 | * with form handling code |
| 52 | 52 | */ |
| 53 | - $params = wp_parse_args( $args, array( |
|
| 54 | - 'id' => uniqid( 'wl-input-' ), |
|
| 53 | + $params = wp_parse_args($args, array( |
|
| 54 | + 'id' => uniqid('wl-input-'), |
|
| 55 | 55 | 'value' => '', |
| 56 | 56 | 'readonly' => false, |
| 57 | 57 | 'css_class' => '', |
| 58 | 58 | 'description' => '', |
| 59 | - ) ); |
|
| 59 | + )); |
|
| 60 | 60 | |
| 61 | 61 | // Set the readonly and class attributes and the description. |
| 62 | 62 | $readonly = $params['readonly'] ? ' readonly="readonly"' : ''; |
| 63 | - $css_class = ! empty( $params['css_class'] ) ? ' class="' . esc_attr( $params['css_class'] ) . '"' : ''; |
|
| 64 | - $description = ! empty( $params['description'] ) ? '<p>' . wp_kses( $params['description'], array( 'a' => array( 'href' => array() ) ) ) . '</p>' : ''; |
|
| 63 | + $css_class = ! empty($params['css_class']) ? ' class="'.esc_attr($params['css_class']).'"' : ''; |
|
| 64 | + $description = ! empty($params['description']) ? '<p>'.wp_kses($params['description'], array('a' => array('href' => array()))).'</p>' : ''; |
|
| 65 | 65 | |
| 66 | 66 | ?> |
| 67 | 67 | |
| 68 | 68 | <input type="text" |
| 69 | - id="<?php echo esc_attr( $params['id'] ); ?>" |
|
| 70 | - name="<?php echo esc_attr( $params['name'] ); ?>" |
|
| 71 | - value="<?php echo esc_attr( $params['value'] ); ?>" |
|
| 69 | + id="<?php echo esc_attr($params['id']); ?>" |
|
| 70 | + name="<?php echo esc_attr($params['name']); ?>" |
|
| 71 | + value="<?php echo esc_attr($params['value']); ?>" |
|
| 72 | 72 | <?php echo $readonly; ?> |
| 73 | 73 | <?php echo $css_class; ?> |
| 74 | 74 | /> |
@@ -5,14 +5,14 @@ discard block |
||
| 5 | 5 | |
| 6 | 6 | // Define the basic options for HTTP calls to REDLINK. |
| 7 | 7 | define( 'WL_REDLINK_API_HTTP_OPTIONS', serialize( array( |
| 8 | - 'timeout' => 300, |
|
| 9 | - 'redirection' => 5, |
|
| 10 | - 'httpversion' => '1.1', |
|
| 11 | - 'blocking' => true, |
|
| 12 | - 'cookies' => array(), |
|
| 13 | - 'sslverify' => ( 'false' === getenv( 'WL_SSL_VERIFY_ENABLED' ) ) ? false : true, |
|
| 14 | - 'sslcertificates' => dirname( __FILE__ ) . '/ssl/ca-bundle.crt', |
|
| 15 | - 'decompress' => false, |
|
| 8 | + 'timeout' => 300, |
|
| 9 | + 'redirection' => 5, |
|
| 10 | + 'httpversion' => '1.1', |
|
| 11 | + 'blocking' => true, |
|
| 12 | + 'cookies' => array(), |
|
| 13 | + 'sslverify' => ( 'false' === getenv( 'WL_SSL_VERIFY_ENABLED' ) ) ? false : true, |
|
| 14 | + 'sslcertificates' => dirname( __FILE__ ) . '/ssl/ca-bundle.crt', |
|
| 15 | + 'decompress' => false, |
|
| 16 | 16 | ) ) ); |
| 17 | 17 | |
| 18 | 18 | // Create a unique ID for this request, useful to hook async HTTP requests. |
@@ -43,14 +43,14 @@ discard block |
||
| 43 | 43 | */ |
| 44 | 44 | function wl_prefixes() { |
| 45 | 45 | |
| 46 | - $items = wl_prefixes_list(); |
|
| 47 | - $prefixes = array(); |
|
| 46 | + $items = wl_prefixes_list(); |
|
| 47 | + $prefixes = array(); |
|
| 48 | 48 | |
| 49 | - foreach ( $items as $item ) { |
|
| 50 | - $prefixes[ $item['prefix'] ] = $item['namespace']; |
|
| 51 | - } |
|
| 49 | + foreach ( $items as $item ) { |
|
| 50 | + $prefixes[ $item['prefix'] ] = $item['namespace']; |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - return $prefixes; |
|
| 53 | + return $prefixes; |
|
| 54 | 54 | |
| 55 | 55 | } |
| 56 | 56 | |
@@ -63,22 +63,22 @@ discard block |
||
| 63 | 63 | */ |
| 64 | 64 | function wl_predicates() { |
| 65 | 65 | |
| 66 | - return array( |
|
| 67 | - 'a', |
|
| 68 | - 'dct:references', |
|
| 69 | - 'dct:relation', |
|
| 70 | - 'dct:title', |
|
| 71 | - 'dct:subject', |
|
| 72 | - 'owl:sameAs', |
|
| 73 | - 'rdfs:label', |
|
| 74 | - 'schema:author', |
|
| 75 | - 'schema:dateModified', |
|
| 76 | - 'schema:datePublished', |
|
| 77 | - 'schema:locationCreated', |
|
| 78 | - 'schema:description', |
|
| 79 | - 'schema:image', |
|
| 80 | - 'schema:interactionCount', |
|
| 81 | - 'schema:url', |
|
| 82 | - ); |
|
| 66 | + return array( |
|
| 67 | + 'a', |
|
| 68 | + 'dct:references', |
|
| 69 | + 'dct:relation', |
|
| 70 | + 'dct:title', |
|
| 71 | + 'dct:subject', |
|
| 72 | + 'owl:sameAs', |
|
| 73 | + 'rdfs:label', |
|
| 74 | + 'schema:author', |
|
| 75 | + 'schema:dateModified', |
|
| 76 | + 'schema:datePublished', |
|
| 77 | + 'schema:locationCreated', |
|
| 78 | + 'schema:description', |
|
| 79 | + 'schema:image', |
|
| 80 | + 'schema:interactionCount', |
|
| 81 | + 'schema:url', |
|
| 82 | + ); |
|
| 83 | 83 | |
| 84 | 84 | } |
@@ -4,36 +4,36 @@ 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 | // 3.13.0, we use by default WLS 1.11 which provides us with the new, faster |
| 33 | 33 | // chunked analysis. |
| 34 | -define( 'WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE', defined( 'WORDLIFT_API_URL' ) ? WORDLIFT_API_URL . '/' : 'https://api.wordlift.it/1.11/' ); |
|
| 34 | +define('WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE', defined('WORDLIFT_API_URL') ? WORDLIFT_API_URL.'/' : 'https://api.wordlift.it/1.11/'); |
|
| 35 | 35 | |
| 36 | -define( 'WL_CONFIG_TEST_GOOGLE_RICH_SNIPPETS_URL', 'https://developers.google.com/structured-data/testing-tool/?url=' ); |
|
| 36 | +define('WL_CONFIG_TEST_GOOGLE_RICH_SNIPPETS_URL', 'https://developers.google.com/structured-data/testing-tool/?url='); |
|
| 37 | 37 | |
| 38 | 38 | |
| 39 | 39 | /** |
@@ -46,8 +46,8 @@ discard block |
||
| 46 | 46 | $items = wl_prefixes_list(); |
| 47 | 47 | $prefixes = array(); |
| 48 | 48 | |
| 49 | - foreach ( $items as $item ) { |
|
| 50 | - $prefixes[ $item['prefix'] ] = $item['namespace']; |
|
| 49 | + foreach ($items as $item) { |
|
| 50 | + $prefixes[$item['prefix']] = $item['namespace']; |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | return $prefixes; |