/** * Set up the test. */ function setUp() { parent::setUp(); $this->log_service = Wordlift_Log_Service::get_logger('UserServiceTest'); wl_configure_wordpress_test(); // wl_empty_blog(); }
/** * Create: * * 1 Post * * 3 Event entities of which 2 referenced by the Post * * 1 Person entity reference by the Post */ function testGetEvents() { $log = Wordlift_Log_Service::get_logger('testGetEvents'); $post_id = wl_create_post('', 'post-1', 'Post 1', 'publish', 'post'); $entity_1_id = wl_create_post("Entity 1's\nText", 'entity-1', "Entity 1's Title", 'publish', 'entity'); $thumbnail_1_id = $this->createPostThumbnail('http://example.org/entity_1.png', 'Entity 1 Thumbnail', 'image/png', 'dummy/image_1.png', $entity_1_id); wl_set_entity_main_type($entity_1_id, Wordlift_Schema_Service::SCHEMA_EVENT_TYPE); add_post_meta($entity_1_id, Wordlift_Schema_Service::FIELD_DATE_START, '2014-01-01', true); add_post_meta($entity_1_id, Wordlift_Schema_Service::FIELD_DATE_END, '2014-01-07', true); $entity_2_id = wl_create_post("Entity 2's\nText", 'entity-2', "Entity 2's Title", 'publish', 'entity'); $thumbnail_2_id = $this->createPostThumbnail('http://example.org/entity_2.png', 'Entity 2 Thumbnail', 'image/png', 'dummy/image_2.png', $entity_2_id); wl_set_entity_main_type($entity_2_id, Wordlift_Schema_Service::SCHEMA_EVENT_TYPE); add_post_meta($entity_2_id, Wordlift_Schema_Service::FIELD_DATE_START, '2014-01-02', true); add_post_meta($entity_2_id, Wordlift_Schema_Service::FIELD_DATE_END, '2014-01-08', true); $entity_3_id = wl_create_post('', 'entity-3', 'Entity 3', 'publish', 'entity'); wl_set_entity_main_type($entity_3_id, Wordlift_Schema_Service::SCHEMA_EVENT_TYPE); add_post_meta($entity_3_id, Wordlift_Schema_Service::FIELD_DATE_START, '2014-01-03', true); add_post_meta($entity_3_id, Wordlift_Schema_Service::FIELD_DATE_END, '2014-01-09', true); $entity_4_id = wl_create_post('', 'entity-4', 'Entity 4', 'publish', 'entity'); wl_set_entity_main_type($entity_4_id, 'http://schema.org/Person'); wl_write_log("[ entity 1 ID :: {$entity_1_id} ][ entity 2 ID :: {$entity_2_id} ][ entity 3 ID :: {$entity_3_id} ][ entity 4 ID :: {$entity_4_id} ]"); wl_core_add_relation_instances($post_id, WL_WHAT_RELATION, array($entity_1_id, $entity_2_id, $entity_4_id)); $events = Wordlift_Timeline_Service::get_instance()->get_events($post_id); $this->assertCount(2, $events); $event_ids = array_map(function ($item) { return $item->ID; }, $events); $this->assertContains($entity_1_id, $event_ids); $this->assertContains($entity_2_id, $event_ids); // From here onwards we check that the JSON response matches the events data. $response = Wordlift_Timeline_Service::get_instance()->to_json($events); $this->assertTrue(isset($response['timeline'])); $this->assertCount(2, $response['timeline']['date']); $this->assertEquals('default', $response['timeline']['type']); $entity_1 = get_post($entity_1_id); $entity_2 = get_post($entity_2_id); $entity_1_headline = '<a href="' . get_permalink($entity_1_id) . '">' . $entity_1->post_title . '</a>'; $entity_2_headline = '<a href="' . get_permalink($entity_2_id) . '">' . $entity_2->post_title . '</a>'; $entity_1_date_start = str_replace('-', ',', get_post_meta($entity_1_id, Wordlift_Schema_Service::FIELD_DATE_START, true)); $entity_1_date_end = str_replace('-', ',', get_post_meta($entity_1_id, Wordlift_Schema_Service::FIELD_DATE_END, true)); $entity_2_date_start = str_replace('-', ',', get_post_meta($entity_2_id, Wordlift_Schema_Service::FIELD_DATE_START, true)); $entity_2_date_end = str_replace('-', ',', get_post_meta($entity_2_id, Wordlift_Schema_Service::FIELD_DATE_END, true)); // This is the right order, i.e. the event 1 is in the 2nd position in the dates array. $date_1 = $response['timeline']['date'][1]; $date_2 = $response['timeline']['date'][0]; $this->assertEquals($entity_1_date_start, $date_1['startDate']); $this->assertEquals($entity_1_date_end, $date_1['endDate']); $this->assertEquals($entity_2_date_start, $date_2['startDate']); $this->assertEquals($entity_2_date_end, $date_2['endDate']); $this->assertEquals($entity_1->post_content, $date_1['text']); $this->assertEquals($entity_2->post_content, $date_2['text']); $this->assertEquals($entity_1_headline, $date_1['headline']); $this->assertEquals($entity_2_headline, $date_2['headline']); $thumbnail_1 = wp_get_attachment_image_src($thumbnail_1_id); $thumbnail_2 = wp_get_attachment_image_src($thumbnail_2_id); $this->assertEquals($thumbnail_1[0], $date_1['asset']['media']); $this->assertEquals($thumbnail_2[0], $date_2['asset']['media']); }
/** * WL_Metabox constructor. * * @since 3.1.0 */ public function __construct() { // Create a logger instance. $this->log_service = Wordlift_Log_Service::get_logger('WL_Metabox'); // Add hooks to print metaboxes and save submitted data. add_action('add_meta_boxes', array(&$this, 'add_main_metabox')); add_action('wl_linked_data_save_post', array(&$this, 'save_form_data')); // Enqueue js and css $this->enqueue_scripts_and_styles(); }
/** * Constructor. Recevies.... TODO write docs */ public function __construct($args) { $this->log_service = Wordlift_Log_Service::get_logger('WL_Metabox_Field'); if (empty($args)) { return; } // Save a copy of the custom field's params $this->raw_custom_field = reset($args); // Extract meta name (post_meta key for the DB) $this->meta_name = key($args); // Extract linked data predicate if (isset($this->raw_custom_field['predicate'])) { $this->predicate = $this->raw_custom_field['predicate']; } else { return; } // Extract human readable label $exploded_predicate = explode('/', $this->predicate); $this->label = end($exploded_predicate); // Extract field constraints (numerosity, expected type) // Default constaints: accept one string. if (isset($this->raw_custom_field['type'])) { $this->expected_wl_type = $this->raw_custom_field['type']; } else { $this->expected_wl_type = Wordlift_Schema_Service::DATA_TYPE_STRING; } $this->cardinality = 1; if (isset($this->raw_custom_field['constraints'])) { $constraints = $this->raw_custom_field['constraints']; // Extract cardinality if (isset($constraints['cardinality'])) { $this->cardinality = $constraints['cardinality']; } // Which type of entity can we accept (e.g. Place, Event, ecc.)? if ($this->expected_wl_type === Wordlift_Schema_Service::DATA_TYPE_URI && isset($constraints['uri_type'])) { $this->expected_uri_type = is_array($constraints['uri_type']) ? $constraints['uri_type'] : array($constraints['uri_type']); } } }
/** * Create a Wordlift_Timeline_Shortcode instance. * * @since 3.1.0 */ public function __construct() { $this->log_service = Wordlift_Log_Service::get_logger('Wordlift_Timeline_Shortcode'); // Add the wl_timeline shortcode. add_shortcode('wl_timeline', array($this, 'render')); }
/** * Create a Wordlift_Entity_Service instance. * * @since 3.2.0 * * @param \Wordlift_UI_Service $ui_service The UI service. */ public function __construct($ui_service, $schema_service, $notice_service) { $this->log_service = Wordlift_Log_Service::get_logger('Wordlift_Entity_Service'); // Set the UI service. $this->ui_service = $ui_service; // Set the Schema service. $this->schema_service = $schema_service; // Set the Schema service. $this->notice_service = $notice_service; // Set the singleton instance. self::$instance = $this; }
/** * Create an instance of the Thumbnail service. * * @since 3.1.5 */ public function __construct() { $this->log_service = Wordlift_Log_Service::get_logger('Wordlift_Thumbnail_Service'); }
/** * Create an instance of Wordlift_Entity_Types_Taxonomy_Walker. * * @since 3.1.0 */ public function __construct() { $this->log_service = Wordlift_Log_Service::get_logger('Wordlift_Entity_Types_Taxonomy_Walker'); }
/** * Create an instance of the User service. * * @since 3.1.7 */ public function __construct() { $this->log_service = Wordlift_Log_Service::get_logger('Wordlift_User_Service'); self::$instance = $this; }
/** * Load the required dependencies for this plugin. * * Include the following files that make up the plugin: * * - Wordlift_Loader. Orchestrates the hooks of the plugin. * - Wordlift_i18n. Defines internationalization functionality. * - Wordlift_Admin. Defines all hooks for the admin area. * - Wordlift_Public. Defines all hooks for the public side of the site. * * Create an instance of the loader which will be used to register the hooks * with WordPress. * * @since 1.0.0 * @access private */ private function load_dependencies() { /** * The class responsible for orchestrating the actions and filters of the * core plugin. */ require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-wordlift-loader.php'; /** * The class responsible for defining internationalization functionality * of the plugin. */ require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-wordlift-i18n.php'; /** * The Redirect service. */ require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-wordlift-redirect-service.php'; /** * The Log service. */ require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-wordlift-log-service.php'; /** * The Query builder. */ require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-wordlift-query-builder.php'; /** * The Schema service. */ require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-wordlift-schema-service.php'; /** * The UI service. */ require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-wordlift-ui-service.php'; /** * The Thumbnail service. */ require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-wordlift-thumbnail-service.php'; /** * The Entity Types Taxonomy service. */ require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-wordlift-entity-types-taxonomy-service.php'; /** * The Entity service. */ require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-wordlift-entity-service.php'; /** * The User service. */ require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-wordlift-user-service.php'; /** * The Timeline service. */ require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-wordlift-timeline-service.php'; /** * The class responsible for defining all actions that occur in the admin area. */ require_once plugin_dir_path(dirname(__FILE__)) . 'admin/class-wordlift-admin.php'; /** * The class to customize the entity list admin page. */ require_once plugin_dir_path(dirname(__FILE__)) . 'admin/class-wordlift-admin-entity-list.php'; /** * The Entity Types Taxonomy Walker (transforms checkboxes into radios). */ require_once plugin_dir_path(dirname(__FILE__)) . 'admin/class-wordlift-entity-types-taxonomy-walker.php'; /** * The Notice service. */ require_once plugin_dir_path(dirname(__FILE__)) . 'admin/class-wordlift-notice-service.php'; /** * The PrimaShop adapter. */ require_once plugin_dir_path(dirname(__FILE__)) . 'admin/class-wordlift-primashop-adapter.php'; /** * The class responsible for defining all actions that occur in the public-facing * side of the site. */ require_once plugin_dir_path(dirname(__FILE__)) . 'public/class-wordlift-public.php'; /** * The Timeline shortcode. */ require_once plugin_dir_path(dirname(__FILE__)) . 'public/class-wordlift-timeline-shortcode.php'; /** * The ShareThis service. */ require_once plugin_dir_path(dirname(__FILE__)) . 'public/class-wordlift-sharethis-service.php'; $this->loader = new Wordlift_Loader(); // Instantiate a global logger. global $wl_logger; $wl_logger = Wordlift_Log_Service::get_logger('WordLift'); // Create an instance of the UI service. $this->ui_service = new Wordlift_UI_Service(); // Create an instance of the Thumbnail service. Later it'll be hooked to post meta events. $this->thumbnail_service = new Wordlift_Thumbnail_Service(); // Create an instance of the Schema service. $this->schema_service = new Wordlift_Schema_Service(); // Create an instance of the Notice service. $this->notice_service = new Wordlift_Notice_Service(); // Create an instance of the Entity service, passing the UI service to draw parts of the Entity admin page. $this->entity_service = new Wordlift_Entity_Service($this->ui_service, $this->schema_service, $this->notice_service); // Create an instance of the User service. $this->user_service = new Wordlift_User_Service(); // Create a new instance of the Timeline service and Timeline shortcode. $this->timeline_service = new Wordlift_Timeline_Service($this->entity_service); // Create a new instance of the Redirect service. $this->redirect_service = new Wordlift_Redirect_Service($this->entity_service); // Create an instance of the Timeline shortcode. new Wordlift_Timeline_Shortcode(); // Create entity list customization (wp-admin/edit.php) $this->entity_list_service = new Wordlift_Entity_List_Service($this->entity_service); $this->entity_types_taxonomy_walker = new Wordlift_Entity_Types_Taxonomy_Walker(); // Create an instance of the ShareThis service, later we hook it to the_content and the_excerpt filters. $this->sharethis_service = new Wordlift_ShareThis_Service(); // Create an instance of the PrimaShop adapter. $this->primashop_adapter = new Wordlift_PrimaShop_Adapter(); }
/** * Create a Wordlift_Redirect_Service instance. * * @since 3.2.0 * * @param \Wordlift_Entity_Service $entity_service The Entity service. */ public function __construct($entity_service) { $this->log_service = Wordlift_Log_Service::get_logger('Wordlift_Redirect_Service'); $this->entity_service = $entity_service; self::$instance = $this; }
/** * Wordlift_Schema_Service constructor. * * @since 3.1.0 */ public function __construct() { $this->log_service = Wordlift_Log_Service::get_logger('Wordlift_Schema_Service'); // Create a singleton instance of the Schema service, useful to provide static functions to global functions. self::$instance = $this; // Set the taxonomy data. // Note: parent types must be defined before child types. $this->schema = array('thing' => $this->get_thing_schema(), 'creative-work' => $this->get_creative_work_schema(), 'event' => $this->get_event_schema(), 'organization' => $this->get_organization_schema(), 'person' => $this->get_person_schema(), 'place' => $this->get_place_schema(), 'localbusiness' => $this->get_local_business_schema()); }
/** * Create an instance of the ShareThis service. * * @since 3.2.0 */ public function __construct() { $this->log_service = Wordlift_Log_Service::get_logger('Wordlift_ShareThis_Service'); }
/** * Create a Wordlift_Entity_List_Service. * * @since 3.3.0 * * @param \Wordlift_Entity_Service $entity_service The Entity service. */ public function __construct($entity_service) { $this->log_service = Wordlift_Log_Service::get_logger('Wordlift_Entity_List_Service'); $this->entity_service = $entity_service; }