/** * Filters the each project and adds the number of the shares to each network. * @param SocialSharing_Projects_Project $project * @return SocialSharing_Projects_Project */ public function filterAddProjectShares(SocialSharing_Projects_Project $project) { if (count($project->getNetworks()) === 0) { return $project; } $networks = array(); /** @var SocialSharing_Shares_Model_Shares $shares */ $shares = $this->getModelsFactory()->get('shares'); foreach ($project->getNetworks() as $index => $network) { if (!in_array($project->get('shares'), array('plugin', 'project', 'post'), false)) { $network->shares = 0; } elseif ($project->get('shares') === 'plugin') { $network->shares = $shares->getNetworkShares($network->id); } elseif ($project->get('shares') === 'project') { $network->shares = $shares->getProjectNetworkShares($project->getId(), $network->id); } elseif ($project->get('shares') === 'post') { // $postId = !is_home() ? get_the_ID() : null; $schema = is_ssl() ? 'https://' : 'http://'; $currentUrl = strtolower(trailingslashit($schema . $_SERVER['HTTP_HOST'] . '/' . $_SERVER['REQUEST_URI'])); $baseUrl = strtolower(trailingslashit(get_bloginfo('wpurl'))); $postId = $currentUrl === $baseUrl ? null : get_the_ID(); $network->shares = $shares->getProjectPageShares($project->getId(), $network->id, $postId); } else { $network->shares = 0; } $networks[$index] = $network; } $project->setNetworks($networks); return $project; }
/** * Callback method to add project's widget to the widgets list. */ public function applyWidgetCallback() { global $wp_widget_factory; $className = 'SocialSharing_Projects_Widget'; $widget = $className . '_' . $this->project->getId(); $wp_widget_factory->widgets[$widget] = new $className($this); }