/**
     * Renders the Timeline.
     *
     * @since 3.1.0
     * @return string The rendered HTML.
     */
    public function render($atts)
    {
        //extract attributes and set default values
        $timeline_atts = shortcode_atts(array('width' => '100%', 'height' => '600px', 'global' => false), $atts);
        // Enqueue the scripts for the timeline.
        $this->enqueue_scripts();
        // Get the current post id or set null if global is set to true.
        $post_id = $timeline_atts['global'] ? null : get_the_ID();
        // Generate a unique ID for this timeline.
        $element_id = uniqid('wl-timeline-');
        // Escaping atts.
        $esc_width = esc_attr($timeline_atts['width']);
        $esc_height = esc_attr($timeline_atts['height']);
        $data_post_id = isset($post_id) ? "data-post-id='{$post_id}'" : '';
        if (WP_DEBUG) {
            $this->log_service->trace("Creating a timeline widget [ element id :: {$element_id} ][ post id :: {$post_id} ]");
        }
        // Building template.
        // TODO: in the HTML code there are static CSS rules. Move them to the CSS file.
        return <<<EOF
<div class="wl-timeline" id="{$element_id}" {$data_post_id}
\tstyle="width:{$esc_width}; height:{$esc_height}; margin-top:10px; margin-bottom:10px">
</div>
EOF;
    }
 function test_delete()
 {
     $users_ids = get_users(array('fields' => 'id'));
     foreach ($users_ids as $user_id) {
         // Get the URI.
         $user_uri = Wordlift_User_Service::get_instance()->get_uri($user_id);
         $query = Wordlift_Query_Builder::new_instance()->delete()->statement($user_uri, Wordlift_Query_Builder::RDFS_TYPE_URI, '?o')->build() . Wordlift_Query_Builder::new_instance()->delete()->statement($user_uri, Wordlift_Query_Builder::RDFS_LABEL_URI, '?o')->build() . Wordlift_Query_Builder::new_instance()->delete()->statement($user_uri, Wordlift_Query_Builder::SCHEMA_GIVEN_NAME_URI, '?o')->build() . Wordlift_Query_Builder::new_instance()->delete()->statement($user_uri, Wordlift_Query_Builder::SCHEMA_FAMILY_NAME_URI, '?o')->build();
         $this->log_service->info($query);
     }
 }
 /**
  * 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']);
 }
Example #5
0
 /**
  * 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();
 }
 /**
  * Get or calculate rating for a given entity
  *
  * @since 3.3.0
  *
  * @param int $post_id The entity post id.
  * @param $force_reload $warnings_needed If true, detailed warnings collection is provided with the rating obj.
  *
  * @return int An array representing the rating obj.
  */
 public function get_rating_for($post_id, $force_reload = false)
 {
     // If forced reload is required or rating is missing ..
     if ($force_reload) {
         $this->log_service->trace("Force rating reload [ post_id :: {$post_id} ]");
         return $this->set_rating_for($post_id);
     }
     $current_raw_score = get_post_meta($post_id, self::RATING_RAW_SCORE_META_KEY, true);
     if (!is_numeric($current_raw_score)) {
         $this->log_service->trace("Rating missing for [ post_id :: {$post_id} ] [ current_raw_score :: {$current_raw_score} ]");
         return $this->set_rating_for($post_id);
     }
     $current_warnings = get_post_meta($post_id, self::RATING_WARNINGS_META_KEY, true);
     // Finally return score and warnings
     return array('raw_score' => $current_raw_score, 'traffic_light_score' => $this->convert_raw_score_to_traffic_light($current_raw_score), 'percentage_score' => $this->convert_raw_score_to_percentage($current_raw_score), 'warnings' => $current_warnings);
 }
 /**
  * Retrieve timeline events.
  *
  * @since 3.1.0
  *
  * @uses wl_core_get_related_entity_ids() to retrieve the entities referenced by the specified post.
  *
  * @param int $post_id The post ID.
  *
  * @return array An array of event posts.
  */
 public function get_events($post_id = null)
 {
     // Get the entity IDs either from the entities related to the specified post or from the last 50 published
     // posts if no post has been specified.
     $ids = is_numeric($post_id) ? wl_core_get_related_entity_ids($post_id) : $this->entity_service->get_all_related_to_last_50_published_posts();
     // Add the post itself if it's an entity.
     if (is_numeric($post_id) && $this->entity_service->is_entity($post_id)) {
         $ids[] = $post_id;
     }
     // If there's no entities, return an empty array right away.
     if (0 === sizeof($ids)) {
         $this->log_service->trace("No events found [ post id :: {$post_id} ]");
         return array();
     }
     $this->log_service->trace("Getting events [ entity ids :: " . join(', ', $ids) . " ]");
     return get_posts(array('post__in' => $ids, 'post_type' => Wordlift_Entity_Service::TYPE_NAME, 'post_status' => 'publish', 'posts_per_page' => -1, 'meta_query' => array('relation' => 'AND', array('key' => Wordlift_Schema_Service::FIELD_DATE_START, 'value' => null, 'compare' => '!='), array('key' => Wordlift_Schema_Service::FIELD_DATE_END, 'value' => null, 'compare' => '!=')), 'tax_query' => array('taxonomy' => Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, 'field' => 'slug', 'terms' => 'event')));
 }
 /**
  * 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 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;
 }