예제 #1
0
 public static function extractShortCode(&$content, $beginShortCode, $endShortCode)
 {
     // Find the opening tag
     $begin = TpsMisc::mb_strpos($content, $beginShortCode);
     if ($begin === false) {
         return null;
     }
     // Find the closing tag
     $end = TpsMisc::mb_strpos($content, $endShortCode, $begin);
     if ($end === false) {
         return null;
     }
     // Cache some string lengths
     $lenBegin = TpsMisc::mb_strlen($beginShortCode);
     $lenEnd = TpsMisc::mb_strlen($endShortCode);
     // If the shortcodes are surrounded by header tags, then extract them too. This is a frequent user error due to the way the text editor inserts shortcodes.
     $beginHeadingTag = $endHeadingTag = '';
     if (preg_match('(<h([1-6])>)', TpsMisc::mb_substr($content, $begin - 4, 4), $beginMatches) && preg_match('(</h([1-6])>)', TpsMisc::mb_substr($content, $end + $lenEnd, 5), $endMatches) && $beginMatches[1] === $endMatches[1]) {
         $beginHeadingTag = $beginMatches[0];
         $endHeadingTag = $endMatches[0];
     }
     $shortCode = $beginHeadingTag . trim(TpsMisc::mb_substr($content, $begin + $lenBegin, $end - $begin - $lenBegin)) . $endHeadingTag;
     $content = TpsMisc::mb_substr($content, 0, $begin - TpsMisc::mb_strlen($beginHeadingTag)) . TpsMisc::mb_substr($content, $end + $lenEnd + TpsMisc::mb_strlen($endHeadingTag));
     return $shortCode;
 }
예제 #2
0
 public static function the_content($content)
 {
     if (self::$forceDisable) {
         return $content;
     }
     global $post, $page, $pages, $multipage;
     if (!isset($post) || !property_exists($post, 'theiaPostSlider')) {
         return $content;
     }
     // Prevent this function from calling itself.
     if (self::$theContentIsCalled) {
         return $content;
     }
     self::$theContentIsCalled = true;
     $currentPage = min(max($page, 1), count($pages));
     // Get all slides except the current one, which will be echoed as actual HTML.
     $slides = array();
     for ($i = 1; $i <= count($pages); $i++) {
         $page = $i;
         $slide = array();
         $slide['title'] = self::getPageTitle();
         $slide['permalink'] = self::getPostPageUrl($i);
         if ($i != $currentPage) {
             // Get the content.
             $slideContent = get_the_content();
             // Save the shortcode title, if present.
             $slide['shortCodeTitle'] = TpsShortCodes::extractShortCode($slideContent, TpsMisc::$beginTitleShortCode, TpsMisc::$endTitleShortCode);
             // Apply filters.
             $slideContent = self::$beginComment . $slideContent . self::$endComment;
             $slideContent = apply_filters('the_content', $slideContent);
             $slideContent = str_replace(']]>', ']]&gt;', $slideContent);
             /*
              * Leave only the actual text. Aditional headers or footers will be discarded. Plugins like "video quicktags"
              * will be left intact, while plugins like "related posts thumbnails" and "better author bio" will be discarded.
              */
             $begin = TpsMisc::mb_strpos($slideContent, self::$beginComment);
             $end = TpsMisc::mb_strpos($slideContent, self::$endComment);
             if ($begin !== false && $end !== false) {
                 // Preserve beginning <p> tag.
                 if (TpsMisc::mb_substr($slideContent, $begin - 3, 3) == '<p>') {
                     if (TpsMisc::mb_substr($slideContent, $begin + TpsMisc::mb_strlen(self::$beginComment), 4) == '</p>') {
                         $begin += TpsMisc::mb_strlen(self::$beginComment) + 4;
                     } else {
                         $begin -= 3;
                     }
                 } else {
                     $begin += TpsMisc::mb_strlen(self::$beginComment);
                 }
                 // Preserve ending <p> tag.
                 if (TpsMisc::mb_substr($slideContent, $end + TpsMisc::mb_strlen(self::$endComment), 4) == '</p>') {
                     if (TpsMisc::mb_substr($slideContent, $end - 3, 3) == '<p>') {
                         $end -= 3;
                     } else {
                         $end += TpsMisc::mb_strlen(self::$endComment) + 4;
                     }
                 }
                 // Cut!
                 $slideContent = TpsMisc::mb_substr($slideContent, $begin, $end - $begin);
             }
             // Trim left and right whitespaces.
             $slideContent = trim($slideContent);
             /*
              * Bug fix for WordPress. Sometimes it adds an invalid "</p>" closing tag at the beginning and/or an
              * opening "<p>" tag at the end.
              */
             if (TpsMisc::mb_substr($slideContent, 0, 4) == '</p>') {
                 $slideContent = TpsMisc::mb_substr($slideContent, 4);
             }
             if (TpsMisc::mb_substr($slideContent, -3) == '<p>') {
                 $slideContent = TpsMisc::mb_substr($slideContent, 0, -3);
             }
             $slide['content'] = $slideContent;
         }
         $slides[$i - 1] = $slide;
     }
     $page = $currentPage;
     // Append the slider initialization script to the "theiaPostSlider.js" script.
     if (TpsOptions::get('refresh_page_on_slide') == false && in_array($post->ID, self::$postsWithSlider) == false) {
         $nav = array();
         if (in_array(TpsOptions::get('nav_vertical_position'), array('top_and_bottom', 'top'))) {
             $nav[] = '#' . $post->theiaPostSlider['navIdUpper'];
         }
         if (in_array(TpsOptions::get('nav_vertical_position'), array('top_and_bottom', 'bottom'))) {
             $nav[] = '#' . $post->theiaPostSlider['navIdLower'];
         }
         $sliderOptions = array('src' => '#' . $post->theiaPostSlider['srcId'] . ' > div', 'dest' => '#' . $post->theiaPostSlider['destId'], 'nav' => $nav, 'navText' => TpsOptions::get('navigation_text'), 'helperText' => TpsOptions::get('helper_text'), 'defaultSlide' => $currentPage - 1, 'transitionEffect' => TpsOptions::get('transition_effect'), 'transitionSpeed' => TpsOptions::get('transition_speed'), 'keyboardShortcuts' => self::isCompatiblePost() ? 'true' : 'false', 'slides' => $slides, 'prevPost' => $post->theiaPostSlider['prevPostUrl'], 'nextPost' => $post->theiaPostSlider['nextPostUrl'], 'prevText' => TpsOptions::get('prev_text'), 'nextText' => TpsOptions::get('next_text'), 'buttonWidth' => TpsOptions::get('button_width'), 'prevText_post' => TpsOptions::get('prev_text_post'), 'nextText_post' => TpsOptions::get('next_text_post'), 'buttonWidth_post' => TpsOptions::get('button_width_post'), 'postUrl' => get_permalink($post->ID));
         $script = "\r\n                jQuery(document).ready(function() {\r\n                    var p = new tps.createSlideshow(" . json_encode($sliderOptions) . ");\r\n                });\r\n            ";
         global $wp_scripts;
         $data = $wp_scripts->get_data('theiaPostSlider.js', 'data');
         if ($data) {
             $script = "{$data}\n{$script}";
         }
         $wp_scripts->add_data('theiaPostSlider.js', 'data', $script);
         self::$postsWithSlider[] = $post->ID;
     }
     // Return the unchanged content.
     self::$theContentIsCalled = false;
     return $content;
 }