protected function beforeParsing()
 {
     $this->duplicateChecker = new GoogleDuplicateChecker();
     $this->duplicateChecker->setPhrasesToCheckCount(Config::get('duplicateContentCheckerPhrasesToCheckCount'))->setWordsInPhraseCount(Config::get('duplicateContentCheckerWordsInPhraseCount'))->setAllowableDuplicatedPhrasesCount(Config::get('duplicateContentCheckerAllowableDuplicatedPhrasesCount'));
 }
Ejemplo n.º 2
0
 function validate($newSite, $oldSite = null, $validationOptions = array())
 {
     $categoryId = intval($newSite->categoryId);
     $url = !empty($newSite->url) ? $newSite->url : "";
     $isAdmin = !empty($validationOptions['admin']);
     $package = !empty($validationOptions['package']) ? $validationOptions['package'] : null;
     // required fields validation
     if (empty($newSite->siteTitle) || !isset($newSite->description)) {
         return 'Please, fill in the fields title and Description.';
     }
     if (empty($categoryId)) {
         return 'Please, select a category from the dropdown list.';
     }
     if (Config::get("urlMandatory") && empty($url)) {
         return 'Please fill URL field';
     }
     if (!empty($url)) {
         // ensure that site is not registered in this category
         if ((!$oldSite || $oldSite->categoryId != $categoryId) && !$isAdmin && empty($validationOptions['forceCategoryDuplicate']) && $this->whetherSiteIsRegisteredInCategory($url, $categoryId)) {
             return 'The site is already registered in this category.';
         }
         // check whether the URL is allowed to be offered
         if (!preg_match('#^' . Config::get("supportedUrlSchemes") . '://#', $url)) {
             return 'We do not support this url protocol';
         }
         if (!preg_match('#^' . Config::get("supportedUrlSchemes") . '://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$#i', $url)) {
             return 'Url is invalid';
         }
         if ($this->getIfHostIsBanned(AppRouter::getHostNameFromUrl($url), 0)) {
             return 'This site is not allowed to be offered.';
         }
         if ($this->bannedSite->isBanned($url)) {
             return 'This site is not allowed to be offered.';
         }
         if (!$oldSite && !$isAdmin) {
             if ((int) $this->getCountOfSiteCopiesInDifferentCategories($url) >= (int) Config::get('maxCategoriesCountPerSite')) {
                 return 'This site is not allowed to be offered more times.';
             }
             if ((int) $this->getCountOfSiteSubpages($url) >= (int) Config::get('maxSubpagesCountPerSite')) {
                 return 'No more subpages of this site can be submitted.';
             }
         }
         if (Config::get('inscriptionCheckHttpResponseCode') == 1) {
             $httpClient = new HttpClient();
             $httpCode = $httpClient->checkResponseCodeOfSite($url);
             if ($httpCode != 200) {
                 return 'This site\' HTTP response code is not 200. The site is not accepted.';
             }
         }
     }
     if (!$isAdmin) {
         $minSiteDescriptionLength = $package ? $package['siteDescriptionMinLength'] : Config::get("minSiteDescriptionLength");
         $rawDescription = strip_tags($newSite->description);
         if ($minSiteDescriptionLength && utf8_strlen($rawDescription) < $minSiteDescriptionLength && !$isAdmin) {
             return _t('Description of site must have minimum') . ' ' . $minSiteDescriptionLength . ' ' . _t('characters length.');
         }
         $siteDescriptionMaxLength = $package ? $package['siteDescriptionMaxLength'] : Config::get('siteDescriptionMaxLength');
         if ($siteDescriptionMaxLength && utf8_strlen($rawDescription) > $siteDescriptionMaxLength) {
             return _t('Description of site must have maximum') . ' ' . $siteDescriptionMaxLength . ' ' . _t('characters length.');
         }
     }
     if (Config::get('backLinkMandatory') && (!$package || $package['backLinkMandatory']) && empty($newSite->returnBond) && !$isAdmin) {
         return 'Backlink is mandatory.';
     }
     if (Config::get('countryFlagsEnabled') && empty($newSite->countryCode) && !$isAdmin) {
         return 'Country is mandatory.';
     }
     $category = $this->category->findByPk($categoryId);
     if (!$category || !$isAdmin && $category->possibleTender != 1 && empty($validationOptions['forcePossibleTender'])) {
         return 'Sites cannot be offered for this category.';
     }
     if ($this->bannedEmail->isBanned($newSite->webmasterEmail) && !$isAdmin) {
         return 'This email is banned.';
     }
     if ($this->bannedIp->isBanned(Request::getInstance()->getIp())) {
         return 'Your IP is banned.';
     }
     if (Config::get('duplicateContentCheckerEnabled') && !$isAdmin) {
         $duplicateChecker = new GoogleDuplicateChecker();
         $duplicateChecker->setPhrasesToCheckCount(Config::get('duplicateContentCheckerPhrasesToCheckCount'))->setWordsInPhraseCount(Config::get('duplicateContentCheckerWordsInPhraseCount'))->setAllowableDuplicatedPhrasesCount(Config::get('duplicateContentCheckerAllowableDuplicatedPhrasesCount'));
         if ($duplicateChecker->isDuplicateContent($newSite->description)) {
             return 'We have detected duplicate content, change your description.';
         }
     }
     $errorMessage = $this->extraField->validate($newSite);
     if ($errorMessage) {
         return $errorMessage;
     }
     return '';
 }