|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* COPS (Calibre OPDS PHP Server) class file |
|
4
|
|
|
* |
|
5
|
|
|
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html) |
|
6
|
|
|
* @author Sébastien Lucas <[email protected]> |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
class Language |
|
10
|
|
|
{ |
|
11
|
|
|
const ALL_LANGUAGES_ID = "cops:languages"; |
|
12
|
|
|
|
|
13
|
|
|
public $id; |
|
14
|
|
|
public $lang_code; |
|
15
|
|
|
|
|
16
|
3 |
|
public function __construct($pid, $plang_code) { |
|
17
|
3 |
|
$this->id = $pid; |
|
18
|
3 |
|
$this->lang_code = $plang_code; |
|
19
|
3 |
|
} |
|
20
|
|
|
|
|
21
|
2 |
|
public function getUri () { |
|
22
|
2 |
|
return "?page=".Base::PAGE_LANGUAGE_DETAIL."&id=$this->id"; |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
3 |
|
public function getEntryId () { |
|
26
|
3 |
|
return self::ALL_LANGUAGES_ID.":".$this->id; |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
13 |
|
public static function getLanguageString ($code) { |
|
30
|
13 |
|
$string = localize("languages.".$code); |
|
31
|
13 |
|
if (preg_match ("/^languages/", $string)) { |
|
32
|
|
|
return $code; |
|
33
|
|
|
} |
|
34
|
13 |
|
return $string; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
18 |
|
public static function getCount() { |
|
38
|
|
|
// str_format (localize("languages.alphabetical", count(array)) |
|
|
|
|
|
|
39
|
18 |
|
return Base::getCountGeneric ("languages", self::ALL_LANGUAGES_ID, Base::PAGE_ALL_LANGUAGES); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
1 |
View Code Duplication |
public static function getLanguageById ($languageId) { |
|
43
|
1 |
|
$result = Base::getDb ()->prepare('select id, lang_code from languages where id = ?'); |
|
44
|
1 |
|
$result->execute (array ($languageId)); |
|
45
|
1 |
|
if ($post = $result->fetchObject ()) { |
|
46
|
1 |
|
return new Language ($post->id, Language::getLanguageString ($post->lang_code)); |
|
47
|
|
|
} |
|
48
|
|
|
return NULL; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
|
|
52
|
|
|
|
|
53
|
2 |
|
public static function getAllLanguages() { |
|
54
|
2 |
|
$result = Base::getDb()->query('select languages.id as id, languages.lang_code as lang_code, count(*) as count |
|
55
|
|
|
from languages, books_languages_link |
|
56
|
|
|
where languages.id = books_languages_link.lang_code |
|
57
|
|
|
group by languages.id, books_languages_link.lang_code |
|
58
|
2 |
|
order by languages.lang_code'); |
|
59
|
2 |
|
$entryArray = array(); |
|
60
|
2 |
|
while ($post = $result->fetchObject ()) |
|
61
|
|
|
{ |
|
62
|
2 |
|
$language = new Language ($post->id, $post->lang_code); |
|
63
|
2 |
|
array_push ($entryArray, new Entry (Language::getLanguageString ($language->lang_code), $language->getEntryId (), |
|
64
|
2 |
|
str_format (localize("bookword", $post->count), $post->count), "text", |
|
65
|
2 |
|
array ( new LinkNavigation ($language->getUri ())), "", $post->count)); |
|
66
|
2 |
|
} |
|
67
|
2 |
|
return $entryArray; |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.