[3761] | 1 | <?php |
---|
| 2 | // +-----------------------------------------------------------------------+ |
---|
| 3 | // | akBookStyle - a plugin for Piwigo | |
---|
| 4 | // +-----------------------------------------------------------------------+ |
---|
| 5 | // | Copyright(C) 2009 Nicolas Roudaire http://www.nikrou.net | |
---|
| 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 | |
---|
| 19 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
| 20 | // | USA. | |
---|
| 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; |
---|
[3770] | 37 | } |
---|
| 38 | |
---|
[3843] | 39 | public function page_force() { |
---|
| 40 | global $page; |
---|
| 41 | if ( isset($page['category']) ) { |
---|
| 42 | $cat_filter = $this->plugin_config->ak_categories; |
---|
| 43 | $this->applicable = (stripos($page['category']['name'], $cat_filter) > 0) ? true:false; |
---|
| 44 | if ( $this->applicable ) { |
---|
| 45 | $page['nb_image_page'] = $this->plugin_config->ak_by_page; |
---|
| 46 | } |
---|
| 47 | } |
---|
[3842] | 48 | } |
---|
| 49 | |
---|
[3787] | 50 | public function loc_begin_index_thumbnails($images) { |
---|
[3842] | 51 | global $template; |
---|
[3843] | 52 | if ($this->applicable === false) return; |
---|
[3787] | 53 | $this->category_url = make_index_url(array('section' => 'category', |
---|
[3829] | 54 | 'category' => $GLOBALS['page']['category'], |
---|
| 55 | 'start' => $GLOBALS['page']['start'] |
---|
| 56 | ) |
---|
| 57 | ); |
---|
[3787] | 58 | $this->current_picture = $this->getPictureId($images); |
---|
| 59 | |
---|
[3770] | 60 | $template->set_filenames(array('index_thumbnails'=> AK_PLUGIN_TEMPLATE . '/ak_thumbnails.tpl')); |
---|
[3791] | 61 | $template->assign('AK_PLUGIN_CSS', AK_PLUGIN_CSS); |
---|
| 62 | $template->assign('AK_PLUGIN_JS', AK_PLUGIN_JS); |
---|
| 63 | |
---|
[3792] | 64 | $template->assign('AK_DIR_THUMBNAIL', isset($GLOBALS['conf']['dir_thumbnail'])?$GLOBALS['conf']['dir_thumbnail']:'thumbnail'); |
---|
[3791] | 65 | $template->assign('AK_PREFIX_THUMBNAIL', $GLOBALS['conf']['prefix_thumbnail']); |
---|
| 66 | $template->assign('AK_BY_LINE', $this->plugin_config->ak_by_line); |
---|
[3806] | 67 | $template->assign('AK_MOUSE_EVENT', $this->plugin_config->ak_mouse_event); |
---|
[3792] | 68 | $template->assign('AK_THUMBNAIL_SIZE', $this->plugin_config->ak_thumbnail_size); |
---|
[3770] | 69 | $template->assign('AK_RELOADED_IMAGE_TPL', AK_PLUGIN_TEMPLATE. '/ak_reloaded_image.tpl'); |
---|
[3806] | 70 | $template->assign('AK_VERTICAL_TPL', AK_PLUGIN_TEMPLATE. '/ak_vertical.tpl'); |
---|
[3807] | 71 | $template->assign('AK_HORIZONTAL_TPL', AK_PLUGIN_TEMPLATE. '/ak_horizontal.tpl'); |
---|
[3804] | 72 | $template->assign('AK_THUMBNAILS_LOC', $this->plugin_config->ak_thumbnails_loc); |
---|
[3838] | 73 | $template->assign('AK_PIC_SRC', get_image_url($images[$this->current_picture])); |
---|
[3787] | 74 | |
---|
[3838] | 75 | $template->assign('AK_NEXT', $this->getNextPicture($this->current_picture, $images)); |
---|
| 76 | $template->assign('AK_PREVIOUS', $this->getPreviousPicture($this->current_picture, $images)); |
---|
| 77 | } |
---|
| 78 | |
---|
[3787] | 79 | public function loc_end_index_thumbnails($tpl_vars, $images) { |
---|
[3843] | 80 | if ($this->applicable === false) return $tpl_vars; |
---|
[3787] | 81 | foreach ($tpl_vars as &$tpl_var) { |
---|
[3792] | 82 | $tpl_var['AK_URL'] = $this->makeAkUrl($tpl_var); |
---|
[3787] | 83 | |
---|
[3792] | 84 | list($thumbnail_width, $thumbnail_height) = getimagesize($tpl_var['TN_SRC']); |
---|
| 85 | $thumbnail_x_center = $thumbnail_width/2; |
---|
| 86 | $thumbnail_y_center = $thumbnail_height/2; |
---|
| 87 | $tpl_var['CLIP_TOP'] = round($thumbnail_y_center - $this->plugin_config->ak_thumbnail_size/2); |
---|
| 88 | $tpl_var['CLIP_RIGHT'] = round($thumbnail_x_center + $this->plugin_config->ak_thumbnail_size/2); |
---|
| 89 | $tpl_var['CLIP_BOTTOM'] = round($thumbnail_y_center + $this->plugin_config->ak_thumbnail_size/2); |
---|
| 90 | $tpl_var['CLIP_LEFT'] = round($thumbnail_x_center - $this->plugin_config->ak_thumbnail_size/2); |
---|
[3787] | 91 | } |
---|
| 92 | |
---|
| 93 | return $tpl_vars; |
---|
| 94 | } |
---|
| 95 | |
---|
| 96 | /*** privates methods ***/ |
---|
| 97 | private function makeAkUrl($image) { |
---|
| 98 | return sprintf('%s/picture/%d', $this->category_url, $image['ID']); |
---|
| 99 | |
---|
| 100 | } |
---|
| 101 | |
---|
| 102 | private function getPictureId($images) { |
---|
| 103 | if ($GLOBALS['conf']['question_mark_in_urls']==false and |
---|
[3829] | 104 | isset($_SERVER["PATH_INFO"]) and !empty($_SERVER["PATH_INFO"]) ) { |
---|
[3787] | 105 | $rewritten = $_SERVER["PATH_INFO"]; |
---|
| 106 | $rewritten = str_replace('//', '/', $rewritten); |
---|
| 107 | } else { |
---|
| 108 | $rewritten = ''; |
---|
| 109 | foreach (array_keys($_GET) as $keynum => $key) { |
---|
[3829] | 110 | $rewritten = $key; |
---|
| 111 | break; |
---|
[3787] | 112 | } |
---|
| 113 | } |
---|
| 114 | $rewritten = make_index_url().$rewritten; |
---|
| 115 | $pattern = sprintf('`^%s/(?:start\-\d+/)?picture/(\d+)$`', |
---|
[3829] | 116 | str_replace('?', '\?', $this->category_url) |
---|
| 117 | ); |
---|
[3787] | 118 | |
---|
| 119 | if (preg_match($pattern, $rewritten, $matches)) { |
---|
| 120 | foreach ($images as $index => $image) { |
---|
[3829] | 121 | if ($image['id']==$matches[1]) { |
---|
| 122 | return $index; |
---|
| 123 | } |
---|
[3787] | 124 | } |
---|
| 125 | return false; |
---|
| 126 | } else { |
---|
| 127 | return false; |
---|
| 128 | } |
---|
| 129 | } |
---|
[3838] | 130 | |
---|
| 131 | private function getPreviousPicture($current, $images) { |
---|
| 132 | $previous = $current--; |
---|
| 133 | if ($previous>0) { |
---|
| 134 | return $this->makeAkUrl(array('ID' => $images[$previous]['id'])); |
---|
| 135 | } else { |
---|
| 136 | return null; |
---|
| 137 | } |
---|
| 138 | } |
---|
| 139 | |
---|
| 140 | private function getNextPicture($current, $images) { |
---|
| 141 | $index_current = null; |
---|
| 142 | foreach ($images as $index => $image) { |
---|
| 143 | if ($image['id']==$current) { |
---|
| 144 | $index_current = $index; |
---|
| 145 | break; |
---|
| 146 | } |
---|
| 147 | } |
---|
| 148 | |
---|
| 149 | $next = $index_current+1; |
---|
| 150 | if ($next<count($images)) { |
---|
| 151 | return $this->makeAkUrl(array('ID' => $images[$next]['id'])); |
---|
| 152 | } else { |
---|
| 153 | return null; |
---|
| 154 | } |
---|
| 155 | } |
---|
[3770] | 156 | } |
---|
[3761] | 157 | ?> |
---|