/** * * @param string $url * @param PCModelUser $user * @param string $comment * @param string $usability * @param string $contents * @param string $reliability * @param string $categoty * @param string $language * @param string $error * @param string $siteIdentifier * @return bool */ public static function addSiteWithReview($url, $user, $comment, $usability, $contents, $reliability, $category, $language, &$error, $siteIdentifier = null) { //estraggo l' hostname dell'URL //Se è stato specificato l' identificativo del sito if (!empty($siteIdentifier)) { $site = PCModelManager::fetchObjectWithIdentifier(PCModelWebsite::getMapper(), $siteIdentifier, NULL, TRUE); if (isset($site) == FALSE) { $error = "Site not found"; return FALSE; } $error3 = NULL; if (PCMapperReview::addReviewForSite($site, $user, $comment, $usability, $contents, $reliability, $language, $error3)) { return TRUE; } $error = $error3; return FALSE; } //se p stato specificato l'URL del sito $parsedUrl = parse_url($url); $scheme = $parsedUrl['scheme']; if ($scheme == NULL || strcmp($scheme, "http") != 0 && strcmp($scheme, "https") != 0) { $scheme = 'http'; } $host = $parsedUrl['host']; if ($host == NULL) { $error = "URL not valid"; return FALSE; } $site = static::getSiteWithDomain($host); //costruisco l'URL da verificare(reggiungibilità) $buildedUrl = $scheme . "://" . $host; //se il sito non è presente lo aggiungo if ($site == NULL) { if (PCMapperCategory::existsCategoryWithIdentifier($category) == FALSE) { $error = "Category is not valid"; return FALSE; } $tld = static::getTLDFromURL($buildedUrl); if (static::checkForWebsiteReachability($buildedUrl) == FALSE) { $error = "Error: site not reachable"; return FALSE; } $date_added = new DateTime('now', new DateTimeZone('UTC')); $date_added_mysql = $date_added->format('Y-m-d H:i:s'); $values = array('domain' => $host, 'date_added' => $date_added_mysql, 'tld' => $tld, 'category' => $category, 'user' => $user->getIdentifier()); if (PCModelManager::insertObject(PCModelWebsite::getMapper(), $values)) { $site = static::getSiteWithDomain($host); } else { $error = "Error adding website, please try later"; return FALSE; } } if ($site == NULL) { $error = "Error adding website, please try later"; return FALSE; } $error2 = NULL; if (PCMapperReview::addReviewForSite($site, $user, $comment, $usability, $contents, $reliability, $language, $error2)) { return TRUE; } $error = $error2; return FALSE; }