0 )
( update_option('wpsary_thumbwidth', (int) $_POST['wpsary_thumbwidth']));
if((int) $_POST['wpsary_colnumbers'] > 0 )
( update_option('wpsary_colnumbers', (int) $_POST['wpsary_colnumbers']));
if((int) $_POST['wpsary_thumbheight'] > 0)
(update_option('wpsary_thumbheight', (int) $_POST['wpsary_thumbheight']));
update_option('wpsary_activated', true);
?>
" . __('Add new', 'wpsary') . ")"; ?>
|
|
|
|
metadata) ;
?>
|
title); ?>
|
description)); ?>
|
"; ?>
|
id . "&albumID=" . $image->albumID . "'>" . __('Album cover', 'wpsary') . ""; ?>
|
id . "&albumID=" . $image->albumID . "'>" . __('Edit', 'wpsary') . ""; ?>
|
id . "&albumID=" . $image->albumID. "' onclick=\"return deleteSomething('" . addslashes(__('You are about to delete this image. \'OK\' to delete, \'Cancel\' to stop.')) . "');\">" . __('Delete', 'wpsary') . ""; ?>
|
" . __('Upload new image', 'wpsary') . ""; ?>
" . __('Go to configuration', 'wpsary') . ""; ?>
" . __('Add new gallery', 'wpsary') . ""; ?>
" . __('Add new', 'wpsary') . ")"; ?>
|
|
|
|
|
title) ?>
|
description) ?>
|
id . "'>" . __('View', 'wpsary') . ""; ?>
|
id . "'>" . __('Edit', 'wpsary') . ""; ?>
|
id . "'>" . __('Add image', 'wpsary') . ""; ?>
|
id . "' onclick=\"return deleteSomething('" . addslashes(__('You are about to delete this gallery. \'OK\' to delete, \'Cancel\' to stop.')) . "');\">" . __('Delete', 'wpsary') . ""; ?>
|
get_row("SELECT * FROM " . $wpdb->prefix . "wpsary_images WHERE id='" . $id . "'");
$id = $wp_image->id
?>
get_row("SELECT * FROM " . $wpdb->prefix . "wpsary_album WHERE id='$albumID'")) {
$album->title = stripslashes($album->title);
$album->description = stripslashes($album->description);
$album->metadata = wpsary_maybe_unserialize($album->metadata);
$album->images = wpsary_getImageList($albumID);
$dir = wpsary_getUploadDir();
$album->url = $dir[url];
Return $album;
} else {
Return false;
}
}
function wpsary_getAlbumList() {
global $wpdb;
$album_table_name = $wpdb->prefix . "wpsary_album";
if($wpdb->get_var("show tables like '$album_table_name'") != $album_table_name) {
Return false;
}
$query = "SELECT * FROM ".$album_table_name;
$result = $wpdb->get_results($query);
Return $result;
}
function wpsary_getUploadDir() {
$siteurl = get_option('siteurl');
//prepend ABSPATH to $dir and $siteurl to $url if they're not already there
$path = str_replace(ABSPATH, '', trim(get_settings('upload_path')));
$dir = ABSPATH . $path;
$url = trailingslashit($siteurl) . $path;
if ( $dir == ABSPATH ) { //the option was empty
$dir = ABSPATH . 'wp-content/uploads';
}
if ( defined('UPLOADS') ) {
$dir = ABSPATH . UPLOADS;
$url = trailingslashit($siteurl) . UPLOADS;
}
$dir .= "/album/";
$url .= "/album/";
// Make sure we have an uploads dir
if ( ! wp_mkdir_p( $dir ) ) {
$message = sprintf(__('Unable to create directory %s. Is its parent directory writable by the server?'), $dir, 'wpsary');
return array('error' => $message);
}
$uploads = array('path' => $dir, 'url' => $url, 'error' => false);
return $uploads;
}
// On success, returns an associative array of file attributes.
// On failure, returns array( 'error'=>$message ).
function wpsary_handle_upload( &$file ) {
// The default error handler.
if (! function_exists( 'wpsary_handle_upload_error' ) ) {
function wpsary_handle_upload_error( &$file, $message ) {
return array( 'error'=>$message );
}
}
// A properly uploaded file will pass this test. There should be no reason to override this one.
if (! @ is_uploaded_file( $file['tmp_name'] ) )
return wpsary_handle_upload_error( $file, __( 'Specified file failed upload test.' ), 'wpsary');
// A correct MIME type will pass this test. Override $mimes or use the upload_mimes filter.
$wp_filetype = wp_check_filetype( $file['name'], $mimes );
extract( $wp_filetype );
if ( !$type || !$ext )
return $wp_check_filetype( $file, __( 'File type does not meet security guidelines. Try another.' ), 'wpsary');
// A writable uploads dir will pass this test. Again, there's no point overriding this one.
if ( ! ( ( $uploads = wpsary_getUploadDir() ) && false === $uploads['error'] ) )
return wpsary_handle_upload_error( $file, $uploads['error'] );
// Increment the file number until we have a unique file to save in $dir. Use $override['unique_filename_callback'] if supplied.
$number = '';
$filename = str_replace( '#', '_', $file['name'] );
$filename = str_replace( array( '\\', "'" ), '', $filename );
if ( empty( $ext) )
$ext = '';
else
$ext = ".$ext";
while ( file_exists( $uploads['path'] . $filename) ) {
if ( '' == "$number$ext" )
$filename = $filename . ++$number . $ext;
else
$filename = str_replace( "$number$ext", ++$number . $ext, $filename );
}
$filename = str_replace( $ext, '', $filename );
$filename = $filename . $ext;
// Move the file to the uploads dir
$new_file = $uploads['path'] . $filename;
if ( false === @ move_uploaded_file( $file['tmp_name'], $new_file ) )
wp_die( printf( __('The uploaded file could not be moved to %s.' ), $uploads['path'] ), 'wpsary');
// Set correct file permissions
$stat = stat( dirname( $new_file ));
$perms = $stat['mode'] & 0000666;
@ chmod( $new_file, $perms );
// Compute the URL
$url = $uploads['url'] . $filename;
$return = apply_filters( 'wpsary_handle_upload', array( 'filename' => $filename, 'file' => $new_file, 'url' => $url, 'type' => $type ) );
return $return;
}
function wpsary_getImageInfo($id) {
global $wpdb;
if($photo = $wpdb->get_row("SELECT * FROM ". $wpdb->prefix . "wpsary_images WHERE id='$id'")) {
$photo->metadata = wpsary_maybe_unserialize($photo->metadata);
$photo->title = stripslashes($photo->title);
$photo->description = stripslashes($photo->description);
$dir = wpsary_getUploadDir();
$photo->url = $dir[url];
Return $photo;
} else {
Return false;
}
}
function wpsary_maybe_serialize($data) {
if ( is_string($data) )
$data = trim($data);
elseif ( is_array($data) || is_object($data) )
return serialize($data);
if ( wpsary_is_serialized($data) )
return serialize($data);
return $data;
}
function wpsary_is_serialized($data) {
// if it isn't a string, it isn't serialized
if ( !is_string($data) )
return false;
$data = trim($data);
if ( 'N;' == $data )
return true;
if ( !preg_match('/^([adObis]):/', $data, $badions) )
return false;
switch ( $badions[1] ) :
case 'a' :
case 'O' :
case 's' :
if ( preg_match("/^{$badions[1]}:[0-9]+:.*[;}]\$/s", $data) )
return true;
break;
case 'b' :
case 'i' :
case 'd' :
if ( preg_match("/^{$badions[1]}:[0-9.E-]+;\$/", $data) )
return true;
break;
endswitch;
return false;
}
function wpsary_maybe_unserialize($original) {
if ( wpsary_is_serialized($original) ) // don't attempt to unserialize data that wasn't serialized going in
if ( false !== $gm = @ unserialize($original) )
return $gm;
return $original;
}
?>