addThisConfigs = $addThisConfigs; $this->cmsConnector = $cmsConnector; add_filter('the_content', array($this, 'addWidget')); if ( has_excerpt()) { add_filter('the_excerpt', array($this, 'addWidget')); } } /** * Adds toolbox to wp pages * * @param string $content Page contents * * @return string */ public function addWidget($content) { if ($this->addThisConfigs->getProfileId() && !is_404() && !is_feed()) { global $post; $postid = $post->ID; $at_flag = get_post_meta( $postid, '_at_widget', TRUE ); if (is_home() || is_front_page()) { if($at_flag == '' || $at_flag == '1'){ $content = self::_buildDiv(self::AT_ABOVE_POST_HOME) . self::_buildDiv(self::AT_CONTENT_ABOVE_POST_HOME) . $content; $content .= self::_buildDiv(self::AT_BELOW_POST_HOME); $content .= self::_buildDiv(self::AT_CONTENT_BELOW_POST_HOME); } } else if (is_page()) { if($at_flag == '' || $at_flag == '1'){ $content = self::_buildDiv(self::AT_ABOVE_POST_PAGE) . self::_buildDiv(self::AT_CONTENT_ABOVE_POST_PAGE) . $content; $content .= self::_buildDiv(self::AT_BELOW_POST_PAGE); $content .= self::_buildDiv(self::AT_CONTENT_BELOW_POST_PAGE); } } else if (is_single()) { if($at_flag == '' || $at_flag == '1'){ $content = self::_buildDiv(self::AT_ABOVE_POST) . self::_buildDiv(self::AT_CONTENT_ABOVE_POST, false) . $content; $content .= self::_buildDiv(self::AT_BELOW_POST); $content .= self::_buildDiv(self::AT_CONTENT_BELOW_POST, false); } } else if (is_category()) { if($at_flag == '' || $at_flag == '1'){ $content = self::_buildDiv(self::AT_ABOVE_POST_CAT_PAGE) . self::_buildDiv(self::AT_CONTENT_ABOVE_CAT_PAGE) . $content; $content .= self::_buildDiv(self::AT_BELOW_POST_CAT_PAGE); $content .= self::_buildDiv(self::AT_CONTENT_BELOW_CAT_PAGE); } } else if (is_archive()) { if($at_flag == '' || $at_flag == '1'){ $content = self::_buildDiv(self::AT_ABOVE_POST_ARCH_PAGE) . self::_buildDiv(self::AT_CONTENT_ABOVE_ARCH_PAGE) . $content; $content .= self::_buildDiv(self::AT_BELOW_POST_ARCH_PAGE); $content .= self::_buildDiv(self::AT_CONTENT_BELOW_ARCH_PAGE); } } } 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(); } }