Пример #1
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]));
 }
Пример #2
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();
 }
Пример #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);
 }
Пример #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();
 }
Пример #5
0
 protected function flush_module()
 {
     include_once dirname(dirname(__FILE__)) . '/models/htaccess.php';
     if (empty($this->location)) {
         return;
     }
     $items = Red_Item::get_by_module($this->get_id());
     // Produce the .htaccess file
     $htaccess = new Red_Htaccess();
     if (is_array($items) && count($items) > 0) {
         foreach ($items as $item) {
             if ($item->is_enabled()) {
                 $htaccess->add($item);
             }
         }
     }
     return $htaccess->save($this->location);
 }