@@ -2,7 +2,8 @@ discard block |
||
| 2 | 2 | |
| 3 | 3 | require_once ("config.php"); |
| 4 | 4 | |
| 5 | -function checkConfiguration () { |
|
| 5 | +function checkConfiguration () |
|
| 6 | +{ |
|
| 6 | 7 | global $config; |
| 7 | 8 | |
| 8 | 9 | if (is_null ($config['cops_mail_configuration']) || |
@@ -14,7 +15,8 @@ discard block |
||
| 14 | 15 | return False; |
| 15 | 16 | } |
| 16 | 17 | |
| 17 | -function checkRequest ($idData, $emailDest) { |
|
| 18 | +function checkRequest ($idData, $emailDest) |
|
| 19 | +{ |
|
| 18 | 20 | if (empty ($idData)) { |
| 19 | 21 | return 'No data sent.'; |
| 20 | 22 | } |
@@ -58,9 +60,15 @@ discard block |
||
| 58 | 60 | $mail->Port = 465; |
| 59 | 61 | } |
| 60 | 62 | $mail->SMTPAuth = !empty ($config['cops_mail_configuration']["smtp.username"]); |
| 61 | -if (!empty ($config['cops_mail_configuration']["smtp.username"])) $mail->Username = $config['cops_mail_configuration']["smtp.username"]; |
|
| 62 | -if (!empty ($config['cops_mail_configuration']["smtp.password"])) $mail->Password = $config['cops_mail_configuration']["smtp.password"]; |
|
| 63 | -if (!empty ($config['cops_mail_configuration']["smtp.secure"])) $mail->SMTPSecure = $config['cops_mail_configuration']["smtp.secure"]; |
|
| 63 | +if (!empty ($config['cops_mail_configuration']["smtp.username"])) { |
|
| 64 | + $mail->Username = $config['cops_mail_configuration']["smtp.username"]; |
|
| 65 | +} |
|
| 66 | +if (!empty ($config['cops_mail_configuration']["smtp.password"])) { |
|
| 67 | + $mail->Password = $config['cops_mail_configuration']["smtp.password"]; |
|
| 68 | +} |
|
| 69 | +if (!empty ($config['cops_mail_configuration']["smtp.secure"])) { |
|
| 70 | + $mail->SMTPSecure = $config['cops_mail_configuration']["smtp.secure"]; |
|
| 71 | +} |
|
| 64 | 72 | |
| 65 | 73 | $mail->From = $config['cops_mail_configuration']["address.from"]; |
| 66 | 74 | $mail->FromName = $config['cops_title_default']; |
@@ -9,7 +9,8 @@ discard block |
||
| 9 | 9 | require_once ("config.php"); |
| 10 | 10 | require_once ("base.php"); |
| 11 | 11 | |
| 12 | -function getComponentContent ($book, $component, $add) { |
|
| 12 | +function getComponentContent ($book, $component, $add) |
|
| 13 | +{ |
|
| 13 | 14 | $data = $book->component ($component); |
| 14 | 15 | |
| 15 | 16 | $callback = function ($m) use ($book, $component, $add) { |
@@ -28,7 +29,9 @@ discard block |
||
| 28 | 29 | $hash = "#" . $matches [2]; |
| 29 | 30 | } |
| 30 | 31 | $comp = $book->getComponentName ($component, $path); |
| 31 | - if (!$comp) return "{$method}'#'{$end}"; |
|
| 32 | + if (!$comp) { |
|
| 33 | + return "{$method}'#'{$end}"; |
|
| 34 | + } |
|
| 32 | 35 | $out = "{$method}'epubfs.php?{$add}comp={$comp}{$hash}'{$end}"; |
| 33 | 36 | if ($end) { |
| 34 | 37 | return $out; |
@@ -48,7 +51,9 @@ discard block |
||
| 48 | 51 | |
| 49 | 52 | $idData = getURLParam ("data", NULL); |
| 50 | 53 | $add = "data=$idData&"; |
| 51 | -if (!is_null (GetUrlParam (DB))) $add .= DB . "=" . GetUrlParam (DB) . "&"; |
|
| 54 | +if (!is_null (GetUrlParam (DB))) { |
|
| 55 | + $add .= DB . "=" . GetUrlParam (DB) . "&"; |
|
| 56 | +} |
|
| 52 | 57 | $myBook = Book::getBookByDataId($idData); |
| 53 | 58 | |
| 54 | 59 | $book = new EPub ($myBook->getFilePath ("EPUB", $idData)); |
@@ -71,8 +76,7 @@ discard block |
||
| 71 | 76 | header('Expires: ' . gmdate('D, d M Y H:i:s', time()+$expires) . ' GMT'); |
| 72 | 77 | header ("Content-Type: " . $book->componentContentType($component)); |
| 73 | 78 | echo $data; |
| 74 | -} |
|
| 75 | -catch (Exception $e) { |
|
| 79 | +} catch (Exception $e) { |
|
| 76 | 80 | error_log ($e); |
| 77 | 81 | notFound (); |
| 78 | 82 | } |
| 79 | 83 | \ No newline at end of file |
@@ -25,7 +25,8 @@ discard block |
||
| 25 | 25 | * @return |
| 26 | 26 | * Transliterated text. |
| 27 | 27 | */ |
| 28 | -function _transliteration_process($string, $unknown = '?', $source_langcode = NULL) { |
|
| 28 | +function _transliteration_process($string, $unknown = '?', $source_langcode = NULL) |
|
| 29 | +{ |
|
| 29 | 30 | // ASCII is always valid NFC! If we're only ever given plain ASCII, we can |
| 30 | 31 | // avoid the overhead of initializing the decomposition tables by skipping |
| 31 | 32 | // out early. |
@@ -41,23 +42,17 @@ discard block |
||
| 41 | 42 | for ($n = 0; $n < 256; $n++) { |
| 42 | 43 | if ($n < 0xc0) { |
| 43 | 44 | $remaining = 0; |
| 44 | - } |
|
| 45 | - elseif ($n < 0xe0) { |
|
| 45 | + } elseif ($n < 0xe0) { |
|
| 46 | 46 | $remaining = 1; |
| 47 | - } |
|
| 48 | - elseif ($n < 0xf0) { |
|
| 47 | + } elseif ($n < 0xf0) { |
|
| 49 | 48 | $remaining = 2; |
| 50 | - } |
|
| 51 | - elseif ($n < 0xf8) { |
|
| 49 | + } elseif ($n < 0xf8) { |
|
| 52 | 50 | $remaining = 3; |
| 53 | - } |
|
| 54 | - elseif ($n < 0xfc) { |
|
| 51 | + } elseif ($n < 0xfc) { |
|
| 55 | 52 | $remaining = 4; |
| 56 | - } |
|
| 57 | - elseif ($n < 0xfe) { |
|
| 53 | + } elseif ($n < 0xfe) { |
|
| 58 | 54 | $remaining = 5; |
| 59 | - } |
|
| 60 | - else { |
|
| 55 | + } else { |
|
| 61 | 56 | $remaining = 0; |
| 62 | 57 | } |
| 63 | 58 | $tail_bytes[chr($n)] = $remaining; |
@@ -100,15 +95,13 @@ discard block |
||
| 100 | 95 | if (--$len && ($c = $str[++$i]) >= "\x80" && $c < "\xc0") { |
| 101 | 96 | // Legal tail bytes are nice. |
| 102 | 97 | $sequence .= $c; |
| 103 | - } |
|
| 104 | - else { |
|
| 98 | + } else { |
|
| 105 | 99 | if ($len == 0) { |
| 106 | 100 | // Premature end of string! Drop a replacement character into |
| 107 | 101 | // output to represent the invalid UTF-8 sequence. |
| 108 | 102 | $result .= $unknown; |
| 109 | 103 | break 2; |
| 110 | - } |
|
| 111 | - else { |
|
| 104 | + } else { |
|
| 112 | 105 | // Illegal tail byte; abandon the sequence. |
| 113 | 106 | $result .= $unknown; |
| 114 | 107 | // Back up and reprocess this byte; it may itself be a legal |
@@ -123,34 +116,27 @@ discard block |
||
| 123 | 116 | $n = ord($head); |
| 124 | 117 | if ($n <= 0xdf) { |
| 125 | 118 | $ord = ($n - 192) * 64 + (ord($sequence[1]) - 128); |
| 126 | - } |
|
| 127 | - elseif ($n <= 0xef) { |
|
| 119 | + } elseif ($n <= 0xef) { |
|
| 128 | 120 | $ord = ($n - 224) * 4096 + (ord($sequence[1]) - 128) * 64 + (ord($sequence[2]) - 128); |
| 129 | - } |
|
| 130 | - elseif ($n <= 0xf7) { |
|
| 121 | + } elseif ($n <= 0xf7) { |
|
| 131 | 122 | $ord = ($n - 240) * 262144 + (ord($sequence[1]) - 128) * 4096 + (ord($sequence[2]) - 128) * 64 + (ord($sequence[3]) - 128); |
| 132 | - } |
|
| 133 | - elseif ($n <= 0xfb) { |
|
| 123 | + } elseif ($n <= 0xfb) { |
|
| 134 | 124 | $ord = ($n - 248) * 16777216 + (ord($sequence[1]) - 128) * 262144 + (ord($sequence[2]) - 128) * 4096 + (ord($sequence[3]) - 128) * 64 + (ord($sequence[4]) - 128); |
| 135 | - } |
|
| 136 | - elseif ($n <= 0xfd) { |
|
| 125 | + } elseif ($n <= 0xfd) { |
|
| 137 | 126 | $ord = ($n - 252) * 1073741824 + (ord($sequence[1]) - 128) * 16777216 + (ord($sequence[2]) - 128) * 262144 + (ord($sequence[3]) - 128) * 4096 + (ord($sequence[4]) - 128) * 64 + (ord($sequence[5]) - 128); |
| 138 | 127 | } |
| 139 | 128 | $result .= _transliteration_replace($ord, $unknown, $source_langcode); |
| 140 | 129 | $head = ''; |
| 141 | - } |
|
| 142 | - elseif ($c < "\x80") { |
|
| 130 | + } elseif ($c < "\x80") { |
|
| 143 | 131 | // ASCII byte. |
| 144 | 132 | $result .= $c; |
| 145 | 133 | $head = ''; |
| 146 | - } |
|
| 147 | - elseif ($c < "\xc0") { |
|
| 134 | + } elseif ($c < "\xc0") { |
|
| 148 | 135 | // Illegal tail bytes. |
| 149 | 136 | if ($head == '') { |
| 150 | 137 | $result .= $unknown; |
| 151 | 138 | } |
| 152 | - } |
|
| 153 | - else { |
|
| 139 | + } else { |
|
| 154 | 140 | // Miscellaneous freaks. |
| 155 | 141 | $result .= $unknown; |
| 156 | 142 | $head = ''; |
@@ -175,7 +161,8 @@ discard block |
||
| 175 | 161 | * @return |
| 176 | 162 | * ASCII replacement character. |
| 177 | 163 | */ |
| 178 | -function _transliteration_replace($ord, $unknown = '?', $langcode = NULL) { |
|
| 164 | +function _transliteration_replace($ord, $unknown = '?', $langcode = NULL) |
|
| 165 | +{ |
|
| 179 | 166 | static $map = array(); |
| 180 | 167 | |
| 181 | 168 | //GL: set language later |
@@ -195,12 +182,10 @@ discard block |
||
| 195 | 182 | if ($langcode != 'en' && isset($variant[$langcode])) { |
| 196 | 183 | // Merge in language specific mappings. |
| 197 | 184 | $map[$bank][$langcode] = $variant[$langcode] + $base; |
| 198 | - } |
|
| 199 | - else { |
|
| 185 | + } else { |
|
| 200 | 186 | $map[$bank][$langcode] = $base; |
| 201 | 187 | } |
| 202 | - } |
|
| 203 | - else { |
|
| 188 | + } else { |
|
| 204 | 189 | $map[$bank][$langcode] = array(); |
| 205 | 190 | } |
| 206 | 191 | } |
@@ -15,7 +15,9 @@ |
||
| 15 | 15 | |
| 16 | 16 | $idData = getURLParam ("data", NULL); |
| 17 | 17 | $add = "data=$idData&"; |
| 18 | -if (!is_null (GetUrlParam (DB))) $add .= DB . "=" . GetUrlParam (DB) . "&"; |
|
| 18 | +if (!is_null (GetUrlParam (DB))) { |
|
| 19 | + $add .= DB . "=" . GetUrlParam (DB) . "&"; |
|
| 20 | +} |
|
| 19 | 21 | $myBook = Book::getBookByDataId($idData); |
| 20 | 22 | |
| 21 | 23 | $book = new EPub ($myBook->getFilePath ("EPUB", $idData)); |
@@ -14,8 +14,9 @@ |
||
| 14 | 14 | $page = getURLParam ("page", Base::PAGE_INDEX); |
| 15 | 15 | $query = getURLParam ("query"); |
| 16 | 16 | $n = getURLParam ("n", "1"); |
| 17 | - if ($query) |
|
| 18 | - $page = Base::PAGE_OPENSEARCH_QUERY; |
|
| 17 | + if ($query) { |
|
| 18 | + $page = Base::PAGE_OPENSEARCH_QUERY; |
|
| 19 | + } |
|
| 19 | 20 | $qid = getURLParam ("id"); |
| 20 | 21 | |
| 21 | 22 | if ($config ['cops_fetch_protect'] == "1") { |
@@ -21,13 +21,11 @@ |
||
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | if(!is_null($config['cops_basic_authentication']) && |
| 24 | - is_array($config['cops_basic_authentication'])) |
|
| 25 | -{ |
|
| 24 | + is_array($config['cops_basic_authentication'])) { |
|
| 26 | 25 | if (!isset($_SERVER['PHP_AUTH_USER']) || |
| 27 | 26 | (isset($_SERVER['PHP_AUTH_USER']) && |
| 28 | 27 | ($_SERVER['PHP_AUTH_USER']!=$config['cops_basic_authentication']['username'] || |
| 29 | - $_SERVER['PHP_AUTH_PW'] != $config['cops_basic_authentication']['password']))) |
|
| 30 | - { |
|
| 28 | + $_SERVER['PHP_AUTH_PW'] != $config['cops_basic_authentication']['password']))) { |
|
| 31 | 29 | header('WWW-Authenticate: Basic realm="COPS Authentication"'); |
| 32 | 30 | header('HTTP/1.0 401 Unauthorized'); |
| 33 | 31 | echo 'This site is password protected'; |
@@ -6,8 +6,9 @@ |
||
| 6 | 6 | * @author Sébastien Lucas <[email protected]> |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | - if (!isset($config)) |
|
| 10 | - $config = array(); |
|
| 9 | + if (!isset($config)) { |
|
| 10 | + $config = array(); |
|
| 11 | + } |
|
| 11 | 12 | |
| 12 | 13 | /* |
| 13 | 14 | * The directory containing calibre's metadata.db file, with sub-directories |
@@ -237,8 +237,7 @@ |
||
| 237 | 237 | $db = new PDO('sqlite:'. Base::getDbFileName ($i)); |
| 238 | 238 | $result = $db->prepare("select books.path || '/' || data.name || '.' || lower (format) as fullpath from data join books on data.book = books.id"); |
| 239 | 239 | $result->execute (); |
| 240 | - while ($post = $result->fetchObject ()) |
|
| 241 | - { |
|
| 240 | + while ($post = $result->fetchObject ()) { |
|
| 242 | 241 | if (!is_file (Base::getDbDirectory ($i) . $post->fullpath)) { |
| 243 | 242 | echo "<p>" . Base::getDbDirectory ($i) . $post->fullpath . "</p>"; |
| 244 | 243 | } |
@@ -13,20 +13,24 @@ discard block |
||
| 13 | 13 | public $id; |
| 14 | 14 | public $lang_code; |
| 15 | 15 | |
| 16 | - public function __construct($pid, $plang_code) { |
|
| 16 | + public function __construct($pid, $plang_code) |
|
| 17 | + { |
|
| 17 | 18 | $this->id = $pid; |
| 18 | 19 | $this->lang_code = $plang_code; |
| 19 | 20 | } |
| 20 | 21 | |
| 21 | - public function getUri () { |
|
| 22 | + public function getUri () |
|
| 23 | + { |
|
| 22 | 24 | return "?page=".parent::PAGE_LANGUAGE_DETAIL."&id=$this->id"; |
| 23 | 25 | } |
| 24 | 26 | |
| 25 | - public function getEntryId () { |
|
| 27 | + public function getEntryId () |
|
| 28 | + { |
|
| 26 | 29 | return self::ALL_LANGUAGES_ID.":".$this->id; |
| 27 | 30 | } |
| 28 | 31 | |
| 29 | - public static function getLanguageString ($code) { |
|
| 32 | + public static function getLanguageString ($code) |
|
| 33 | + { |
|
| 30 | 34 | $string = localize("languages.".$code); |
| 31 | 35 | if (preg_match ("/^languages/", $string)) { |
| 32 | 36 | return $code; |
@@ -34,12 +38,14 @@ discard block |
||
| 34 | 38 | return $string; |
| 35 | 39 | } |
| 36 | 40 | |
| 37 | - public static function getCount() { |
|
| 41 | + public static function getCount() |
|
| 42 | + { |
|
| 38 | 43 | // str_format (localize("languages.alphabetical", count(array)) |
| 39 | 44 | return parent::getCountGeneric ("languages", self::ALL_LANGUAGES_ID, parent::PAGE_ALL_LANGUAGES); |
| 40 | 45 | } |
| 41 | 46 | |
| 42 | - public static function getLanguageById ($languageId) { |
|
| 47 | + public static function getLanguageById ($languageId) |
|
| 48 | + { |
|
| 43 | 49 | $result = parent::getDb ()->prepare('select id, lang_code from languages where id = ?'); |
| 44 | 50 | $result->execute (array ($languageId)); |
| 45 | 51 | if ($post = $result->fetchObject ()) { |
@@ -50,15 +56,15 @@ discard block |
||
| 50 | 56 | |
| 51 | 57 | |
| 52 | 58 | |
| 53 | - public static function getAllLanguages() { |
|
| 59 | + public static function getAllLanguages() |
|
| 60 | + { |
|
| 54 | 61 | $result = parent::getDb ()->query('select languages.id as id, languages.lang_code as lang_code, count(*) as count |
| 55 | 62 | from languages, books_languages_link |
| 56 | 63 | where languages.id = books_languages_link.lang_code |
| 57 | 64 | group by languages.id, books_languages_link.lang_code |
| 58 | 65 | order by languages.lang_code'); |
| 59 | 66 | $entryArray = array(); |
| 60 | - while ($post = $result->fetchObject ()) |
|
| 61 | - { |
|
| 67 | + while ($post = $result->fetchObject ()) { |
|
| 62 | 68 | $language = new Language ($post->id, $post->lang_code); |
| 63 | 69 | array_push ($entryArray, new Entry (Language::getLanguageString ($language->lang_code), $language->getEntryId (), |
| 64 | 70 | str_format (localize("bookword", $post->count), $post->count), "text", |