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;
 }
 public function ajax_group_save()
 {
     global $hook_suffix;
     $hook_suffix = '';
     $group_id = intval($_POST['id']);
     $this->check_ajax_referer('redirection-group_save_' . $group_id);
     $group = Red_Group::get($group_id);
     if ($group) {
         $group->update($_POST);
         $pager = new Redirection_Group_Table(array(), false);
         $json = array('html' => $pager->column_name($group));
     } else {
         $json['error'] = __('Unable to perform action') . ' - could not find redirect';
     }
     $this->output_ajax_response($json);
 }
Beispiel #4
0
 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;
 }
Beispiel #5
0
 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);
 }
Beispiel #6
0
 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);
         }
     }
 }
Beispiel #7
0
 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);
     }
 }
 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'));
 }
 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')));
 }
Beispiel #10
0
 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);
     }
 }
Beispiel #11
0
 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);
 }
Beispiel #12
0
 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());
                         }
                     }
                 }
             }
         }
     }
 }
 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')));
 }
Beispiel #14
0
	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);
	}