plugin_config = $config; $this->current_picture = 0; $this->next_picture = null; $this->previous_picture = null; $this->applicable = false; $this->picture_pattern_format = '`^%s/(?:start\-\d+/)?picture/(\d+)$`'; } 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->picture_pattern = sprintf($this->picture_pattern_format, str_replace('?', '\?', $this->category_url) ); $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) { 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; } public function loc_end_picture() { if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && ($_SERVER['HTTP_X_REQUESTED_WITH']=='XMLHttpRequest')) { header("Content-Type: application/json"); $response = array(); $tpl_vars = $GLOBALS['template']->smarty->_tpl_vars; $response['AK_PIC_SRC'] = $tpl_vars['SRC_IMG']; $response['AK_PIC_ALT'] = $tpl_vars['ALT_IMG']; if (isset($tpl_vars['ALT_IMG'])) { $response['AK_PIC_TITLE'] = $tpl_vars['ALT_IMG']; } else { $response['AK_PIC_TITLE'] = ''; } if (isset($tpl_vars['previous'])) { $response['AK_PREVIOUS'] = $tpl_vars['previous']['url']; } if (isset($tpl_vars['next'])) { $response['AK_NEXT'] = $tpl_vars['next']['url']; } echo json_encode($response); exit(); } } /*** 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; if (preg_match($this->picture_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-1; if ($previous>0) { return $this->makeAkUrl(array('ID' => $images[$previous]['id'])); } else { return null; } } private function getNextPicture($current, $images) { $next = $current+1; if ($nextmakeAkUrl(array('ID' => $images[$next]['id'])); } else { return null; } } } ?>