plugin_config = $config; $this->current_picture = 0; $this->next_picture = null; $this->previous_picture = null; $this->applicable = false; } public function page_force() { global $page; if ( isset($page['category']) ) { $cat_filter = $this->plugin_config->ak_categories; $this->applicable = (stripos($page['category']['name'], $cat_filter) === false) ? false:true; if ( $this->applicable ) { $page['nb_image_page'] = $this->plugin_config->ak_by_page; } } } public function loc_begin_index_thumbnails($images) { global $template; if ($this->applicable === false) return; $this->category_url = make_index_url(array('section' => 'category', 'category' => $GLOBALS['page']['category'], 'start' => $GLOBALS['page']['start'] ) ); $this->current_picture = $this->getPictureId($images); $template->set_filenames(array('index_thumbnails'=> AK_PLUGIN_TEMPLATE . '/ak_thumbnails.tpl')); $template->assign('AK_PLUGIN_CSS', AK_PLUGIN_CSS); $template->assign('AK_PLUGIN_JS', AK_PLUGIN_JS); $template->assign('AK_DIR_THUMBNAIL', isset($GLOBALS['conf']['dir_thumbnail'])?$GLOBALS['conf']['dir_thumbnail']:'thumbnail'); $template->assign('AK_PREFIX_THUMBNAIL', $GLOBALS['conf']['prefix_thumbnail']); $template->assign('AK_BY_LINE', $this->plugin_config->ak_by_line); $template->assign('AK_MOUSE_EVENT', $this->plugin_config->ak_mouse_event); $template->assign('AK_THUMBNAIL_SIZE', $this->plugin_config->ak_thumbnail_size); $template->assign('AK_RELOADED_IMAGE_TPL', AK_PLUGIN_TEMPLATE. '/ak_reloaded_image.tpl'); $template->assign('AK_VERTICAL_TPL', AK_PLUGIN_TEMPLATE. '/ak_vertical.tpl'); $template->assign('AK_HORIZONTAL_TPL', AK_PLUGIN_TEMPLATE. '/ak_horizontal.tpl'); $template->assign('AK_THUMBNAILS_LOC', $this->plugin_config->ak_thumbnails_loc); $template->assign('AK_PIC_SRC', get_image_url($images[$this->current_picture])); $template->assign('AK_NEXT', $this->getNextPicture($this->current_picture, $images)); $template->assign('AK_PREVIOUS', $this->getPreviousPicture($this->current_picture, $images)); } public function loc_end_index_thumbnails($tpl_vars, $images) { if ($this->applicable === false) return $tpl_vars; foreach ($tpl_vars as &$tpl_var) { $tpl_var['AK_URL'] = $this->makeAkUrl($tpl_var); list($thumbnail_width, $thumbnail_height) = getimagesize($tpl_var['TN_SRC']); $thumbnail_x_center = $thumbnail_width/2; $thumbnail_y_center = $thumbnail_height/2; $tpl_var['CLIP_TOP'] = round($thumbnail_y_center - $this->plugin_config->ak_thumbnail_size/2); $tpl_var['CLIP_RIGHT'] = round($thumbnail_x_center + $this->plugin_config->ak_thumbnail_size/2); $tpl_var['CLIP_BOTTOM'] = round($thumbnail_y_center + $this->plugin_config->ak_thumbnail_size/2); $tpl_var['CLIP_LEFT'] = round($thumbnail_x_center - $this->plugin_config->ak_thumbnail_size/2); } return $tpl_vars; } /*** privates methods ***/ private function makeAkUrl($image) { return sprintf('%s/picture/%d', $this->category_url, $image['ID']); } private function getPictureId($images) { if ($GLOBALS['conf']['question_mark_in_urls']==false and isset($_SERVER["PATH_INFO"]) and !empty($_SERVER["PATH_INFO"]) ) { $rewritten = $_SERVER["PATH_INFO"]; $rewritten = str_replace('//', '/', $rewritten); } else { $rewritten = ''; foreach (array_keys($_GET) as $keynum => $key) { $rewritten = $key; break; } } $rewritten = make_index_url().$rewritten; $pattern = sprintf('`^%s/(?:start\-\d+/)?picture/(\d+)$`', str_replace('?', '\?', $this->category_url) ); if (preg_match($pattern, $rewritten, $matches)) { foreach ($images as $index => $image) { if ($image['id']==$matches[1]) { return $index; } } return false; } else { return false; } } private function getPreviousPicture($current, $images) { $previous = $current--; if ($previous>0) { return $this->makeAkUrl(array('ID' => $images[$previous]['id'])); } else { return null; } } private function getNextPicture($current, $images) { $index_current = null; foreach ($images as $index => $image) { if ($image['id']==$current) { $index_current = $index; break; } } $next = $index_current+1; if ($nextmakeAkUrl(array('ID' => $images[$next]['id'])); } else { return null; } } } ?>