function install_smooth_slider()
{
    global $wpdb, $table_prefix;
    $table_name = $table_prefix . SLIDER_TABLE;
    if ($wpdb->get_var("show tables like '{$table_name}'") != $table_name) {
        $sql = "CREATE TABLE {$table_name} (\r\r\n\t\t\t\t\tid int(5) NOT NULL AUTO_INCREMENT,\r\r\n\t\t\t\t\tpost_id int(11) NOT NULL,\r\r\n\t\t\t\t\tdate datetime NOT NULL,\r\r\n\t\t\t\t\tslider_id int(5) NOT NULL DEFAULT '1',\r\r\n\t\t\t\t\tUNIQUE KEY id(id)\r\r\n\t\t\t\t);";
        $rs = $wpdb->query($sql);
        $prev_table_name = $table_prefix . PREV_SLIDER_TABLE;
        if ($wpdb->get_var("show tables like '{$prev_table_name}'") == $prev_table_name) {
            $prev_slider_data = ss_get_prev_slider();
            foreach ($prev_slider_data as $prev_slider_row) {
                $prev_post_id = $prev_slider_row['id'];
                $prev_date_time = $prev_slider_row['date'];
                if ($prev_post_id) {
                    $sql = "INSERT INTO {$table_name} (post_id,date) VALUES('{$prev_post_id}','{$prev_date_time}');";
                    $result = $wpdb->query($sql);
                }
            }
        }
    }
    add_column_if_not_exist($table_name, 'slide_order', "ALTER TABLE " . $table_name . " ADD slide_order int(5) NOT NULL DEFAULT '0';");
    $meta_table_name = $table_prefix . SLIDER_META;
    if ($wpdb->get_var("show tables like '{$meta_table_name}'") != $meta_table_name) {
        $sql = "CREATE TABLE {$meta_table_name} (\r\r\n\t\t\t\t\tslider_id int(5) NOT NULL AUTO_INCREMENT,\r\r\n\t\t\t\t\tslider_name varchar(100) NOT NULL default '',\r\r\n\t\t\t\t\tUNIQUE KEY slider_id(slider_id)\r\r\n\t\t\t\t);";
        $rs2 = $wpdb->query($sql);
        $sql = "INSERT INTO {$meta_table_name} (slider_id,slider_name) VALUES('1','Smooth Slider');";
        $rs3 = $wpdb->query($sql);
    }
    $slider_postmeta = $table_prefix . SLIDER_POST_META;
    if ($wpdb->get_var("show tables like '{$slider_postmeta}'") != $slider_postmeta) {
        $sql = "CREATE TABLE {$slider_postmeta} (\r\r\n\t\t\t\t\tpost_id int(11) NOT NULL,\r\r\n\t\t\t\t\tslider_id int(5) NOT NULL default '1',\r\r\n\t\t\t\t\tUNIQUE KEY post_id(post_id)\r\r\n\t\t\t\t);";
        $rs4 = $wpdb->query($sql);
    }
    // Need to delete the previously created options in old versions and create only one option field for Smooth Slider
    $default_slider = array();
    $default_slider = array('speed' => '7', 'no_posts' => '5', 'bg_color' => '#ffffff', 'height' => '200', 'width' => '450', 'border' => '1', 'brcolor' => '#999999', 'prev_next' => '0', 'goto_slide' => '1', 'title_text' => 'Featured Posts', 'title_font' => 'Georgia', 'title_fsize' => '20', 'title_fstyle' => 'bold', 'title_fcolor' => '#000000', 'ptitle_font' => 'Trebuchet MS', 'ptitle_fsize' => '14', 'ptitle_fstyle' => 'bold', 'ptitle_fcolor' => '#000000', 'img_align' => 'left', 'img_height' => '120', 'img_width' => '165', 'img_border' => '1', 'img_brcolor' => '#000000', 'content_font' => 'Verdana', 'content_fsize' => '12', 'content_fstyle' => 'normal', 'content_fcolor' => '#333333', 'content_from' => 'content', 'content_chars' => '300', 'bg' => '0', 'image_only' => '0', 'allowable_tags' => '', 'more' => 'Read More', 'img_size' => '1', 'img_pick' => array('1', 'slider_thumbnail', '1', '1', '1', '1'), 'user_level' => 'edit_others_posts', 'custom_nav' => '', 'crop' => '0', 'transition' => '5', 'autostep' => '1', 'multiple_sliders' => '0', 'navimg_w' => '32', 'navimg_ht' => '32', 'content_limit' => '50', 'stylesheet' => 'default.css', 'shortcode' => '1');
    $smooth_slider = get_option('smooth_slider_options');
    $img_pick = $smooth_slider['img_pick'];
    if (is_array($img_pick)) {
        //if(isset($smooth_slider['img_pick'][1])) {
        $cskey = $smooth_slider['img_pick'][1];
    } else {
        $cskey = 'slider_thumbnail';
    }
    if (!is_array($img_pick)) {
        //if(!isset($smooth_slider['img_pick'][0])) {
        if ($smooth_slider['img_pick'] == '1') {
            $smooth_slider['img_pick'] = array('0', $cskey, '0', '0', '1', '1');
        } elseif ($smooth_slider['img_pick'] == '0') {
            $smooth_slider['img_pick'] = array('1', $cskey, '0', '0', '1', '0');
        } else {
            $smooth_slider['img_pick'] = array('1', $cskey, '1', '1', '1', '1');
        }
    }
    /*	    if(is_array($img_pick) and (count($img_pick)<6 or count($img_pick)>6)) {
    		  $smooth_slider['img_pick'] = array('1',$cskey,'1','1','1','1');
    		}
    */
    if (!$smooth_slider) {
        $smooth_slider = array();
    }
    foreach ($default_slider as $key => $value) {
        if (!isset($smooth_slider[$key])) {
            $smooth_slider[$key] = $value;
        }
    }
    if ($smooth_slider['user_level'] <= 10 and $smooth_slider['user_level'] >= 1) {
        if ($smooth_slider['user_level'] <= 10 and $smooth_slider['user_level'] > 7) {
            $smooth_slider['user_level'] = 'manage_options';
        } elseif ($smooth_slider['user_level'] <= 7 and $smooth_slider['user_level'] > 2) {
            $smooth_slider['user_level'] = 'edit_others_posts';
        } elseif ($smooth_slider['user_level'] == 2) {
            $smooth_slider['user_level'] = 'publish_posts';
        } else {
            $smooth_slider['user_level'] = 'edit_posts';
        }
    }
    delete_option('smooth_slider_options');
    update_option('smooth_slider_options', $smooth_slider);
    delete_option('smooth_slider_speed');
    delete_option('smooth_slider_no_posts');
    delete_option('smooth_slider_bg_color');
    delete_option('smooth_slider_height');
    delete_option('smooth_slider_width');
    delete_option('smooth_slider_border');
    delete_option('smooth_slider_brcolor');
    delete_option('smooth_slider_prev_next');
    delete_option('smooth_slider_goto_slide');
    delete_option('smooth_slider_title_text');
    delete_option('smooth_slider_title_font');
    delete_option('smooth_slider_title_fsize');
    delete_option('smooth_slider_title_fstyle');
    delete_option('smooth_slider_title_fcolor');
    delete_option('smooth_slider_ptitle_font');
    delete_option('smooth_slider_ptitle_fsize');
    delete_option('smooth_slider_ptitle_fstyle');
    delete_option('smooth_slider_ptitle_fcolor');
    delete_option('smooth_slider_img_align');
    delete_option('smooth_slider_img_height');
    delete_option('smooth_slider_img_width');
    delete_option('smooth_slider_img_border');
    delete_option('smooth_slider_img_brcolor');
    delete_option('smooth_slider_content_font');
    delete_option('smooth_slider_content_fsize');
    delete_option('smooth_slider_content_fstyle');
    delete_option('smooth_slider_content_fcolor');
    delete_option('smooth_slider_content_from');
    delete_option('smooth_slider_content_chars');
    delete_option('smooth_slider_bg');
    delete_option('smooth_slider_clear');
    delete_option('smooth_slider_image_only');
}
Exemplo n.º 2
0
function install_smooth_slider()
{
    global $wpdb, $table_prefix, $smooth_db_version;
    $installed_ver = get_option("smooth_db_version");
    if ($installed_ver != $smooth_db_version) {
        $table_name = $table_prefix . SLIDER_TABLE;
        if ($wpdb->get_var("show tables like '{$table_name}'") != $table_name) {
            $sql = "CREATE TABLE {$table_name} (\r\n\t\t\t\t\t\tid int(5) NOT NULL AUTO_INCREMENT,\r\n\t\t\t\t\t\tpost_id int(11) NOT NULL,\r\n\t\t\t\t\t\tdate datetime NOT NULL,\r\n\t\t\t\t\t\tslider_id int(5) NOT NULL DEFAULT '1',\r\n\t\t\t\t\t\tUNIQUE KEY id(id)\r\n\t\t\t\t\t);";
            $rs = $wpdb->query($sql);
            $prev_table_name = $table_prefix . PREV_SLIDER_TABLE;
            if ($wpdb->get_var("show tables like '{$prev_table_name}'") == $prev_table_name) {
                $prev_slider_data = ss_get_prev_slider();
                foreach ($prev_slider_data as $prev_slider_row) {
                    $prev_post_id = $prev_slider_row['id'];
                    $prev_date_time = $prev_slider_row['date'];
                    if ($prev_post_id) {
                        $sql = "INSERT INTO {$table_name} (post_id,date) VALUES('{$prev_post_id}','{$prev_date_time}');";
                        $result = $wpdb->query($sql);
                    }
                }
            }
        }
        add_cf5_column_if_not_exist($table_name, 'slide_order', "ALTER TABLE " . $table_name . " ADD slide_order int(5) NOT NULL DEFAULT '0';");
        $meta_table_name = $table_prefix . SLIDER_META;
        if ($wpdb->get_var("show tables like '{$meta_table_name}'") != $meta_table_name) {
            $sql = "CREATE TABLE {$meta_table_name} (\r\n\t\t\t\t\t\tslider_id int(5) NOT NULL AUTO_INCREMENT,\r\n\t\t\t\t\t\tslider_name varchar(100) NOT NULL default '',\r\n\t\t\t\t\t\tUNIQUE KEY slider_id(slider_id)\r\n\t\t\t\t\t);";
            $rs2 = $wpdb->query($sql);
            $sql = "INSERT INTO {$meta_table_name} (slider_id,slider_name) VALUES('1','Smooth Slider');";
            $rs3 = $wpdb->query($sql);
        }
        $slider_postmeta = $table_prefix . SLIDER_POST_META;
        if ($wpdb->get_var("show tables like '{$slider_postmeta}'") != $slider_postmeta) {
            $sql = "CREATE TABLE {$slider_postmeta} (\r\n\t\t\t\t\t\tpost_id int(11) NOT NULL,\r\n\t\t\t\t\t\tslider_id int(5) NOT NULL default '1',\r\n\t\t\t\t\t\tUNIQUE KEY post_id(post_id)\r\n\t\t\t\t\t);";
            $rs4 = $wpdb->query($sql);
        }
        global $default_slider;
        $smooth_slider = get_option('smooth_slider_options');
        $img_pick = $smooth_slider['img_pick'];
        if (is_array($img_pick)) {
            $cskey = $smooth_slider['img_pick'][1];
        } else {
            $cskey = 'slider_thumbnail';
        }
        if (!is_array($img_pick)) {
            //if(!isset($smooth_slider['img_pick'][0])) {
            if ($smooth_slider['img_pick'] == '1') {
                $smooth_slider['img_pick'] = array('0', $cskey, '0', '0', '1', '1');
            } elseif ($smooth_slider['img_pick'] == '0') {
                $smooth_slider['img_pick'] = array('1', $cskey, '0', '0', '1', '0');
            } else {
                $smooth_slider['img_pick'] = array('1', $cskey, '1', '1', '1', '1');
            }
        }
        /*	    if(is_array($img_pick) and (count($img_pick)<6 or count($img_pick)>6)) {
        			  $smooth_slider['img_pick'] = array('1',$cskey,'1','1','1','1');
        			}
        	*/
        if (!$smooth_slider) {
            $smooth_slider = array();
        }
        //if($smooth_slider and !isset($smooth_slider['ver'])){
        $smooth_slider['stylesheet'] = 'default';
        //}
        foreach ($default_slider as $key => $value) {
            if (!isset($smooth_slider[$key])) {
                $smooth_slider[$key] = $value;
            }
        }
        $smooth_slider['ver'] = 'j';
        if ($smooth_slider['user_level'] <= 10 and $smooth_slider['user_level'] >= 1) {
            if ($smooth_slider['user_level'] <= 10 and $smooth_slider['user_level'] > 7) {
                $smooth_slider['user_level'] = 'manage_options';
            } elseif ($smooth_slider['user_level'] <= 7 and $smooth_slider['user_level'] > 2) {
                $smooth_slider['user_level'] = 'edit_others_posts';
            } elseif ($smooth_slider['user_level'] == 2) {
                $smooth_slider['user_level'] = 'publish_posts';
            } else {
                $smooth_slider['user_level'] = 'edit_posts';
            }
        }
        delete_option('smooth_slider_options');
        update_option('smooth_slider_options', $smooth_slider);
        update_option("smooth_db_version", $smooth_db_version);
    }
}
function install_smooth_slider() {
	global $wpdb, $table_prefix;
	$table_name = $table_prefix.SLIDER_TABLE;
	if($wpdb->get_var("show tables like '$table_name'") != $table_name) {
		$sql = "CREATE TABLE $table_name (
					id int(5) NOT NULL AUTO_INCREMENT,
					post_id int(11) NOT NULL,
					date datetime NOT NULL,
					slider_id int(5) NOT NULL DEFAULT '1',
					UNIQUE KEY id(id)
				);";
		$rs = $wpdb->query($sql);
		
		$prev_table_name = $table_prefix.PREV_SLIDER_TABLE;
		
		if($wpdb->get_var("show tables like '$prev_table_name'") == $prev_table_name) {
			$prev_slider_data = ss_get_prev_slider();
			foreach ($prev_slider_data as $prev_slider_row){
				$prev_post_id = $prev_slider_row['id'];
				$prev_date_time = $prev_slider_row['date'];
				if ($prev_post_id) {
					$sql = "INSERT INTO $table_name (post_id,date) VALUES('$prev_post_id','$prev_date_time');";
					$result = $wpdb->query($sql);
				}
			}
		}
	}
	add_cf5_column_if_not_exist($table_name, 'slide_order', "ALTER TABLE ".$table_name." ADD slide_order int(5) NOT NULL DEFAULT '0';");

   	$meta_table_name = $table_prefix.SLIDER_META;
	if($wpdb->get_var("show tables like '$meta_table_name'") != $meta_table_name) {
		$sql = "CREATE TABLE $meta_table_name (
					slider_id int(5) NOT NULL AUTO_INCREMENT,
					slider_name varchar(100) NOT NULL default '',
					UNIQUE KEY slider_id(slider_id)
				);";
		$rs2 = $wpdb->query($sql);
		
		$sql = "INSERT INTO $meta_table_name (slider_id,slider_name) VALUES('1','Smooth Slider');";
		$rs3 = $wpdb->query($sql);
	}
	
	$slider_postmeta = $table_prefix.SLIDER_POST_META;
	if($wpdb->get_var("show tables like '$slider_postmeta'") != $slider_postmeta) {
		$sql = "CREATE TABLE $slider_postmeta (
					post_id int(11) NOT NULL,
					slider_id int(5) NOT NULL default '1',
					UNIQUE KEY post_id(post_id)
				);";
		$rs4 = $wpdb->query($sql);
	}
   // Need to delete the previously created options in old versions and create only one option field for Smooth Slider
   $default_slider = array();
   $default_slider = array('speed'=>'7', 
	                       'no_posts'=>'5', 
						   'bg_color'=>'#ffffff', 
						   'height'=>'250',
						   'width'=>'450',
						   'border'=>'1',
						   'brcolor'=>'#999999',
						   'prev_next'=>'0',
						   'goto_slide'=>'1',
						   'title_text'=>'Featured Posts',
						   'title_from'=>'0',
						   'title_font'=>'Georgia',
						   'title_fsize'=>'20',
						   'title_fstyle'=>'bold',
						   'title_fcolor'=>'#000000',
						   'ptitle_font'=>'Trebuchet MS',
						   'ptitle_fsize'=>'14',
						   'ptitle_fstyle'=>'bold',
						   'ptitle_fcolor'=>'#000000',
						   'img_align'=>'left',
						   'img_height'=>'120',
						   'img_width'=>'165',
						   'img_border'=>'1',
						   'img_brcolor'=>'#000000',
						   'content_font'=>'Verdana',
						   'content_fsize'=>'12',
						   'content_fstyle'=>'normal',
						   'content_fcolor'=>'#333333',
						   'content_from'=>'content',
						   'content_chars'=>'300',
						   'bg'=>'0',
						   'image_only'=>'0',
						   'allowable_tags'=>'',
						   'more'=>'Read More',
						   'img_size'=>'1',
						   'img_pick'=>array('1','slider_thumbnail','1','1','1','1'), //use custom field/key, name of the key, use post featured image, pick the image attachment, attachment order,scan images
						   'user_level'=>'edit_others_posts',
						   'custom_nav'=>'',
						   'crop'=>'0',
						   'transition'=>'5',
						   'autostep'=>'1',
						   'multiple_sliders'=>'0',
						   'navimg_w'=>'32',
						   'navimg_ht'=>'32',
						   'content_limit'=>'20',
						   'stylesheet'=>'default',
						   'shortcode'=>'1',
						   'rand'=>'0',
						   'ver'=>'j',
						   'support'=>'1',
						   'fouc'=>'0',
						   'fx'=>'scrollHorz',
						   'responsive'=>'0',
						   'css'=>'',
						   'noscript'=>'This page is having a slideshow that uses Javascript. Your browser either doesn\'t support Javascript or you have it turned off. To see this page as it is meant to appear please use a Javascript enabled browser.'
			              );
   
	   $smooth_slider = get_option('smooth_slider_options');
	   /*if($smooth_slider){
	      $default_slider['ver']='step';
	   }*/
	   	   
	   $img_pick = $smooth_slider['img_pick'];
  
       if(is_array($img_pick)) {
	    $cskey = $smooth_slider['img_pick'][1];
	   }
	   else{
	    $cskey = 'slider_thumbnail';
	   }
      
	   if(!is_array($img_pick)) {
	   //if(!isset($smooth_slider['img_pick'][0])) {
		   if($smooth_slider['img_pick'] == '1') {
			  $smooth_slider['img_pick'] = array('0',$cskey,'0','0','1','1');
		   }
		   elseif($smooth_slider['img_pick'] == '0'){
			  $smooth_slider['img_pick'] = array('1',$cskey,'0','0','1','0');
		   }
		   else {
			  $smooth_slider['img_pick'] = array('1',$cskey,'1','1','1','1');
		   }
	   }
	   
/*	    if(is_array($img_pick) and (count($img_pick)<6 or count($img_pick)>6)) {
		  $smooth_slider['img_pick'] = array('1',$cskey,'1','1','1','1');
		}
*/	   
	   if(!$smooth_slider) {
	     $smooth_slider = array();
	   }
	   
	   //if($smooth_slider and !isset($smooth_slider['ver'])){
	      $smooth_slider['stylesheet']='default';
	   //}
	   
	   foreach($default_slider as $key=>$value) {
	      if(!isset($smooth_slider[$key])) {
		     $smooth_slider[$key] = $value;
		  }
	   }
	   	   
	   $smooth_slider['ver']='j';
     
	 if($smooth_slider['user_level']<=10 and $smooth_slider['user_level'] >=1) {
		 if($smooth_slider['user_level']<=10 and $smooth_slider['user_level'] >7) {
		  $smooth_slider['user_level']='manage_options';
		 }
		 elseif($smooth_slider['user_level']<=7 and $smooth_slider['user_level'] >2){
		  $smooth_slider['user_level']='edit_others_posts';
		 } 
		  elseif($smooth_slider['user_level']==2){
		  $smooth_slider['user_level']='publish_posts';
		 } 
		 else {
		  $smooth_slider['user_level']='edit_posts';
		 }
	 }
	  
	   delete_option('smooth_slider_options');	  
	   update_option('smooth_slider_options',$smooth_slider);
}