Esempio n. 1
0
 public static function import($jsonDatas, $keep_ids = FALSE, $logged = FALSE)
 {
     global $_CONFIG;
     if (!$logged) {
         die('You are not authorized to import books.');
     }
     $datas = json_decode($jsonDatas, TRUE);
     if (!isset($datas['books']) || !isset($datas['posters'])) {
         return FALSE;
     }
     $booksDatas = $datas['books'];
     $images = $datas['posters'];
     $id = time();
     $i = 0;
     $books = new Books($logged);
     foreach ($booksDatas as $book) {
         $id = $keep_ids && isset($book['id']) ? $book['id'] : $id;
         while (isset($books[$id])) {
             $id--;
         }
         $inputs = array('id' => $id, 'title' => isset($book['title']) ? trim(self::html_escaped($book['title'])) : NULL, 'author' => isset($book['author']) ? trim(self::html_escaped($book['author'])) : NULL, 'summary' => isset($book['summary']) ? checkNewLineContent(preg_replace('#<br( /)?>#', '', $book['summary'])) : NULL, 'publisher' => isset($book['publisher']) ? trim(self::html_escaped($book['publisher'])) : NULL, 'status' => isset($book['status']) && $book['status'] != NULL ? Book::SEEN : NULL, 'note' => isset($book['note']) ? checkRatingNote($book['note'], isset($book['status']) && $book['status'] != NULL ? Book::SEEN : NULL) : NULL, 'read_date' => isset($book['read_date']) ? checkInputDate($book['read_date']) : NULL, 'review' => isset($book['review']) ? checkNewLineContent(preg_replace('#<br( /)?>#', '', $book['review'])) : NULL, 'genre' => isset($book['genre']) ? checkGenre($book['genre']) : NULL, 'publication_year' => isset($book['release_date']) ? checkInputYear($book['release_date']) : NULL, 'pages' => isset($book['pages']) ? checkPages($book['pages']) : NULL, 'country' => isset($book['country']) ? checkCountry($book['country']) : NULL, 'link_website' => isset($book['link_website']) ? checkLink($book['link_website']) : NULL, 'link_image' => NULL);
         if (empty($inputs['title']) && empty($inputs['author']) && empty($inputs['summary'])) {
             continue;
         }
         if (function_exists('imagecreatefromjpeg') && !empty($images[$i])) {
             $image = explode(',', $images[$i]);
             if (!isset($image[1])) {
                 continue;
             }
             $imported = file_put_contents($_CONFIG['images'] . '/' . $id . '.jpg', base64_decode($image[1]));
             if ($imported == false) {
                 continue;
             }
             $inputs['link_image'] = $_CONFIG['images'] . '/' . $id . '.jpg';
         }
         $books[$id] = $inputs;
         $i++;
     }
     $books->save();
     return TRUE;
 }
$archivesLinks = array("January" => "http://www.[DOMAIN].net/January.html", "February" => "http://www.[DOMAIN].net/February.html", "March" => "http://www.[DOMAIN].net/March.html", "April" => "http://www.[DOMAIN].net/April.html", "May" => "http://www.[DOMAIN].net/May.html", "June" => "http://www.[DOMAIN].net/June.html", "July" => "http://www.[DOMAIN].net/July.html", "August" => "http://www.[DOMAIN].net/August.html", "September" => "http://www.[DOMAIN].net/September.html", "October" => "http://www.[DOMAIN].net/October.html", "November" => "http://www.[DOMAIN].net/November.html", "December" => "http://www.[DOMAIN].net/December.html");
define("LINK_PATTERN", '{<a\\s+href="([^"]+)">%s\\s+\\d+:.+?</a><br>}si');
define("RED_MIN", "f0");
define("RED_MAX", "ff");
define("GREEN_MIN", "f0");
define("GREEN_MAX", "ff");
define("BLUE_MIN", "70");
define("BLUE_MAX", "90");
foreach ($archivesLinks as $archive => $url) {
    $pattern = sprintf(LINK_PATTERN, $archive);
    print "Load archive: " . $url . "...\n";
    $content = file_get_contents($url);
    if (!preg_match_all($pattern, $content, $matches, PREG_PATTERN_ORDER)) {
        continue;
    }
    checkPages($matches[1]);
}
saveContents("processResult.txt", "Processing finished.");
function colorRGB($hexColor)
{
    if ($hexColor[0] != "#") {
        return array("0", "0", "0");
    }
    $r = substr($hexColor, 1, 2);
    $g = substr($hexColor, 3, 2);
    $b = substr($hexColor, 5, 2);
    return array($r, $g, $b);
}
/**
 * Проверка галеры на наличие заданого цвета
 */