1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | Piwigo - a PHP based picture gallery | |
---|
4 | // +-----------------------------------------------------------------------+ |
---|
5 | // | Copyright(C) 2008 Piwigo Team http://piwigo.org | |
---|
6 | // | Copyright(C) 2003-2008 Piwigo team http://phpwebgallery.net | |
---|
7 | // | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick | |
---|
8 | // +-----------------------------------------------------------------------+ |
---|
9 | // | This program is free software; you can redistribute it and/or modify | |
---|
10 | // | it under the terms of the GNU General Public License as published by | |
---|
11 | // | the Free Software Foundation | |
---|
12 | // | | |
---|
13 | // | This program is distributed in the hope that it will be useful, but | |
---|
14 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
15 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
16 | // | General Public License for more details. | |
---|
17 | // | | |
---|
18 | // | You should have received a copy of the GNU General Public License | |
---|
19 | // | along with this program; if not, write to the Free Software | |
---|
20 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
21 | // | USA. | |
---|
22 | // +-----------------------------------------------------------------------+ |
---|
23 | |
---|
24 | add_event_handler('loc_end_page_header', 'set_admin_advice_add_css' ); |
---|
25 | |
---|
26 | // Add a XHTML tag in HEAD section |
---|
27 | function set_admin_advice_add_css() |
---|
28 | { |
---|
29 | global $template, $page; |
---|
30 | if ( isset($page['body_id']) and $page['body_id']=='theAdminPage' |
---|
31 | and $page['page'] == 'intro' |
---|
32 | ) |
---|
33 | {// This Plugin works only on the Admin page |
---|
34 | $template->append( |
---|
35 | 'head_elements', |
---|
36 | '<link rel="stylesheet" type="text/css" ' |
---|
37 | . 'href="'.PHPWG_PLUGINS_PATH.'admin_advices/default-layout.css">' |
---|
38 | ); |
---|
39 | add_event_handler('loc_begin_page_tail', 'set_admin_advice' ); |
---|
40 | } |
---|
41 | } |
---|
42 | |
---|
43 | // Build an advice on the Admin Intro page |
---|
44 | function set_admin_advice() |
---|
45 | { |
---|
46 | global $page, $user, $template, $conf, $prefixeTable, $lang; |
---|
47 | $my_path = dirname(__FILE__).'/'; |
---|
48 | |
---|
49 | // Include language advices |
---|
50 | foreach ($conf as $key => $value) |
---|
51 | { |
---|
52 | if ( is_string($value) ) |
---|
53 | { |
---|
54 | $bool = ($value == 'false') ? false : $value; |
---|
55 | $bool = ($value == 'true') ? true : $bool; |
---|
56 | $conf[$key] = $bool; |
---|
57 | } |
---|
58 | } |
---|
59 | $adv = array(); |
---|
60 | ini_set('error_reporting', E_ALL); |
---|
61 | ini_set('display_errors', true); |
---|
62 | |
---|
63 | include_once( $my_path."adv_set.php" ); |
---|
64 | |
---|
65 | $cases = range(0,count($lang['Adv_case'])-1); |
---|
66 | srand ((double) microtime() * 10000000); |
---|
67 | shuffle($cases); |
---|
68 | |
---|
69 | |
---|
70 | $cond = false; |
---|
71 | foreach ($cases as $id) |
---|
72 | { |
---|
73 | if (!isset($adv['c'][$id])) $adv['c'][$id] = true; |
---|
74 | if (!isset($adv['n'][$id])) $adv['c'][$id] = false; |
---|
75 | if (!isset($lang['Adv_case'][$id])) $adv['c'][$id] = false; |
---|
76 | $cond = $adv['c'][$id]; |
---|
77 | if ($cond) break; |
---|
78 | } |
---|
79 | $confk = $adv['n'][$id]; |
---|
80 | if (substr($confk,0,2) == '**') $confk = substr($confk,2); |
---|
81 | else $confk = '$conf[' . "'$confk']"; |
---|
82 | $advice_text = (isset($adv['v'][$id])) ? $adv['v'][$id] : ''; |
---|
83 | $more = $lang['Adv_case'][$id]; |
---|
84 | |
---|
85 | $template->set_filenames(array( |
---|
86 | 'admin_advice' => $my_path.'admin_advices.tpl') |
---|
87 | ); |
---|
88 | |
---|
89 | // Mysql status |
---|
90 | $result = pwg_query('SHOW TABLE STATUS ;'); |
---|
91 | $pwgspacef = $spacef = $pwgsize = $size = 0; |
---|
92 | $len = strlen($prefixeTable); |
---|
93 | $check = array(); |
---|
94 | while ($row = mysql_fetch_array($result)) |
---|
95 | { |
---|
96 | $size += ($row['Data_length'] + $row['Index_length']); |
---|
97 | $spacef += $row['Data_free']; |
---|
98 | if ( substr( $row['Name'], 0, $len ) == $prefixeTable ) { |
---|
99 | $pwgsize += ($row['Data_length'] + $row['Index_length']); |
---|
100 | $pwgspacef += $row['Data_free']; |
---|
101 | $check[] = (string) $row['Check_time']; |
---|
102 | } |
---|
103 | } |
---|
104 | $size .= ' bytes'; |
---|
105 | $pwgsize .= ' bytes'; |
---|
106 | $spacef .= ' bytes'; |
---|
107 | $pwgspacef .= ' bytes'; |
---|
108 | if ($size > 1024) $size = round($size / 1024, 1) . ' Kb'; |
---|
109 | if ($size > 1024) $size = round($size / 1024, 1) . ' Mb'; |
---|
110 | if ($pwgsize > 1024) $pwgsize = round($pwgsize / 1024, 1) . ' Kb'; |
---|
111 | if ($pwgsize > 1024) $pwgsize = round($pwgsize / 1024, 1) . ' Mb'; |
---|
112 | if ($spacef > 1024) $spacef = round($spacef / 1024, 1) . ' Kb'; |
---|
113 | if ($spacef > 1024) $spacef = round($spacef / 1024, 1) . ' Mb'; |
---|
114 | if ($pwgspacef > 1024) $pwgspacef = round($pwgspacef / 1024, 1) . ' Kb'; |
---|
115 | if ($pwgspacef > 1024) $pwgspacef = round($pwgspacef / 1024, 1) . ' Mb'; |
---|
116 | $check = array_flip(array_flip($check)); |
---|
117 | rsort($check); |
---|
118 | $end = end($check); |
---|
119 | $prev = prev($check); |
---|
120 | $first = $check[0]; |
---|
121 | $checkon = ''; |
---|
122 | if (empty($end)) $end = $prev; |
---|
123 | if ($end == $first) $checkon .= 'Last table check on: %s'; |
---|
124 | else $checkon .= 'Most recent table check on: %s - oldest: %s'; |
---|
125 | $checkon = sprintf($checkon, $first, $end); |
---|
126 | $template->assign( |
---|
127 | array( |
---|
128 | 'prefixTable' => $prefixeTable, |
---|
129 | 'pwgsize' => $pwgsize, |
---|
130 | 'size' => $size, |
---|
131 | 'checked_tables' => $checkon, |
---|
132 | 'pwgspacef' => $pwgspacef, |
---|
133 | 'spacef' => $spacef, |
---|
134 | 'U_maintenance' => get_root_url() |
---|
135 | . 'admin.php?page=maintenance&action=database', |
---|
136 | ) |
---|
137 | ); |
---|
138 | |
---|
139 | // If there is an advice |
---|
140 | if ( $cond ) |
---|
141 | { |
---|
142 | |
---|
143 | // Random Thumbnail |
---|
144 | $query = ' |
---|
145 | SELECT * |
---|
146 | FROM '.IMAGES_TABLE.' |
---|
147 | ORDER BY RAND(NOW()) |
---|
148 | LIMIT 0, 1 |
---|
149 | ;'; |
---|
150 | $result = pwg_query($query); |
---|
151 | $row = mysql_fetch_assoc($result); |
---|
152 | if ( is_array($row) ) |
---|
153 | { |
---|
154 | $url_modify = get_root_url().'admin.php?page=picture_modify' |
---|
155 | .'&image_id='.$row['id']; |
---|
156 | $query = ' |
---|
157 | SELECT * FROM '.IMAGE_TAG_TABLE.' |
---|
158 | WHERE image_id = ' . $row['id'] .' |
---|
159 | ;'; |
---|
160 | $tag_count = mysql_num_rows(mysql_query($query)); |
---|
161 | $template->assign('thumbnail', |
---|
162 | array( |
---|
163 | 'IMAGE' => get_thumbnail_url($row), |
---|
164 | 'IMAGE_ALT' => $row['file'], |
---|
165 | 'IMAGE_TITLE' => $row['name'], |
---|
166 | 'METADATA' => (empty($row['date_metadata_update'])) ? |
---|
167 | 'un' : '', |
---|
168 | 'NAME' => (empty($row['name'])) ? |
---|
169 | 'un' : '', |
---|
170 | 'COMMENT' => (empty($row['comment'])) ? |
---|
171 | 'un' : '', |
---|
172 | 'AUTHOR' => (empty($row['author'])) ? |
---|
173 | 'un' : '', |
---|
174 | 'CREATE_DATE' => (empty($row['date_creation'])) ? |
---|
175 | 'un' : '', |
---|
176 | 'TAGS' => ($tag_count == 0) ? |
---|
177 | 'un' : '', |
---|
178 | 'NUM_TAGS' => $tag_count, |
---|
179 | 'U_MODIFY' => $url_modify, |
---|
180 | ) |
---|
181 | ); |
---|
182 | } |
---|
183 | //$advice_text = array_shift($adv); |
---|
184 | $template->assign( |
---|
185 | array( |
---|
186 | 'ADVICE_ABOUT' => $confk, |
---|
187 | 'ADVICE_TEXT' => $advice_text, |
---|
188 | ) |
---|
189 | ); |
---|
190 | $template->assign('More', $more ); |
---|
191 | $template->pparse('admin_advice'); |
---|
192 | } |
---|
193 | } |
---|
194 | ?> |
---|