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