| @@ 1004-1126 (lines=123) @@ | ||
| 1001 | * @param string $content Content from which we have to create metakeywords |
|
| 1002 | * @return string The list of meta keywords |
|
| 1003 | */ |
|
| 1004 | public static function createMetaKeywords($content) |
|
| 1005 | { |
|
| 1006 | $keywordscount = static::getModuleOption('metagen_maxwords'); |
|
| 1007 | $keywordsorder = static::getModuleOption('metagen_order'); |
|
| 1008 | ||
| 1009 | $tmp = array(); |
|
| 1010 | // Search for the "Minimum keyword length" |
|
| 1011 | if (isset($_SESSION['oledrion_keywords_limit'])) { |
|
| 1012 | $limit = $_SESSION['oledrion_keywords_limit']; |
|
| 1013 | } else { |
|
| 1014 | $configHandler = xoops_getHandler('config'); |
|
| 1015 | $xoopsConfigSearch = $configHandler->getConfigsByCat(XOOPS_CONF_SEARCH); |
|
| 1016 | $limit = $xoopsConfigSearch['keyword_min']; |
|
| 1017 | $_SESSION['oledrion_keywords_limit'] = $limit; |
|
| 1018 | } |
|
| 1019 | $myts = MyTextSanitizer::getInstance(); |
|
| 1020 | $content = str_replace('<br>', ' ', $content); |
|
| 1021 | $content = $myts->undoHtmlSpecialChars($content); |
|
| 1022 | $content = strip_tags($content); |
|
| 1023 | $content = strtolower($content); |
|
| 1024 | $search_pattern = array( |
|
| 1025 | ' ', |
|
| 1026 | "\t", |
|
| 1027 | "\r\n", |
|
| 1028 | "\r", |
|
| 1029 | "\n", |
|
| 1030 | ',', |
|
| 1031 | '.', |
|
| 1032 | "'", |
|
| 1033 | ';', |
|
| 1034 | ':', |
|
| 1035 | ')', |
|
| 1036 | '(', |
|
| 1037 | '"', |
|
| 1038 | '?', |
|
| 1039 | '!', |
|
| 1040 | '{', |
|
| 1041 | '}', |
|
| 1042 | '[', |
|
| 1043 | ']', |
|
| 1044 | '<', |
|
| 1045 | '>', |
|
| 1046 | '/', |
|
| 1047 | '+', |
|
| 1048 | '-', |
|
| 1049 | '_', |
|
| 1050 | '\\', |
|
| 1051 | '*' |
|
| 1052 | ); |
|
| 1053 | $replace_pattern = array( |
|
| 1054 | ' ', |
|
| 1055 | ' ', |
|
| 1056 | ' ', |
|
| 1057 | ' ', |
|
| 1058 | ' ', |
|
| 1059 | ' ', |
|
| 1060 | ' ', |
|
| 1061 | ' ', |
|
| 1062 | '', |
|
| 1063 | '', |
|
| 1064 | '', |
|
| 1065 | '', |
|
| 1066 | '', |
|
| 1067 | '', |
|
| 1068 | '', |
|
| 1069 | '', |
|
| 1070 | '', |
|
| 1071 | '', |
|
| 1072 | '', |
|
| 1073 | '', |
|
| 1074 | '', |
|
| 1075 | '', |
|
| 1076 | '', |
|
| 1077 | '', |
|
| 1078 | '', |
|
| 1079 | '', |
|
| 1080 | '' |
|
| 1081 | ); |
|
| 1082 | $content = str_replace($search_pattern, $replace_pattern, $content); |
|
| 1083 | $keywords = explode(' ', $content); |
|
| 1084 | switch ($keywordsorder) { |
|
| 1085 | case 0: // Ordre d'apparition dans le texte |
|
| 1086 | $keywords = array_unique($keywords); |
|
| 1087 | break; |
|
| 1088 | case 1: // Ordre de fréquence des mots |
|
| 1089 | $keywords = array_count_values($keywords); |
|
| 1090 | asort($keywords); |
|
| 1091 | $keywords = array_keys($keywords); |
|
| 1092 | break; |
|
| 1093 | case 2: // Ordre inverse de la fréquence des mots |
|
| 1094 | $keywords = array_count_values($keywords); |
|
| 1095 | arsort($keywords); |
|
| 1096 | $keywords = array_keys($keywords); |
|
| 1097 | break; |
|
| 1098 | } |
|
| 1099 | // Remove black listed words |
|
| 1100 | if (xoops_trim(static::getModuleOption('metagen_blacklist')) != '') { |
|
| 1101 | $metagen_blacklist = str_replace("\r", '', static::getModuleOption('metagen_blacklist')); |
|
| 1102 | $metablack = explode("\n", $metagen_blacklist); |
|
| 1103 | array_walk($metablack, 'trim'); |
|
| 1104 | $keywords = array_diff($keywords, $metablack); |
|
| 1105 | } |
|
| 1106 | ||
| 1107 | foreach ($keywords as $keyword) { |
|
| 1108 | if (strlen($keyword) >= $limit && !is_numeric($keyword)) { |
|
| 1109 | $tmp[] = $keyword; |
|
| 1110 | } |
|
| 1111 | } |
|
| 1112 | $tmp = array_slice($tmp, 0, $keywordscount); |
|
| 1113 | if (count($tmp) > 0) { |
|
| 1114 | return implode(',', $tmp); |
|
| 1115 | } else { |
|
| 1116 | if (!isset($configHandler) || !is_object($configHandler)) { |
|
| 1117 | $configHandler = xoops_getHandler('config'); |
|
| 1118 | } |
|
| 1119 | $xoopsConfigMetaFooter = $configHandler->getConfigsByCat(XOOPS_CONF_METAFOOTER); |
|
| 1120 | if (isset($xoopsConfigMetaFooter['meta_keywords'])) { |
|
| 1121 | return $xoopsConfigMetaFooter['meta_keywords']; |
|
| 1122 | } else { |
|
| 1123 | return ''; |
|
| 1124 | } |
|
| 1125 | } |
|
| 1126 | } |
|
| 1127 | ||
| 1128 | /** |
|
| 1129 | * Fonction chargée de gérer l'upload |
|
| @@ 1147-1269 (lines=123) @@ | ||
| 1144 | * @param string $content Content from which we have to create metakeywords |
|
| 1145 | * @return string The list of meta keywords |
|
| 1146 | */ |
|
| 1147 | public static function createMetaKeywords($content) |
|
| 1148 | { |
|
| 1149 | $keywordscount = self::getModuleOption('metagen_maxwords'); |
|
| 1150 | $keywordsorder = self::getModuleOption('metagen_order'); |
|
| 1151 | ||
| 1152 | $tmp = array(); |
|
| 1153 | // Search for the "Minimum keyword length" |
|
| 1154 | if (isset($_SESSION['oledrion_keywords_limit'])) { |
|
| 1155 | $limit = $_SESSION['oledrion_keywords_limit']; |
|
| 1156 | } else { |
|
| 1157 | $configHandler = xoops_getHandler('config'); |
|
| 1158 | $xoopsConfigSearch = $configHandler->getConfigsByCat(XOOPS_CONF_SEARCH); |
|
| 1159 | $limit = $xoopsConfigSearch['keyword_min']; |
|
| 1160 | $_SESSION['oledrion_keywords_limit'] = $limit; |
|
| 1161 | } |
|
| 1162 | $myts = MyTextSanitizer::getInstance(); |
|
| 1163 | $content = str_replace('<br>', ' ', $content); |
|
| 1164 | $content = $myts->undoHtmlSpecialChars($content); |
|
| 1165 | $content = strip_tags($content); |
|
| 1166 | $content = strtolower($content); |
|
| 1167 | $search_pattern = array( |
|
| 1168 | ' ', |
|
| 1169 | "\t", |
|
| 1170 | "\r\n", |
|
| 1171 | "\r", |
|
| 1172 | "\n", |
|
| 1173 | ',', |
|
| 1174 | '.', |
|
| 1175 | "'", |
|
| 1176 | ';', |
|
| 1177 | ':', |
|
| 1178 | ')', |
|
| 1179 | '(', |
|
| 1180 | '"', |
|
| 1181 | '?', |
|
| 1182 | '!', |
|
| 1183 | '{', |
|
| 1184 | '}', |
|
| 1185 | '[', |
|
| 1186 | ']', |
|
| 1187 | '<', |
|
| 1188 | '>', |
|
| 1189 | '/', |
|
| 1190 | '+', |
|
| 1191 | '-', |
|
| 1192 | '_', |
|
| 1193 | '\\', |
|
| 1194 | '*' |
|
| 1195 | ); |
|
| 1196 | $replace_pattern = array( |
|
| 1197 | ' ', |
|
| 1198 | ' ', |
|
| 1199 | ' ', |
|
| 1200 | ' ', |
|
| 1201 | ' ', |
|
| 1202 | ' ', |
|
| 1203 | ' ', |
|
| 1204 | ' ', |
|
| 1205 | '', |
|
| 1206 | '', |
|
| 1207 | '', |
|
| 1208 | '', |
|
| 1209 | '', |
|
| 1210 | '', |
|
| 1211 | '', |
|
| 1212 | '', |
|
| 1213 | '', |
|
| 1214 | '', |
|
| 1215 | '', |
|
| 1216 | '', |
|
| 1217 | '', |
|
| 1218 | '', |
|
| 1219 | '', |
|
| 1220 | '', |
|
| 1221 | '', |
|
| 1222 | '', |
|
| 1223 | '' |
|
| 1224 | ); |
|
| 1225 | $content = str_replace($search_pattern, $replace_pattern, $content); |
|
| 1226 | $keywords = explode(' ', $content); |
|
| 1227 | switch ($keywordsorder) { |
|
| 1228 | case 0: // Ordre d'apparition dans le texte |
|
| 1229 | $keywords = array_unique($keywords); |
|
| 1230 | break; |
|
| 1231 | case 1: // Ordre de fréquence des mots |
|
| 1232 | $keywords = array_count_values($keywords); |
|
| 1233 | asort($keywords); |
|
| 1234 | $keywords = array_keys($keywords); |
|
| 1235 | break; |
|
| 1236 | case 2: // Ordre inverse de la fréquence des mots |
|
| 1237 | $keywords = array_count_values($keywords); |
|
| 1238 | arsort($keywords); |
|
| 1239 | $keywords = array_keys($keywords); |
|
| 1240 | break; |
|
| 1241 | } |
|
| 1242 | // Remove black listed words |
|
| 1243 | if (xoops_trim(self::getModuleOption('metagen_blacklist')) != '') { |
|
| 1244 | $metagen_blacklist = str_replace("\r", '', self::getModuleOption('metagen_blacklist')); |
|
| 1245 | $metablack = explode("\n", $metagen_blacklist); |
|
| 1246 | array_walk($metablack, 'trim'); |
|
| 1247 | $keywords = array_diff($keywords, $metablack); |
|
| 1248 | } |
|
| 1249 | ||
| 1250 | foreach ($keywords as $keyword) { |
|
| 1251 | if (strlen($keyword) >= $limit && !is_numeric($keyword)) { |
|
| 1252 | $tmp[] = $keyword; |
|
| 1253 | } |
|
| 1254 | } |
|
| 1255 | $tmp = array_slice($tmp, 0, $keywordscount); |
|
| 1256 | if (count($tmp) > 0) { |
|
| 1257 | return implode(',', $tmp); |
|
| 1258 | } else { |
|
| 1259 | if (!isset($configHandler) || !is_object($configHandler)) { |
|
| 1260 | $configHandler = xoops_getHandler('config'); |
|
| 1261 | } |
|
| 1262 | $xoopsConfigMetaFooter = $configHandler->getConfigsByCat(XOOPS_CONF_METAFOOTER); |
|
| 1263 | if (isset($xoopsConfigMetaFooter['meta_keywords'])) { |
|
| 1264 | return $xoopsConfigMetaFooter['meta_keywords']; |
|
| 1265 | } else { |
|
| 1266 | return ''; |
|
| 1267 | } |
|
| 1268 | } |
|
| 1269 | } |
|
| 1270 | ||
| 1271 | /** |
|
| 1272 | * Fonction chargée de gérer l'upload |
|