Exemple #1
0
function showMediaLibrary($messages = false, $addvar_check = false, $smarty_vars = array())
{
    global $serendipity;
    if (!serendipity_checkPermission('adminImagesView')) {
        return;
    }
    $output = "";
    // After upload, do not show the list to be able to proceed to
    // media selection.
    if ($addvar_check && !empty($GLOBALS['image_selector_addvars'])) {
        return true;
    }
    if (!isset($serendipity['thumbPerPage'])) {
        $serendipity['thumbPerPage'] = 2;
    }
    $smarty_vars = array('textarea' => isset($serendipity['GET']['textarea']) ? $serendipity['GET']['textarea'] : false, 'htmltarget' => isset($serendipity['GET']['htmltarget']) ? $serendipity['GET']['htmltarget'] : '', 'filename_only' => isset($serendipity['GET']['filename_only']) ? $serendipity['GET']['filename_only'] : false);
    $show_upload = isset($serendipity['GET']['showUpload']) ? $serendipity['GET']['showUpload'] : false;
    $output .= serendipity_displayImageList(isset($serendipity['GET']['page']) ? $serendipity['GET']['page'] : 1, $serendipity['thumbPerPage'], isset($serendipity['GET']['showMediaToolbar']) ? serendipity_db_bool($serendipity['GET']['showMediaToolbar']) : true, NULL, $show_upload, NULL, $smarty_vars);
    return $output;
}
function showMediaLibrary($messages = false, $addvar_check = false)
{
    global $serendipity;
    if (!serendipity_checkPermission('adminImagesView')) {
        return;
    }
    if (!empty($messages)) {
        echo '<div class="imageMessage"><ul>';
        foreach ($messages as $message) {
            echo '<li>' . $message . '</li>';
        }
        echo '</ul></div>';
    }
    // After upload, do not show the list to be able to proceed to
    // media selection.
    if ($addvar_check && !empty($GLOBALS['image_selector_addvars'])) {
        return true;
    }
    ?>
<script type="text/javascript" language="javascript">
    <!--
        function rename(id, fname) {
            if(newname = prompt('<?php 
    echo ENTER_NEW_NAME;
    ?>
' + fname, fname)) {
                location.href='?<?php 
    echo serendipity_setFormToken('url');
    ?>
&serendipity[adminModule]=images&serendipity[adminAction]=rename&serendipity[fid]='+ escape(id) + '&serendipity[newname]='+ escape(newname);
            }
        }
    //-->
</script>

<?php 
    if (!isset($serendipity['thumbPerPage'])) {
        $serendipity['thumbPerPage'] = 2;
    }
    serendipity_displayImageList(isset($serendipity['GET']['page']) ? $serendipity['GET']['page'] : 1, $serendipity['thumbPerPage'], true);
}
        $media['case'] = 'start';
        break;
    case 'default':
    default:
        if (!empty($serendipity['GET']['adminAction']) && $serendipity['GET']['adminModule'] == 'images' && $serendipity['GET']['adminAction'] != 'default') {
            // Might need to set $serendipity['adminFile_redirect'] here.
            $serendipity['adminFile'] = 'serendipity_admin_image_selector.php';
            ob_start();
            include S9Y_INCLUDE_PATH . 'include/admin/images.inc.php';
            $media['external'] = ob_get_contents();
            $media['case'] = 'external';
            ob_end_clean();
            break;
        }
        $media['case'] = 'default';
        $add_url = '';
        if (!empty($serendipity['GET']['htmltarget'])) {
            $add_url .= '&amp;serendipity[htmltarget]=' . serendipity_specialchars($serendipity['GET']['htmltarget']);
        }
        if (!empty($serendipity['GET']['filename_only'])) {
            $add_url .= '&amp;serendipity[filename_only]=' . serendipity_specialchars($serendipity['GET']['filename_only']);
        }
        if (!isset($serendipity['thumbPerPage2'])) {
            $serendipity['thumbPerPage2'] = 3;
        }
        $media['external'] = serendipity_displayImageList(isset($serendipity['GET']['page']) ? $serendipity['GET']['page'] : 1, $serendipity['thumbPerPage2'], $serendipity['showMediaToolbar'] ? true : false, '?serendipity[step]=1' . $add_url . '&amp;serendipity[textarea]=' . serendipity_specialchars($serendipity['GET']['textarea']), true, null);
}
$media = array_merge($serendipity['GET'], $media);
$serendipity['smarty']->assignByRef('media', $media);
$serendipity['smarty']->display(serendipity_getTemplateFile($showFile, 'serendipityPath'));
/* vim: set sts=4 ts=4 expandtab : */
        if (!empty($serendipity['GET']['adminAction']) && $serendipity['GET']['adminModule'] == 'images' && $serendipity['GET']['adminAction'] != 'default') {
            // Might need to set $serendipity['adminFile_redirect'] here.
            $serendipity['adminFile'] = 'serendipity_admin_image_selector.php';
            ob_start();
            include S9Y_INCLUDE_PATH . 'include/admin/images.inc.php';
            $media['external'] = ob_get_contents();
            $media['case'] = 'external';
            ob_end_clean();
            break;
        }
        $media['case'] = 'default';
        $add_url = '';
        if (!empty($serendipity['GET']['htmltarget'])) {
            $add_url .= '&amp;serendipity[htmltarget]=' . htmlspecialchars($serendipity['GET']['htmltarget']);
        }
        if (!empty($serendipity['GET']['filename_only'])) {
            $add_url .= '&amp;serendipity[filename_only]=' . htmlspecialchars($serendipity['GET']['filename_only']);
        }
        if (!isset($serendipity['thumbPerPage2'])) {
            $serendipity['thumbPerPage2'] = 3;
        }
        ob_start();
        $block = serendipity_displayImageList(isset($serendipity['GET']['page']) ? $serendipity['GET']['page'] : 1, $serendipity['thumbPerPage2'], $serendipity['showMediaToolbar'] ? true : false, '?serendipity[step]=1' . $add_url . '&amp;serendipity[textarea]=' . $serendipity['GET']['textarea'], true, null, false);
        $media['external'] = ob_get_contents();
        ob_end_clean();
        serendipity_smarty_fetch('MEDIA_LIST', $block);
}
$media = array_merge($serendipity['GET'], $media);
$serendipity['smarty']->assign_by_ref('media', $media);
$serendipity['smarty']->display(serendipity_getTemplateFile($showFile, 'serendipityPath'));
/* vim: set sts=4 ts=4 expandtab : */
 function show()
 {
     global $serendipity;
     if (!headers_sent()) {
         header('HTTP/1.0 200');
         header('Status: 200');
     }
     if (!is_object($serendipity['smarty'])) {
         serendipity_smarty_init();
     }
     $_ENV['staticpage_pagetitle'] = preg_replace('@[^a-z0-9]@i', '_', $this->get_config('base_directory'));
     $serendipity['smarty']->assign('staticpage_pagetitle', $_ENV['staticpage_pagetitle']);
     $serendipity['smarty']->assign('const', array('filesize' => PLUGIN_EVENT_USERGALLERY_FILESIZE, 'filename' => PLUGIN_EVENT_USERGALLERY_FILENAME, 'dimension' => PLUGIN_EVENT_USERGALLERY_DIMENSION, 'uponelevel' => PLUGIN_EVENT_USERGALLERY_UPONELEVEL, 'back' => PLUGIN_EVENT_USERGALLERY_BACK, 'previous' => PLUGIN_EVENT_USERGALLERY_PREVIOUS, 'next' => PLUGIN_EVENT_USERGALLERY_NEXT, 'PREVIOUS_PAGE' => PREVIOUS_PAGE, 'NEXT_PAGE' => NEXT_PAGE));
     $sub_page = $this->get_config('subpage');
     $permalink = $this->get_config('permalink');
     $serendipity['smarty']->assign('plugin_usergallery_httppath', $serendipity['rewrite'] != 'none' ? $permalink : $serendipity['indexFile'] . '?serendipity[subpage]=' . $sub_page);
     $serendipity['smarty']->assign('plugin_usergallery_httppath_extend', $serendipity['rewrite'] != 'none' ? $permalink . '?' : $serendipity['indexFile'] . '?serendipity[subpage]=' . $sub_page . '&amp;');
     //Can't trust $serendipity['GET'] on all servers.... so we build it ourselves from subpage
     if ($serendipity['rewrite'] != 'none') {
         $uri_parts = explode('?', str_replace('&amp;', '&', $serendipity['GET']['subpage']));
         $parts = explode('&', $uri_parts[1]);
         if (count($parts) > 1) {
             foreach ($parts as $key => $value) {
                 $val = explode('=', $value);
                 $val0 = str_replace('serendipity[', '', $val[0]);
                 if ($val[0] == $val0) {
                     $_GET[$val[0]] = $val[1];
                 } else {
                     $val0 = str_replace(']', '', $val0);
                     $serendipity['GET'][$val0] = $val[1];
                 }
             }
         } else {
             $val = explode('=', $parts[0]);
             $val0 = str_replace('serendipity[', '', $val[0]);
             if ($val[0] == $val0) {
                 $_GET[$val[0]] = $val[1];
             } else {
                 $val0 = str_replace(']', '', $val0);
                 $serendipity['GET'][$val0] = $val[1];
             }
         }
     }
     switch ($this->get_config("image_order")) {
         case 'nameacs':
             $orderby = 'i.name';
             $order = 'ASC';
             break;
         case 'namedesc':
             $orderby = 'i.name';
             $order = 'DESC';
             break;
         case 'dateacs':
             $orderby = 'i.date';
             $order = 'ASC';
             break;
         case 'datedesc':
             $orderby = 'i.date';
             $order = 'DESC';
             break;
     }
     if (isset($serendipity['GET']['image'])) {
         $this->displayImage($serendipity['GET']['image'], $orderby, $order);
     } else {
         $num_cols = $this->get_config('num_cols');
         $base_directory = $this->get_config('base_directory');
         $show_objects = serendipity_db_bool($this->get_config('show_objects', false));
         if ($this->get_config('style') == "thumbpage") {
             $images_per_page = $this->get_config('images_per_page');
             $display_dir_tree = $this->get_config('display_dir_tree', 'no');
             $show_1lvl_sub = $this->get_config('show_1lvl_sub', 'no');
             $dir_list = $this->get_config('dir_list');
             $num_cols = $this->get_config('num_cols');
             $permitted_gallery = false;
             if ($base_directory == 'gallery') {
                 $limit_directory = '';
             } else {
                 $limit_directory = $base_directory;
             }
             $limit_images_directory = $limit_directory;
             $limit_output = $limit_directory;
             $serendipity['smarty']->assign('plugin_usergallery_currentgal', '');
             $serendipity['smarty']->assign('plugin_usergallery_uppath', '');
             $serendipity['smarty']->assign('plugin_usergallery_toplevel', 'yes');
             //Let's get a directory listing that has all our ACLs applied already!
             $directories_temp = serendipity_traversePath($serendipity['serendipityPath'] . $serendipity['uploadPath'], $limit_directory, NULL, $pattern, 1, NULL, "read", NULL);
             //Check to see if we are calling a gallery directly
             if (isset($_GET['gallery']) && $_GET['gallery'] != '') {
                 //replace weird characters.  Was more important before we used the database.
                 $getpathtemp = str_replace("//", "/", str_replace("..", "", urldecode($_GET['gallery'])));
                 //Ok, let's check the out directory is actually in the returned directories.
                 if (is_array($directories_temp)) {
                     foreach ($directories_temp as $f => $dir) {
                         if ($getpathtemp == $dir['relpath']) {
                             //yay! We have access to the directory.
                             $permitted_gallery = true;
                             break;
                         }
                     }
                 }
                 //If we have a matching directory, let's set the gallery up.
                 if ($permitted_gallery) {
                     $limit_images_directory = $getpathtemp;
                     $temp_array = explode('/', $getpathtemp);
                     array_pop($temp_array);
                     $limit_output = array_pop($temp_array);
                     if ($display_dir_tree == 'no') {
                         $up_path = implode('/', $temp_array);
                         if ($up_path != "") {
                             $up_path = $up_path . "/";
                         }
                     }
                     $serendipity['smarty']->assign('plugin_usergallery_currentgal', $getpathtemp);
                     $serendipity['smarty']->assign('plugin_usergallery_uppath', $up_path);
                     $serendipity['smarty']->assign('plugin_usergallery_toplevel', 'no');
                 }
             } else {
                 //We weren't calling a gallery directory, so it is set up in the configuration.  If it is the base 'uploads' directory there are never any permissions on it.
                 if ($limit_images_directory != '') {
                     $perm_test_array = array(array('name' => str_replace("/", "", $limit_images_directory), 'depth' => 1, 'relpath' => $limit_images_directory, 'directory' => 1));
                     if (serendipity_directoryACL($perm_test_array, 'read')) {
                         $permitted_gallery = true;
                     }
                 } else {
                     $permitted_gallery = true;
                 }
             }
             $where = $show_objects ? '' : "WHERE mime LIKE 'image/%'";
             $query = "SELECT path, count(id) FROM {$serendipity['dbPrefix']}images " . $where . " GROUP BY path";
             $rs = serendipity_db_query($query, false, 'assoc');
             if (is_array($rs)) {
                 foreach ($rs as $f => $record) {
                     if ($limit_directory != '') {
                         $temp_count = strlen($limit_directory);
                         if (strcmp(substr($record['path'], 0, $temp_count), $limit_directory) == 0) {
                             $temp_filecount[$record['path']] = $record['count(id)'];
                         }
                     } else {
                         $temp_filecount[$record['path']] = $record['count(id)'];
                     }
                 }
             }
             if ($dir_list == 'yes') {
                 if ($display_dir_tree == 'yes') {
                     if (!isset($temp_filecount[$limit_directory])) {
                         $temp_filecount[$limit_directory] = '0';
                     }
                     $serendipity['smarty']->assign('plugin_usergallery_maindir_filecount', $temp_filecount[$limit_directory]);
                 } else {
                     if ($up_path == '') {
                         $temp_filecount[$up_path] = $temp_filecount[$limit_directory];
                     }
                     if (!isset($temp_filecount[$up_path])) {
                         $temp_filecount[$up_path] = '0';
                     }
                     $serendipity['smarty']->assign('plugin_usergallery_maindir_filecount', $temp_filecount[$up_path]);
                 }
             }
             if (is_array($directories_temp)) {
                 usort($directories_temp, 'serendipity_sortPath');
                 foreach ($directories_temp as $f => $dir) {
                     $directory = $dir['relpath'];
                     $dir['filecount'] = $temp_filecount[$directory];
                     if (isset($dir['depth'])) {
                         $dir['pxdepth'] = $dir['depth'] * $this->get_config('dir_tab', 10);
                     }
                     if ($dir['filecount'] == '') {
                         $dir['filecount'] = 0;
                     }
                     if ($display_dir_tree == 'yes') {
                         $directories[$dir['relpath']] = $dir;
                     } else {
                         if ($show_1lvl_sub == 'yes') {
                             $temp_count = strlen($limit_images_directory);
                             if (strcmp(substr($directory, 0, $temp_count), $limit_images_directory) == 0 && $directory != $limit_images_directory) {
                                 $full_length = strlen($directory);
                                 if (substr_count(substr($directory, $temp_count, $full_length), '/') == 1) {
                                     $directories[$dir['relpath']] = $dir;
                                 } else {
                                     $temp_count = $temp_count + 1 + strpos(substr($directory, $temp_count, $full_length), '/');
                                     $directories[substr($directory, 0, $temp_count)]['filecount'] = $directories[substr($directory, 0, $temp_count)]['filecount'] + $dir['filecount'];
                                 }
                             }
                         } else {
                             $temp_count = strlen($limit_images_directory);
                             if (strcmp(substr($directory, 0, $temp_count), $limit_images_directory) == 0 && $directory != $limit_images_directory) {
                                 $directories[$directory] = $dir;
                             }
                         }
                     }
                 }
             }
             $serendipity['smarty']->assign('plugin_usergallery_subdirectories', $directories);
             $lower_limit = 0;
             $showpage = false;
             if ($images_per_page != 0 && $permitted_gallery) {
                 $showpage = true;
                 $total_count = $temp_filecount[$limit_images_directory];
                 if ($total_count <= $images_per_page) {
                     $showpage = false;
                 }
                 if ($showpage) {
                     if (isset($_GET['page']) && $_GET['page'] != '') {
                         $current_page = intval($_GET['page']);
                     } else {
                         $current_page = 1;
                     }
                     $total_pages = ceil($total_count / $images_per_page);
                     $previous_page = $current_page - 1;
                     if ($previous_page == 0) {
                         $lower_limit = 0;
                     } else {
                         $lower_limit = $previous_page * $images_per_page;
                     }
                 }
             }
             $serendipity['smarty']->assign(array('plugin_usergallery_pagination' => $showpage, 'plugin_usergallery_total_count' => $total_count, 'plugin_usergallery_total_pages' => $total_pages, 'plugin_usergallery_current_page' => $current_page, 'plugin_usergallery_next_page' => $current_page + 1, 'plugin_usergallery_previous_page' => $current_page - 1));
             if ($this->get_config('image_strict') == 'yes') {
                 $images = serendipity_fetchImagesFromDatabase($lower_limit, $images_per_page, $total, $orderby, $order, $limit_images_directory, '', '', array(), true);
             } else {
                 $images = serendipity_fetchImagesFromDatabase($lower_limit, $images_per_page, $total, $orderby, $order, $limit_images_directory);
             }
             if (is_array($images)) {
                 foreach ($images as $f => $image) {
                     $is_image = serendipity_isImage($image);
                     if (!$is_image && !$show_objects) {
                         continue;
                     }
                     // do not include Non-Image objects to array
                     if ($is_image) {
                         $image['link'] = $serendipity['serendipityHTTPPath'] . $serendipity['uploadHTTPPath'] . $image['path'] . $image['name'] . '.' . $image['thumbnail_name'] . '.' . $image['extension'];
                         $image['dimension'] = $image['dimensions_width'] . 'x' . $image['dimensions_height'];
                         $image['isimage'] = true;
                     } else {
                         $image['isimage'] = false;
                         $image['link'] = serendipity_getTemplateFile('admin/img/mime_unknown.png');
                     }
                     $image['fullimage'] = $serendipity['serendipityHTTPPath'] . $serendipity['uploadHTTPPath'] . $image['path'] . $image['name'] . '.' . $image['extension'];
                     $image['filesize'] = round($image['size'] / 1024);
                     $image['popupwidth'] = $is_image ? $image['dimensions_width'] + 20 : 600;
                     $image['popupheight'] = $is_image ? $image['dimensions_height'] + 20 : 500;
                     $process_images[$image['name']] = $image;
                 }
             }
             $gallery_array = explode('/', $up_path);
             foreach ($gallery_array as $f => $gallery) {
                 $gallery_path = $gallery_path . $gallery . "/";
                 if ($gallery_path != $base_directory) {
                     $path_array[$gallery]['path'] = $gallery_path;
                     $path_array[$gallery]['name'] = $gallery;
                 }
             }
             unset($path_array['']);
             if ($limit_output == $base_directory) {
                 $limit_output = '';
             }
             // this needs the latest >= v. 2.0 lightbox plugin installed!
             $lightbox_type = $this->get_config('lightbox_type');
             $lbtype = 'rel="lightbox[]"';
             if ($lightbox_type == 'prettyphoto') {
                 $lbtype = 'rel="prettyPhoto[]"';
             } elseif ($lightbox_type == 'colorbox') {
                 $lbtype = 'rel="colorbox[]"';
             } elseif ($lightbox_type == 'magnific') {
                 $lbtype = 'rel="magnificPopup[]"';
             }
             $serendipity['smarty']->assign(array('plugin_usergallery_title' => $this->get_config('title'), 'plugin_usergallery_cols' => $num_cols, 'plugin_usergallery_preface' => $this->get_config('intro'), 'plugin_usergallery_fixed_width' => $this->get_config('fixed_width'), 'plugin_usergallery_image_display' => $this->get_config('image_display'), 'plugin_usergallery_gallery_breadcrumb' => $path_array, 'plugin_usergallery_dir_list' => $dir_list, 'plugin_usergallery_display_dir_tree' => $display_dir_tree, 'plugin_usergallery_colwidth' => round(10 / $num_cols * 10 - 6, 2), 'plugin_usergallery_limit_directory' => preg_replace('@[^a-z0-9]@i', ' ', $limit_output), 'plugin_usergallery_uselightbox' => serendipity_db_bool($this->get_config('show_lightbox', false)), 'plugin_usergallery_lightbox_script' => $lightbox_type, 'plugin_usergallery_lightbox_dir' => $this->get_config('lightbox_path'), 'plugin_usergallery_lightbox_jquery' => !class_exists('serendipity_event_jquery') && !$serendipity['capabilities']['jquery'] ? true : false, 'plugin_usergallery_lightbox_type' => $lbtype, 'plugin_usergallery_images' => $process_images));
             $content = $this->parseTemplate('plugin_usergallery.tpl');
             echo $content;
         } else {
             $add_url = '?serendipity[subpage]=' . $this->get_config('subpage');
             if ($base_directory == 'gallery') {
                 $limit_directory = '';
             } else {
                 $limit_directory = $base_directory;
             }
             serendipity_displayImageList(isset($serendipity['GET']['page']) ? $serendipity['GET']['page'] : 1, $num_cols, false, $add_url, false, $limit_directory);
         }
     }
 }