static function flush($group_id) { $group = Red_Group::get($group_id); if ($group) { $module = Red_Module::get($group->get_module_id()); if ($module) { $module->flush_module(); } } }
static function create($name, $module_id) { global $wpdb; $name = trim($name); if ($name !== '' && $module_id > 0) { $position = $wpdb->get_var($wpdb->prepare("SELECT COUNT( * ) FROM {$wpdb->prefix}redirection_groups WHERE module_id=%d", $module_id)); $data = array('name' => trim($name), 'module_id' => intval($module_id), 'position' => intval($position)); $wpdb->insert($wpdb->prefix . 'redirection_groups', $data); return Red_Group::get($wpdb->insert_id); } return false; }
<tr id="target"> <th align="right"><?php _e('Target URL', 'redirection'); ?> :</th> <td><input type="text" name="target" style="width: 95%"/></td> </tr> <tr> <th><?php _e('Group', 'redirection'); ?> :</th> <td> <select name="group_id"> <?php echo $this->select(Red_Group::get_for_select(), $group); ?> </select> </td> </tr> <tr> <th></th> <td> <input class="button-primary" type="submit" name="add" value="<?php esc_attr_e('Add Redirection', 'redirection'); ?> " id="submit"/> <?php if (isset($group)) { ?> <input type="hidden" name="group" value="<?php
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); } }
<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 (); ?> </div> </div> </form> <?php if (count ($logs) > 0) : ?>
<strong><?php _e ('Action', 'redirection'); ?>:</strong> <select name="red_action" onchange="return change_add_redirect (this)"> <?php echo $this->select (Red_Item::actions (), 'url'); ?> </select> <label><?php _e ('Regular expression', 'redirection'); ?>: <input id="regex" type="checkbox" name="regex"/></label> </td> </tr> <tr id="target"> <th align="right"><?php _e ('Target URL', 'redirection') ?>:</th> <td><input type="text" name="target" style="width: 95%"/></td> </tr> <?php if (!isset($group)) : ?> <tr> <th><?php _e ('Group', 'redirection'); ?>:</th> <td><select name="group"><?php echo $this->select (Red_Group::get_for_select (), isset ($_GET['group']) ? intval ($_GET['group']) : 0)?></select></td> </tr> <?php endif; ?> <tr> <th></th> <td> <input class="button-primary" type="submit" name="add" value="<?php _e ('Add Redirection', 'redirection') ?>" id="submit"/> <?php if (isset($group)) : ?> <input type="hidden" name="group" value="<?php echo esc_attr( $group ) ?>"/> <?php endif; ?> <input type="hidden" name="action" value="red_redirect_add"/> <input type="hidden" name="_ajax_nonce" value="<?php echo wp_create_nonce( 'redirection-redirect_add' ); ?>"/> <div id="error"></div> </td>
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); }
<th align="right"><?php _e('Target URL', 'redirection'); ?> :</th> <td><input type="text" name="target" style="width: 95%"/></td> </tr> <?php if (!isset($group)) { ?> <tr> <th><?php _e('Group', 'redirection'); ?> :</th> <td><select name="group"><?php echo $this->select(Red_Group::get_for_select(), isset($_GET['group']) ? intval($_GET['group']) : 0); ?> </select></td> </tr> <?php } ?> <tr> <th></th> <td> <input class="button-primary" type="submit" name="add" value="<?php esc_attr_e('Add Redirection', 'redirection'); ?> " id="submit"/> <?php if (isset($group)) {
function process_bulk_action() { if (!isset($_POST['item'])) { return; } if (in_array($this->current_action(), array('delete'))) { $groups = array(); foreach ((array) $_POST['item'] as $id) { $redirect = Red_Group::get(intval($id)); if ($redirect) { $groups[] = $redirect; } } array_map(array(&$this, 'delete_item'), $groups); } }
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 save_order($items, $start) { global $wpdb; foreach ($items as $pos => $id) { $wpdb->query("UPDATE {$wpdb->prefix}redirection_groups SET position='" . ($pos + $start) . "' WHERE id='{$id}'"); } $group = Red_Group::get($items[0]); Red_Module::flush($group->module_id); }
function process_bulk_action() { if (!isset($_POST['item'])) { return; } if (in_array($this->current_action(), array('delete', 'enable', 'disable'))) { $groups = array(); foreach ((array) $_POST['item'] as $id) { $group = Red_Group::get(intval($id)); if ($group) { if ($this->current_action() === 'delete') { $group->delete(); } else { if ($this->current_action() === 'enable') { $group->enable(); Red_Module::flush($group->get_id()); } else { if ($this->current_action() === 'disable') { $group->disable(); Red_Module::flush($group->get_id()); } } } } } } }
<tr id="target"> <th align="right"><?php _e('Target URL', 'redirection'); ?> :</th> <td><input type="text" name="target" style="width: 95%"/></td> </tr> <tr> <th><?php _e('Group', 'redirection'); ?> :</th> <td> <select name="group_id"> <?php echo $this->select(Red_Group::get_for_select(), isset($group) ? intval($group) : ''); ?> </select> </td> </tr> <tr> <th></th> <td> <input class="button-primary" type="submit" name="add" value="<?php esc_attr_e('Add Redirection', 'redirection'); ?> " id="submit"/> <?php if (isset($group)) { ?> <input type="hidden" name="group" value="<?php
function admin_redirects($group) { include dirname(__FILE__) . '/models/pager.php'; if ($group == 0) { $group = Red_Group::get_first_id(); } $pager = new RE_Pager($_GET, admin_url(add_query_arg(array(), 'tools.php?page=redirection.php')), 'position', 'ASC'); $items = Red_Item::get_by_group($group, $pager); $this->render_admin('item_list', array('options' => $this->get_options(), 'items' => $items, 'pager' => $pager, 'group' => Red_Group::get($group), 'groups' => Red_Group::get_for_select(), 'date_format' => get_option('date_format'))); }
"/> <span class="sub">(<?php _e('optional', 'redirection'); ?> )</span> </td> </tr> <tr class="advanced"> <th width="100"><?php _e('Group', 'redirection'); ?> :</th> <td> <select name="group_id"> <?php echo $this->select(Red_Group::get_for_select(), $redirect->get_group_id()); ?> </select> </td> </tr> <?php $redirect->match->show(); ?> <tr> <th></th> <td> <div class="table-actions"> <input class="button-primary" type="submit" name="save" value="<?php _e('Save', 'redirection');
function save_order($items, $start) { global $wpdb; foreach ($items as $pos => $id) { $wpdb->update($wpdb->prefix . 'redirection_groups', array('position' => $pos + $start), array('id' => intval($id))); } $group = Red_Group::get($items[0]); Red_Module::flush($group->module_id); }
static function create(array $details) { global $wpdb; $details = array_map('trim', $details); $details = array_map('stripslashes', $details); // Auto generate URLs if (empty($details['source'])) { $details['source'] = self::auto_generate(); } if (empty($details['target'])) { $details['target'] = self::auto_generate(); } // Make sure we don't redirect to ourself if ($details['source'] == $details['target']) { return new WP_Error('redirect-add', __('Source and target URL must be different', 'redirection')); } $parsed_url = parse_url($details['source']); $parsed_domain = parse_url(site_url()); if (isset($parsed_url['scheme']) && ($parsed_url['scheme'] === 'http' || $parsed_url['scheme'] === 'https') && $parsed_url['host'] !== $parsed_domain['host']) { return new WP_Error('redirect-add', sprintf(__('You can only redirect from a relative URL (<code>%s</code>) on this domain (<code>%s</code>).', 'redirection'), $parsed_url['path'], $parsed_domain['host'])); } $matcher = Red_Match::create($details['match']); $group_id = intval($details['group_id']); $group = Red_Group::get($group_id); if ($group_id <= 0 || !$group) { return new WP_Error('redirect-add', __('Invalid group when creating redirect', 'redirection')); } if (!$matcher) { return new WP_Error('redirect-add', __('Invalid source URL when creating redirect for given match type', 'redirection')); } $regex = isset($details['regex']) && $details['regex'] != false ? 1 : 0; $position = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM {$wpdb->prefix}redirection_items WHERE group_id=%d", $group_id)); $action = $details['red_action']; $action_code = 0; if ($action == 'url' || $action == 'random') { $action_code = 301; } elseif ($action == 'error') { $action_code = 404; } if (isset($details['action_code'])) { $action_code = intval($details['action_code']); } $data = array('url' => self::sanitize_url($details['source'], $regex), 'action_type' => $details['red_action'], 'regex' => $regex, 'position' => $position, 'match_type' => $details['match'], 'action_data' => $matcher->data($details), 'action_code' => $action_code, 'last_access' => '0000-00-00 00:00:00', 'group_id' => $group_id); $data = apply_filters('redirection_create_redirect', $data); $wpdb->delete($wpdb->prefix . 'redirection_items', array('url' => $data['action_data'], 'action_type' => $data['action_type'], 'action_data' => $data['url'])); if ($wpdb->insert($wpdb->prefix . 'redirection_items', $data)) { Red_Module::flush($group_id); return self::get_by_id($wpdb->insert_id); } return new WP_Error('redirect-add', __('Unable to add new redirect - delete Redirection from the options page and re-install')); }
static function create($data) { global $wpdb; $name = trim($data['name']); $module = intval($data['module_id']); if ($name != '' && $module > 0) { $position = $wpdb->get_var($wpdb->prepare("SELECT COUNT( * ) FROM {$wpdb->prefix}redirection_groups WHERE module_id=%d", $module)); if (isset($data['position'])) { $position = $data['position']; } $data = array('name' => trim($name), 'module_id' => intval($module), 'position' => intval($position)); if (isset($data['status']) && isset($data['position'])) { $data['status'] = $data['status']; } $wpdb->insert($wpdb->prefix . 'redirection_groups', $data); Red_Module::flush($module); return Red_Group::get($wpdb->insert_id); } return false; }
function admin_redirects($group) { include dirname(__FILE__) . '/models/pager.php'; if ($group == 0) { $group = Red_Group::get_first_id(); } $pager = new RE_Pager($_GET, $_SERVER['REQUEST_URI'], 'position', 'ASC'); $items = Red_Item::get_by_group($group, $pager); $this->render_admin('item_list', array('items' => $items, 'pager' => $pager, 'group' => Red_Group::get($group), 'groups' => Red_Group::get_for_select(), 'date_format' => get_option('date_format'))); }
public function ajax_redirect_edit() { $this->check_ajax_referer('red-edit_' . intval($_POST['id'])); $redirect = Red_Item::get_by_id(intval($_POST['id'])); if ($redirect) { $json['html'] = $this->capture('item_edit', array('redirect' => $redirect, 'groups' => Red_Group::get_for_select())); } else { $json['error'] = __('Unable to perform action') . ' - could not find redirect'; } $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); }