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; }