1: <?php
  2:   3:   4:   5:   6:   7:   8:   9:  10:  11:  12:  13: 
 14: 
 15: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
 16: 
 17: 
 18:  19:  20:  21:  22:  23:  24: 
 25: class ModRewrite_ContentExpertController extends ModRewrite_ControllerAbstract {
 26: 
 27:      28:  29:  30: 
 31:     protected $_htaccessRestrictive = '';
 32: 
 33:      34:  35:  36: 
 37:     protected $_htaccessSimple = '';
 38: 
 39:      40:  41: 
 42:     public function init() {
 43:         $this->_oView->content_before = '';
 44: 
 45:         $pluginPath = $this->_cfg['path']['contenido'] . $this->_cfg['path']['plugins'] . 'mod_rewrite/';
 46:         $this->_htaccessRestrictive = $pluginPath . 'files/htaccess_restrictive.txt';
 47:         $this->_htaccessSimple = $pluginPath . 'files/htaccess_simple.txt';
 48:     }
 49: 
 50:      51:  52: 
 53:     public function indexAction() {
 54: 
 55:     }
 56: 
 57:      58:  59: 
 60:     public function copyHtaccessAction() {
 61:         $type = $this->_getParam('htaccesstype');
 62:         $copy = $this->_getParam('copy');
 63: 
 64:         if ($type != 'restrictive' && $type != 'simple') {
 65:             return;
 66:         } elseif ($copy != 'contenido' && $copy != 'cms') {
 67:             return;
 68:         }
 69: 
 70:         $aInfo = $this->getProperty('htaccessInfo');
 71: 
 72:         if ($aInfo['has_htaccess']) {
 73:             $this->_oView->content_before = $this->_notifyBox('warning', i18n('.htaccess already exists at CONTENIDO-/or client directory, so it is not copied.', 'mod_rewrite'));
 74:             return;
 75:         }
 76: 
 77:         if ($type == 'restrictive') {
 78:             $source = $this->_htaccessRestrictive;
 79:         } else {
 80:             $source = $this->_htaccessSimple;
 81:         }
 82: 
 83:         if ($copy == 'contenido') {
 84:             $dest = $aInfo['contenido_full_path'] . '.htaccess';
 85:         } else {
 86:             $dest = $aInfo['client_full_path'] . '.htaccess';
 87:         }
 88: 
 89:         if (!$result = @copy($source, $dest)) {
 90:             $this->_oView->content_before = $this->_notifyBox('warning', sprintf(i18n('.htaccess could not copy from <strong>%s</strong> to <strong>%s</strong>! Perhaps the target directory has not the required rights to write files at your webserver.', 'mod_rewrite'), $source, $dest));
 91:             return;
 92:         }
 93: 
 94:         $msg = sprintf(i18n('.htaccess are successfully copied to %s', 'mod_rewrite'), str_replace('.htaccess', '', $dest));
 95:         $this->_oView->content_before = $this->_notifyBox('info', $msg);
 96:     }
 97: 
 98:      99: 100: 
101:     public function downloadHtaccessAction() {
102:         $type = $this->_getParam('htaccesstype');
103: 
104:         if ($type != 'restrictive' && $type != 'simple') {
105:             return;
106:         }
107: 
108:         if ($type == 'restrictive') {
109:             $source = $this->_htaccessRestrictive;
110:         } else {
111:             $source = $this->_htaccessSimple;
112:         }
113: 
114:         $this->_oView->content = cFileHandler::read($source);
115: 
116:         header('Content-Type: text/plain');
117:         header('Etag: ' . md5(mt_rand()));
118:         header('Content-Disposition: attachment; filename="' . $type . '.htaccess"');
119:         $this->render('{CONTENT}');
120:     }
121: 
122:     123: 124: 
125:     public function resetAction() {
126:         
127:         ModRewrite::recreateAliases(false);
128:         $this->_oView->content_before = $this->_notifyBox('info', i18n('All aliases have been reset.', 'mod_rewrite'));
129:     }
130: 
131:     132: 133: 
134:     public function resetEmptyAction() {
135:         
136:         ModRewrite::recreateAliases(true);
137:         $this->_oView->content_before = $this->_notifyBox('info', i18n('Only empty aliases have been reset.', 'mod_rewrite'));
138:     }
139: 
140: }
141: