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; }
$tmp = null; if (false === $useCachePermanentStatus) { $tmp = PepVN_Data::$cacheObject->get_cache($keyCache); } else { $tmp = self::$_tempData[$keyCache] = PepVN_Data::$cachePermanentObject->get_cache($keyCache); } if ($tmp !== null) { //return $tmp; self::$_tempData[$keyCache] = $tmp; return self::$_tempData[$keyCache]; } } return null; } 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; } } TempDataAndCacheFile::init();
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; }
public static function escapeSpecialElementsInHtmlPage($input_content) { $input_content = (string) $input_content; $keyCache1 = Utils::hashKey(array('PepVN_Data_escapeSpecialElementsInHtmlPage', $input_content)); $resultData = TempDataAndCacheFile::get_cache($keyCache1); if (null === $resultData) { $resultData = array('content' => $input_content, 'patterns' => array()); $patternsEscape1 = array(); $matched1 = false; preg_match_all('/<\\!--\\s*\\[\\s*if[^>]+>(.*?)<\\!\\s*\\[\\s*endif\\s*\\]\\s*-->/si', $input_content, $matched1); if (isset($matched1[0]) && $matched1[0]) { if (!empty($matched1[0])) { foreach ($matched1[0] as $key1 => $value1) { $search1 = $value1; $replace1 = md5($value1); //$replace1 = str_split($replace1); //$replace1 = implode('_',$replace1); $patternsEscape1[$search1] = '_' . $replace1 . '_'; } } } if (!empty($patternsEscape1)) { $input_content = str_replace(array_keys($patternsEscape1), array_values($patternsEscape1), $input_content); $resultData['content'] = $input_content; $resultData['patterns'] = $patternsEscape1; } TempDataAndCacheFile::set_cache($keyCache1, $resultData); } return $resultData; }
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; }