/** * Render the admin page */ public function handle_page() { global $wpdb; require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; require_once dirname(__FILE__) . '/class-list-table.php'; echo '<div class="wrap">'; echo '<div>'; $query_args = array('action' => 'pantheon_clear_session', 'nonce' => wp_create_nonce('pantheon_clear_session'), 'session' => 'all'); if ($wpdb->get_var("SELECT COUNT(session_id) FROM {$wpdb->pantheon_sessions}")) { echo '<a class="button pantheon-clear-all-sessions" style="float:right; margin-top: 9px;" href="' . esc_url(add_query_arg($query_args, admin_url('admin-ajax.php'))) . '">' . esc_html__('Clear All', 'pantheon-sessions') . '</a>'; } echo '<h2>' . esc_html__('Pantheon Sessions', 'pantheon-sessions') . '</h2>'; if (isset($_GET['message']) && in_array($_GET['message'], array('delete-all-session', 'delete-session'))) { if ('delete-all-session' === $_GET['message']) { $message = __('Cleared all sessions.', 'pantheon-sessions'); } else { if ('delete-session' === $_GET['message']) { $message = __('Session cleared.', 'pantheon-sessions'); } } echo '<div id="message" class="updated"><p>' . esc_html($message) . '</p></div>'; } echo '</div>'; $wp_list_table = new List_Table(); $wp_list_table->prepare_items(); $wp_list_table->display(); echo '</div>'; add_action('admin_footer', array($this, 'action_admin_footer')); }
/** * Handles live updates for Stream Post List * * @action heartbeat_recieved * * @param array $response Response to be sent to heartbeat tick * @param array $data Data from heartbeat send * * @return array Data sent to heartbeat tick */ public function heartbeat_received($response, $data) { // Only fire when Stream is requesting a live update if (!isset($data['wp-stream-heartbeat'])) { return $response; } $enable_stream_update = 'off' !== $this->plugin->admin->get_user_meta(get_current_user_id(), $this->user_meta_key); // Register list table $this->list_table = new WP_Stream_List_Table(array('screen' => 'toplevel_page_' . $this->plugin->admin->records_page_slug)); $this->list_table->prepare_items(); $total_items = isset($this->list_table->_pagination_args['total_items']) ? $this->list_table->_pagination_args['total_items'] : null; $total_pages = isset($this->list_table->_pagination_args['total_pages']) ? $this->list_table->_pagination_args['total_pages'] : null; if (isset($data['wp-stream-heartbeat']) && isset($total_items)) { $response['total_items'] = $total_items; $response['total_items_i18n'] = sprintf(_n('1 item', '%s items', $total_items), number_format_i18n($total_items)); } if (isset($data['wp-stream-heartbeat']) && 'live-update' === $data['wp-stream-heartbeat'] && $enable_stream_update) { if (!empty($data['wp-stream-heartbeat'])) { if (isset($total_pages)) { $response['total_pages'] = $total_pages; $response['total_pages_i18n'] = number_format_i18n($total_pages); $query_args = json_decode($data['wp-stream-heartbeat-query'], true); $query_args['paged'] = $total_pages; $response['last_page_link'] = add_query_arg($query_args, admin_url('admin.php')); } else { $response['total_pages'] = 0; } } $response['wp-stream-heartbeat'] = $this->live_update($response, $data); } else { $response['log'] = 'fail'; } return $response; }
function get_columns() { $cols = parent::get_columns(); if ($_GET['action'] == 'xls') { unset($cols['checkbox']); } return $cols; }
/** * Constructor * * @param array $args */ public function __construct($args = array()) { global $post; if ($post && !isset($args['query']['post_parent'])) { $args['query']['post_parent'] = $post->ID; } parent::__construct($args); add_filter('page_row_actions', function ($actions, $post) { return array(); }, 10, 2); }
/** * Изменение порядка следования элементов в multi и link элемах * @param $data * @return void */ function changePriority($data) { $page_name = get('page_name', '', 'p'); $elem_name = get('elem_name', '', 'p'); // инициализация элема $elem_object = $this->initElemByParams($page_name, $elem_name); if (is_string($elem_object)) { echo json_encode(array('error' => iconv('windows-1251', 'utf-8', $elem_object))); die; } if (!$elem_object->elem_fields['id_field']) { echo json_encode(array('error' => iconv('windows-1251', 'utf-8', "Не определен параметр id_field"))); die; } // ищем таблицу $table = $elem_object->elem_type == 'multi' ? $elem_object->elem_table : $elem_object->elem_table_link; if (!$table) { echo json_encode(array('error' => iconv('windows-1251', 'utf-8', "Не определена таблица"))); die; } $id = (int) get('id', 0, 'p'); if (!$id) { echo json_encode(array('error' => iconv('windows-1251', 'utf-8', "Неизвестный параметр: id"))); die; } $direction = get('direction', 0, 'p'); if (!in_array($direction, array(1, -1))) { echo json_encode(array('error' => iconv('windows-1251', 'utf-8', "Неизвестный параметр: direction"))); die; } $tabname = get('tab', '', 'p'); if (!$tabname) { echo json_encode(array('error' => iconv('windows-1251', 'utf-8', "Неизвестный параметр: tabname"))); die; } // Родительский id, внутри которого идет нумерация priority $id_field = $elem_object->elem_type == 'multi' ? 'id' : $elem_object->elem_fields['id2_field']; $pid = (int) sql_getValue("SELECT " . $elem_object->elem_fields['id_field'] . " FROM " . $table . " WHERE " . $id_field . "=" . $id); if (!$pid) { echo json_encode(array('error' => iconv('windows-1251', 'utf-8', "Не определено значение для " . $elem_object->elem_fields['id_field']))); die; } $priority_field = isset($elem_object->elem_fields['priority_field']) ? $elem_object->elem_fields['priority_field'] : 'priority'; // Исходный приоритет $where = ""; if ($elem_object->elem_type == 'link') { $where = " AND " . $elem_object->elem_fields['id_field'] . "=" . $pid; } $priority = sql_getValue("SELECT " . $priority_field . " FROM " . $table . " WHERE " . $id_field . "=" . $id . $where); if ($priority <= 1 && $direction < 0) { // некуда уменьшать приоритет } elseif ($priority >= sql_getValue("SELECT MAX(" . $priority_field . ") FROM " . $table . " WHERE " . $elem_object->elem_fields['id_field'] . "=" . $pid) && $direction > 0) { // некуда увеличивать приоритет } else { // Получаем id элемента для замены $trg_id = sql_getValue("SELECT " . $id_field . " FROM " . $table . " WHERE " . $priority_field . "=" . ($priority + $direction) . " AND " . $elem_object->elem_fields['id_field'] . "=" . $pid . " AND " . $id_field . "<>" . $id); if (!$trg_id) { // Делаем автонумерацию, если ошибка $this->EnumPriority($pid, $elem_object->elem_fields['id_field'], $table, $id_field, $priority_field); $trg_id = sql_getValue("SELECT " . $id_field . " FROM " . $table . " WHERE " . $priority_field . "=" . $priority . " AND " . $elem_object->elem_fields['id_field'] . "=" . $pid); // Если нумерация не помогла, выдаем ошибку. if (!$trg_id) { echo json_encode(array('error' => iconv('windows-1251', 'utf-8', "Не определено значение для trg_id"))); die; } } // Заменяем priority sql_query("UPDATE " . $table . " SET " . $priority_field . "=" . $priority . " WHERE " . $id_field . "=" . $trg_id . $where); sql_query("UPDATE " . $table . " SET " . $priority_field . "=" . ($priority + $direction) . " WHERE " . $id_field . "=" . $id . $where); } $this->EnumPriority($pid, $elem_object->elem_fields['id_field'], $table, $id_field, $priority_field); //Вызовем обработчик данных таблицы require_once core('table.lib'); $list_table = new List_Table(); $table_columns = $list_table->getAllOptionsParams($elem_object->columns); foreach ($table_columns as $k => $v) { $table_columns[$k]['this'] = $elem_object; $table_columns[$k]['this']->page = $page_name; } $rows = $elem_object->getWCfromDb($pid); foreach ($rows as $k => $v) { $rows[$k]['tabname'] = $tabname; $rows[$k]['onclick'] = $tabname . ".showSelectDiv(" . $v['id'] . ", this);"; } $elem_object->tabname = $tabname; $ret = array(); foreach ($rows as $row) { $tableRows = $list_table->getRowsHtml(array('columns' => $table_columns), array($row), -1, array(), $elem_object); //Получим верстку строк, таблицы $ret[] = array(iconv('windows-1251', 'utf-8', Parse($tableRows + array('id_table_list_name' => 'tbl' . $tabname . $page_name . $pid), 'table_only_rows.tmpl'))); } ob_clean(); echo json_encode(array('ret' => $ret)); die; }