コード例 #1
0
ファイル: CommentManager.php プロジェクト: kanso-cms/cms
 /**
  * Black or whitelist or remove from both an IP address from commenting
  *
  * @param  array    $comment    The comment array from the database
  * @return null
  */
 public static function moderateIp($ipAddress, $blackOrWhiteList)
 {
     if ($blackOrWhiteList === 'whitelist') {
         \Kanso\Comments\Spam\SpamProtector::appendToDictionary($ipAddress, 'whitelist_ip');
         \Kanso\Comments\Spam\SpamProtector::removeFromDictionary($ipAddress, 'blacklist_ip');
     } else {
         if ($blackOrWhiteList === 'blacklist') {
             \Kanso\Comments\Spam\SpamProtector::appendToDictionary($ipAddress, 'blacklist_ip');
             \Kanso\Comments\Spam\SpamProtector::removeFromDictionary($ipAddress, 'whitelist_ip');
         } else {
             if ($blackOrWhiteList === 'nolist') {
                 \Kanso\Comments\Spam\SpamProtector::removeFromDictionary($ipAddress, 'blacklist_ip');
                 \Kanso\Comments\Spam\SpamProtector::removeFromDictionary($ipAddress, 'whitelist_ip');
             }
         }
     }
 }
コード例 #2
0
ファイル: Ajax.php プロジェクト: kanso-cms/cms
 /**
  * Get a single info on the comment
  *
  * @param  $queries    array     POST data from client
  * @param  $filter     string
  * @return array
  */
 public function getCommentInfo($queries)
 {
     # Get the SQL builder
     $SQL = \Kanso\Kanso::getInstance()->Database->Builder();
     $commentRow = $SQL->SELECT('*')->FROM('comments')->WHERE('id', '=', (int) $queries['comment_id'])->FIND();
     # If it doesn't exist return false
     if (!$commentRow) {
         return false;
     }
     $ip_address = $commentRow['ip_address'];
     $name = $commentRow['name'];
     $email = $commentRow['email'];
     # Get all the user's comments
     $userComments = $SQL->SELECT('*')->FROM('comments')->WHERE('ip_address', '=', $ip_address)->OR_WHERE('email', '=', $email)->OR_WHERE('name', '=', $name)->FIND_ALL();
     $response = ['reputation' => 0, 'posted_count' => 0, 'spam_count' => 0, 'first_date' => 0, 'blacklisted' => false, 'whitelisted' => false, 'ip_address' => $ip_address, 'name' => $name, 'email' => $email, 'avatar' => \Kanso\Kanso::getInstance()->Query->get_avatar($email, 150, true), 'status' => $commentRow['status'], 'content' => $commentRow['content'], 'html_content' => $commentRow['html_content']];
     $blacklistedIps = \Kanso\Comments\Spam\SpamProtector::loadDictionary('blacklist_ip');
     $whiteListedIps = \Kanso\Comments\Spam\SpamProtector::loadDictionary('whitelist_ip');
     foreach ($userComments as $comment) {
         $response['reputation'] += $comment['rating'];
         $response['posted_count'] += 1;
         if ($comment['status'] === 'spam') {
             $response['spam_count'] += 1;
         }
         if ($comment['date'] < $response['first_date'] || $response['first_date'] === 0) {
             $response['first_date'] = $comment['date'];
         }
     }
     $response['reputation'] = $response['reputation'] / count($userComments);
     if (in_array($ip_address, $blacklistedIps)) {
         $response['blacklisted'] = true;
     }
     if (in_array($ip_address, $whiteListedIps)) {
         $response['whitelisted'] = true;
     }
     return $response;
 }