@@ -163,7 +163,7 @@ |
||
| 163 | 163 | /** |
| 164 | 164 | * Replaces a Unicode character using the transliteration database. |
| 165 | 165 | * |
| 166 | - * @param $ord |
|
| 166 | + * @param integer $ord |
|
| 167 | 167 | * An ordinal Unicode character code. |
| 168 | 168 | * @param $unknown |
| 169 | 169 | * Replacement string for characters that do not have a suitable ASCII |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | // Counting down is faster. I'm *so* sorry. |
| 91 | 91 | $len = $chunk + 1; |
| 92 | 92 | |
| 93 | - for ($i = -1; --$len; ) { |
|
| 93 | + for ($i = -1; --$len;) { |
|
| 94 | 94 | $c = $str[++$i]; |
| 95 | 95 | if ($remaining = $tail_bytes[$c]) { |
| 96 | 96 | // UTF-8 head byte! |
@@ -207,5 +207,5 @@ discard block |
||
| 207 | 207 | |
| 208 | 208 | $ord = $ord & 255; |
| 209 | 209 | |
| 210 | - return isset($map[$bank][$langcode][$ord]) ? $map[$bank][$langcode][$ord] : $unknown; |
|
| 210 | + return isset($map[$bank][$langcode][$ord])?$map[$bank][$langcode][$ord]:$unknown; |
|
| 211 | 211 | } |
@@ -2,11 +2,11 @@ discard block |
||
| 2 | 2 | |
| 3 | 3 | require_once ("config.php"); |
| 4 | 4 | |
| 5 | -function checkConfiguration () { |
|
| 5 | +function checkConfiguration() { |
|
| 6 | 6 | global $config; |
| 7 | 7 | |
| 8 | - if (is_null ($config['cops_mail_configuration']) || |
|
| 9 | - !is_array ($config['cops_mail_configuration']) || |
|
| 8 | + if (is_null($config['cops_mail_configuration']) || |
|
| 9 | + !is_array($config['cops_mail_configuration']) || |
|
| 10 | 10 | empty ($config['cops_mail_configuration']["smtp.host"]) || |
| 11 | 11 | empty ($config['cops_mail_configuration']["address.from"])) { |
| 12 | 12 | return "NOK. bad configuration."; |
@@ -14,7 +14,7 @@ discard block |
||
| 14 | 14 | return False; |
| 15 | 15 | } |
| 16 | 16 | |
| 17 | -function checkRequest ($idData, $emailDest) { |
|
| 17 | +function checkRequest($idData, $emailDest) { |
|
| 18 | 18 | if (empty ($idData)) { |
| 19 | 19 | return 'No data sent.'; |
| 20 | 20 | } |
@@ -28,22 +28,22 @@ discard block |
||
| 28 | 28 | |
| 29 | 29 | global $config; |
| 30 | 30 | |
| 31 | -if ($error = checkConfiguration ()) { |
|
| 31 | +if ($error = checkConfiguration()) { |
|
| 32 | 32 | echo $error; |
| 33 | 33 | exit; |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | $idData = $_REQUEST["data"]; |
| 37 | 37 | $emailDest = $_REQUEST["email"]; |
| 38 | -if ($error = checkRequest ($idData, $emailDest)) { |
|
| 38 | +if ($error = checkRequest($idData, $emailDest)) { |
|
| 39 | 39 | echo $error; |
| 40 | 40 | exit; |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | $book = Book::getBookByDataId($idData); |
| 44 | -$data = $book->getDataById ($idData); |
|
| 44 | +$data = $book->getDataById($idData); |
|
| 45 | 45 | |
| 46 | -if (filesize ($data->getLocalPath ()) > 10 * 1024 * 1024) { |
|
| 46 | +if (filesize($data->getLocalPath()) > 10 * 1024 * 1024) { |
|
| 47 | 47 | echo 'Attachment too big'; |
| 48 | 48 | exit; |
| 49 | 49 | } |
@@ -65,23 +65,23 @@ discard block |
||
| 65 | 65 | $mail->From = $config['cops_mail_configuration']["address.from"]; |
| 66 | 66 | $mail->FromName = $config['cops_title_default']; |
| 67 | 67 | |
| 68 | -foreach (explode (";", $emailDest) as $emailAddress) { |
|
| 68 | +foreach (explode(";", $emailDest) as $emailAddress) { |
|
| 69 | 69 | if (empty ($emailAddress)) { continue; } |
| 70 | 70 | $mail->AddAddress($emailAddress); |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | -$mail->AddAttachment($data->getLocalPath ()); |
|
| 73 | +$mail->AddAttachment($data->getLocalPath()); |
|
| 74 | 74 | |
| 75 | 75 | $mail->IsHTML(true); |
| 76 | -$mail->Subject = 'Sent by COPS : ' . $data->getUpdatedFilename (); |
|
| 77 | -$mail->Body = "<h1>" . $book->title . "</h1><h2>" . $book->getAuthorsName () . "</h2>" . $book->getComment (); |
|
| 76 | +$mail->Subject = 'Sent by COPS : ' . $data->getUpdatedFilename(); |
|
| 77 | +$mail->Body = "<h1>" . $book->title . "</h1><h2>" . $book->getAuthorsName() . "</h2>" . $book->getComment(); |
|
| 78 | 78 | $mail->AltBody = "Sent by COPS"; |
| 79 | 79 | |
| 80 | 80 | if (!$mail->Send()) { |
| 81 | - echo localize ("mail.messagenotsent"); |
|
| 81 | + echo localize("mail.messagenotsent"); |
|
| 82 | 82 | echo 'Mailer Error: ' . $mail->ErrorInfo; |
| 83 | 83 | exit; |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | -echo localize ("mail.messagesent"); |
|
| 86 | +echo localize("mail.messagesent"); |
|
| 87 | 87 | |
@@ -60,6 +60,9 @@ discard block |
||
| 60 | 60 | $_SERVER['REDIRECT_STATUS'] = 404; |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | +/** |
|
| 64 | + * @param string $name |
|
| 65 | + */ |
|
| 63 | 66 | function getURLParam ($name, $default = NULL) { |
| 64 | 67 | if (!empty ($_GET) && isset($_GET[$name]) && $_GET[$name] != "") { |
| 65 | 68 | return $_GET[$name]; |
@@ -95,6 +98,11 @@ discard block |
||
| 95 | 98 | return $url . "?v=" . VERSION; |
| 96 | 99 | } |
| 97 | 100 | |
| 101 | +/** |
|
| 102 | + * @param string $xml |
|
| 103 | + * |
|
| 104 | + * @return string |
|
| 105 | + */ |
|
| 98 | 106 | function xml2xhtml($xml) { |
| 99 | 107 | return preg_replace_callback('#<(\w+)([^>]*)\s*/>#s', create_function('$m', ' |
| 100 | 108 | $xhtml_tags = array("br", "hr", "input", "frame", "img", "area", "link", "col", "base", "basefont", "param"); |
@@ -308,6 +316,9 @@ discard block |
||
| 308 | 316 | return $phrase; |
| 309 | 317 | } |
| 310 | 318 | |
| 319 | +/** |
|
| 320 | + * @param string $paramName |
|
| 321 | + */ |
|
| 311 | 322 | function addURLParameter($urlParams, $paramName, $paramValue) { |
| 312 | 323 | if (empty ($urlParams)) { |
| 313 | 324 | $urlParams = ""; |
@@ -8,8 +8,8 @@ discard block |
||
| 8 | 8 | |
| 9 | 9 | require_once 'config.php'; |
| 10 | 10 | |
| 11 | -define ('VERSION', '1.0.0RC4'); |
|
| 12 | -define ('DB', 'db'); |
|
| 11 | +define('VERSION', '1.0.0RC4'); |
|
| 12 | +define('DB', 'db'); |
|
| 13 | 13 | date_default_timezone_set($config['default_timezone']); |
| 14 | 14 | |
| 15 | 15 | |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | function serverSideRender($data) |
| 23 | 23 | { |
| 24 | 24 | // Get the templates |
| 25 | - $theme = getCurrentTemplate (); |
|
| 25 | + $theme = getCurrentTemplate(); |
|
| 26 | 26 | $header = file_get_contents('templates/' . $theme . '/header.html'); |
| 27 | 27 | $footer = file_get_contents('templates/' . $theme . '/footer.html'); |
| 28 | 28 | $main = file_get_contents('templates/' . $theme . '/main.html'); |
@@ -30,8 +30,8 @@ discard block |
||
| 30 | 30 | $page = file_get_contents('templates/' . $theme . '/page.html'); |
| 31 | 31 | |
| 32 | 32 | // Generate the function for the template |
| 33 | - $template = new doT (); |
|
| 34 | - $dot = $template->template ($page, array ('bookdetail' => $bookdetail, |
|
| 33 | + $template = new doT(); |
|
| 34 | + $dot = $template->template($page, array('bookdetail' => $bookdetail, |
|
| 35 | 35 | 'header' => $header, |
| 36 | 36 | 'footer' => $footer, |
| 37 | 37 | 'main' => $main)); |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | } |
| 43 | 43 | // Execute the template |
| 44 | 44 | if (!empty ($data)) { |
| 45 | - return $dot ($data); |
|
| 45 | + return $dot($data); |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | return NULL; |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | |
| 59 | 59 | function notFound() |
| 60 | 60 | { |
| 61 | - header($_SERVER['SERVER_PROTOCOL'].' 404 Not Found'); |
|
| 61 | + header($_SERVER['SERVER_PROTOCOL'] . ' 404 Not Found'); |
|
| 62 | 62 | header('Status: 404 Not Found'); |
| 63 | 63 | |
| 64 | 64 | $_SERVER['REDIRECT_STATUS'] = 404; |
@@ -76,8 +76,8 @@ discard block |
||
| 76 | 76 | { |
| 77 | 77 | global $config; |
| 78 | 78 | if (isset($_COOKIE[$option])) { |
| 79 | - if (isset($config ['cops_' . $option]) && is_array ($config ['cops_' . $option])) { |
|
| 80 | - return explode (',', $_COOKIE[$option]); |
|
| 79 | + if (isset($config ['cops_' . $option]) && is_array($config ['cops_' . $option])) { |
|
| 80 | + return explode(',', $_COOKIE[$option]); |
|
| 81 | 81 | } else { |
| 82 | 82 | return $_COOKIE[$option]; |
| 83 | 83 | } |
@@ -91,12 +91,12 @@ discard block |
||
| 91 | 91 | |
| 92 | 92 | function getCurrentCss() |
| 93 | 93 | { |
| 94 | - return 'templates/' . getCurrentTemplate () . '/styles/style-' . getCurrentOption('style') . '.css'; |
|
| 94 | + return 'templates/' . getCurrentTemplate() . '/styles/style-' . getCurrentOption('style') . '.css'; |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | function getCurrentTemplate() |
| 98 | 98 | { |
| 99 | - return getCurrentOption ('template'); |
|
| 99 | + return getCurrentOption('template'); |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | function getUrlWithVersion($url) |
@@ -160,10 +160,10 @@ discard block |
||
| 160 | 160 | libxml_use_internal_errors(true); |
| 161 | 161 | |
| 162 | 162 | $doc->loadHTML('<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body>' . |
| 163 | - $html . '</body></html>'); // Load the HTML |
|
| 163 | + $html . '</body></html>'); // Load the HTML |
|
| 164 | 164 | $output = $doc->saveXML($doc->documentElement); // Transform to an Ansi xml stream |
| 165 | 165 | $output = xml2xhtml($output); |
| 166 | - if (preg_match ('#<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></meta></head><body>(.*)</body></html>#ms', $output, $matches)) { |
|
| 166 | + if (preg_match('#<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></meta></head><body>(.*)</body></html>#ms', $output, $matches)) { |
|
| 167 | 167 | $output = $matches [1]; // Remove <html><body> |
| 168 | 168 | } |
| 169 | 169 | /* |
@@ -175,7 +175,7 @@ discard block |
||
| 175 | 175 | } |
| 176 | 176 | */ |
| 177 | 177 | |
| 178 | - if (!are_libxml_errors_ok ()) $output = 'HTML code not valid.'; |
|
| 178 | + if (!are_libxml_errors_ok()) $output = 'HTML code not valid.'; |
|
| 179 | 179 | |
| 180 | 180 | libxml_use_internal_errors(false); |
| 181 | 181 | return $output; |
@@ -264,7 +264,7 @@ discard block |
||
| 264 | 264 | //echo var_dump($langs); |
| 265 | 265 | $lang_file = NULL; |
| 266 | 266 | foreach ($langs as $language => $val) { |
| 267 | - $temp_file = dirname(__FILE__). '/lang/Localization_' . $language . '.json'; |
|
| 267 | + $temp_file = dirname(__FILE__) . '/lang/Localization_' . $language . '.json'; |
|
| 268 | 268 | if (file_exists($temp_file)) { |
| 269 | 269 | $lang = $language; |
| 270 | 270 | $lang_file = $temp_file; |
@@ -272,7 +272,7 @@ discard block |
||
| 272 | 272 | } |
| 273 | 273 | } |
| 274 | 274 | if (empty ($lang_file)) { |
| 275 | - $lang_file = dirname(__FILE__). '/lang/Localization_' . $lang . '.json'; |
|
| 275 | + $lang_file = dirname(__FILE__) . '/lang/Localization_' . $lang . '.json'; |
|
| 276 | 276 | } |
| 277 | 277 | return array($lang, $lang_file); |
| 278 | 278 | } |
@@ -281,7 +281,7 @@ discard block |
||
| 281 | 281 | * This method is based on this page |
| 282 | 282 | * http://www.mind-it.info/2010/02/22/a-simple-approach-to-localization-in-php/ |
| 283 | 283 | */ |
| 284 | -function localize($phrase, $count=-1, $reset=false) |
|
| 284 | +function localize($phrase, $count = -1, $reset = false) |
|
| 285 | 285 | { |
| 286 | 286 | global $config; |
| 287 | 287 | if ($count == 0) |
@@ -301,7 +301,7 @@ discard block |
||
| 301 | 301 | $lang_file_en = NULL; |
| 302 | 302 | list ($lang, $lang_file) = getLangAndTranslationFile(); |
| 303 | 303 | if ($lang != 'en') { |
| 304 | - $lang_file_en = dirname(__FILE__). '/lang/' . 'Localization_en.json'; |
|
| 304 | + $lang_file_en = dirname(__FILE__) . '/lang/' . 'Localization_en.json'; |
|
| 305 | 305 | } |
| 306 | 306 | |
| 307 | 307 | $lang_file_content = file_get_contents($lang_file); |
@@ -309,8 +309,8 @@ discard block |
||
| 309 | 309 | $translations = json_decode($lang_file_content, true); |
| 310 | 310 | |
| 311 | 311 | /* Clean the array of all unfinished translations */ |
| 312 | - foreach (array_keys ($translations) as $key) { |
|
| 313 | - if (preg_match ('/^##TODO##/', $key)) { |
|
| 312 | + foreach (array_keys($translations) as $key) { |
|
| 313 | + if (preg_match('/^##TODO##/', $key)) { |
|
| 314 | 314 | unset ($translations [$key]); |
| 315 | 315 | } |
| 316 | 316 | } |
@@ -318,10 +318,10 @@ discard block |
||
| 318 | 318 | { |
| 319 | 319 | $lang_file_content = file_get_contents($lang_file_en); |
| 320 | 320 | $translations_en = json_decode($lang_file_content, true); |
| 321 | - $translations = array_merge ($translations_en, $translations); |
|
| 321 | + $translations = array_merge($translations_en, $translations); |
|
| 322 | 322 | } |
| 323 | 323 | } |
| 324 | - if (array_key_exists ($phrase, $translations)) { |
|
| 324 | + if (array_key_exists($phrase, $translations)) { |
|
| 325 | 325 | return $translations[$phrase]; |
| 326 | 326 | } |
| 327 | 327 | return $phrase; |
@@ -333,7 +333,7 @@ discard block |
||
| 333 | 333 | $urlParams = ''; |
| 334 | 334 | } |
| 335 | 335 | $start = ''; |
| 336 | - if (preg_match ('#^\?(.*)#', $urlParams, $matches)) { |
|
| 336 | + if (preg_match('#^\?(.*)#', $urlParams, $matches)) { |
|
| 337 | 337 | $start = '?'; |
| 338 | 338 | $urlParams = $matches[1]; |
| 339 | 339 | } |
@@ -60,6 +60,9 @@ discard block |
||
| 60 | 60 | return self::getEntryArray (self::SQL_AUTHORS_BY_FIRST_LETTER, array ($letter . "%")); |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | + /** |
|
| 64 | + * @param string $query |
|
| 65 | + */ |
|
| 63 | 66 | public static function getAuthorsForSearch($query) { |
| 64 | 67 | return self::getEntryArray (self::SQL_AUTHORS_FOR_SEARCH, array ($query . "%", $query . "%")); |
| 65 | 68 | } |
@@ -68,6 +71,9 @@ discard block |
||
| 68 | 71 | return self::getEntryArray (self::SQL_ALL_AUTHORS, array ()); |
| 69 | 72 | } |
| 70 | 73 | |
| 74 | + /** |
|
| 75 | + * @param string $query |
|
| 76 | + */ |
|
| 71 | 77 | public static function getEntryArray ($query, $params) { |
| 72 | 78 | return Base::getEntryArrayWithBookNumber ($query, self::AUTHOR_COLUMNS, $params, "Author"); |
| 73 | 79 | } |
@@ -24,69 +24,69 @@ |
||
| 24 | 24 | $this->sort = $post->sort; |
| 25 | 25 | } |
| 26 | 26 | |
| 27 | - public function getUri () { |
|
| 28 | - return "?page=".parent::PAGE_AUTHOR_DETAIL."&id=$this->id"; |
|
| 27 | + public function getUri() { |
|
| 28 | + return "?page=" . parent::PAGE_AUTHOR_DETAIL . "&id=$this->id"; |
|
| 29 | 29 | } |
| 30 | 30 | |
| 31 | - public function getEntryId () { |
|
| 32 | - return self::ALL_AUTHORS_ID.":".$this->id; |
|
| 31 | + public function getEntryId() { |
|
| 32 | + return self::ALL_AUTHORS_ID . ":" . $this->id; |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | - public static function getEntryIdByLetter ($startingLetter) { |
|
| 36 | - return self::ALL_AUTHORS_ID.":letter:".$startingLetter; |
|
| 35 | + public static function getEntryIdByLetter($startingLetter) { |
|
| 36 | + return self::ALL_AUTHORS_ID . ":letter:" . $startingLetter; |
|
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | public static function getCount() { |
| 40 | 40 | // str_format (localize("authors.alphabetical", count(array)) |
| 41 | - return parent::getCountGeneric ("authors", self::ALL_AUTHORS_ID, parent::PAGE_ALL_AUTHORS); |
|
| 41 | + return parent::getCountGeneric("authors", self::ALL_AUTHORS_ID, parent::PAGE_ALL_AUTHORS); |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | public static function getAllAuthorsByFirstLetter() { |
| 45 | - list (, $result) = parent::executeQuery ("select {0} |
|
| 45 | + list (, $result) = parent::executeQuery("select {0} |
|
| 46 | 46 | from authors |
| 47 | 47 | group by substr (upper (sort), 1, 1) |
| 48 | -order by substr (upper (sort), 1, 1)", "substr (upper (sort), 1, 1) as title, count(*) as count", "", array (), -1); |
|
| 48 | +order by substr (upper (sort), 1, 1)", "substr (upper (sort), 1, 1) as title, count(*) as count", "", array(), -1); |
|
| 49 | 49 | $entryArray = array(); |
| 50 | - while ($post = $result->fetchObject ()) |
|
| 50 | + while ($post = $result->fetchObject()) |
|
| 51 | 51 | { |
| 52 | - array_push ($entryArray, new Entry ($post->title, Author::getEntryIdByLetter ($post->title), |
|
| 53 | - str_format (localize("authorword", $post->count), $post->count), "text", |
|
| 54 | - array ( new LinkNavigation ("?page=".parent::PAGE_AUTHORS_FIRST_LETTER."&id=". rawurlencode ($post->title))), "", $post->count)); |
|
| 52 | + array_push($entryArray, new Entry($post->title, Author::getEntryIdByLetter($post->title), |
|
| 53 | + str_format(localize("authorword", $post->count), $post->count), "text", |
|
| 54 | + array(new LinkNavigation("?page=" . parent::PAGE_AUTHORS_FIRST_LETTER . "&id=" . rawurlencode($post->title))), "", $post->count)); |
|
| 55 | 55 | } |
| 56 | 56 | return $entryArray; |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | public static function getAuthorsByStartingLetter($letter) { |
| 60 | - return self::getEntryArray (self::SQL_AUTHORS_BY_FIRST_LETTER, array ($letter . "%")); |
|
| 60 | + return self::getEntryArray(self::SQL_AUTHORS_BY_FIRST_LETTER, array($letter . "%")); |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | public static function getAuthorsForSearch($query) { |
| 64 | - return self::getEntryArray (self::SQL_AUTHORS_FOR_SEARCH, array ($query . "%", $query . "%")); |
|
| 64 | + return self::getEntryArray(self::SQL_AUTHORS_FOR_SEARCH, array($query . "%", $query . "%")); |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | public static function getAllAuthors() { |
| 68 | - return self::getEntryArray (self::SQL_ALL_AUTHORS, array ()); |
|
| 68 | + return self::getEntryArray(self::SQL_ALL_AUTHORS, array()); |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | - public static function getEntryArray ($query, $params) { |
|
| 72 | - return Base::getEntryArrayWithBookNumber ($query, self::AUTHOR_COLUMNS, $params, "Author"); |
|
| 71 | + public static function getEntryArray($query, $params) { |
|
| 72 | + return Base::getEntryArrayWithBookNumber($query, self::AUTHOR_COLUMNS, $params, "Author"); |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | - public static function getAuthorById ($authorId) { |
|
| 76 | - $result = parent::getDb ()->prepare('select ' . self::AUTHOR_COLUMNS . ' from authors where id = ?'); |
|
| 77 | - $result->execute (array ($authorId)); |
|
| 78 | - $post = $result->fetchObject (); |
|
| 79 | - return new Author ($post); |
|
| 75 | + public static function getAuthorById($authorId) { |
|
| 76 | + $result = parent::getDb()->prepare('select ' . self::AUTHOR_COLUMNS . ' from authors where id = ?'); |
|
| 77 | + $result->execute(array($authorId)); |
|
| 78 | + $post = $result->fetchObject(); |
|
| 79 | + return new Author($post); |
|
| 80 | 80 | } |
| 81 | 81 | |
| 82 | - public static function getAuthorByBookId ($bookId) { |
|
| 83 | - $result = parent::getDb ()->prepare('select authors.id as id, authors.name as name, authors.sort as sort from authors, books_authors_link |
|
| 82 | + public static function getAuthorByBookId($bookId) { |
|
| 83 | + $result = parent::getDb()->prepare('select authors.id as id, authors.name as name, authors.sort as sort from authors, books_authors_link |
|
| 84 | 84 | where author = authors.id |
| 85 | 85 | and book = ?'); |
| 86 | - $result->execute (array ($bookId)); |
|
| 87 | - $authorArray = array (); |
|
| 88 | - while ($post = $result->fetchObject ()) { |
|
| 89 | - array_push ($authorArray, new Author ($post)); |
|
| 86 | + $result->execute(array($bookId)); |
|
| 87 | + $authorArray = array(); |
|
| 88 | + while ($post = $result->fetchObject()) { |
|
| 89 | + array_push($authorArray, new Author($post)); |
|
| 90 | 90 | } |
| 91 | 91 | return $authorArray; |
| 92 | 92 | } |
@@ -84,6 +84,9 @@ discard block |
||
| 84 | 84 | return ""; |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | + /** |
|
| 88 | + * @return string |
|
| 89 | + */ |
|
| 87 | 90 | public static function getDbDirectory ($database = NULL) { |
| 88 | 91 | global $config; |
| 89 | 92 | if (self::isMultipleDatabaseEnabled ()) { |
@@ -143,10 +146,18 @@ discard block |
||
| 143 | 146 | self::$db = NULL; |
| 144 | 147 | } |
| 145 | 148 | |
| 149 | + /** |
|
| 150 | + * @param string $query |
|
| 151 | + */ |
|
| 146 | 152 | public static function executeQuerySingle ($query, $database = NULL) { |
| 147 | 153 | return self::getDb ($database)->query($query)->fetchColumn(); |
| 148 | 154 | } |
| 149 | 155 | |
| 156 | + /** |
|
| 157 | + * @param string $table |
|
| 158 | + * @param string $id |
|
| 159 | + * @param string $numberOfString |
|
| 160 | + */ |
|
| 150 | 161 | public static function getCountGeneric($table, $id, $pageId, $numberOfString = NULL) { |
| 151 | 162 | if (!$numberOfString) { |
| 152 | 163 | $numberOfString = $table . ".alphabetical"; |
@@ -159,6 +170,10 @@ discard block |
||
| 159 | 170 | return $entry; |
| 160 | 171 | } |
| 161 | 172 | |
| 173 | + /** |
|
| 174 | + * @param string $columns |
|
| 175 | + * @param string $category |
|
| 176 | + */ |
|
| 162 | 177 | public static function getEntryArrayWithBookNumber ($query, $columns, $params, $category) { |
| 163 | 178 | list (, $result) = self::executeQuery ($query, $columns, "", $params, -1); |
| 164 | 179 | $entryArray = array(); |
@@ -177,6 +192,9 @@ discard block |
||
| 177 | 192 | return $entryArray; |
| 178 | 193 | } |
| 179 | 194 | |
| 195 | + /** |
|
| 196 | + * @param string $filter |
|
| 197 | + */ |
|
| 180 | 198 | public static function executeQuery($query, $columns, $filter, $params, $n, $database = NULL, $numberPerPage = NULL) { |
| 181 | 199 | $totalResult = -1; |
| 182 | 200 | |
@@ -37,146 +37,146 @@ discard block |
||
| 37 | 37 | |
| 38 | 38 | private static $db = NULL; |
| 39 | 39 | |
| 40 | - public static function isMultipleDatabaseEnabled () { |
|
| 40 | + public static function isMultipleDatabaseEnabled() { |
|
| 41 | 41 | global $config; |
| 42 | - return is_array ($config['calibre_directory']); |
|
| 42 | + return is_array($config['calibre_directory']); |
|
| 43 | 43 | } |
| 44 | 44 | |
| 45 | - public static function useAbsolutePath () { |
|
| 45 | + public static function useAbsolutePath() { |
|
| 46 | 46 | global $config; |
| 47 | 47 | $path = self::getDbDirectory(); |
| 48 | - return preg_match ('/^\//', $path) || // Linux / |
|
| 49 | - preg_match ('/^\w\:/', $path); // Windows X: |
|
| 48 | + return preg_match('/^\//', $path) || // Linux / |
|
| 49 | + preg_match('/^\w\:/', $path); // Windows X: |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | - public static function noDatabaseSelected () { |
|
| 53 | - return self::isMultipleDatabaseEnabled () && is_null (GetUrlParam (DB)); |
|
| 52 | + public static function noDatabaseSelected() { |
|
| 53 | + return self::isMultipleDatabaseEnabled() && is_null(GetUrlParam(DB)); |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | - public static function getDbList () { |
|
| 56 | + public static function getDbList() { |
|
| 57 | 57 | global $config; |
| 58 | - if (self::isMultipleDatabaseEnabled ()) { |
|
| 58 | + if (self::isMultipleDatabaseEnabled()) { |
|
| 59 | 59 | return $config['calibre_directory']; |
| 60 | 60 | } else { |
| 61 | - return array ("" => $config['calibre_directory']); |
|
| 61 | + return array("" => $config['calibre_directory']); |
|
| 62 | 62 | } |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | - public static function getDbNameList () { |
|
| 65 | + public static function getDbNameList() { |
|
| 66 | 66 | global $config; |
| 67 | - if (self::isMultipleDatabaseEnabled ()) { |
|
| 68 | - return array_keys ($config['calibre_directory']); |
|
| 67 | + if (self::isMultipleDatabaseEnabled()) { |
|
| 68 | + return array_keys($config['calibre_directory']); |
|
| 69 | 69 | } else { |
| 70 | - return array (""); |
|
| 70 | + return array(""); |
|
| 71 | 71 | } |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | - public static function getDbName ($database = NULL) { |
|
| 74 | + public static function getDbName($database = NULL) { |
|
| 75 | 75 | global $config; |
| 76 | - if (self::isMultipleDatabaseEnabled ()) { |
|
| 77 | - if (is_null ($database)) $database = GetUrlParam (DB, 0); |
|
| 76 | + if (self::isMultipleDatabaseEnabled()) { |
|
| 77 | + if (is_null($database)) $database = GetUrlParam(DB, 0); |
|
| 78 | 78 | if (!is_null($database) && !preg_match('/^\d+$/', $database)) { |
| 79 | - self::error ($database); |
|
| 79 | + self::error($database); |
|
| 80 | 80 | } |
| 81 | - $array = array_keys ($config['calibre_directory']); |
|
| 81 | + $array = array_keys($config['calibre_directory']); |
|
| 82 | 82 | return $array[$database]; |
| 83 | 83 | } |
| 84 | 84 | return ""; |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | - public static function getDbDirectory ($database = NULL) { |
|
| 87 | + public static function getDbDirectory($database = NULL) { |
|
| 88 | 88 | global $config; |
| 89 | - if (self::isMultipleDatabaseEnabled ()) { |
|
| 90 | - if (is_null ($database)) $database = GetUrlParam (DB, 0); |
|
| 89 | + if (self::isMultipleDatabaseEnabled()) { |
|
| 90 | + if (is_null($database)) $database = GetUrlParam(DB, 0); |
|
| 91 | 91 | if (!is_null($database) && !preg_match('/^\d+$/', $database)) { |
| 92 | - self::error ($database); |
|
| 92 | + self::error($database); |
|
| 93 | 93 | } |
| 94 | - $array = array_values ($config['calibre_directory']); |
|
| 94 | + $array = array_values($config['calibre_directory']); |
|
| 95 | 95 | return $array[$database]; |
| 96 | 96 | } |
| 97 | 97 | return $config['calibre_directory']; |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | |
| 101 | - public static function getDbFileName ($database = NULL) { |
|
| 102 | - return self::getDbDirectory ($database) .'metadata.db'; |
|
| 101 | + public static function getDbFileName($database = NULL) { |
|
| 102 | + return self::getDbDirectory($database) . 'metadata.db'; |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | - private static function error ($database) { |
|
| 105 | + private static function error($database) { |
|
| 106 | 106 | if (php_sapi_name() != "cli") { |
| 107 | 107 | header("location: checkconfig.php?err=1"); |
| 108 | 108 | } |
| 109 | 109 | throw new Exception("Database <{$database}> not found."); |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | - public static function getDb ($database = NULL) { |
|
| 113 | - if (is_null (self::$db)) { |
|
| 112 | + public static function getDb($database = NULL) { |
|
| 113 | + if (is_null(self::$db)) { |
|
| 114 | 114 | try { |
| 115 | - if (is_readable (self::getDbFileName ($database))) { |
|
| 116 | - self::$db = new PDO('sqlite:'. self::getDbFileName ($database)); |
|
| 117 | - if (useNormAndUp ()) { |
|
| 118 | - self::$db->sqliteCreateFunction ('normAndUp', 'normAndUp', 1); |
|
| 115 | + if (is_readable(self::getDbFileName($database))) { |
|
| 116 | + self::$db = new PDO('sqlite:' . self::getDbFileName($database)); |
|
| 117 | + if (useNormAndUp()) { |
|
| 118 | + self::$db->sqliteCreateFunction('normAndUp', 'normAndUp', 1); |
|
| 119 | 119 | } |
| 120 | 120 | } else { |
| 121 | - self::error ($database); |
|
| 121 | + self::error($database); |
|
| 122 | 122 | } |
| 123 | 123 | } catch (Exception $e) { |
| 124 | - self::error ($database); |
|
| 124 | + self::error($database); |
|
| 125 | 125 | } |
| 126 | 126 | } |
| 127 | 127 | return self::$db; |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | - public static function checkDatabaseAvailability () { |
|
| 131 | - if (self::noDatabaseSelected ()) { |
|
| 132 | - for ($i = 0; $i < count (self::getDbList ()); $i++) { |
|
| 133 | - self::getDb ($i); |
|
| 134 | - self::clearDb (); |
|
| 130 | + public static function checkDatabaseAvailability() { |
|
| 131 | + if (self::noDatabaseSelected()) { |
|
| 132 | + for ($i = 0; $i < count(self::getDbList()); $i++) { |
|
| 133 | + self::getDb($i); |
|
| 134 | + self::clearDb(); |
|
| 135 | 135 | } |
| 136 | 136 | } else { |
| 137 | - self::getDb (); |
|
| 137 | + self::getDb(); |
|
| 138 | 138 | } |
| 139 | 139 | return true; |
| 140 | 140 | } |
| 141 | 141 | |
| 142 | - public static function clearDb () { |
|
| 142 | + public static function clearDb() { |
|
| 143 | 143 | self::$db = NULL; |
| 144 | 144 | } |
| 145 | 145 | |
| 146 | - public static function executeQuerySingle ($query, $database = NULL) { |
|
| 147 | - return self::getDb ($database)->query($query)->fetchColumn(); |
|
| 146 | + public static function executeQuerySingle($query, $database = NULL) { |
|
| 147 | + return self::getDb($database)->query($query)->fetchColumn(); |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | public static function getCountGeneric($table, $id, $pageId, $numberOfString = NULL) { |
| 151 | 151 | if (!$numberOfString) { |
| 152 | 152 | $numberOfString = $table . ".alphabetical"; |
| 153 | 153 | } |
| 154 | - $count = self::executeQuerySingle ('select count(*) from ' . $table); |
|
| 154 | + $count = self::executeQuerySingle('select count(*) from ' . $table); |
|
| 155 | 155 | if ($count == 0) return NULL; |
| 156 | - $entry = new Entry (localize($table . ".title"), $id, |
|
| 157 | - str_format (localize($numberOfString, $count), $count), "text", |
|
| 158 | - array ( new LinkNavigation ("?page=".$pageId)), "", $count); |
|
| 156 | + $entry = new Entry(localize($table . ".title"), $id, |
|
| 157 | + str_format(localize($numberOfString, $count), $count), "text", |
|
| 158 | + array(new LinkNavigation("?page=" . $pageId)), "", $count); |
|
| 159 | 159 | return $entry; |
| 160 | 160 | } |
| 161 | 161 | |
| 162 | - public static function getEntryArrayWithBookNumber ($query, $columns, $params, $category) { |
|
| 162 | + public static function getEntryArrayWithBookNumber($query, $columns, $params, $category) { |
|
| 163 | 163 | /* @var $result PDOStatement */ |
| 164 | 164 | |
| 165 | - list (, $result) = self::executeQuery ($query, $columns, "", $params, -1); |
|
| 165 | + list (, $result) = self::executeQuery($query, $columns, "", $params, -1); |
|
| 166 | 166 | $entryArray = array(); |
| 167 | - while ($post = $result->fetchObject ()) |
|
| 167 | + while ($post = $result->fetchObject()) |
|
| 168 | 168 | { |
| 169 | 169 | /* @var $instance Author|Tag|Serie|Publisher */ |
| 170 | 170 | |
| 171 | - $instance = new $category ($post); |
|
| 171 | + $instance = new $category($post); |
|
| 172 | 172 | if (property_exists($post, "sort")) { |
| 173 | 173 | $title = $post->sort; |
| 174 | 174 | } else { |
| 175 | 175 | $title = $post->name; |
| 176 | 176 | } |
| 177 | - array_push ($entryArray, new Entry ($title, $instance->getEntryId (), |
|
| 178 | - str_format (localize("bookword", $post->count), $post->count), "text", |
|
| 179 | - array ( new LinkNavigation ($instance->getUri ())), "", $post->count)); |
|
| 177 | + array_push($entryArray, new Entry($title, $instance->getEntryId(), |
|
| 178 | + str_format(localize("bookword", $post->count), $post->count), "text", |
|
| 179 | + array(new LinkNavigation($instance->getUri())), "", $post->count)); |
|
| 180 | 180 | } |
| 181 | 181 | return $entryArray; |
| 182 | 182 | } |
@@ -184,30 +184,30 @@ discard block |
||
| 184 | 184 | public static function executeQuery($query, $columns, $filter, $params, $n, $database = NULL, $numberPerPage = NULL) { |
| 185 | 185 | $totalResult = -1; |
| 186 | 186 | |
| 187 | - if (useNormAndUp ()) { |
|
| 187 | + if (useNormAndUp()) { |
|
| 188 | 188 | $query = preg_replace("/upper/", "normAndUp", $query); |
| 189 | 189 | $columns = preg_replace("/upper/", "normAndUp", $columns); |
| 190 | 190 | } |
| 191 | 191 | |
| 192 | - if (is_null ($numberPerPage)) { |
|
| 193 | - $numberPerPage = getCurrentOption ("max_item_per_page"); |
|
| 192 | + if (is_null($numberPerPage)) { |
|
| 193 | + $numberPerPage = getCurrentOption("max_item_per_page"); |
|
| 194 | 194 | } |
| 195 | 195 | |
| 196 | 196 | if ($numberPerPage != -1 && $n != -1) |
| 197 | 197 | { |
| 198 | 198 | // First check total number of results |
| 199 | - $result = self::getDb ($database)->prepare (str_format ($query, "count(*)", $filter)); |
|
| 200 | - $result->execute ($params); |
|
| 201 | - $totalResult = $result->fetchColumn (); |
|
| 199 | + $result = self::getDb($database)->prepare(str_format($query, "count(*)", $filter)); |
|
| 200 | + $result->execute($params); |
|
| 201 | + $totalResult = $result->fetchColumn(); |
|
| 202 | 202 | |
| 203 | 203 | // Next modify the query and params |
| 204 | 204 | $query .= " limit ?, ?"; |
| 205 | - array_push ($params, ($n - 1) * $numberPerPage, $numberPerPage); |
|
| 205 | + array_push($params, ($n - 1) * $numberPerPage, $numberPerPage); |
|
| 206 | 206 | } |
| 207 | 207 | |
| 208 | - $result = self::getDb ($database)->prepare(str_format ($query, $columns, $filter)); |
|
| 209 | - $result->execute ($params); |
|
| 210 | - return array ($totalResult, $result); |
|
| 208 | + $result = self::getDb($database)->prepare(str_format($query, $columns, $filter)); |
|
| 209 | + $result->execute($params); |
|
| 210 | + return array($totalResult, $result); |
|
| 211 | 211 | } |
| 212 | 212 | |
| 213 | 213 | } |
@@ -141,6 +141,9 @@ discard block |
||
| 141 | 141 | return new Link ($href, $this->getMimeType (), Link::OPDS_ACQUISITION_TYPE, $title); |
| 142 | 142 | } |
| 143 | 143 | |
| 144 | + /** |
|
| 145 | + * @param Book $book |
|
| 146 | + */ |
|
| 144 | 147 | public static function getDataByBook ($book) { |
| 145 | 148 | $out = array (); |
| 146 | 149 | $result = parent::getDb ()->prepare('select id, format, name |
@@ -154,6 +157,9 @@ discard block |
||
| 154 | 157 | return $out; |
| 155 | 158 | } |
| 156 | 159 | |
| 160 | + /** |
|
| 161 | + * @param string $urlParam |
|
| 162 | + */ |
|
| 157 | 163 | public static function handleThumbnailLink ($urlParam, $height) { |
| 158 | 164 | global $config; |
| 159 | 165 | |
@@ -173,6 +179,10 @@ discard block |
||
| 173 | 179 | return $urlParam; |
| 174 | 180 | } |
| 175 | 181 | |
| 182 | + /** |
|
| 183 | + * @param string $type |
|
| 184 | + * @param string $filename |
|
| 185 | + */ |
|
| 176 | 186 | public static function getLink ($book, $type, $mime, $rel, $filename, $idData, $title = NULL, $height = NULL) |
| 177 | 187 | { |
| 178 | 188 | global $config; |
@@ -59,25 +59,25 @@ discard block |
||
| 59 | 59 | $this->id = $post->id; |
| 60 | 60 | $this->name = $post->name; |
| 61 | 61 | $this->format = $post->format; |
| 62 | - $this->realFormat = str_replace ("ORIGINAL_", "", $post->format); |
|
| 63 | - $this->extension = strtolower ($this->realFormat); |
|
| 62 | + $this->realFormat = str_replace("ORIGINAL_", "", $post->format); |
|
| 63 | + $this->extension = strtolower($this->realFormat); |
|
| 64 | 64 | $this->book = $book; |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | - public function isKnownType () { |
|
| 68 | - return array_key_exists ($this->extension, self::$mimetypes); |
|
| 67 | + public function isKnownType() { |
|
| 68 | + return array_key_exists($this->extension, self::$mimetypes); |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | - public function getMimeType () { |
|
| 71 | + public function getMimeType() { |
|
| 72 | 72 | $result = "application/octet-stream"; |
| 73 | - if ($this->isKnownType ()) { |
|
| 73 | + if ($this->isKnownType()) { |
|
| 74 | 74 | return self::$mimetypes [$this->extension]; |
| 75 | 75 | } elseif (function_exists('finfo_open') === true) { |
| 76 | 76 | $finfo = finfo_open(FILEINFO_MIME_TYPE); |
| 77 | 77 | |
| 78 | 78 | if (is_resource($finfo) === true) |
| 79 | 79 | { |
| 80 | - $result = finfo_file($finfo, $this->getLocalPath ()); |
|
| 80 | + $result = finfo_file($finfo, $this->getLocalPath()); |
|
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | finfo_close($finfo); |
@@ -86,82 +86,82 @@ discard block |
||
| 86 | 86 | return $result; |
| 87 | 87 | } |
| 88 | 88 | |
| 89 | - public function isEpubValidOnKobo () { |
|
| 89 | + public function isEpubValidOnKobo() { |
|
| 90 | 90 | return $this->format == "EPUB" || $this->format == "KEPUB"; |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | - public function getFilename () { |
|
| 94 | - return $this->name . "." . strtolower ($this->format); |
|
| 93 | + public function getFilename() { |
|
| 94 | + return $this->name . "." . strtolower($this->format); |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | - public function getUpdatedFilename () { |
|
| 98 | - return $this->book->getAuthorsSort () . " - " . $this->book->title; |
|
| 97 | + public function getUpdatedFilename() { |
|
| 98 | + return $this->book->getAuthorsSort() . " - " . $this->book->title; |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | - public function getUpdatedFilenameEpub () { |
|
| 102 | - return $this->getUpdatedFilename () . ".epub"; |
|
| 101 | + public function getUpdatedFilenameEpub() { |
|
| 102 | + return $this->getUpdatedFilename() . ".epub"; |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | - public function getUpdatedFilenameKepub () { |
|
| 106 | - $str = $this->getUpdatedFilename () . ".kepub.epub"; |
|
| 105 | + public function getUpdatedFilenameKepub() { |
|
| 106 | + $str = $this->getUpdatedFilename() . ".kepub.epub"; |
|
| 107 | 107 | return str_replace(array(':', '#', '&'), |
| 108 | - array('-', '-', ' '), $str ); |
|
| 108 | + array('-', '-', ' '), $str); |
|
| 109 | 109 | } |
| 110 | 110 | |
| 111 | - public function getDataLink ($rel, $title = NULL) { |
|
| 111 | + public function getDataLink($rel, $title = NULL) { |
|
| 112 | 112 | global $config; |
| 113 | 113 | |
| 114 | 114 | if ($rel == Link::OPDS_ACQUISITION_TYPE && $config['cops_use_url_rewriting'] == "1") { |
| 115 | 115 | return $this->getHtmlLinkWithRewriting($title); |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | - return self::getLink ($this->book, $this->extension, $this->getMimeType (), $rel, $this->getFilename (), $this->id, $title); |
|
| 118 | + return self::getLink($this->book, $this->extension, $this->getMimeType(), $rel, $this->getFilename(), $this->id, $title); |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | - public function getHtmlLink () { |
|
| 121 | + public function getHtmlLink() { |
|
| 122 | 122 | return $this->getDataLink(Link::OPDS_ACQUISITION_TYPE)->href; |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | - public function getLocalPath () { |
|
| 126 | - return $this->book->path . "/" . $this->getFilename (); |
|
| 125 | + public function getLocalPath() { |
|
| 126 | + return $this->book->path . "/" . $this->getFilename(); |
|
| 127 | 127 | } |
| 128 | 128 | |
| 129 | - public function getHtmlLinkWithRewriting ($title = NULL) { |
|
| 129 | + public function getHtmlLinkWithRewriting($title = NULL) { |
|
| 130 | 130 | global $config; |
| 131 | 131 | |
| 132 | 132 | $database = ""; |
| 133 | - if (!is_null (GetUrlParam (DB))) $database = GetUrlParam (DB) . "/"; |
|
| 133 | + if (!is_null(GetUrlParam(DB))) $database = GetUrlParam(DB) . "/"; |
|
| 134 | 134 | |
| 135 | 135 | $href = "download/" . $this->id . "/" . $database; |
| 136 | 136 | |
| 137 | 137 | if ($config['cops_provide_kepub'] == "1" && |
| 138 | - $this->isEpubValidOnKobo () && |
|
| 138 | + $this->isEpubValidOnKobo() && |
|
| 139 | 139 | preg_match("/Kobo/", $_SERVER['HTTP_USER_AGENT'])) { |
| 140 | - $href .= rawurlencode ($this->getUpdatedFilenameKepub ()); |
|
| 140 | + $href .= rawurlencode($this->getUpdatedFilenameKepub()); |
|
| 141 | 141 | } else { |
| 142 | - $href .= rawurlencode ($this->getFilename ()); |
|
| 142 | + $href .= rawurlencode($this->getFilename()); |
|
| 143 | 143 | } |
| 144 | - return new Link ($href, $this->getMimeType (), Link::OPDS_ACQUISITION_TYPE, $title); |
|
| 144 | + return new Link($href, $this->getMimeType(), Link::OPDS_ACQUISITION_TYPE, $title); |
|
| 145 | 145 | } |
| 146 | 146 | |
| 147 | - public static function getDataByBook ($book) { |
|
| 148 | - $out = array (); |
|
| 149 | - $result = parent::getDb ()->prepare('select id, format, name |
|
| 147 | + public static function getDataByBook($book) { |
|
| 148 | + $out = array(); |
|
| 149 | + $result = parent::getDb()->prepare('select id, format, name |
|
| 150 | 150 | from data where book = ?'); |
| 151 | - $result->execute (array ($book->id)); |
|
| 151 | + $result->execute(array($book->id)); |
|
| 152 | 152 | |
| 153 | - while ($post = $result->fetchObject ()) |
|
| 153 | + while ($post = $result->fetchObject()) |
|
| 154 | 154 | { |
| 155 | - array_push ($out, new Data ($post, $book)); |
|
| 155 | + array_push($out, new Data($post, $book)); |
|
| 156 | 156 | } |
| 157 | 157 | return $out; |
| 158 | 158 | } |
| 159 | 159 | |
| 160 | - public static function handleThumbnailLink ($urlParam, $height) { |
|
| 160 | + public static function handleThumbnailLink($urlParam, $height) { |
|
| 161 | 161 | global $config; |
| 162 | 162 | |
| 163 | - if (is_null ($height)) { |
|
| 164 | - if (preg_match ('/feed.php/', $_SERVER["SCRIPT_NAME"])) { |
|
| 163 | + if (is_null($height)) { |
|
| 164 | + if (preg_match('/feed.php/', $_SERVER["SCRIPT_NAME"])) { |
|
| 165 | 165 | $height = $config['cops_opds_thumbnail_height']; |
| 166 | 166 | } |
| 167 | 167 | else |
@@ -176,13 +176,13 @@ discard block |
||
| 176 | 176 | return $urlParam; |
| 177 | 177 | } |
| 178 | 178 | |
| 179 | - public static function getLink ($book, $type, $mime, $rel, $filename, $idData, $title = NULL, $height = NULL) |
|
| 179 | + public static function getLink($book, $type, $mime, $rel, $filename, $idData, $title = NULL, $height = NULL) |
|
| 180 | 180 | { |
| 181 | 181 | global $config; |
| 182 | 182 | |
| 183 | 183 | $urlParam = addURLParameter("", "data", $idData); |
| 184 | 184 | |
| 185 | - if (Base::useAbsolutePath () || |
|
| 185 | + if (Base::useAbsolutePath() || |
|
| 186 | 186 | $rel == Link::OPDS_THUMBNAIL_TYPE || |
| 187 | 187 | ($type == "epub" && $config['cops_update_epub-metadata'])) |
| 188 | 188 | { |
@@ -191,18 +191,18 @@ discard block |
||
| 191 | 191 | $urlParam = self::handleThumbnailLink($urlParam, $height); |
| 192 | 192 | } |
| 193 | 193 | $urlParam = addURLParameter($urlParam, "id", $book->id); |
| 194 | - if (!is_null (GetUrlParam (DB))) $urlParam = addURLParameter ($urlParam, DB, GetUrlParam (DB)); |
|
| 194 | + if (!is_null(GetUrlParam(DB))) $urlParam = addURLParameter($urlParam, DB, GetUrlParam(DB)); |
|
| 195 | 195 | if ($config['cops_thumbnail_handling'] != "1" && |
| 196 | 196 | !empty ($config['cops_thumbnail_handling']) && |
| 197 | 197 | $rel == Link::OPDS_THUMBNAIL_TYPE) { |
| 198 | - return new Link ($config['cops_thumbnail_handling'], $mime, $rel, $title); |
|
| 198 | + return new Link($config['cops_thumbnail_handling'], $mime, $rel, $title); |
|
| 199 | 199 | } else { |
| 200 | - return new Link ("fetch.php?" . $urlParam, $mime, $rel, $title); |
|
| 200 | + return new Link("fetch.php?" . $urlParam, $mime, $rel, $title); |
|
| 201 | 201 | } |
| 202 | 202 | } |
| 203 | 203 | else |
| 204 | 204 | { |
| 205 | - return new Link (str_replace('%2F','/',rawurlencode ($book->path."/".$filename)), $mime, $rel, $title); |
|
| 205 | + return new Link(str_replace('%2F', '/', rawurlencode($book->path . "/" . $filename)), $mime, $rel, $title); |
|
| 206 | 206 | } |
| 207 | 207 | } |
| 208 | 208 | } |
@@ -8,6 +8,9 @@ |
||
| 8 | 8 | |
| 9 | 9 | class LinkFacet extends Link |
| 10 | 10 | { |
| 11 | + /** |
|
| 12 | + * @param string $phref |
|
| 13 | + */ |
|
| 11 | 14 | public function __construct($phref, $ptitle = NULL, $pfacetGroup = NULL, $pactiveFacet = FALSE) { |
| 12 | 15 | parent::__construct ($phref, Link::OPDS_PAGING_TYPE, "http://opds-spec.org/facet", $ptitle, $pfacetGroup, $pactiveFacet); |
| 13 | 16 | if (!is_null (GetUrlParam (DB))) $this->href = addURLParameter ($this->href, DB, GetUrlParam (DB)); |
@@ -9,8 +9,8 @@ |
||
| 9 | 9 | class LinkFacet extends Link |
| 10 | 10 | { |
| 11 | 11 | public function __construct($phref, $ptitle = NULL, $pfacetGroup = NULL, $pactiveFacet = FALSE) { |
| 12 | - parent::__construct ($phref, Link::OPDS_PAGING_TYPE, "http://opds-spec.org/facet", $ptitle, $pfacetGroup, $pactiveFacet); |
|
| 13 | - if (!is_null (GetUrlParam (DB))) $this->href = addURLParameter ($this->href, DB, GetUrlParam (DB)); |
|
| 12 | + parent::__construct($phref, Link::OPDS_PAGING_TYPE, "http://opds-spec.org/facet", $ptitle, $pfacetGroup, $pactiveFacet); |
|
| 13 | + if (!is_null(GetUrlParam(DB))) $this->href = addURLParameter($this->href, DB, GetUrlParam(DB)); |
|
| 14 | 14 | $this->href = parent::getScriptName() . $this->href; |
| 15 | 15 | } |
| 16 | 16 | } |
@@ -8,6 +8,9 @@ |
||
| 8 | 8 | |
| 9 | 9 | class LinkNavigation extends Link |
| 10 | 10 | { |
| 11 | + /** |
|
| 12 | + * @param string $prel |
|
| 13 | + */ |
|
| 11 | 14 | public function __construct($phref, $prel = NULL, $ptitle = NULL) { |
| 12 | 15 | parent::__construct ($phref, Link::OPDS_NAVIGATION_TYPE, $prel, $ptitle); |
| 13 | 16 | if (!is_null (GetUrlParam (DB))) $this->href = addURLParameter ($this->href, DB, GetUrlParam (DB)); |
@@ -9,10 +9,10 @@ |
||
| 9 | 9 | class LinkNavigation extends Link |
| 10 | 10 | { |
| 11 | 11 | public function __construct($phref, $prel = NULL, $ptitle = NULL) { |
| 12 | - parent::__construct ($phref, Link::OPDS_NAVIGATION_TYPE, $prel, $ptitle); |
|
| 13 | - if (!is_null (GetUrlParam (DB))) $this->href = addURLParameter ($this->href, DB, GetUrlParam (DB)); |
|
| 14 | - if (!preg_match ("#^\?(.*)#", $this->href) && !empty ($this->href)) $this->href = "?" . $this->href; |
|
| 15 | - if (preg_match ("/(bookdetail|getJSON).php/", parent::getScriptName())) { |
|
| 12 | + parent::__construct($phref, Link::OPDS_NAVIGATION_TYPE, $prel, $ptitle); |
|
| 13 | + if (!is_null(GetUrlParam(DB))) $this->href = addURLParameter($this->href, DB, GetUrlParam(DB)); |
|
| 14 | + if (!preg_match("#^\?(.*)#", $this->href) && !empty ($this->href)) $this->href = "?" . $this->href; |
|
| 15 | + if (preg_match("/(bookdetail|getJSON).php/", parent::getScriptName())) { |
|
| 16 | 16 | $this->href = "index.php" . $this->href; |
| 17 | 17 | } else { |
| 18 | 18 | $this->href = parent::getScriptName() . $this->href; |
@@ -8,6 +8,9 @@ discard block |
||
| 8 | 8 | |
| 9 | 9 | class PageCustomize extends Page |
| 10 | 10 | { |
| 11 | + /** |
|
| 12 | + * @param string $key |
|
| 13 | + */ |
|
| 11 | 14 | private function isChecked ($key, $testedValue = 1) { |
| 12 | 15 | $value = getCurrentOption ($key); |
| 13 | 16 | if (is_array ($value)) { |
@@ -22,6 +25,9 @@ discard block |
||
| 22 | 25 | return ""; |
| 23 | 26 | } |
| 24 | 27 | |
| 28 | + /** |
|
| 29 | + * @param string $key |
|
| 30 | + */ |
|
| 25 | 31 | private function isSelected ($key, $value) { |
| 26 | 32 | if (getCurrentOption ($key) == $value) { |
| 27 | 33 | return "selected='selected'"; |
@@ -8,10 +8,10 @@ discard block |
||
| 8 | 8 | |
| 9 | 9 | class PageCustomize extends Page |
| 10 | 10 | { |
| 11 | - private function isChecked ($key, $testedValue = 1) { |
|
| 12 | - $value = getCurrentOption ($key); |
|
| 13 | - if (is_array ($value)) { |
|
| 14 | - if (in_array ($testedValue, $value)) { |
|
| 11 | + private function isChecked($key, $testedValue = 1) { |
|
| 12 | + $value = getCurrentOption($key); |
|
| 13 | + if (is_array($value)) { |
|
| 14 | + if (in_array($testedValue, $value)) { |
|
| 15 | 15 | return "checked='checked'"; |
| 16 | 16 | } |
| 17 | 17 | } else { |
@@ -22,29 +22,29 @@ discard block |
||
| 22 | 22 | return ""; |
| 23 | 23 | } |
| 24 | 24 | |
| 25 | - private function isSelected ($key, $value) { |
|
| 26 | - if (getCurrentOption ($key) == $value) { |
|
| 25 | + private function isSelected($key, $value) { |
|
| 26 | + if (getCurrentOption($key) == $value) { |
|
| 27 | 27 | return "selected='selected'"; |
| 28 | 28 | } |
| 29 | 29 | return ""; |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | - private function getStyleList () { |
|
| 33 | - $result = array (); |
|
| 34 | - foreach (glob ("templates/" . getCurrentTemplate () . "/styles/style-*.css") as $filename) { |
|
| 35 | - if (preg_match ('/styles\/style-(.*?)\.css/', $filename, $m)) { |
|
| 36 | - array_push ($result, $m [1]); |
|
| 32 | + private function getStyleList() { |
|
| 33 | + $result = array(); |
|
| 34 | + foreach (glob("templates/" . getCurrentTemplate() . "/styles/style-*.css") as $filename) { |
|
| 35 | + if (preg_match('/styles\/style-(.*?)\.css/', $filename, $m)) { |
|
| 36 | + array_push($result, $m [1]); |
|
| 37 | 37 | } |
| 38 | 38 | } |
| 39 | 39 | return $result; |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | - public function InitializeContent () |
|
| 42 | + public function InitializeContent() |
|
| 43 | 43 | { |
| 44 | - $this->title = localize ("customize.title"); |
|
| 45 | - $this->entryArray = array (); |
|
| 44 | + $this->title = localize("customize.title"); |
|
| 45 | + $this->entryArray = array(); |
|
| 46 | 46 | |
| 47 | - $ignoredBaseArray = array (PageQueryResult::SCOPE_AUTHOR, |
|
| 47 | + $ignoredBaseArray = array(PageQueryResult::SCOPE_AUTHOR, |
|
| 48 | 48 | PageQueryResult::SCOPE_TAG, |
| 49 | 49 | PageQueryResult::SCOPE_SERIES, |
| 50 | 50 | PageQueryResult::SCOPE_PUBLISHER, |
@@ -52,49 +52,49 @@ discard block |
||
| 52 | 52 | "language"); |
| 53 | 53 | |
| 54 | 54 | $content = ""; |
| 55 | - array_push ($this->entryArray, new Entry ("Template", "", |
|
| 55 | + array_push($this->entryArray, new Entry("Template", "", |
|
| 56 | 56 | "<span style='cursor: pointer;' onclick='$.cookie(\"template\", \"bootstrap\", { expires: 365 });window.location=$(\".headleft\").attr(\"href\");'>Click to switch to Bootstrap</span>", "text", |
| 57 | - array ())); |
|
| 57 | + array())); |
|
| 58 | 58 | if (!preg_match("/(Kobo|Kindle\/3.0|EBRD1101)/", $_SERVER['HTTP_USER_AGENT'])) { |
| 59 | 59 | $content .= '<select id="style" onchange="updateCookie (this);">'; |
| 60 | - foreach ($this-> getStyleList () as $filename) { |
|
| 61 | - $content .= "<option value='{$filename}' " . $this->isSelected ("style", $filename) . ">{$filename}</option>"; |
|
| 60 | + foreach ($this-> getStyleList() as $filename) { |
|
| 61 | + $content .= "<option value='{$filename}' " . $this->isSelected("style", $filename) . ">{$filename}</option>"; |
|
| 62 | 62 | } |
| 63 | 63 | $content .= '</select>'; |
| 64 | 64 | } else { |
| 65 | - foreach ($this-> getStyleList () as $filename) { |
|
| 66 | - $content .= "<input type='radio' onchange='updateCookieFromCheckbox (this);' id='style-{$filename}' name='style' value='{$filename}' " . $this->isChecked ("style", $filename) . " /><label for='style-{$filename}'> {$filename} </label>"; |
|
| 65 | + foreach ($this-> getStyleList() as $filename) { |
|
| 66 | + $content .= "<input type='radio' onchange='updateCookieFromCheckbox (this);' id='style-{$filename}' name='style' value='{$filename}' " . $this->isChecked("style", $filename) . " /><label for='style-{$filename}'> {$filename} </label>"; |
|
| 67 | 67 | } |
| 68 | 68 | } |
| 69 | - array_push ($this->entryArray, new Entry (localize ("customize.style"), "", |
|
| 69 | + array_push($this->entryArray, new Entry(localize("customize.style"), "", |
|
| 70 | 70 | $content, "text", |
| 71 | - array ())); |
|
| 72 | - if (!useServerSideRendering ()) { |
|
| 73 | - $content = '<input type="checkbox" onchange="updateCookieFromCheckbox (this);" id="use_fancyapps" ' . $this->isChecked ("use_fancyapps") . ' />'; |
|
| 74 | - array_push ($this->entryArray, new Entry (localize ("customize.fancybox"), "", |
|
| 71 | + array())); |
|
| 72 | + if (!useServerSideRendering()) { |
|
| 73 | + $content = '<input type="checkbox" onchange="updateCookieFromCheckbox (this);" id="use_fancyapps" ' . $this->isChecked("use_fancyapps") . ' />'; |
|
| 74 | + array_push($this->entryArray, new Entry(localize("customize.fancybox"), "", |
|
| 75 | 75 | $content, "text", |
| 76 | - array ())); |
|
| 76 | + array())); |
|
| 77 | 77 | } |
| 78 | - $content = '<input type="number" onchange="updateCookie (this);" id="max_item_per_page" value="' . getCurrentOption ("max_item_per_page") . '" min="-1" max="1200" pattern="^[-+]?[0-9]+$" />'; |
|
| 79 | - array_push ($this->entryArray, new Entry (localize ("customize.paging"), "", |
|
| 78 | + $content = '<input type="number" onchange="updateCookie (this);" id="max_item_per_page" value="' . getCurrentOption("max_item_per_page") . '" min="-1" max="1200" pattern="^[-+]?[0-9]+$" />'; |
|
| 79 | + array_push($this->entryArray, new Entry(localize("customize.paging"), "", |
|
| 80 | 80 | $content, "text", |
| 81 | - array ())); |
|
| 82 | - $content = '<input type="text" onchange="updateCookie (this);" id="email" value="' . getCurrentOption ("email") . '" />'; |
|
| 83 | - array_push ($this->entryArray, new Entry (localize ("customize.email"), "", |
|
| 81 | + array())); |
|
| 82 | + $content = '<input type="text" onchange="updateCookie (this);" id="email" value="' . getCurrentOption("email") . '" />'; |
|
| 83 | + array_push($this->entryArray, new Entry(localize("customize.email"), "", |
|
| 84 | 84 | $content, "text", |
| 85 | - array ())); |
|
| 86 | - $content = '<input type="checkbox" onchange="updateCookieFromCheckbox (this);" id="html_tag_filter" ' . $this->isChecked ("html_tag_filter") . ' />'; |
|
| 87 | - array_push ($this->entryArray, new Entry (localize ("customize.filter"), "", |
|
| 85 | + array())); |
|
| 86 | + $content = '<input type="checkbox" onchange="updateCookieFromCheckbox (this);" id="html_tag_filter" ' . $this->isChecked("html_tag_filter") . ' />'; |
|
| 87 | + array_push($this->entryArray, new Entry(localize("customize.filter"), "", |
|
| 88 | 88 | $content, "text", |
| 89 | - array ())); |
|
| 89 | + array())); |
|
| 90 | 90 | $content = ""; |
| 91 | 91 | foreach ($ignoredBaseArray as $key) { |
| 92 | - $keyPlural = preg_replace ('/(ss)$/', 's', $key . "s"); |
|
| 93 | - $content .= '<input type="checkbox" name="ignored_categories[]" onchange="updateCookieFromCheckboxGroup (this);" id="ignored_categories_' . $key . '" ' . $this->isChecked ("ignored_categories", $key) . ' > ' . localize ("{$keyPlural}.title") . '</input> '; |
|
| 92 | + $keyPlural = preg_replace('/(ss)$/', 's', $key . "s"); |
|
| 93 | + $content .= '<input type="checkbox" name="ignored_categories[]" onchange="updateCookieFromCheckboxGroup (this);" id="ignored_categories_' . $key . '" ' . $this->isChecked("ignored_categories", $key) . ' > ' . localize("{$keyPlural}.title") . '</input> '; |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | - array_push ($this->entryArray, new Entry (localize ("customize.ignored"), "", |
|
| 96 | + array_push($this->entryArray, new Entry(localize("customize.ignored"), "", |
|
| 97 | 97 | $content, "text", |
| 98 | - array ())); |
|
| 98 | + array())); |
|
| 99 | 99 | } |
| 100 | 100 | } |