/** * 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; }
/** * 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; }
/** * LazyestGallery::access_check() * Check if user is allowed to view gallery/folder * * @since 1.1.0 * @param LazyestFolder $folder * @param bool $show_error * @return bool * @todo redundance LazyestGallery::user_can_browse() */ function access_check($folder = null, $show_error = true) { $viewer_level = $this->get_option('viewer_level'); $viewer_level = $viewer_level == '' ? 'everyone' : $viewer_level; $can_access = null != $folder ? $folder->user_can('viewer') : current_user_can($this->level_cap($viewer_level)) || $viewer_level == 'everyone'; if (!$can_access && $show_error) { if (!is_user_logged_in()) { $message = esc_html__('Please log in or register to view the gallery.', 'lazyest-gallery'); } else { $message = esc_html__('Sorry, you are not allowed to view this item. The owner of this gallery has set access restrictions.', 'lazyest-gallery'); } printf('<p>%s</p>', $message); } return $can_access; }
/** * lg_login_required() * Checks if login is required to view the current folder or slide page * * @since 1.1.0 * @return bool */ function lg_login_required() { global $lg_gallery; if (is_user_logged_in()) { return false; } if (!isset($lg_gallery)) { return false; } if (!isset($lg_gallery->file)) { $lg_gallery->valid(); } if ($lg_gallery->is_folder($lg_gallery->file)) { $the_folder = new LazyestFolder($lg_gallery->file); } elseif ($lg_gallery->is_image($lg_gallery->file)) { $the_folder = new LazyestFolder(dirname($lg_gallery->file)); } else { return false; } $login_required = !$the_folder->user_can('viewer'); unset($the_folder); return $login_required; }