xml_load_file($file);
}
function simplexml_load_string($string) {
$sx = new SimpleXML;
return $sx->xml_load_string($string);
}
} else {
define('FGALLERY_PHP4_MODE', 0);
}
global $wpdb;
// DENY direct access to the file
if(preg_match('#' . basename(__FILE__) . '#', $_SERVER['PHP_SELF'])) {
die('You are not allowed to call this page directly.');
}
$siteurl = get_option('siteurl');
$extra_dir = str_replace($_SERVER['HTTP_HOST'],'',$siteurl);
$extra_dir = str_replace('http://','',$extra_dir);
//define table names and constants
define('FGALLERY_VERSION','1.2.6');
define('EXTRA_DIR',$extra_dir.'/');
define('ALBUMS_TABLE', $wpdb->prefix . "fgallery_albums");
define('IMAGES_TABLE', $wpdb->prefix . "fgallery_images");
define('IMAGES_TO_ALBUMS_TABLE', $wpdb->prefix . "fgallery_album_images");
define('ALBUMS_SETTINGS_TABLE', $wpdb->prefix . "fgallery_albums_settings");
define('FGALLERY_PATH', WP_PLUGIN_URL.'/'.basename(dirname(__FILE__)));
define('FGALLERY_ABSPATH', ABSPATH.'/wp-content/plugins/'.basename(dirname(__FILE__)));
define('FGALLERY_DIR', ABSPATH . 'wp-content/uploads/fgallery');
define('COVER_PATH',WP_PLUGIN_URL.'/'.basename(dirname(__FILE__)).'/image.php/cover.jpg?width=200&image='.EXTRA_DIR);
define('THUMB_PATH',WP_PLUGIN_URL.'/'.basename(dirname(__FILE__)).'/image.php/cover.jpg?width=600&image='.EXTRA_DIR);
define('MUSIC_PATH','musicPath');
define('FGALLERY_APP_ID','101920689894773');
define('FGALLERY_FB_PATH','http://test.1plugin.com/facebook/index.php');
//registering install and uninstall hooks
register_activation_hook(__FILE__,'fgallery_install');
if (function_exists('register_update_hook')) {
register_update_hook(__FILE__,'fgallery_update');
}
register_uninstall_hook(__FILE__,'fgallery_uninstall');
//localizations
$plugin_dir = basename(dirname(__FILE__)).'/languages/';
load_plugin_textdomain( 'fgallery', null, $plugin_dir );
// installation script
function fgallery_install() {
global $wpdb;
global $wp_filesystem;
//add option for screen options (number of elements per page)
add_option('1_flash_gallery_page_fgallery_images_per_page', '25', '', 'no');
add_option('toplevel_page_fgallery_per_page', '25', '', 'no');
add_option('1_flash_gallery_watermark_enabled','0','','no');
add_option('1_flash_gallery_watermark_path','','','no');
add_option('1_flash_gallery_watermark_place','','','no');
if($wpdb->get_var("SHOW TABLES LIKE '" . ALBUMS_TABLE . "'") != ALBUMS_TABLE) {
add_option("fgallery_db_version", FGALLERY_VERSION);
// create albums table
$create_albums = "CREATE TABLE " . ALBUMS_TABLE . " (
`gall_id` int(11) NOT NULL auto_increment,
`gall_name` varchar(255) collate utf8_unicode_ci NOT NULL,
`gall_description` text collate utf8_unicode_ci NULL default NULL,
`gall_cover` int(11) default '0',
`gall_createddate` datetime NOT NULL,
`gall_createdby` int(11) NOT NULL,
`gall_published` tinyint(1) default 1,
`gall_width` int(11) default '450',
`gall_height` int(11) default '385',
`gall_bgcolor` varchar(6) default 'ffffff',
`gall_type` smallint(3) default '3',
`gall_order` int(11) NOT NULL,
PRIMARY KEY (`gall_id`)
);" ;
require_once(ABSPATH . 'wp-admin/upgrade-functions.php');
dbDelta($create_albums);
}
if($wpdb->get_var("SHOW TABLES LIKE '" . IMAGES_TABLE . "'") != IMAGES_TABLE) {
// create images table
$create_images = "CREATE TABLE " . IMAGES_TABLE . " (
`img_id` int(11) NOT NULL auto_increment,
`img_caption` varchar(255) collate utf8_unicode_ci NULL,
`img_description` text collate utf8_unicode_ci NULL,
`img_date` datetime NOT NULL,
`img_type` varchar(50) collate utf8_unicode_ci default '',
`img_size` int(11) default '0',
`img_path` varchar(255) collate utf8_unicode_ci default '',
`img_vs_folder` smallint(5) default '0',
`img_parent` int(11) default '0',
PRIMARY KEY (`img_id`)
)";
require_once(ABSPATH . 'wp-admin/upgrade-functions.php');
dbDelta($create_images);
}
if($wpdb->get_var("SHOW TABLES LIKE '" . IMAGES_TO_ALBUMS_TABLE . "'") != IMAGES_TO_ALBUMS_TABLE) {
// create table for relation between images and albums
$create_albums_images = "CREATE TABLE " . IMAGES_TO_ALBUMS_TABLE . " (
`img_id` int(11) NOT NULL,
`gall_id` int(11) NOT NULL,
`gall_folder` int(11) default 0,
`img_order` smallint(5) default 0,
`img_url` varchar(255) collate utf8_unicode_ci NULL,
PRIMARY KEY (`img_id`, `gall_id`)
)";
require_once(ABSPATH . 'wp-admin/upgrade-functions.php');
dbDelta($create_albums_images);
}
$version = get_option('fgallery_db_version', 0);
if (version_compare($version, '1.0.7', '<')) {
$wpdb->query("ALTER TABLE `".IMAGES_TO_ALBUMS_TABLE."` ADD `img_url` VARCHAR( 255 ) collate utf8_unicode_ci NULL AFTER `img_order` ;");
}
if (version_compare($version, '1.2.2', '<')) {
$array = array('acosta','airion','arai','pax','pazin','postma','pageflip','nilus');
foreach ($array as $key=>$value) {
$temp = get_option('1_flash_gallery_'.$value);
if ($temp) {
$option = substr($temp, 1, 9);
update_option('1_flash_gallery_'.$value, $option);
}
}
$wpdb->query("ALTER TABLE `".IMAGES_TO_ALBUMS_TABLE."` CHANGE `gall_folder` `gall_folder` int( 11 ) default 0 ;");
$wpdb->query("ALTER TABLE `".IMAGES_TO_ALBUMS_TABLE."` CHANGE `img_order` `img_order` int( 11 ) default 0 ;");
$wpdb->query("ALTER TABLE `".IMAGES_TABLE."` CHANGE `img_parent` `img_parent` int( 11 ) default 0 ;");
$wpdb->query("ALTER TABLE `".IMAGES_TABLE."` CHANGE `img_vs_folder` `img_vs_folder` int( 11 ) default 0 ;");
$wpdb->query("ALTER TABLE `".IMAGES_TABLE."` CHANGE `img_size` `img_size` int( 11 ) default 0 ;");
$wpdb->query("ALTER TABLE `".IMAGES_TABLE."` CHANGE `img_type` `img_type` varchar(50) collate utf8_unicode_ci default '' ;");
$wpdb->query("ALTER TABLE `".IMAGES_TABLE."` CHANGE `img_path` `img_path` varchar(50) collate utf8_unicode_ci default '' ;");
$wpdb->query("ALTER TABLE `".ALBUMS_TABLE."` CHANGE `gall_cover` `gall_cover` int(11) default 0 ;");
$wpdb->query("ALTER TABLE `".ALBUMS_TABLE."` CHANGE `gall_description` `gall_description` text collate utf8_unicode_ci ;");
}
if($wpdb->get_var("SHOW TABLES LIKE '" . ALBUMS_SETTINGS_TABLE . "'") != ALBUMS_SETTINGS_TABLE) {
// create table for albums settings
$albums_settings = "CREATE TABLE " . ALBUMS_SETTINGS_TABLE . " (
`gall_id` int(11) NOT NULL,
`value` text NOT NULL,
PRIMARY KEY (`gall_id`)
)";
require_once(ABSPATH . 'wp-admin/upgrade-functions.php');
dbDelta($albums_settings);
}
update_option("fgallery_db_version", FGALLERY_VERSION);
// try to make gallery dir if not exists
if (!is_dir(FGALLERY_DIR)) {
WP_Filesystem();
@ mkdir(FGALLERY_DIR);
@ mkdir(FGALLERY_DIR.'/tmp');
@ chmod(FGALLERY_ABSPATH,'/imagecache', 777);
}
return true;
}
function fgallery_update() {
$version = get_option('fgallery_db_version', 0);
if (version_compare($version, '1.0.7', '<')) {
$wpdb->query("ALTER TABLE `".IMAGES_TO_ALBUMS_TABLE."` ADD `img_url` VARCHAR( 255 ) collate utf8_unicode_ci NULL AFTER `img_order` ;");
}
if (version_compare($version, '1.2.2', '<')) {
$array = array('acosta','airion','arai','pax','pazin','postma','pageflip','nilus');
foreach ($array as $key=>$value) {
$temp = get_option('1_flash_gallery_'.$value);
if ($temp) {
$option = substr($temp, 1, 9);
update_option('1_flash_gallery_'.$value, $option);
}
}
$wpdb->query("ALTER TABLE `".IMAGES_TO_ALBUMS_TABLE."` CHANGE `gall_folder` `gall_folder` int( 11 ) default 0 ;");
$wpdb->query("ALTER TABLE `".IMAGES_TO_ALBUMS_TABLE."` CHANGE `img_order` `img_order` int( 11 ) default 0 ;");
$wpdb->query("ALTER TABLE `".IMAGES_TABLE."` CHANGE `img_parent` `img_parent` int( 11 ) default 0 ;");
$wpdb->query("ALTER TABLE `".IMAGES_TABLE."` CHANGE `img_vs_folder` `img_vs_folder` int( 11 ) default 0 ;");
$wpdb->query("ALTER TABLE `".IMAGES_TABLE."` CHANGE `img_size` `img_size` int( 11 ) default 0 ;");
$wpdb->query("ALTER TABLE `".IMAGES_TABLE."` CHANGE `img_type` `img_type` varchar(50) collate utf8_unicode_ci default '' ;");
$wpdb->query("ALTER TABLE `".IMAGES_TABLE."` CHANGE `img_path` `img_path` varchar(50) collate utf8_unicode_ci default '' ;");
$wpdb->query("ALTER TABLE `".ALBUMS_TABLE."` CHANGE `gall_cover` `gall_cover` int(11) default 0 ;");
$wpdb->query("ALTER TABLE `".ALBUMS_TABLE."` CHANGE `gall_description` `gall_description` text collate utf8_unicode_ci ;");
}
if (version_compare($version, '1.2.4', '<')) {
add_option('1_flash_gallery_watermark_enabled','0','','no');
add_option('1_flash_gallery_watermark_path','','','no');
add_option('1_flash_gallery_watermark_place','','','no');
}
update_option("fgallery_db_version", FGALLERY_VERSION);
return true;
}
// function that recursively removes directory and all files in it
function fgallery_delete_dir($path) {
$files = glob("$path/*");
foreach($files as $file) {
if(is_dir($file) && !is_link($file)) {
fgallery_delete_dir($file);
} else {
unlink($file);
}
}
rmdir($path);
}
// uninstall script
function fgallery_uninstall() {
global $wpdb;
require_once(ABSPATH . 'wp-admin/upgrade-functions.php');
//drop tables after uninstall
dbDelta("DROP TABLE ". ALBUMS_TABLE);
dbDelta("DROP TABLE ". PHOTOS_TABLE);
dbDelta("DROP TABLE ". IMAGES_TO_ALBUMS_TABLE);
dbDelta("DROP TABLE ". ALBUMS_SETTINGS_TABLE);
//remove gallery directory
fgallery_delete_dir(FGALLERY_DIR);
return true;
}
function fgallery_get_current_user_role() {
global $current_user;
$user_roles = $current_user->roles;
$user_role = array_shift($user_roles);
return $user_role;
}
// defines the current user access level
function fgallery_access_level(){
$role = fgallery_get_current_user_role();
switch ($role) {
case 'administrator':
return 10;
case 'editor':
return 7;
case 'author':
return 2;
default:
return 2;
}
}
// initialization script
function fgallery_init() {
global $wp_version;
wp_register_script('uploadify', FGALLERY_PATH.'/js/uploadify/jquery.uploadify.v2.1.4.min.js',array('jquery'));
wp_register_script('uploadjs', FGALLERY_PATH.'/js/fgallery_upload.js',array('jquery'));
wp_register_script('fgalleryedit', FGALLERY_PATH.'/js/fgallery_edit.js',array('jquery'));
wp_register_script('fgalleryjs', FGALLERY_PATH.'/js/fgallery.js',array('jquery'));
wp_register_script('fgalleryimages', FGALLERY_PATH.'/js/fgallery_images.js',array('jquery'));
wp_register_script('configurator', FGALLERY_PATH.'/js/configurator.js',array('jquery'));
if ( version_compare( $wp_version, '3.1', '>=' ) ) {
wp_register_script('uislider', FGALLERY_PATH.'/js/ui.slider31.js',array('jquery','jquery-ui-core'));// some code
} else {
wp_register_script('uislider', FGALLERY_PATH.'/js/ui.slider.js',array('jquery','jquery-ui-core'));
}
wp_register_script('copytoclipboard', FGALLERY_PATH.'/js/ZeroClipboard.js',array('jquery'));
wp_register_script('copypref', FGALLERY_PATH.'/js/copy.js',array('jquery'));
wp_register_script('swfhelper', FGALLERY_PATH. '/js/swfhelper.js',array('jquery'));
wp_register_style('uploadifycss', FGALLERY_PATH. '/css/uploadify.css');
wp_register_style('uislidercss', FGALLERY_PATH. '/css/ui.slider.css');
wp_register_style('uithemecss', FGALLERY_PATH. '/css/ui.theme.css');
wp_register_style('uitabscss', FGALLERY_PATH. '/css/ui.tabs.css');
wp_register_style('configuratorcss', FGALLERY_PATH. '/css/configurator.css');
wp_register_style('farbtasticcss', FGALLERY_PATH. '/css/farbtastic.css');
wp_register_style('fgallerycss', FGALLERY_PATH. '/css/fgallery.css');
//needed for flash embeding
wp_enqueue_script('swfobject');
wp_enqueue_script('thickbox');
wp_enqueue_script('swfhelper');
wp_enqueue_style('thickbox');
// building menu items
add_action('admin_menu', 'fgallery_add_pages');
}
add_action('init', 'fgallery_init');
// calls scripts for upload page
function fgallery_upload_scripts(){
wp_enqueue_script('jquery-ui-tabs');
wp_enqueue_script('uploadjs');
wp_enqueue_script('uploadify');
wp_enqueue_script('jquery-form');
}
// calls scripts for gallery index/add/edit pages
function fgallery_admin_scripts() {
global $wp_version;
wp_enqueue_script('jquery-form');
if ($_GET['action'] == 'edit' || $_GET['page'] == 'fgallery_add') {
wp_enqueue_script('farbtastic');
wp_enqueue_script('configurator');
wp_enqueue_script('jquery-ui-tabs');
wp_enqueue_script('uislider');
wp_enqueue_script('copytoclipboard');
wp_enqueue_script('copypref');
}
if ($_GET['action'] == 'pref') {
wp_enqueue_script('copytoclipboard');
wp_enqueue_script('copypref');
}
if ($_GET['action'] == 'images') {
wp_enqueue_script('jquery-color');
}
wp_enqueue_script('fgalleryedit');
wp_enqueue_script('jquery-ui-sortable');
wp_enqueue_script('fgalleryjs');
}
// calls scripts for images index/add/edit pages
function fgallery_admin_images_scripts(){
wp_enqueue_script('jquery-ui-droppable');
wp_enqueue_script('jquery-ui-draggable');
wp_enqueue_script('fgalleryimages');
}
// calls css files for upload page
function fgallery_upload_styles() {
wp_enqueue_style('uploadifycss');
wp_enqueue_style('fgallerycss');
wp_enqueue_style('uitabscss');
wp_enqueue_style('uithemecss');
}
// calls css files for upload page
function fgallery_images_styles() {
wp_enqueue_style('fgallerycss');
}
// calls css files for upload page
function fgallery_watermark_styles() {
wp_enqueue_style('fgallerycss');
}
// calls css files for upload page
function fgallery_admin_styles() {
wp_enqueue_style('fgallerycss');
wp_enqueue_style('uitabscss');
wp_enqueue_style('uithemecss');
wp_enqueue_style('uislidercss');
wp_enqueue_style('farbtasticcss');
wp_enqueue_style('configuratorcss');
}
// adding items to menu
function fgallery_add_pages() {
$pref = add_menu_page(__('1 Flash Gallery','fgallery'), __('1 Flash Gallery', 'fgallery'), 'upload_files', 'fgallery', 'fgallery_admin_albums');
if ( function_exists('add_submenu_page') ) {
$main = add_submenu_page('fgallery', __('Galleries List','fgallery'), __('Galleries List','fgallery'), 'upload_files', 'fgallery', 'fgallery_admin_albums');
$add = add_submenu_page('fgallery', __('Create gallery','fgallery'), __('Create Gallery','fgallery'), 'upload_files', 'fgallery_add', 'fgallery_add_gallery');
$images = add_submenu_page('fgallery', __('Images List','fgallery'), __('Images List','fgallery'), 'upload_files', 'fgallery_images', 'fgallery_images_page');
$upload = add_submenu_page('fgallery', __('Upload images','fgallery'), __('Upload Images','fgallery'), 'upload_files', 'fgallery_upload', 'fgallery_upload_page');
$watermark = add_submenu_page('fgallery', __('Watermark','fgallery'), __('Watermark','fgallery'), 'upload_files', 'fgallery_watermark', 'fgallery_watermark_page');
}
add_action('admin_print_scripts-' . $upload, 'fgallery_upload_scripts');
add_action('admin_print_scripts-' . $main, 'fgallery_admin_scripts');
add_action('admin_print_scripts-' . $add, 'fgallery_admin_scripts');
add_action('admin_print_scripts-' . $images, 'fgallery_admin_images_scripts');
add_action('admin_print_styles-' . $upload, 'fgallery_upload_styles' );
add_action('admin_print_styles-' . $images, 'fgallery_images_styles' );
add_action('admin_print_styles-' . $main, 'fgallery_admin_styles' );
add_action('admin_print_styles-' . $add, 'fgallery_admin_styles' );
add_action('admin_print_styles-' . $watermark, 'fgallery_watermark_styles' );
}
/*
* Starting admin pages render
*
*/
function fgallery_upload_page() {
$nextgen = false;
if (plugin_is_active('nextgen-gallery/nggallery.php')) {
$nextgen = true;
}
$folders = fgallery_get_folders();
?>
'attachment','post_mime_type'=>'image','numberposts'=>999999999);
$images = get_posts($args);
?>
'.__("Folder", 'fagllery').' wp-content/uploads/fgallery '.__("doesn't exist", 'fagllery').'';
} elseif (!is_writeable(FGALLERY_DIR)) {
echo '
'.__("Folder", 'fagllery').' wp-content/uploads/fgallery '.__("is not writable", 'fagllery').'
';
}
_e('Note: Important! If single image is more then 1Mb galleries may work slower', 'fgallery');?>
guid).'" alt="'.$image->post_title.'" />';
?>
post_title?>
path.'/thumbs/thumbs_'.$image->filename.'" alt="'.$image->image_slug.'" />';
?>
image_slug?>
'.__('Server Name:', 'fagllery').' '.$_SERVER['SERVER_NAME']."";
echo '
'.__('Document Root:', 'fagllery').' '.$_SERVER['DOCUMENT_ROOT']."
";
echo '
'.__('Web server:', 'fagllery').' '.$_SERVER['SERVER_SOFTWARE']."
";
echo '
'.__('Host:', 'fagllery').' '.$_SERVER['HTTP_HOST']."
";
echo '
'.__('Client Agent:', 'fagllery').' '.$_SERVER['HTTP_USER_AGENT']."
";
echo '
'.__('Word Press version:', 'fagllery').' '.$wp_version;
echo '
'.__('Plugin version:', 'fagllery').' '.FGALLERY_VERSION;
echo '
'.__('Max size of uploaded file:', 'fagllery').' '.ini_get('upload_max_filesize').'
';
if (!is_dir(FGALLERY_DIR)) {
echo '
'.__("Folder", 'fagllery').' wp-content/uploads/fgallery '.__("doesn't exist", 'fagllery').'
';
} elseif (!is_writeable(FGALLERY_DIR)) {
echo '
'.__("Folder", 'fagllery').' wp-content/uploads/fgallery '.__("is not writable", 'fagllery').'
';
}
if (!is_dir(FGALLERY_DIR.'/tmp')) {
echo '
'.__("Folder", 'fagllery').' wp-content/uploads/fgallery/tmp '.__("doesn't exist", 'fagllery').'
';
} elseif (!is_writeable(FGALLERY_DIR.'/tmp')) {
echo '
'.__("Folder", 'fagllery').' wp-content/uploads/fgallery/tmp '.__("is not writable", 'fagllery').'
';
}
if (!is_dir(ABSPATH . 'wp-content/plugins/'.basename(dirname(__FILE__)) .'/imagecache') || !is_writeable(ABSPATH . 'wp-content/plugins/'.basename(dirname(__FILE__)) .'/imagecache')) {
echo '
'.__("Folder", 'fagllery').' wp-content/plugins/'.basename(dirname(__FILE__)) .'/imagecache '.__("is not writable", 'fagllery').'
';
}
?>
'.__('Copy settings to clipboard', 'fagllery').'';?>
';
$updated = true;
}
if (get_option('1_flash_gallery_airion') != '') {
echo '1 Flash Gallery Update Airion
';
$updated = true;
}
if (get_option('1_flash_gallery_arai') != '') {
echo '1 Flash Gallery Update Arai
';
$updated = true;
}
if (get_option('1_flash_gallery_pax') != '') {
echo '1 Flash Gallery Update Pax
';
$updated = true;
}
if (get_option('1_flash_gallery_pazin') != '') {
echo '1 Flash Gallery Update Pazin
';
$updated = true;
}
if (get_option('1_flash_gallery_postma') != '') {
echo '1 Flash Gallery Update Postma
';
$updated = true;
}
if (get_option('1_flash_gallery_pageflip') != '') {
echo '1 Flash Gallery Update PageFlip
';
$updated = true;
}
if (get_option('1_flash_gallery_nilus') != '') {
echo '1 Flash Gallery Update Nilus
';
$updated = true;
}
if (get_option('1_flash_gallery_nusl') != '') {
echo '1 Flash Gallery Update Nusl
';
$updated = true;
}
if (!$updated) {
_e('There are no updates yet. You can get them at
1 Flash Gallery Wordpress Plugin Site ', 'fgallery');
}
?>
');
}
update_option('1_flash_gallery_watermark_path',$file_name);
}
update_option('1_flash_gallery_watermark_place',$_POST['wm_placement']);
}
$wm_enabled = get_option('1_flash_gallery_watermark_enabled');
$wm_path = get_option('1_flash_gallery_watermark_path');
$wm_place = get_option('1_flash_gallery_watermark_place');
?>
update(ALBUMS_TABLE, array('gall_order' => $order), array('gall_id' => $id));
}
die();
break;
default:
// -- pagination ------------
if (!empty($_POST) && wp_verify_nonce($_POST['screenoptionnonce'], 'screen-options-nonce')) {
update_option( $_POST['wp_screen_options']['option'], $_POST['wp_screen_options']['value']);
}
$pagenum = isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 0;
$sort_by = isset($_GET['sort']) ? absint($_GET['sort']) : 4;
if ( empty($pagenum) )
$pagenum = 1;
if ( empty( $per_page ) || $per_page < 1 )
$per_page = get_option('toplevel_page_fgallery_per_page',25);
apply_filters('toplevel_page_fgallery_per_page', $per_page);
$num_pages = ceil(fgallery_albums_count() / $per_page);
$page_links = paginate_links( array(
'base' => add_query_arg( 'paged', '%#%' ),
'format' => '',
'prev_text' => __('«'),
'next_text' => __('»'),
'total' => $num_pages,
'current' => $pagenum
));
// ---------------------------
$items = fgallery_get_albums($pagenum,$per_page, $sort_by); ?>
' . __( 'Displaying %s–%s of %s' ) . '%s',
number_format_i18n( ( $pagenum - 1 ) * $per_page + 1 ),
number_format_i18n( min( $pagenum * $per_page, $count_posts ) ),
number_format_i18n( $count_posts ),
$page_links
);
echo $page_links_text; ?>
$page_links_text
";
} ?>
';
echo '
';
$title = __('Add images', 'fgallery');
echo '
'.$title.' ';
$title = __('Create album', 'fgallery');
echo '
'.$title.' ';
if (!empty($images)){
echo fgallery_render_album_images($images, $id);
} else {
_e('There are no images in this gallery', 'fgallery');
}
echo '
';
}
// render edit gallery page
function fgallery_edit_album_page($id){
echo '';
$album = fgallery_get_album($id);
if (empty($album)) {
$album['gall_id'] = 0;
$album['gall_width'] = 450;
$album['gall_height'] = 385;
$album['gall_bgcolor'] = "ffffff";
$album['gall_type'] = 3;
}
if ($id != 0) {
echo '
'.__('Edit gallery', 'fgallery').' "'.$album['gall_name'].'" ';
} else {
echo '
'.__('Add new gallery', 'fgallery').' ';
}
echo '
';
echo '
';
}
// renders image edit page
function fgallery_edit_image_page($id){
echo '';
if ( !empty($_POST) && check_admin_referer('fgallery_edit','fgallery_edit_image_field') ) {
$save = fgallery_edit_image($_POST, $id);
if ($save) {
echo '
'.__('Image has been saved', 'fgallery').'
';
} else {
echo '
'.__('Image name cannot be empty', 'fgallery').'
';
}
}
$image = fgallery_get_image($id);
if ($image['img_vs_folder'] == 1) {
echo '
'.__('Edit folder', 'fgallery').' "'.$image['img_caption'].'" ';
} elseif ($image['img_vs_folder'] == 0) {
echo '
'.__('Edit image', 'fgallery').' "#'.$image['img_id'].' '.$image['img_caption'].'" ';
}
echo fgallery_render_edit_image_form($image);
if ($image['img_vs_folder'] == 0) {
echo '
';
}
echo '
';
}
// renders images index page
function fgallery_images_page() {
global $wpdb;
if (isset($_GET['action'])) {
$action = $_GET['action'];
}
switch ($action) {
case 'edit':
if (isset($_GET['id']) && is_numeric($_GET['id'])) {
$id = $_GET['id'];
fgallery_edit_image_page($id);
}
break;
case 'edit_album':
fgallery_edit_album_image($_POST);
die();
break;
case 'delete':
if (isset($_GET['id']) && is_numeric($_GET['id'])) {
$id = $_GET['id'];
fgallery_delete_image($id);
}
break;
case 'remove':
if (isset($_GET['id']) && isset($_GET['gall_id']) && is_numeric($_GET['id']) && is_numeric($_GET['gall_id'])) {
$id = $_GET['id'];
$gall_id = $_GET['gall_id'];
$wpdb->query("UPDATE ".IMAGES_TO_ALBUMS_TABLE." SET `gall_folder` = 0 WHERE `gall_folder` =".$id);
$wpdb->query("DELETE FROM ". IMAGES_TO_ALBUMS_TABLE. " WHERE img_id =".$id." AND gall_id = ".$gall_id);
}
break;
case 'cover':
if (isset($_GET['id']) && isset($_GET['gall_id']) && is_numeric($_GET['id']) && is_numeric($_GET['gall_id'])) {
$id = $_GET['id'];
$gall_id = $_GET['gall_id'];
$wpdb->update(ALBUMS_TABLE, array('gall_cover'=>$id), array('gall_id' => $gall_id));
}
break;
case 'sort':
if (isset($_GET['id']) && isset($_GET['gall_id']) && is_numeric($_GET['id']) && is_numeric($_GET['gall_id'])) {
$id = $_GET['id'];
$gall_id = $_GET['gall_id'];
$order = $_GET['order'];
$wpdb->update(IMAGES_TO_ALBUMS_TABLE, array('img_order' => $order), array('img_id' => $id, 'gall_id' => $gall_id));
}
break;
default:
// -- pagination ------------
if (!empty($_POST) && wp_verify_nonce($_POST['screenoptionnonce'], 'screen-options-nonce')) {
update_option( $_POST['wp_screen_options']['option'], $_POST['wp_screen_options']['value']);
}
$pagenum = isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 0;
$sort_by = isset($_GET['sort']) ? absint($_GET['sort']) : 3;
$folder = isset($_GET['folder']) ? absint($_GET['folder']) : 0;
if ($folder) {
$folder_name = fgallery_get_folder_name($folder);
}
if ( empty($pagenum) )
$pagenum = 1;
if ( empty( $per_page ) || $per_page < 1 )
$per_page = get_option('1_flash_gallery_page_fgallery_images_per_page',25);
apply_filters('1_flash_gallery_page_fgallery_images_per_page', $per_page);
$num_pages = ceil(fgallery_images_count($folder) / $per_page);
$page_links = paginate_links( array(
'base' => add_query_arg( 'paged', '%#%' ),
'format' => '',
'prev_text' => __('«'),
'next_text' => __('»'),
'total' => $num_pages,
'current' => $pagenum
));
// ---------------------------
$items = fgallery_get_images($pagenum,$per_page, $folder, $sort_by); ?>
' . __( 'Displaying %s–%s of %s' ) . '%s',
number_format_i18n( ( $pagenum - 1 ) * $per_page + 1 ),
number_format_i18n( min( $pagenum * $per_page, $count_posts ) ),
number_format_i18n( $count_posts ),
$page_links
);
echo $page_links_text; ?>
$page_links_text
";
} ?>
get_var("SELECT value FROM ".ALBUMS_SETTINGS_TABLE." WHERE gall_id = ".$gall_id);
if (empty($settings)) {
return fgallery_default_album_settings();
} else {
return unserialize($settings);
}
}
// saves the albums settings to db
function fgallery_save_album_settings($gall_id, $data) {
global $wpdb;
$res = $wpdb->get_row("SELECT * FROM ".ALBUMS_SETTINGS_TABLE." WHERE gall_id = ".$gall_id, ARRAY_A);
if (empty($res)) {
$wpdb->insert(ALBUMS_SETTINGS_TABLE, array('gall_id'=>$gall_id, 'value'=>serialize($data)));
} else {
$wpdb->update(ALBUMS_SETTINGS_TABLE, array('value'=>serialize($data)), array('gall_id'=>$gall_id));
}
return true;
}
// save changes to gallery into db
function fgallery_edit_album($data,$id) {
global $wpdb;
global $current_user;
$name = htmlentities($data['fgallery_name'], ENT_NOQUOTES, "UTF-8");
$desc = htmlentities($data['fgallery_description'], ENT_NOQUOTES, "UTF-8");
$published = $data['fgallery_status'];
$width = (int)$data['gall_width'];
if ($width == 0) $width = 450;
$height = (int)$data['gall_height'];
if ($height == 0) $height = 385;
$bgcolor = str_replace('#','',$data['gall_bgcolor']);
$type = $data['gall_type'];
if ($id == 0) {
$user_id = $current_user->ID;//get_current_user_id();
$max = $wpdb->get_var("SELECT MAX(`gall_order`) FROM ".ALBUMS_TABLE);
$wpdb->insert(ALBUMS_TABLE, array('gall_name' => $name, 'gall_description' => $desc, 'gall_createddate' => date("Y-m-d H:i:s"), 'gall_createdby' => $user_id, 'gall_published' => $published, 'gall_width'=>$width, 'gall_height'=> $height, 'gall_bgcolor'=> $bgcolor, 'gall_type'=> $type, 'gall_order' => $max + 1));
return $wpdb->insert_id;
}
if ($name != '') {
$wpdb->update(ALBUMS_TABLE, array('gall_name' => $name, 'gall_description' => $desc, 'gall_published' => $published, 'gall_width'=>$width, 'gall_height'=> $height, 'gall_bgcolor'=> $bgcolor, 'gall_type'=> $type), array('gall_id' => $id));
return $id;
} else {
return 0;
}
}
// save changes to image into db
function fgallery_edit_image($data,$id) {
global $wpdb;
$name = htmlentities($data['fgallery_image_caption'], ENT_NOQUOTES, "UTF-8");
$desc = htmlentities($data['fgallery_image_description'], ENT_NOQUOTES, "UTF-8");
if ($name != '') {
$wpdb->update(IMAGES_TABLE, array('img_caption' => $name, 'img_description' => $desc), array('img_id' => $id));
return 1;
} else {
return 0;
}
}
function fgallery_edit_album_image($data) {
global $wpdb;
if (isset($data['img_id']) && is_numeric($data['img_id'])) {
$id = $data['img_id'];
} else {
return 0;
}
if (isset($data['gall_id']) && is_numeric($data['gall_id'])) {
$gall_id = $data['gall_id'];
} else {
return 0;
}
if (!wp_verify_nonce($_POST['nonce'], 'fgallery_edit')) {
return 0;
}
$name = htmlentities($data['img_caption'], ENT_NOQUOTES, "UTF-8");
$desc = htmlentities($data['img_description'], ENT_NOQUOTES, "UTF-8");
$url = $data['img_url'];
if ($name != '') {
$wpdb->update(IMAGES_TABLE, array('img_caption' => $name, 'img_description' => $desc), array('img_id' => $id));
$wpdb->update(IMAGES_TO_ALBUMS_TABLE, array('img_url' => $url), array('img_id' => $id, 'gall_id' => $gall_id));
return 1;
} else {
return 0;
}
}
// deletes image from db and deletes file
function fgallery_delete_image($id) {
global $wpdb;
if (fgallery_access_level()>=5) {
$wpdb->query("DELETE FROM ".IMAGES_TO_ALBUMS_TABLE." WHERE `img_id` = ".$id);
$image = fgallery_get_image($id);
if ($image['img_vs_folder'] == 1){
$wpdb->query("UPDATE ".IMAGES_TABLE." SET `img_parent` = 0 WHERE `img_parent` =".$id);
$wpdb->query("DELETE FROM ".IMAGES_TABLE." WHERE `img_id` = ".$id);
} elseif ($image['img_vs_folder'] == 0) {
// we shouldn't delete wp media files so .....
if (strpos($image['img_path'],'fgallery') === false) {
$wpdb->query("DELETE FROM ".IMAGES_TABLE." WHERE `img_id` = ".$id);
} else {
unlink(ABSPATH.$image['img_path']);
$wpdb->query("DELETE FROM ".IMAGES_TABLE." WHERE `img_id` = ".$id);
}
}
return true;
} else {
return false;
}
}
// deletes gallery from db (does not delete files)
function fgallery_delete_album($id) {
global $wpdb;
if (fgallery_access_level()>=8) {
$wpdb->query("DELETE FROM ".IMAGES_TO_ALBUMS_TABLE." WHERE `gall_id` = ".$id);
$wpdb->query("DELETE FROM ".ALBUMS_SETTINGS_TABLE." WHERE `gall_id` = ".$id);
$wpdb->query("DELETE FROM ".ALBUMS_TABLE." WHERE `gall_id` = ".$id);
return true;
} else {
return false;
}
}
// returns the way of gallery sorting
function fgallery_sort_albums_condition($sort) {
switch ($sort){
case 0:
return 'gall_name ASC';
break;
case 1:
return 'gall_name DESC';
break;
case 2:
return 'gall_createddate ASC';
break;
case 3:
return 'gall_createddate DESC';
break;
case 4:
return 'gall_order ASC';
break;
default:
return 'gall_order ASC';
break;
}
}
// returns the way of image sorting
function fgallery_sort_images_condition($sort) {
switch ($sort){
case 0:
return 'img_caption ASC';
break;
case 1:
return 'img_caption DESC';
break;
case 2:
return 'img_date ASC';
break;
case 3:
return 'img_date DESC';
break;
case 4:
return 'img_size ASC';
break;
case 5:
return 'img_size DESC';
break;
}
}
function fgallery_get_nextgen_images() {
global $wpdb;
$images = $wpdb->get_results("SELECT a.pid, a.image_slug, a.filename, b.path FROM ".$wpdb->prefix."ngg_pictures as a LEFT JOIN ".$wpdb->prefix."ngg_gallery as b ON (a.galleryid = b.gid)");
return $images;
}
// returns all folders
function fgallery_get_folders(){
global $wpdb;
$folders = $wpdb->get_results("SELECT * FROM " . IMAGES_TABLE." WHERE `img_vs_folder` = 1 ORDER BY `img_caption`", 'ARRAY_A');
return $folders;
}
// Returns all albums
function fgallery_get_albums($pagenum, $per_page, $sort) {
global $wpdb;
$cond = fgallery_sort_albums_condition($sort);
$albums = $wpdb->get_results("SELECT * FROM " . ALBUMS_TABLE." ORDER BY ".$cond." LIMIT ".($pagenum-1)*$per_page.",".$pagenum*$per_page, 'ARRAY_A');
return $albums;
}
// counts the number of galleries
function fgallery_albums_count() {
global $wpdb;
$count = $wpdb->get_var("SELECT COUNT(*) FROM " .ALBUMS_TABLE);
return $count;
}
function fgallery_count_gallery_album_images($folder) {
global $wpdb;
$count = $wpdb->get_var("SELECT COUNT(*) FROM ".IMAGES_TO_ALBUMS_TABLE." WHERE `gall_folder` = ".$folder);
return $count;
}
// returns all the images
function fgallery_get_images($pagenum, $per_page, $parent = 0, $sort = 3) {
global $wpdb;
$cond = fgallery_sort_images_condition($sort);
$images = $wpdb->get_results("SELECT * FROM ". IMAGES_TABLE. " WHERE `img_parent` = ".$parent." AND `img_vs_folder` IN (0,1) ORDER BY `img_vs_folder` DESC, ".$cond." LIMIT ".($pagenum-1)*$per_page.",".$pagenum*$per_page, 'ARRAY_A');
return $images;
}
// counts the number of images in the folder (0 - root folder or not in any folder)
function fgallery_images_count($folder) {
global $wpdb;
$count = $wpdb->get_var("SELECT COUNT(*) FROM " .IMAGES_TABLE." WHERE `img_parent` = ".$folder." AND `img_vs_folder` IN (0,1)");
return $count;
}
// returns defined gallery
function fgallery_get_album($id) {
global $wpdb;
$album = $wpdb->get_row("SELECT * FROM ".ALBUMS_TABLE." WHERE gall_id = ".$id, ARRAY_A);
return $album;
}
// returns defined image
function fgallery_get_image($id) {
global $wpdb;
$image = $wpdb->get_row("SELECT * FROM ".IMAGES_TABLE." WHERE img_id = ".$id, ARRAY_A);
return $image;
}
// returns the images from defined gallery
function fgallery_get_album_images($gall_id, $folder = 0) {
global $wpdb;
$items = $wpdb->get_results("SELECT a.*, b.* FROM " . IMAGES_TABLE . " as a LEFT JOIN ". IMAGES_TO_ALBUMS_TABLE." as b ON (a.img_id = b.img_id) WHERE b.gall_id = " .$gall_id." AND b.gall_folder = ".$folder." ORDER BY a.img_vs_folder DESC, b.img_order ASC", 'ARRAY_A');
return $items;
}
// returns the galleries that have the defined image in them
function fgallery_image_get_albums($id) {
global $wpdb;
$albums = $wpdb->get_results("SELECT a.gall_name, a.gall_id FROM ". ALBUMS_TABLE ." as a LEFT JOIN ". IMAGES_TO_ALBUMS_TABLE. " as b ON (a.gall_id = b.gall_id) WHERE b.img_id =".$id, ARRAY_A);
return $albums;
}
// returns the folder name
function fgallery_get_folder_name($id) {
global $wpdb;
$name = $wpdb->get_var("SELECT `img_caption` FROM ".IMAGES_TABLE." WHERE `img_id` =".$id);
return $name;
}
function fgallery_get_settings_param($param, $settings) {
$name = (string)$param['element_name'];
if ($param['values'] == 'true') {
return $settings[$name] ? 'true' : 'false';
} else {
return $settings[$name];
}
}
function fgallery_prepare_settings($data) {
unset($data['gallery']);
$new = fgallery_default_album_settings();
foreach ($new as $key=>$value) {
if ($data[$key] != '') {
$new[$key] = $data[$key];
}
}
return $new;
}
/*
* Starting the configurator rendering
*/
function sc_params_pane($album) {
$gall_id = $album['gall_id'];
$type = $album['gall_type'];
$form = '';
return $form;
}
/**
* Element text
*/
function sc_controls_text($p) {
return ''
. '' . $p['title'] . ': '
. ' '
. '
';
}
/**
* Element - checkbox.
*/
function sc_controls_checkbox($p) {
$checked = (int)$p['default'] ? 'checked="checked"' : '';
if ($checked == '' && (string)$p['default'] == 'true') $checked = 'checked = "checked"';
return ''
. ' '
. '' . $p['title'] . ' '
. '
';
}
/**
* Element - select.
*/
function sc_controls_select($p) {
$options_raw = explode(',', $p['values']);
$options = '';
foreach ($options_raw as $o) {
$selected = (string) $p['default'] == $o ? 'selected="selected"' : '';
$options .= '' . $o . ' ';
}
return ''
. '' . $p['title'] . ': '
. '' . $options . ' '
. '
';
}
/**
* Element - slider (jQuery UI slider).
*/
function sc_controls_slider($p) {
$values = explode(':', $p['values']); // format "1..5:1"
$range = $values[0];
$range = explode('..', $range);
$min = $range[0];
$max = $range[1];
$step = $values[1];
// Validate values
if (!is_numeric($step) || !is_numeric($min) || !is_numeric($max)) {
return 'Parse error
';
}
return ''
. '' . $p['title'] . ': '
. ' '
. '
';
}
/**
* Form element - color picker (Farbtastic).
*/
function sc_controls_color($p) {
return ''
. '' . $p['title'] . ': '
. ' '
. '
';
}
// Renders the list of all albums
function fgallery_render_albums_table($albums){
$output .= '
'.__('ID').'
'.__('Name','fgallery').'
'.__('Cover','fgallery').'
'.__('Description','fgallery').'
'.__('Attributes','fgallery').'
'.__('Actions','fgallery').'
';
$output .= '
'.__('ID').'
'.__('Name','fgallery').'
'.__('Cover','fgallery').'
'.__('Description','fgallery').'
'.__('Attributes','fgallery').'
'.__('Actions','fgallery').'
';
if (!empty($albums)) {
foreach ($albums as $album) {
$output .= fgallery_render_album_item_row($album);
}
} else {
$output .= ''.__('There are no galleries yet. You can create new one using Add gallery menu','fgallery'). ' ';
}
$output .= '
';
$output .= ' ';
return $output;
}
// renders the row in the albums list
function fgallery_render_album_item_row($album) {
$id = $album['gall_id'];
$output = '';
$output .= ' ';
$output .= ''.$id.''.$album['gall_order'].' ';
$output .= ''.$album['gall_name'].' ';
$output .= ''.fgallery_get_album_cover($album).' ';
$output .= ''.$album['gall_description'].' ';
$output .= ''.fgallery_get_album_attributes($album).' ';
$output .= ''.fgallery_get_album_actions($id).' ';
$output .= ' ';
return $output;
}
function fgallery_render_album_image_form($item, $gall_id, $type) {
if ($gall_id == '') {
return '';
}
$output .= ''.__('Caption:', 'fgallery').'
';
$output .= ''.__('Description:', 'fgallery').'
';
$output .= ''.__('URL:', 'fgallery').'
';
$output .= wp_nonce_field('fgallery_edit','fgallery_edit_image_field_'.$item['img_id']);
$output .= ' ';
$output .= ''.__('Save').' ';
return $output;
}
// renders the list of album images on gallery edit page
function fgallery_render_album_images($items, $gall_id) {
$title = __('Remove', 'fgallery');
$title_2 = __('Set as cover', 'fgallery');
$title_3 = __('Edit','fgallery');
$album = fgallery_get_album($gall_id);
$output = '';
return $output;
}
// renders the list of images
function fgallery_render_images_table($images){
$output .= '
'.__('ID').'
'.__('Caption', 'fgallery').'
'.__('Preview', 'fgallery').'
'.__('Description', 'fgallery').'
'.__('Attributes', 'fgallery').'
'.__('Actions', 'fgallery').'
';
$output .= '
'.__('ID').'
'.__('Caption', 'fgallery').'
'.__('Preview', 'fgallery').'
'.__('Description', 'fgallery').'
'.__('Attributes', 'fgallery').'
'.__('Actions', 'fgallery').'
';
if (isset($_GET['folder'])) {
$output .= ''.__('Go up', 'fgallery').'... ';
}
if (!empty($images)) {
foreach ($images as $image) {
$output .= fgallery_render_image_item_row($image);
}
} else {
$output .= ''.__('There are no images yet. You can upload new ones using Upload images menu', 'fgallery'). ' ';
}
$output .= '
';
return $output;
}
// renders the row in the albums list
function fgallery_render_image_item_row($image) {
$id = $image['img_id'];
if ($image['img_vs_folder']){
$output = '';
} else {
$output = ' ';
}
$output .= ' ';
$output .= ''.$id.' ';
if ($image['img_vs_folder']) {
$output .= ''.$image['img_caption'].' ';
$output .= ' ';
$output .= ''.html_entity_decode($image['img_description']).' ';
$output .= ''.fgallery_get_folder_attributes($image).' ';
$output .= ''.fgallery_get_folder_actions($id).' ';
} else {
$output .= ''.$image['img_caption'].' ';
$output .= ' ';
$output .= ''.html_entity_decode($image['img_description']).' ';
$output .= ''.fgallery_get_image_attributes($image).' ';
$output .= ''.fgallery_get_image_actions($id).' ';
}
$output .= ' ';
return $output;
}
function fgallery_get_listof_gallery_albums($id) {
global $wpdb;
$albums =$wpdb->get_results("SELECT a.img_caption, a.img_id FROM ".IMAGES_TABLE." as a LEFT JOIN ".IMAGES_TO_ALBUMS_TABLE." as b ON (a.img_id = b.img_id) WHERE a.img_vs_folder = 2 AND b.gall_id = ".$id, ARRAY_A);
if (count($albums) > 0) {
$output = '';
$output .= '';
foreach ($albums as $album) {
$output .= ''.$album['img_caption'].' ';
}
$output .= ' ';
$output .= '';
$output .= ''.__('Remove selected').' ';
$output .= ' ';
$output .= ' ';
$output .= ' ';
$output .= ' ';
}
$output .= ' ';
return $output;
}
function fgallery_create_thumb_url($width) {
if (is_numeric($width)) {
return WP_PLUGIN_URL.'/'.basename(dirname(__FILE__)).'/image.php/cover.jpg?width='.$width.'&image='.EXTRA_DIR;
} else {
return COVER_PATH;
}
}
// returns the wrapped in img tag album cover
function fgallery_get_album_cover($album, $width ='') {
global $wpdb;
$gall_id = $album['gall_id'];
if ($album['gall_cover'] != 0){
$cover_id = $album['gall_cover'];
$cover = $wpdb->get_row("SELECT `img_path`, `img_caption` FROM " . IMAGES_TABLE . " WHERE `img_id` = " .$cover_id." LIMIT 1", 'ARRAY_A');
} else {
$cover = $wpdb->get_row("SELECT a.`img_path`, a.`img_caption` FROM " . IMAGES_TABLE . " as a LEFT JOIN ". IMAGES_TO_ALBUMS_TABLE ." as b ON (a.img_id = b.img_id) WHERE b.gall_id = " .$gall_id." ORDER BY b.img_order ASC LIMIT 1", 'ARRAY_A');
}
if ($cover['img_path']!=''){
$gall_cover = ' ';
}
return $gall_cover;
}
//returns rendered album attributes (image quantity, total size, publish date and etc.)
function fgallery_get_album_attributes($album, $extra = true) {
global $wpdb;
$id = $album['gall_id'];
$attr = $wpdb->get_row("SELECT COUNT(a.img_id) as 'quantity', SUM(a.img_size) as 'total_size' FROM " . IMAGES_TABLE . " as a LEFT JOIN ". IMAGES_TO_ALBUMS_TABLE ." as b ON (a.img_id = b.img_id) WHERE b.gall_id = " .$id." AND a.img_vs_folder <> 2", 'ARRAY_A');
$output = __('Number of photos:', 'fgallery').$attr['quantity']. ' ';
$output .= __('Total size:','fgallery').formatBytes($attr['total_size']). ' ';
if ($extra) {
if ($album['gall_published']) {
$status = __('Published');
} else {
$status = __('Draft');
}
$output .= __('Gallery status:','fgallery').$status. ' ';
$output .= date("d F Y",strtotime($album['gall_createddate'])). ' ';
}
return $output;
}
//returns rendered album attributes
function fgallery_get_image_attributes($image){
$id = $image['img_id'];
$albums = fgallery_image_get_albums($id);
$albums_name = '';
if (count($albums)>0){
foreach ($albums as $album) {
$albums_name .= $album['gall_name'].',';
}
$albums_name = substr($albums_name, 0, -1);
} else {
$albums_name = __('Image is not in any gallery', 'fgallery');
}
$output = __('Galleries:', 'fgallery').$albums_name.' ';
$output.= __('Image type:', 'fgallery').$image['img_type'].' ';
$output.= __('Image size:', 'fgallery').formatBytes($image['img_size']).' ';
$output.= __('Upload date:', 'fgallery').date("d F Y",strtotime($image['img_date']));
return $output;
}
//returns rendered folder attributes
function fgallery_get_folder_attributes($image){
global $wpdb;
if ($image['img_vs_folder']) {
$id = $image['img_id'];
$attr = $wpdb->get_row("SELECT COUNT(a.img_id) as 'quantity', SUM(a.img_size) as 'total_size' FROM " . IMAGES_TABLE . " as a WHERE a.img_parent = " .$id, 'ARRAY_A');
$output = __('Images:', 'fgallery').$attr['quantity'].' ';
$output.= __('Images size:', 'fgallery').formatBytes($attr['total_size']).' ';
$output.= __('Create date:', 'fgallery').date("d F Y",strtotime($image['img_date']));
}
return $output;
}
//renders the album actions
function fgallery_get_album_actions($id) {
$title_1 = __('Add images','fgallery');
$title_2 = __('Edit gallery','fgallery');
$title_3 = __('Delete gallery','fgallery');
$title_4 = __('Edit images', 'fgallery');
$output = ''.$title_1.' ';
$output .= ''.$title_2.' ';
$output .= ''.$title_4.' ';
if (fgallery_access_level()>= 8){
$output .= ''.$title_3.' ';
}
return $output;
}
//renders the folder actions
function fgallery_get_folder_actions($id) {
$title_2 = __('Change name', 'fgallery');
$title_3 = __('Delete folder', 'fgallery');
$output .= ''.$title_2.' ';
$output .= ' ';
$output .= ''.__('Create gallery', 'fgallery').' ';
if (fgallery_access_level()>= 5){
$output .= ''.$title_3.' ';
}
return $output;
}
//renders the image actions
function fgallery_get_image_actions($id) {
$title_2 = __('Edit image', 'fgallery');
$title_3 = __('Delete image', 'fgallery');
$output = ''.$title_2.' ';
if (fgallery_access_level()>= 5){
$output .= ''.$title_3.' ';
}
return $output;
}
// renders the shortcode for inserting the gallery into the content
function fgallery_do_shortcode($id, $type = 0) {
$album = fgallery_get_album($id);
return sprintf('[fgallery id=%d w=%d h=%d t=%d title="%s"]',$id, $album['gall_width'], $album['gall_height'], $type, trim($album['gall_name']));
}
// renders the gaellery edit form
function fgallery_render_edit_album_form($album, $source) {
$id = $album['gall_id'];
$output .= '';
$output .= '
'.__('Name:', 'fgallery').'
';
$output .= '
'.__('Description:','fgallery').'
';
$output .= '
'.__('Status', 'fgallery').'
'.__('Published').' ';
$output .= '
';
$output .= '
'.__('Source', 'fgallery').'
'.__('Local').' ';
$output .= '
';
$output .= '
'.__('Width:', 'fgallery').'
';
$output .= '
'.__('Height:', 'fgallery').'
';
$output .= '
'.__('Background Color:', 'fgallery').'
';
$opt = array();
$opt[$album['gall_type']] = 'selected ="selected"';
$output .= '
'.__('Gallery Type:', 'fgallery').'
'.__('Acosta').'
'.__('Airion').'
'.__('Arai').'
'.__('Pax').'
'.__('Pazin').'
'.__('Postma').'
'.__('Pageflip').'
'.__('Nilus').'
'.__('Nusl').'
';
$output .= '
';
return $output;
}
function fgallery_get_flash_type($album) {
switch ($album['gall_type']) {
case 1: return 'acosta';
case 2: return 'airion';
case 3: return 'arai';
case 4: return 'pax';
case 5: return 'pazin';
case 6: return 'postma';
case 7: return 'pageflip';
case 8: return 'nilus';
case 9: return 'nusl';
default: return 'arai';
}
}
// renders the image edit form
function fgallery_render_edit_image_form($image) {
$id = $image['img_id'];
$output = '';
return $output;
}
// formats the image/folder/gallery size
function formatBytes($b,$p = null) {
/**
*
* @author Martin Sweeny
* @version 2010.0617
*
* returns formatted number of bytes.
* two parameters: the bytes and the precision (optional).
* if no precision is set, function will determine clean
* result automatically.
*
**/
$units = array("B","kB","MB","GB","TB","PB","EB","ZB","YB");
$c=0;
if(!$p && $p !== 0) {
foreach($units as $k => $u) {
if(($b / pow(1024,$k)) >= 1) {
$r["bytes"] = $b / pow(1024,$k);
$r["units"] = $u;
$c++;
}
}
return number_format($r["bytes"],2) . " " . $r["units"];
} else {
return number_format($b / pow(1024,$p)) . " " . $units[$p];
}
}
/*
* Starting URLs()
*
*/
function fgallery_images_url() {
return admin_url('admin.php?page=fgallery_images');
}
function fgallery_get_upload_url() {
return admin_url('admin.php?page=fgallery_upload');
}
function fgallery_createalbum_url() {
return admin_url('admin.php?page=fgallery_add');
}
function fgallery_get_addimages_url($id) {
return FGALLERY_PATH.'/addimage.php?id='.$id.'&TB_iframe=1';
}
function fgallery_get_addimages_url_clean($id) {
return FGALLERY_PATH.'/addimage.php?id='.$id;
}
function fgallery_get_album_images_url($id) {
return admin_url('admin.php?page=fgallery&action=images&id='.$id);
}
function fgallery_create_folder_url($type,$id) {
return FGALLERY_PATH.'/folder.php?&action=create&type='.$type.'&gall_id='.$id.'&TB_iframe=1';
}
function fgallery_get_settings_url($id) {
return FGALLERY_PATH.'/settings.php?gall_id='.$id;
}
function fgallery_get_edit_url($id) {
return admin_url('admin.php?page=fgallery&action=edit&id='.$id);
}
function fgallery_get_edit_url_clean($id) {
return admin_url('admin.php?page=fgallery&action=edit&id='.$id);
}
function fgallery_get_image_edit_url($id) {
return admin_url('admin.php?page=fgallery_images&action=edit&id='.$id);
}
function fgallery_get_album_image_edit_url() {
return admin_url('admin.php?page=fgallery_images&action=edit_album');
}
function fgallery_get_folder_url($id) {
return admin_url('admin.php?page=fgallery_images&folder='.$id);
}
function fgallery_get_image_delete_url($id) {
return admin_url('admin.php?page=fgallery_images&action=delete&id='.$id);
}
function fgallery_get_delete_url($id){
return admin_url('admin.php?page=fgallery&action=delete&id='.$id);
}
function fgallery_upload_zip_get_url() {
return FGALLERY_PATH.'/upload.php?action=unzip';
}
function fgallery_upload_ftp_get_url() {
return FGALLERY_PATH.'/upload.php?action=ftp';
}
function fgallery_upload_url_get_url() {
return FGALLERY_PATH.'/upload.php?action=upload_url';
}
function fgallery_upload_media_get_url() {
return FGALLERY_PATH.'/upload.php?action=media';
}
function fgallery_upload_facebook_get_url() {
return FGALLERY_PATH.'/upload.php?action=facebook';
}
function fgallery_upload_nextgen_get_url() {
return FGALLERY_PATH.'/upload.php?action=nextgen';
}
function fgallery_upload_scandir_get_url() {
return FGALLERY_PATH.'/upload.php?action=scandir';
}
function fgallery_remove_image_from_gallery_url($img_id, $gall_id) {
return admin_url('admin.php?page=fgallery_images&action=remove&id='.$img_id.'&gall_id='.$gall_id);
}
function fgallery_set_gallery_cover_url($img_id, $gall_id) {
return admin_url('admin.php?page=fgallery_images&action=cover&id='.$img_id.'&gall_id='.$gall_id);
}
function fgallery_sort_url() {
return admin_url('admin.php?page=fgallery_images&action=sort');
}
function fgallery_sort_galleries_url() {
return admin_url('admin.php?page=fgallery&action=sort');
}
function fgallery_get_massedit_url() {
return FGALLERY_PATH.'/massedit.php';
}
function fgallery_get_massedit_album_url() {
return FGALLERY_PATH.'/massedit_album.php';
}
function fgallery_get_add_album_url(){
return FGALLERY_PATH.'/insert_gallery.php?TB_iframe=1';
}
function fgallery_get_insert_button_url(){
return FGALLERY_PATH.'/images/icon_gallery.gif';
}
function fgallery_get_folder_addimage_url() {
return FGALLERY_PATH.'/folder_addimage.php';
}
function fgallery_get_props_url($id) {
return FGALLERY_PATH.'/folder_addimage.php?action=prop&gall_id='.$id;
}
function fgallery_get_values_url($id) {
return FGALLERY_PATH.'/folder_addimage.php?action=value&gall_id='.$id;
}
function fgallery_get_pref_url() {
return admin_url('admin.php?page=fgallery&action=pref');
}
function fgallery_view_gallery_url($id, $width, $height, $bgcolor) {
$height = $height+30;
return FGALLERY_PATH.'/view.php?gall_id='.$id.'&width='.$width.'&height='.$height.'&bg='.$bgcolor.'&TB_iframe=1';
}
/*
* Filters
*
*/
add_filter('screen_settings', 'fgallery_screen_settings', 10, 2);
add_filter('contextual_help', 'fgallery_plugin_help', 10, 3);
add_filter('media_buttons_context','fgallery_add_button',9);
add_shortcode( 'fgallery', 'fgallery_shortcode_handler' );
function fgallery_plugin_help($contextual_help, $screen_id, $screen) {
if ($screen_id == 'toplevel_page_fgallery' || $screen_id == '1-flash-gallery_page_fgallery_add'
|| $screen_id == '1-flash-gallery_page_fgallery_add' || $screen_id == '1-flash-gallery_page_fgallery_images' || $screen_id == '1-flash-gallery_page_fgallery_upload') {
$contextual_help = ''.__('FAQ').'
';
}
return $contextual_help;
}
// filter for setting the number of elements on the screen
function fgallery_screen_options($screen) {
if ( is_string($screen) )
$screen = convert_to_screen($screen);
$option = str_replace( '-', '_', "{$screen->id}_per_page" );
$per_page = (int) get_option( $option , 25);
if ( $screen->id == '1-flash-gallery_page_fgallery_images') {
$per_page_label = _x( 'Images', 'images per page (screen options)' );
} else {
$per_page_label = _x( 'Galleries', 'galleries per page (screen options)' );
}
$return = "\n";
if ( !empty($per_page_label) )
$return .= " $per_page_label \n";
$return .= " ";
$return .= " ";
$return .= "
\n";
return $return;
}
function fgallery_screen_settings($current, $screen){
if ( $screen->id == '1-flash-gallery_page_fgallery_images' && !isset($_GET['action'])){
$current = ''._x('Show on screen', 'Screen Options').' ';
$current .= fgallery_screen_options($screen);
$current .= ''. wp_nonce_field( 'screen-options-nonce', 'screenoptionnonce', true ).'
';
} elseif ($screen->id == 'toplevel_page_fgallery' && !isset($_GET['action'])){
$current = ''._x('Show on screen', 'Screen Options').' ';
$current .= fgallery_screen_options($screen);
$current .= ''. wp_nonce_field( 'screen-options-nonce', 'screenoptionnonce', true ).'
';
}
return $current;
}
function plugin_is_active($plugin_path) {
$return_var = in_array( $plugin_path, apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) );
return $return_var;
}
function fgallery_search_flash_path($album) {
$type = fgallery_get_flash_type($album);
if (get_option('1_flash_gallery_'.fgallery_get_flash_type($album)) !='') {
if (plugin_is_active('1-flash-gallery-update/update_fgallery.php')) {
return WP_PLUGIN_URL .'/1-flash-gallery-update/swf/'.fgallery_get_flash_type($album).'.swf';
} elseif (plugin_is_active('1-flash-gallery-update-'.fgallery_get_flash_type($album).'/update_'.fgallery_get_flash_type($album).'.php')) {
return WP_PLUGIN_URL .'/1-flash-gallery-update-'.fgallery_get_flash_type($album).'/swf/'.fgallery_get_flash_type($album).'.swf';
} else {
return FGALLERY_PATH.'/swf/'.fgallery_get_flash_type($album).'.swf';
}
} else {
return FGALLERY_PATH.'/swf/'.fgallery_get_flash_type($album).'.swf';
}
}
// filter for replacing gallery shortcode with flash movie itself
function fgallery_shortcode_handler($atts, $content = null){
// set default params if not present
extract(shortcode_atts( array(
'id' => 0,
'w' => 450,
'h' => 385,
'bg' => 'ffffff',
't' => 0,
'align' => '',
'thumb' => '',
'title' => '',
), $atts ));
if ($t < 0 || $t > 2) {
$t = 0;
}
// check if the gallery exist
if ($id > 0) {
$album = fgallery_get_album($id);
if (empty($album)) {
return '[fgallery 404 Not found]';
}
} else {
return '[fgallery 404 Not found]';
}
// different output for different insert type
switch ($t) {
case '0' :
$rand = rand(0, 150);
$path = fgallery_search_flash_path($album);
if (isset($align)) {
switch ($align) {
case 'left' : case 'right' :
$align_text = 'float:'.$align;
break;
default:
$align_text = '';
break;
}
}
$gallery_snippet = '
You need to upgrade your Flash Player
';
if (get_option('1_flash_gallery_'.fgallery_get_flash_type($album)) =='') {
$gallery_snippet .= '
';
}
$gallery_snippet .= '
';
break;
case '1' :
if ($title == '') {
$insert_text = $album['gall_name'];
} else {
$insert_text = $title;
}
$gallery_snippet = ''.$insert_text.'
'.fgallery_get_album_attributes($album, false).'
';
break;
case '2' :
$gallery_snippet = ''.fgallery_get_album_cover($album, $thumb).'
'.$album['gall_name'].'
'.fgallery_get_album_attributes($album, false).'
';
break;
}
return $gallery_snippet;
}
// filter to add the button (for inserting the gallery into post) to post edit page
function fgallery_add_button($buttons) {
$fgallery_button = "
";
$buttons .= $fgallery_button;
return $buttons;
}