Exemplo n.º 1
0
 public function get(array $items)
 {
     include_once dirname(dirname(__FILE__)) . '/models/htaccess.php';
     $htaccess = new Red_Htaccess();
     foreach ($items as $item) {
         $htaccess->add($item);
     }
     return $htaccess->get();
 }
Exemplo n.º 2
0
 public function testRedirectUrlWithQuery()
 {
     $htaccess = new Red_Htaccess();
     $htaccess->add(new Red_Item((object) array('match_type' => 'url', 'id' => 1, 'action_type' => 'url', 'url' => '/my-test?query=1', 'action_code' => 301)));
     $htaccess->add(new Red_Item((object) array('match_type' => 'url', 'id' => 1, 'action_type' => 'url', 'url' => '/my-test.php?query=1&thing=2', 'action_code' => 302)));
     $file = $htaccess->get();
     $lines = explode("\n", $file);
     $this->assertEquals('RewriteCond %{QUERY_STRING} ^query=1$', trim($lines[5]));
     $this->assertEquals('RewriteRule ^/my-test$  [R=301,L]', trim($lines[6]));
     $this->assertEquals('RewriteCond %{QUERY_STRING} ^query=1&thing=2$', trim($lines[7]));
     $this->assertEquals('RewriteRule ^/my-test\\.php$  [R=302,L]', trim($lines[8]));
 }
Exemplo n.º 3
0
 function module_flush($items)
 {
     // Produce the .htaccess file
     include_once dirname(__FILE__) . '/../models/htaccess.php';
     $htaccess = new Red_Htaccess($this);
     if (is_array($items) && count($items) > 0) {
         foreach ($items as $item) {
             $htaccess->add($item);
         }
     }
     $htaccess->save($this->location, $this->name);
 }
Exemplo n.º 4
0
 function export(array $items)
 {
     include_once dirname(dirname(__FILE__)) . '/models/htaccess.php';
     $htaccess = new Red_Htaccess();
     $filename = 'redirection-' . date_i18n(get_option('date_format')) . '.htaccess';
     header('Content-Type: application/octet-stream');
     header('Cache-Control: no-cache, must-revalidate');
     header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
     header('Content-Disposition: attachment; filename="' . $filename . '"');
     foreach ($items as $item) {
         $htaccess->add($item);
     }
     echo $htaccess->generate();
 }
Exemplo n.º 5
0
 public function update($data)
 {
     include_once dirname(dirname(__FILE__)) . '/models/htaccess.php';
     $save = array('location' => isset($data['location']) ? $data['location'] : false, 'canonical' => isset($data['canonical']) ? $data['canonical'] : false);
     if (!empty($this->location) && $save['location'] !== $this->location) {
         // Location has moved. Remove from old location
         $htaccess = new Red_Htaccess();
         $htaccess->save($this->location, '');
     }
     $this->load($save);
     if ($save['location'] && $this->flush_module() === false) {
         return __('Cannot write to chosen location - check path and permissions.', 'redirection');
     }
     $options = red_get_options();
     $options['modules'][self::MODULE_ID] = $save;
     update_option('redirection_options', $options);
     return true;
 }