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_ContentTestController extends ModRewrite_ControllerAbstract {
26:
27: 28: 29: 30:
31: protected $_iMaxItems = 0;
32:
33: 34: 35:
36: public function init() {
37: $this->_oView->content = '';
38: $this->_oView->form_idart_chk = ($this->_getParam('idart')) ? ' checked="checked"' : '';
39: $this->_oView->form_idcat_chk = ($this->_getParam('idcat')) ? ' checked="checked"' : '';
40: $this->_oView->form_idcatart_chk = ($this->_getParam('idcatart')) ? ' checked="checked"' : '';
41: $this->_oView->form_idartlang_chk = ($this->_getParam('idartlang')) ? ' checked="checked"' : '';
42: $this->_oView->form_maxitems = (int) $this->_getParam('maxitems', 200);
43: $this->_iMaxItems = $this->_oView->form_maxitems;
44: }
45:
46: 47: 48:
49: public function indexAction() {
50: $this->_oView->content = '';
51: }
52:
53: 54: 55:
56: public function testAction() {
57: $this->_oView->content = '';
58:
59:
60: $aTests = array();
61:
62:
63: $oMRTest = new ModRewriteTest($this->_iMaxItems);
64:
65: $startTime = getmicrotime();
66:
67:
68: $aStruct = $oMRTest->fetchFullStructure();
69: ModRewriteDebugger::add($aStruct, 'mr_test.php $aStruct');
70:
71:
72: foreach ($aStruct as $idcat => $aCat) {
73:
74: $aTests[] = array(
75: 'url' => $oMRTest->composeURL($aCat, 'c'),
76: 'level' => $aCat['level'],
77: 'name' => $aCat['name']
78: );
79:
80: foreach ($aCat['articles'] as $idart => $aArt) {
81:
82: $aTests[] = array(
83: 'url' => $oMRTest->composeURL($aArt, 'a'),
84: 'level' => $aCat['level'],
85: 'name' => $aCat['name'] . ' :: ' . $aArt['title']
86: );
87: }
88: }
89:
90:
91: $this->_oView->content = '<pre>';
92:
93: $oMRUrlStack = ModRewriteUrlStack::getInstance();
94:
95:
96: foreach ($aTests as $p => $v) {
97: $oMRUrlStack->add($v['url']);
98: }
99:
100: $successCounter = 0;
101: $failCounter = 0;
102:
103:
104: foreach ($aTests as $p => $v) {
105: $url = mr_buildNewUrl($v['url']);
106: $arr = $oMRTest->resolveUrl($url);
107: $error = '';
108: $resUrl = $oMRTest->getResolvedUrl();
109: $color = 'green';
110:
111: if ($url !== $resUrl) {
112: if ($oMRTest->getRoutingFoundState()) {
113: $successCounter++;
114: $resUrl = 'route to -> ' . $resUrl;
115: } else {
116: $color = 'red';
117: $failCounter++;
118: }
119: } else {
120: $successCounter++;
121: }
122:
123:
124: if (isset($arr['error'])) {
125: switch ($arr['error']) {
126: case ModRewriteController::ERROR_CLIENT:
127: $error = 'client';
128: break;
129: case ModRewriteController::ERROR_LANGUAGE:
130: $error = 'language';
131: break;
132: case ModRewriteController::ERROR_CATEGORY:
133: $error = 'category';
134: break;
135: case ModRewriteController::ERROR_ARTICLE:
136: $error = 'article';
137: break;
138: case ModRewriteController::ERROR_POST_VALIDATION:
139: $error = 'validation';
140: break;
141: }
142: }
143:
144: $pref = str_repeat(' ', $v['level']);
145:
146:
147: $itemTpl = $this->_oView->lng_result_item_tpl;
148: $itemTpl = str_replace('{pref}', $pref, $itemTpl);
149: $itemTpl = str_replace('{name}', $v['name'], $itemTpl);
150: $itemTpl = str_replace('{url_in}', $v['url'], $itemTpl);
151: $itemTpl = str_replace('{url_out}', $url, $itemTpl);
152: $itemTpl = str_replace('{color}', $color, $itemTpl);
153: $itemTpl = str_replace('{url_res}', $resUrl, $itemTpl);
154: $itemTpl = str_replace('{err}', $error, $itemTpl);
155: $itemTpl = str_replace('{data}', $oMRTest->getReadableResolvedData($arr), $itemTpl);
156:
157: $this->_oView->content .= "\n" . $itemTpl . "\n";
158: }
159: $this->_oView->content .= '</pre>';
160:
161: $totalTime = sprintf('%.4f', (getmicrotime() - $startTime));
162:
163:
164: $msg = $this->_oView->lng_result_message_tpl;
165: $msg = str_replace('{time}', $totalTime, $msg);
166: $msg = str_replace('{num_urls}', ($successCounter + $failCounter), $msg);
167: $msg = str_replace('{num_success}', $successCounter, $msg);
168: $msg = str_replace('{num_fail}', $failCounter, $msg);
169:
170: $this->_oView->content = $msg . $this->_oView->content;
171: }
172:
173: }
174: