public function display($pid)
 {
     if (!isset($this->optObj)) {
         if (!$this->loadProfileOptions()) {
             return '';
         }
     }
     erpPROPaths::requireOnce(erpPROPaths::$erpPROTheme);
     if (!is_int($pid) || erpPROTheme::areOthersSuppressed()) {
         $this->setSuppressOthers();
         return '';
     }
     erpPROPaths::requireOnce(erpPROPaths::$VPluginThemeFactory);
     erpPROPaths::requireOnce(erpPROPaths::$erpProRelated);
     $relatedObj = erpProRelated::get_instance($this->optObj);
     $result = $relatedObj->getRelated($pid);
     $ratings = $relatedObj->getRatingsFromRelDataObj();
     if (empty($result) || empty($result->posts)) {
         return '';
     }
     VPluginThemeFactory::registerThemeInPathRecursive(erpPROPaths::getAbsPath(erpPROPaths::$scThemesFolder), $this->optObj->getDsplLayout());
     $theme = VPluginThemeFactory::getThemeByName($this->optObj->getDsplLayout(), 'shortcode');
     if (!$theme) {
         return '';
     }
     $theme->setOptions($this->optObj->getOptions());
     $theme->formPostData($result, $this->optObj, $ratings);
     $relContent = $theme->render();
     $this->setSuppressOthers();
     return $relContent;
 }
 /**
  * Return an instance of this class.
  *
  * @since 1.0.0
  * @return erpProRelated A single instance of this class.
  */
 public static function get_instance(&$options)
 {
     // If the single instance hasn't been set, set it now.
     if (null == self::$instance) {
         self::$instance = new self($options);
     }
     self::$instance->options = $options;
     return self::$instance;
 }
 /**
  * Front-end display of widget.
  *
  * @see WP_Widget::widget()
  *
  * @param array $args
  *        	Widget arguments.
  * @param array $instance
  *        	Saved values from database.
  * @since 1.0.0
  * @author Panagiotis Vagenas <*****@*****.**>
  */
 public function widget($args, $instance)
 {
     global $post;
     // get instance of main plugin
     $plugin = easyRelatedPostsPRO::get_instance();
     // check if it's time to take action
     if (!is_single($post->ID)) {
         return;
     }
     if ($plugin->isInExcludedPostTypes($post) || $plugin->isInExcludedTaxonomies($post)) {
         return;
     }
     // Fill missing options
     if (empty($instance)) {
         $instance = erpPRODefaults::$comOpts + erpPRODefaults::$widOpts;
     } else {
         $instance = $instance + erpPRODefaults::$comOpts + erpPRODefaults::$widOpts;
     }
     erpPROPaths::requireOnce(erpPROPaths::$erpProRelated);
     erpPROPaths::requireOnce(erpPROPaths::$erpPROMainOpts);
     erpPROPaths::requireOnce(erpPROPaths::$erpPROWidOpts);
     $mainOpts = new erpPROMainOpts();
     $instance['tags'] = $mainOpts->getTags();
     $instance['categories'] = $mainOpts->getCategories();
     $instance['postTypes'] = $mainOpts->getPostTypes();
     $widOpts = new erpPROWidOpts($instance);
     // Get related
     $relatedObj = erpProRelated::get_instance($widOpts);
     $wpQ = $relatedObj->getRelated($post->ID);
     // If we have some posts to show
     if (!$wpQ->have_posts()) {
         $this->displayEmptyWidget($args, $instance);
     }
     erpPROPaths::requireOnce(erpPROPaths::$VPluginThemeFactory);
     VPluginThemeFactory::registerThemeInPathRecursive(erpPROPaths::getAbsPath(erpPROPaths::$widgetThemesFolder), $instance['dsplLayout']);
     $theme = VPluginThemeFactory::getThemeByName($instance['dsplLayout'], 'widget');
     if (!$theme) {
         return $this->displayEmptyWidget($args, $instance);
     }
     $theme->setOptions($instance);
     $theme->formPostData($wpQ, $widOpts, $relatedObj->getRatingsFromRelDataObj());
     $content = $theme->renderW($this->number);
     // display rel content
     echo $args['before_widget'];
     echo $args['before_title'] . $instance['title'] . $args['after_title'];
     echo $content;
     echo $args['after_widget'];
 }
 /**
  * This is for a future release.
  * It should be called through ajax and rebuild cache for all posts in that are cached
  * 
  * @author Panagiotis Vagenas <*****@*****.**>
  * @since 1.0.0
  */
 public function rebuildCache()
 {
     if (!user_can_access_admin_page() || !current_user_can('manage_options')) {
         echo json_encode(false);
         die;
     }
     // This may take a while so set time limit to 0
     set_time_limit(0);
     erpPROPaths::requireOnce(erpPROPaths::$erpPRODBActions);
     erpPROPaths::requireOnce(erpPROPaths::$erpPROMainOpts);
     erpPROPaths::requireOnce(erpPROPaths::$erpProRelated);
     $db = erpPRODBActions::getInstance();
     $mainOpts = new erpPROMainOpts();
     $rel = erpProRelated::get_instance($mainOpts);
     $allCached = $db->getUniqueIds();
     $db->emptyRelTable();
     $plugin = easyRelatedPostsPRO::get_instance();
     global $wpdb, $wp_actions;
     foreach ($allCached as $key => $value) {
         $pid = (int) $value['pid'];
         if ($plugin->isInExcludedPostTypes($pid) || $plugin->isInExcludedTaxonomies($pid)) {
             continue;
         }
         $rel->doRating($pid);
     }
     echo json_encode(true);
     die;
 }
 /**
  * Decides if content should be modified, if yes calls content modifier
  *
  * @param string $content
  * @return string
  * @author Panagiotis Vagenas <*****@*****.**>
  * @since 1.0.0
  */
 public function contentFilter($content)
 {
     global $post;
     /**
      * Check if is time to take action
      */
     if ($this->isShowTime($post) && !$this->isInExcludedPostTypes($post) && !$this->isInExcludedTaxonomies($post) && (bool) $this->mainOpts->getValue('activate')) {
         erpPROPaths::requireOnce(erpPROPaths::$erpPROTheme);
         if (erpPROTheme::areOthersSuppressed()) {
             return $content;
         }
         erpPROPaths::requireOnce(erpPROPaths::$VPluginThemeFactory);
         erpPROPaths::requireOnce(erpPROPaths::$erpProRelated);
         $relatedObj = erpProRelated::get_instance($this->mainOpts);
         $result = $relatedObj->getRelated($post->ID);
         $ratings = $relatedObj->getRatingsFromRelDataObj();
         if (empty($result) || empty($result->posts)) {
             return $content;
         }
         VPluginThemeFactory::registerThemeInPathRecursive(erpPROPaths::getAbsPath(erpPROPaths::$mainThemesFolder), $this->mainOpts->getDsplLayout());
         $theme = VPluginThemeFactory::getThemeByName($this->mainOpts->getDsplLayout(), 'main');
         if (!$theme) {
             return $content;
         }
         $theme->formPostData($result, $this->mainOpts, $ratings);
         $relContent = $theme->render();
         return $this->mainOpts->getPosition() == 'top' ? $relContent . $content : $content . $relContent;
     }
     return $content;
 }