1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
| <?php // no direct access
defined('_JEXEC') or die('Restricted access');
define("PERCENT_COMMON_WORDS", 75.0);
define("CAUSE_NEW_TWEET", 0);
define("CAUSE_RETWEET_PERCENT", 2);
function CheckReTweet($strMsg, $strUrlTweet, &$arrTweet, &$arrText)
{ // True if at least PERCENT_COMMON_WORDS of similarity between tweets
if (is_array($arrText))
{
$strMsgNew = Tokenization($strMsg);
foreach ($arrText as $strUrlOld => $strMsgOld)
{
$strMsgCmp = Tokenization($strMsgOld);
$nbrMatchChar = similar_text($strMsgNew, $strMsgCmp, $percent);
if ($percent >= PERCENT_COMMON_WORDS)
{
unset($arrTweet[$strUrlOld]); // Remove the Re-Tweet key / value
unset($arrText[$strUrlOld]);
return CAUSE_RETWEET_PERCENT;
}
}
}
return CAUSE_NEW_TWEET;
} // end CheckReTweet
function Tokenization($strTxt)
{ // Remove punctuation and duplicated blanks, trim string, force lower case
$strTok = $strTxt;
$strTok = str_replace("à", "a", $strTok);
$strTok = str_replace("â", "a", $strTok);
$strTok = str_replace("é", "e", $strTok);
$strTok = str_replace("è", "e", $strTok);
$strTok = str_replace("ê", "e", $strTok);
$strTok = str_replace("î", "i", $strTok);
$strTok = str_replace("ô", "o", $strTok);
$strTok = str_replace("ù", "u", $strTok);
$strTok = str_replace(".", " ", $strTok);
$strTok = str_replace(",", " ", $strTok);
$strTok = str_replace(";", " ", $strTok);
$strTok = str_replace(":", " ", $strTok);
$strTok = str_replace("!", " ", $strTok);
$strTok = str_replace("?", " ", $strTok);
$strTok = str_replace('"', " ", $strTok);
$strTok = preg_replace("/\s+/", " ", $strTok);
$strTok = trim($strTok);
$strTok = strtolower($strTok); // strtolower corrupts accents. So convert them before!
return $strTok;
} // end Tokenization |
Partager