1 | <?php |
---|
2 | /* |
---|
3 | Theme Name: Gally |
---|
4 | Version: auto |
---|
5 | Description: Parent theme for all the Gally themes |
---|
6 | Theme URI: http://piwigo.org/ext/extension_view.php?eid=382 |
---|
7 | Author: Grum |
---|
8 | Author URI: http://www.grum.fr |
---|
9 | */ |
---|
10 | |
---|
11 | $themeconf = array( |
---|
12 | 'theme' => 'gally-default', |
---|
13 | 'icon_dir' => 'themes/gally-default/icon', |
---|
14 | 'mime_icon_dir' => 'themes/gally-default/icon/mimetypes/', |
---|
15 | 'activable' => false |
---|
16 | ); |
---|
17 | |
---|
18 | |
---|
19 | if(!defined('IN_ADMIN')) add_event_handler('init', 'initTemplateVar'); |
---|
20 | |
---|
21 | /** |
---|
22 | * GallyTpl class is used to initialise some templates variable and provide some |
---|
23 | * usefull function in template |
---|
24 | */ |
---|
25 | class GallyTpl |
---|
26 | { |
---|
27 | private $comment=array( |
---|
28 | 'id' => null |
---|
29 | ); |
---|
30 | |
---|
31 | public function __construct() |
---|
32 | { |
---|
33 | global $template, $themeconf; |
---|
34 | |
---|
35 | $this->loadConfDirectories(); |
---|
36 | $this->loadThemeJS(); |
---|
37 | |
---|
38 | $template->assign('gally', $this); |
---|
39 | } |
---|
40 | |
---|
41 | public function getToken() |
---|
42 | { |
---|
43 | return(get_pwg_token()); |
---|
44 | } |
---|
45 | |
---|
46 | public function getCommentKey($id) |
---|
47 | { |
---|
48 | if($this->loadComment($id)) |
---|
49 | { |
---|
50 | return(get_ephemeral_key(2, $this->comment['image_id'])); |
---|
51 | } |
---|
52 | return(''); |
---|
53 | } |
---|
54 | |
---|
55 | public function getCommentImage($id) |
---|
56 | { |
---|
57 | if($this->loadComment($id)) |
---|
58 | { |
---|
59 | return($this->comment['image_id']); |
---|
60 | } |
---|
61 | return(''); |
---|
62 | } |
---|
63 | |
---|
64 | public function getAlternateBannerContent() |
---|
65 | { |
---|
66 | global $template; |
---|
67 | |
---|
68 | return(html_entity_decode($template->smarty->get_config_vars('alternateBannerContent'))); |
---|
69 | } |
---|
70 | |
---|
71 | public function getRandomBox($value) |
---|
72 | { |
---|
73 | global $template; |
---|
74 | |
---|
75 | if(is_numeric($value)) return(rand(-$value, $value)); |
---|
76 | |
---|
77 | $v=$template->smarty->get_config_vars($value); |
---|
78 | return(rand(-$v, $v)); |
---|
79 | } |
---|
80 | |
---|
81 | /** |
---|
82 | * |
---|
83 | */ |
---|
84 | private function loadThemeJS() |
---|
85 | { |
---|
86 | global $template; |
---|
87 | |
---|
88 | $currentTheme=$template->get_template_vars('themeconf'); |
---|
89 | $file="themes/".$currentTheme['id']."/js/theme.js"; |
---|
90 | |
---|
91 | if(file_exists(dirname($_SERVER['SCRIPT_FILENAME']).'/'.$file)) |
---|
92 | { |
---|
93 | $template->scriptLoader->add($currentTheme['id'].'.theme.js', 'header', array('jquery'), $file, 0); |
---|
94 | } |
---|
95 | } |
---|
96 | |
---|
97 | /** |
---|
98 | * load conf directories in smarty variables |
---|
99 | * {$default_conf} |
---|
100 | * {$local_conf} |
---|
101 | */ |
---|
102 | private function loadConfDirectories() |
---|
103 | { |
---|
104 | global $template; |
---|
105 | |
---|
106 | $themes=$template->get_template_vars('themes'); |
---|
107 | foreach($themes as $theme) |
---|
108 | { |
---|
109 | $dir=dirname($_SERVER['SCRIPT_FILENAME'])."/themes/".$theme['id']."/conf/"; |
---|
110 | $dirlocal=dirname($_SERVER['SCRIPT_FILENAME'])."/".PWG_LOCAL_DIR."themes/".$theme['id']."/conf/"; |
---|
111 | |
---|
112 | if(file_exists($dir."local.conf")) $template->smarty->config_load($dir."default.conf"); |
---|
113 | if(file_exists($dirlocal."local.conf")) $template->smarty->config_load($dirlocal."local.conf"); |
---|
114 | } |
---|
115 | } |
---|
116 | |
---|
117 | /** |
---|
118 | * load comment properties |
---|
119 | * result is stored in $this->comment |
---|
120 | * |
---|
121 | * @param Integer $id: comment id |
---|
122 | */ |
---|
123 | private function loadComment($id) |
---|
124 | { |
---|
125 | if($id==null or $id=='') return(false); |
---|
126 | if($id==$this->comment['id']) return(true); |
---|
127 | |
---|
128 | $sql="SELECT image_id FROM ".COMMENTS_TABLE." WHERE id=$id"; |
---|
129 | $result=pwg_query($sql); |
---|
130 | if($result) |
---|
131 | { |
---|
132 | while($row=pwg_db_fetch_assoc($result)) |
---|
133 | { |
---|
134 | $this->comment=array( |
---|
135 | 'id' => $id, |
---|
136 | 'image_id' => $row['image_id'] |
---|
137 | ); |
---|
138 | return(true); |
---|
139 | } |
---|
140 | } |
---|
141 | return(false); |
---|
142 | } |
---|
143 | } |
---|
144 | |
---|
145 | |
---|
146 | |
---|
147 | function initTemplateVar() |
---|
148 | { |
---|
149 | $gallyVar=new GallyTpl(); |
---|
150 | } |
---|
151 | |
---|
152 | ?> |
---|