false, "full" => false), $noindexClassName = 'sharexyWidgetNoindexUniqueClassName', $priority = 16, $defaultPriority = 10, $placeIds, $dataScripts; function SharexyWidget() { $this->parentInit(); $this->dataScripts = array(); $this->placeIds = array(); } function setErrorObject($errorReporter) { $this->errorReporter = $errorReporter; } function loadWidget() { add_filter('get_the_excerpt', array(&$this, 'displayWidgetExcerpt'), $this->priority); add_filter('the_content', array(&$this, 'displayWidget'), $this->priority); add_action('wp_footer', array(&$this, 'displayFloatWidget'), $this->priority); add_action('wp_footer', array(&$this, 'dataScriptsLoader'), $this->priority + 1); add_action('wp_footer', array(&$this, 'footLoader'), $this->priority + 2); } function displayWidgetExcerpt($content = '') { return has_excerpt() ? $this->displayWidget($content) : $content; } function removeTag($content, $text = '') { if ($text !== '') { return $content; } $text = get_the_content(''); $text = strip_shortcodes( $text ); remove_filter('the_content', array(&$this, 'displayWidget'), $this->defaultPriority - 1); $text = apply_filters('the_content', $text); add_filter('the_content', array(&$this, 'displayWidget'), $this->defaultPriority + 1); $text = str_replace(']]>', ']]>', $text); $text = strip_tags($text); $excerpt_length = apply_filters('excerpt_length', 55); $excerpt_more = apply_filters('excerpt_more', ' ' . '[...]'); $words = preg_split("/[\n\r\t ]+/", $text, $excerpt_length + 1, PREG_SPLIT_NO_EMPTY); if ( count($words) > $excerpt_length ) { array_pop($words); $text = implode(' ', $words); $text = $text . $excerpt_more; } else { $text = implode(' ', $words); } return $this->displayWidget($text, false); } function displayWidget($content = '', $filtered = true) { $pageHTML = ''; remove_filter('wp_trim_excerpt', array(&$this, 'removeTag'), $this->defaultPriority - 1, 2); $placements = $this->getPlacements(); $mainStyle = $this->getStyle(); $pageHTML .= $this->getPlaceCode('top', $placements, $mainStyle); $pageHTML .= $this->getPlaceCode('top_post', $placements, $mainStyle); $pageHTML .= $content; $pageHTML .= $this->getPlaceCode('bottom', $placements, $mainStyle); $pageHTML .= $this->getPlaceCode('bottom_post', $placements, $mainStyle); if ($filtered === true) { add_filter('wp_trim_excerpt', array(&$this, 'removeTag'), $this->priority, 2); } return $pageHTML; } function displayFloatWidget() { $placements = $this->getPlacements(); $mainStyle = $this->getStyle(); echo $this->getPlaceCode('float', $placements, $mainStyle); } function getPlaceCode($place, &$placements, &$mainStyle) { $pageHTML = ''; if (!isset($placements[$place]) || !is_array($placements[$place]) || !isset($placements[$place]['display']) || $placements[$place]['display'] !== 1) { return $pageHTML; } $customLink = false; $customTitle = false; $placeParams = $placements[$place]; $show = false; if ( is_home() && !is_paged() && isset($placeParams['pages_mode']['front']) && $placeParams['pages_mode']['front'] === 1 ) { $customLink = get_permalink(); $customTitle = get_the_title(); $show = true; } elseif ( (!is_home() || is_paged()) && !is_single() && !is_page() && isset($placeParams['pages_mode']['page']) && $placeParams['pages_mode']['page'] === 1 ) { $customLink = get_permalink(); $customTitle = get_the_title(); $show = true; } elseif ( (is_single() || is_page()) && isset($placeParams['pages_mode']['post']) && $placeParams['pages_mode']['post'] === 1 ) { $show = true; } if (!$show) { return $pageHTML; } $placeStyle = $this->getPlacementsStyleParams($place); $mixStyle = $this->mixMainPlaceStyleParams($mainStyle, $placeStyle); if ($customLink && $customTitle && $place !== 'float') { $mixStyle['customLink'] = $customLink; $mixStyle['customTitle'] = $customTitle; } return $this->getSharexyCodeHTML($place, $mixStyle, $placeParams); } function getSharexyCodeHTML($place, $styleParams, $placeParams) { global $post; $key = isset($post) && $post && isset($post->ID) ? md5($place . $post->ID) : md5($place); $debugInfo = isset($post) && $post && isset($post->ID) ? $place . " " . $post->ID : $place; $this->placeIds[$key] = isset($this->placeIds[$key]) ? $this->placeIds[$key] : rand(999999, 99999999); $code_id = $this->placeIds[$key]; $this->codeType['lite'] = isset($styleParams['user_id']) && $this->validateWebmasterId($styleParams['user_id'])? false : true; $this->codeType['full'] = isset($styleParams['user_id']) && $this->validateWebmasterId($styleParams['user_id']) ? true : false; $styleParams['publisher_key'] = isset($styleParams['user_id']) ? $this->validateWebmasterId($styleParams['user_id']) : 0; $styleParams['code_id'] = $code_id; $styleParams['d'] = $debugInfo; $align = isset($placeParams['align']) ? $placeParams['align'] : ""; $this->dataScripts[$code_id] = $styleParams; return '
'; } function dataScriptsLoader() { if (is_array($this->dataScripts) && !empty($this->dataScripts)) { $script = <</* dataScripts as $id => $styleParams) { if (function_exists('json_encode')) { $params = json_encode($styleParams); } else { $json = new SharexyJson(); $params = $json->encode($styleParams); } $script .= "w.SharexyWidget.Params['shr_{$id}'] = {$params};\n"; } $script .= "})(window); /* ]]> */ "; echo $script; } } function footLoader() { if ($this->codeType['full'] === true || $this->codeType['lite'] === true) { echo <</* noindexClassName}').each(function (n, element) { var content = jQuery(element).html(); jQuery(element).html('' + content + ''); }); })(window); /* ]]> */ EOF; } if ($this->codeType['full'] === true) { echo ''; } elseif ($this->codeType['lite'] === true) { echo ''; } } }