public_build_img_gallery( $gallery ); return $_bsg_->build_image_set( $gallery, true, false ); } else{ //return $bsg->public_build_img_gallery( $gallery ); return $_bsg_->build_image_set( $gallery, true ); } } } /** * function : put_gallery * purpose : This is so you can put the gallery into a post or excerpt */ add_filter('the_content', 'put_gallery'); add_filter('the_excerpt', 'put_gallery'); if(!function_exists('put_gallery')) { function put_gallery($content){ if(!is_feed()) { $content = preg_replace("/\[gallery=(\d+)\]/ise", "bsg_getGallery('\\1',false)", $content); } else { $content = preg_replace("/\[gallery=(\d+)\]/ise", "bsg_getGallery('\\1',true)", $content); } return $content; } } $to = ""; $objs = ""; $sql = ""; $to = $_REQUEST['to']; $return = ""; switch($to){ case 'get': //set_time_limit(30); if($_GET['who'] == "locally"){ $r = $wpdb->get_results(" SELECT * FROM wp_posts WHERE post_type = 'attachment' AND (post_mime_type = 'image/jpeg' OR post_mime_type = 'image/gif' OR post_mime_type = 'image/png')"); if (!extension_loaded('json')){ include($bsg->dir.'/common/inc/JSON.php'); $json = new JSON; echo $json->serialize($r); } else{ echo json_encode($r); } } else{ echo $bsgAdmin->get_album_json($_GET['url']); } break; case 'put': if (!extension_loaded('json')){ include($bsg->dir.'/common/inc/JSON.php'); $json = new JSON; $objs = $json->unserialize(stripslashes($_POST['images'])); } else{ $objs = json_decode(stripslashes($_POST['images'])); } $j=0; while (list(, $value) = @each($objs)) {$j++;} if($j==0){//(is_object($objs)){// echo '{"result":"error","errorType":"notObj"}'; exit(); } $sql = "SELECT * FROM ".$bsg->default_options['bsg_gallery']." WHERE gallery_id = ".$_POST['gallery_id']; $results = $wpdb->get_row($sql); $return.= '"gallery":"'.$results->gallery_js.'"'; $sql = "INSERT INTO ".$bsg->default_options['bsg_album']; $sql .= " (album_title, gallery_id, album_params, album_css, "; $sql .= " album_framework, album_uselarge, album_structure) VALUES ('"; $sql .= $wpdb->escape($_POST['album_title'])."',"; $sql .= $_POST['gallery_id'].",'"; $sql .= $wpdb->escape($_POST['album_params'])."','"; $sql .= $results->gallery_css."','"; $sql .= $results->gallery_framework."',"; $sql .= $wpdb->escape($_POST['album_uselarge']).",'"; $sql .= $wpdb->escape($_POST['album_structure'])."')"; $wpdb->query($sql); /* $pattern = '/gvContainer/'; echo '
';
echo preg_replace($pattern, '#me', $css);
*/
		$id = mysql_insert_id();
		$sql = "UPDATE ".$bsg->default_options['bsg_album'];
		$sql .= " SET album_css = '".preg_replace(array('/#bsg/','/{BSGPATH}/'), array('#bsg'.$id,$bsg->default_options['bsg_js'].$results->gallery_js),$results->gallery_css) ."'";
		$sql .= " WHERE album_id = " . $id;
		$wpdb->query($sql);//
		
		
		//

		foreach($objs as $obj => $v){
			$sql = "INSERT INTO ".$bsg->default_options['bsg_photos']." (photo_alt, photo_url, photo_tnurl, photo_order,album_id) VALUES ('".$wpdb->escape($v->alt)."','".$v->url."','".$v->tnurl."','".$obj."',$id)";
			$wpdb->query($sql);
		}
		echo '{"result":"done","id":'.$id.",".$return.'}';
		
		break;
	case 'update':
		if (!extension_loaded('json')){
			include($bsg->dir.'/common/inc/JSON.php');
			$json = new JSON;
			$objs = $json->unserialize(stripslashes($_POST['images']));
		}
		else{
			$objs = json_decode(stripslashes($_POST['images']));
		}

		if(!is_array($objs) && !is_a($objs[0], 'stdClass')){
			echo '{"result":"error","errorType":"notObj"}';
			exit();
		}

		$return = '';

		$sql = "SELECT * FROM ".$bsg->default_options['bsg_gallery']." WHERE gallery_id = ".$_POST['gallery_id'];
		$results = $wpdb->get_row($sql);
		$return.= '"gallery":"'.$results->gallery_js.'"';

		$sql = "UPDATE ".$bsg->default_options['bsg_album']." SET album_title='".$wpdb->escape($_POST['album_title']);
		$sql .= "', gallery_id=".$_POST['gallery_id'];
		$sql .= ", album_params='".$wpdb->escape($_POST['album_params']);
		$sql .= "', album_uselarge=".$wpdb->escape($_POST['album_uselarge']);
		$sql .= ", album_css='".preg_replace(array('/#bsg/','/{BSGPATH}/'), array('#bsg'.$id,$bsg->default_options['bsg_js'].$results->gallery_js),$results->gallery_css);
		$sql .= "', album_structure='".$wpdb->escape($_POST['album_structure'])."' ";
		$sql .= " WHERE album_id = ".$_POST['id']." LIMIT 1";
		$wpdb->query($sql);

		$id = $_POST['id'];
		
		$sql = "DELETE FROM ".$bsg->default_options['bsg_photos']." WHERE album_id = ".$_POST['id'];
		$wpdb->query($sql);

		foreach($objs as $obj => $v){
			$sql = "INSERT INTO ".$bsg->default_options['bsg_photos']." (photo_alt, photo_url, photo_tnurl, photo_order,album_id) VALUES ('".$wpdb->escape($v->alt)."','".$v->url."','".$v->tnurl."','".$obj."',$id)";
			$wpdb->query($sql);
		}

		echo '{"result":"done","id":'.$id.','.$return.'}';
		
		break;
	case 'css':
		header('Content-type: text/css');
		$bsg->print_css();
		break;
	case 'edit_styles':
		$bsg->print_js('edit_styles');
		break;
	case 'update_styles':
		echo $bsgAdmin->update_styles();
		break;
	case 'edit_image_attr':
		$bsg->print_js('edit_image_attr');
		break;
	case 'update_photos':
		echo $bsgAdmin->update_photos();
		break;
	case 'core':
		$bsg->print_js('core');
		break;
	case 'preview':
		$bsgPreview = new bsg(__FILE__);
		$bsgPreview->build_js($_GET['aid']);
		break;
		
}


/**
 * function 	: cleanSQL
 * purpuse	: to help with sql injections
 */
if(!function_exists('cleanSQL')){
	function cleanSQL($theValue, $theType){
		/*if(get_magic_quotes_gpc()){
			$theValue = stripslashes($theValue);
		}
		if (phpversion() >= '4.3.0'){
			$theValue = mysql_real_escape_string($theValue);
		}
		else{
			$theValue = mysql_escape_string($theValue);
		}*/
		switch ($theType) {
			case "text":
				$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
				break;    
			case "long":
			case "int":
				$theValue = ($theValue != "") ? intval($theValue) : "NULL";
				break;
			case "double":
				$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
				break;
			case "date":
				$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
				break;
			default:
				$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
				break;  
		}
		return $theValue;
	}
}
?>