public function controls()
 {
     global $wpdb;
     $inc_obj = new q2w3_include_obj($this->plugin_id);
     // count number of sub filters
     $count_filters = $wpdb->get_results('SELECT count(DISTINCT ' . $inc_obj->status->col_name . ') FROM ' . $inc_obj->table(), ARRAY_N);
     if ($count_filters[0][0]) {
         $count_filters = $count_filters[0][0];
     } else {
         return false;
     }
     // if no data to be filtered return false
     // Add additional 'Select All' sub filter
     $filters['all'] = __('All', $this->plugin_id);
     $filters += $inc_obj->status->input_values;
     $count_filters++;
     $i = 0;
     $res = '';
     if (key_exists(self::VAR_NAME, $_GET)) {
         $cur_filter = $_GET[self::VAR_NAME];
     } else {
         $cur_filter = false;
     }
     foreach ($filters as $filter_key => $filter_name) {
         // sub filter cycle
         $condition = 'WHERE ' . $inc_obj->status->col_name . ' = ' . $filter_key;
         if ($filter_key == 'all') {
             $condition = false;
         }
         // total records for sub filter
         $count = $wpdb->get_results('SELECT count(*) FROM ' . $inc_obj->table() . ' ' . $condition, ARRAY_N);
         if ($count[0][0] > 0) {
             $i++;
             if ($i < $count_filters) {
                 $separator = '|';
             } else {
                 $separator = '';
             }
             $link = q2w3_table_func::change_qstring(self::VAR_NAME, $filter_key);
             // change filter id
             $link = $_SERVER['PHP_SELF'] . '?' . q2w3_table_func::change_qstring(q2w3_table_page_filter::VAR_NAME, '', $link);
             // reset page to number 1
             if ($cur_filter == $filter_key || !$cur_filter && $filter_key == 'all') {
                 $selected = ' class="current"';
             } else {
                 $selected = false;
             }
             $res .= '<div style="float: left"><a href="' . $link . '"' . $selected . '>' . $filter_name . ' <span class="count">(' . $count[0][0] . ')</span></a>' . $separator . '</div>' . PHP_EOL;
         }
     }
     if ($res) {
         $ul = '<div class="subsubsub">' . PHP_EOL;
         $ul .= $res;
         $ul .= '</div>' . PHP_EOL;
         $ul .= '<div style="clear: left;"></div>' . PHP_EOL;
         $this->inc_obj = $inc_obj;
         $this->filters = $filters;
     }
     return $ul;
 }
 public static function action($plugin_id, $object_name)
 {
     $object = new $object_name($plugin_id);
     $object->load_values_from_array($_POST['propertie'], 'php2db');
     $insert_id = $object->save();
     if ($insert_id) {
         q2w3_table_func::change_referer(q2w3_table::NEW_MARKER, $insert_id);
     }
 }
 public static function action($plugin_id, $object_name)
 {
     $id = intval($_GET['id']);
     if ($id) {
         $object = new $object_name($plugin_id);
         $object->id->val = $id;
         if ($object->delete()) {
             q2w3_table_func::change_ref_after_del($object->id->col_name, $id);
         }
     }
 }
 /**
  * Return page title
  * 
  * @param string $id Page id
  * @return string Page title or false if title not found
  */
 public static function page_title($id)
 {
     static $pages = array();
     if (!$pages) {
         $pages = q2w3_table_func::page_selectors();
     }
     if (isset($pages[$id]) && !empty($pages[$id])) {
         return $pages[$id];
     } else {
         return false;
     }
 }
 public static function action($plugin_id, $object_name)
 {
     $checked = $_POST['checked'];
     if (is_array($checked)) {
         $object = new $object_name($plugin_id);
         foreach ($checked as $id => $no_value) {
             $object->id->val = $id;
             if ($object->delete()) {
                 q2w3_table_func::change_ref_after_del($object->id->col_name, $id);
             }
         }
     }
 }
 public function controls()
 {
     $res = '<div id="poststuff" class="metabox-holder">' . PHP_EOL;
     $res .= '<div id="q2w3_table_search" class="postbox" style="width: 100%; margin-bottom: 0px;">' . PHP_EOL;
     $res .= '<h3 class="hndle" style="cursor: normal;"><span>Поиск</span></h3>' . PHP_EOL;
     if (!empty($_SESSION['search'])) {
         $show_form = 'style="display: block"';
     } else {
         $show_form = 'style="display: none"';
     }
     $res .= '<div class="inside" ' . $show_form . '>' . PHP_EOL;
     $res .= '<form method="post" action="' . q2w3_table_func::folder_url() . '/q2w3_post.php' . '" id="q2w3_table_search_form">' . PHP_EOL;
     $search = new q2w3_table_search($this->plugin_id);
     $res .= $search->html();
     $res .= new q2w3_hidden_input(array('name' => 'wp_nonce', 'value' => wp_create_nonce('q2w3_table_post')));
     $res .= '<table>' . PHP_EOL;
     foreach ($this->obj as $pname => $propertie) {
         if ($propertie->search == true) {
             $propertie->input->value = $_SESSION['search'][$propertie->col_name];
             $res .= '<tr>' . PHP_EOL;
             $res .= '<td>' . $propertie->name . '</td>' . PHP_EOL;
             $res .= '<td>' . $propertie->input . '</td>' . PHP_EOL;
             $res .= '</tr>' . PHP_EOL;
         }
     }
     $res .= '<tr>' . PHP_EOL;
     $res .= '<td><input type="button" value="Сброс" class="button-secondary"/></td>' . PHP_EOL;
     $res .= '<td><input type="submit" value="Поиск" class="button-primary"/></td>' . PHP_EOL;
     $res .= '</tr>' . PHP_EOL;
     $res .= '</table>' . PHP_EOL;
     $res .= '</form>' . PHP_EOL;
     $res .= '</div>' . PHP_EOL . '</div>' . PHP_EOL . '</div>' . PHP_EOL;
     //'</div>'.PHP_EOL;
     $res .= '<script type="text/javascript">jQuery("#q2w3_table_search .hndle").click(function(){jQuery("#q2w3_table_search .inside").toggle()});';
     $res .= 'jQuery("#q2w3_table_search_form .button-secondary").click(function(){jQuery(":input","#q2w3_table_search_form").not(":button, :submit, :reset, :hidden").val("").removeAttr("checked").removeAttr("selected");jQuery("#q2w3_table_search_form").submit();});';
     $res .= '</script>';
     return $res;
 }
 /**
  * @param integer $page Current page number in a cycle
  * @param integer $cur_page Current page selected by user
  * @param string $var_name $_GET variable name
  * @return string Button html
  */
 protected function page_button($page, $cur_page, $var_name)
 {
     if ($page == $cur_page) {
         $res = '<span class="page-numbers current">' . $page . '</span> ';
     } else {
         $res = '<a class="page-numbers" href="?' . q2w3_table_func::change_qstring($var_name, $page) . '">' . $page . '</a> ';
     }
     return $res;
 }
 public static function change_ref_after_del($id_col_name, $id)
 {
     q2w3_table_func::change_referer('&' . $id_col_name . '=' . $id, '');
     // remove deleted id from query string
     if (!(isset($_GET['last_record']) || isset($_POST['last_record']))) {
         return;
     }
     // continue if deleted record is last
     $page = strstr($_SERVER['HTTP_REFERER'], q2w3_table_page_filter::VAR_NAME);
     if ($page) {
         // if page var is set
         $next_var = strpos($page, '&');
         if ($next_var) {
             $page = substr($page, 0, $next_var);
         }
         // remove other vars from string
         $page_num = explode('=', $page);
         $page_num = intval($page_num[1]);
         // page number
     } else {
         // there is only one page
         $page_num = 1;
     }
     if ($page_num > 1) {
         // if this is not first page reset page number to 1
         q2w3_table_func::change_referer('&' . $page, '');
     } else {
         // if this is first page reset location filter var
         $location = strstr($_SERVER['HTTP_REFERER'], q2w3_table_location_filter::VAR_NAME);
         $next_var = strpos($location, '&');
         if ($next_var) {
             $location = substr($location, 0, $next_var);
         }
         if ($location) {
             q2w3_table_func::change_referer('&' . $location, '');
         }
     }
 }
 public static function deactivation()
 {
     if (isset($_POST['deactivate']) && $_POST['deactivate'] == 'deactivate' || $_POST['deactivate'] == 'deactivate_and_clean') {
         // process deactivation options
         global $wpdb;
         require_once ABSPATH . 'wp-admin/includes/plugin.php';
         $redirect_url = get_option('siteurl') . '/wp-admin/plugins.php?deactivate=true';
         if ($_POST['deactivate'] == 'deactivate') {
             // simple deactivation
             deactivate_plugins(plugin_basename(__FILE__));
             wp_redirect($redirect_url);
         } elseif ($_POST['deactivate'] == 'deactivate_and_clean') {
             // advanced deactivation (delete tables and settings)
             self::object();
             deactivate_plugins(plugin_basename(__FILE__));
             // deactivate plugin
             $wpdb->query('DELETE FROM ' . $wpdb->options . " WHERE option_name LIKE '%q2w3_inc_manager%'");
             // delete all plugin entries in options table
             $wpdb->query('DELETE FROM ' . $wpdb->usermeta . " WHERE meta_key = '" . q2w3_table_func::safe_plugin_id(self::ID) . "_table_settings'");
             // delete all plugin entries in usermeta table
             $wpdb->query('DROP TABLE IF EXISTS ' . self::$object->table());
             // delete includes table
             wp_redirect($redirect_url);
         }
     }
 }
 /**
  * Returns array of selectable pages 
  * 
  */
 protected static function selectable_pages($plugin_id, $type)
 {
     // $type = [include] [exclude]
     global $wp_post_types, $wp_taxonomies;
     $values_to_select = q2w3_include_obj::page_selectors($plugin_id);
     if ($type == 'exclude') {
         array_shift($values_to_select);
     }
     $options = get_option(q2w3_inc_manager::ID);
     if (!$options) {
         $options = q2w3_inc_manager::$default_options;
     }
     if ($options['taxonomies']['post_format']['enable']) {
         $formats_orig = get_post_format_strings();
         foreach ($formats_orig as $fkey => $fname) {
             $formats['post_format_' . $fkey] = __('PF', $plugin_id) . ': ' . $fname;
         }
         $values_to_select[__('Post Formats')] = $formats;
     }
     foreach ($options['post_types'] as $post_type => $params) {
         $pages = NULL;
         if ($params['enable'] == 'on' && !in_array($post_type, q2w3_inc_manager::$restricted_post_types)) {
             $post_type_name = $wp_post_types[$post_type]->labels->name;
             $selectors = array($post_type . '_all' => __('All', $plugin_id) . ' ' . $post_type_name);
             if (version_compare($GLOBALS['wp_version'], '3.1.0', '>=') && $post_type != 'page') {
                 $selectors = array_merge($selectors, array('post_type_archive_' . $post_type => __('Archive', $plugin_id) . ': ' . $post_type_name));
             }
             if ($params['expand'] == 'on') {
                 $pages = q2w3_table_func::select_post_type($post_type);
             }
             if (!empty($pages)) {
                 $selectors = array_merge($selectors, $pages);
             }
             $values_to_select[$post_type_name] = $selectors;
         }
     }
     foreach ($options['taxonomies'] as $taxonomy => $params) {
         $pages = NULL;
         if ($params['enable'] == 'on' && !in_array($taxonomy, q2w3_inc_manager::$restricted_taxonomies)) {
             $taxonomy_name = $wp_taxonomies[$taxonomy]->labels->name;
             $selectors = array($taxonomy . '_all' => __('All', $plugin_id) . ' ' . $taxonomy_name);
             if ($params['expand'] == 'on') {
                 $pages = q2w3_table_func::select_taxonomy($taxonomy);
             }
             if (!empty($pages)) {
                 $selectors = array_merge($selectors, $pages);
             }
             $values_to_select[$taxonomy_name] = $selectors;
         }
     }
     /*$pages = q2w3_table_func::wp_pages();
     		
     		if (!empty($pages)) $values_to_select[__('Pages', $plugin_id)] = $pages;
     		
     		$pages = q2w3_table_func::wp_categories();
     		
     		if (!empty($pages)) $values_to_select[__('Categories', $plugin_id)] = $pages;
     		
     		$pages = q2w3_table_func::wp_tags();
     				
     		if (!empty($pages)) $values_to_select[__('Tags', $plugin_id)] = $pages;
     		
     		$pages = q2w3_table_func::wp_posts();
     		
     		if (!empty($pages)) $values_to_select[__('Posts', $plugin_id)] = $pages;*/
     return $values_to_select;
 }
 /**
  * Returns table rows html
  * 
  * @return string
  */
 protected function table_rows()
 {
     $columns = $this->get_columns_names();
     $col_num = count($columns);
     array_unshift($columns, 'id');
     $columns = implode(',', $columns);
     $where = false;
     if (is_array($this->filters)) {
         foreach ($this->filters as $filter) {
             if ($filter_sql = $filter->sql()) {
                 $where[] = $filter->sql();
             }
         }
         $where = @implode(' AND ', $where);
         if ($where) {
             $where = 'WHERE ' . $where;
         }
     }
     if ($this->group_by) {
         $group_by = 'GROUP BY ' . $this->group_by;
     } else {
         $group_by = false;
     }
     if ($this->order_by) {
         $order_by = 'ORDER BY ' . $this->order_by;
     } else {
         $order_by = false;
     }
     $conditions = 'FROM ' . $this->object->table() . ' ' . $where . ' ' . $group_by . ' ' . $order_by;
     if ($this->enable_page_filter) {
         $this->page_filter = new q2w3_table_page_filter($this->plugin_id);
         $limit_start = $this->page_filter->cur_page() * $this->rows_per_page - $this->rows_per_page;
         $limit = 'LIMIT ' . $limit_start . ',' . $this->rows_per_page;
         $tmp_rows = $this->wpdb->get_results('SELECT count(*) ' . $conditions, ARRAY_N);
         $this->total_rows = $tmp_rows[0][0];
     }
     $data = $this->wpdb->get_results('SELECT ' . $columns . ' ' . $conditions . ' ' . $limit, ARRAY_A);
     //status, location, priority
     if (!empty($data)) {
         if (count($data) == 1 && $this->page_filter->cur_page() == ceil($this->total_rows / $this->rows_per_page)) {
             $this->last_record = true;
         }
         $i = 0;
         $res = '';
         foreach ($data as $row) {
             $this->object->load_values_from_array($row, 'db2text');
             $row_id = $this->object->id->val;
             $i++;
             if ($i & 1) {
                 $class = 'class="alternate"';
             } else {
                 $class = false;
             }
             $res .= '<tr ' . $class . '>' . PHP_EOL;
             if ($this->enable_bulk_actions) {
                 $res .= '<th scope="row" class="check-column"><input type="checkbox" name="checked[' . $row_id . ']" value="" class="q2w3_table_checkbox" /></th>' . PHP_EOL;
                 $col_num++;
             }
             $propertie_link = get_option('siteurl') . '/wp-admin/admin.php';
             foreach ($this->object as $propertie => $definition) {
                 if ($definition->table_view) {
                     if ($propertie == 'title') {
                         $res .= '<td><a href="' . $propertie_link . '?' . q2w3_table_func::change_qstring('id', $row_id) . '" class="row-title">' . $definition->val . '</a>' . $this->row_actions($this->object, $row) . '</td>' . PHP_EOL;
                     } else {
                         $res .= '<td>' . $definition->val . '</td>' . PHP_EOL;
                     }
                 }
             }
             $res .= '</tr>' . PHP_EOL;
         }
     } else {
         $res = '<tr><td></td><td colspan="' . $col_num . '">' . __('No data', $this->plugin_id) . '</td></tr>' . PHP_EOL;
     }
     return $res;
 }
Exemple #12
0
<?php

if ($_SERVER['REQUEST_METHOD'] != 'POST') {
    die;
}
require_once 'q2w3_table_load.php';
require_once 'q2w3_table_func.php';
require_once q2w3_table_func::wp_load();
if (!check_admin_referer('q2w3_table_post', 'wp_nonce')) {
    wp_die('Security check failed');
}
require_once dirname(dirname(__FILE__)) . '/q2w3-inc-manager.php';
q2w3_inc_manager::load_language();
if (isset($_POST['deactivate'])) {
    q2w3_inc_manager::deactivation();
} else {
    $action = $_POST['action'];
    $object = $_POST['object'];
    eval($action . '::action(q2w3_inc_manager::ID, $object);');
    if ($_SERVER['HTTP_REFERER']) {
        header('Location: ' . $_SERVER['HTTP_REFERER']);
    }
}
    /**
     * Returns javascript needed for include edit form 
     * 
     */
    public function js()
    {
        $this->widget_title->input->value = $this->widget_title->val;
        $this->code_align->input->value = $this->code_align->val;
        $zcbpath = q2w3_table_func::folder_url() . '_js/zeroclipboard/';
        $zcbptext = __('Copy to clipboard', self::$plugin_id);
        $manual_inc_code = '&lt;?php if ( method_exists(\'q2w3_inc_manager\', \'manual_inc\') ) q2w3_inc_manager::manual_inc(' . $_GET['id'] . '); ?&gt;';
        $shortcode_inc_code = '[include id=&quot;' . $_GET['id'] . '&quot; title=&quot;" + get_inc_title() + "&quot;]';
        $js = '<script src="' . $zcbpath . 'ZeroClipboard.js"></script>
<script type="text/javascript">

jQuery("#select_location").parent("td").append(\'<span id="manual_include_code"></span>\');
jQuery("#inc_code").parent("td").prepend(\'<span id="code_align"></span>\');
jQuery("#select_location").change(function() {
	var location = jQuery(this).attr("value");
	if (location == ' . self::LOC_WIDGET . ' || location == ' . self::LOC_MANUAL . ') {
		jQuery(this).parent("td").parent("tr").next("tr").hide();	
	} else {
		jQuery(this).parent("td").parent("tr").next("tr").show();
	}	
	if (location == ' . self::LOC_MANUAL . ') {
		jQuery("#manual_include_code").text("");
		jQuery("#manual_include_code").append("<span id=\\"text_to_copy\\">' . $manual_inc_code . '</span> <input data-clipboard-text=\\"' . $manual_inc_code . '\\" type=\\"button\\" value=\\"' . $zcbptext . '\\" id=\\"copy-button-manual\\" class=\\"button-secondary\\" />");
		var clip = new ZeroClipboard( document.getElementById("copy-button-manual"), {
  			moviePath: "' . $zcbpath . 'ZeroClipboard.swf"
		} );
	} else if (location == ' . self::LOC_WIDGET . ') {
		jQuery("#manual_include_code").text("");
		jQuery("#manual_include_code").append(\'' . $this->widget_title->name . ': ' . trim($this->widget_title->input) . '\');
	} else if (location == ' . self::LOC_SHORTCODE . ') {
		jQuery("#manual_include_code").text("");
		jQuery("#manual_include_code").append("<span id=\\"text_to_copy\\">' . $shortcode_inc_code . '</span> <input data-clipboard-text=\\"' . $shortcode_inc_code . '\\" type=\\"button\\" value=\\"' . $zcbptext . '\\" id=\\"copy-button-shortcode\\" class=\\"button-secondary\\" />");
		var clip = new ZeroClipboard( document.getElementById("copy-button-shortcode"), {
  			moviePath: "' . $zcbpath . 'ZeroClipboard.swf"
		} );
	} else {
		jQuery("#manual_include_code").text("");
	}
	if (location != ' . self::LOC_HEADER . ') {
		jQuery("#code_align").text("");
		jQuery("#code_align").append(\'' . str_replace(PHP_EOL, '', $this->code_align->input) . '\');
	} else {
		jQuery("#code_align").text("");
	}
}).trigger("change");

function get_inc_title() {
	return jQuery("input[name=\'propertie[description]\']").attr("value");
}

function htmlDecode(value){ 
 	return jQuery(\'<div/>\').html(value).text(); 
}
</script>';
        return $js;
    }