/**
  * Checks if current post belongs in an excluded taxonimies
  * Returns true iff all post categories are in excluded ones
  * or all post tags are in excluded ones
  *
  * @author Panagiotis Vagenas <*****@*****.**>
  * @since 2.0.0
  */
 public function isInExcludedTaxonomies($post)
 {
     if (is_a($post, 'WP_Post')) {
         $post = $post->ID;
     }
     $exCats = $this->mainOpts->getCategories();
     if (!empty($exCats)) {
         $postCategories = get_the_category($post);
         if (is_array($postCategories) && !empty($postCategories)) {
             $catIds = array();
             foreach ($postCategories as $cat) {
                 array_push($catIds, $cat->term_id);
             }
             $intersect = array_intersect($catIds, $exCats);
             if (!empty($intersect) && count($intersect) == count($postCategories)) {
                 return TRUE;
             }
         }
     }
     $exTags = $this->mainOpts->getTags();
     if (!empty($exTags)) {
         $postTags = get_the_tags($post);
         if (is_array($postTags) && !empty($postTags)) {
             $tagsIds = array();
             foreach ($postTags as $tag) {
                 array_push($tagsIds, (string) $tag->term_id);
             }
             $intersect = array_intersect($tagsIds, $exTags);
             if (!empty($intersect) && count($intersect) == count($postTags)) {
                 return TRUE;
             }
         }
     }
     return FALSE;
 }
Пример #2
0
 /**
  * Front-end display of widget.
  *
  * @see WP_Widget::widget()
  *
  * @param array $args
  *        	Widget arguments.
  * @param array $instance
  *        	Saved values from database.
  * @since 2.0.0
  * @author Panagiotis Vagenas <*****@*****.**>
  */
 public function widget($args, $instance)
 {
     global $post;
     // get instance of main plugin
     $plugin = easyRelatedPosts::get_instance();
     // check if it's time to take action
     if (is_single($post->ID)) {
         if ($plugin->isInExcludedPostTypes($post) || $plugin->isInExcludedTaxonomies($post)) {
             return;
         }
         // Fill missing options
         if (empty($instance)) {
             $instance = erpDefaults::$comOpts + erpDefaults::$widOpts;
         } else {
             $instance = $instance + erpDefaults::$comOpts + erpDefaults::$widOpts;
         }
         erpPaths::requireOnce(erpPaths::$erpRelated);
         erpPaths::requireOnce(erpPaths::$erpMainOpts);
         erpPaths::requireOnce(erpPaths::$erpWidOpts);
         $mainOpts = new erpMainOpts();
         $instance['tags'] = $mainOpts->getTags();
         $instance['categories'] = $mainOpts->getCategories();
         $instance['postTypes'] = $mainOpts->getPostTypes();
         $widOpts = new erpWidOpts($instance);
         // Get related
         $relatedObj = erpRelated::get_instance($widOpts);
         $wpQ = $relatedObj->getRelated($post->ID);
         // If we have some posts to show
         if ($wpQ->have_posts()) {
             // Get template instance for the specific widget number
             erpPaths::requireOnce(erpPaths::$VPluginThemeFactory);
             VPluginThemeFactory::registerThemeInPathRecursive(erpPaths::getAbsPath(erpPaths::$widgetThemesFolder), $instance['dsplLayout']);
             $theme = VPluginThemeFactory::getThemeByName($instance['dsplLayout']);
             if (!$theme) {
                 return $this->displayEmptyWidget($args, $instance);
             }
             $theme->setOptions($instance);
             $theme->formPostData($wpQ, $widOpts, $relatedObj->getRatingsFromRelDataObj());
             $content = $theme->renderW($this->number);
             echo $args['before_widget'];
             echo $args['before_title'] . $instance['title'] . $args['after_title'];
             echo $content;
             echo $args['after_widget'];
         } else {
             // else diplay empty widget
             $this->displayEmptyWidget($args, $instance);
         }
     }
 }