/*
Plugin Name: Explore
Plugin URI: http://www.mbyte.org.ua/
Description: Структуризация страниц с большим кол-вом вложений.
Version: 0.5
Author: mByte
Author URI: http://mbyte.org.ua/
*/
/* Copyright 2007 mByte (email : mbyte@mbzeus.net)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
wp_enqueue_script('page');
wp_enqueue_script('editor');
add_thickbox();
wp_enqueue_script('media-upload');
wp_enqueue_script('word-count');
add_action('admin_menu', 'explore_amenu');
function explore_amenu() {
add_menu_page('Edit pages', 'Edit pages', 3, __FILE__, 'explore_it');
}
function explore_pagination($page, $parent, $count) {
global $wpdb;
print "
";
}
function explore_insert_post($params) {
global $wpdb;
$wpdb->show_errors = true;
$query = "INSERT INTO $wpdb->posts (`post_author`,`post_date`,`post_date_gmt`,`post_content`,`post_title`,`post_status`,`post_parent`,`post_type`) VALUES('1','".date("Y-m-d H:i:s")."','".date("Y-m-d H:i:s")."','','New page','publish','$params','page');";
$wpdb->query($query);
$insid = $wpdb->insert_id;
return $insid;
}
function explore_it() {
global $wpdb;
if ($_GET['edit']) {
le_it();
} else {
if (isset($_POST['bulkdelete'])) {
$bulk = $_POST['bulk'];
foreach($bulk as $id) {
$wpdb->query("DELETE FROM $wpdb->posts WHERE `ID`='$id' LIMIT 1;");
}
print '';
}
if (isset($_GET['delete'])) {
$id = intval($_GET['delete']);
$wpdb->query("DELETE FROM $wpdb->posts WHERE `ID`='$id' LIMIT 1;");
print '';
}
if (isset($_GET['addpage'])) {
if (preg_match("/explore\.php/", $_SERVER["HTTP_REFERER"])) {
$parent = intval($_GET['parent']);
$newid = explore_insert_post($parent);
print "
";
}
}
print "
Pages
";
if (isset($_GET['parent'])) {
$parent = intval($_GET['parent']);
} else {
$parent = 0;
}
if ($parent != 0) {
$p_title = $wpdb->get_var("SELECT post_title FROM $wpdb->posts WHERE `ID`='$parent' LIMIT 1;");
} else {
$p_title = "Root";
}
print "
";
if ($parent != 0) {
$upid = $wpdb->get_var("SELECT post_parent FROM $wpdb->posts WHERE `ID`='".$parent."' LIMIT 1 ;");
print "
";
}
$count = $wpdb->get_var("SELECT COUNT(ID) FROM $wpdb->posts WHERE `post_type`='page' AND `post_parent`='".$parent."';");
if (isset($_GET['paged'])) {
$page = intval($_GET['paged']) - 1;
} else {
$page = 0;
}
if ($parent != 67) {
$limit = "LIMIT ".($page*10).",10";
explore_pagination($page,$parent,$count);
}
$pages = $wpdb->get_results("SELECT ID,post_title FROM $wpdb->posts WHERE `post_type`='page' AND `post_parent`='".$parent."' ORDER BY `ID` ASC $limit;");
print "
";
print "
";
}
}
function le_it() {
if (!isset($_GET['id'])) {
header("Location: /wp-admin/admin.php?page=explore.php");
print "";
die();
}
global $wpdb;
$id = intval($_GET['id']);
if (isset($_POST['set'])) {
$post_title = $wpdb->prepare($_POST['post_title']);
$content = $wpdb->prepare($_POST['content']);
$parent_id = $wpdb->prepare($_POST['parent_id']);
$wpdb->query("UPDATE $wpdb->posts SET `post_title`='$post_title',`post_content`='$content',`post_parent`='$parent_id' WHERE `ID`='$id' LIMIT 1;");
echo '';
}
print "