<?php
//error_reporting(E_ERROR | E_WARNING);
header('Content-Type: text/html; charset=UTF-8');
include_once('core.php');
class px extends px_core{
var $dirName;
var $dirPath;
var $options;
var $parentFile;
var $baseFile;
var $vars;
var $api_smugmug = '8vjhYpC7wz53UTdspu33yRaYXEPgrU5D';
var $api_flickr = '99c12772538849fb2890645771d923f9';
var $cur_album_id = 0;
var $cur_album_info = NULL;
var $cur_gallery_id = 0;
var $cur_gallery_info = NULL;
var $cur_image_group =
array();
var $cur_return = '';
var $cur_js_func = '';
var $cur_js_show = '';
var $cur_upload_dir = '';
var $cur_album_dir = '';
var $cur_image_info = '';
var $album_list = '';
var $safe_mode = false;
function px($file=''){
$this->baseFile = $file;
$this->baseName = plugin_basename($this->baseFile);
$this->
dirName =
basename($this->
dirPath);
$this->parentFileUrl = get_bloginfo('wpurl') . '/wp-content/plugins/' . $this->baseName;
// database tables
'albums' => $wpdb->prefix . "px_albums",
'albums_version' => "1.2",
'albumPhotos' => $wpdb->prefix . "px_albumPhotos",
'albumPhotos_version' => "1.2",
'galleries' => $wpdb->prefix . "px_galleries",
'galleries_version' => "1.2",
'photos' => $wpdb->prefix . "px_photos",
'photos_version' => "1.2",
'plugins' => $wpdb->prefix . "px_plugins",
'plugins_version' => "1.2",
'js' => get_bloginfo('wpurl') . '/wp-content/plugins/' . $this->dirName . '/common/js/',
'css' => get_bloginfo('wpurl') . '/wp-content/plugins/' . $this->dirName . '/common/css/',
'img' => get_bloginfo('wpurl') . '/wp-content/plugins/' . $this->dirName . '/common/img/',
'pluginjs' => get_bloginfo('wpurl') . '/wp-content/plugins/' . $this->dirName . '/galleryScripts/',
'parts' => get_bloginfo('wpurl') . '/wp-content/plugins/' . $this->dirName . '/common/inc/pages/parts/'
);
$this->options = $options;
if (ini_get('safe_mode') ==
'off'){
$this->safe_mode = false;
}
else{
$this->
safe_mode =
ini_get('safe_mode');
}
}
else{
$this->
safe_mode =
ini_get('safe_mode');
}
add_action
('admin_menu',
array(&
$this,
'adminMenu'));
if( isset( $_POST['onetimer'] ) ){
$this->onetimers( $_POST['onetimer'] );
}
parent::px_core($file);
$this->init();
}
/**
*
*/
function init(){
add_action
('activate_' .
$this->
dirName .
'/photoxhibit.php',
array(&
$this,
'install'));
add_action
('deactivate_' .
$this->
dirName .
'/photoxhibit.php',
array(&
$this,
'unintall'));
}
function unintall(){}
/**
*
*/
function adminMenu(){
add_menu_page
('PhotoXhibit',
'PhotoXhibit',
7,
$this->
baseFile,
array(&
$this,
'adminOverView'));
}
add_submenu_page
($this->
baseFile, __
('OverView',
'photoxhibit'), __
('OverView',
'photoxhibit'),
7,
$this->
baseFile,
array(&
$this,
'adminOverView'));
add_submenu_page
($this->
baseFile, __
('Manage Gallery',
'photoxhibit'), __
('Manage Gallery',
'photoxhibit'),
7,
'px_manage',
array(&
$this,
'adminManageGallery'));
add_submenu_page
($this->
baseFile, __
('Build Gallery',
'photoxhibit'), __
('Build Gallery',
'photoxhibit'),
7,
'px_build',
array(&
$this,
'adminBuild'));
add_submenu_page
($this->
baseFile, __
('Manage Album',
'photoxhibit'), __
('Manage Album',
'photoxhibit'),
7,
'px_manageAlbum',
array(&
$this,
'adminManageAlbum'));
add_submenu_page
($this->
baseFile, __
('Options',
'photoxhibit'), __
('Options',
'photoxhibit'),
7,
'px_options',
array(&
$this,
'adminOptions'));
add_submenu_page
($this->
baseFile, __
('About',
'photoxhibit'), __
('About',
'photoxhibit'),
7,
'px_about',
array(&
$this,
'adminAbout'));
}
} // end : adminMenu()
function edit_image_form( $id = NULL ){
if( $id == NULL ){
$id = $_GET['iid'];
}
$this->cur_image_info = $wpdb->get_row("SELECT * FROM ".$this->options['albumPhotos']." WHERE albumPhotos_id = ".$wpdb->escape($id));
if( !
empty($_GET['iid']) ){
include($this->dirPath.'/common/views/album/edit_image_attr.php');
}
}
function edit_image_single(){
$sql = "UPDATE ".$this->options['albumPhotos'] . " SET
albumPhotos_alt='". $wpdb->escape($_GET['albumPhotos_alt'])."',
albumPhotos_tags='". $wpdb->escape($_GET['albumPhotos_tags'])."',
albumPhotos_isactive='". $wpdb->escape($_GET['albumPhotos_isactive'])."' ,
albumPhotos_desc='". $wpdb->escape($_GET['albumPhotos_desc'])."'
WHERE albumPhotos_id=" . $wpdb->escape($_GET['albumPhotos_id']);
$wpdb->query($sql);
echo '{"id":'.
$_GET['albumPhotos_id'].
'}';
}
function delete_image( $id = NULL ){
if( $id == NULL ){
$id = $_GET['iid'];
}
$this->edit_image_form( $id );
$sql = "DELETE FROM ".$this->options['photos']." WHERE albumPhotos_id = " . $wpdb->escape($id) . " LIMIT 1";
$sql = "DELETE FROM ".$this->options['albumPhotos']." WHERE albumPhotos_id = " . $wpdb->escape($id) . " LIMIT 1";
$options = get_option('photoxhibit');
if( $options['options_delete'] == 1 ){
$this->get_upload_dir($this->cur_image_info->album_id);
$dir = $this->cur_upload_dir;
@
unlink($dir .
'/' .
$this->
cur_image_info->
albumPhotos_file .
'.' .
$this->
cur_image_info->
albumPhotos_ext);
@
unlink($dir .
'/' .
$this->
cur_image_info->
albumPhotos_file .
'_tn.' .
$this->
cur_image_info->
albumPhotos_ext);
@
unlink($dir .
'/' .
$this->
cur_image_info->
albumPhotos_file .
'_ltn.' .
$this->
cur_image_info->
albumPhotos_ext);
@
unlink($dir .
'/' .
$this->
cur_image_info->
albumPhotos_file .
'_o.' .
$this->
cur_image_info->
albumPhotos_ext);
}
if( $id != NULL ){
echo '{"complete":true}';
}
}
/**
*
*/
function get_set_album($get){
$id = $get['album_id'];
if( $id == 0 ){
$sql = "INSERT INTO ".$this->options['albums'] . "
(album_name) VALUES ('". $wpdb->escape($get['album_name'])."')";
$wpdb->query($sql);
}
else{
$sql = "UPDATE ".$this->options['albums'] . " SET album_name='". $wpdb->escape($get['album_name'])."' WHERE album_id=" . $id;
$wpdb->query($sql);
}
echo '{"id":'.
$id.
',"album_name":"'.
$get['album_name'].
'"}';
}
function get_photos_from_album($id = NULL){
if( $id == NULL ){
$id = $_GET['aid'];
}
return $wpdb->get_results("SELECT * FROM ".$this->options['albumPhotos']." WHERE album_id=".$wpdb->escape($id));
}
/**
*
*/
function adminManageAlbum(){
$this->
styles =
array('base.css');
$this->loadCss();
$this->
js =
array('jquery',
'ui',
'core',
'json');
$this->getOptions();
$this->loadJs();
$imageGroup = '';
if( isset($_GET['do']) ){
$this->imageUpload();
}
$this->vars = get_option('photoxhibit');
if( isset( $_GET['aid'] ) ){
$imageGroup = $this->get_photos_from_album();
$this->get_album_dir();
}
switch($_GET['action']){
case 'edit_images':
include($this->dirPath.'/common/views/album/edit_images.php');
break;
case 'edit_image':
include('pages/parts/edit_image.php');
break;
case 'build_album':
include('pages/build_album.php');
break;
case 'delete_album':
$this->deleteAlbum();
default:
include('pages/albumManager.php');
}
} // end : adminManageGallery()
function deleteAlbum(){
// $sql = "DELETE FROM ".$this->options['albums']." WHERE album_id = " . $wpdb->escape($_GET['aid']) . " LIMIT 1";
// @mysql_query( $sql ) or die("(deleteAlbum) An unexpected error occured.".mysql_error());
$options = get_option('photoxhibit');
if( $options['options_dropall'] == 1 ){
$this->get_upload_dir($_GET['aid']);
$this->removeFolder($this->cur_upload_dir);
$results = $wpdb->get_results("SELECT albumPhotos_id FROM ".$this->options['albumPhotos']."
WHERE album_id=".$wpdb->escape($_GET['aid']));
foreach($results as $result => $v){
$sql = "DELETE FROM ".$this->options['photos']."
WHERE albumPhotos_id = " . $wpdb->escape($v->albumPhotos_id) . "
LIMIT 1";
}
}
$sql = "DELETE FROM ".$this->options['albumPhotos']."
WHERE album_id = " . $wpdb->escape($_GET['aid']);
}
else{
$sql = "UPDATE ".$this->options['albumPhotos'] ."
SET album_id = 0
WHERE album_id = " . $_GET['aid'];
$wpdb->query($sql);
}
$sql = "DELETE FROM ".$this->options['albums']." WHERE album_id = " . $wpdb->escape($_GET['aid']) . " LIMIT 1";
}
function removeFolder($dir){
return false;
for($s = DIRECTORY_SEPARATOR,
$stack =
array($dir),
$emptyDirs =
array($dir);
$dir =
array_pop($stack);
){
if(!
($handle = @
dir($dir)))
continue;
while(false !== $item = $handle->read())
$item !=
'.' &&
$item !=
'..' &&
(is_dir($path =
$handle->
path .
$s .
$item) ?
$handle->close();
}
for($i =
count($emptyDirs);
$i--;
rmdir($emptyDirs[$i]));
}
/**
* Load overview page
*/
function adminOverView(){
$this->write_baseCss();
$this->checkforblogrollentry();
include('pages/overview.php');
} // end : adminOverView()
function update_styles($local = false){
if($local){
$return = '';
//if(empty($_POST['px_stylesTextarea'])) array_push($returnA,'{"error":"error_no_styles"}');
if( count($returnA) <=
0 ){
$sql = "UPDATE " . $this->options['galleries'] . " SET gallery_css='".$wpdb->escape($_POST['px_stylesTextarea']) ."' WHERE gallery_id = " . $wpdb->escape($_POST['gid']);
}
if($r){
echo '<div class="wrap">'.__
('Styles have been updated') .
'</div>';
}
else{
echo '<div class="wrap">' . __
('Error(s) on update:') .
'<br/>' .
join('<br/>',
$returnA) .
'</div>';
}
}
else{
$return = '';
if(empty($_POST['styles'])) array_push($returnA,
'{"error":"error_no_styles"}');
if( count($returnA) <=
0 ){
$sql = "UPDATE " . $this->options['galleries'] . " SET gallery_css='".$wpdb->escape($_POST['styles']) ."' WHERE gallery_id = " . $wpdb->escape($_POST['gid']);
}
if($r){
echo '{"good":"no_errors"}';
}
else{
echo '['.
'{"error":"error_update"}'.
join(',',
$returnA) .
']';
}
}
}
/**
* Load build page
*/
function get_gallery_data($id=0){
$id = ($id==0) ? $this->cur_gallery_id : $id;
$sql = "SELECT * FROM ".$this->options['galleries']." WHERE gallery_id = ".$wpdb->escape($id);
return $wpdb->get_row($sql);
}// end : get_album_data
/**
* Get Gallery Information
*/
function get_gallery_info(){
$this->cur_gallery_info = $this->get_gallery_data();
}// end : get_album_info
/**
* Build Image Gallery
*/
function build_image_set($gallery_id=0, $r = false, $js = true){
if( $gallery_id == 0 ) return;
$this->cur_gallery_id = $gallery_id;
$this->cur_js_show = $js;
$this->get_gallery_info();
if($this->cur_gallery_info){
$this->get_js_func();
$this->get_imgs_group();
$this->buildout_images();
$this->get_css_link();
$this->get_js_code();
}
if($r){
return $this->cur_return;
}
else{
}
} // end : function build_image_set()
/**
*
*/
function get_css_link(){
$this->
cur_return .=
'<link id="px_editstylesheet" type="text/css" href="'.
$this->
parentFileUrl.
'?option=css&gid='.
$this->
cur_gallery_id.
'&'.
time().
'" rel="stylesheet"/>';
} // end : get_css_link
/**
*
*/
function get_js_func(){
$sql = "SELECT * FROM " . $this->options['plugins'] .' where plugin_id ='.$this->cur_gallery_info->plugin_id;
$tmp = $wpdb->get_row($sql);
$this->cur_js_func = $tmp->plugin_js;
} // end : get_js_func
/**
*
*/
function get_js_code(){
if(!$this->cur_js_show) return;
include_once('JSON.php');
$json = new JSON;
$objs =
$json->
unserialize(stripslashes($this->
cur_gallery_info->
gallery_params));
}
else{
$objs = json_decode
(stripslashes($this->
cur_gallery_info->
gallery_params));
}
if($objs){
foreach($objs as $obj => $k){