本文整理汇总了PHP中nggdb::add_gallery方法的典型用法代码示例。如果您正苦于以下问题:PHP nggdb::add_gallery方法的具体用法?PHP nggdb::add_gallery怎么用?PHP nggdb::add_gallery使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nggdb
的用法示例。
在下文中一共展示了nggdb::add_gallery方法的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`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;
}
示例2: create_gallery
/**
* create a new gallery & folder
*
* @class nggAdmin
* @param string $name of the gallery
* @param string $defaultpath
* @param bool $output if the function should show an error messsage or not
* @return
*/
function create_gallery($title, $defaultpath, $output = true)
{
global $user_ID;
// get the current user ID
get_currentuserinfo();
//cleanup pathname
$name = sanitize_file_name(sanitize_title($title));
$name = apply_filters('ngg_gallery_name', $name);
$nggRoot = WINABSPATH . $defaultpath;
$txt = '';
// No gallery name ?
if (empty($name)) {
if ($output) {
nggGallery::show_error(__('No valid gallery name!', 'nggallery'));
}
return false;
}
// check for main folder
if (!is_dir($nggRoot)) {
if (!wp_mkdir_p($nggRoot)) {
$txt = __('Directory', 'nggallery') . ' <strong>' . $defaultpath . '</strong> ' . __('didn\'t exist. Please create first the main gallery folder ', 'nggallery') . '!<br />';
$txt .= __('Check this link, if you didn\'t know how to set the permission :', 'nggallery') . ' <a href="http://codex.wordpress.org/Changing_File_Permissions">http://codex.wordpress.org/Changing_File_Permissions</a> ';
if ($output) {
nggGallery::show_error($txt);
}
return false;
}
}
// check for permission settings, Safe mode limitations are not taken into account.
if (!is_writeable($nggRoot)) {
$txt = __('Directory', 'nggallery') . ' <strong>' . $defaultpath . '</strong> ' . __('is not writeable !', 'nggallery') . '<br />';
$txt .= __('Check this link, if you didn\'t know how to set the permission :', 'nggallery') . ' <a href="http://codex.wordpress.org/Changing_File_Permissions">http://codex.wordpress.org/Changing_File_Permissions</a> ';
if ($output) {
nggGallery::show_error($txt);
}
return false;
}
// 1. Check for existing folder
if (is_dir(WINABSPATH . $defaultpath . $name)) {
$suffix = 1;
do {
$alt_name = substr($name, 0, 200 - (strlen($suffix) + 1)) . "_{$suffix}";
$dir_check = is_dir(WINABSPATH . $defaultpath . $alt_name);
$suffix++;
} while ($dir_check);
$name = $alt_name;
}
// define relative path to gallery inside wp root folder
$nggpath = $defaultpath . $name;
// 2. Create new gallery folder
if (!wp_mkdir_p(WINABSPATH . $nggpath)) {
$txt = __('Unable to create directory ', 'nggallery') . $nggpath . '!<br />';
}
// 3. Check folder permission
if (!is_writeable(WINABSPATH . $nggpath)) {
$txt .= __('Directory', 'nggallery') . ' <strong>' . $nggpath . '</strong> ' . __('is not writeable !', 'nggallery') . '<br />';
}
// 4. Now create thumbnail folder inside
if (!is_dir(WINABSPATH . $nggpath . '/thumbs')) {
if (!wp_mkdir_p(WINABSPATH . $nggpath . '/thumbs')) {
$txt .= __('Unable to create directory ', 'nggallery') . ' <strong>' . $nggpath . '/thumbs !</strong>';
}
}
if (SAFE_MODE) {
$help = __('The server setting Safe-Mode is on !', 'nggallery');
$help .= '<br />' . __('If you have problems, please create directory', 'nggallery') . ' <strong>' . $nggpath . '</strong> ';
$help .= __('and the thumbnails directory', 'nggallery') . ' <strong>' . $nggpath . '/thumbs</strong> ' . __('with permission 777 manually !', 'nggallery');
if ($output) {
nggGallery::show_message($help);
}
}
// show a error message
if (!empty($txt)) {
if (SAFE_MODE) {
// for safe_mode , better delete folder, both folder must be created manually
@rmdir(WINABSPATH . $nggpath . '/thumbs');
@rmdir(WINABSPATH . $nggpath);
}
if ($output) {
nggGallery::show_error($txt);
}
return false;
}
// now add the gallery to the database
$galleryID = nggdb::add_gallery($title, $nggpath, '', 0, 0, $user_ID);
// here you can inject a custom function
do_action('ngg_created_new_gallery', $galleryID);
// return only the id if defined
if ($output == false) {
return $galleryID;
}
//.........这里部分代码省略.........
示例3: old_import_gallery
/**
* nggAdmin::old_import_gallery()
* TODO: Check permission of existing thumb folder & images
* Use is not recommended!
*
* @class nggAdmin
* @param string $galleryfolder contains relative path to the gallery itself
* @return void
*/
static function old_import_gallery($galleryfolder)
{
global $wpdb, $user_ID;
// get the current user ID
get_currentuserinfo();
$created_msg = '';
// remove trailing slash at the end, if somebody use it
$galleryfolder = untrailingslashit($galleryfolder);
$gallerypath = WINABSPATH . $galleryfolder;
if (!is_dir($gallerypath)) {
nggGallery::show_error(__('Directory', 'nggallery') . ' <strong>' . esc_html($gallerypath) . '</strong> ' . __('doesn`t exist!', 'nggallery'));
return;
}
// read list of images
$new_imageslist = nggAdmin::scandir($gallerypath);
if (empty($new_imageslist)) {
nggGallery::show_message(__('Directory', 'nggallery') . ' <strong>' . esc_html($gallerypath) . '</strong> ' . __('contains no pictures', 'nggallery'));
return;
}
// check & create thumbnail folder
if (!nggGallery::get_thumbnail_folder($gallerypath)) {
return;
}
// take folder name as gallery name
$galleryname = basename($galleryfolder);
$galleryname = apply_filters('ngg_gallery_name', $galleryname);
// check for existing gallery folder
$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;
}
$created_msg = __('Gallery', 'nggallery') . ' <strong>' . esc_html($galleryname) . '</strong> ' . __('successfully created!', 'nggallery') . '<br />';
}
// 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);
//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 . count($image_ids) . __(' picture(s) successfully added', 'nggallery');
$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;
}