@@ -3,7 +3,7 @@ discard block |
||
| 3 | 3 | |
| 4 | 4 | class WL_Metabox_Field_coordinates extends WL_Metabox_Field { |
| 5 | 5 | |
| 6 | - public function __construct( $args ) { |
|
| 6 | + public function __construct($args) { |
|
| 7 | 7 | |
| 8 | 8 | // Just set up the necessary info without calling the parent constructor. |
| 9 | 9 | // TODO: write a parent class for grouped properties |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | |
| 16 | 16 | public function get_data() { |
| 17 | 17 | $entity_id = get_the_ID(); |
| 18 | - $this->data = wl_get_coordinates( $entity_id ); |
|
| 18 | + $this->data = wl_get_coordinates($entity_id); |
|
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | public function html() { |
@@ -33,20 +33,20 @@ discard block |
||
| 33 | 33 | $data = $this->data; |
| 34 | 34 | // TODO: We temporary use here 0,0 as default coordinates for the marker, but if no coordinates are given we |
| 35 | 35 | // want to use the current user location for the marker. |
| 36 | - $coordinates = ( ! empty( $data['latitude'] ) && ! empty( $data['longitude'] ) ? sprintf( '[%f,%f]', $data['latitude'], $data['longitude'] ) : '[0,0]' ); |
|
| 36 | + $coordinates = ( ! empty($data['latitude']) && ! empty($data['longitude']) ? sprintf('[%f,%f]', $data['latitude'], $data['longitude']) : '[0,0]'); |
|
| 37 | 37 | $map_init = '[0,0]' === $coordinates |
| 38 | 38 | ? 'locate( {setView: true, maxZoom: 16} )' |
| 39 | - : sprintf( "setView( [%f,%f], 9 )", $data['latitude'], $data['longitude'] ); |
|
| 39 | + : sprintf("setView( [%f,%f], 9 )", $data['latitude'], $data['longitude']); |
|
| 40 | 40 | |
| 41 | 41 | // Print input fields |
| 42 | - $html .= '<label for="wl_place_lat">' . __( 'Latitude', 'wordlift' ) . '</label>'; |
|
| 43 | - $html .= '<input type="text" id="wl_place_lat" name="wl_metaboxes[coordinates][]" value="' . $data['latitude'] . '" style="width:100%" />'; |
|
| 42 | + $html .= '<label for="wl_place_lat">'.__('Latitude', 'wordlift').'</label>'; |
|
| 43 | + $html .= '<input type="text" id="wl_place_lat" name="wl_metaboxes[coordinates][]" value="'.$data['latitude'].'" style="width:100%" />'; |
|
| 44 | 44 | |
| 45 | - $html .= '<label for="wl_place_lon">' . __( 'Longitude', 'wordlift' ) . '</label>'; |
|
| 46 | - $html .= '<input type="text" id="wl_place_lon" name="wl_metaboxes[coordinates][]" value="' . $data['longitude'] . '" style="width:100%" />'; |
|
| 45 | + $html .= '<label for="wl_place_lon">'.__('Longitude', 'wordlift').'</label>'; |
|
| 46 | + $html .= '<input type="text" id="wl_place_lon" name="wl_metaboxes[coordinates][]" value="'.$data['longitude'].'" style="width:100%" />'; |
|
| 47 | 47 | |
| 48 | 48 | // Show Leaflet map to pick coordinates |
| 49 | - $element_id = uniqid( 'wl-gep-map-' ); |
|
| 49 | + $element_id = uniqid('wl-gep-map-'); |
|
| 50 | 50 | $html .= <<<EOF |
| 51 | 51 | |
| 52 | 52 | <div id="$element_id"></div> |
@@ -84,23 +84,23 @@ discard block |
||
| 84 | 84 | return $html; |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | - public function save_data( $coords ) { |
|
| 87 | + public function save_data($coords) { |
|
| 88 | 88 | |
| 89 | - $this->sanitize_data( $coords ); |
|
| 89 | + $this->sanitize_data($coords); |
|
| 90 | 90 | |
| 91 | 91 | $entity_id = get_the_ID(); |
| 92 | 92 | |
| 93 | 93 | // Take away old values |
| 94 | - delete_post_meta( $entity_id, Wordlift_Schema_Service::FIELD_GEO_LATITUDE ); |
|
| 95 | - delete_post_meta( $entity_id, Wordlift_Schema_Service::FIELD_GEO_LONGITUDE ); |
|
| 94 | + delete_post_meta($entity_id, Wordlift_Schema_Service::FIELD_GEO_LATITUDE); |
|
| 95 | + delete_post_meta($entity_id, Wordlift_Schema_Service::FIELD_GEO_LONGITUDE); |
|
| 96 | 96 | |
| 97 | 97 | $latitude = $this->data[0]; |
| 98 | 98 | $longitude = $this->data[1]; |
| 99 | 99 | |
| 100 | 100 | // insert new coordinate values |
| 101 | - if ( ! empty( $latitude ) && ! empty( $longitude ) ) { |
|
| 102 | - add_post_meta( $entity_id, Wordlift_Schema_Service::FIELD_GEO_LATITUDE, $latitude, true ); |
|
| 103 | - add_post_meta( $entity_id, Wordlift_Schema_Service::FIELD_GEO_LONGITUDE, $longitude, true ); |
|
| 101 | + if ( ! empty($latitude) && ! empty($longitude)) { |
|
| 102 | + add_post_meta($entity_id, Wordlift_Schema_Service::FIELD_GEO_LATITUDE, $latitude, true); |
|
| 103 | + add_post_meta($entity_id, Wordlift_Schema_Service::FIELD_GEO_LONGITUDE, $longitude, true); |
|
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | } |
@@ -108,11 +108,11 @@ discard block |
||
| 108 | 108 | /** |
| 109 | 109 | * Only accept float numbers |
| 110 | 110 | */ |
| 111 | - public function sanitize_data_filter( $value ) { |
|
| 111 | + public function sanitize_data_filter($value) { |
|
| 112 | 112 | |
| 113 | 113 | // DO NOT set latitude/longitude to 0/0 as default values. It's a specific place on the globe: |
| 114 | 114 | // "The zero/zero point of this system is located in the Gulf of Guinea about 625 km (390 mi) south of Tema, Ghana." |
| 115 | - if ( ! is_numeric( $value ) ) { |
|
| 115 | + if ( ! is_numeric($value)) { |
|
| 116 | 116 | return ''; |
| 117 | 117 | } |
| 118 | 118 | |
@@ -1,54 +1,54 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -function wordlift_ajax_related_posts( $http_raw_data = null ) { |
|
| 3 | +function wordlift_ajax_related_posts($http_raw_data = null) { |
|
| 4 | 4 | |
| 5 | 5 | // Extract filtering conditions |
| 6 | - if( !isset( $_GET["post_id"] ) || !is_numeric( $_GET["post_id"] ) ) { |
|
| 6 | + if ( ! isset($_GET["post_id"]) || ! is_numeric($_GET["post_id"])) { |
|
| 7 | 7 | wp_die('Post id missing or invalid!'); |
| 8 | 8 | return; |
| 9 | 9 | } |
| 10 | 10 | |
| 11 | 11 | $post_id = $_GET["post_id"]; |
| 12 | 12 | // Get the current post |
| 13 | - $post = get_post( $post_id ); |
|
| 13 | + $post = get_post($post_id); |
|
| 14 | 14 | |
| 15 | - wl_write_log( "Going to find posts related to current with post id: $post_id ..." ); |
|
| 15 | + wl_write_log("Going to find posts related to current with post id: $post_id ..."); |
|
| 16 | 16 | |
| 17 | 17 | // Extract filtering conditions |
| 18 | - $filtering_entity_uris = ( null == $http_raw_data ) ? file_get_contents("php://input") : $http_raw_data; |
|
| 19 | - $filtering_entity_uris = json_decode( $filtering_entity_uris ); |
|
| 18 | + $filtering_entity_uris = (null == $http_raw_data) ? file_get_contents("php://input") : $http_raw_data; |
|
| 19 | + $filtering_entity_uris = json_decode($filtering_entity_uris); |
|
| 20 | 20 | |
| 21 | - $filtering_entity_ids = wl_get_entity_post_ids_by_uris( $filtering_entity_uris ); |
|
| 21 | + $filtering_entity_ids = wl_get_entity_post_ids_by_uris($filtering_entity_uris); |
|
| 22 | 22 | $related_posts = array(); |
| 23 | 23 | |
| 24 | 24 | // If the current post is an antity |
| 25 | 25 | // related posts to the current entity are returned |
| 26 | - if ( Wordlift_Entity_Service::TYPE_NAME == $post->post_type ) { |
|
| 27 | - $filtering_entity_ids = array( $post_id ); |
|
| 26 | + if (Wordlift_Entity_Service::TYPE_NAME == $post->post_type) { |
|
| 27 | + $filtering_entity_ids = array($post_id); |
|
| 28 | 28 | } |
| 29 | 29 | |
| 30 | - if ( !empty( $filtering_entity_ids ) ) { |
|
| 30 | + if ( ! empty($filtering_entity_ids)) { |
|
| 31 | 31 | |
| 32 | - $related_posts = wl_core_get_posts( array( |
|
| 32 | + $related_posts = wl_core_get_posts(array( |
|
| 33 | 33 | 'get' => 'posts', |
| 34 | 34 | 'related_to__in' => $filtering_entity_ids, |
| 35 | - 'post__not_in' => array( $post_id ), |
|
| 35 | + 'post__not_in' => array($post_id), |
|
| 36 | 36 | 'post_type' => 'post', |
| 37 | 37 | 'post_status' => 'publish', |
| 38 | 38 | 'as' => 'subject', |
| 39 | - ) ); |
|
| 39 | + )); |
|
| 40 | 40 | |
| 41 | - foreach ( $related_posts as $post_obj ) { |
|
| 41 | + foreach ($related_posts as $post_obj) { |
|
| 42 | 42 | |
| 43 | - $thumbnail = wp_get_attachment_url( get_post_thumbnail_id( $post_obj->ID, 'thumbnail' ) ); |
|
| 44 | - $post_obj->thumbnail = ( $thumbnail ) ? $thumbnail : WL_DEFAULT_THUMBNAIL_PATH; |
|
| 45 | - $post_obj->link = get_edit_post_link( $post_obj->ID, 'none' ); |
|
| 46 | - $post_obj->permalink = get_post_permalink( $post_obj->ID ); |
|
| 43 | + $thumbnail = wp_get_attachment_url(get_post_thumbnail_id($post_obj->ID, 'thumbnail')); |
|
| 44 | + $post_obj->thumbnail = ($thumbnail) ? $thumbnail : WL_DEFAULT_THUMBNAIL_PATH; |
|
| 45 | + $post_obj->link = get_edit_post_link($post_obj->ID, 'none'); |
|
| 46 | + $post_obj->permalink = get_post_permalink($post_obj->ID); |
|
| 47 | 47 | |
| 48 | 48 | } |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | - wl_core_send_json( $related_posts ); |
|
| 51 | + wl_core_send_json($related_posts); |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | -add_action( 'wp_ajax_wordlift_related_posts', 'wordlift_ajax_related_posts' ); |
|
| 54 | +add_action('wp_ajax_wordlift_related_posts', 'wordlift_ajax_related_posts'); |
|
@@ -21,25 +21,25 @@ discard block |
||
| 21 | 21 | * @param string $old_status The old post status |
| 22 | 22 | * @param array $post An array with the post data |
| 23 | 23 | */ |
| 24 | -function wl_transition_post_status( $new_status, $old_status, $post ) { |
|
| 24 | +function wl_transition_post_status($new_status, $old_status, $post) { |
|
| 25 | 25 | |
| 26 | 26 | // wl_write_log( "wl_transition_post_status [ new status :: $new_status ][ old status :: $old_status ][ post ID :: $post->ID ]" ); |
| 27 | 27 | |
| 28 | 28 | // transition from *published* to any other status: delete the post. |
| 29 | - if ( 'publish' === $old_status && 'publish' !== $new_status ) { |
|
| 30 | - rl_delete_post( $post ); |
|
| 29 | + if ('publish' === $old_status && 'publish' !== $new_status) { |
|
| 30 | + rl_delete_post($post); |
|
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | // when a post is published, then all the referenced entities must be published. |
| 34 | - if ( 'publish' !== $old_status && 'publish' === $new_status ) { |
|
| 35 | - foreach ( wl_core_get_related_entity_ids( $post->ID ) as $entity_id ) { |
|
| 36 | - wl_update_post_status( $entity_id, 'publish' ); |
|
| 34 | + if ('publish' !== $old_status && 'publish' === $new_status) { |
|
| 35 | + foreach (wl_core_get_related_entity_ids($post->ID) as $entity_id) { |
|
| 36 | + wl_update_post_status($entity_id, 'publish'); |
|
| 37 | 37 | } |
| 38 | 38 | } |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | // hook save events. |
| 42 | -add_action( 'transition_post_status', 'wl_transition_post_status', 10, 3 ); |
|
| 42 | +add_action('transition_post_status', 'wl_transition_post_status', 10, 3); |
|
| 43 | 43 | |
| 44 | 44 | |
| 45 | 45 | /** |
@@ -47,51 +47,51 @@ discard block |
||
| 47 | 47 | * |
| 48 | 48 | * @param array|int $post An array of post data |
| 49 | 49 | */ |
| 50 | -function rl_delete_post( $post ) { |
|
| 50 | +function rl_delete_post($post) { |
|
| 51 | 51 | |
| 52 | - $post_id = ( is_numeric( $post ) ? $post : $post->ID ); |
|
| 52 | + $post_id = (is_numeric($post) ? $post : $post->ID); |
|
| 53 | 53 | |
| 54 | 54 | // hide all entities that are not referenced by any published post. |
| 55 | - foreach ( wl_core_get_related_entity_ids( $post_id ) as $entity_id ) { |
|
| 55 | + foreach (wl_core_get_related_entity_ids($post_id) as $entity_id) { |
|
| 56 | 56 | |
| 57 | 57 | // check if there is at least one referencing post published. |
| 58 | - $is_published = array_reduce( wl_core_get_related_post_ids( $entity_id ), function ( $carry, $item ) { |
|
| 59 | - $post = get_post( $item ); |
|
| 60 | - return ( $carry || ( 'publish' === $post->post_status ) ); |
|
| 58 | + $is_published = array_reduce(wl_core_get_related_post_ids($entity_id), function($carry, $item) { |
|
| 59 | + $post = get_post($item); |
|
| 60 | + return ($carry || ('publish' === $post->post_status)); |
|
| 61 | 61 | } ); |
| 62 | 62 | // set the entity to draft if no referencing posts are published. |
| 63 | - if ( ! $is_published ) { |
|
| 64 | - wl_update_post_status( $entity_id, 'draft' ); |
|
| 63 | + if ( ! $is_published) { |
|
| 64 | + wl_update_post_status($entity_id, 'draft'); |
|
| 65 | 65 | } |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | // get the entity URI (valid also for posts) |
| 69 | - $uri_esc = wl_sparql_escape_uri( wl_get_entity_uri( $post_id ) ); |
|
| 69 | + $uri_esc = wl_sparql_escape_uri(wl_get_entity_uri($post_id)); |
|
| 70 | 70 | |
| 71 | - wl_write_log( "rl_delete_post [ post id :: $post_id ][ uri esc :: $uri_esc ]" ); |
|
| 71 | + wl_write_log("rl_delete_post [ post id :: $post_id ][ uri esc :: $uri_esc ]"); |
|
| 72 | 72 | |
| 73 | 73 | // create the SPARQL statement by joining the SPARQL prefixes and deleting any known predicate. |
| 74 | 74 | $stmt = rl_sparql_prefixes(); |
| 75 | - foreach ( wl_predicates() as $predicate ) { |
|
| 76 | - $stmt .= "DELETE { <$uri_esc> $predicate ?o . } WHERE { <$uri_esc> $predicate ?o . };\n" . |
|
| 75 | + foreach (wl_predicates() as $predicate) { |
|
| 76 | + $stmt .= "DELETE { <$uri_esc> $predicate ?o . } WHERE { <$uri_esc> $predicate ?o . };\n". |
|
| 77 | 77 | "DELETE { ?s $predicate <$uri_esc> . } WHERE { ?s $predicate <$uri_esc> . };\n"; |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | // if the post is an entity and has exported properties, delete the related predicates. |
| 81 | - if ( Wordlift_Entity_Service::TYPE_NAME === $post->post_type ) { |
|
| 82 | - $type = wl_entity_type_taxonomy_get_type( $post->ID ); |
|
| 81 | + if (Wordlift_Entity_Service::TYPE_NAME === $post->post_type) { |
|
| 82 | + $type = wl_entity_type_taxonomy_get_type($post->ID); |
|
| 83 | 83 | |
| 84 | - if ( isset( $type['custom_fields'] ) ) { |
|
| 85 | - foreach ( $type['custom_fields'] as $field => $params ) { |
|
| 84 | + if (isset($type['custom_fields'])) { |
|
| 85 | + foreach ($type['custom_fields'] as $field => $params) { |
|
| 86 | 86 | // TODO: enclose in <> only if predicate starts with http(s):// |
| 87 | - $predicate = '<' . $params['predicate'] . '>'; |
|
| 87 | + $predicate = '<'.$params['predicate'].'>'; |
|
| 88 | 88 | $stmt .= "DELETE { <$uri_esc> $predicate ?o . } WHERE { <$uri_esc> $predicate ?o . };\n"; |
| 89 | 89 | } |
| 90 | 90 | } |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | // finally execute the query. |
| 94 | - rl_execute_sparql_update_query( $stmt ); |
|
| 94 | + rl_execute_sparql_update_query($stmt); |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | /** |
@@ -100,36 +100,36 @@ discard block |
||
| 100 | 100 | * @param int $post_id The post ID |
| 101 | 101 | * @param string $status The new status |
| 102 | 102 | */ |
| 103 | -function wl_update_post_status( $post_id, $status ) { |
|
| 103 | +function wl_update_post_status($post_id, $status) { |
|
| 104 | 104 | |
| 105 | - wl_write_log( "wl_update_post_status [ post ID :: $post_id ][ status :: $status ]" ); |
|
| 105 | + wl_write_log("wl_update_post_status [ post ID :: $post_id ][ status :: $status ]"); |
|
| 106 | 106 | |
| 107 | 107 | global $wpdb; |
| 108 | 108 | |
| 109 | - if ( ! $post = get_post( $post_id ) ) { |
|
| 109 | + if ( ! $post = get_post($post_id)) { |
|
| 110 | 110 | return; |
| 111 | 111 | } |
| 112 | 112 | |
| 113 | - if ( $status === $post->post_status ) { |
|
| 113 | + if ($status === $post->post_status) { |
|
| 114 | 114 | return; |
| 115 | 115 | } |
| 116 | 116 | |
| 117 | - $wpdb->update( $wpdb->posts, array( 'post_status' => $status ), array( 'ID' => $post->ID ) ); |
|
| 117 | + $wpdb->update($wpdb->posts, array('post_status' => $status), array('ID' => $post->ID)); |
|
| 118 | 118 | |
| 119 | - clean_post_cache( $post->ID ); |
|
| 119 | + clean_post_cache($post->ID); |
|
| 120 | 120 | |
| 121 | 121 | $old_status = $post->post_status; |
| 122 | 122 | $post->post_status = $status; |
| 123 | 123 | |
| 124 | - wp_transition_post_status( $status, $old_status, $post ); |
|
| 124 | + wp_transition_post_status($status, $old_status, $post); |
|
| 125 | 125 | |
| 126 | 126 | /** This action is documented in wp-includes/post.php */ |
| 127 | - do_action( 'edit_post', $post->ID, $post ); |
|
| 127 | + do_action('edit_post', $post->ID, $post); |
|
| 128 | 128 | /** This action is documented in wp-includes/post.php */ |
| 129 | - do_action( "save_post_{$post->post_type}", $post->ID, $post, true ); |
|
| 129 | + do_action("save_post_{$post->post_type}", $post->ID, $post, true); |
|
| 130 | 130 | /** This action is documented in wp-includes/post.php */ |
| 131 | - do_action( 'wl_linked_data_save_post', $post->ID ); |
|
| 131 | + do_action('wl_linked_data_save_post', $post->ID); |
|
| 132 | 132 | /** This action is documented in wp-includes/post.php */ |
| 133 | - do_action( 'wp_insert_post', $post->ID, $post, true ); |
|
| 133 | + do_action('wp_insert_post', $post->ID, $post, true); |
|
| 134 | 134 | } |
| 135 | 135 | |
@@ -10,10 +10,10 @@ discard block |
||
| 10 | 10 | */ |
| 11 | 11 | function wl_admin_shortcode_buttons() { |
| 12 | 12 | // Only add hooks when the current user has permissions AND is in Rich Text editor mode |
| 13 | - if ( ( current_user_can( 'edit_posts' ) || current_user_can( 'edit_pages' ) ) && get_user_option( 'rich_editing' ) ) { |
|
| 14 | - add_filter( 'mce_external_plugins', 'wl_admin_shortcode_buttons_register_tinymce_javascript' ); |
|
| 15 | - add_filter( 'mce_buttons', 'wl_admin_shortcode_register_buttons' ); |
|
| 16 | - add_action( 'admin_footer', 'wl_admin_inject_chord_dialog_dependencies' ); |
|
| 13 | + if ((current_user_can('edit_posts') || current_user_can('edit_pages')) && get_user_option('rich_editing')) { |
|
| 14 | + add_filter('mce_external_plugins', 'wl_admin_shortcode_buttons_register_tinymce_javascript'); |
|
| 15 | + add_filter('mce_buttons', 'wl_admin_shortcode_register_buttons'); |
|
| 16 | + add_action('admin_footer', 'wl_admin_inject_chord_dialog_dependencies'); |
|
| 17 | 17 | } |
| 18 | 18 | } |
| 19 | 19 | |
@@ -24,9 +24,9 @@ discard block |
||
| 24 | 24 | * |
| 25 | 25 | * @return array The TinyMCE plugins array including WordLift shortcodes plugin. |
| 26 | 26 | */ |
| 27 | -function wl_admin_shortcode_buttons_register_tinymce_javascript( $plugin_array ) { |
|
| 27 | +function wl_admin_shortcode_buttons_register_tinymce_javascript($plugin_array) { |
|
| 28 | 28 | |
| 29 | - $plugin_array['wl_shortcodes'] = plugin_dir_url( __FILE__ ) . 'js/wordlift_shortcode_tinymce_plugin.js'; |
|
| 29 | + $plugin_array['wl_shortcodes'] = plugin_dir_url(__FILE__).'js/wordlift_shortcode_tinymce_plugin.js'; |
|
| 30 | 30 | |
| 31 | 31 | return $plugin_array; |
| 32 | 32 | } |
@@ -38,14 +38,14 @@ discard block |
||
| 38 | 38 | * |
| 39 | 39 | * @return array The buttons array including the *wl_shortcodes_menu*. |
| 40 | 40 | */ |
| 41 | -function wl_admin_shortcode_register_buttons( $buttons ) { |
|
| 42 | - array_push( $buttons, 'wl_shortcodes_menu' ); |
|
| 41 | +function wl_admin_shortcode_register_buttons($buttons) { |
|
| 42 | + array_push($buttons, 'wl_shortcodes_menu'); |
|
| 43 | 43 | |
| 44 | 44 | return $buttons; |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | // init process for button control |
| 48 | -add_action( 'admin_init', 'wl_admin_shortcode_buttons' ); |
|
| 48 | +add_action('admin_init', 'wl_admin_shortcode_buttons'); |
|
| 49 | 49 | |
| 50 | 50 | |
| 51 | 51 | /** |
@@ -55,16 +55,16 @@ discard block |
||
| 55 | 55 | */ |
| 56 | 56 | function wl_admin_inject_chord_dialog_dependencies() { |
| 57 | 57 | |
| 58 | - wp_enqueue_style( 'wp-color-picker' ); |
|
| 59 | - wp_enqueue_script( 'wp-color-picker' ); |
|
| 60 | - wp_enqueue_style( 'jquery-ui-slider' ); |
|
| 58 | + wp_enqueue_style('wp-color-picker'); |
|
| 59 | + wp_enqueue_script('wp-color-picker'); |
|
| 60 | + wp_enqueue_style('jquery-ui-slider'); |
|
| 61 | 61 | // Not included by default :| |
| 62 | 62 | // TODO include jquery ui css from the plugin creates css issues on the slider |
| 63 | 63 | // wp_enqueue_style('jquery-ui-css', plugins_url( 'css/jquery-ui/jquery-ui.min.css', __FILE__ ) ); |
| 64 | - wp_enqueue_style( 'wp-jquery-ui-css', 'https://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery.ui.all.css' ); |
|
| 64 | + wp_enqueue_style('wp-jquery-ui-css', 'https://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery.ui.all.css'); |
|
| 65 | 65 | |
| 66 | - wp_enqueue_script( 'jquery' ); |
|
| 67 | - wp_enqueue_script( 'jquery-ui-core' ); |
|
| 68 | - wp_enqueue_script( 'jquery-ui-slider' ); |
|
| 66 | + wp_enqueue_script('jquery'); |
|
| 67 | + wp_enqueue_script('jquery-ui-core'); |
|
| 68 | + wp_enqueue_script('jquery-ui-slider'); |
|
| 69 | 69 | |
| 70 | 70 | } |
@@ -9,16 +9,16 @@ discard block |
||
| 9 | 9 | */ |
| 10 | 10 | function wl_admin_sync_to_redlink() { |
| 11 | 11 | |
| 12 | - $posts = get_posts( array( |
|
| 12 | + $posts = get_posts(array( |
|
| 13 | 13 | 'post_type' => 'any', |
| 14 | - 'posts_per_page' => - 1 |
|
| 15 | - ) ); |
|
| 14 | + 'posts_per_page' => -1 |
|
| 15 | + )); |
|
| 16 | 16 | |
| 17 | - wl_write_log( "wl_admin_sync_to_redlink [ post count :: " . sizeof( $posts ) . " ]" ); |
|
| 17 | + wl_write_log("wl_admin_sync_to_redlink [ post count :: ".sizeof($posts)." ]"); |
|
| 18 | 18 | |
| 19 | - foreach ( $posts as $post ) { |
|
| 20 | - echo esc_html( $post->post_title ) . '<br/>'; |
|
| 21 | - wl_linked_data_push_to_redlink( $post->ID ); |
|
| 19 | + foreach ($posts as $post) { |
|
| 20 | + echo esc_html($post->post_title).'<br/>'; |
|
| 21 | + wl_linked_data_push_to_redlink($post->ID); |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | // Schedule the execution of SPARQL. |
@@ -36,4 +36,4 @@ discard block |
||
| 36 | 36 | |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | -add_action( 'wp_ajax_wl_sync_to_redlink', 'wl_admin_ajax_sync_to_redlink' ); |
|
| 39 | +add_action('wp_ajax_wl_sync_to_redlink', 'wl_admin_ajax_sync_to_redlink'); |
|
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | load_plugin_textdomain( |
| 46 | 46 | $this->domain, |
| 47 | 47 | false, |
| 48 | - dirname( dirname( plugin_basename( __FILE__ ) ) ) . '/languages/' |
|
| 48 | + dirname(dirname(plugin_basename(__FILE__))).'/languages/' |
|
| 49 | 49 | ); |
| 50 | 50 | |
| 51 | 51 | } |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | * @since 1.0.0 |
| 57 | 57 | * @param string $domain The domain that represents the locale of this plugin. |
| 58 | 58 | */ |
| 59 | - public function set_domain( $domain ) { |
|
| 59 | + public function set_domain($domain) { |
|
| 60 | 60 | $this->domain = $domain; |
| 61 | 61 | } |
| 62 | 62 | |
@@ -63,8 +63,8 @@ discard block |
||
| 63 | 63 | * @param int $priority Optional. he priority at which the function should be fired. Default is 10. |
| 64 | 64 | * @param int $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1. |
| 65 | 65 | */ |
| 66 | - public function add_action( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) { |
|
| 67 | - $this->actions = $this->add( $this->actions, $hook, $component, $callback, $priority, $accepted_args ); |
|
| 66 | + public function add_action($hook, $component, $callback, $priority = 10, $accepted_args = 1) { |
|
| 67 | + $this->actions = $this->add($this->actions, $hook, $component, $callback, $priority, $accepted_args); |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | /** |
@@ -77,8 +77,8 @@ discard block |
||
| 77 | 77 | * @param int $priority Optional. he priority at which the function should be fired. Default is 10. |
| 78 | 78 | * @param int $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1 |
| 79 | 79 | */ |
| 80 | - public function add_filter( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) { |
|
| 81 | - $this->filters = $this->add( $this->filters, $hook, $component, $callback, $priority, $accepted_args ); |
|
| 80 | + public function add_filter($hook, $component, $callback, $priority = 10, $accepted_args = 1) { |
|
| 81 | + $this->filters = $this->add($this->filters, $hook, $component, $callback, $priority, $accepted_args); |
|
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | /** |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | * @param int $accepted_args The number of arguments that should be passed to the $callback. |
| 96 | 96 | * @return array The collection of actions and filters registered with WordPress. |
| 97 | 97 | */ |
| 98 | - private function add( $hooks, $hook, $component, $callback, $priority, $accepted_args ) { |
|
| 98 | + private function add($hooks, $hook, $component, $callback, $priority, $accepted_args) { |
|
| 99 | 99 | |
| 100 | 100 | $hooks[] = array( |
| 101 | 101 | 'hook' => $hook, |
@@ -116,12 +116,12 @@ discard block |
||
| 116 | 116 | */ |
| 117 | 117 | public function run() { |
| 118 | 118 | |
| 119 | - foreach ( $this->filters as $hook ) { |
|
| 120 | - add_filter( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] ); |
|
| 119 | + foreach ($this->filters as $hook) { |
|
| 120 | + add_filter($hook['hook'], array($hook['component'], $hook['callback']), $hook['priority'], $hook['accepted_args']); |
|
| 121 | 121 | } |
| 122 | 122 | |
| 123 | - foreach ( $this->actions as $hook ) { |
|
| 124 | - add_action( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] ); |
|
| 123 | + foreach ($this->actions as $hook) { |
|
| 124 | + add_action($hook['hook'], array($hook['component'], $hook['callback']), $hook['priority'], $hook['accepted_args']); |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | } |
@@ -31,15 +31,15 @@ discard block |
||
| 31 | 31 | * |
| 32 | 32 | * @param string $class_name The class related to the logs. |
| 33 | 33 | */ |
| 34 | - public function __construct( $class_name ) { |
|
| 34 | + public function __construct($class_name) { |
|
| 35 | 35 | |
| 36 | 36 | $this->class_name = $class_name; |
| 37 | 37 | |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | - public static function get_logger( $class_name ) { |
|
| 40 | + public static function get_logger($class_name) { |
|
| 41 | 41 | |
| 42 | - return new Wordlift_Log_Service( $class_name ); |
|
| 42 | + return new Wordlift_Log_Service($class_name); |
|
| 43 | 43 | |
| 44 | 44 | } |
| 45 | 45 | |
@@ -51,44 +51,44 @@ discard block |
||
| 51 | 51 | * @param string $level The log level. |
| 52 | 52 | * @param string $message The message to log. |
| 53 | 53 | */ |
| 54 | - public function log( $level, $message ) { |
|
| 54 | + public function log($level, $message) { |
|
| 55 | 55 | |
| 56 | 56 | // If we're tracing or debugging, but the debug flag isn't set, then we don't log. |
| 57 | - if ( ( self::TRACE === $level || self::DEBUG === $level ) && ( ! defined( 'WP_DEBUG' ) || ! WP_DEBUG ) ) { |
|
| 57 | + if ((self::TRACE === $level || self::DEBUG === $level) && ( ! defined('WP_DEBUG') || ! WP_DEBUG)) { |
|
| 58 | 58 | return; |
| 59 | 59 | } |
| 60 | 60 | |
| 61 | - error_log( sprintf( self::MESSAGE_TEMPLATE, $level, $this->class_name, $message ) ); |
|
| 61 | + error_log(sprintf(self::MESSAGE_TEMPLATE, $level, $this->class_name, $message)); |
|
| 62 | 62 | |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | - public function error( $message ) { |
|
| 65 | + public function error($message) { |
|
| 66 | 66 | |
| 67 | - $this->log( self::ERROR, $message ); |
|
| 67 | + $this->log(self::ERROR, $message); |
|
| 68 | 68 | |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | - public function warn( $message ) { |
|
| 71 | + public function warn($message) { |
|
| 72 | 72 | |
| 73 | - $this->log( self::WARN, $message ); |
|
| 73 | + $this->log(self::WARN, $message); |
|
| 74 | 74 | |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | - public function info( $message ) { |
|
| 77 | + public function info($message) { |
|
| 78 | 78 | |
| 79 | - $this->log( self::INFO, $message ); |
|
| 79 | + $this->log(self::INFO, $message); |
|
| 80 | 80 | |
| 81 | 81 | } |
| 82 | 82 | |
| 83 | - public function debug( $message ) { |
|
| 83 | + public function debug($message) { |
|
| 84 | 84 | |
| 85 | - $this->log( self::DEBUG, $message ); |
|
| 85 | + $this->log(self::DEBUG, $message); |
|
| 86 | 86 | |
| 87 | 87 | } |
| 88 | 88 | |
| 89 | - public function trace( $message ) { |
|
| 89 | + public function trace($message) { |
|
| 90 | 90 | |
| 91 | - $this->log( self::TRACE, $message ); |
|
| 91 | + $this->log(self::TRACE, $message); |
|
| 92 | 92 | |
| 93 | 93 | } |
| 94 | 94 | |
@@ -26,28 +26,28 @@ discard block |
||
| 26 | 26 | * @param int $expires_in_seconds How many seconds the cache is valid. |
| 27 | 27 | * @return array The remote response. |
| 28 | 28 | */ |
| 29 | -function wl_caching_remote_request( $url, $args, $refresh = false, $expires_in_seconds = 3600 ) { |
|
| 29 | +function wl_caching_remote_request($url, $args, $refresh = false, $expires_in_seconds = 3600) { |
|
| 30 | 30 | |
| 31 | 31 | // Merge the default settings for remote queries. |
| 32 | - $args = array_merge_recursive( unserialize( WL_REDLINK_API_HTTP_OPTIONS ), $args ); |
|
| 32 | + $args = array_merge_recursive(unserialize(WL_REDLINK_API_HTTP_OPTIONS), $args); |
|
| 33 | 33 | |
| 34 | 34 | // echo $url . "\n"; |
| 35 | 35 | // print_r( $args ); |
| 36 | 36 | |
| 37 | 37 | // Create an hash of the request. |
| 38 | - $hash = wl_caching_hash( $url, $args ); |
|
| 38 | + $hash = wl_caching_hash($url, $args); |
|
| 39 | 39 | |
| 40 | 40 | // If the document is cached, return the cached copy. |
| 41 | - if ( ! $refresh && false !== ( $response = wl_caching_get( $hash ) ) ) { |
|
| 41 | + if ( ! $refresh && false !== ($response = wl_caching_get($hash))) { |
|
| 42 | 42 | return $response; |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | // Make the request, put the response in the cache and return it to the client. |
| 46 | - $response = wp_remote_request( $url, $args ); |
|
| 46 | + $response = wp_remote_request($url, $args); |
|
| 47 | 47 | |
| 48 | 48 | // Cache only valid responses. |
| 49 | - if ( ! is_wp_error( $response ) && 200 === (int)$response['response']['code'] ) { |
|
| 50 | - wl_caching_put( $hash, $response, $expires_in_seconds ); |
|
| 49 | + if ( ! is_wp_error($response) && 200 === (int) $response['response']['code']) { |
|
| 50 | + wl_caching_put($hash, $response, $expires_in_seconds); |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | return $response; |
@@ -63,9 +63,9 @@ discard block |
||
| 63 | 63 | * @param string $args The request parameters. |
| 64 | 64 | * @return string The hash. |
| 65 | 65 | */ |
| 66 | -function wl_caching_hash( $url, $args ) { |
|
| 66 | +function wl_caching_hash($url, $args) { |
|
| 67 | 67 | |
| 68 | - return hash( 'md5', $url ) . '-' . hash( 'md5', serialize( $args ) ); |
|
| 68 | + return hash('md5', $url).'-'.hash('md5', serialize($args)); |
|
| 69 | 69 | |
| 70 | 70 | } |
| 71 | 71 | |
@@ -81,10 +81,10 @@ discard block |
||
| 81 | 81 | * @param string $hash The hash. |
| 82 | 82 | * @return string|false The cache filename or false if not found. |
| 83 | 83 | */ |
| 84 | -function wl_caching_get_filename( $hash ) { |
|
| 84 | +function wl_caching_get_filename($hash) { |
|
| 85 | 85 | |
| 86 | - $files = glob( wl_caching_get_temp_path( $hash ) . '_*' ); |
|
| 87 | - if ( ! is_array( $files ) || 0 === sizeof( $files ) ) { |
|
| 86 | + $files = glob(wl_caching_get_temp_path($hash).'_*'); |
|
| 87 | + if ( ! is_array($files) || 0 === sizeof($files)) { |
|
| 88 | 88 | return false; |
| 89 | 89 | } |
| 90 | 90 | |
@@ -93,19 +93,19 @@ discard block |
||
| 93 | 93 | |
| 94 | 94 | // Return false if the filename doesn't conform. |
| 95 | 95 | $matches = array(); |
| 96 | - if ( 1 !== preg_match( '/_(\d+)$/', $filename, $matches ) ) { |
|
| 96 | + if (1 !== preg_match('/_(\d+)$/', $filename, $matches)) { |
|
| 97 | 97 | return false; |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | // echo 'time: ' . time() . ' > expires at: ' . (int)$matches[1] . "\n"; |
| 101 | 101 | |
| 102 | 102 | // Delete the file and return false if it's expired. |
| 103 | - if ( time() >= (int)$matches[1] ) { |
|
| 104 | - wl_caching_delete_file( $filename ); |
|
| 103 | + if (time() >= (int) $matches[1]) { |
|
| 104 | + wl_caching_delete_file($filename); |
|
| 105 | 105 | return false; |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | - wl_write_log( "[ wl_caching ] Found a cached response [ filename :: $filename ]" ); |
|
| 108 | + wl_write_log("[ wl_caching ] Found a cached response [ filename :: $filename ]"); |
|
| 109 | 109 | |
| 110 | 110 | return $filename; |
| 111 | 111 | |
@@ -123,10 +123,10 @@ discard block |
||
| 123 | 123 | * @param string $hash The document hash |
| 124 | 124 | * @return array|false The cached response or false if the document is not found in the cache. |
| 125 | 125 | */ |
| 126 | -function wl_caching_get( $hash ) { |
|
| 126 | +function wl_caching_get($hash) { |
|
| 127 | 127 | |
| 128 | - if ( false !== ( $filename = wl_caching_get_filename( $hash ) ) ) { |
|
| 129 | - return json_decode( file_get_contents( $filename ), true ); |
|
| 128 | + if (false !== ($filename = wl_caching_get_filename($hash))) { |
|
| 129 | + return json_decode(file_get_contents($filename), true); |
|
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | return false; |
@@ -143,7 +143,7 @@ discard block |
||
| 143 | 143 | * @param array $response The response. |
| 144 | 144 | * @param int $expires_in_seconds How many seconds the cache is valid. |
| 145 | 145 | */ |
| 146 | -function wl_caching_put( $hash, $response, $expires_in_seconds = 3600 ) { |
|
| 146 | +function wl_caching_put($hash, $response, $expires_in_seconds = 3600) { |
|
| 147 | 147 | |
| 148 | 148 | // Add the cached flag. |
| 149 | 149 | $now = time(); |
@@ -155,14 +155,14 @@ discard block |
||
| 155 | 155 | |
| 156 | 156 | // According to http://stackoverflow.com/questions/804045/preferred-method-to-store-php-arrays-json-encode-vs-serialize |
| 157 | 157 | // the fastest serialization/deserialization function is json_encode/json_decode |
| 158 | - $filename = wl_caching_get_temp_path( $hash ) . '_' . $expires_at; |
|
| 159 | - $pathname = dirname( $filename ); |
|
| 158 | + $filename = wl_caching_get_temp_path($hash).'_'.$expires_at; |
|
| 159 | + $pathname = dirname($filename); |
|
| 160 | 160 | |
| 161 | - if ( ! file_exists( dirname( $pathname ) ) ) { |
|
| 161 | + if ( ! file_exists(dirname($pathname))) { |
|
| 162 | 162 | mkdir($pathname, 0777, true); |
| 163 | 163 | } |
| 164 | 164 | |
| 165 | - file_put_contents( $filename, json_encode( $response ) ); |
|
| 165 | + file_put_contents($filename, json_encode($response)); |
|
| 166 | 166 | |
| 167 | 167 | } |
| 168 | 168 | |
@@ -177,8 +177,8 @@ discard block |
||
| 177 | 177 | function wl_caching_get_cache_folder() { |
| 178 | 178 | |
| 179 | 179 | $temp_dir = sys_get_temp_dir(); |
| 180 | - $temp_dir .= ( '/' === substr( $temp_dir, -1, 1 ) ? '' : '/' ); // add a trailing slash |
|
| 181 | - return $temp_dir . 'wordlift.tmp/cache/'; |
|
| 180 | + $temp_dir .= ('/' === substr($temp_dir, -1, 1) ? '' : '/'); // add a trailing slash |
|
| 181 | + return $temp_dir.'wordlift.tmp/cache/'; |
|
| 182 | 182 | |
| 183 | 183 | } |
| 184 | 184 | |
@@ -193,10 +193,10 @@ discard block |
||
| 193 | 193 | * @param string $hash The hash. |
| 194 | 194 | * @return string The full path to the file. |
| 195 | 195 | */ |
| 196 | -function wl_caching_get_temp_path( $hash ) { |
|
| 196 | +function wl_caching_get_temp_path($hash) { |
|
| 197 | 197 | |
| 198 | 198 | // By chunking the hash we ensure we don't put too many files in the same folder |
| 199 | - return wl_caching_get_cache_folder() . chunk_split( substr( $hash, 0, 15 ), 3, '/' ) . $hash; |
|
| 199 | + return wl_caching_get_cache_folder().chunk_split(substr($hash, 0, 15), 3, '/').$hash; |
|
| 200 | 200 | |
| 201 | 201 | } |
| 202 | 202 | |
@@ -210,11 +210,11 @@ discard block |
||
| 210 | 210 | * |
| 211 | 211 | * @param string $hash The hash file. |
| 212 | 212 | */ |
| 213 | -function wl_caching_delete( $hash ) { |
|
| 213 | +function wl_caching_delete($hash) { |
|
| 214 | 214 | |
| 215 | 215 | // Delete all cached versions of the provided hash. |
| 216 | - while ( false !== ( $filename = wl_caching_get_filename( $hash ) ) ) { |
|
| 217 | - wl_caching_delete_file( $filename ); |
|
| 216 | + while (false !== ($filename = wl_caching_get_filename($hash))) { |
|
| 217 | + wl_caching_delete_file($filename); |
|
| 218 | 218 | } |
| 219 | 219 | |
| 220 | 220 | } |
@@ -226,17 +226,17 @@ discard block |
||
| 226 | 226 | * |
| 227 | 227 | * @param string $filename The cache file to delete. |
| 228 | 228 | */ |
| 229 | -function wl_caching_delete_file( $filename ) { |
|
| 229 | +function wl_caching_delete_file($filename) { |
|
| 230 | 230 | |
| 231 | 231 | $cache_folder = wl_caching_get_cache_folder(); |
| 232 | 232 | |
| 233 | - if ( file_exists( $filename ) ) { |
|
| 234 | - unlink( $filename ); |
|
| 233 | + if (file_exists($filename)) { |
|
| 234 | + unlink($filename); |
|
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | // Delete folders contained in the cache folder - rmdir is safe: it doesn't delete non-empty folders. |
| 238 | - while ( 0 === strpos( $filename = dirname( $filename ), $cache_folder ) ) { |
|
| 239 | - @rmdir( $filename ); |
|
| 238 | + while (0 === strpos($filename = dirname($filename), $cache_folder)) { |
|
| 239 | + @rmdir($filename); |
|
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | } |
@@ -250,8 +250,8 @@ discard block |
||
| 250 | 250 | * @param array $response The response structure. |
| 251 | 251 | * @return bool True if cached otherwise false. |
| 252 | 252 | */ |
| 253 | -function wl_caching_response_is_cached( $response ) { |
|
| 253 | +function wl_caching_response_is_cached($response) { |
|
| 254 | 254 | |
| 255 | - return ( is_array( $response ) && isset( $response['wl_cached'] ) && true === $response['wl_cached'] ); |
|
| 255 | + return (is_array($response) && isset($response['wl_cached']) && true === $response['wl_cached']); |
|
| 256 | 256 | |
| 257 | 257 | } |
| 258 | 258 | \ No newline at end of file |