bsg_album = $wpdb->prefix . "bsg_album";
$wpdb->bsg_gallery = $wpdb->prefix . "bsg_gallery";
$wpdb->bsg_photos = $wpdb->prefix . "bsg_photos";
$wpdb->bsg_ablumTable_version = ".1";
$wpdb->bsg_galleryTable_version = ".1";
$wpdb->bsg_photosTable_version = ".1";
define('BSG_DIR', dirname(__FILE__));
define('BSG_BUILD_FUNCTIONS', get_bloginfo('wpurl').'/wp-content/plugins/' . basename(BSG_DIR) . '/bsg-build-function.php');
define('BSG_GALLERYSCRIPTS', get_bloginfo('wpurl').'/wp-content/plugins/' . basename(BSG_DIR) . '/galleryScripts/');
function bsg_getAlbum($id=0){
global $wpdb;
$sql = "SELECT * FROM $wpdb->bsg_album WHERE album_id = ".cleanSQL($id,'int');
return $wpdb->get_row($sql);
}
function bsg_retievePhotosBuild($album_id=0,$gallery_id=0,$params=NULL){
global $wpdb;
$sql = "SELECT * FROM $wpdb->bsg_gallery WHERE gallery_id = ".$gallery_id;
$r = $wpdb->get_row($sql);
$r = $r->gallery_js;
$imgJSON = '';
$sql = "SELECT * FROM $wpdb->bsg_photos WHERE album_id=".cleanSQL($album_id, "int")." ORDER BY photo_order ASC";
$results = $wpdb->get_results($sql);
$return = '
';
$cnt = 0;
$rcnt = $wpdb->get_var("SELECT COUNT(album_id) FROM $wpdb->bsg_photos WHERE album_id=".cleanSQL($album_id, "int"));
foreach ($results as $result) {
$return.= '
';
$imgJSON .= 'encodeURIComponent(\'{"tnurl":"'.$result->photo_tnurl.'","url":"'.$result->photo_url.'","alt":"'.addslashes($result->photo_alt).'"}\')';
if($rcnt != $cnt+1){
$imgJSON .= ',';
}
$cnt++;
}
echo $return .= '
';
if (!extension_loaded('json')){
include_once('common/inc/JSON.php');
$json = new JSON;
$objs = $json->unserialize(stripslashes($params));
}
else{
$objs = json_decode(stripslashes($params));
}
$tmp = array();
if($objs){
foreach($objs as $obj => $k){
$k = (is_numeric($k) || is_bool($k)) ? $k : '"'.$k.'"';
array_push($tmp, $obj . ':' . $k);
}
}
if (function_exists('wp_register_script')) {
wp_register_script('bsg_javascript', get_bloginfo('wpurl') . '/wp-content/plugins/' . basename(BSG_DIR) . '/galleryScripts/'.$r.'/'.$r.'.js');
wp_print_scripts('bsg_javascript');
}
echo '
';
}
function bsg_retievePhotosTnBuild($album_id=0){
global $wpdb;
$sql = "SELECT * FROM $wpdb->bsg_photos WHERE album_id=".cleanSQL($album_id, "int")." ORDER BY photo_order ASC";
$results = $wpdb->get_results($sql);
$return = '';
foreach ($results as $result) {
echo "\n";
$return.= '
photo_tnurl.'","url":"'.$result->photo_url.'","alt":"'.htmlentities($result->photo_alt,ENT_QUOTES).'"}').'"/>';
}
echo $return;
echo '
';
}
function bsg_retrieveOptionTable($params=NULL, $gallery_id=0){
global $wpdb;
if($params == NULL){
echo '
';
}
else{
if (!extension_loaded('json')){
include_once('common/inc/JSON.php');
$json = new JSON;
$objs = $json->unserialize(stripslashes($params));
}
else{
$objs = json_decode(stripslashes($params));
}
$sql = "SELECT * FROM $wpdb->bsg_gallery WHERE gallery_id = ".cleanSQL($gallery_id, "int");
$r = $wpdb->get_row($sql);
if (!extension_loaded('json')){
include_once('common/inc/JSON.php');
$json = new JSON;
$galparams = $json->unserialize(stripslashes($r->gallery_params));
}
else{
$galparams = json_decode(stripslashes($r->gallery_params));
}
$return = '';
if($galparams->parameters){
foreach ($galparams->parameters as $galparam => $v) {
$return .= '| '.$v->param.' | param;
$return .= ($objs->$tmp) ? ' value="'.$objs->$tmp.'" ' : '';
$return .= '/> | '.$v->desc.' |
';
}
}
echo $return;
}
}
// start : bsg_config_page
function bsg_config_page() {
if ( function_exists('add_submenu_page') )
add_submenu_page('options-general.php', __('BSG Configuration'), __('BSG Configuration'), 'manage_options', 'bsg-config', 'bsg_conf');
}
// end : bsg_config_page
if(!function_exists('bsg_getGalleries')) {
function bsg_getGalleries($id=0){
global $wpdb;
$sql = "SELECT * FROM $wpdb->bsg_gallery";
$results = $wpdb->get_results($sql);
$return = '';
}
}
/**
$sql = 'INSERT INTO `wp_dummy`.`wp_bsg_gallery` (`gallery_id`, `gallery_title`, `gallery_js`, `gallery_css`, `gallery_example`) VALUES (NULL, \'jQuery Gallery Viewer\', \'jqGalView\', \'\', \'http://benjaminsterling.com/?p=6\');';
$sql = 'INSERT INTO `wp_dummy`.`wp_bsg_gallery` (`gallery_id`, `gallery_title`, `gallery_js`, `gallery_css`, `gallery_example`) VALUES (NULL, \'jQuery Gallery Viewer II\', \'jqGalViewII\', \'\', \'http://benjaminsterling.com/?p=14\'), (NULL, \'jQuery Gallery Viewer III\', \'jqGalViewIII\', \'\', \'http://benjaminsterling.com/?p=17\');';
**/
add_action('wp_head', 'bsg_head');
if(!function_exists('bsg_head')) {
function bsg_head() {
echo '
';
}
}
// start : options
add_option('bsg_skip_jq', '0', 'Benjamin Sterling Galleries Plugin. Flag to skip adding jquery.js code on page', false);
// end : options
/**
* function : put_gallery
* purpose : This is so you can put the gallery into a post or excerpt
*/
add_filter('the_content', 'put_gallery', '10');
add_filter('the_excerpt', 'put_gallery', '10');
if(!function_exists('put_gallery')) {
function put_gallery($content){
if(!is_feed()) {
$content = preg_replace("/\[gallery=(\d+)\]/ise", "display_gallery('\\1',false,false)", $content);
} else {
$content = preg_replace("/\[gallery=(\d+)\]/ise", "display_gallery('\\1',true,false)", $content);
}
return $content;
}
}
/**
* function : display_gallery
* purpose :
*/
if(!function_exists('display_gallery')) {
function display_gallery($album_id=0,$hideCSSJS=false) {
global $wpdb;
// the final return holder
$return = '';
$sql = "SELECT * FROM $wpdb->bsg_album WHERE album_id = ".cleanSQL($album_id,'int');
$ablum = $wpdb->get_row($sql);
$sql = "SELECT * FROM $wpdb->bsg_gallery WHERE gallery_id = ".$ablum->gallery_id;
$gallery = $wpdb->get_row($sql);
$gallery = $gallery->gallery_js;
$sql = "SELECT * FROM $wpdb->bsg_photos WHERE album_id=".cleanSQL($album_id, "int")." ORDER BY photo_order ASC";
$results = $wpdb->get_results($sql);
$return = '';
$cnt = 0;
$rcnt = $wpdb->get_var("SELECT COUNT(album_id) FROM $wpdb->bsg_photos WHERE album_id=".cleanSQL($album_id, "int"));
foreach ($results as $result) {
$return.= '
';
}
$return .= '
';
if(!$hideCSSJS){
if (function_exists('wp_register_script')) {
wp_register_script('bsg_jquery', get_bloginfo('wpurl') . '/wp-content/plugins/' . basename(BSG_DIR) . '/common/js/jquery-1.2.1.min.js');
wp_print_scripts('bsg_jquery');
wp_register_script('bsg_javascript', get_bloginfo('wpurl') . '/wp-content/plugins/' . basename(BSG_DIR) . '/galleryScripts/'.$gallery.'/'.$gallery.'.js');
wp_print_scripts('bsg_javascript');
}
if (!extension_loaded('json')){
include_once('common/inc/JSON.php');
$json = new JSON;
$objs = $json->unserialize(stripslashes($ablum->album_params));
}
else{
$objs = json_decode(stripslashes($ablum->album_params));
}
$tmp = array();
if($objs){
foreach($objs as $obj => $k){
$k = (is_numeric($k) || is_bool($k)) ? $k : '"'.$k.'"';
array_push($tmp, $obj . ':' . $k);
}
}
$return .= '
';
} // show css and javascript
if($show){
echo $return;
}
else{
return $return;
}
}
}
/**
* function : cleanSQL
* purpuse : to help with sql injections
*/
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;
}
add_action('admin_head', 'bsg_admin_head');
if(!function_exists('bsg_admin_head')) {
function bsg_admin_head(){
echo '
';
}
}
/**
* function : bsg_menu
*/
add_action('admin_menu', 'bsg_menu');
if(!function_exists('bsg_menu')) {
function bsg_menu() {
if (function_exists('add_menu_page')) {
add_menu_page('BSG','BSG', 7, basename(BSG_DIR) . '/bsg-manager.php');
}
if (function_exists('add_submenu_page')) {
add_submenu_page(basename(BSG_DIR) . '/bsg-manager.php', 'Manage Galleries', 'Manage Galleries', 7, basename(BSG_DIR) . '/bsg-manager.php');
add_submenu_page(basename(BSG_DIR) . '/bsg-manager.php', 'Build Gallery', 'Build Gallery', 7, basename(BSG_DIR) . '/bsg-build.php');
add_submenu_page(basename(BSG_DIR) . '/bsg-manager.php', 'BSG Usage', 'BSG Usage', 7, basename(BSG_DIR) . '/bsg-usage.php');
}
}
} // end : bsg_menu
add_action('activate_' . basename(BSG_DIR) . '/benjaminSterlingGalleries.php','bsg_install');
if(!function_exists('bsg_install')) {
function bsg_install(){
global $wpdb;
require_once(ABSPATH . 'wp-admin/upgrade-functions.php');
$bsg_album = $wpdb->bsg_album;
if($wpdb->get_var("show tables like '$bsg_album'") != $bsg_album) {
$sql = "CREATE TABLE " . $bsg_album . " (
album_id mediumint(9) NOT NULL AUTO_INCREMENT PRIMARY KEY,
album_title VARCHAR(100) NOT NULL,
gallery_id mediumint(9) DEFAULT '0' NULL,
album_params VARCHAR(255) NULL
);";
dbDelta($sql);
add_option("bsg_ablumTable_version", $wpdb->bsg_ablumTable_version);
}
$bsg_gallery = $wpdb->bsg_gallery;
if($wpdb->get_var("show tables like '$bsg_gallery'") != $bsg_gallery) {
$sql = "CREATE TABLE " . $bsg_gallery . " (
gallery_id mediumint(9) NOT NULL AUTO_INCREMENT PRIMARY KEY,
gallery_title VARCHAR(100) NOT NULL,
gallery_js VARCHAR(100) NOT NULL,
gallery_css VARCHAR(100) NOT NULL,
gallery_example VARCHAR(255) NULL,
gallery_params TEXT NULL
);";
dbDelta($sql);
$sql = "INSERT INTO " . $bsg_gallery . " (gallery_id, gallery_title, gallery_js, gallery_css, gallery_example, gallery_params) VALUES (1, 'jQuery Gallery Viewer', 'jqGalView', '', 'http://benjaminsterling.com/?p=6', '{\"parameters\":[{\"param\":\"openTxt\",\"desc\":\"The text you want to have shown when you hover over a thumbnail\"},{\"param\":\"backTxt\",\"desc\":\"The text that gets append to the full images title attribute to give a hint for the user to click to return to the thumbnails\"}, {\"param\":\"goFullSizeTxt\",\"desc\":\"The text that gets appended after the alt text when the full sized image is being view and will allow the user to view the resized full image in a new browser window or in the modal box\"}, {\"param\":\"title\",\"desc\":\"Set to null by default and will allow you to add a title to gallery if not already set in a title tag of the parent element of the thumbnail group\"}]}'),
(2, 'jQuery Gallery Viewer II', 'jqGalViewII', '', 'http://benjaminsterling.com/?p=14', ''), (3, 'jQuery jqGalScroll Plugin', 'jqGalScroll', '', 'http://benjaminsterling.com/?p=8', '{\r\n \"parameters\":\r\n [\r\n {\r\n \"param\":\"speed\",\r\n \"desc\":\"fast, slow, 1000, ext..\"\r\n },\r\n {\r\n \"param\":\"height\",\r\n \"desc\":\"the default height of your wrapper\"\r\n },\r\n {\r\n \"param\":\"width\",\r\n \"desc\":\"the default width of your wrapper\"\r\n },\r\n {\r\n \"param\":\"titleOpacity\",\r\n \"desc\":\"the opacity of your title bar (if present)\"\r\n }\r\n ]\r\n}'), (4, 'cycle', 'cycle', 'f', 'http://www.malsup.com/jquery/cycle/', '{\r\n \"parameters\":[\r\n {\r\n \"param\":\"fx\",\r\n \"desc\":\"one of: fade, shuffle, zoom, slideX, slideY, scrollUp/Down/Left/Right\"\r\n },\r\n {\r\n \"param\":\"timeout\",\r\n \"desc\":\"milliseconds between slide transitions (0 to disable auto advance) \"\r\n },\r\n {\r\n \"param\":\"speed\",\r\n \"desc\":\"speed of the transition (any valid fx speed value) \"\r\n },\r\n {\r\n \"param\":\"speedIn\",\r\n \"desc\":\"speed of the `in` transition \"\r\n },\r\n {\r\n \"param\":\"speedOut\",\r\n \"desc\":\"peed of the `out` transition\"\r\n },\r\n {\r\n \"param\":\"easing\",\r\n \"desc\":\"easing method for both in and out transitions \"\r\n },\r\n {\r\n \"param\":\"easeIn\",\r\n \"desc\":\"easing for `in` transition \"\r\n },\r\n {\r\n \"param\":\"easeOut\",\r\n \"desc\":\"easing for `out` transition \"\r\n },\r\n {\r\n \"param\":\"shuffle\",\r\n \"desc\":\"coords for shuffle animation, ex: { top:15, left: 200 } \"\r\n },\r\n {\r\n \"param\":\"animIn\",\r\n \"desc\":\"properties that define how the slide animates in \"\r\n },\r\n {\r\n \"param\":\"animOut\",\r\n \"desc\":\"properties that define how the slide animates out \"\r\n },\r\n {\r\n \"param\":\"height\",\r\n \"desc\":\"container height \"\r\n },\r\n {\r\n \"param\":\"sync\",\r\n \"desc\":\"true if in/out transitions should occur simultaneously \"\r\n },\r\n {\r\n \"param\":\"random\",\r\n \"desc\":\"true for random, false for sequence (not applicable to shuffle fx)\"\r\n },\r\n {\r\n \"param\":\"fit\",\r\n \"desc\":\"force slides to fit container \"\r\n },\r\n {\r\n \"param\":\"pause\",\r\n \"desc\":\"true to enable `pause on hover` \"\r\n },\r\n {\r\n \"param\":\"autostop\",\r\n \"desc\":\"true to end slideshow after X transitions (where X == slide count) \"\r\n },\r\n {\r\n \"param\":\"delay\",\r\n \"desc\":\"additional delay (in ms) for first transition (hint: can be negative)}; \"\r\n }\r\n ]\r\n}')";
$wpdb->query($sql);
add_option("bsg_galleryTable_version", $wpdb->bsg_galleryTable_version);
}
$bsg_photos = $wpdb->bsg_photos;
if($wpdb->get_var("show tables like '$bsg_photos'") != $bsg_photos) {
$sql = "CREATE TABLE " . $bsg_photos . " (
`photo_id` mediumint(9) NOT NULL auto_increment,
`photo_alt` varchar(255) default NULL,
`photo_url` varchar(255) NOT NULL,
`photo_tnurl` varchar(255) NOT NULL,
`photo_order` int(3) NOT NULL default '99',
`album_id` int(3) NOT NULL,
PRIMARY KEY (`photo_id`)
);";
dbDelta($sql);
add_option("bsg_photosTable_version", $wpdb->bsg_photosTable_version);
}
}
} // end : bsg_install
add_action('deactivate_' . basename(BSG_DIR) . '/benjaminSterlingGalleries.php','bsg_unintall');
if(!function_exists('bsg_unintall')) {
function bsg_unintall(){
global $wpdb, $user_level;
if ( $user_level >= 10 ) {
$bsg_album = $wpdb->bsg_album;
mysql_query(" DROP TABLE $bsg_album ") or die("An unexpected error occured.".mysql_error());
$bsg_gallery = $wpdb->bsg_gallery;
mysql_query(" DROP TABLE $bsg_gallery ") or die("An unexpected error occured.".mysql_error());
$bsg_photos = $wpdb->bsg_photos;
mysql_query(" DROP TABLE $bsg_photos ") or die("An unexpected error occured.".mysql_error());
delete_option('bsg_skip_jq');
remove_action('wp_head', 'bsg_head');
}
}
} // end : bsg_unintall
?>