1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10: 11:
12:
13:
14: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
15:
16: 17: 18: 19: 20:
21: class Solr {
22:
23: 24: 25: 26: 27:
28: private static $_name = 'search_solr';
29:
30: 31: 32: 33:
34: public static function log($whatever, $file = NULL, $line = NULL) {
35: $msg = '';
36: if ($whatever instanceof Exception) {
37: $msg .= '========================' . PHP_EOL;
38: $msg .= '=== LOGGED EXCEPTION ===' . PHP_EOL;
39: $msg .= 'REFERER: ' . $_SERVER['HTTP_REFERER'] . PHP_EOL;
40: $msg .= 'URI: ' . $_SERVER['REQUEST_URI'] . PHP_EOL;
41: $msg .= 'MSG: ' . $whatever->getMessage() . PHP_EOL;
42: $msg .= 'TRACE: ' . $whatever->getTraceAsString() . PHP_EOL;
43: $msg .= '========================';
44: } else {
45: $msg = $whatever;
46: }
47:
48: static $start = 0;
49: if (0 == $start) {
50: $start = microtime(true);
51: }
52: $delta = microtime(true) - $start;
53:
54:
55: $cfg = cRegistry::getConfig();
56: $filename = $cfg['path']['contenido_logs'] . 'errorlog.txt';
57:
58:
59: $prefix = number_format($delta * 1000, 0) . 'ms: ';
60: if (NULL !== $file) {
61: $prefix .= $file;
62: if (NULL !== $line) {
63: $prefix .= ':' . $line;
64: }
65: $prefix .= ' ';
66: }
67:
68:
69: $log = new cLog(cLogWriter::factory('file', array(
70: 'destination' => $filename
71: )));
72: $log->info($prefix . $whatever);
73: }
74:
75: 76:
77: public static function getName() {
78: return self::$_name;
79: }
80:
81: 82: 83: 84: 85:
86: public static function getPath() {
87: $cfg = cRegistry::getConfig();
88:
89: $path = cRegistry::getBackendPath() . $cfg['path']['plugins'];
90: $path .= self::$_name . '/';
91:
92: return $path;
93: }
94:
95: 96: 97: 98: 99:
100: public static function i18n($key) {
101: $trans = i18n($key, self::$_name);
102: return $trans;
103: }
104:
105: 106: 107: 108: 109: 110: 111: 112: 113:
114: public static function getClientOptions() {
115: $options = array();
116:
117:
118: $options['secure'] = (bool) getSystemProperty('solr', 'secure');
119:
120:
121: $options['hostname'] = getSystemProperty('solr', 'hostname');
122:
123:
124: $options['port'] = getSystemProperty('solr', 'port');
125:
126:
127: $options['path'] = getSystemProperty('solr', 'path');
128:
129:
130: $options['wt'] = getSystemProperty('solr', 'wt');
131:
132:
133: $options['login'] = getSystemProperty('solr', 'login');
134:
135:
136: $options['password'] = getSystemProperty('solr', 'password');
137:
138:
139: $options['proxy_host'] = getSystemProperty('solr', 'proxy_host');
140:
141:
142: $options['proxy_port'] = getSystemProperty('solr', 'proxy_port');
143:
144:
145: $options['proxy_login'] = getSystemProperty('solr', 'proxy_login');
146:
147:
148: $options['proxy_password'] = getSystemProperty('solr', 'proxy_password');
149:
150:
151:
152: $options['timeout'] = getSystemProperty('solr', 'timeout');
153:
154:
155:
156:
157:
158: $options['ssl_cert'] = getSystemProperty('solr', 'ssl_cert');
159:
160:
161: $options['ssl_key'] = getSystemProperty('solr', 'ssl_key');
162:
163:
164:
165:
166: $options['ssl_keypassword'] = getSystemProperty('solr', 'ssl_keypassword');
167:
168:
169: $options['ssl_cainfo'] = getSystemProperty('solr', 'ssl_cainfo');
170:
171:
172:
173: $options['ssl_capath'] = getSystemProperty('solr', 'ssl_capath');
174:
175:
176: foreach ($options as $key => $value) {
177: if (0 == strlen(trim($value))) {
178: unset($options[$key]);
179: }
180: }
181:
182: return $options;
183: }
184:
185: 186: 187: 188: 189: 190:
191: public static function validateClientOptions(array $options) {
192: $valid = true;
193: $valid &= array_key_exists('hostname', $options);
194: $valid &= array_key_exists('port', $options);
195: $valid &= array_key_exists('path', $options);
196: $valid &= array_key_exists('login', $options);
197: $valid &= array_key_exists('password', $options);
198:
199: if (!$valid) {
200: throw new SolrWarning(Solr::i18n('WARNING_INVALID_CLIENT_OPTIONS'));
201: }
202: }
203:
204: 205: 206: 207:
208: public static function logException(Exception $e) {
209: $cfg = cRegistry::getConfig();
210:
211: $log = new cLog(cLogWriter::factory('file', array(
212: 'destination' => $cfg['path']['contenido_logs'] . 'errorlog.txt'
213: )), cLog::ERR);
214:
215: $log->err($e->getMessage());
216: $log->err($e->getTraceAsString());
217: }
218:
219: 220: 221: 222: 223: 224:
225: public static function displayException(Exception $e, $showTrace = false) {
226: header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error', true, 500);
227:
228: if (true) {
229:
230: $class = "ui-state-error";
231: $icon = "ui-icon-alert";
232: } else {
233:
234: $class = "ui-state-highlight";
235: $icon = "ui-icon-info";
236: }
237:
238: echo '<div class="ui-widget">';
239: echo '<div class="' . $class . ' ui-corner-all">';
240: echo '<p>';
241: echo '<span class="ui-icon ' . $icon . '"></span>';
242:
243: echo $e->getMessage();
244: if (true === $showTrace) {
245: echo '<pre style="overflow: auto">';
246: echo htmlentities($e->getTraceAsString(), ENT_COMPAT | ENT_HTML401, 'UTF-8');
247: echo '</pre>';
248: }
249: echo '</p>';
250: echo '</div>';
251: echo '</div>';
252: }
253:
254: 255: 256: 257: 258: 259: 260:
261: public static function notifyException(Exception $e) {
262: $cGuiNotification = new cGuiNotification();
263: $level = cGuiNotification::LEVEL_ERROR;
264: $message = $e->getMessage();
265:
266: return $cGuiNotification->returnNotification($level, $message);
267: }
268: }
269:
270:
271: $cfg['templates']['solr_right_bottom'] = $cfg['plugins'][Solr::getName()] . 'templates/template.right_bottom.tpl';
272:
273:
274: $pluginClassPath = 'contenido/plugins/' . Solr::getName() . '/';
275: cAutoload::addClassmapConfig(array(
276: 'SolrIndexer' => $pluginClassPath . 'classes/class.solr_indexer.php',
277: 'SolrSearcherAbstract' => $pluginClassPath . 'classes/class.solr_searcher_abstract.php',
278: 'SolrSearcherSimple' => $pluginClassPath . 'classes/class.solr_searcher_simple.php',
279: 'SolrSearchModule' => $pluginClassPath . 'classes/class.solr_search_module.php',
280: 'SolrRightBottomPage' => $pluginClassPath . 'classes/class.solr.gui.php',
281: 'SolrException' => $pluginClassPath . 'classes/class.solr_exception.php',
282: 'SolrWarning' => $pluginClassPath . 'classes/class.solr_warning.php'
283: ));
284: unset($pluginClassPath);
285:
286:
287:
288: cRegistry::getCecRegistry()->addChainFunction('Contenido.Action.con_saveart.AfterCall', 'SolrIndexer::handleStoringOfArticle');
289:
290: cRegistry::getCecRegistry()->addChainFunction('Contenido.Content.AfterStore', 'SolrIndexer::handleStoringOfContentEntry');
291: