addThisConfigs = $addThisConfigs; $this->cmsConnector = $cmsConnector; add_filter('the_content', array($this, 'addWidget')); add_filter('get_the_excerpt', array($this, 'addWidgetForExcerpt')); } /** * Adds toolbox to excerpts wp pages -- can't use addWidget straight out * because when the filter on get_the_excerpt is added, it doesn't yet know * if it has an excerpt or not * * @param string $content Page contents * @return string Page content with our sharing button HTML added */ public function addWidgetForExcerpt($content){ if (has_excerpt() || !is_single()) { $content = $this->addWidget($content); } return $content; } /** * Adds toolbox to wp pages * * @param string $content Page contents * * @return string */ public function addWidget($content) { $configs = $this->addThisConfigs->getConfigs(); if ($this->addThisConfigs->getProfileId() && !is_404() && !is_feed()) { global $post; $postid = $post->ID; $metaBoxFlag = get_post_meta($postid, '_at_widget', TRUE); if (!$configs['addthis_per_post_enabled'] || $metaBoxFlag == '' || $metaBoxFlag == '1' ) { $metaBoxFlag = true; } else { $metaBoxFlag = false; } if ($metaBoxFlag) { $recommendedContent = false; $htmlComments = array(); $htmlCommentLocations = array('above', 'below'); foreach ($htmlCommentLocations as $location) { $htmlComments[$location] = array(); $search = 'AddThis Sharing Buttons '.$location; $comment = ''; $htmlComments[$location]['search'] = $search; $htmlComments[$location]['comment'] = $comment; } if (is_home() || is_front_page()) { $aboveDivClass = self::AT_ABOVE_POST_HOME; $belowDivClass = self::AT_BELOW_POST_HOME; } else if (is_page()) { $aboveDivClass = self::AT_ABOVE_POST_PAGE; $belowDivClass = self::AT_BELOW_POST_PAGE; } else if (is_single()) { $aboveDivClass = self::AT_ABOVE_POST; $belowDivClass = self::AT_BELOW_POST; $recommendedContent = true; } else if (is_category()) { $aboveDivClass = self::AT_ABOVE_POST_CAT_PAGE; $belowDivClass = self::AT_BELOW_POST_CAT_PAGE; } else if (is_archive()) { $aboveDivClass = self::AT_ABOVE_POST_ARCH_PAGE; $belowDivClass = self::AT_BELOW_POST_ARCH_PAGE; } if (isset($aboveDivClass) && strpos($content, $htmlComments['above']['search']) === false ) { $content = $htmlComments['above']['comment'] . self::_buildDiv($aboveDivClass) . $content; } if (isset($belowDivClass) && strpos($content, $htmlComments['below']['search']) === false ) { $content .= $htmlComments['below']['comment']; $content .= self::_buildDiv($belowDivClass); } if ($recommendedContent && strpos($inputHtml, 'AddThis Recommended Content below') === false ) { $content .= ' ' ; $content .= self::_buildDiv(self::AT_CONTENT_BELOW_POST, false); } } } return $content; } /** * Build toolbox div * * @param string $class Class name * * @return string */ private static function _buildDiv($class, $inline_data = true) { $title = get_the_title(); $url = get_permalink(); if($inline_data == true){ return "
". "
"; } else { return "
"; } } /** * Get user's activated tools in addthis * * @return array */ public static function getUserTools() { $curl = curl_init(); $url = AT_API_URL . '?pub='. $this->addThisConfigs->getProfileId(); $url .= '&dp=' . Addthis_Wordpress::getDomain(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($curl); curl_close($curl); $response = json_decode($response); $activatedTools = null; if ($response) { foreach ($response as $key => $value) { if ($key == 'pc') { $activatedTools = $value; break; } } } return $activatedTools ? explode(',', $activatedTools) : array(); } }