当前位置: 首页>>代码示例>>PHP>>正文


PHP nggAdmin::set_gallery_preview方法代码示例

本文整理汇总了PHP中nggAdmin::set_gallery_preview方法的典型用法代码示例。如果您正苦于以下问题:PHP nggAdmin::set_gallery_preview方法的具体用法?PHP nggAdmin::set_gallery_preview怎么用?PHP nggAdmin::set_gallery_preview使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在nggAdmin的用法示例。


在下文中一共展示了nggAdmin::set_gallery_preview方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: import_gallery

 /**
  * nggAdmin::import_gallery()
  * TODO: Check permission of existing thumb folder & images
  *
  * @class nggAdmin
  * @param string $galleryfolder contains relative path to the gallery itself
  * @return void
  */
 static function import_gallery($galleryfolder, $gallery_id = NULL)
 {
     global $wpdb, $user_ID;
     // get the current user ID
     wp_get_current_user();
     $created_msg = '';
     // remove trailing slash at the end, if somebody use it
     $galleryfolder = untrailingslashit($galleryfolder);
     $fs = C_Fs::get_instance();
     if (is_null($gallery_id)) {
         $gallerypath = $fs->join_paths($fs->get_document_root('content'), $galleryfolder);
     } else {
         $storage = C_Gallery_Storage::get_instance();
         $gallerypath = $storage->get_gallery_abspath($gallery_id);
     }
     if (!is_dir($gallerypath)) {
         nggGallery::show_error(sprintf(__("Directory <strong>%s</strong> doesn&#96;t exist!", 'nggallery'), esc_html($gallerypath)));
         return;
     }
     // read list of images
     $new_imageslist = nggAdmin::scandir($gallerypath);
     if (empty($new_imageslist)) {
         nggGallery::show_message(sprintf(__("Directory <strong>%s</strong> contains no pictures", 'nggallery'), esc_html($gallerypath)));
         return;
     }
     // take folder name as gallery name
     $galleryname = basename($galleryfolder);
     $galleryname = apply_filters('ngg_gallery_name', $galleryname);
     // check for existing gallery folder
     if (is_null($gallery_id)) {
         $gallery_id = $wpdb->get_var("SELECT gid FROM {$wpdb->nggallery} WHERE path = '{$galleryfolder}' ");
     }
     if (!$gallery_id) {
         // now add the gallery to the database
         $gallery_id = nggdb::add_gallery($galleryname, $galleryfolder, '', 0, 0, $user_ID);
         if (!$gallery_id) {
             nggGallery::show_error(__('Database error. Could not add gallery!', 'nggallery'));
             return;
         } else {
             do_action('ngg_created_new_gallery', $gallery_id);
         }
         $created_msg = sprintf(_n("Gallery <strong>%s</strong> successfully created!", 'Galleries <strong>%s</strong> successfully created!', 1, 'nggallery'), esc_html($galleryname));
     }
     // Look for existing image list
     $old_imageslist = $wpdb->get_col("SELECT filename FROM {$wpdb->nggpictures} WHERE galleryid = '{$gallery_id}' ");
     // if no images are there, create empty array
     if ($old_imageslist == NULL) {
         $old_imageslist = array();
     }
     // check difference
     $new_images = array_diff($new_imageslist, $old_imageslist);
     // all images must be valid files
     foreach ($new_images as $key => $picture) {
         // filter function to rename/change/modify image before
         $picture = apply_filters('ngg_pre_add_new_image', $picture, $gallery_id);
         $new_images[$key] = $picture;
         if (!@getimagesize($gallerypath . '/' . $picture)) {
             unset($new_images[$key]);
             @unlink($gallerypath . '/' . $picture);
         }
     }
     // add images to database
     $image_ids = nggAdmin::add_Images($gallery_id, $new_images);
     do_action('ngg_after_new_images_added', $gallery_id, $image_ids);
     //add the preview image if needed
     nggAdmin::set_gallery_preview($gallery_id);
     // now create thumbnails
     nggAdmin::do_ajax_operation('create_thumbnail', $image_ids, __('Create new thumbnails', 'nggallery'));
     //TODO:Message will not shown, because AJAX routine require more time, message should be passed to AJAX
     $message = $created_msg . sprintf(_n('%s picture successfully added', '%s pictures successfully added', count($image_ids), 'nggallery'), count($image_ids));
     $message .= ' [<a href="' . admin_url() . 'admin.php?page=nggallery-manage-gallery&mode=edit&gid=' . $gallery_id . '" >';
     $message .= __('Edit gallery', 'nggallery');
     $message .= '</a>]';
     nggGallery::show_message($message);
     return;
 }
开发者ID:kixortillan,项目名称:dfosashworks,代码行数:84,代码来源:functions.php

示例2: upload_images

 /**
  * Function for uploading of images via the upload form
  * 
  * @class nggAdmin
  * @return void
  */
 function upload_images()
 {
     global $nggdb;
     // WPMU action
     if (nggWPMU::check_quota()) {
         return;
     }
     // Images must be an array
     $imageslist = array();
     // get selected gallery
     $galleryID = (int) $_POST['galleryselect'];
     if ($galleryID == 0) {
         nggGallery::show_error(__('No gallery selected !', 'nggallery'));
         return;
     }
     // get the path to the gallery
     $gallery = $nggdb->find_gallery($galleryID);
     if (empty($gallery->path)) {
         nggGallery::show_error(__('Failure in database, no gallery path set !', 'nggallery'));
         return;
     }
     // read list of images
     $dirlist = nggAdmin::scandir($gallery->abspath);
     $imagefiles = $_FILES['imagefiles'];
     if (is_array($imagefiles)) {
         foreach ($imagefiles['name'] as $key => $value) {
             // look only for uploded files
             if ($imagefiles['error'][$key] == 0) {
                 $temp_file = $imagefiles['tmp_name'][$key];
                 //clean filename and extract extension
                 $filepart = nggGallery::fileinfo($imagefiles['name'][$key]);
                 $filename = $filepart['basename'];
                 // check for allowed extension and if it's an image file
                 $ext = array('jpg', 'png', 'gif');
                 if (!in_array($filepart['extension'], $ext) || !@getimagesize($temp_file)) {
                     nggGallery::show_error('<strong>' . $imagefiles['name'][$key] . ' </strong>' . __('is no valid image file!', 'nggallery'));
                     continue;
                 }
                 // check if this filename already exist in the folder
                 $i = 0;
                 while (in_array($filename, $dirlist)) {
                     $filename = $filepart['filename'] . '_' . $i++ . '.' . $filepart['extension'];
                 }
                 $dest_file = $gallery->abspath . '/' . $filename;
                 //check for folder permission
                 if (!is_writeable($gallery->abspath)) {
                     $message = sprintf(__('Unable to write to directory %s. Is this directory writable by the server?', 'nggallery'), $gallery->abspath);
                     nggGallery::show_error($message);
                     return;
                 }
                 // save temp file to gallery
                 if (!@move_uploaded_file($temp_file, $dest_file)) {
                     nggGallery::show_error(__('Error, the file could not be moved to : ', 'nggallery') . $dest_file);
                     nggAdmin::check_safemode($gallery->abspath);
                     continue;
                 }
                 if (!nggAdmin::chmod($dest_file)) {
                     nggGallery::show_error(__('Error, the file permissions could not be set', 'nggallery'));
                     continue;
                 }
                 // add to imagelist & dirlist
                 $imageslist[] = $filename;
                 $dirlist[] = $filename;
             }
         }
     }
     if (count($imageslist) > 0) {
         // add images to database
         $image_ids = nggAdmin::add_Images($galleryID, $imageslist);
         //create thumbnails
         nggAdmin::do_ajax_operation('create_thumbnail', $image_ids, __('Create new thumbnails', 'nggallery'));
         //add the preview image if needed
         nggAdmin::set_gallery_preview($galleryID);
         nggGallery::show_message(count($image_ids) . __(' Image(s) successfully added', 'nggallery'));
     }
     return;
 }
开发者ID:ahsaeldin,项目名称:projects,代码行数:83,代码来源:functions.php

示例3: upload_images

 function upload_images()
 {
     // upload of pictures
     global $wpdb;
     // WPMU action
     if (nggAdmin::check_quota()) {
         return;
     }
     // Images must be an array
     $imageslist = array();
     // get selected gallery
     $galleryID = (int) $_POST['galleryselect'];
     if ($galleryID == 0) {
         nggGallery::show_error(__('No gallery selected !', 'nggallery'));
         return;
     }
     // get the path to the gallery
     $gallerypath = $wpdb->get_var("SELECT path FROM {$wpdb->nggallery} WHERE gid = '{$galleryID}' ");
     if (!$gallerypath) {
         nggGallery::show_error(__('Failure in database, no gallery path set !', 'nggallery'));
         return;
     }
     // read list of images
     $dirlist = nggAdmin::scandir(WINABSPATH . $gallerypath);
     foreach ($_FILES as $key => $value) {
         // look only for uploded files
         if ($_FILES[$key]['error'] == 0) {
             $temp_file = $_FILES[$key]['tmp_name'];
             $filepart = pathinfo(strtolower($_FILES[$key]['name']));
             // required until PHP 5.2.0
             $filepart['filename'] = substr($filepart["basename"], 0, strlen($filepart["basename"]) - (strlen($filepart["extension"]) + 1));
             $filename = sanitize_title($filepart['filename']) . '.' . $filepart['extension'];
             // check for allowed extension
             $ext = array('jpeg', 'jpg', 'png', 'gif');
             if (!in_array($filepart['extension'], $ext)) {
                 nggGallery::show_error('<strong>' . $_FILES[$key]['name'] . ' </strong>' . __('is no valid image file!', 'nggallery'));
                 continue;
             }
             // check if this filename already exist in the folder
             $i = 0;
             while (in_array($filename, $dirlist)) {
                 $filename = sanitize_title($filepart['filename']) . '_' . $i++ . '.' . $filepart['extension'];
             }
             $dest_file = WINABSPATH . $gallerypath . '/' . $filename;
             //check for folder permission
             if (!is_writeable(WINABSPATH . $gallerypath)) {
                 $message = sprintf(__('Unable to write to directory %s. Is this directory writable by the server?', 'nggallery'), WINABSPATH . $gallerypath);
                 nggGallery::show_error($message);
                 return;
             }
             // save temp file to gallery
             if (!@move_uploaded_file($_FILES[$key]['tmp_name'], $dest_file)) {
                 nggGallery::show_error(__('Error, the file could not moved to : ', 'nggallery') . $dest_file);
                 nggAdmin::check_safemode(WINABSPATH . $gallerypath);
                 continue;
             }
             if (!nggAdmin::chmod($dest_file)) {
                 nggGallery::show_error(__('Error, the file permissions could not set', 'nggallery'));
                 continue;
             }
             // add to imagelist & dirlist
             $imageslist[] = $filename;
             $dirlist[] = $filename;
         }
     }
     if (count($imageslist) > 0) {
         // add images to database
         $image_ids = nggAdmin::add_Images($galleryID, $imageslist);
         //create thumbnails
         nggAdmin::do_ajax_operation('create_thumbnail', $image_ids, __('Create new thumbnails', 'nggallery'));
         //add the preview image if needed
         nggAdmin::set_gallery_preview($galleryID);
         nggGallery::show_message(count($image_ids) . __(' Image(s) successfully added', 'nggallery'));
     }
     return;
 }
开发者ID:pravinhirmukhe,项目名称:flow1,代码行数:76,代码来源:functions.php


注:本文中的nggAdmin::set_gallery_preview方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。