/** * LazyestFrontendFolder::load() * Loads images without the folder icon image * * @param string $what * @see LazyestFolder::load() * @return void */ function load($what = 'images') { global $lg_gallery; LazyestFolder::load($what); if ('icon' == $lg_gallery->get_option('folder_image') && 0 < count($this->list)) { foreach ($this->list as $key_i => $image) { if ($this->is_folder_icon($image->image)) { unset($this->list[$key_i]); $this->list = array_values($this->list); } } } }
/** * LazyestSearchFolder::load() * Search for images * * @param string $what * @return */ function load($what = 'thumbs') { global $lg_gallery; if (isset($this->list)) { $this->_empty_list(); } $this->list = array(); $found = false; $query = utf8_encode(htmlentities($lg_gallery->query)); $folderlist = $lg_gallery->search_in_xml($query); if (0 == count($folderlist)) { return false; } foreach ($folderlist as $path) { $folder = new LazyestFolder($path); $folder->open(); if (!$folder->user_can('viewer')) { continue; } $folder->load('thumbs'); if (0 < count($folder->list)) { foreach ($folder->list as $thumb) { if (strripos($thumb->image, $lg_gallery->query) !== false) { $this->list[] = $thumb; } else { if (strripos($thumb->caption, $lg_gallery->query) !== false) { $this->list[] = $thumb; } else { if (strripos($thumb->description, $lg_gallery->query) !== false) { $this->list[] = $thumb; } } } } } } if (0 < count($this->list)) { $lg_gallery->found = true; } return true; }
/** * LazyestUploadTab::show_folder() * Display all image rows * * @param LazyestFolder $folder * @param string $current_url * @return void */ function show_folder($folder, $current_url = '') { global $lg_gallery; if (!$folder->valid()) { echo sprintf('<div class="media-item"><div class="filename"><span class="title">%s</span></div></div>', __('Error opening folder', 'lazyest-gallery')); return; } $folder->open(); $folder->load('thumbs'); if (0 == count($folder->list)) { echo sprintf('<div class="media-item"><div class="filename"><span class="title">%s</span></div></div>', __('This folder is empty', 'lazyest-gallery')); return; } $pagination = $lg_gallery->pagination('cimages', $folder->list, $current_url); $perpage = 10; $total_pages = ceil(count($folder->list) / $perpage); $query_var = 'lg_pagei'; if (isset($pagei)) { $current = $pagei; } else { $current = isset($_REQUEST[$query_var]) ? absint($_REQUEST[$query_var]) : 0; $current = min(max(1, $current), $total_pages); } $start = ($current - 1) * $perpage + 1; $end = min(count($folder->list), $current * $perpage); ?> <div class="media-item" id="lg_folder_nav"> <form id="ifilter" method="post" action=""> <div class="tablenav"><?php echo $pagination; ?> </div> <input type="hidden" name="current_url" value="<?php echo $current_url; ?> " /> </form> </div> <?php for ($i = $start - 1; $i != $end; $i++) { $image = $folder->list[$i]; $this->_image_row($image); } }
/** * LazyestCommentor::edit_comments() * * @param mixed $filevar * @return void */ function edit_comments($filevar) { global $lg_gallery; switch ($this->comments_from) { case 'folder': $folder = new LazyestFolder($filevar); $folder->open(); $comments = $this->get_comments($folder->id); $caption = $folder->caption; break; case 'image': $folder = new LazyestFolder(dirname($filevar)); $folder->load('images'); $image = $folder->single_image(basename($filevar)); $comments = $this->get_comments($image->id); $caption = $image->caption; break; case 'gallery': $comments = $this->get_root_comments(); $page_id = $lg_gallery->get_option('gallery_id'); $gallery_page = get_post($page_id); $caption = $gallery_page->post_title; break; case 'all': default: $page_id = (int) $lg_gallery->get_option('gallery_id'); $comments = $this->get_approved_comments($page_id); $gallery_page = get_post($page_id); $caption = $gallery_page->post_title; break; } $do_pagination = false; if ($comments) { update_comment_cache($comments); $comments = array_reverse($comments); $comments_table = new LazyestCommentsTable($comments); $perpage = 20; $total_pages = ceil(count($comments) / $perpage); $query_var = 'lg_paged'; if (isset($paged)) { $current = $paged; } else { $current = isset($_REQUEST[$query_var]) ? absint($_REQUEST[$query_var]) : 0; $current = min(max(1, $current), $total_pages); } $start = ($current - 1) * $perpage + 1; $end = min(count($comments), $current * $perpage); $do_pagination = 1 < $total_pages; if ($do_pagination) { $pagination = $lg_gallery->pagination('comments', $comments); ?> <div class="tablenav"><?php echo $pagination; ?> </div> <?php } ?> <br class="clear" /> <?php $comments_table->display(); ?> <?php } if ($do_pagination) { ?> <div class="tablenav"><?php echo $pagination; ?> </div> <?php } if (isset($folder)) { unset($folder); } unset($comments_table); }
/** * LazyestAdmin::rebuild_database() * Rebuild the lazyestfiles table per folder * * @since 1.1.0 * @uses $wpdb, get_transient, set_transient, delete_transient * @param int $i key of folder in _build_folders_array() * @return int next key */ function rebuild_database($i) { global $wpdb; $folder_array = get_transient('lg_rebuild_database_folders'); if (false === $folder_array) { $folder_array = $this->_build_folders_array(); set_transient('lg_rebuild_database_folders', $folder_array, 300); } $j = $i == 0 ? count($folder_array) : $i; $insert = ''; if ($j < count($folder_array)) { $file = substr($folder_array[$j - 1], strlen($this->root)); $folder = $folder = new LazyestFolder($file); $folder->open(); $imgID = $folder->id; $file = rawurlencode($folder->curdir); $into = "INSERT INTO {$this->table} ( img_ID, file ) VALUES \n"; $insert = $into . "( {$imgID}, \"{$file}\" ),"; $folder->load(); $lines = 0; if (0 < count($folder->list)) { $lines = 1; foreach ($folder->list as $image) { $imgID = $image->id; $file = rawurlencode($folder->curdir . $image->image); $insert .= "\n( {$imgID}, \"{$file}\" ),"; $lines++; if ($lines == 64) { $insert = trim($insert, ',') . ';'; $wpdb->query($insert); $insert = $into; $lines = 0; } } } if ($lines = 0) { $insert = ''; } if ('' != $insert) { $insert = trim($insert, ',') . ';'; $wpdb->query($insert); } } if ($j == 1) { delete_transient('lg_rebuild_cache_folders'); } return $j - 1; }
/** * LazyestGallery::get_file_by_id() * Finds all folders or images with a particular ID. returns an array holding the relative path to the gallery root * @param int $img_ID can also be string but should be number * @return array */ function get_file_by_id($img_ID) { $imgID = (int) $img_ID; $results = $this->_db_get_file($imgID); if (false !== $results) { return '/' == $results[0] ? false : $results; } $results = array(); $search = ">{$imgID}<"; $paths = $this->search_in_xml($search); if (0 < count($paths)) { foreach ($paths as $path) { $folder = new LazyestFolder($path); $folder->open(); $folder->load(); if ($imgID == $folder->id) { $results[] = $folder->curdir; } if (0 < count($folder->list)) { foreach ($folder->list as $image) { if ($imgID == $image->id) { $results[] = $folder->curdir . $image->image; break; // stop searching, id is unique per folder } } } unset($folder); } } return $results; }
/** * LazyestAdminFolder::copy_image() * Copy or move an image to another folder * * @return void * @since 1.0 * */ function copy_image($action = 'copy') { global $lg_gallery; $success = false; $get = $action == 'copy' ? $_REQUEST['copy_to'] : $_REQUEST['move_to']; $folderfile = urldecode($get); $imagefile = urldecode($_REQUEST['image']); if ('' == $folderfile || '' == $imagefile) { $message = sprintf(__('Cannot find image or folder, please <a href="%s">reload</a> this folder', 'lazyest-gallery'), admin_url('admin.php') . '?page=lazyest-filemanager&folder=' . lg_nice_link($this->curdir)); } else { $to_folderobj = new LazyestFolder($folderfile); $to_folderobj->open(); $to_folderobj->load(); if (!$to_folderobj->user_can('editor')) { $message = sprintf(esc_html__('You have insufficient permissions to copy to folder %s', 'lazyest-gallery'), htmlentities($folderfile)); } else { $to_folder = $lg_gallery->root . $folderfile; $from_image = $lg_gallery->root . $imagefile; $from_folderobj = new LazyestFolder(dirname($imagefile)); $from_imageobj = $from_folderobj->single_image(basename($from_image)); $to_image = $to_folder . basename($from_image); if (file_exists($to_image)) { $message = sprintf(esc_html__('Cannot copy, %s already exists in %s', 'lazyest-gallery'), htmlentities(basename($from_image)), htmlentities($folderfile)); } else { if (!@copy($from_image, $to_image)) { $message = esc_html__('Cannot copy, Something went wrong copying your image. Please check your server permissions', 'lazyest-gallery'); } else { if ('move' == $action) { $success = @unlink($from_image); if (!$success) { $message = esc_html__('Cannot move, image is copied instead', 'lazyest-gallery'); } } else { $success = true; } if ($success) { $from_imageobj->folder = $to_folderobj; $to_folderobj->list[] = $from_imageobj; $to_folderobj->save(); $copymove = $action == 'copy' ? 'copied' : 'moved'; $folderlink = '<a href="' . admin_url('admin.php') . '?page=lazyest-filemanager&folder=' . urlencode($folderfile) . '#' . $from_imageobj->form_name() . '">' . htmlentities($folderfile) . '</a>'; $message = sprintf(esc_html__('%s successfully %s to %s', 'lazyest-gallery'), htmlentities(basename($from_image)), $copymove, $folderlink); } } } } } $lg_gallery->message = $message; $lg_gallery->success = $success; }
/** * lg_refresh_folder() * refresh image table in folder edit screen when upload thickbox closes * @since 1.1.0 * @return void */ function lg_refresh_folder() { global $lg_paged, $lg_gallery; if (isset($_POST['folder'])) { $lg_paged = isset($_POST['lg_paged']) ? $_POST['lg_paged'] : 1; $path = utf8_decode(rawurldecode($_POST['folder'])); $folder = new LazyestFolder($path); $folder->open(); $folder->load('thumbs'); $imagetable = new LazyestImageTable($folder->list); $imagetable->page('lg_paged'); $imagetable->display(); } die; }