コード例 #1
0
    /**
     * 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;
    }
コード例 #2
0
 /**
  * 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);
 }
コード例 #3
0
 /**
  * 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')));
 }