pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

PHP pastebin - collaborative debugging tool View Help


Posted by bmsterling on Mon 12 May 04:24 (modification of post by view diff)
report spam | View followups from giluo | download | new post

  1. <?php
  2. //error_reporting(E_ERROR | E_WARNING);
  3. header('Content-Type: text/html; charset=UTF-8');
  4. include_once('core.php');
  5. if(!class_exists("px")){
  6.         class px extends px_core{
  7.                 var $dirName;
  8.                 var $dirPath;
  9.                 var $options;
  10.                 var $parentFile;
  11.                 var $baseFile;
  12.                 var $vars;
  13.                
  14.                 var $api_smugmug = '8vjhYpC7wz53UTdspu33yRaYXEPgrU5D';
  15.                 var $api_flickr = '99c12772538849fb2890645771d923f9';
  16.                  
  17.                 var $cur_album_id = 0;
  18.                 var $cur_album_info = NULL;
  19.                  
  20.                 var $cur_gallery_id = 0;
  21.                 var $cur_gallery_info = NULL;
  22.                 var $cur_image_group = array();
  23.                 var $cur_return = '';
  24.                 var $cur_js_func = '';
  25.                 var $cur_js_show = '';
  26.                
  27.                 var $cur_upload_dir = '';
  28.                 var $cur_album_dir = '';
  29.                 var $cur_image_info = '';
  30.                
  31.                 var $album_list = '';
  32.                
  33.                 var $safe_mode = false;
  34.                
  35.                 function px($file=''){
  36.                         global $wpdb;
  37.                         $this->baseFile = $file;
  38.                         $this->baseName = plugin_basename($this->baseFile);
  39.                         $this->dirPath = dirname($file);
  40.                         $this->dirName = basename($this->dirPath);
  41.                         $this->parentFile = array_pop( explode  ('\\',$file) );
  42.                         $this->parentFileUrl = get_bloginfo('wpurl')  . '/wp-content/plugins/' . $this->baseName;
  43.  
  44.                         $options = array(
  45.                                 // database tables
  46.                                 'albums' => $wpdb->prefix . "px_albums",
  47.                                 'albums_version' => "1.2",
  48.                                
  49.                                 'albumPhotos' => $wpdb->prefix . "px_albumPhotos",
  50.                                 'albumPhotos_version' => "1.2",
  51.  
  52.                                 'galleries' => $wpdb->prefix . "px_galleries",
  53.                                 'galleries_version' => "1.2",
  54.  
  55.                                 'photos' => $wpdb->prefix . "px_photos",
  56.                                 'photos_version' => "1.2",
  57.                                
  58.                                 'plugins' => $wpdb->prefix . "px_plugins",
  59.                                 'plugins_version' => "1.2",
  60.  
  61.                                 'js' => get_bloginfo('wpurl') . '/wp-content/plugins/' . $this->dirName . '/common/js/',
  62.  
  63.                                 'css' => get_bloginfo('wpurl') . '/wp-content/plugins/' . $this->dirName . '/common/css/',
  64.  
  65.                                 'img' => get_bloginfo('wpurl') . '/wp-content/plugins/' . $this->dirName . '/common/img/',
  66.                                
  67.                                 'pluginjs' => get_bloginfo('wpurl') . '/wp-content/plugins/' . $this->dirName . '/galleryScripts/',
  68.                                
  69.                                 'parts' => get_bloginfo('wpurl') . '/wp-content/plugins/' . $this->dirName . '/common/inc/pages/parts/'
  70.                         );
  71.                         $this->options = $options;
  72.                         unset($options);
  73.  
  74.  
  75.                         if ((gettype(ini_get('safe_mode')) == 'string')) {
  76.                                 if (ini_get('safe_mode') == 'off'){
  77.                                         $this->safe_mode = false;
  78.                                 }
  79.                                 else{
  80.                                         $this->safe_mode = ini_get('safe_mode');
  81.                                 }
  82.                         }
  83.                         else{
  84.                                 echo ini_get('safe_mode');
  85.                                 $this->safe_mode = ini_get('safe_mode');
  86.                         }
  87.                        
  88.                         add_action('admin_menu', array(&$this, 'adminMenu'));
  89.                        
  90.                         if( isset( $_POST['onetimer'] ) ){
  91.                                 $this->onetimers( $_POST['onetimer'] );
  92.                         }
  93.                         parent::px_core($file);
  94.                         unset($file);
  95.                         $this->init();
  96.                 }
  97.  
  98.  
  99.                 /**
  100.                  *     
  101.                  */
  102.                 function init(){
  103.                         add_action('activate_' . $this->dirName . '/photoxhibit.php',array(&$this,'install'));
  104.                         add_action('deactivate_' . $this->dirName . '/photoxhibit.php',array(&$this,'unintall'));
  105.                 }
  106.  
  107.                 function unintall(){}
  108.  
  109.  
  110.                 /**
  111.                  *     
  112.                  */
  113.                 function adminMenu(){
  114.                         if (function_exists('add_menu_page')) {
  115.                                 add_menu_page('PhotoXhibit','PhotoXhibit', 7, $this->baseFile, array(&$this, 'adminOverView'));
  116.                         }
  117.                         if (function_exists('add_submenu_page')) {
  118.                                 add_submenu_page($this->baseFile, __('OverView', 'photoxhibit'), __('OverView', 'photoxhibit'), 7, $this->baseFile, array(&$this, 'adminOverView'));
  119.                                 add_submenu_page($this->baseFile, __('Manage Gallery', 'photoxhibit'), __('Manage Gallery', 'photoxhibit'), 7, 'px_manage', array(&$this, 'adminManageGallery'));
  120.                                 add_submenu_page($this->baseFile, __('Build Gallery', 'photoxhibit'), __('Build Gallery', 'photoxhibit'), 7, 'px_build', array(&$this, 'adminBuild'));
  121.                        
  122.                                 add_submenu_page($this->baseFile, __('Manage Album', 'photoxhibit'), __('Manage Album', 'photoxhibit'), 7, 'px_manageAlbum', array(&$this, 'adminManageAlbum'));
  123.  
  124.                                 add_submenu_page($this->baseFile, __('Options', 'photoxhibit'), __('Options', 'photoxhibit'), 7, 'px_options', array(&$this, 'adminOptions'));
  125.  
  126.                                 add_submenu_page($this->baseFile, __('About', 'photoxhibit'), __('About', 'photoxhibit'), 7, 'px_about', array(&$this, 'adminAbout'));
  127.                         }
  128.                 }  //  end : adminMenu()
  129.                
  130.                 function edit_image_form( $id = NULL ){
  131.                         global $wpdb;
  132.                         if( $id == NULL ){
  133.                                 $id = $_GET['iid'];
  134.                         }
  135.                         $this->cur_image_info = $wpdb->get_row("SELECT * FROM ".$this->options['albumPhotos']." WHERE albumPhotos_id = ".$wpdb->escape($id));
  136.                         if( !empty($_GET['iid']) ){
  137.                                 include($this->dirPath.'/common/views/album/edit_image_attr.php');
  138.                         }
  139.                 }
  140.                
  141.                 function edit_image_single(){
  142.                         global $wpdb;
  143.                                 $sql = "UPDATE ".$this->options['albumPhotos'] . " SET
  144.                                                 albumPhotos_alt='". $wpdb->escape($_GET['albumPhotos_alt'])."',
  145.                                                 albumPhotos_tags='". $wpdb->escape($_GET['albumPhotos_tags'])."',
  146.                                                 albumPhotos_isactive='". $wpdb->escape($_GET['albumPhotos_isactive'])."' ,
  147.                                                 albumPhotos_desc='". $wpdb->escape($_GET['albumPhotos_desc'])."'
  148.                                                 WHERE albumPhotos_id=" . $wpdb->escape($_GET['albumPhotos_id']);
  149.                                 $wpdb->query($sql);
  150.                                
  151.                         echo '{"id":'.$_GET['albumPhotos_id'].'}';
  152.                        
  153.                 }
  154.                
  155.                 function delete_image( $id = NULL ){
  156.                         global $wpdb;
  157.                         if( $id == NULL ){
  158.                                 $id = $_GET['iid'];
  159.                         }
  160.                        
  161.  
  162.                         $this->edit_image_form( $id );
  163.                         $sql = "DELETE FROM ".$this->options['photos']." WHERE albumPhotos_id = " . $wpdb->escape($id) . " LIMIT 1";
  164.                         @mysql_query( $sql ) or die("An unexpected error occured.".mysql_error());
  165.                         $sql = "DELETE FROM ".$this->options['albumPhotos']." WHERE albumPhotos_id = " . $wpdb->escape($id) . " LIMIT 1";
  166.                         @mysql_query( $sql ) or die("An unexpected error occured.".mysql_error());
  167.                         $options = get_option('photoxhibit');
  168.                        
  169.  
  170.                         if( $options['options_delete'] == 1 ){
  171.                                 $this->get_upload_dir($this->cur_image_info->album_id);
  172.  
  173.                                 $dir = $this->cur_upload_dir;
  174.  
  175.                                 @unlink($dir . '/' . $this->cur_image_info->albumPhotos_file . '.' . $this->cur_image_info->albumPhotos_ext);
  176.                                 @unlink($dir . '/' . $this->cur_image_info->albumPhotos_file . '_tn.' . $this->cur_image_info->albumPhotos_ext);
  177.                                 @unlink($dir . '/' . $this->cur_image_info->albumPhotos_file . '_ltn.' . $this->cur_image_info->albumPhotos_ext);
  178.                                 @unlink($dir . '/' . $this->cur_image_info->albumPhotos_file . '_o.' . $this->cur_image_info->albumPhotos_ext);
  179.                         }
  180.  
  181.                         if( $id != NULL ){
  182.                                 echo '{"complete":true}';
  183.                                 exit(0);
  184.                         }
  185.                 }
  186.  
  187.                 /**
  188.                  *     
  189.                  */
  190.                 function get_set_album($get){
  191.                         global $wpdb;
  192.                         $id = $get['album_id'];
  193.                        
  194.                         if( $id == 0 ){
  195.                                 $sql = "INSERT INTO ".$this->options['albums'] . "
  196.                                                 (album_name) VALUES ('". $wpdb->escape($get['album_name'])."')";
  197.                                 $wpdb->query($sql);
  198.  
  199.                                 $id = mysql_insert_id();
  200.                         }
  201.                         else{
  202.                                 $sql = "UPDATE ".$this->options['albums'] . " SET album_name='". $wpdb->escape($get['album_name'])."' WHERE album_id=" . $id;
  203.                                 $wpdb->query($sql);
  204.                         }
  205.                                
  206.                         echo '{"id":'.$id.',"album_name":"'.$get['album_name'].'"}';
  207.                 }
  208.                
  209.                 function get_photos_from_album($id = NULL){
  210.                         global $wpdb;
  211.                         if( $id == NULL ){
  212.                                 $id = $_GET['aid'];
  213.                         }
  214.                         return $wpdb->get_results("SELECT * FROM ".$this->options['albumPhotos']." WHERE album_id=".$wpdb->escape($id));
  215.                 }
  216.  
  217.  
  218.                 /**
  219.                  *     
  220.                  */
  221.                 function adminManageAlbum(){
  222.                         global $wpdb;
  223.  
  224.                         $this->styles = array('base.css');
  225.                         $this->loadCss();
  226.  
  227.                         $this->js = array('jquery','ui','core','json');
  228.                         $this->getOptions();
  229.                         $this->loadJs();
  230.                        
  231.                         $imageGroup = '';
  232.  
  233.                         if( isset($_GET['do']) ){
  234.                                 $this->imageUpload();
  235.                         }
  236.                        
  237.                         $this->vars = get_option('photoxhibit');
  238.                         if( isset( $_GET['aid'] ) ){
  239.                                 $imageGroup = $this->get_photos_from_album();
  240.                                 $this->get_album_dir();
  241.                         }
  242.  
  243.                         switch($_GET['action']){
  244.                                 case 'edit_images':
  245.                                         include($this->dirPath.'/common/views/album/edit_images.php');
  246.                                         break;
  247.                                 case 'edit_image':
  248.                                         include('pages/parts/edit_image.php');
  249.                                         break;
  250.                                 case 'build_album':
  251.                                         include('pages/build_album.php');
  252.                                         break;
  253.                                 case 'delete_album':
  254.                                         $this->deleteAlbum();
  255.                                 default:
  256.                                         include('pages/albumManager.php');
  257.                         }
  258.                 }  //  end : adminManageGallery()
  259.                
  260.                 function deleteAlbum(){
  261.                         global $wpdb;
  262.                 //      $sql = "DELETE FROM ".$this->options['albums']." WHERE album_id = " . $wpdb->escape($_GET['aid']) . " LIMIT 1";
  263.                 //      @mysql_query( $sql ) or die("(deleteAlbum) An unexpected error occured.".mysql_error());
  264.                        
  265.                         $options = get_option('photoxhibit');
  266.                        
  267.                         if( $options['options_dropall'] == 1 ){
  268.  
  269.                                 $this->get_upload_dir($_GET['aid']);
  270.                                 $this->removeFolder($this->cur_upload_dir);
  271.  
  272.                                 $results = $wpdb->get_results("SELECT albumPhotos_id FROM ".$this->options['albumPhotos']."
  273.                                                                                         WHERE album_id=".$wpdb->escape($_GET['aid']));
  274.                                 if(is_array($results) && is_a($results[0], 'stdClass')){
  275.                                         foreach($results as $result => $v){
  276.                                                 $sql = "DELETE FROM ".$this->options['photos']."
  277.                                                                 WHERE albumPhotos_id = " . $wpdb->escape($v->albumPhotos_id) . "
  278.                                                                 LIMIT 1";
  279.                                                 @mysql_query( $sql ) or die("An unexpected error occured.".mysql_error());
  280.                                         }
  281.                                 }
  282.                                
  283.                                 $sql = "DELETE FROM ".$this->options['albumPhotos']."
  284.                                                 WHERE album_id = " . $wpdb->escape($_GET['aid']);
  285.                                 @mysql_query( $sql ) or die("An unexpected error occured.".mysql_error());
  286.  
  287.                         }
  288.                         else{
  289.                                 $sql = "UPDATE ".$this->options['albumPhotos'] ."
  290.                                                 SET album_id = 0
  291.                                                 WHERE album_id = " . $_GET['aid'];
  292.                                 $wpdb->query($sql);                    
  293.                         }
  294.  
  295.                         $sql = "DELETE FROM ".$this->options['albums']." WHERE album_id = " . $wpdb->escape($_GET['aid']) . " LIMIT 1";
  296.                         @mysql_query( $sql ) or die("An unexpected error occured.".mysql_error());
  297.                 }
  298.  
  299.                 function removeFolder($dir){
  300.                         if(!is_dir($dir))
  301.                                 return false;
  302.                         for($s = DIRECTORY_SEPARATOR, $stack = array($dir), $emptyDirs = array($dir); $dir = array_pop($stack);){
  303.                                 if(!($handle = @dir($dir)))
  304.                                         continue;
  305.                                 while(false !== $item = $handle->read())
  306.                                         $item != '.' && $item != '..' && (is_dir($path = $handle->path . $s . $item) ?
  307.                                         array_push($stack, $path) && array_push($emptyDirs, $path) : unlink($path));
  308.                                 $handle->close();
  309.                         }
  310.                         for($i = count($emptyDirs); $i--; rmdir($emptyDirs[$i]));
  311.                 }
  312.  
  313.  
  314.                 /**
  315.                  *      Load overview page
  316.                  */
  317.                 function adminOverView(){
  318.                         $this->write_baseCss();
  319.                         $this->checkforblogrollentry();
  320.                         include('pages/overview.php');
  321.                 }  //  end : adminOverView()
  322.  
  323.                
  324.                 function update_styles($local = false){
  325.                         global $wpdb;//editStyles
  326.                        
  327.                         if($local){
  328.                        
  329.                                 $return = '';
  330.                                 $returnA = array();
  331.                                 //if(empty($_POST['px_stylesTextarea'])) array_push($returnA,'{"error":"error_no_styles"}');
  332.                                 if(empty($_POST['gid'])) array_push($returnA,__('No gallery id'));
  333.                                
  334.                                 if( count($returnA) <= 0 ){
  335.                                         $sql = "UPDATE " . $this->options['galleries'] . " SET gallery_css='".$wpdb->escape($_POST['px_stylesTextarea']) ."' WHERE gallery_id = " . $wpdb->escape($_POST['gid']);
  336.                                         $r = @mysql_query($sql) or die("An unexpected error occured.".mysql_error());;
  337.                                 }
  338.                                 if($r){
  339.                                         echo '<div class="wrap">'.__('Styles have been updated') .'</div>';
  340.                                 }
  341.                                 else{
  342.                                         echo '<div class="wrap">' . __('Error(s) on update:') . '<br/>' . join('<br/>',$returnA) .'</div>';
  343.                                 }
  344.                         }
  345.                         else{
  346.                        
  347.                                 $return = '';
  348.                                 $returnA = array();
  349.                                 if(empty($_POST['styles'])) array_push($returnA,'{"error":"error_no_styles"}');
  350.                                 if(empty($_POST['gid'])) array_push($returnA,'{"error":"error_no_id"}');
  351.                                
  352.                                 if( count($returnA) <= 0 ){
  353.                                         $sql = "UPDATE " . $this->options['galleries'] . " SET gallery_css='".$wpdb->escape($_POST['styles']) ."' WHERE gallery_id = " . $wpdb->escape($_POST['gid']);
  354.                                         $r = @mysql_query($sql) or die("An unexpected error occured.".mysql_error());;
  355.                                 }
  356.                                 if($r){
  357.                                         echo '{"good":"no_errors"}';
  358.                                 }
  359.                                 else{
  360.                                         echo '['.'{"error":"error_update"}'.join(',',$returnA) . ']';
  361.                                 }
  362.                         }
  363.                 }
  364.  
  365.                 /**
  366.                  *      Load build page
  367.                  */
  368.                 function get_gallery_data($id=0){
  369.                         global $wpdb;
  370.                         $id = ($id==0) ? $this->cur_gallery_id : $id;
  371.                         $sql = "SELECT * FROM ".$this->options['galleries']." WHERE gallery_id = ".$wpdb->escape($id);
  372.                         return $wpdb->get_row($sql);
  373.                 }// end : get_album_data
  374.  
  375.  
  376.                 /**
  377.                  *      Get Gallery Information
  378.                  */
  379.                 function get_gallery_info(){
  380.                         global $wpdb;
  381.                         $this->cur_gallery_info = $this->get_gallery_data();
  382.                 }// end : get_album_info
  383.  
  384.  
  385.                 /**
  386.                  *      Build Image Gallery
  387.                  */
  388.                 function build_image_set($gallery_id=0, $r = false, $js = true){
  389.                         if( $gallery_id == 0 ) return;
  390.  
  391.                         $this->cur_gallery_id = $gallery_id;
  392.                         $this->cur_js_show = $js;
  393.                         $this->get_gallery_info();
  394.                        
  395.                         if($this->cur_gallery_info){
  396.                                 $this->get_js_func();
  397.                                 $this->get_imgs_group();
  398.                                 $this->buildout_images();
  399.                                
  400.                                 $this->get_css_link();
  401.                                 $this->get_js_code();
  402.                         }
  403.  
  404.                         if($r){
  405.                                 return $this->cur_return;
  406.                         }
  407.                         else{
  408.                                 echo $this->cur_return;
  409.                         }
  410.                  }  //  end :  function build_image_set()
  411.  
  412.  
  413.                 /**
  414.                  *     
  415.                  */
  416.                 function get_css_link(){
  417.                         $this->cur_return .= '<link id="px_editstylesheet" type="text/css" href="'.$this->parentFileUrl.'?option=css&gid='.$this->cur_gallery_id.'&'.time().'" rel="stylesheet"/>';
  418.                 }  // end : get_css_link
  419.  
  420.  
  421.                 /**
  422.                  *     
  423.                  */
  424.                 function get_js_func(){
  425.                         global $wpdb;
  426.                         $sql = "SELECT * FROM " . $this->options['plugins'] .' where plugin_id ='.$this->cur_gallery_info->plugin_id;
  427.                         $tmp = $wpdb->get_row($sql);
  428.                         $this->cur_js_func = $tmp->plugin_js;
  429.                 }  // end : get_js_func
  430.  
  431.  
  432.                 /**
  433.                  *     
  434.                  */
  435.                 function get_js_code(){
  436.                         if(!$this->cur_js_show) return;
  437.  
  438.                         if (!extension_loaded('json')){
  439.                                 include_once('JSON.php');
  440.                                 $json = new JSON;
  441.                                 $objs = $json->unserialize(stripslashes($this->cur_gallery_info->gallery_params));
  442.                         }
  443.                         else{
  444.                                 $objs = json_decode(stripslashes($this->cur_gallery_info->gallery_params));
  445.                         }
  446.                         $jsParam = array();
  447.                         if($objs){
  448.                                 foreach($objs as $obj => $k){
  449.                                         $k = (is_numeric($k) || is_bool($k)) ? $k : '"'.$k.'"';
  450.                                         array_push($jsParam, $obj . ':' . $k);
  451.