Exemple #1
0
 /**
  * LazyestImage::uri()
  * The address for the image in Lazyest Gallery
  * This can be a slide view page
  * @param string $widget
  * @return string
  */
 function uri($widget = 'none')
 {
     global $lg_gallery;
     if ('' == $this->image || !isset($lg_gallery)) {
         return false;
     }
     return $this->folder->uri($widget) . lg_nice_link($this->image);
 }
Exemple #2
0
 /**
  * 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);
             }
         }
     }
 }
Exemple #3
0
 /**
  * LazyestUploadTab::image_to_editor()
  * 
  * @param mixed $whathtml what to insert, shortcode
  * @return void
  */
 function image_to_editor($whathtml)
 {
     global $lg_gallery;
     $file = urldecode($_POST['lg_folder']);
     $single = urldecode($_POST['lg_image']);
     $folder = new LazyestFolder($file);
     $folder->open();
     $image = $folder->single_image($single, $_POST["image-size"] . 's');
     $onclick = $image->on_click('widget');
     $caption = isset($_POST["short_code_caption"]) ? $_POST["short_code_caption"] : '';
     $html = '';
     switch ($whathtml) {
         case 'shortcode':
             $caption = '' != $caption ? sprintf('caption="%s"', $caption) : $caption;
             $align = isset($_POST["image_align"]) ? sprintf('align="%s"', $_POST["image_align"]) : '';
             $display = sprintf('display="%s"', $_POST["image-size"]);
             $html .= sprintf('[lg_image folder="%s" image="%s" %s %s %s]', $file, $single, $caption, $align, $display);
             break;
     }
     return media_send_to_editor($html);
 }
Exemple #4
0
 /**
  * LazyestFolder::user_can()
  * Check if the current user has certain capabilities in this folder 
  * 
  * @param string $capability
  * @return
  */
 function user_can($capability = '')
 {
     global $lg_gallery, $current_user;
     if (current_user_can('manage_options')) {
         return true;
     }
     // administrator should always have access
     get_currentuserinfo();
     if (!isset($this->visibility)) {
         $this->open();
     }
     // check for private folder
     if ('private' == $this->visibility && $this->editor != $current_user->ID) {
         return false;
     }
     // check for acces by role
     switch ($capability) {
         case 'viewer':
             $roles = array();
             $roles[] = $this->viewer_level;
             $up_dirs = explode('/', untrailingslashit($this->curdir));
             $path = '';
             if (1 < count($up_dirs)) {
                 for ($i = 0; $i < count($up_dirs) - 1; $i++) {
                     $path .= trailingslashit($up_dirs[$i]);
                     $upfolder = new LazyestFolder($path);
                     $upfolder->open();
                     $roles[] = $upfolder->viewer_level;
                     unset($upfolder);
                 }
             }
             $user_can = true;
             foreach ($roles as $role) {
                 if ('everyone' == $role || '' == $role) {
                     $user_can = $user_can ? true : false;
                 } else {
                     $cap = $lg_gallery->level_cap($role);
                     $user_can = $user_can ? current_user_can($cap) : false;
                 }
             }
             return $user_can;
             break;
         case 'editor':
             if (-1 < $this->editor) {
                 return current_user_can('manage_lazyest_files') || $this->editor == $current_user->ID;
             } else {
                 return current_user_can('manage_lazyest_files') || current_user_can('create_lazyest_folder');
             }
             break;
         case 'author':
             if (0 < count($this->authors)) {
                 return current_user_can('manage_lazyest_files') || in_array($current_user->ID, $this->authors);
             } else {
                 return current_user_can('manage_lazyest_files') || current_user_can('edit_lazyest_fields');
             }
             break;
     }
 }
Exemple #5
0
 /**
  * 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;
 }
Exemple #6
0
 /**
  * Lazyest_Widget_Really_Slideshow::get_image()
  * 
  * @return void
  */
 function get_image()
 {
     global $post, $lg_gallery;
     $nonce = $_POST['_wpnonce'];
     if (!wp_verify_nonce($nonce, 'lazyest_widgets')) {
         die(0);
     }
     $not_images = get_option('lazyest_not_images');
     if (!$not_images) {
         $not_images = array();
     }
     $response = '0';
     $filevar = false;
     $count = 0;
     $tried = array();
     while (!$filevar && $count < $this->retry) {
         $id = rand(1, absint($lg_gallery->get_option('image_indexing')));
         if (in_array($id, $tried) || in_array($id, $not_images)) {
             continue;
         }
         $afile = $lg_gallery->get_file_by_id($id);
         if ($afile && $lg_gallery->is_image($afile[0])) {
             $filevar = $afile[0];
         } else {
             $not_images[] = $id;
         }
         $tried[] = $id;
         $count++;
     }
     update_option('lazyest_not_images', $not_images);
     if ($filevar) {
         $folder_path = dirname($filevar);
         $image_file = basename($filevar);
         $folder = new LazyestFolder($folder_path);
         if ($folder) {
             $image = $folder->single_image($image_file, 'thumbs');
             $response = '<div class="lg_thumb">';
             $onclick = $image->on_click();
             $class = 'thumb';
             if ('TRUE' != $lg_gallery->get_option('enable_cache') || 'TRUE' == $lg_gallery->get_option('async_cache') && !file_exists($image->loc())) {
                 $class .= ' lg_ajax';
             }
             $postid = is_object($post) ? $post->ID : $lg_gallery->get_option('gallery_id');
             $response .= sprintf('<div class="lg_thumb_image"><a id="%s_%s" href="%s" class="%s" rel="%s" title="%s" ><img class="%s" src="%s" alt="%s" /></a></div>', $onclick['id'], $postid, $onclick['href'], $onclick['class'], $onclick['rel'], $image->title(), $class, $image->src(), $image->alt());
             $response .= "</div>\n";
         }
     }
     echo $response;
     die;
 }
Exemple #7
0
    /**
     * 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);
    }
Exemple #8
0
 /**
  * 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;
 }
Exemple #10
0
 /**
  * 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;
 }
 /**
  * LazyestFields::folder_description()
  * Appends extra fileds to folder description in thumbnail view
  * 
  * @since 1.1.10
  * @param string $description
  * @param LazyestFolder $folder
  * @return void
  */
 function folder_description($after, $folder)
 {
     if (0 != count($this->fields)) {
         foreach ($this->fields as $field) {
             if ('folder' == $field['target']) {
                 $after .= sprintf('<div class="extra-field %s"><p><span class="name">%s</span> <span class="value">%s</span></p></div>', $field['name'], esc_html($field['display']), lg_html($folder->get_extra_field($field['name'])));
             }
         }
     }
     return $after;
 }
Exemple #12
0
/**
 * 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;
}
Exemple #13
0
 function body_cell($key, $value, $i)
 {
     global $comment, $lg_gallery;
     // set global $comment so we can use WordPress functions
     $comment = $this->items[$i];
     $comment_ID = $comment->comment_ID;
     // in this table we only shows approved comments
     $comment_status = 'approve';
     $pending_comments = 0;
     switch ($key) {
         case 'author':
             $author_url = get_comment_author_url();
             $cell = '<td class="author column-author">';
             $cell .= sprintf('<strong> %s %s </strong><br />', get_avatar($comment, 32), get_comment_author($comment));
             if (current_user_can('moderate_comments')) {
                 if (!empty($comment->comment_author_email)) {
                     $cell .= get_comment_author_email_link() . '<br />';
                 }
                 $cell .= sprintf('<a href="edit-comments.php?s=%s&amp;mode=detail">%s</a>', get_comment_author_IP($comment), get_comment_author_IP($comment));
             }
             $cell .= '</td>';
             break;
         case 'comment':
             $approve_nonce = esc_html('_wpnonce=' . wp_create_nonce("approve-comment_{$comment_ID}"));
             $del_nonce = esc_html('_wpnonce=' . wp_create_nonce("delete-comment_{$comment_ID}"));
             $postID = $lg_gallery->get_option('gallery_id');
             $cell = '<td class="comment column-comment">';
             $filevar = isset($comment->filevar) ? $comment->filevar : '';
             $uri = trailingslashit($lg_gallery->get_option('gallery_prev'));
             if ('TRUE' != $lg_gallery->get_option('use_permalinks')) {
                 $comment_url = add_query_arg('file', $filevar, $uri);
             } else {
                 $comment_url = trailingslashit($uri . $filevar);
             }
             $comment_url .= '#comment-' . $comment_ID;
             $cell .= '<div class="submitted-on">';
             $cell .= sprintf(__('Submitted on <a href="%1$s">%2$s - %3$s</a>'), esc_url($comment_url), get_comment_date(get_option('date_format')), get_comment_date(get_option('time_format')));
             $cell .= sprintf('<p>%s</p>', apply_filters('comment_text', get_comment_text($comment), $comment));
             if (current_user_can('moderate_comments')) {
                 $cell .= '<div class="row-actions">';
                 $cell .= sprintf('<span class="unapprove"><a href="%s" class="delete:the-comment-list:comment-%s:e7e7d3:action=dim-comment&amp;new=unapproved vim-u vim-destructive" title="%s">%s</a> | </span>', esc_url("comment.php?action=unapprovecomment&p={$postID}&c={$comment_ID}&{$approve_nonce}"), $comment_ID, esc_attr__('Unapprove this comment'), __('Unapprove'));
                 $cell .= sprintf('<span class="edit"><a href="comment.php?action=editcomment&amp;c=%s" title="%s">%s</a> | </span>', $comment_ID, esc_attr__('Edit comment'), __('Edit'));
                 $cell .= sprintf('<span class="spam"><a href="%s" class="delete:the-comment-list:comment-%s::spam=1 vim-s vim-destructive" title="%s">%s</a> | </span>', esc_url("comment.php?action=spamcomment&p={$postID}&c={$comment_ID}&{$del_nonce}"), $comment_ID, esc_attr__('Mark this comment as spam'), _x('Spam', 'verb'));
                 $cell .= sprintf('<span class="trash"><a href="%s" class="delete:the-comment-list:%s::trash=1 delete vim-d vim-destructive" title="%s">%s</a></span>', esc_url("comment.php?action=trashcomment&p={$postID}&c={$comment_ID}&{$del_nonce}"), $comment_ID, esc_attr__('Move this comment to the trash'), _x('Trash', 'verb'));
             }
             $cell .= '</td>';
             break;
         case 'response':
             $cell = '<td class="response column-response">';
             $edit_title = esc_html__('Gallery', 'lazyest-gallery');
             $edit_url = admin_url('admin.php?page=lazyest-filemanager&folder=');
             $filevar = isset($comment->filevar) ? stripslashes(rawurldecode($comment->filevar)) : $lg_gallery->commentor->get_file_by_comment_id($comment_ID);
             $preview = $lg_gallery->get_option('gallery_prev');
             $class = 'alignright';
             $img_src = trailingslashit($lg_gallery->plugin_url) . 'images/folders.png';
             $img_alt = __('Icon', 'lazyest-gallery');
             $img_title = __('Click to View', 'lazyest-gallery');
             $img_id = 0;
             $img_class = 'lg';
             if ('' !== $filevar) {
                 $edit_url .= $lg_gallery->is_folder($filevar) ? lg_nice_link($filevar) : lg_nice_link(dirname($filevar));
                 if ($lg_gallery->is_folder($filevar)) {
                     $folder = new LazyestFolder($filevar);
                     $folder->open();
                     $edit_title = $folder->title();
                     $preview = $folder->uri();
                     $img_src = trailingslashit($lg_gallery->plugin_url) . 'images/folder-icon.png';
                     $img_id = $folder->id;
                 }
                 if ($lg_gallery->is_image($filevar)) {
                     $folder = new LazyestFolder(dirname($filevar));
                     $image = $folder->single_image(basename($filevar), 'thumbs');
                     $edit_url .= '#' . $image->form_name();
                     $edit_title = $image->title();
                     $onclick = $image->on_click();
                     $preview = $onclick['href'];
                     $class .= ' ' . $onclick['class'];
                     $img_src = $image->src();
                     if ('TRUE' == $lg_gallery->get_option('async_cache') && !file_exists($image->loc())) {
                         $img_class = 'lg_ajax';
                     }
                     $img_alt = $image->alt();
                     $img_id = $image->id;
                 }
             }
             $cell .= '<div class="response-links"><span class="post-com-count-wrapper">';
             $cell .= sprintf('<a href="%s">%s</a><br />', $edit_url, $edit_title);
             $cell .= sprintf('<a href="admin.php?page=lazyest-filemanager&edit=comments&file=%s" title="%s" class="post-com-count"><span class="comment-count">%s</span></a>', $filevar, esc_attr(__('0 pending')), $lg_gallery->commentor->count_comments($img_id));
             $cell .= '</div>';
             $cell .= sprintf('<a target="_blank" href="%s" class="alignright"><img width="32" height="32" src="%s" alt="%s"  title="%s" class="%s" /></a>', $preview, $img_src, $img_alt, $img_title, $img_class);
             $cell .= "</td>\n";
             break;
     }
     return $cell;
 }
Exemple #14
0
/**
 * 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;
}