static function flush_by_module($module_id) { $module = Red_Module::get($module_id); if ($module) { $module->flush_module(); } }
function export($type) { include dirname(__FILE__) . '/../models/pager.php'; $module = Red_Module::get(intval($_GET['module'])); if ($module) { include dirname(__FILE__) . "/../fileio/{$type}.php"; if ($type == 'rss') { $exporter = new Red_Rss_File(); } else { if ($type == 'xml') { $exporter = new Red_Xml_File(); } else { if ($type == 'csv') { $exporter = new Red_Csv_File(); } else { if ($type == 'apache') { $exporter = new Red_Apache_File(); } } } } $exporter->collect($module); $exporter->feed(); return true; } return false; }
function template_redirect() { // Load data $modules = Red_Module::get_by_type('wp'); if (count($modules) > 0) { foreach ($modules as $wp) { // Timeout if ($wp->time_limit != 'default') { set_time_limit($wp->time_limit); } // Error level if ($wp->error_level == 'none') { error_reporting(0); } else { if ($wp->error_level == 'show') { error_reporting(E_ALL); } } // Mangle the URL, if needed $url = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ? 'https://' : 'http://'; $url .= $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; $original = $url; if ($wp->canonical == 'www') { $url = preg_replace('@(https?)://(www)?\\.?@', '$1://www.', $url); } else { if ($wp->canonical == 'nowww') { $url = preg_replace('@(https?)://(www)?\\.?@', '$1://', $url); } } if ($wp->strip_index == 'yes') { $url = preg_replace('@index.(htm|html|php|asp|aspx|jsp)@', '', $url); } if ($url != $original) { wp_redirect($url, 301); } if ($this->matched) { $this->matched->action->process_after($this->matched->action_code, $original); } } } }
function template_redirect() { global $redirection; if (is_404() && !$redirection->hasMatched()) { $url = $_SERVER['REQUEST_URI']; $redirects = Red_Item::get_for_url($url, '404'); if (!empty($redirects)) { foreach ($redirects as $key => $item) { if ($item->matches($url)) { $redirection->setMatched(true); $this->matched = $item; break; } } } if (empty($this->matched)) { $modules = Red_Module::get_by_type('404'); if (count($modules) > 0) { foreach ($modules as $module) { // Log 404 errors if ($module->log_404) { if (isset($_SERVER['REMOTE_ADDR'])) { $myip = $_SERVER['REMOTE_ADDR']; } else { if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { $myip = $_SERVER['HTTP_X_FORWARDED_FOR']; } } $options = $redirection->get_options(); if ($options['log_404s']) { $log = RE_Log::create($_SERVER['REQUEST_URI'], '', $_SERVER['HTTP_USER_AGENT'], $myip, isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '', 'NULL', $module->id); } } } } } } }
function red_redirect_delete() { if (check_ajax_referer('redirection-items')) { if (preg_match_all('/=(\\d*)/', $this->post['checked'], $items) > 0) { $redirect = Red_Item::get_by_id($items[0]); foreach ($items[1] as $item) { Red_Item::delete(intval($item)); } $group = Red_Group::get($redirect->group_id); Red_Module::flush($group->module_id); } } }
static function save_order($items, $start) { global $wpdb; foreach ($items as $pos => $id) { $wpdb->update($wpdb->prefix . 'redirection_items', array('position' => $pos + $start), array('id' => $id)); } $item = self::get_by_id($id); $group = Red_Group::get($item->group_id); if ($group) { Red_Module::flush($group->module_id); } }
<div id="pager" class="tablenav"> <div class="alignleft actions"> <select name="action2" id="action2_select"> <option value="-1" selected="selected"><?php _e('Bulk Actions'); ?></option> <option value="delete"><?php _e('Delete'); ?></option> </select> <input type="submit" value="<?php _e('Apply'); ?>" name="doaction2" id="actionator" class="button-secondary action" /> <?php $pager->per_page ('redirection'); ?> <?php if (isset ($_GET['module'])) : ?> <?php _e ('Module', 'redirection'); ?>: <select name="module"> <?php echo $this->select (Red_Module::get_for_select (), intval ($_GET['module']))?> </select> <?php elseif (isset ($_GET['group'])) : ?> <?php _e ('Group', 'redirection'); ?>: <select name="group"> <?php echo $this->select (Red_Group::get_for_select (), intval ($_GET['group']))?> </select> <?php endif; ?> <input type="submit" value="<?php _e('Filter'); ?>" class="button-secondary" /> <br class="clear" /> </div> <div class="tablenav-pages"> <?php echo $pager->page_links (); ?>
public function __construct() { $this->module = Red_Module::get(WordPress_Module::MODULE_ID); $this->module->start(); add_action(Red_Flusher::DELETE_HOOK, array($this, 'clean_redirection_logs')); }
function reset() { Red_Module::clear_cache($this->id); $groups = Red_Group::get_for_module($this->id); if (count($groups) > 0) { foreach ($groups as $group) { $group->reset(); } } RE_Log::delete_for_module($this->id); }
function prepare_items($type = '', $id = 0) { global $wpdb; $table = $wpdb->prefix . 'redirection_modules'; $rows = $wpdb->get_results("SELECT * FROM {$table}"); $this->total_items = $wpdb->get_var("SELECT COUNT(*) FROM {$table}"); $columns = $this->get_columns(); $sortable = $this->get_sortable_columns(); $this->_column_headers = array($columns, array(), $sortable); $this->items = array(); foreach ((array) $rows as $row) { $this->items[] = Red_Module::new_item($row); } $this->set_pagination_args(array('total_items' => $this->total_items, 'per_page' => 100, 'total_pages' => ceil($this->total_items / 100))); }
function load($group, $data) { $count = 0; if (function_exists('simplexml_load_string')) { global $wpdb; $xml = simplexml_load_string($data); // Extract module $moduledata = array('type' => (string) $xml->module['type'], 'name' => sprintf(__('%s imported on %s at %s', 'redirection'), (string) $xml->module['name'], date('M d Y'), date('H:i'))); if (isset($xml->module->options)) { foreach ($xml->module->options->option as $option) { $options[(string) $option['name']] = trim((string) $option); } $moduledata['options'] = $options; } $module = Red_Module::create($moduledata); // Look at groups if (count($xml->module->group) > 0) { foreach ($xml->module->group as $group) { $id = Red_Group::create(array('module_id' => $module, 'name' => (string) $group['name'], 'status' => (string) $group['status'], 'position' => (string) $group['position'])); // Look at items if (count($group->item) > 0) { foreach ($group->item as $item) { $actiondata = array(); if (isset($item->action->option) && count($item->action->option) > 0) { foreach ($item->action->option as $option) { $actiondata[(string) $option['key']] = trim((string) $option); } $actiondata = serialize($actiondata); } else { $actiondata = trim((string) $item->action); } $data = array('group_id' => $id, 'url' => trim((string) $item->source), 'position' => intval((string) $item['position']), 'status' => (string) $item['status'], 'regex' => (string) $item->match['regex'], 'match_type' => (string) $item->match['type'], 'action_type' => (string) $item->action['type'], 'action_code' => (string) $item->action['code'], 'action_data' => $actiondata); foreach ($data as $key => $value) { $data[$key] = "'" . $wpdb->escape($value) . "'"; } // Easier to insert it directly here $wpdb->query("INSERT INTO {$wpdb->prefix}redirection_items (" . implode(',', array_keys($data)) . ") VALUES (" . implode(',', $data) . ")"); $count++; } } } } } else { global $redirection; $redirection->render_error(__('XML importing is only available with PHP5 - you have PHP4.', 'redirection')); } return $count; }
function move_to($module) { global $wpdb; $wpdb->query("UPDATE {$wpdb->prefix}redirection_groups SET module_id='{$module}' WHERE id='{$this->id}'"); Red_Module::flush($module); Red_Module::flush($this->id); }
function prepare_items($type = '', $id = 0) { global $wpdb; $options = red_get_options(); $columns = $this->get_columns(); $sortable = $this->get_sortable_columns(); $this->_column_headers = array($columns, array(), $sortable); $this->items = Red_Module::get_for_select(); $this->total_items = count($this->items); $this->set_pagination_args(array('total_items' => $this->total_items, 'per_page' => 100, 'total_pages' => ceil($this->total_items / 100))); }
private function get_module_column($module_id, $export_type) { $json['error'] = __('Invalid module', 'redirection'); $module = Red_Module::get($module_id); $exporter = Red_FileIO::create($export_type); if ($module && $exporter) { global $hook_suffix; $hook_suffix = ''; $options = red_get_options(); $pager = new Redirection_Module_Table($options['token']); $items = Red_Item::get_all_for_module($module_id); $json = array('html' => $pager->column_name($module)); $json['html'] .= '<textarea readonly="readonly" class="module-export" rows="10">' . esc_textarea($exporter->get($items)) . '</textarea>'; $json['html'] .= '<div class="table-actions"><a href="?page=redirection.php&token=' . $options['token'] . '&sub=' . $export_type . '&module=' . $module_id . '"><input class="button-primary" type="button" value="' . __('Download', 'redirection') . '"/></a> '; $json['html'] .= '<input class="button-secondary" type="submit" name="cancel" value="' . __('Cancel', 'redirection') . '"/>'; } $this->output_ajax_response($json); }
?> :</th> <td><input style="width: 95%" type="text" name="name" value="<?php echo esc_attr($group->get_name()); ?> "/></td> </tr> <tr> <th width="70"><?php _e('Module', 'redirection'); ?> </th> <td> <select name="module_id"> <?php foreach (Red_Module::get_for_select() as $module) { ?> <option value="<?php echo esc_attr($module->get_id()); ?> "<?php selected($module->get_id(), $group->get_module_id()); ?> ><?php echo esc_html($module->get_name()); ?> </option> <?php } ?> </select>
public function disable() { global $wpdb; $wpdb->update($wpdb->prefix . 'redirection_groups', array('status' => 'disabled'), array('id' => $this->id)); $wpdb->update($wpdb->prefix . 'redirection_items', array('status' => 'disabled'), array('group_id' => $this->id)); Red_Module::flush($this->id); }
static function save_order($items, $start) { global $wpdb; foreach ($items as $pos => $id) { $wpdb->update($wpdb->prefix . 'redirection_items', array('position' => $pos + $start), array('id' => $id)); } Red_Module::flush($this->group_id); }
function move_to($module) { global $wpdb; $wpdb->update($wpdb->prefix . 'redirection_groups', array('module_id' => intval($module)), array('id' => $this->id)); Red_Module::flush($module); Red_Module::flush($this->id); }
function admin_groups($module) { include dirname(__FILE__) . '/models/pager.php'; if (isset($_POST['add']) && check_admin_referer('redirection-add_group')) { if (Red_Group::create(stripslashes_deep($_POST))) { $this->render_message(__('Your group was added successfully', 'redirection')); Red_Module::flush($module); } else { $this->render_error(__('Please specify a group name', 'redirection')); } } if ($module == 0) { $module = Red_Module::get_first_id(); } $pager = new RE_Pager($_GET, $_SERVER['REQUEST_URI'], 'position', 'ASC'); $items = Red_Group::get_all($module, $pager); $this->render_admin('group_list', array('groups' => $items, 'pager' => $pager, 'modules' => Red_Module::get_for_select(), 'module' => Red_Module::get($module))); }
public function ajax_group_edit() { $group_id = intval($_POST['id']); $this->check_ajax_referer('red-edit_' . $group_id); $group = Red_Group::get($group_id); if ($group) { $json['html'] = $this->capture('group_edit', array('group' => $group, 'modules' => Red_Module::get_for_select())); } else { $json['error'] = __('Unable to perform action') . ' - could not find group'; } $this->output_ajax_response($json); }
function save_order($items, $start) { global $wpdb; foreach ($items as $pos => $id) { $wpdb->query("UPDATE {$wpdb->prefix}redirection_items SET position='" . ($pos + $start) . "' WHERE id='{$id}'"); } $item = Red_Item::get_by_id($id); $group = Red_Group::get($item->group_id); Red_Module::flush($group->module_id); }