Exemplo n.º 1
0
 public static function get_option($option_name, $default_data = null, $configs = false)
 {
     if (!$configs) {
         $configs = array();
     }
     $k = Utils::hashKey(array('WPOptimizeByxTraffic_WpOptions_get_option', $option_name, $default_data));
     if (isset($configs['cache_status']) && $configs['cache_status']) {
         if (isset(self::$_tempData[$k])) {
             return self::$_tempData[$k];
         } else {
             $tmp = PepVN_Data::$cacheObject->get_cache($k);
             if ($tmp !== null) {
                 self::$_tempData[$k] = $tmp;
                 return self::$_tempData[$k];
             }
         }
     }
     $maximumLengthOptionName = 64 - strlen(self::$_prefix);
     if (strlen($option_name) > $maximumLengthOptionName) {
         throw new Exception('Option\'s name is too long. Maximum length is "' . $maximumLengthOptionName . ' characters".');
     }
     self::$_tempData[$k] = get_option(self::$_prefix . $option_name, $default_data);
     if (isset($configs['cache_status']) && $configs['cache_status']) {
         PepVN_Data::$cacheObject->set_cache($k, self::$_tempData[$k]);
     }
     return self::$_tempData[$k];
 }
Exemplo n.º 2
0
 public function fix($options = false)
 {
     if (!$options) {
         $options = array();
     }
     if (!isset($options['minify_status'])) {
         $options['minify_status'] = false;
     }
     $keyCache = Utils::hashKey(array(__CLASS__, __METHOD__, $options));
     $tmp = PepVN_Data::$cacheObject->get_cache($keyCache);
     if (null !== $tmp) {
         return $tmp;
     }
     if (isset($options['css_url'])) {
         $this->css_url = $options['css_url'];
     }
     $options['css_content'] = (array) $options['css_content'];
     $options['css_content'] = implode(PHP_EOL, $options['css_content']);
     if ($options['minify_status']) {
         $options['css_content'] = $this->minify($options['css_content']);
     }
     $options['css_content'] = $this->fixPathsInCssContent($options['css_content']);
     $options['css_content'] = $this->fixRules($options['css_content']);
     PepVN_Data::$cacheObject->set_cache($keyCache, $options['css_content']);
     return trim($options['css_content']);
 }
Exemplo n.º 3
0
 public function newDIID()
 {
     $newDIID = Utils::hashKey(Utils::randomHash());
     $this->_DIID = $newDIID;
     DIStore::$instances[$newDIID] = $this;
     return DIStore::$instances[$newDIID];
 }
Exemplo n.º 4
0
 public function __construct()
 {
     if (function_exists('igbinary_serialize')) {
         $this->_has_igbinary_status = true;
     }
     $bag = Utils::randomHash();
     $this->_bag = crc32($bag);
 }
Exemplo n.º 5
0
 public function save($data, $method = 'm', $keyCachePlus = '')
 {
     if ('m' === $method) {
         $data = Utils::mergeArrays(array($this->get($keyCachePlus), $data));
     }
     $this->_cacheObject->set_cache($this->_key . $keyCachePlus, $data);
     return true;
 }
Exemplo n.º 6
0
 public function add_notice($text, $type, $options = array())
 {
     $text = trim($text);
     if ($text) {
         $bag = $this->_bag;
         $key = Utils::hashKey(array($bag, $text, $type, $options));
         self::$_notices[$this->_bag][$key] = array('text' => $text, 'type' => $type, 'options' => $options);
         if (!isset(self::$_statistics[$bag]['type'][$type])) {
             self::$_statistics[$bag]['type'][$type] = 0;
         }
         self::$_statistics[$bag]['type'][$type]++;
     }
 }
Exemplo n.º 7
0
 public static function set_cache($keyCache, $data, $useCachePermanentStatus = false)
 {
     $keyCache = Utils::hashKey(array(self::$_key_salt, $keyCache));
     if (is_object($data)) {
         $data = clone $data;
     }
     self::$_tempData[$keyCache] = $data;
     if (false === $useCachePermanentStatus) {
         PepVN_Data::$cacheObject->set_cache($keyCache, $data);
     } else {
         PepVN_Data::$cachePermanentObject->set_cache($keyCache, $data);
     }
     return true;
 }
Exemplo n.º 8
0
function pepvn_MinifyHtml($input_data)
{
    $input_data = (array) $input_data;
    $input_data = implode(PHP_EOL, $input_data);
    $input_data = (string) $input_data;
    $input_data = trim($input_data);
    $keyCache1 = Utils::hashKey(array('pepvn_MinifyHtml', $input_data));
    $tmp = PepVN_Data::$cachePermanentObject->get_cache($keyCache1);
    if (null !== $tmp) {
        return $tmp;
    }
    $findAndReplace1 = array();
    $rsOne = PepVN_Data::escapeHtmlTagsAndContents($input_data, 'pre;code;textarea;input');
    $input_data = $rsOne['content'];
    unset($rsOne['content']);
    if (!empty($rsOne['patterns'])) {
        $findAndReplace1 = array_merge($findAndReplace1, $rsOne['patterns']);
    }
    unset($rsOne);
    $input_data = Minify_HTML::minify($input_data, array('jsCleanComments' => true, 'cssMinifier' => 'pepvn_MinifyCss', 'jsMinifier' => 'pepvn_MinifyJavascript'));
    $findAndReplace2 = array();
    preg_match_all('#<(script|style)[^><]*?>.*?</\\1>#is', $input_data, $matched1);
    if (!empty($matched1[0])) {
        $matched1 = $matched1[0];
        foreach ($matched1 as $key1 => $value1) {
            unset($matched1[$key1]);
            $findAndReplace2[$value1] = '__' . hash('crc32b', md5($value1)) . '__';
        }
    }
    $matched1 = 0;
    if (!empty($findAndReplace2)) {
        $input_data = str_replace(array_keys($findAndReplace2), array_values($findAndReplace2), $input_data);
        $findAndReplace1 = array_merge($findAndReplace1, $findAndReplace2);
        unset($findAndReplace2);
    }
    $patterns1 = array('#>[\\s \\t]+<#is' => '><', '#[\\s \\t]+#is' => ' ');
    $input_data = preg_replace(array_keys($patterns1), array_values($patterns1), $input_data);
    if (!empty($findAndReplace1)) {
        $input_data = str_replace(array_values($findAndReplace1), array_keys($findAndReplace1), $input_data);
        unset($findAndReplace1);
    }
    $input_data = trim($input_data);
    PepVN_Data::$cachePermanentObject->set_cache($keyCache1, $input_data);
    return $input_data;
}
Exemplo n.º 9
0
 public function run()
 {
     $wpExtend = $this->di->getShared('wpExtend');
     $hook = $this->di->getShared('hook');
     $resultData = array('status' => 1);
     $dataSent = PepVN_Data::getDataSent();
     if ($dataSent && isset($dataSent['localTimeSent']) && $dataSent['localTimeSent']) {
         if (isset($dataSent['preview_optimize_traffic_modules']) && $dataSent['preview_optimize_traffic_modules']) {
             if ($wpExtend->is_admin()) {
                 if ($wpExtend->isCurrentUserCanManagePlugin()) {
                     $optimizeTraffic = $this->di->getShared('optimizeTraffic');
                     $rsOne = $optimizeTraffic->preview_optimize_traffic_modules($dataSent);
                     $resultData = Utils::mergeArrays(array($resultData, $rsOne));
                     unset($rsOne);
                 }
             }
         }
     }
     if ($hook->has_filter('ajax')) {
         $rsOne = $hook->apply_filters('ajax', $dataSent);
         if (is_array($rsOne)) {
             $resultData = Utils::mergeArrays(array($resultData, $rsOne));
         }
         unset($rsOne);
     }
     if (isset($dataSent['cronjob']['status']) && $dataSent['cronjob']['status']) {
         $cronjob = new ServiceCronjob($this->di);
         $cronjob->run();
     }
     if (isset($resultData['notice']['success']) && $resultData['notice']['success'] && is_array($resultData['notice']['success'])) {
         $resultData['notice']['success'] = array_unique($resultData['notice']['success']);
     }
     if (isset($resultData['notice']['error']) && $resultData['notice']['error'] && is_array($resultData['notice']['error'])) {
         $resultData['notice']['error'] = array_unique($resultData['notice']['error']);
     }
     PepVN_Data::encodeResponseData($resultData, true);
     unset($resultData);
     ob_end_flush();
     exit;
 }
Exemplo n.º 10
0
    public static function parse_load_html_scripts_by_tag($input_parameters)
    {
        $resultData = '';
        if (isset($input_parameters['url']) || isset($input_parameters['code'])) {
            if (isset($input_parameters['url'])) {
                $input_parameters['url'] = self::removeProtocolUrl($input_parameters['url']);
                if (!isset($input_parameters['id'])) {
                    $input_parameters['id'] = Hash::crc32b($input_parameters['url']);
                }
            } else {
                if (isset($input_parameters['code'])) {
                    if (!isset($input_parameters['id'])) {
                        $input_parameters['id'] = Hash::crc32b(md5($input_parameters['code']));
                    }
                }
            }
            $loaderId = Hash::crc32b($input_parameters['id'] . '_loader');
            $loadTimeDelay = 5;
            if ('js' === $input_parameters['type']) {
                $loadTimeDelay = 5;
            } else {
                if (!isset($input_parameters['media'])) {
                    $input_parameters['media'] = 'all';
                }
            }
            $loadTimeDelay = (int) $loadTimeDelay;
            if ($loadTimeDelay < 1) {
                $loadTimeDelay = 1;
            }
            if ('js' === $input_parameters['load_by']) {
                if ('js' === $input_parameters['type']) {
                    $resultData = ' <script data-cfasync="false" language="javascript" type="text/javascript" id="' . $loaderId . '" defer async>
/*<![CDATA[*/
setTimeout(function() {
(function(e) { var t, n, r, s, i = "' . $input_parameters['id'] . '"; if(e.getElementById(i)) { return 0; } t = document.location.protocol; if(-1 !== t.indexOf("https")) { n = "https:"; } else { n = "http:"; } r = e.createElement("script"); r.setAttribute("data-cfasync","false"); r.id = i; r.setAttribute("language","javascript"); r.setAttribute("type","text/javascript"); r.async = true; r.src = n + "//' . $input_parameters['url'] . '"; s = e.getElementById("' . $loaderId . '"); s.parentNode.insertBefore(r, s); s.parentNode.removeChild(s); })(document);
}, ' . $loadTimeDelay . ');
/*]]>*/
</script> ';
                } else {
                    if ('css' === $input_parameters['type']) {
                        if (!isset($input_parameters['append_to'])) {
                            $input_parameters['append_to'] = 'head';
                        }
                        if ('head' === $input_parameters['append_to']) {
                            $resultData = ' <script language="javascript" type="text/javascript" id="' . $loaderId . '" defer async>
/*<![CDATA[*/
setTimeout(function() {
(function(e) { var t, n, r, s, hd = document.getElementsByTagName("head")[0], i = "' . $input_parameters['id'] . '"; if(e.getElementById(i)) { return 0; } t = document.location.protocol; if(-1 !== t.indexOf("https")) { n = "https:"; } else { n = "http:"; } r = e.createElement("link"); r.id = i; r.setAttribute("rel","stylesheet"); r.setAttribute("type","text/css"); r.setAttribute("media","' . $input_parameters['media'] . '"); r.async = true; r.href = n + "//' . $input_parameters['url'] . '"; hd.appendChild(r); s = e.getElementById("' . $loaderId . '"); s.parentNode.removeChild(s); })(document);
}, ' . (1 * $loadTimeDelay + 2) . ');
/*]]>*/
</script> ';
                        } else {
                            $resultData = ' <script language="javascript" type="text/javascript" id="' . $loaderId . '">
/*<![CDATA[*/
setTimeout(function() {
(function(e) { var t, n, r, s, i = "' . $input_parameters['id'] . '"; if(e.getElementById(i)) { return 0; } t = document.location.protocol; if(-1 !== t.indexOf("https")) { n = "https:"; } else { n = "http:"; } r = e.createElement("link"); r.id = i; r.setAttribute("rel","stylesheet"); r.setAttribute("type","text/css"); r.setAttribute("media","' . $input_parameters['media'] . '"); r.async = true; r.href = n + "//' . $input_parameters['url'] . '"; s = e.getElementById("' . $loaderId . '"); s.parentNode.insertBefore(r, s); s.parentNode.removeChild(s); })(document);
}, ' . $loadTimeDelay . ');
/*]]>*/
</script> ';
                        }
                    }
                }
            } else {
                if ('div_tag' === $input_parameters['load_by'] || 'js_data' === $input_parameters['load_by']) {
                    $configs = array('delay' => $loadTimeDelay, 'loader_id' => $loaderId, 'id' => $input_parameters['id'], 'type' => $input_parameters['type']);
                    if (isset($input_parameters['url'])) {
                        $configs['url'] = $input_parameters['url'];
                    } else {
                        if (isset($input_parameters['code'])) {
                            $configs['code'] = $input_parameters['code'];
                        }
                    }
                    if (isset($input_parameters['media'])) {
                        $configs['media'] = $input_parameters['media'];
                    }
                    if ('div_tag' === $input_parameters['load_by']) {
                        $resultData = ' <div class="wp-optimize-speed-by-xtraffic-loader-data-' . $input_parameters['type'] . '" id="' . $loaderId . '" data-pepvn-configs="' . Utils::encodeVar($configs) . '" style="display:none;"></div> ';
                    } else {
                        if ('js_data' === $input_parameters['load_by']) {
                            $keyStoreJs = 'window.wppepvnloaderdata' . $input_parameters['type'];
                            $resultData = ' <script language="javascript" type="text/javascript" id="' . $loaderId . '">
if(typeof(' . $keyStoreJs . ') === "undefined") { ' . $keyStoreJs . ' = new Array(); }
' . $keyStoreJs . '.push("' . Utils::encodeVar($configs) . '");
</script> ';
                        }
                    }
                }
            }
        }
        return $resultData;
    }
Exemplo n.º 11
0
 public static function analysisKeyword_GetKeywordsFromText($input_parameters)
 {
     //ini_set('max_execution_time', 10);
     $inputExplodedContents = false;
     $resultAnalysis = false;
     $common = array();
     $checkStatusOne = false;
     $keyCache1 = Utils::hashKey(array(__CLASS__ . __METHOD__, $input_parameters));
     $resultData = TempDataAndCacheFile::get_cache($keyCache1);
     if (null === $resultData) {
         $resultData = array();
         $resultData['data'] = false;
         if (isset($input_parameters['contents'])) {
             $input_parameters['contents'] = (array) $input_parameters['contents'];
             $input_parameters['contents'] = implode(' ', $input_parameters['contents']);
             $input_parameters['contents'] = trim($input_parameters['contents']);
             if ($input_parameters['contents']) {
                 $inputExplodedContents = self::analysisKeyword_PrepareContents($input_parameters['contents']);
                 if ($inputExplodedContents) {
                     $inputExplodedContents = explode(' ', $inputExplodedContents);
                     unset($input_parameters['contents']);
                     $checkStatusOne = true;
                 }
             }
         }
         if ($checkStatusOne) {
             $inputMinWord = 0;
             $inputMaxWord = 0;
             $inputMinOccur = 0;
             $inputMinCharEachWord = 0;
             if (isset($input_parameters['min_word']) && $input_parameters['min_word']) {
                 $inputMinWord = $input_parameters['min_word'];
             }
             if (isset($input_parameters['max_word']) && $input_parameters['max_word']) {
                 $inputMaxWord = $input_parameters['max_word'];
             }
             if (isset($input_parameters['min_occur']) && $input_parameters['min_occur']) {
                 $inputMinOccur = $input_parameters['min_occur'];
             }
             if (isset($input_parameters['min_char_each_word']) && $input_parameters['min_char_each_word']) {
                 $inputMinCharEachWord = $input_parameters['min_char_each_word'];
             }
             $inputMinWord = (int) $inputMinWord;
             $inputMaxWord = (int) $inputMaxWord;
             $inputMinOccur = (int) $inputMinOccur;
             $inputMinCharEachWord = (int) $inputMinCharEachWord;
             if (!$inputMinWord) {
                 $inputMinWord = 1;
                 //min word each keyword
             }
             if (!$inputMaxWord) {
                 $inputMaxWord = 3;
                 //max word each keyword
             }
             if (!$inputMinOccur) {
                 $inputMinOccur = 2;
                 //number appear
             }
             if (!$inputMinCharEachWord) {
                 $inputMinCharEachWord = 3;
                 // min char each word
             }
             if ($inputMinWord > $inputMaxWord) {
                 $inputMinWord = $inputMaxWord;
             }
         }
         if ($checkStatusOne) {
             $countExplodedContents = count($inputExplodedContents);
             for ($iOne = 0; $iOne < $countExplodedContents; ++$iOne) {
                 for ($iTwo = $inputMinWord; $iTwo <= $inputMaxWord; ++$iTwo) {
                     $minCharOfPhrase = $inputMinCharEachWord * $iTwo + ($iTwo - 1);
                     $phraseNeedAnalysis = '';
                     $maxIThree = $iOne + $iTwo;
                     for ($iThree = $iOne; $iThree < $maxIThree; ++$iThree) {
                         if (isset($inputExplodedContents[$iThree])) {
                             $wordTemp = trim($inputExplodedContents[$iThree]);
                             if (isset($wordTemp[0])) {
                                 $phraseNeedAnalysis .= ' ' . $wordTemp;
                             }
                         } else {
                             break 2;
                         }
                     }
                     $phraseNeedAnalysis = trim($phraseNeedAnalysis);
                     if (mb_strlen($phraseNeedAnalysis, 'UTF-8') >= $minCharOfPhrase && !isset($common[$phraseNeedAnalysis]) && !is_numeric($phraseNeedAnalysis)) {
                         $resultAnalysis[$iTwo][] = $phraseNeedAnalysis;
                     }
                 }
             }
         }
         if (is_array($resultAnalysis)) {
             reset($resultAnalysis);
             foreach ($resultAnalysis as $keyOne => $valueOne) {
                 $valueOne = array_count_values($valueOne);
                 if ($inputMinOccur > 1) {
                     $valueOne = self::analysisKeyword_OccureFilter($valueOne, $inputMinOccur);
                 }
                 if (!empty($valueOne)) {
                     arsort($valueOne);
                     $resultAnalysis[$keyOne] = $valueOne;
                 } else {
                     unset($resultAnalysis[$keyOne]);
                 }
             }
             krsort($resultAnalysis);
         }
         $resultData['data'] = $resultAnalysis;
         TempDataAndCacheFile::set_cache($keyCache1, $resultData);
     }
     return $resultData;
 }
Exemplo n.º 12
0
        $resultData = false;
        if (preg_match('#^(https?:)?//.+\\.(gif|jpeg|jpg|png)\\??.*$#i', $url)) {
            $resultData = true;
        }
        return $resultData;
    }
    public static function isUrlSameHost($url, $host)
    {
        $resultData = false;
        if (preg_match('#^(https?:)?//' . preg_quote($host, '#') . '/?#i', $url)) {
            $resultData = true;
        }
        return $resultData;
    }
    public static function isUrlSameDomain($url, $domain, $strict_status = true)
    {
        $resultData = false;
        if (true === $strict_status) {
            if (preg_match('#^(https?:)?//' . preg_quote($domain, '#') . '/?#i', $url)) {
                $resultData = true;
            }
        } else {
            if (preg_match('#^(https?:)?//[^/\\?]*' . preg_quote($domain, '#') . '/?#i', $url)) {
                $resultData = true;
            }
        }
        return $resultData;
    }
}
Utils::setDefaultParams();
Exemplo n.º 13
0
 public function process_text($text)
 {
     $device_screen_width = $this->_check_get_screen_width();
     $options = self::getOption();
     if (!isset($options['optimize_images_alttext'])) {
         $options['optimize_images_alttext'] = '';
     }
     if (!isset($options['optimize_images_titletext'])) {
         $options['optimize_images_titletext'] = '';
     }
     $optimize_images_alttext = trim($options['optimize_images_alttext']);
     $optimize_images_titletext = trim($options['optimize_images_titletext']);
     if ('on' !== $options['optimize_images_optimize_image_file_enable'] && !$optimize_images_alttext && !$optimize_images_titletext) {
         return $text;
     }
     global $wpdb, $post;
     $classMethodKey = crc32(__CLASS__ . __METHOD__);
     $currentPostId = 0;
     if (isset($post->ID) && $post->ID) {
         $currentPostId = $post->ID;
     }
     $currentPostId = (int) $currentPostId;
     if (!$currentPostId) {
         if (System::function_exists('get_the_ID')) {
             $tmp = get_the_ID();
             $tmp = (int) $tmp;
             if ($tmp > 0) {
                 $currentPostId = $tmp;
             }
         }
     }
     $parametersPrimary = array();
     $patternsEscaped = array();
     $patternsReplace = array();
     $patternsReplaceImgSrc = array();
     $patternsPregReplace = array();
     $rsSettingWatermarksFirstOptions = $this->parse_watermarks_first_options(array('options' => $options));
     $paramsWatermarkOptions = $rsSettingWatermarksFirstOptions['paramsWatermarkOptions'];
     $options = $rsSettingWatermarksFirstOptions['options'];
     unset($rsSettingWatermarksFirstOptions);
     $options['optimize_images_rename_img_filename_value'] = trim($options['optimize_images_rename_img_filename_value']);
     $keyCacheProcessText = Utils::hashKey(array($classMethodKey, $text, 'process_text', 'dvsw_' . $device_screen_width, $options));
     $tmp = TempDataAndCacheFile::get_cache($keyCacheProcessText, true);
     if (null !== $tmp) {
         return $tmp;
     }
     //Begin process image file
     if ('on' === $options['optimize_images_optimize_image_file_enable'] && $this->_isSystemReadyToHandleImagesStatus) {
         preg_match_all('#<img[^<>]+(\'|\\")(https?:)?//' . Utils::preg_quote(PepVN_Data::$defaultParams['fullDomainName']) . '[^\'\\"]+\\.(' . implode('|', $this->imageExtensionsAllow) . ')\\??[^\'\\"]*\\1#is', $text, $matched1);
         if (isset($matched1[0]) && $matched1[0] && !empty($matched1[0])) {
             $matched1 = $matched1[0];
             foreach ($matched1 as $key1 => $value1) {
                 unset($matched1[$key1]);
                 if ($value1) {
                     preg_match('#(\'|\\")((https?:)?//[^\\"\']+)\\1#i', $value1, $matched2);
                     if (isset($matched2[2]) && $matched2[2]) {
                         $matched2 = trim($matched2[2]);
                         if ($matched2) {
                             $imgName1 = WP_OPTIMIZE_BY_XTRAFFIC_PLUGIN_SLUG;
                             $imgInfo1 = pathinfo($matched2);
                             if (isset($imgInfo1['filename'])) {
                                 $imgName1 = $imgInfo1['filename'];
                             }
                             $processImageOptions1 = array('optimized_image_file_name' => trim($imgName1), 'original_image_src' => $matched2, 'action' => 'do_process_image');
                             if ($device_screen_width > 0) {
                                 $processImageOptions1['resize_max_width'] = $device_screen_width;
                             }
                             $rsProcessImage1 = $this->process_image($processImageOptions1);
                             unset($processImageOptions1);
                             if ($rsProcessImage1['image_optimized_file_url']) {
                                 $valueTemp1 = '//' . PepVN_Data::removeProtocolUrl($matched2);
                                 $valueTemp2 = '//' . PepVN_Data::removeProtocolUrl($rsProcessImage1['image_optimized_file_url']);
                                 if ($valueTemp1 !== $valueTemp2) {
                                     $patternsReplaceImgSrc[$valueTemp1] = $valueTemp2;
                                 }
                                 unset($valueTemp1, $valueTemp2);
                             }
                             unset($rsProcessImage1);
                         }
                     }
                 }
             }
         }
     }
     unset($matched1);
     //Begin process image's attributes
     if (preg_match_all('#<img[^>]+\\\\?>#i', $text, $matched1)) {
         if (isset($matched1[0]) && is_array($matched1[0]) && !empty($matched1[0])) {
             $matched1 = $matched1[0];
             foreach ($matched1 as $keyOne => $valueOne) {
                 unset($matched1[$keyOne]);
                 $oldImgTag = $valueOne;
                 $newImgTag = $valueOne;
                 $imgTitle1 = '';
                 $imgAlt1 = '';
                 $imgName = '';
                 $imgFullName = '';
                 $imgSrc = '';
                 $imgInfo = false;
                 $matched2 = 0;
                 if (preg_match('#title=(\'|")([^"\']+)\\1#i', $valueOne, $matched2)) {
                     if (isset($matched2[2]) && $matched2[2]) {
                         $imgTitle1 = trim($matched2[2]);
                     }
                 }
                 $matched2 = 0;
                 if (preg_match('#alt=(\'|")([^"\']+)\\1#i', $valueOne, $matched2)) {
                     if (isset($matched2[2]) && $matched2[2]) {
                         $imgAlt1 = trim($matched2[2]);
                     }
                 }
                 $matched2 = 0;
                 if (preg_match('#src=(\'|")(https?://[^"\']+)\\1#i', $valueOne, $matched2)) {
                     if (isset($matched2[2]) && $matched2[2]) {
                         $imgSrc = trim($matched2[2]);
                         $imgName = trim($matched2[2]);
                     }
                 }
                 $matched2 = 0;
                 $imgName = trim($imgName);
                 if ($imgName) {
                     $imgInfo = pathinfo($imgName);
                     if (isset($imgInfo['filename'])) {
                         $imgName = $imgInfo['filename'];
                         $imgFullName = $imgInfo['basename'];
                     }
                 }
                 $imgName = trim($imgName);
                 $imgTitle1 = PepVN_Data::cleanKeyword($imgTitle1);
                 $imgAlt1 = PepVN_Data::cleanKeyword($imgAlt1);
                 $imgName = PepVN_Data::cleanKeyword($imgName);
                 if ($imgAlt1 && 'on' === $options['optimize_images_override_alt'] || !$imgAlt1) {
                     $optimize_images_alttext1 = $this->parse_custom_tag_of_image(array('raw_tag' => $optimize_images_alttext, 'post_id' => $currentPostId, 'patterns' => array('img_name' => $imgName, 'img_title' => $imgTitle1, 'img_alt' => $imgAlt1)));
                     if ($optimize_images_alttext1) {
                         $newImgTag = preg_replace('#alt=(\'|")([^"\']+)?\\1#i', '', $newImgTag);
                         $newImgTag = preg_replace('#<img(.+)#is', '<img alt="' . $optimize_images_alttext1 . '" \\1', $newImgTag);
                     }
                 }
                 if ($imgTitle1 && 'on' === $options['optimize_images_override_alt'] || !$imgTitle1) {
                     $optimize_images_titletext1 = $this->parse_custom_tag_of_image(array('raw_tag' => $optimize_images_titletext, 'post_id' => $currentPostId, 'patterns' => array('img_name' => $imgName, 'img_title' => $imgTitle1, 'img_alt' => $imgAlt1)));
                     if ($optimize_images_titletext1) {
                         $newImgTag = preg_replace('#title=(\'|")([^"\']+)?\\1#i', '', $newImgTag);
                         $newImgTag = preg_replace('#<img(.+)#is', '<img title="' . $optimize_images_titletext1 . '" \\1', $newImgTag);
                     }
                 }
                 if ($imgSrc) {
                     //Begin Process Image File
                     $checkStatus2 = false;
                     if ($this->_isSystemReadyToHandleImagesStatus) {
                         if (Utils::isUrl($imgSrc)) {
                             $checkStatus2 = true;
                         }
                     }
                     if ($checkStatus2) {
                         $imgNewName = $imgName;
                         if ($options['optimize_images_rename_img_filename_value']) {
                             $optimize_images_rename_img_filename_value = $options['optimize_images_rename_img_filename_value'];
                             $optimize_images_rename_img_filename_value = $this->parse_custom_tag_of_image(array('raw_tag' => $optimize_images_rename_img_filename_value, 'post_id' => $currentPostId, 'patterns' => array('img_name' => $imgName, 'img_title' => $imgTitle1, 'img_alt' => $imgAlt1)));
                             if ($optimize_images_rename_img_filename_value) {
                                 $imgNewName = $optimize_images_rename_img_filename_value;
                             }
                         }
                         $max_size_image_tag = $this->get_max_size_image_tag($oldImgTag);
                         $imgOptimizedFilePathExists1 = false;
                         $processImageOptions1 = array('optimized_image_file_name' => $imgNewName, 'original_image_src' => $imgSrc, 'options' => $options, 'paramsWatermarkOptions' => $paramsWatermarkOptions);
                         if ($max_size_image_tag['width'] > 0) {
                             $processImageOptions1['resize_max_width'] = $max_size_image_tag['width'];
                         }
                         if ($max_size_image_tag['height'] > 0) {
                             $processImageOptions1['resize_max_height'] = $max_size_image_tag['height'];
                         }
                         $rsProcessImage1 = $this->process_image($processImageOptions1);
                         unset($processImageOptions1);
                         if ($rsProcessImage1['image_optimized_file_path']) {
                             $imgOptimizedFilePathExists1 = $rsProcessImage1['image_optimized_file_path'];
                         }
                         if (false === $imgOptimizedFilePathExists1) {
                             if (isset($options['optimize_images_optimize_image_file_enable']) && 'on' === $options['optimize_images_optimize_image_file_enable']) {
                                 $processImageOptions1 = array('optimized_image_file_name' => $imgNewName, 'original_image_src' => $imgSrc, 'options' => $options, 'paramsWatermarkOptions' => $paramsWatermarkOptions, 'action' => 'do_process_image');
                                 if ($max_size_image_tag['width'] > 0) {
                                     $processImageOptions1['resize_max_width'] = $max_size_image_tag['width'];
                                 }
                                 if ($max_size_image_tag['height'] > 0) {
                                     $processImageOptions1['resize_max_height'] = $max_size_image_tag['height'];
                                 }
                                 $rsProcessImage1 = $this->process_image($processImageOptions1);
                                 unset($processImageOptions1);
                                 if ($rsProcessImage1['image_optimized_file_path']) {
                                     $imgOptimizedFilePathExists1 = $rsProcessImage1['image_optimized_file_path'];
                                 }
                             }
                         }
                         if ($imgOptimizedFilePathExists1) {
                             if (is_file($imgOptimizedFilePathExists1)) {
                                 if (filesize($imgOptimizedFilePathExists1) > 0) {
                                     $rs_getimagesize1 = getimagesize($imgOptimizedFilePathExists1);
                                     if (isset($rs_getimagesize1[0]) && $rs_getimagesize1[0]) {
                                         $newImgTag = $this->check_set_size_image_tag($newImgTag, array('width' => $rs_getimagesize1[0], 'height' => $rs_getimagesize1[1]), true);
                                         $imgSrc2 = str_replace($this->_folderStorePath, $this->_folderStoreUrl, $imgOptimizedFilePathExists1);
                                         $newImgTag = str_replace($imgSrc, $imgSrc2, $newImgTag);
                                         $patternsReplaceImgSrc[$imgSrc] = $imgSrc2;
                                     }
                                 }
                             }
                         }
                     }
                 }
                 if ($oldImgTag !== $newImgTag) {
                     $patternsReplace[$oldImgTag] = $newImgTag;
                 }
             }
         }
         if ($patternsReplace && !empty($patternsReplace)) {
             $text = str_replace(array_keys($patternsReplace), array_values($patternsReplace), $text);
         }
         unset($patternsReplace);
         if ($patternsPregReplace && !empty($patternsPregReplace)) {
             $text = preg_replace(array_keys($patternsPregReplace), array_values($patternsPregReplace), $text);
         }
         unset($patternsPregReplace);
         if ($patternsReplaceImgSrc && !empty($patternsReplaceImgSrc)) {
             $patternsReplaceImgSrc2 = array();
             foreach ($patternsReplaceImgSrc as $keyOne => $valueOne) {
                 unset($patternsReplaceImgSrc[$keyOne]);
                 if ($keyOne && $valueOne) {
                     $tmp1 = '#([\'\\"\\s \\t]*?)' . PepVN_Data::preg_quote($keyOne) . '([\'\\"\\s \\t]*?)#is';
                     $tmp2 = '\\1' . $valueOne . '\\2';
                     $patternsReplaceImgSrc2[$tmp1] = $tmp2;
                 }
             }
             if (!empty($patternsReplaceImgSrc2)) {
                 $text = preg_replace(array_keys($patternsReplaceImgSrc2), array_values($patternsReplaceImgSrc2), $text);
             }
         }
     }
     /*
     if('on' === $options['optimize_images_images_lazy_load_enable']) {
     	//$text = $this->process_allimagestags_lazyload($text,0);
     }
     */
     $text = trim($text);
     TempDataAndCacheFile::set_cache($keyCacheProcessText, $text, true);
     return $text;
 }
Exemplo n.º 14
0
 public function process_attributes_links($text)
 {
     $options = self::getOption();
     if (!isset($options['nofollow_url'])) {
         $options['nofollow_url'] = '';
     }
     $options['nofollow_url'] = (string) $options['nofollow_url'];
     $options['nofollow_url'] = trim($options['nofollow_url']);
     if (isset($options['nofollow_url']) && $options['nofollow_url'] || isset($options['external_new_window']) && 'on' === $options['external_new_window'] || isset($options['external_nofollow']) && 'on' === $options['external_nofollow']) {
         if (!isset($options['external_new_window'])) {
             $options['external_new_window'] = '';
         }
         if (!isset($options['external_exclude_url'])) {
             $options['external_exclude_url'] = '';
         }
         $options['external_exclude_url'] = (string) $options['external_exclude_url'];
         $options['external_exclude_url'] = trim($options['external_exclude_url']);
         $nofollow_url = PepVN_Data::cleanPregPatternsArray($options['nofollow_url']);
         $nofollow_url = implode('|', $nofollow_url);
         $nofollow_url = trim($nofollow_url);
         $external_exclude_url = PepVN_Data::cleanPregPatternsArray($options['external_exclude_url']);
         $external_exclude_url = implode('|', $external_exclude_url);
         $external_exclude_url = trim($external_exclude_url);
         $keyCacheProcessText = Utils::hashKey(array(__CLASS__ . __METHOD__, $text, $nofollow_url, $external_exclude_url, $options['external_new_window'], 'process_text'));
         $tmp = TempDataAndCacheFile::get_cache($keyCacheProcessText, true);
         if (null !== $tmp) {
             return $tmp;
         }
         $patternSelfHost = '#^https?://' . Utils::preg_quote(PepVN_Data::$defaultParams['parseedUrlFullRequest']['host']) . '.+#i';
         $arraySearchAndReplace = array();
         $rsOne = PepVN_Data::escapeHtmlTags($text);
         unset($rsOne['content']);
         if (!empty($rsOne['patterns'])) {
             foreach ($rsOne['patterns'] as $keyOne => $valueOne) {
                 unset($rsOne['patterns'][$keyOne]);
                 if (preg_match('#<a[^>]+>#i', $keyOne, $matched1)) {
                     if (preg_match('#href=(\'|")(https?://[^"\']+)\\1#i', $keyOne, $matched2)) {
                         $oldValue = $keyOne;
                         $newValue = $keyOne;
                         if (isset($matched2[2]) && $matched2[2]) {
                             $matched2[2] = trim($matched2[2]);
                             $isNofollowStatus1 = false;
                             $isExternalLinksStatus1 = false;
                             if (!preg_match($patternSelfHost, $matched2[2])) {
                                 $isExternalLinksStatus1 = true;
                             }
                             if ($nofollow_url && preg_match('#(' . $nofollow_url . ')#i', $matched2[2], $matched3)) {
                                 $isNofollowStatus1 = true;
                             } else {
                                 if ($options['external_nofollow']) {
                                     if ($isExternalLinksStatus1) {
                                         //is external links = true
                                         if ($external_exclude_url && preg_match('#(' . $external_exclude_url . ')#i', $matched2[2], $matched3)) {
                                         } else {
                                             $isNofollowStatus1 = true;
                                         }
                                     }
                                 }
                             }
                             if ($options['external_new_window']) {
                                 if ($isExternalLinksStatus1) {
                                     $newValue = preg_replace('#target=(\'|")([^"\']+)\\1#i', '', $newValue);
                                     $newValue = preg_replace('#<a(.+)#is', '<a target="_blank" \\1', $newValue);
                                 }
                             }
                             if ($isNofollowStatus1) {
                                 if (preg_match('#rel=(\'|")([^"\']+)\\1#i', $newValue, $matched3)) {
                                     $newValue = preg_replace('#(rel=)(\'|")([^"\']+)\\2#i', '\\1\\2\\3 nofollow \\2', $newValue);
                                 } else {
                                     $newValue = preg_replace('#<a(.+)#is', '<a rel="nofollow" \\1', $newValue);
                                 }
                             }
                         }
                         if ($oldValue !== $newValue) {
                             $arraySearchAndReplace[$oldValue] = $newValue;
                         }
                     }
                     unset($matched2);
                 }
                 unset($matched2);
                 unset($keyOne, $valueOne);
             }
             if (!empty($arraySearchAndReplace)) {
                 $text = str_replace(array_keys($arraySearchAndReplace), array_values($arraySearchAndReplace), $text);
             }
             unset($arraySearchAndReplace);
         }
         TempDataAndCacheFile::set_cache($keyCacheProcessText, $text, true);
     }
     return $text;
 }
Exemplo n.º 15
0
 public function getAndParseTags($input_term_id = 0)
 {
     $input_term_id = (int) $input_term_id;
     $keyCache1 = Utils::hashKey(array(__CLASS__ . __METHOD__, $input_term_id));
     $resultData = PepVN_Data::$cacheObject->get_cache($keyCache1);
     if (null === $resultData) {
         $resultData = array();
         $terms = $this->get_tags($input_term_id);
         if ($terms) {
             foreach ($terms as $index => $term) {
                 unset($terms[$index]);
                 if ($term) {
                     if (isset($term->term_id) && $term->term_id) {
                         $term->term_id = (int) $term->term_id;
                         $resultData[$term->name] = array('name' => $term->name, 'term_id' => $term->term_id, 'tagLink' => $this->get_tag_link($term->term_id));
                     }
                 }
             }
         }
         PepVN_Data::$cacheObject->set_cache($keyCache1, $resultData);
     }
     return $resultData;
 }
Exemplo n.º 16
0
 public function get($input_url, $input_args = false)
 {
     if (!$this->_cacheFile) {
         $this->_cacheFile = $this->di->getShared('cache');
     }
     if (!$input_args) {
         $input_args = array();
     }
     if (preg_match('#^//.+#i', $input_url, $matched1)) {
         $input_url = 'http:' . $input_url;
     }
     if (!isset($input_args['request_timeout'])) {
         $input_args['request_timeout'] = 6;
     }
     $input_args['request_timeout'] = (int) $input_args['request_timeout'];
     if ($input_args['request_timeout'] < 1) {
         $input_args['request_timeout'] = 1;
     }
     $return_detail_status = false;
     if (isset($input_args['return_detail_status'])) {
         $return_detail_status = (bool) $input_args['return_detail_status'];
         unset($input_args['return_detail_status']);
     }
     $cache_timeout = 0;
     if (isset($input_args['cache_timeout'])) {
         $cache_timeout = (int) $input_args['cache_timeout'];
         unset($input_args['cache_timeout']);
     }
     $cache_timeout = (int) $cache_timeout;
     $redirection = 9;
     if (isset($input_args['redirection'])) {
         $redirection = (int) $input_args['redirection'];
         unset($input_args['redirection']);
     }
     $redirection = (int) $redirection;
     if ($cache_timeout > 0) {
         if ($this->_cacheFile) {
             $keyCache1 = Utils::hashKey(array('WpPepVN_Remote_get', $input_url, $input_args));
             $resultData = $this->_cacheFile->get($keyCache1);
             if (null !== $resultData) {
                 return $resultData;
             }
         }
     }
     $input_args = array_merge(array('method' => 'GET', 'timeout' => 6, 'redirection' => $redirection, 'user-agent' => $this->_http_UserAgent, 'blocking' => true, 'headers' => array(), 'cookies' => array(), 'compress' => true, 'decompress' => true, 'sslverify' => false, 'filename' => null), $input_args);
     //$objWPHttp = new \WP_Http_Streams();
     $objWPHttp = new \WP_Http();
     $resultData = $objWPHttp->request($input_url, $input_args);
     if (!$return_detail_status) {
         $isOkStatus = false;
         if (!is_wp_error($resultData)) {
             if (is_array($resultData)) {
                 if (isset($resultData['body'])) {
                     $isOkStatus = true;
                     if (isset($resultData['response']['code']) && $resultData['response']['code']) {
                         $resultData['response']['code'] = (int) $resultData['response']['code'];
                         if (200 !== $resultData['response']['code']) {
                             $isOkStatus = false;
                         }
                     }
                 }
             }
         }
         if ($isOkStatus) {
             $resultData = $resultData['body'];
         } else {
             $resultData = false;
             if ($this->_curl) {
                 $resultData = $this->_curl->get($input_url, $input_args);
                 if (!$resultData) {
                     $resultData = false;
                 }
             }
         }
     }
     if ($cache_timeout > 0) {
         if ($this->_cacheFile) {
             $this->_cacheFile->save($keyCache1, $resultData);
         }
     }
     return $resultData;
 }
Exemplo n.º 17
0
 public function process_text($input_text, $postId = 0)
 {
     $classMethodKey = crc32(__CLASS__ . __METHOD__);
     $options = self::getOption();
     if (isset($options['optimize_traffic_modules']) && !PepVN_Data::isEmptyArray($options['optimize_traffic_modules'])) {
     } else {
         return $input_text;
     }
     $keyCacheProcessText = Utils::hashKey(array($classMethodKey, $input_text, 'process_text', $options['optimize_traffic_modules'], $postId));
     $tmp = TempDataAndCacheFile::get_cache($keyCacheProcessText, true);
     if (null !== $tmp) {
         return $tmp;
     }
     $wpExtend = $this->di->getShared('wpExtend');
     global $wpdb;
     $postId = (int) $postId;
     if ($postId) {
         $post = $wpExtend->get_post($post_id);
     } else {
         global $post;
     }
     $patternsEscaped1 = array();
     $rsOne = PepVN_Data::escapeByPattern($input_text, array('pattern' => '#<([a-z]+)[^><]+class=(\'|\\")[^><\'\\"]*?wp\\-caption[^><\'\\"]*?\\2[^><]*?>.*?</\\1>#is', 'target_patterns' => array(0), 'wrap_target_patterns' => ''));
     $input_text = $rsOne['content'];
     if (!empty($rsOne['patterns'])) {
         $patternsEscaped1 = array_merge($patternsEscaped1, $rsOne['patterns']);
     }
     unset($rsOne);
     $rsOne = PepVN_Data::escapeHtmlTagsAndContents($input_text, 'a;table;pre;ol;ul;blockquote');
     $input_text = $rsOne['content'];
     if (!empty($rsOne['patterns'])) {
         $patternsEscaped1 = array_merge($patternsEscaped1, $rsOne['patterns']);
     }
     unset($rsOne);
     $original_InputText1 = $input_text;
     $post->ID = (int) $post->ID;
     $rsGetTerms = $wpExtend->getTermsByPostId($post->ID);
     $rsGetTerms2 = $rsGetTerms;
     $rsGetTerms2 = array_keys($rsGetTerms2);
     $rsGetTerms2 = $this->_clean_terms($rsGetTerms2);
     $postExcerpt1 = $post->post_content;
     $postExcerpt1 = PepVN_Data::mb_substr($postExcerpt1, 0, 360);
     $allPostTextCombined = $post->post_title . ' ' . PHP_EOL . ' ' . $post->post_excerpt . ' ' . PHP_EOL . implode(' ', $rsGetTerms2) . ' ' . PHP_EOL . ' ' . $post->post_content;
     $allPostTextCombined = $this->_remove_escaped_string($allPostTextCombined);
     $patternsModulesReplaceText = array();
     $groupModules_ByModuleType = array();
     $groupModules_PositionsAddedToQueue = array();
     $groupModules_ByFixedTypeBeginOrEnd = array();
     foreach ($options['optimize_traffic_modules'] as $keyOne => $valueOne) {
         if (isset($valueOne['module_type']) && $valueOne['module_type']) {
             if (isset($valueOne['module_position'])) {
                 if (!in_array($valueOne['module_position'], $groupModules_PositionsAddedToQueue)) {
                     $valueOne['module_mumber_of_items'] = abs((int) $valueOne['module_mumber_of_items']);
                     if ($valueOne['module_mumber_of_items'] < 1) {
                         $valueOne['module_mumber_of_items'] = 1;
                     } else {
                         if ($valueOne['module_mumber_of_items'] > 10) {
                             $valueOne['module_mumber_of_items'] = 10;
                         }
                     }
                     $groupModules_PositionsAddedToQueue[] = $valueOne['module_position'];
                     $groupModules_ByModuleType[$valueOne['module_type']][$valueOne['module_position']] = $valueOne;
                 }
             }
         }
     }
     $numberElementContentInText = 0;
     preg_match_all('/<(p|h1|h2|h3|h4|h5|h6)(\\s+[^><]*?)?>.*?<\\/\\1>/is', $original_InputText1, $matchedElementContentInText);
     if (isset($matchedElementContentInText[0]) && $matchedElementContentInText[0]) {
         if (!empty($matchedElementContentInText[0])) {
             foreach ($matchedElementContentInText[0] as $key1 => $value1) {
                 $valueTemp1 = $value1;
                 $valueTemp1 = AnalyzeText::cleanRawTextForProcessSearch($valueTemp1);
                 $checkStatus2 = false;
                 if ($valueTemp1) {
                     $valueTemp2 = explode(' ', $valueTemp1);
                     if (count($valueTemp2) > 5) {
                         $checkStatus2 = true;
                     } else {
                         if (preg_match('#<(h1|h2|h3|h4|h5|h6)(\\s+[^><]*?)?>.*?</\\1>#is', $value1, $matched1)) {
                             $checkStatus2 = true;
                         }
                     }
                 }
                 if (!$checkStatus2) {
                     unset($matchedElementContentInText[0][$key1]);
                 }
             }
         }
         $numberElementContentInText = count($matchedElementContentInText[0]);
     }
     if (isset($groupModules_ByModuleType['flyout']) && $groupModules_ByModuleType['flyout'] && !empty($groupModules_ByModuleType['flyout'])) {
         foreach ($groupModules_ByModuleType['flyout'] as $keyOne => $valueOne) {
             if (isset($valueOne['module_type'])) {
                 $postsIdsFound1 = array();
                 $rsSearchPost1 = $this->search_post_by_text($allPostTextCombined, array('group_text_weight' => array(array('text' => $post->post_title, 'weight' => 20), array('text' => $post->post_excerpt, 'weight' => 2), array('text' => implode(' ', $rsGetTerms2), 'weight' => 30), array('text' => $postExcerpt1, 'weight' => 2)), 'exclude_posts_ids' => array($post->ID), 'post_id_less_than' => $post->ID, 'limit' => $valueOne['module_mumber_of_items'], 'key_cache' => $valueOne['module_type'] . '_' . $valueOne['module_position']));
                 if ($rsSearchPost1) {
                     foreach ($rsSearchPost1 as $keyTwo => $valueTwo) {
                         $postsIdsFound1[] = $valueTwo['post_id'];
                     }
                 }
                 if ($postsIdsFound1 && !empty($postsIdsFound1)) {
                     $rsCreateTrafficModule1 = $this->create_traffic_module(array('option' => $valueOne, 'data' => array('posts_ids' => $postsIdsFound1)));
                     if ($rsCreateTrafficModule1['module']) {
                         $input_text .= ' ' . $rsCreateTrafficModule1['module'];
                     }
                 }
             }
         }
     }
     if (isset($groupModules_ByModuleType['fixed']) && !PepVN_Data::isEmptyArray($groupModules_ByModuleType['fixed'])) {
         foreach ($groupModules_ByModuleType['fixed'] as $keyOne => $valueOne) {
             if (isset($valueOne['module_position'])) {
                 $valueOne['module_position'] = (int) $valueOne['module_position'];
                 if (0 == $valueOne['module_position'] || 100 == $valueOne['module_position']) {
                     $groupModules_ByFixedTypeBeginOrEnd[$valueOne['module_position']] = $valueOne;
                     unset($groupModules_ByModuleType['fixed'][$keyOne]);
                 }
             }
         }
         if ($groupModules_ByFixedTypeBeginOrEnd && !empty($groupModules_ByFixedTypeBeginOrEnd)) {
             ksort($groupModules_ByFixedTypeBeginOrEnd);
             foreach ($groupModules_ByFixedTypeBeginOrEnd as $keyOne => $valueOne) {
                 if (isset($valueOne['module_position'])) {
                     $valueOne['module_position'] = (int) $valueOne['module_position'];
                     $postsIdsFound1 = array();
                     $rsSearchPost1 = $this->search_post_by_text($allPostTextCombined, array('group_text_weight' => array(array('text' => $post->post_title, 'weight' => 20), array('text' => $post->post_excerpt, 'weight' => 2), array('text' => implode(' ', $rsGetTerms2), 'weight' => 30), array('text' => $postExcerpt1, 'weight' => 2)), 'exclude_posts_ids' => array($post->ID), 'post_id_less_than' => $post->ID, 'limit' => $valueOne['module_mumber_of_items'], 'key_cache' => $valueOne['module_type'] . '_' . $valueOne['module_position']));
                     if ($rsSearchPost1) {
                         foreach ($rsSearchPost1 as $keyTwo => $valueTwo) {
                             $postsIdsFound1[] = $valueTwo['post_id'];
                         }
                     }
                     if (!empty($postsIdsFound1)) {
                         $rsCreateTrafficModule1 = $this->create_traffic_module(array('option' => $valueOne, 'data' => array('posts_ids' => $postsIdsFound1)));
                         if ($rsCreateTrafficModule1['module']) {
                             if (0 == $valueOne['module_position']) {
                                 $input_text = $rsCreateTrafficModule1['module'] . ' ' . $input_text;
                             } else {
                                 if (100 == $valueOne['module_position']) {
                                     $input_text .= ' ' . $rsCreateTrafficModule1['module'];
                                 }
                             }
                         }
                     }
                 }
             }
         }
         if ($numberElementContentInText > 0) {
             ksort($groupModules_ByModuleType['fixed']);
             $arrayMatchedElementContentInTextIsProcessed = array();
             foreach ($groupModules_ByModuleType['fixed'] as $keyOne => $valueOne) {
                 if (isset($valueOne['module_position'])) {
                     $valueOne['module_position'] = (int) $valueOne['module_position'];
                     $originalTextNeedProcess1 = '';
                     $rawTextNeedProcess1 = '';
                     $iNumber1 = 0;
                     foreach ($matchedElementContentInText[0] as $keyTwo => $valueTwo) {
                         if (!in_array($valueTwo, $arrayMatchedElementContentInTextIsProcessed)) {
                             $originalTextNeedProcess1 .= ' ' . $valueTwo;
                         }
                         $iNumber1++;
                         $currentPercentPos = $iNumber1 / $numberElementContentInText * 100;
                         $currentPercentPos = (int) $currentPercentPos;
                         if ($currentPercentPos >= $valueOne['module_position'] && $originalTextNeedProcess1) {
                             if (preg_match('#<(p)(\\s+[^><]*?)?>.*?</\\1>#is', $valueTwo, $matched2)) {
                                 $originalTextNeedProcess1 = $this->_remove_escaped_string($originalTextNeedProcess1);
                                 $postsIdsFound1 = array();
                                 $rsSearchPost1 = $this->search_post_by_text($originalTextNeedProcess1, array('group_text_weight' => array(array('text' => $post->post_title, 'weight' => 20), array('text' => $post->post_excerpt, 'weight' => 2), array('text' => implode(' ', $rsGetTerms2), 'weight' => 30), array('text' => $originalTextNeedProcess1, 'weight' => 2)), 'exclude_posts_ids' => array($post->ID), 'post_id_less_than' => $post->ID, 'limit' => $valueOne['module_mumber_of_items'], 'key_cache' => $valueOne['module_type'] . '_' . $valueOne['module_position']));
                                 if ($rsSearchPost1) {
                                     foreach ($rsSearchPost1 as $keyThree => $valueThree) {
                                         $postsIdsFound1[] = $valueThree['post_id'];
                                     }
                                 }
                                 if ($postsIdsFound1 && !empty($postsIdsFound1)) {
                                     $rsCreateTrafficModule1 = $this->create_traffic_module(array('option' => $valueOne, 'data' => array('posts_ids' => $postsIdsFound1)));
                                     if ($rsCreateTrafficModule1['module']) {
                                         $originalTextNeedProcess1 = '';
                                         $patternsModulesReplaceText_K = $valueTwo;
                                         $patternsModulesReplaceText_V = $valueTwo . ' ' . $rsCreateTrafficModule1['module'];
                                         $patternsModulesReplaceText[$patternsModulesReplaceText_K] = $patternsModulesReplaceText_V;
                                         break;
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             $arrayMatchedElementContentInTextIsProcessed = 0;
         }
     }
     if (!empty($patternsModulesReplaceText)) {
         $tmp = array();
         foreach ($patternsModulesReplaceText as $key1 => $value1) {
             unset($patternsModulesReplaceText[$key1]);
             $key1 = '#' . Utils::preg_quote($key1) . '#';
             $tmp[$key1] = $value1;
         }
         if (!empty($tmp)) {
             $input_text = preg_replace(array_keys($tmp), array_values($tmp), $input_text, 1);
         }
         unset($tmp);
     }
     unset($patternsModulesReplaceText);
     if (!empty($patternsEscaped1)) {
         $input_text = str_replace(array_values($patternsEscaped1), array_keys($patternsEscaped1), $input_text);
     }
     unset($patternsEscaped1);
     TempDataAndCacheFile::set_cache($keyCacheProcessText, $input_text, true);
     return $input_text;
 }
Exemplo n.º 18
0
 public function addParamsToUri($uri = null, $args = null)
 {
     $request = $this->getRequest();
     if ($uri === null) {
         $uri = $request->getFullUri();
     }
     if ($uri) {
         if ($args && is_string($args)) {
             parse_str($args, $args);
         }
         $parsedUrl = $request->get_parse_url($uri);
         if (isset($parsedUrl['url_no_parameters']) && $parsedUrl['url_no_parameters']) {
             $uri = $parsedUrl['url_no_parameters'];
             if (!isset($parsedUrl['parameters'])) {
                 $parsedUrl['parameters'] = array();
             }
             $args = Utils::mergeArrays(array($parsedUrl['parameters'], $args));
         }
         if ($args) {
             $args = http_build_query($args);
             if (is_string($args) && !empty($args)) {
                 if (strpos($uri, '?') !== false) {
                     $uri .= '&' . $args;
                 } else {
                     $uri .= '?' . $args;
                 }
             }
         }
     }
     return $uri;
 }