Exemple #1
0
 public function addPromotionTextToHtml($buffer)
 {
     $wpExtend = $this->di->getShared('wpExtend');
     $tmp = $wpExtend->getWpOptimizeByxTrafficPluginPromotionInfo();
     $buffer = PepVN_Data::appendTextToTagBodyOfHtml($tmp['html_comment_text'], $buffer);
     return $buffer;
 }
Exemple #2
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;
}
Exemple #3
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;
 }
Exemple #4
0
 public static function cleanRawTextForProcessSearch($input_text)
 {
     $input_text = (array) $input_text;
     $input_text = implode(' ', $input_text);
     $input_text = self::decodeText($input_text);
     $input_text = strip_tags($input_text);
     $input_text = PepVN_Data::strtolower($input_text);
     $input_text = self::analysisKeyword_RemovePunctuations($input_text);
     $input_text = Text::replaceSpecialChar($input_text);
     $input_text = PepVN_Data::reduceSpace($input_text);
     return $input_text;
 }
 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;
 }
Exemple #6
0
 public static function initCacheObject()
 {
     //cacheObject : store cache for short time (less than 1 day)
     $pepvnDirCachePathTemp = WP_OPTIMIZE_BY_XTRAFFIC_PLUGIN_STORAGES_CACHE_DIR . 's' . DIRECTORY_SEPARATOR;
     if (!is_dir($pepvnDirCachePathTemp)) {
         System::mkdir($pepvnDirCachePathTemp);
     }
     if (is_dir($pepvnDirCachePathTemp) && is_readable($pepvnDirCachePathTemp) && is_writable($pepvnDirCachePathTemp)) {
         $pepvnCacheHashKeySaltTemp = self::$defaultParams['fullDomainName'] . $pepvnDirCachePathTemp;
         if (defined('WP_PEPVN_SITE_SALT')) {
             $pepvnCacheHashKeySaltTemp .= '_' . WP_PEPVN_SITE_SALT;
         }
         self::$cacheObject = new \WPOptimizeByxTraffic\Application\Service\PepVN_CacheSimpleFile(array('cache_timeout' => 86400, 'hash_key_method' => 'crc32b', 'hash_key_salt' => hash('crc32b', md5($pepvnCacheHashKeySaltTemp)), 'gzcompress_level' => 2, 'key_prefix' => 'dts_', 'cache_dir' => $pepvnDirCachePathTemp));
     } else {
         self::$cacheObject = new \WPOptimizeByxTraffic\Application\Service\PepVN_CacheSimpleFile(array());
     }
     //cachePermanentObject : store cache for long time (>6 days)
     $pepvnDirCachePathTemp = WP_OPTIMIZE_BY_XTRAFFIC_PLUGIN_STORAGES_CACHE_DIR . 'pm' . DIRECTORY_SEPARATOR;
     if (!is_dir($pepvnDirCachePathTemp)) {
         System::mkdir($pepvnDirCachePathTemp);
     }
     if (is_dir($pepvnDirCachePathTemp) && is_readable($pepvnDirCachePathTemp) && is_writable($pepvnDirCachePathTemp)) {
         $pepvnCacheHashKeySaltTemp = self::$defaultParams['fullDomainName'] . $pepvnDirCachePathTemp;
         if (defined('WP_PEPVN_SITE_SALT')) {
             $pepvnCacheHashKeySaltTemp .= '_' . WP_PEPVN_SITE_SALT;
         }
         $pepvnCacheTimeoutTemp = 86400 * 6;
         PepVN_Data::$cachePermanentObject = new \WPOptimizeByxTraffic\Application\Service\PepVN_CacheSimpleFile(array('cache_timeout' => $pepvnCacheTimeoutTemp, 'hash_key_method' => 'crc32b', 'hash_key_salt' => hash('crc32b', md5($pepvnCacheHashKeySaltTemp)), 'gzcompress_level' => 2, 'key_prefix' => 'dtpm_', 'cache_dir' => $pepvnDirCachePathTemp));
     } else {
         PepVN_Data::$cachePermanentObject = new \WPOptimizeByxTraffic\Application\Service\PepVN_CacheSimpleFile(array());
     }
     /*
     		//cacheByTagObject
     		$pepvnDirCachePathTemp = WP_OPTIMIZE_BY_XTRAFFIC_PLUGIN_STORAGES_CACHE_DIR.'cbtg'.DIRECTORY_SEPARATOR; 
     
     		if(!is_dir($pepvnDirCachePathTemp)) {
     			PepVN_Data::createFolder($pepvnDirCachePathTemp);
     		}
     
     		if(is_dir($pepvnDirCachePathTemp) && is_readable($pepvnDirCachePathTemp) && is_writable($pepvnDirCachePathTemp)) {
     			$pepvnCacheHashKeySaltTemp = __FILE__ . PepVN_Data::$defaultParams['fullDomainName'] . $pepvnDirCachePathTemp;
     			
     			if(defined('WP_PEPVN_SITE_SALT')) {
     				$pepvnCacheHashKeySaltTemp .= '_'.WP_PEPVN_SITE_SALT;
     			}
     			
     			$pepvnCacheTimeoutTemp = 86400 * 6;
     			
     			PepVN_Data::$cacheByTagObject = new PepVN_Cache(
     				array(
     					'cache_timeout' => $pepvnCacheTimeoutTemp	//int : seconds
     					,'hash_key_method' => 'crc32b'
     					,'hash_key_salt' => hash('crc32b',md5($pepvnCacheHashKeySaltTemp))
     					,'gzcompress_level' => 2
     					,'key_prefix' => 'cbtg_dt_'
     					,'cache_methods' => array(
     						'file' => array(
     							'cache_timeout' => $pepvnCacheTimeoutTemp
     							, 'cache_dir' => $pepvnDirCachePathTemp
     						),
     						
     					)
     				)
     			);
     		} else {
     			PepVN_Data::$cacheByTagObject = new PepVN_Cache(array()); 
     		}
     		//*/
 }
 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;
 }
 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;
 }