[3322] | 1 | <?php |
---|
| 2 | // +-----------------------------------------------------------------------+ |
---|
| 3 | // | DotClear Easy - a Piwigo Plugin | |
---|
[8425] | 4 | // | Copyright (C) 2007-2011 Ruben ARNAUD - rub@piwigo.org | |
---|
[3322] | 5 | // +-----------------------------------------------------------------------+ |
---|
| 6 | // | This program is free software; you can redistribute it and/or modify | |
---|
| 7 | // | it under the terms of the GNU General Public License as published by | |
---|
| 8 | // | the Free Software Foundation | |
---|
| 9 | // | | |
---|
| 10 | // | This program is distributed in the hope that it will be useful, but | |
---|
| 11 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
| 12 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
| 13 | // | General Public License for more details. | |
---|
| 14 | // | | |
---|
| 15 | // | You should have received a copy of the GNU General Public License | |
---|
| 16 | // | along with this program; if not, write to the Free Software | |
---|
| 17 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
| 18 | // | USA. | |
---|
| 19 | // +-----------------------------------------------------------------------+ |
---|
| 20 | |
---|
| 21 | class DotclearEasy |
---|
| 22 | { |
---|
| 23 | var $plugin_name, $plugin_path; |
---|
| 24 | var $opened, $to_close; |
---|
| 25 | |
---|
| 26 | function DotclearEasy($plugin_name, $plugin_path) |
---|
| 27 | { |
---|
| 28 | // Args |
---|
| 29 | $this->plugin_name = $plugin_name; |
---|
| 30 | $this->plugin_path = $plugin_path; |
---|
| 31 | // handler |
---|
| 32 | $this->initialize_event_handler(); |
---|
| 33 | } |
---|
| 34 | |
---|
| 35 | function initialize_event_handler() |
---|
| 36 | { |
---|
| 37 | if (script_basename() != $this->plugin_name.'_controller') |
---|
| 38 | { |
---|
| 39 | add_event_handler('loc_end_page_header', array(&$this, 'loc_end_page_header')); |
---|
| 40 | add_event_handler('loc_end_index', array(&$this, 'loc_end_index')); |
---|
| 41 | add_event_handler('picture_pictures_data', array(&$this, 'picture_pictures_data')); |
---|
| 42 | } |
---|
| 43 | |
---|
| 44 | if (isset($_GET[$this->plugin_name])) |
---|
| 45 | { |
---|
| 46 | add_event_handler('loc_begin_page_header', array(&$this, 'loc_begin_page_header')); |
---|
| 47 | pwg_set_session_var($this->plugin_name, ($_GET[$this->plugin_name] === 'open')); |
---|
| 48 | } |
---|
| 49 | $this->opened = pwg_get_session_var($this->plugin_name, false); |
---|
| 50 | $this->to_close = (isset($_GET[$this->plugin_name]) and ($_GET[$this->plugin_name] === 'close')); |
---|
| 51 | } |
---|
| 52 | |
---|
| 53 | function get_text_dotclear() |
---|
| 54 | { |
---|
| 55 | global $page, $lang_info; |
---|
| 56 | |
---|
| 57 | $list = array(); |
---|
| 58 | |
---|
| 59 | $S = ''; |
---|
| 60 | |
---|
| 61 | switch (script_basename()) |
---|
| 62 | { |
---|
| 63 | case 'index': |
---|
| 64 | { |
---|
| 65 | global $pictures; |
---|
| 66 | |
---|
| 67 | if (isset($pictures)) |
---|
| 68 | { |
---|
| 69 | $list = $pictures; |
---|
| 70 | } |
---|
| 71 | break; |
---|
| 72 | } |
---|
| 73 | case 'picture': |
---|
| 74 | { |
---|
| 75 | global $picture; |
---|
| 76 | |
---|
| 77 | if (isset($picture['current'])) |
---|
| 78 | { |
---|
| 79 | $list[] = $picture['current']; |
---|
| 80 | } |
---|
| 81 | break; |
---|
| 82 | } |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | if (empty($list) and !empty($page['items'])) |
---|
| 86 | { |
---|
| 87 | $query = ' |
---|
| 88 | SELECT * |
---|
| 89 | FROM '.IMAGES_TABLE.' |
---|
| 90 | WHERE id IN ('.implode(',', $page['items']).') |
---|
| 91 | ;'; |
---|
| 92 | |
---|
| 93 | $result = pwg_query($query); |
---|
| 94 | |
---|
| 95 | while ($row = mysql_fetch_assoc($result)) |
---|
| 96 | { |
---|
| 97 | $row['rank'] = $page['rank_of'][ $row['id'] ]; |
---|
| 98 | array_push($list, $row); |
---|
| 99 | } |
---|
| 100 | |
---|
| 101 | usort($list, 'rank_compare'); |
---|
| 102 | } |
---|
| 103 | |
---|
| 104 | if (!empty($list)) |
---|
| 105 | { |
---|
| 106 | set_make_full_url(); |
---|
| 107 | |
---|
| 108 | foreach ($list as $row) |
---|
| 109 | { |
---|
| 110 | //'[(('.$picture['current']['thumbnail'].'))|'.$picture['current']['url'].'|'.$lang_info['code'].']'; |
---|
| 111 | $S .= '*** '.(!empty($row['name']) ? $row['name'] : $row['file']).' ***\n'; |
---|
| 112 | $S .= '[(('. |
---|
| 113 | str_replace('/./', '/', get_thumbnail_url($row)).'))|'. |
---|
| 114 | duplicate_picture_url( |
---|
| 115 | array( |
---|
| 116 | 'image_id' => $row['id'], |
---|
| 117 | 'image_file' => $row['file'], |
---|
| 118 | )).'|'. |
---|
| 119 | $lang_info['code'].']\n\n'; |
---|
| 120 | } |
---|
| 121 | |
---|
| 122 | unset_make_full_url(); |
---|
| 123 | } |
---|
| 124 | |
---|
| 125 | return $S; |
---|
| 126 | } |
---|
| 127 | |
---|
| 128 | function loc_begin_page_header() |
---|
| 129 | { |
---|
| 130 | global $template; |
---|
| 131 | |
---|
| 132 | $redirect_url = ( script_basename()=='picture' |
---|
| 133 | ? duplicate_picture_url(array(), array($this->plugin_name)) |
---|
| 134 | : duplicate_index_url(array(), array($this->plugin_name)) |
---|
| 135 | ); |
---|
| 136 | |
---|
| 137 | $template->assign( |
---|
| 138 | array( |
---|
| 139 | 'page_refresh' => array( |
---|
| 140 | 'TIME' => 1, |
---|
| 141 | 'U_REFRESH' => $redirect_url |
---|
| 142 | ) |
---|
| 143 | )); |
---|
| 144 | } |
---|
| 145 | |
---|
| 146 | function loc_end_page_header() |
---|
| 147 | { |
---|
| 148 | global $template; |
---|
| 149 | |
---|
| 150 | if ($this->opened or $this->to_close) |
---|
| 151 | { |
---|
| 152 | $plugin_root_url = get_root_url().'plugins/'.$this->plugin_name.'/'; |
---|
| 153 | |
---|
| 154 | $js = ' |
---|
| 155 | <script type="text/javascript"> |
---|
| 156 | var theController = window.open("", "'.$this->plugin_name.'_controller", "alwaysRaised=yes,dependent=yes,toolbar=no,height=600,width=500,menubar=no,resizable=yes,scrollbars=yes,status=no");'; |
---|
| 157 | |
---|
| 158 | if ($this->to_close) |
---|
| 159 | { |
---|
| 160 | $js .= ' |
---|
| 161 | theController.close();'; |
---|
| 162 | } |
---|
| 163 | else |
---|
| 164 | { |
---|
| 165 | $js .= ' |
---|
| 166 | if (theController.location.toString()=="about:blank" || !theController.location.toString().match(/^(https?.*\/)'.$this->plugin_name.'_controller\.php(\?.+)?$/)) |
---|
| 167 | { |
---|
| 168 | theController.location = "'.$plugin_root_url.$this->plugin_name.'_controller.php"; |
---|
| 169 | } |
---|
| 170 | else |
---|
| 171 | { |
---|
| 172 | theController.focus(); |
---|
| 173 | } |
---|
| 174 | theController.document.getElementsByName("content_text")[0].value = "'.$this->get_text_dotclear().'";'; |
---|
| 175 | } |
---|
| 176 | $js .= ' |
---|
| 177 | </script>'; |
---|
| 178 | |
---|
| 179 | $template->append('head_elements', $js); |
---|
| 180 | } |
---|
| 181 | } |
---|
| 182 | |
---|
| 183 | function get_link_icon($main_link) |
---|
| 184 | { |
---|
| 185 | global $page; |
---|
| 186 | |
---|
| 187 | if (empty($page['items'])) |
---|
| 188 | { |
---|
| 189 | return; |
---|
| 190 | } |
---|
| 191 | |
---|
| 192 | $this->loading_lang(); |
---|
| 193 | |
---|
| 194 | if ($this->opened) |
---|
| 195 | { |
---|
| 196 | $suffix_url = 'close'; |
---|
| 197 | $link_title = l10n('close_window_dotcleareasy'); |
---|
| 198 | } |
---|
| 199 | else |
---|
| 200 | { |
---|
| 201 | $suffix_url = 'open'; |
---|
| 202 | $link_title = l10n('open_window_dotcleareasy'); |
---|
| 203 | } |
---|
| 204 | |
---|
| 205 | $link_url = add_url_params($main_link, array($this->plugin_name => $suffix_url)); |
---|
| 206 | if (!empty($link_url)) |
---|
| 207 | { |
---|
| 208 | $link_url = |
---|
[8818] | 209 | '<a class="pwg-state-default pwg-button" href="'.$link_url.'" title="'.$link_title.'" rel="nofollow"><img src="'.get_root_url().'plugins/'.$this->plugin_name.'/icon/controller_'.$suffix_url.'.png" class="button" alt="DotClear Easy controller"></a>'; |
---|
[3322] | 210 | } |
---|
| 211 | |
---|
| 212 | return $link_url; |
---|
| 213 | } |
---|
| 214 | |
---|
| 215 | function loc_end_index() |
---|
| 216 | { |
---|
| 217 | global $template; |
---|
| 218 | |
---|
| 219 | $link_url = $this->get_link_icon(duplicate_index_url()); |
---|
| 220 | if (!empty($link_url)) |
---|
| 221 | { |
---|
| 222 | $template->concat( |
---|
| 223 | 'PLUGIN_INDEX_ACTIONS', |
---|
| 224 | '<li>'.$link_url.'</li>'); |
---|
| 225 | } |
---|
| 226 | } |
---|
| 227 | |
---|
| 228 | function picture_pictures_data($pictures) |
---|
| 229 | { |
---|
| 230 | global $template; |
---|
| 231 | |
---|
| 232 | $link_url = $this->get_link_icon(duplicate_picture_url()); |
---|
| 233 | if (!empty($link_url)) |
---|
| 234 | { |
---|
| 235 | $template->concat( |
---|
| 236 | 'PLUGIN_PICTURE_ACTIONS', |
---|
| 237 | $link_url); |
---|
| 238 | } |
---|
| 239 | |
---|
| 240 | return $pictures; |
---|
| 241 | } |
---|
| 242 | |
---|
| 243 | function loading_lang() |
---|
| 244 | { |
---|
| 245 | load_language('plugin.lang', $this->plugin_path); |
---|
| 246 | } |
---|
| 247 | } |
---|
| 248 | |
---|
| 249 | ?> |
---|