[3761] | 1 | <?php |
---|
| 2 | // +-----------------------------------------------------------------------+ |
---|
| 3 | // | akBookStyle - a plugin for Piwigo | |
---|
| 4 | // +-----------------------------------------------------------------------+ |
---|
[5432] | 5 | // | Copyright(C) 2009-2010 Nicolas Roudaire http://www.nikrou.net | |
---|
[3761] | 6 | // | Copyright(C) 2009 vdigital | |
---|
| 7 | // +-----------------------------------------------------------------------+ |
---|
| 8 | // | This program is free software; you can redistribute it and/or modify | |
---|
| 9 | // | it under the terms of the GNU General Public License as published by | |
---|
| 10 | // | the Free Software Foundation | |
---|
| 11 | // | | |
---|
| 12 | // | This program is distributed in the hope that it will be useful, but | |
---|
| 13 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
| 14 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
| 15 | // | General Public License for more details. | |
---|
| 16 | // | | |
---|
| 17 | // | You should have received a copy of the GNU General Public License | |
---|
| 18 | // | along with this program; if not, write to the Free Software | |
---|
[6852] | 19 | // | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | |
---|
| 20 | // | MA 02110-1301 USA | |
---|
[3761] | 21 | // +-----------------------------------------------------------------------+ |
---|
| 22 | |
---|
[3764] | 23 | if (!defined('PHPWG_ROOT_PATH')) { |
---|
| 24 | die('Hacking attempt!'); |
---|
| 25 | } |
---|
[3770] | 26 | |
---|
[3787] | 27 | include_once(PHPWG_ROOT_PATH.'include/functions_picture.inc.php'); |
---|
| 28 | |
---|
[3770] | 29 | class akContent |
---|
| 30 | { |
---|
| 31 | public function __construct($config) { |
---|
| 32 | $this->plugin_config = $config; |
---|
[3787] | 33 | $this->current_picture = 0; |
---|
[3838] | 34 | $this->next_picture = null; |
---|
| 35 | $this->previous_picture = null; |
---|
[3843] | 36 | $this->applicable = false; |
---|
[3876] | 37 | |
---|
| 38 | $this->picture_pattern_format = '`^%s/(?:start\-\d+/)?picture/(\d+)$`'; |
---|
[3770] | 39 | } |
---|
| 40 | |
---|
[3843] | 41 | public function page_force() { |
---|
| 42 | global $page; |
---|
[3876] | 43 | |
---|
[5432] | 44 | if (!empty($page['category'])) { |
---|
| 45 | if (in_array($page['category']['id'], $this->plugin_config->ak_categories)) |
---|
| 46 | { |
---|
| 47 | $this->applicable = true; |
---|
[3843] | 48 | $page['nb_image_page'] = $this->plugin_config->ak_by_page; |
---|
[5445] | 49 | $GLOBALS['user']['nb_image_page'] = $this->plugin_config->ak_by_page; |
---|
[3843] | 50 | } |
---|
[5432] | 51 | else |
---|
| 52 | { |
---|
| 53 | $this->applicable = false; |
---|
| 54 | } |
---|
[3843] | 55 | } |
---|
[3842] | 56 | } |
---|
| 57 | |
---|
[3787] | 58 | public function loc_begin_index_thumbnails($images) { |
---|
[3842] | 59 | global $template; |
---|
[5432] | 60 | |
---|
[5445] | 61 | if (!$this->applicable) { |
---|
| 62 | return; |
---|
| 63 | } |
---|
| 64 | |
---|
[9286] | 65 | load_language('plugin.lang', AK_PLUGIN_LANG); |
---|
| 66 | |
---|
[3787] | 67 | $this->category_url = make_index_url(array('section' => 'category', |
---|
[3876] | 68 | 'category' => $GLOBALS['page']['category'], |
---|
| 69 | 'start' => $GLOBALS['page']['start'] |
---|
| 70 | ) |
---|
| 71 | ); |
---|
| 72 | $this->picture_pattern = sprintf($this->picture_pattern_format, |
---|
| 73 | str_replace('?', '\?', $this->category_url) |
---|
| 74 | ); |
---|
| 75 | |
---|
[3787] | 76 | $this->current_picture = $this->getPictureId($images); |
---|
[3770] | 77 | $template->set_filenames(array('index_thumbnails'=> AK_PLUGIN_TEMPLATE . '/ak_thumbnails.tpl')); |
---|
[3791] | 78 | $template->assign('AK_PLUGIN_CSS', AK_PLUGIN_CSS); |
---|
| 79 | $template->assign('AK_PLUGIN_JS', AK_PLUGIN_JS); |
---|
| 80 | |
---|
[3792] | 81 | $template->assign('AK_DIR_THUMBNAIL', isset($GLOBALS['conf']['dir_thumbnail'])?$GLOBALS['conf']['dir_thumbnail']:'thumbnail'); |
---|
[3791] | 82 | $template->assign('AK_PREFIX_THUMBNAIL', $GLOBALS['conf']['prefix_thumbnail']); |
---|
| 83 | $template->assign('AK_BY_LINE', $this->plugin_config->ak_by_line); |
---|
[3806] | 84 | $template->assign('AK_MOUSE_EVENT', $this->plugin_config->ak_mouse_event); |
---|
[3792] | 85 | $template->assign('AK_THUMBNAIL_SIZE', $this->plugin_config->ak_thumbnail_size); |
---|
[3770] | 86 | $template->assign('AK_RELOADED_IMAGE_TPL', AK_PLUGIN_TEMPLATE. '/ak_reloaded_image.tpl'); |
---|
[3806] | 87 | $template->assign('AK_VERTICAL_TPL', AK_PLUGIN_TEMPLATE. '/ak_vertical.tpl'); |
---|
[3807] | 88 | $template->assign('AK_HORIZONTAL_TPL', AK_PLUGIN_TEMPLATE. '/ak_horizontal.tpl'); |
---|
[3804] | 89 | $template->assign('AK_THUMBNAILS_LOC', $this->plugin_config->ak_thumbnails_loc); |
---|
[3838] | 90 | $template->assign('AK_PIC_SRC', get_image_url($images[$this->current_picture])); |
---|
[3787] | 91 | |
---|
[3838] | 92 | $template->assign('AK_NEXT', $this->getNextPicture($this->current_picture, $images)); |
---|
| 93 | $template->assign('AK_PREVIOUS', $this->getPreviousPicture($this->current_picture, $images)); |
---|
[5432] | 94 | if (empty($_SESSION['ak_previous_image'])) { |
---|
| 95 | $_SESSION['ak_previous_image'] = $images[$this->current_picture]['id']; |
---|
| 96 | } |
---|
[3838] | 97 | } |
---|
[5432] | 98 | |
---|
| 99 | public function loc_end_index_thumbnails($tpl_vars, $images) { |
---|
| 100 | if (!$this->applicable) { |
---|
| 101 | return $tpl_vars; |
---|
| 102 | } |
---|
[3838] | 103 | |
---|
[5432] | 104 | $selected_one = false; |
---|
[3787] | 105 | foreach ($tpl_vars as &$tpl_var) { |
---|
[3792] | 106 | list($thumbnail_width, $thumbnail_height) = getimagesize($tpl_var['TN_SRC']); |
---|
| 107 | $thumbnail_x_center = $thumbnail_width/2; |
---|
| 108 | $thumbnail_y_center = $thumbnail_height/2; |
---|
| 109 | $tpl_var['CLIP_TOP'] = round($thumbnail_y_center - $this->plugin_config->ak_thumbnail_size/2); |
---|
| 110 | $tpl_var['CLIP_RIGHT'] = round($thumbnail_x_center + $this->plugin_config->ak_thumbnail_size/2); |
---|
| 111 | $tpl_var['CLIP_BOTTOM'] = round($thumbnail_y_center + $this->plugin_config->ak_thumbnail_size/2); |
---|
| 112 | $tpl_var['CLIP_LEFT'] = round($thumbnail_x_center - $this->plugin_config->ak_thumbnail_size/2); |
---|
[5432] | 113 | |
---|
| 114 | if (!empty($_SESSION['ak_previous_image']) |
---|
| 115 | && ($tpl_var['ID']==$_SESSION['ak_previous_image'])) { |
---|
| 116 | $tpl_var['SELECTED'] = true; |
---|
| 117 | $selected_one =true; |
---|
| 118 | } |
---|
| 119 | if (!$selected_one) { |
---|
| 120 | $tpl_vars[0]['SELECTED'] = true; |
---|
| 121 | } |
---|
[3787] | 122 | } |
---|
| 123 | |
---|
| 124 | return $tpl_vars; |
---|
| 125 | } |
---|
| 126 | |
---|
[3876] | 127 | public function loc_end_picture() { |
---|
| 128 | if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) |
---|
| 129 | && ($_SERVER['HTTP_X_REQUESTED_WITH']=='XMLHttpRequest')) { |
---|
| 130 | |
---|
| 131 | $response = array(); |
---|
| 132 | $tpl_vars = $GLOBALS['template']->smarty->_tpl_vars; |
---|
| 133 | $response['AK_PIC_SRC'] = $tpl_vars['SRC_IMG']; |
---|
| 134 | $response['AK_PIC_ALT'] = $tpl_vars['ALT_IMG']; |
---|
| 135 | if (isset($tpl_vars['ALT_IMG'])) { |
---|
| 136 | $response['AK_PIC_TITLE'] = $tpl_vars['ALT_IMG']; |
---|
| 137 | } else { |
---|
| 138 | $response['AK_PIC_TITLE'] = ''; |
---|
| 139 | } |
---|
| 140 | |
---|
| 141 | if (isset($tpl_vars['previous'])) { |
---|
| 142 | $response['AK_PREVIOUS'] = $tpl_vars['previous']['url']; |
---|
| 143 | } |
---|
| 144 | if (isset($tpl_vars['next'])) { |
---|
| 145 | $response['AK_NEXT'] = $tpl_vars['next']['url']; |
---|
| 146 | } |
---|
[5432] | 147 | $_SESSION['ak_previous_image'] = $tpl_vars['current']['id']; |
---|
| 148 | header("Content-Type: application/json"); |
---|
[3876] | 149 | echo json_encode($response); |
---|
| 150 | exit(); |
---|
| 151 | |
---|
| 152 | } |
---|
| 153 | } |
---|
| 154 | |
---|
[3787] | 155 | /*** privates methods ***/ |
---|
| 156 | private function makeAkUrl($image) { |
---|
[3877] | 157 | return duplicate_picture_url(array('image_id' => $image['id'], |
---|
| 158 | 'image_file' => $image['file'] |
---|
| 159 | ), |
---|
| 160 | array('start') |
---|
| 161 | ); |
---|
[3787] | 162 | } |
---|
| 163 | |
---|
| 164 | private function getPictureId($images) { |
---|
| 165 | if ($GLOBALS['conf']['question_mark_in_urls']==false and |
---|
[3829] | 166 | isset($_SERVER["PATH_INFO"]) and !empty($_SERVER["PATH_INFO"]) ) { |
---|
[3787] | 167 | $rewritten = $_SERVER["PATH_INFO"]; |
---|
| 168 | $rewritten = str_replace('//', '/', $rewritten); |
---|
| 169 | } else { |
---|
| 170 | $rewritten = ''; |
---|
| 171 | foreach (array_keys($_GET) as $keynum => $key) { |
---|
[3829] | 172 | $rewritten = $key; |
---|
| 173 | break; |
---|
[3787] | 174 | } |
---|
| 175 | } |
---|
| 176 | $rewritten = make_index_url().$rewritten; |
---|
| 177 | |
---|
[3876] | 178 | if (preg_match($this->picture_pattern, $rewritten, $matches)) { |
---|
[3787] | 179 | foreach ($images as $index => $image) { |
---|
[3829] | 180 | if ($image['id']==$matches[1]) { |
---|
| 181 | return $index; |
---|
| 182 | } |
---|
[3787] | 183 | } |
---|
| 184 | return false; |
---|
| 185 | } else { |
---|
| 186 | return false; |
---|
| 187 | } |
---|
| 188 | } |
---|
[3838] | 189 | |
---|
| 190 | private function getPreviousPicture($current, $images) { |
---|
[3876] | 191 | $previous = $current-1; |
---|
[3838] | 192 | if ($previous>0) { |
---|
[3877] | 193 | return $this->makeAkUrl($images[$previous]); |
---|
[3838] | 194 | } else { |
---|
| 195 | return null; |
---|
| 196 | } |
---|
| 197 | } |
---|
| 198 | |
---|
| 199 | private function getNextPicture($current, $images) { |
---|
[3876] | 200 | $next = $current+1; |
---|
[3838] | 201 | if ($next<count($images)) { |
---|
[3877] | 202 | return $this->makeAkUrl($images[$next]); |
---|
[3838] | 203 | } else { |
---|
| 204 | return null; |
---|
| 205 | } |
---|
| 206 | } |
---|
[3770] | 207 | } |
---|
[3761] | 208 | ?> |
---|