1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | Piwigo - a PHP based picture gallery | |
---|
4 | // +-----------------------------------------------------------------------+ |
---|
5 | // | Copyright(C) 2008-2010 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 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 advice |
---|
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 | |
---|
61 | include_once( $my_path."adv_set.php" ); |
---|
62 | |
---|
63 | $cases = range(0,count($lang['Adv_case'])-1); |
---|
64 | srand ((double) microtime() * 10000000); |
---|
65 | shuffle($cases); |
---|
66 | |
---|
67 | |
---|
68 | $cond = false; |
---|
69 | foreach ($cases as $id) |
---|
70 | { |
---|
71 | if (!isset($adv['c'][$id])) $adv['c'][$id] = true; |
---|
72 | if (!isset($adv['n'][$id])) $adv['c'][$id] = false; |
---|
73 | if (!isset($lang['Adv_case'][$id])) $adv['c'][$id] = false; |
---|
74 | $cond = $adv['c'][$id]; |
---|
75 | if ($cond) break; |
---|
76 | } |
---|
77 | $confk = $adv['n'][$id]; |
---|
78 | if (substr($confk,0,2) == '**') $confk = substr($confk,2); |
---|
79 | else $confk = '$conf[' . "'$confk']"; |
---|
80 | $advice_text = (isset($adv['v'][$id])) ? $adv['v'][$id] : ''; |
---|
81 | $more = $lang['Adv_case'][$id]; |
---|
82 | |
---|
83 | $template->set_filenames(array( |
---|
84 | 'admin_advice' => $my_path.'admin_advices.tpl') |
---|
85 | ); |
---|
86 | |
---|
87 | // Mysql status |
---|
88 | $result = pwg_query('SHOW TABLE STATUS ;'); |
---|
89 | $pwgspacef = $spacef = $pwgsize = $size = 0; |
---|
90 | $len = strlen($prefixeTable); |
---|
91 | $check = array(); |
---|
92 | while ($row = mysql_fetch_array($result)) |
---|
93 | { |
---|
94 | $size += ($row['Data_length'] + $row['Index_length']); |
---|
95 | $spacef += $row['Data_free']; |
---|
96 | if ( substr( $row['Name'], 0, $len ) == $prefixeTable ) { |
---|
97 | $pwgsize += ($row['Data_length'] + $row['Index_length']); |
---|
98 | $pwgspacef += $row['Data_free']; |
---|
99 | $check[] = (string) $row['Check_time']; |
---|
100 | } |
---|
101 | } |
---|
102 | $size .= ' bytes'; |
---|
103 | $pwgsize .= ' bytes'; |
---|
104 | $spacef .= ' bytes'; |
---|
105 | $pwgspacef .= ' bytes'; |
---|
106 | if ($size > 1024) $size = round($size / 1024, 1) . ' Kb'; |
---|
107 | if ($size > 1024) $size = round($size / 1024, 1) . ' Mb'; |
---|
108 | if ($pwgsize > 1024) $pwgsize = round($pwgsize / 1024, 1) . ' Kb'; |
---|
109 | if ($pwgsize > 1024) $pwgsize = round($pwgsize / 1024, 1) . ' Mb'; |
---|
110 | if ($spacef > 1024) $spacef = round($spacef / 1024, 1) . ' Kb'; |
---|
111 | if ($spacef > 1024) $spacef = round($spacef / 1024, 1) . ' Mb'; |
---|
112 | if ($pwgspacef > 1024) $pwgspacef = round($pwgspacef / 1024, 1) . ' Kb'; |
---|
113 | if ($pwgspacef > 1024) $pwgspacef = round($pwgspacef / 1024, 1) . ' Mb'; |
---|
114 | $check = array_flip(array_flip($check)); |
---|
115 | rsort($check); |
---|
116 | $end = end($check); |
---|
117 | $prev = prev($check); |
---|
118 | $first = $check[0]; |
---|
119 | $checkon = ''; |
---|
120 | if (empty($end)) $end = $prev; |
---|
121 | if ($end == $first) $checkon .= 'Last table check on: %s'; |
---|
122 | else $checkon .= 'Most recent table check on: %s - oldest: %s'; |
---|
123 | $checkon = sprintf($checkon, $first, $end); |
---|
124 | $template->assign( |
---|
125 | array( |
---|
126 | 'prefixTable' => $prefixeTable, |
---|
127 | 'pwgsize' => $pwgsize, |
---|
128 | 'size' => $size, |
---|
129 | 'checked_tables' => $checkon, |
---|
130 | 'pwgspacef' => $pwgspacef, |
---|
131 | 'spacef' => $spacef, |
---|
132 | 'U_maintenance' => get_root_url() |
---|
133 | . 'admin.php?page=maintenance&action=database', |
---|
134 | ) |
---|
135 | ); |
---|
136 | |
---|
137 | // If there is advice |
---|
138 | if ( $cond ) |
---|
139 | { |
---|
140 | |
---|
141 | // Random Thumbnail |
---|
142 | $query = ' |
---|
143 | SELECT * |
---|
144 | FROM '.IMAGES_TABLE.' |
---|
145 | ORDER BY RAND(NOW()) |
---|
146 | LIMIT 0, 1 |
---|
147 | ;'; |
---|
148 | $result = pwg_query($query); |
---|
149 | $row = mysql_fetch_assoc($result); |
---|
150 | if ( is_array($row) ) |
---|
151 | { |
---|
152 | $url_modify = get_root_url().'admin.php?page=picture_modify' |
---|
153 | .'&image_id='.$row['id']; |
---|
154 | $query = ' |
---|
155 | SELECT * FROM '.IMAGE_TAG_TABLE.' |
---|
156 | WHERE image_id = ' . $row['id'] .' |
---|
157 | ;'; |
---|
158 | $tag_count = mysql_num_rows(pwg_query($query)); |
---|
159 | $template->assign('thumbnail', |
---|
160 | array( |
---|
161 | 'IMAGE' => get_thumbnail_url($row), |
---|
162 | 'IMAGE_ALT' => $row['file'], |
---|
163 | 'IMAGE_TITLE' => $row['name'], |
---|
164 | 'METADATA' => (empty($row['date_metadata_update'])) ? |
---|
165 | 'un' : '', |
---|
166 | 'NAME' => (empty($row['name'])) ? |
---|
167 | 'un' : '', |
---|
168 | 'COMMENT' => (empty($row['comment'])) ? |
---|
169 | 'un' : '', |
---|
170 | 'AUTHOR' => (empty($row['author'])) ? |
---|
171 | 'un' : '', |
---|
172 | 'CREATE_DATE' => (empty($row['date_creation'])) ? |
---|
173 | 'un' : '', |
---|
174 | 'TAGS' => ($tag_count == 0) ? |
---|
175 | 'un' : '', |
---|
176 | 'NUM_TAGS' => $tag_count, |
---|
177 | 'U_MODIFY' => $url_modify, |
---|
178 | ) |
---|
179 | ); |
---|
180 | } |
---|
181 | //$advice_text = array_shift($adv); |
---|
182 | $template->assign( |
---|
183 | array( |
---|
184 | 'ADVICE_ABOUT' => $confk, |
---|
185 | 'ADVICE_TEXT' => $advice_text, |
---|
186 | ) |
---|
187 | ); |
---|
188 | $template->assign('More', $more ); |
---|
189 | $template->pparse('admin_advice'); |
---|
190 | } |
---|
191 | } |
---|
192 | ?> |
---|