@@ -19,25 +19,25 @@ |
||
| 19 | 19 | */ |
| 20 | 20 | class Wordlift_Duration_Property_Service extends Wordlift_Simple_Property_Service { |
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * {@inheritdoc} |
|
| 24 | - */ |
|
| 25 | - function get( $post_id, $meta_key ) { |
|
| 22 | + /** |
|
| 23 | + * {@inheritdoc} |
|
| 24 | + */ |
|
| 25 | + function get( $post_id, $meta_key ) { |
|
| 26 | 26 | |
| 27 | - // Get the values and filter out the empty ones (or the ones with 00:00). |
|
| 28 | - $values = array_filter( parent::get( $post_id, $meta_key ), function ( $item ) { |
|
| 29 | - return ! empty( $item ) && '00:00' !== $item; |
|
| 30 | - } ); |
|
| 27 | + // Get the values and filter out the empty ones (or the ones with 00:00). |
|
| 28 | + $values = array_filter( parent::get( $post_id, $meta_key ), function ( $item ) { |
|
| 29 | + return ! empty( $item ) && '00:00' !== $item; |
|
| 30 | + } ); |
|
| 31 | 31 | |
| 32 | - /* |
|
| 32 | + /* |
|
| 33 | 33 | * Map the value in the meta |
| 34 | 34 | * The UI for the meta date enable two forms, a number of minutes |
| 35 | 35 | * or an h:mm format. |
| 36 | 36 | * Both needs to be adjusted to the iso format. |
| 37 | 37 | */ |
| 38 | - return array_map( function ( $value ) { |
|
| 39 | - return 'PT' . str_replace( ':', 'H', $value ) . 'M'; |
|
| 40 | - }, $values ); |
|
| 41 | - } |
|
| 38 | + return array_map( function ( $value ) { |
|
| 39 | + return 'PT' . str_replace( ':', 'H', $value ) . 'M'; |
|
| 40 | + }, $values ); |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | 43 | } |
@@ -22,11 +22,11 @@ discard block |
||
| 22 | 22 | /** |
| 23 | 23 | * {@inheritdoc} |
| 24 | 24 | */ |
| 25 | - function get( $post_id, $meta_key ) { |
|
| 25 | + function get($post_id, $meta_key) { |
|
| 26 | 26 | |
| 27 | 27 | // Get the values and filter out the empty ones (or the ones with 00:00). |
| 28 | - $values = array_filter( parent::get( $post_id, $meta_key ), function ( $item ) { |
|
| 29 | - return ! empty( $item ) && '00:00' !== $item; |
|
| 28 | + $values = array_filter(parent::get($post_id, $meta_key), function($item) { |
|
| 29 | + return ! empty($item) && '00:00' !== $item; |
|
| 30 | 30 | } ); |
| 31 | 31 | |
| 32 | 32 | /* |
@@ -35,9 +35,9 @@ discard block |
||
| 35 | 35 | * or an h:mm format. |
| 36 | 36 | * Both needs to be adjusted to the iso format. |
| 37 | 37 | */ |
| 38 | - return array_map( function ( $value ) { |
|
| 39 | - return 'PT' . str_replace( ':', 'H', $value ) . 'M'; |
|
| 40 | - }, $values ); |
|
| 38 | + return array_map(function($value) { |
|
| 39 | + return 'PT'.str_replace(':', 'H', $value).'M'; |
|
| 40 | + }, $values); |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | } |
@@ -16,56 +16,56 @@ |
||
| 16 | 16 | // Mapping options / validations rules used by wl_core_get_posts to perform validation on args |
| 17 | 17 | // The array is serialized because array constants are only from php 5.6 on. |
| 18 | 18 | define( 'WL_CORE_GET_POSTS_VALIDATION_RULES', serialize( array( |
| 19 | - 'get' => array( 'posts', 'post_ids' ), |
|
| 20 | - 'as' => array( 'object', 'subject' ), |
|
| 21 | - 'post_type' => array( 'post', 'entity' ), |
|
| 22 | - 'post_status' => array( 'draft', 'trash', 'publish' ), |
|
| 23 | - 'with_predicate' => array( |
|
| 24 | - WL_WHAT_RELATION, |
|
| 25 | - WL_WHEN_RELATION, |
|
| 26 | - WL_WHERE_RELATION, |
|
| 27 | - WL_WHO_RELATION, |
|
| 28 | - ), |
|
| 19 | + 'get' => array( 'posts', 'post_ids' ), |
|
| 20 | + 'as' => array( 'object', 'subject' ), |
|
| 21 | + 'post_type' => array( 'post', 'entity' ), |
|
| 22 | + 'post_status' => array( 'draft', 'trash', 'publish' ), |
|
| 23 | + 'with_predicate' => array( |
|
| 24 | + WL_WHAT_RELATION, |
|
| 25 | + WL_WHEN_RELATION, |
|
| 26 | + WL_WHERE_RELATION, |
|
| 27 | + WL_WHO_RELATION, |
|
| 28 | + ), |
|
| 29 | 29 | ) ) ); |
| 30 | 30 | |
| 31 | 31 | // Classification boxes configuration for angularjs edit-post widget |
| 32 | 32 | // The array is serialized because array constants are only from php 5.6 on. |
| 33 | 33 | |
| 34 | 34 | define( 'WL_CORE_POST_CLASSIFICATION_BOXES', serialize( array( |
| 35 | - array( |
|
| 36 | - 'id' => WL_WHAT_RELATION, |
|
| 37 | - 'label' => 'What', |
|
| 38 | - 'registeredTypes' => array( |
|
| 39 | - 'thing', |
|
| 40 | - // WLS returns the `creativework` (lowercase version of `CreativeWork`). |
|
| 41 | - 'creativework', |
|
| 42 | - 'creative-work', |
|
| 43 | - 'recipe', |
|
| 44 | - ), |
|
| 45 | - 'selectedEntities' => array(), |
|
| 46 | - ), |
|
| 47 | - array( |
|
| 48 | - 'id' => WL_WHO_RELATION, |
|
| 49 | - 'label' => 'Who', |
|
| 50 | - 'registeredTypes' => array( |
|
| 51 | - 'organization', |
|
| 52 | - 'person', |
|
| 53 | - // WLS returns the `localbusiness` (lowercase version of `LocalBusiness`). |
|
| 54 | - 'localbusiness', |
|
| 55 | - 'local-business', |
|
| 56 | - ), |
|
| 57 | - 'selectedEntities' => array(), |
|
| 58 | - ), |
|
| 59 | - array( |
|
| 60 | - 'id' => WL_WHERE_RELATION, |
|
| 61 | - 'label' => 'Where', |
|
| 62 | - 'registeredTypes' => array( 'place' ), |
|
| 63 | - 'selectedEntities' => array(), |
|
| 64 | - ), |
|
| 65 | - array( |
|
| 66 | - 'id' => WL_WHEN_RELATION, |
|
| 67 | - 'label' => 'When', |
|
| 68 | - 'registeredTypes' => array( 'event' ), |
|
| 69 | - 'selectedEntities' => array(), |
|
| 70 | - ), |
|
| 35 | + array( |
|
| 36 | + 'id' => WL_WHAT_RELATION, |
|
| 37 | + 'label' => 'What', |
|
| 38 | + 'registeredTypes' => array( |
|
| 39 | + 'thing', |
|
| 40 | + // WLS returns the `creativework` (lowercase version of `CreativeWork`). |
|
| 41 | + 'creativework', |
|
| 42 | + 'creative-work', |
|
| 43 | + 'recipe', |
|
| 44 | + ), |
|
| 45 | + 'selectedEntities' => array(), |
|
| 46 | + ), |
|
| 47 | + array( |
|
| 48 | + 'id' => WL_WHO_RELATION, |
|
| 49 | + 'label' => 'Who', |
|
| 50 | + 'registeredTypes' => array( |
|
| 51 | + 'organization', |
|
| 52 | + 'person', |
|
| 53 | + // WLS returns the `localbusiness` (lowercase version of `LocalBusiness`). |
|
| 54 | + 'localbusiness', |
|
| 55 | + 'local-business', |
|
| 56 | + ), |
|
| 57 | + 'selectedEntities' => array(), |
|
| 58 | + ), |
|
| 59 | + array( |
|
| 60 | + 'id' => WL_WHERE_RELATION, |
|
| 61 | + 'label' => 'Where', |
|
| 62 | + 'registeredTypes' => array( 'place' ), |
|
| 63 | + 'selectedEntities' => array(), |
|
| 64 | + ), |
|
| 65 | + array( |
|
| 66 | + 'id' => WL_WHEN_RELATION, |
|
| 67 | + 'label' => 'When', |
|
| 68 | + 'registeredTypes' => array( 'event' ), |
|
| 69 | + 'selectedEntities' => array(), |
|
| 70 | + ), |
|
| 71 | 71 | ) ) ); |
@@ -1,37 +1,37 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -define( 'WL_DEFAULT_THUMBNAIL_PATH', dirname( dirname( plugin_dir_url( __FILE__ ) ) ) . '/public/images/missing-image-150x150.png' ); |
|
| 4 | -define( 'WL_DEFAULT_PATH', dirname( dirname( plugin_dir_url( __FILE__ ) ) ) . '/' ); |
|
| 3 | +define('WL_DEFAULT_THUMBNAIL_PATH', dirname(dirname(plugin_dir_url(__FILE__))).'/public/images/missing-image-150x150.png'); |
|
| 4 | +define('WL_DEFAULT_PATH', dirname(dirname(plugin_dir_url(__FILE__))).'/'); |
|
| 5 | 5 | |
| 6 | 6 | // Database version |
| 7 | -define( 'WL_DB_VERSION', '3.14' ); |
|
| 7 | +define('WL_DB_VERSION', '3.14'); |
|
| 8 | 8 | // Custom table name |
| 9 | -define( 'WL_DB_RELATION_INSTANCES_TABLE_NAME', 'wl_relation_instances' ); |
|
| 9 | +define('WL_DB_RELATION_INSTANCES_TABLE_NAME', 'wl_relation_instances'); |
|
| 10 | 10 | |
| 11 | -define( 'WL_WHAT_RELATION', 'what' ); |
|
| 12 | -define( 'WL_WHO_RELATION', 'who' ); |
|
| 13 | -define( 'WL_WHERE_RELATION', 'where' ); |
|
| 14 | -define( 'WL_WHEN_RELATION', 'when' ); |
|
| 11 | +define('WL_WHAT_RELATION', 'what'); |
|
| 12 | +define('WL_WHO_RELATION', 'who'); |
|
| 13 | +define('WL_WHERE_RELATION', 'where'); |
|
| 14 | +define('WL_WHEN_RELATION', 'when'); |
|
| 15 | 15 | |
| 16 | 16 | // Mapping options / validations rules used by wl_core_get_posts to perform validation on args |
| 17 | 17 | // The array is serialized because array constants are only from php 5.6 on. |
| 18 | -define( 'WL_CORE_GET_POSTS_VALIDATION_RULES', serialize( array( |
|
| 19 | - 'get' => array( 'posts', 'post_ids' ), |
|
| 20 | - 'as' => array( 'object', 'subject' ), |
|
| 21 | - 'post_type' => array( 'post', 'entity' ), |
|
| 22 | - 'post_status' => array( 'draft', 'trash', 'publish' ), |
|
| 18 | +define('WL_CORE_GET_POSTS_VALIDATION_RULES', serialize(array( |
|
| 19 | + 'get' => array('posts', 'post_ids'), |
|
| 20 | + 'as' => array('object', 'subject'), |
|
| 21 | + 'post_type' => array('post', 'entity'), |
|
| 22 | + 'post_status' => array('draft', 'trash', 'publish'), |
|
| 23 | 23 | 'with_predicate' => array( |
| 24 | 24 | WL_WHAT_RELATION, |
| 25 | 25 | WL_WHEN_RELATION, |
| 26 | 26 | WL_WHERE_RELATION, |
| 27 | 27 | WL_WHO_RELATION, |
| 28 | 28 | ), |
| 29 | -) ) ); |
|
| 29 | +))); |
|
| 30 | 30 | |
| 31 | 31 | // Classification boxes configuration for angularjs edit-post widget |
| 32 | 32 | // The array is serialized because array constants are only from php 5.6 on. |
| 33 | 33 | |
| 34 | -define( 'WL_CORE_POST_CLASSIFICATION_BOXES', serialize( array( |
|
| 34 | +define('WL_CORE_POST_CLASSIFICATION_BOXES', serialize(array( |
|
| 35 | 35 | array( |
| 36 | 36 | 'id' => WL_WHAT_RELATION, |
| 37 | 37 | 'label' => 'What', |
@@ -59,13 +59,13 @@ discard block |
||
| 59 | 59 | array( |
| 60 | 60 | 'id' => WL_WHERE_RELATION, |
| 61 | 61 | 'label' => 'Where', |
| 62 | - 'registeredTypes' => array( 'place' ), |
|
| 62 | + 'registeredTypes' => array('place'), |
|
| 63 | 63 | 'selectedEntities' => array(), |
| 64 | 64 | ), |
| 65 | 65 | array( |
| 66 | 66 | 'id' => WL_WHEN_RELATION, |
| 67 | 67 | 'label' => 'When', |
| 68 | - 'registeredTypes' => array( 'event' ), |
|
| 68 | + 'registeredTypes' => array('event'), |
|
| 69 | 69 | 'selectedEntities' => array(), |
| 70 | 70 | ), |
| 71 | -) ) ); |
|
| 71 | +))); |
|
@@ -7,14 +7,14 @@ discard block |
||
| 7 | 7 | * |
| 8 | 8 | * @return boolean Return true if supported, false otherwise |
| 9 | 9 | */ |
| 10 | -function wl_core_check_relation_predicate_is_supported( $predicate ) { |
|
| 10 | +function wl_core_check_relation_predicate_is_supported($predicate) { |
|
| 11 | 11 | |
| 12 | - return in_array( $predicate, array( |
|
| 12 | + return in_array($predicate, array( |
|
| 13 | 13 | WL_WHAT_RELATION, |
| 14 | 14 | WL_WHEN_RELATION, |
| 15 | 15 | WL_WHERE_RELATION, |
| 16 | 16 | WL_WHO_RELATION, |
| 17 | - ) ); |
|
| 17 | + )); |
|
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | /** |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | */ |
| 25 | 25 | function wl_core_get_validation_rules() { |
| 26 | 26 | |
| 27 | - return unserialize( WL_CORE_GET_POSTS_VALIDATION_RULES ); |
|
| 27 | + return unserialize(WL_CORE_GET_POSTS_VALIDATION_RULES); |
|
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | /** |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | function wl_core_get_relation_instances_table_name() { |
| 36 | 36 | |
| 37 | 37 | global $wpdb; |
| 38 | - $table_name = $wpdb->prefix . WL_DB_RELATION_INSTANCES_TABLE_NAME; |
|
| 38 | + $table_name = $wpdb->prefix.WL_DB_RELATION_INSTANCES_TABLE_NAME; |
|
| 39 | 39 | |
| 40 | 40 | return $table_name; |
| 41 | 41 | } |
@@ -50,15 +50,15 @@ discard block |
||
| 50 | 50 | * @uses $wpdb->replace() to perform the query |
| 51 | 51 | * @return integer|boolean Return then relation instance ID or false |
| 52 | 52 | */ |
| 53 | -function wl_core_add_relation_instance( $subject_id, $predicate, $object_id ) { |
|
| 53 | +function wl_core_add_relation_instance($subject_id, $predicate, $object_id) { |
|
| 54 | 54 | |
| 55 | 55 | // Checks on subject and object |
| 56 | - if ( ! is_numeric( $subject_id ) || ! is_numeric( $object_id ) ) { |
|
| 56 | + if ( ! is_numeric($subject_id) || ! is_numeric($object_id)) { |
|
| 57 | 57 | return false; |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | // Checks on the given relation |
| 61 | - if ( ! wl_core_check_relation_predicate_is_supported( $predicate ) ) { |
|
| 61 | + if ( ! wl_core_check_relation_predicate_is_supported($predicate)) { |
|
| 62 | 62 | return false; |
| 63 | 63 | } |
| 64 | 64 | |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | 'predicate' => $predicate, |
| 75 | 75 | 'object_id' => $object_id, |
| 76 | 76 | ), |
| 77 | - array( '%d', '%s', '%d' ) |
|
| 77 | + array('%d', '%s', '%d') |
|
| 78 | 78 | ); |
| 79 | 79 | |
| 80 | 80 | // Return record id |
@@ -91,22 +91,22 @@ discard block |
||
| 91 | 91 | * |
| 92 | 92 | * @return (boolean) False for failure. True for success. |
| 93 | 93 | */ |
| 94 | -function wl_core_delete_relation_instance( $subject_id, $predicate, $object_id ) { |
|
| 94 | +function wl_core_delete_relation_instance($subject_id, $predicate, $object_id) { |
|
| 95 | 95 | |
| 96 | 96 | // Checks on subject and object |
| 97 | - if ( ! is_numeric( $subject_id ) || ! is_numeric( $object_id ) ) { |
|
| 97 | + if ( ! is_numeric($subject_id) || ! is_numeric($object_id)) { |
|
| 98 | 98 | return false; |
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | // Checks on the given relation |
| 102 | - if ( ! wl_core_check_relation_predicate_is_supported( $predicate ) ) { |
|
| 102 | + if ( ! wl_core_check_relation_predicate_is_supported($predicate)) { |
|
| 103 | 103 | return false; |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | // Prepare interaction with db |
| 107 | 107 | global $wpdb; |
| 108 | 108 | |
| 109 | - wl_write_log( "Going to delete relation instace [ subject_id :: $subject_id ] [ object_id :: $object_id ] [ predicate :: $predicate ]" ); |
|
| 109 | + wl_write_log("Going to delete relation instace [ subject_id :: $subject_id ] [ object_id :: $object_id ] [ predicate :: $predicate ]"); |
|
| 110 | 110 | |
| 111 | 111 | // @see ttps://codex.wordpress.org/it:Riferimento_classi/wpdb#DELETE_di_righe |
| 112 | 112 | $wpdb->delete( |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | 'predicate' => $predicate, |
| 117 | 117 | 'object_id' => $object_id, |
| 118 | 118 | ), |
| 119 | - array( '%d', '%s', '%d' ) |
|
| 119 | + array('%d', '%s', '%d') |
|
| 120 | 120 | ); |
| 121 | 121 | |
| 122 | 122 | return true; |
@@ -132,27 +132,27 @@ discard block |
||
| 132 | 132 | * |
| 133 | 133 | * @return (integer|boolean) Return the relation instances IDs or false |
| 134 | 134 | */ |
| 135 | -function wl_core_add_relation_instances( $subject_id, $predicate, $object_ids ) { |
|
| 135 | +function wl_core_add_relation_instances($subject_id, $predicate, $object_ids) { |
|
| 136 | 136 | |
| 137 | 137 | // Checks on subject and object |
| 138 | - if ( ! is_numeric( $subject_id ) ) { |
|
| 138 | + if ( ! is_numeric($subject_id)) { |
|
| 139 | 139 | return false; |
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | // Checks on the given relation |
| 143 | - if ( ! wl_core_check_relation_predicate_is_supported( $predicate ) ) { |
|
| 143 | + if ( ! wl_core_check_relation_predicate_is_supported($predicate)) { |
|
| 144 | 144 | return false; |
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | // Check $object_ids is an array |
| 148 | - if ( ! is_array( $object_ids ) || empty( $object_ids ) ) { |
|
| 148 | + if ( ! is_array($object_ids) || empty($object_ids)) { |
|
| 149 | 149 | return false; |
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | // Call method to check and add each single relation |
| 153 | 153 | $inserted_records_ids = array(); |
| 154 | - foreach ( $object_ids as $object_id ) { |
|
| 155 | - $new_record_id = wl_core_add_relation_instance( $subject_id, $predicate, $object_id ); |
|
| 154 | + foreach ($object_ids as $object_id) { |
|
| 155 | + $new_record_id = wl_core_add_relation_instance($subject_id, $predicate, $object_id); |
|
| 156 | 156 | $inserted_records_ids[] = $new_record_id; |
| 157 | 157 | } |
| 158 | 158 | |
@@ -167,10 +167,10 @@ discard block |
||
| 167 | 167 | * |
| 168 | 168 | * @return (boolean) False for failure. True for success. |
| 169 | 169 | */ |
| 170 | -function wl_core_delete_relation_instances( $subject_id ) { |
|
| 170 | +function wl_core_delete_relation_instances($subject_id) { |
|
| 171 | 171 | |
| 172 | 172 | // Checks on subject and object |
| 173 | - if ( ! is_numeric( $subject_id ) ) { |
|
| 173 | + if ( ! is_numeric($subject_id)) { |
|
| 174 | 174 | return false; |
| 175 | 175 | } |
| 176 | 176 | |
@@ -185,7 +185,7 @@ discard block |
||
| 185 | 185 | array( |
| 186 | 186 | 'subject_id' => $subject_id, |
| 187 | 187 | ), |
| 188 | - array( '%d' ) |
|
| 188 | + array('%d') |
|
| 189 | 189 | ); |
| 190 | 190 | |
| 191 | 191 | return true; |
@@ -202,16 +202,16 @@ discard block |
||
| 202 | 202 | * 'status' => null |
| 203 | 203 | * ); |
| 204 | 204 | */ |
| 205 | -function wl_core_validate_filters_for_related( $filters ) { |
|
| 205 | +function wl_core_validate_filters_for_related($filters) { |
|
| 206 | 206 | |
| 207 | - if ( ! is_array( $filters ) ) { |
|
| 207 | + if ( ! is_array($filters)) { |
|
| 208 | 208 | $filters = array(); |
| 209 | 209 | } |
| 210 | 210 | |
| 211 | - if ( ! isset( $filters['predicate'] ) ) { |
|
| 211 | + if ( ! isset($filters['predicate'])) { |
|
| 212 | 212 | $filters['predicate'] = null; |
| 213 | 213 | } |
| 214 | - if ( ! isset( $filters['status'] ) ) { |
|
| 214 | + if ( ! isset($filters['status'])) { |
|
| 215 | 215 | $filters['status'] = null; |
| 216 | 216 | } |
| 217 | 217 | |
@@ -234,11 +234,11 @@ discard block |
||
| 234 | 234 | * |
| 235 | 235 | * @return array Array of post entity objects. |
| 236 | 236 | */ |
| 237 | -function wl_core_get_related_entities( $subject_id, $filters = array() ) { |
|
| 237 | +function wl_core_get_related_entities($subject_id, $filters = array()) { |
|
| 238 | 238 | |
| 239 | - $filters = wl_core_validate_filters_for_related( $filters ); |
|
| 239 | + $filters = wl_core_validate_filters_for_related($filters); |
|
| 240 | 240 | |
| 241 | - return wl_core_inner_get_related_entities( "posts", $subject_id, $filters['predicate'], $filters['status'] ); |
|
| 241 | + return wl_core_inner_get_related_entities("posts", $subject_id, $filters['predicate'], $filters['status']); |
|
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | /** |
@@ -257,11 +257,11 @@ discard block |
||
| 257 | 257 | * |
| 258 | 258 | * @return array Array of post entity objects. |
| 259 | 259 | */ |
| 260 | -function wl_core_get_related_entity_ids( $subject_id, $filters = array() ) { |
|
| 260 | +function wl_core_get_related_entity_ids($subject_id, $filters = array()) { |
|
| 261 | 261 | |
| 262 | - $filters = wl_core_validate_filters_for_related( $filters ); |
|
| 262 | + $filters = wl_core_validate_filters_for_related($filters); |
|
| 263 | 263 | |
| 264 | - return wl_core_inner_get_related_entities( 'post_ids', $subject_id, $filters['predicate'], $filters['status'] ); |
|
| 264 | + return wl_core_inner_get_related_entities('post_ids', $subject_id, $filters['predicate'], $filters['status']); |
|
| 265 | 265 | } |
| 266 | 266 | |
| 267 | 267 | /** |
@@ -276,16 +276,16 @@ discard block |
||
| 276 | 276 | * |
| 277 | 277 | * @return array Array of ids. |
| 278 | 278 | */ |
| 279 | -function wl_core_inner_get_related_entities( $get, $item_id, $predicate = null, $post_status = null ) { |
|
| 279 | +function wl_core_inner_get_related_entities($get, $item_id, $predicate = null, $post_status = null) { |
|
| 280 | 280 | |
| 281 | - if ( $results = wl_core_get_posts( array( |
|
| 281 | + if ($results = wl_core_get_posts(array( |
|
| 282 | 282 | 'get' => $get, |
| 283 | 283 | 'post_type' => 'entity', |
| 284 | 284 | 'post_status' => $post_status, |
| 285 | 285 | 'related_to' => $item_id, |
| 286 | 286 | 'as' => 'object', |
| 287 | 287 | 'with_predicate' => $predicate, |
| 288 | - ) ) |
|
| 288 | + )) |
|
| 289 | 289 | ) { |
| 290 | 290 | return $results; |
| 291 | 291 | } |
@@ -310,11 +310,11 @@ discard block |
||
| 310 | 310 | * |
| 311 | 311 | * @return array Array of objects. |
| 312 | 312 | */ |
| 313 | -function wl_core_get_related_posts( $object_id, $filters = array() ) { |
|
| 313 | +function wl_core_get_related_posts($object_id, $filters = array()) { |
|
| 314 | 314 | |
| 315 | - $filters = wl_core_validate_filters_for_related( $filters ); |
|
| 315 | + $filters = wl_core_validate_filters_for_related($filters); |
|
| 316 | 316 | |
| 317 | - return wl_core_inner_get_related_posts( "posts", $object_id, $filters['predicate'], $filters['status'] ); |
|
| 317 | + return wl_core_inner_get_related_posts("posts", $object_id, $filters['predicate'], $filters['status']); |
|
| 318 | 318 | } |
| 319 | 319 | |
| 320 | 320 | /** |
@@ -333,11 +333,11 @@ discard block |
||
| 333 | 333 | * |
| 334 | 334 | * @return array Array of objects. |
| 335 | 335 | */ |
| 336 | -function wl_core_get_related_post_ids( $object_id, $filters = array() ) { |
|
| 336 | +function wl_core_get_related_post_ids($object_id, $filters = array()) { |
|
| 337 | 337 | |
| 338 | - $filters = wl_core_validate_filters_for_related( $filters ); |
|
| 338 | + $filters = wl_core_validate_filters_for_related($filters); |
|
| 339 | 339 | |
| 340 | - return wl_core_inner_get_related_posts( "post_ids", $object_id, $filters['predicate'], $filters['status'] ); |
|
| 340 | + return wl_core_inner_get_related_posts("post_ids", $object_id, $filters['predicate'], $filters['status']); |
|
| 341 | 341 | } |
| 342 | 342 | |
| 343 | 343 | /** |
@@ -351,36 +351,36 @@ discard block |
||
| 351 | 351 | * |
| 352 | 352 | * @return array Array of objects. |
| 353 | 353 | */ |
| 354 | -function wl_core_inner_get_related_posts( $get, $item_id, $predicate = null, $post_status = null ) { |
|
| 354 | +function wl_core_inner_get_related_posts($get, $item_id, $predicate = null, $post_status = null) { |
|
| 355 | 355 | |
| 356 | 356 | // Retrieve the post object |
| 357 | - $post = get_post( $item_id ); |
|
| 358 | - if ( null === $post ) { |
|
| 357 | + $post = get_post($item_id); |
|
| 358 | + if (null === $post) { |
|
| 359 | 359 | return array(); |
| 360 | 360 | } |
| 361 | 361 | |
| 362 | - if ( "entity" === $post->post_type ) { |
|
| 363 | - if ( $results = wl_core_get_posts( array( |
|
| 362 | + if ("entity" === $post->post_type) { |
|
| 363 | + if ($results = wl_core_get_posts(array( |
|
| 364 | 364 | 'get' => $get, |
| 365 | 365 | 'post_type' => 'post', |
| 366 | 366 | 'post_status' => $post_status, |
| 367 | 367 | 'related_to' => $item_id, |
| 368 | 368 | 'as' => 'subject', |
| 369 | 369 | 'with_predicate' => $predicate, |
| 370 | - ) ) |
|
| 370 | + )) |
|
| 371 | 371 | ) { |
| 372 | 372 | return $results; |
| 373 | 373 | } |
| 374 | 374 | } else { |
| 375 | - if ( $results = wl_core_get_posts( array( |
|
| 375 | + if ($results = wl_core_get_posts(array( |
|
| 376 | 376 | 'get' => $get, |
| 377 | 377 | 'post_type' => 'post', |
| 378 | 378 | 'post_status' => $post_status, |
| 379 | - 'post__not_in' => array( $item_id ), |
|
| 380 | - 'related_to__in' => wl_core_get_related_entity_ids( $post->ID ), |
|
| 379 | + 'post__not_in' => array($item_id), |
|
| 380 | + 'related_to__in' => wl_core_get_related_entity_ids($post->ID), |
|
| 381 | 381 | 'as' => 'subject', |
| 382 | 382 | 'with_predicate' => $predicate, |
| 383 | - ) ) |
|
| 383 | + )) |
|
| 384 | 384 | ) { |
| 385 | 385 | return $results; |
| 386 | 386 | } |
@@ -415,7 +415,7 @@ discard block |
||
| 415 | 415 | * |
| 416 | 416 | * @return string | false String representing a sql statement, or false in case of error |
| 417 | 417 | */ |
| 418 | -function wl_core_sql_query_builder( $args ) { |
|
| 418 | +function wl_core_sql_query_builder($args) { |
|
| 419 | 419 | |
| 420 | 420 | // Prepare interaction with db |
| 421 | 421 | global $wpdb; |
@@ -425,7 +425,7 @@ discard block |
||
| 425 | 425 | // Sql Action |
| 426 | 426 | $sql = "SELECT "; |
| 427 | 427 | // Determine what has to be returned depending on 'get' argument value |
| 428 | - switch ( $args['get'] ) { |
|
| 428 | + switch ($args['get']) { |
|
| 429 | 429 | case 'posts': |
| 430 | 430 | $sql .= "p.*"; |
| 431 | 431 | break; |
@@ -435,16 +435,16 @@ discard block |
||
| 435 | 435 | } |
| 436 | 436 | |
| 437 | 437 | // If we look for posts related as objects the JOIN has to be done with the object_id column and viceversa |
| 438 | - $join_column = $args['as'] . "_id"; |
|
| 438 | + $join_column = $args['as']."_id"; |
|
| 439 | 439 | |
| 440 | 440 | $sql .= " FROM $wpdb->posts as p JOIN $table_name as r ON p.id = r.$join_column"; |
| 441 | 441 | |
| 442 | 442 | // Sql add post type filter |
| 443 | - $sql .= $wpdb->prepare( " AND p.post_type = %s AND", $args['post_type'] ); |
|
| 443 | + $sql .= $wpdb->prepare(" AND p.post_type = %s AND", $args['post_type']); |
|
| 444 | 444 | |
| 445 | 445 | // Sql add post status filter |
| 446 | - if ( isset( $args['post_status'] ) && ! is_null( $args['post_status'] ) ) { |
|
| 447 | - $sql .= $wpdb->prepare( " p.post_status = %s AND", $args['post_status'] ); |
|
| 446 | + if (isset($args['post_status']) && ! is_null($args['post_status'])) { |
|
| 447 | + $sql .= $wpdb->prepare(" p.post_status = %s AND", $args['post_status']); |
|
| 448 | 448 | } |
| 449 | 449 | |
| 450 | 450 | // Add filtering conditions |
@@ -453,36 +453,36 @@ discard block |
||
| 453 | 453 | // If we look for posts related as subject this means that |
| 454 | 454 | // related_to is reference for an object: object_id is the filtering column |
| 455 | 455 | |
| 456 | - $filtering_column = ( 'object' == $args['as'] ) ? "subject_id" : "object_id"; |
|
| 456 | + $filtering_column = ('object' == $args['as']) ? "subject_id" : "object_id"; |
|
| 457 | 457 | |
| 458 | - if ( isset( $args['related_to'] ) ) { |
|
| 459 | - $sql .= $wpdb->prepare( " r.$filtering_column = %d", $args['related_to'] ); |
|
| 458 | + if (isset($args['related_to'])) { |
|
| 459 | + $sql .= $wpdb->prepare(" r.$filtering_column = %d", $args['related_to']); |
|
| 460 | 460 | } |
| 461 | - if ( isset( $args['related_to'] ) && isset( $args['related_to__in'] ) ) { |
|
| 461 | + if (isset($args['related_to']) && isset($args['related_to__in'])) { |
|
| 462 | 462 | $sql .= " AND"; |
| 463 | 463 | } |
| 464 | - if ( isset( $args['related_to__in'] ) ) { |
|
| 465 | - $sql .= " r.$filtering_column IN (" . implode( ",", $args['related_to__in'] ) . ")"; |
|
| 464 | + if (isset($args['related_to__in'])) { |
|
| 465 | + $sql .= " r.$filtering_column IN (".implode(",", $args['related_to__in']).")"; |
|
| 466 | 466 | } |
| 467 | - if ( isset( $args['post__not_in'] ) ) { |
|
| 468 | - $sql .= " AND r." . $args['as'] . "_id NOT IN (" . implode( ",", $args['post__not_in'] ) . ")"; |
|
| 467 | + if (isset($args['post__not_in'])) { |
|
| 468 | + $sql .= " AND r.".$args['as']."_id NOT IN (".implode(",", $args['post__not_in']).")"; |
|
| 469 | 469 | } |
| 470 | - if ( isset( $args['post__in'] ) ) { |
|
| 471 | - $sql .= " AND r." . $args['as'] . "_id IN (" . implode( ",", $args['post__in'] ) . ")"; |
|
| 470 | + if (isset($args['post__in'])) { |
|
| 471 | + $sql .= " AND r.".$args['as']."_id IN (".implode(",", $args['post__in']).")"; |
|
| 472 | 472 | } |
| 473 | 473 | // Add predicate filter if required |
| 474 | - if ( isset( $args['with_predicate'] ) ) { |
|
| 474 | + if (isset($args['with_predicate'])) { |
|
| 475 | 475 | // Sql Inner Join clausole |
| 476 | - $sql .= $wpdb->prepare( " AND r.predicate = %s", $args['with_predicate'] ); |
|
| 476 | + $sql .= $wpdb->prepare(" AND r.predicate = %s", $args['with_predicate']); |
|
| 477 | 477 | } |
| 478 | 478 | // Add a group by clause to avoid duplicated rows |
| 479 | 479 | // @todo: isn't a distinct a better choice? |
| 480 | 480 | $sql .= " GROUP BY p.id"; |
| 481 | 481 | |
| 482 | 482 | // @todo: how does `first` represent the limit? |
| 483 | - if ( isset( $args['first'] ) && is_numeric( $args['first'] ) ) { |
|
| 483 | + if (isset($args['first']) && is_numeric($args['first'])) { |
|
| 484 | 484 | // Sql Inner Join clause. |
| 485 | - $sql .= $wpdb->prepare( " LIMIT %d", $args['first'] ); |
|
| 485 | + $sql .= $wpdb->prepare(" LIMIT %d", $args['first']); |
|
| 486 | 486 | } |
| 487 | 487 | // Close sql statement |
| 488 | 488 | $sql .= ";"; |
@@ -501,23 +501,23 @@ discard block |
||
| 501 | 501 | * |
| 502 | 502 | * @return array|false List of WP_Post objects or list of WP_Post ids. False in case of error or invalid params |
| 503 | 503 | */ |
| 504 | -function wl_core_get_posts( $args, $returned_type = OBJECT ) { |
|
| 504 | +function wl_core_get_posts($args, $returned_type = OBJECT) { |
|
| 505 | 505 | |
| 506 | 506 | // Merge given args with defaults args value |
| 507 | - $args = array_merge( array( |
|
| 507 | + $args = array_merge(array( |
|
| 508 | 508 | 'with_predicate' => null, |
| 509 | 509 | 'as' => 'subject', |
| 510 | 510 | 'post_type' => 'post', |
| 511 | 511 | 'get' => 'posts', |
| 512 | 512 | 'post_status' => null, |
| 513 | - ), $args ); |
|
| 513 | + ), $args); |
|
| 514 | 514 | |
| 515 | 515 | // Arguments validation rules |
| 516 | 516 | // At least one between related_to and related_to__in has to be set |
| 517 | - if ( ! isset( $args['related_to'] ) && ! isset( $args['related_to__in'] ) ) { |
|
| 517 | + if ( ! isset($args['related_to']) && ! isset($args['related_to__in'])) { |
|
| 518 | 518 | return false; |
| 519 | 519 | } |
| 520 | - if ( isset( $args['related_to'] ) && ! is_numeric( $args['related_to'] ) ) { |
|
| 520 | + if (isset($args['related_to']) && ! is_numeric($args['related_to'])) { |
|
| 521 | 521 | return false; |
| 522 | 522 | } |
| 523 | 523 | |
@@ -531,18 +531,18 @@ discard block |
||
| 531 | 531 | 'related_to__in', |
| 532 | 532 | ) as $option_name |
| 533 | 533 | ) { |
| 534 | - if ( isset( $args[ $option_name ] ) ) { |
|
| 535 | - if ( ! is_array( $args[ $option_name ] ) || 0 == count( array_filter( $args[ $option_name ], "is_numeric" ) ) ) { |
|
| 534 | + if (isset($args[$option_name])) { |
|
| 535 | + if ( ! is_array($args[$option_name]) || 0 == count(array_filter($args[$option_name], "is_numeric"))) { |
|
| 536 | 536 | return false; |
| 537 | 537 | } |
| 538 | 538 | // Sanitize value removing non numeric values from the array |
| 539 | - $args[ $option_name ] = array_filter( $args[ $option_name ], "is_numeric" ); |
|
| 539 | + $args[$option_name] = array_filter($args[$option_name], "is_numeric"); |
|
| 540 | 540 | } |
| 541 | 541 | } |
| 542 | 542 | // Performing validation rules |
| 543 | - foreach ( wl_core_get_validation_rules() as $option_name => $accepeted_values ) { |
|
| 544 | - if ( isset( $args[ $option_name ] ) && ! is_null( $args[ $option_name ] ) ) { |
|
| 545 | - if ( ! in_array( $args[ $option_name ], $accepeted_values ) ) { |
|
| 543 | + foreach (wl_core_get_validation_rules() as $option_name => $accepeted_values) { |
|
| 544 | + if (isset($args[$option_name]) && ! is_null($args[$option_name])) { |
|
| 545 | + if ( ! in_array($args[$option_name], $accepeted_values)) { |
|
| 546 | 546 | return false; |
| 547 | 547 | } |
| 548 | 548 | } |
@@ -552,21 +552,21 @@ discard block |
||
| 552 | 552 | global $wpdb; |
| 553 | 553 | |
| 554 | 554 | // Build sql statement with given arguments |
| 555 | - $sql_statement = wl_core_sql_query_builder( $args ); |
|
| 555 | + $sql_statement = wl_core_sql_query_builder($args); |
|
| 556 | 556 | |
| 557 | 557 | // wl_write_log( "Going to execute sql statement: $sql_statement " ); |
| 558 | 558 | // $results = array(); |
| 559 | 559 | |
| 560 | 560 | // If ids are required, returns a one-dimensional array containing ids. |
| 561 | 561 | // Otherwise an array of associative arrays representing the post | relation object |
| 562 | - if ( 'post_ids' == $args['get'] ) { |
|
| 562 | + if ('post_ids' == $args['get']) { |
|
| 563 | 563 | # See https://codex.wordpress.org/Class_Reference/wpdb#SELECT_a_Column |
| 564 | - $results = $wpdb->get_col( $sql_statement ); |
|
| 564 | + $results = $wpdb->get_col($sql_statement); |
|
| 565 | 565 | } else { |
| 566 | - $results = $wpdb->get_results( $sql_statement, $returned_type ); |
|
| 566 | + $results = $wpdb->get_results($sql_statement, $returned_type); |
|
| 567 | 567 | } |
| 568 | 568 | // If there were an error performing the query then false is returned |
| 569 | - if ( ! empty( $wpdb->last_error ) ) { |
|
| 569 | + if ( ! empty($wpdb->last_error)) { |
|
| 570 | 570 | return false; |
| 571 | 571 | } |
| 572 | 572 | |