コード例 #1
0
ファイル: images.inc.php プロジェクト: beealone/Serendipity
             $data['ob_serendipity_killPath'] = ob_get_contents();
             ob_end_clean();
         }
     } else {
         $data['print_ERROR_NO_DIRECTORY'] = sprintf(ERROR_NO_DIRECTORY, $new_dir);
     }
     serendipity_plugin_api::hook_event('backend_directory_delete', $new_dir);
     break;
 case 'directoryEdit':
     if (!serendipity_checkPermission('adminImagesDirectories')) {
         return;
     }
     $data['case_directoryEdit'] = true;
     $use_dir = serendipity_uploadSecure($serendipity['GET']['dir']);
     $checkpath = array(array('relpath' => $use_dir));
     if (!serendipity_directoryACL($checkpath, 'write')) {
         return;
     }
     if (!empty($serendipity['POST']['save'])) {
         $newDir = serendipity_uploadSecure(serendipity_makeFilename($serendipity['POST']['newDir']));
         $oldDir = serendipity_uploadSecure($serendipity['POST']['oldDir']);
         if ($oldDir != $newDir) {
             //is this possible?
             ob_start();
             serendipity_moveMediaDirectory($oldDir, $newDir);
             $data['ob_serendipity_moveMediaDirectory'] = ob_get_contents();
             ob_end_clean();
             $use_dir = $newDir;
         }
         serendipity_ACLGrant(0, 'directory', 'read', $serendipity['POST']['read_authors'], $use_dir);
         serendipity_ACLGrant(0, 'directory', 'write', $serendipity['POST']['write_authors'], $use_dir);
コード例 #2
0
/**
 * Gets all available media directories
 *
 * @return array
 *
 */
function &serendipity_getMediaPaths()
{
    global $serendipity;
    $aExclude = array("CVS" => true, ".svn" => true);
    serendipity_plugin_api::hook_event('backend_media_path_exclude_directories', $aExclude);
    $paths = array();
    $aResultSet = serendipity_traversePath($serendipity['serendipityPath'] . $serendipity['uploadPath'], '', false, NULL, 1, NULL, FALSE, $aExclude);
    foreach ($aResultSet as $sKey => $sFile) {
        if ($sFile['directory']) {
            array_push($paths, $sFile);
        }
        unset($aResultSet[$sKey]);
    }
    serendipity_directoryACL($paths, 'read');
    usort($paths, 'serendipity_sortPath');
    return $paths;
}
コード例 #3
0
 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 . '&');
     //Can't trust $serendipity['GET'] on all servers.... so we build it ourselves from subpage
     if ($serendipity['rewrite'] != 'none') {
         $uri_parts = explode('?', str_replace('&', '&', $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);
         }
     }
 }