function create($details)
 {
     global $wpdb;
     // Auto generate URLs
     if ($details['source'] == '') {
         $details['source'] = Red_Item::auto_generate();
     }
     if ($details['target'] == '') {
         $details['target'] = Red_Item::auto_generate();
     }
     // Make sure we don't redirect to ourself
     if ($details['source'] == $details['target']) {
         $details['target'] .= '-1';
     }
     $matcher = Red_Match::create($details['match']);
     $group_id = intval($details['group']);
     if ($group_id > 0 && $matcher) {
         $regex = isset($details['regex']) && $details['regex'] != false ? 1 : 0;
         $position = $wpdb->get_var($wpdb->prepare("SELECT COUNT(id) 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' => Red_Item::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);
         $wpdb->insert($wpdb->prefix . 'redirection_items', $data);
         $group = Red_Group::get($group_id);
         Red_Module::flush($group->module_id);
         return Red_Item::get_by_id($wpdb->insert_id);
     }
     return false;
 }
Ejemplo n.º 2
0
 function create($details)
 {
     global $wpdb;
     // Auto generate URLs
     if ($details['source'] == '') {
         $details['source'] = Red_Item::auto_generate();
     }
     if ($details['target'] == '') {
         $details['target'] = Red_Item::auto_generate();
     }
     // Make sure we don't redirect to ourself
     if ($details['source'] == $details['target']) {
         $details['target'] .= '-1';
     }
     $matcher = Red_Match::create($details['match']);
     $group_id = intval($details['group']);
     if ($group_id > 0 && $matcher) {
         $match = $wpdb->escape($details['match']);
         $regex = isset($details['regex']) && $details['regex'] != false ? true : false;
         $url = $wpdb->escape(Red_Item::sanitize_url($details['source'], $regex));
         $action = $details['red_action'];
         $position = $wpdb->get_var("SELECT COUNT(id) FROM {$wpdb->prefix}redirection_items WHERE group_id='{$group_id}'");
         $data = $wpdb->escape($matcher->data($details));
         if ($action == 'url' || $action == 'random') {
             $action_code = 301;
         } else {
             if ($action == 'error') {
                 $action_code = 404;
             } else {
                 $action_code = 0;
             }
         }
         if (isset($details['action_code'])) {
             $action_code = intval($details['action_code']);
         }
         $wpdb->query("INSERT INTO {$wpdb->prefix}redirection_items (url,action_type,regex,position,match_type,action_data,action_code,last_access,group_id) VALUES ('{$url}','{$action}','" . ($regex ? 1 : 0) . "','{$position}','{$match}','{$data}',{$action_code},0,'{$group_id}')");
         $group = Red_Group::get($group_id);
         Red_Module::flush($group->module_id);
         return Red_Item::get_by_id($wpdb->insert_id);
     }
     return false;
 }