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