show_errors(); //forbidden direct access to plugin if (eregi(basename(__FILE__),$_SERVER['PHP_SELF'])) { if (!headers_sent()) { header('HTTP/1.1 403 Forbidden'); exit; }} //runs on activate function jsslsh_install () { global $wpdb; $table_name = $wpdb->prefix . "slideshow"; //create database if($wpdb->get_var("show tables like '$table_name'") != $table_name) { $sql="CREATE TABLE `$table_name` ( `id` SMALLINT NOT NULL AUTO_INCREMENT PRIMARY KEY , `category` SMALLINT NOT NULL , `imgorder` SMALLINT NOT NULL , `image` VARCHAR( 55 ) NOT NULL )"; require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); dbDelta($sql); } $uploaddirname='jsslsh'; //create options update_option("jsslsh_uploadpath", $uploaddirname); update_option("jsslsh_imgwidth", 400); update_option("jsslsh_imgheight", 200); update_option("jsslsh_bannerwidth", 150); //create upload dir $uploaddirname=ABSPATH . "wp-content/uploads/".$uploaddirname; if (!file_exists($uploaddirname) && !mkdir ($uploaddirname, 0777)) echo "Не могу создать $uploaddirname"; //[fix] error output } //end jsslsh_install() function jsslsh_options() { global $wpdb; if( isset($_POST['jsslsh_update'])) { if(! is_numeric($_POST[ 'jsslsh_imgwidth' ]) || ! is_numeric($_POST[ 'jsslsh_imgheight' ]) || ! is_numeric($_POST[ 'jsslsh_bannerwidth' ]) ) { echo '

Ошибка ввода параметров

'; } else { $_POST[ 'jsslsh_uploadpath' ]=$wpdb->escape($_POST[ 'jsslsh_uploadpath' ]); $uploaddirname=ABSPATH . "wp-content/uploads/".$_POST[ 'jsslsh_uploadpath' ]; if ($_POST[ 'jsslsh_uploadpath' ]!=get_option('jsslsh_uploadpath') && !file_exists($uploaddirname) && !mkdir ($uploaddirname, 0777)) echo "Не могу создать $uploaddirname"; //[fix] error output update_option('jsslsh_uploadpath',$_POST[ 'jsslsh_uploadpath' ]); update_option('jsslsh_imgwidth',$_POST[ 'jsslsh_imgwidth' ]); update_option('jsslsh_imgheight',$_POST[ 'jsslsh_imgheight' ]); update_option('jsslsh_bannerwidth',$_POST[ 'jsslsh_bannerwidth' ]); //update_option(,$_POST[ ]); echo '

Настройки сохранены

'; } } //get options from database $uploadpath=get_option('jsslsh_uploadpath'); $imgwidth=get_option('jsslsh_imgwidth'); $imgheight=get_option('jsslsh_imgheight'); $bannerwidth=get_option('jsslsh_bannerwidth'); //$=get_option(''); ?>

JS Slideshow

Настройка параметров

prefix . "slideshow"; //get options from database $uploaddir=get_option('jsslsh_uploadpath'); $uploadurl=get_option("siteurl")."/wp-content/uploads/".$uploaddir; $imagesurl=get_option("siteurl")."/wp-content/plugins/js-slideshow/"; $uploadpath=ABSPATH . "wp-content/uploads/".$uploaddir; $imgwidth=get_option('jsslsh_imgwidth'); $imgheight=get_option('jsslsh_imgheight'); $bannerwidth=get_option('jsslsh_bannerwidth'); //adding new image if( isset($_POST['jsslsh_add'])/* && isset($_FILES['image'])*/) { require('class.upload.php'); function showError ($handle)// one error occured { echo '
Файл не загружен в указанную дирректориюОшибка: ' . $handle->error . '
'; } // we create an instance of the class, giving as argument the PHP object // corresponding to the file field from the form // All the uploads are accessible from the PHP object $_FILES $handle = new Upload($_FILES['image'],'ru_RU'); echo '
'; // then we check if the file has been uploaded properly // in its *temporary* location in the server (often, it is /tmp) if ($handle->uploaded) { // yes, the file is on the server $handle->image_resize = true; if ($category>0) { $handle->image_x = $bannerwidth; $handle->image_ratio_y = true; } else { $handle->image_x = $imgwidth; $handle->image_y = $imgheight; } // now, we start the upload 'process'. That is, to copy the uploaded file // from its temporary location to the wanted location // It could be something like $handle->Process('/home/www/my_uploads/'); $handle->Process($uploadpath); // we check if everything went OK if ($handle->processed) { // everything was fine ! //update db $sql="SELECT MAX(`imgorder`) + 1 as imgord FROM `$table_name`"; $result = $wpdb->get_results($sql, ARRAY_A); $order=$result[0]['imgord']; if (empty($order)) $order=1; $sql="INSERT INTO `$table_name` VALUES (NULL, $category,$order, '".$wpdb->escape($handle->file_dst_name)."');"; $wpdb->query($sql); echo '
Файл успешно загружен'; $info = getimagesize($handle->file_dst_pathname); echo '

' . $info['mime'] . '  - ' . round(filesize($handle->file_dst_pathname)/256)/4 . 'KB

'; echo '
'; } else // one error occured showError ($handle); $handle-> Clean(); // we delete the temporary files } else { // if we're here, the upload file failed for some reasons // i.e. the server didn't receive the file showError ($handle); } echo '
' ; //end updated div } //reorder if( isset($_POST['first']) && isset($_POST['second'])) { $sql="SELECT `imgorder` FROM `$table_name` WHERE `id` ={$_POST['first']} OR `id` ={$_POST['second']}"; $orders = $wpdb->get_results($sql, ARRAY_A); $sql="UPDATE `$table_name` SET `imgorder` = '{$orders[1]['imgorder']}' WHERE `id` ={$_POST['first']}"; $wpdb->query($sql); $sql="UPDATE `$table_name` SET `imgorder` = '{$orders[0]['imgorder']}' WHERE `id` ={$_POST['second']}"; $wpdb->query($sql); } //delete image if( isset($_POST['imgdelete'])) { $_POST['imgdelete']=$wpdb->escape($_POST['imgdelete']); //get filename and delete it $sql="SELECT `image` FROM `$table_name` WHERE `id`=".$_POST['imgdelete']; $result = $wpdb->get_results($sql, ARRAY_A); $file=$uploadpath.'/'.$result[0]['image']; unlink($file); //delete from db $sql="DELETE FROM `$table_name` WHERE `id`=".$_POST['imgdelete']; $wpdb->query($sql); } //output $formaction=str_replace( '%7E', '~', $_SERVER['REQUEST_URI']); ?>

Управление слайдами

Список слайдов

get_results($sql, ARRAY_A); function drawElement($img,$id,$order,$imgwidth,$imgheight,$uploadurl,$imagesurl) { echo ""; } function getOrderHtml($up,$down,$imagesurl) { $o=''; if (count($up)) $o=$o.""; $o.='
$img$order
' ; if (count($down)) $o=$o." "; return $o; } $imgwidth=min($imgwidth,150); $imgheight=min($imgheight,100); $c=count($images); if ($c>0) { //draw first $o=array(); if($c>1) $o=array($images[0]['id'],$images[1]['id']); drawElement($images[0]['image'],$images[0]['id'],getOrderHtml(array(),$o,$imagesurl),$imgwidth,$imgheight,$uploadurl,$imagesurl); //draw all for ($i=1;$i<$c-1;$i++) drawElement($images[$i]['image'],$images[$i]['id'],getOrderHtml(array($images[$i]['id'],$images[$i-1]['id']),array($images[$i]['id'],$images[$i+1]['id']),$imagesurl),$imgwidth,$imgheight,$uploadurl,$imagesurl); //draw last if($c>1) drawElement($images[$c-1]['image'],$images[$c-1]['id'],getOrderHtml(array($images[$c-1]['id'],$images[$c-2]['id']),array(),$imagesurl),$imgwidth,$imgheight,$uploadurl,$imagesurl); } else echo 'нет слайдов'; ?>

Добавить новый

prefix}slideshow` WHERE `category`=$blockID ORDER BY `imgorder`"; $result = $wpdb->get_results($sql, ARRAY_A); if (count($result)) foreach($result as $images) { // echo ""; echo ""; } } //register hooks register_activation_hook(__FILE__,'jsslsh_install'); add_action('admin_menu', 'jsslsh_optionshookmenu'); /* jsslsh_ */