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: public static function validateClientOptions(array $options) {
191: $valid = true;
192: $valid &= array_key_exists('hostname', $options);
193: $valid &= array_key_exists('port', $options);
194: $valid &= array_key_exists('path', $options);
195: $valid &= array_key_exists('login', $options);
196: $valid &= array_key_exists('password', $options);
197:
198: if (!$valid) {
199: throw new SolrWarning(Solr::i18n('WARNING_INVALID_CLIENT_OPTIONS'));
200: }
201: }
202:
203: 204: 205: 206:
207: public static function logException(Exception $e) {
208: $cfg = cRegistry::getConfig();
209:
210: $log = new cLog(cLogWriter::factory('file', array(
211: 'destination' => $cfg['path']['contenido_logs'] . 'errorlog.txt'
212: )), cLog::ERR);
213:
214: $log->err($e->getMessage());
215: $log->err($e->getTraceAsString());
216: }
217:
218: 219: 220: 221: 222: 223:
224: public static function displayException(Exception $e, $showTrace = false) {
225: header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error', true, 500);
226:
227: if (true) {
228:
229: $class = "ui-state-error";
230: $icon = "ui-icon-alert";
231: } else {
232:
233: $class = "ui-state-highlight";
234: $icon = "ui-icon-info";
235: }
236:
237: echo '<div class="ui-widget">';
238: echo '<div class="' . $class . ' ui-corner-all">';
239: echo '<p>';
240: echo '<span class="ui-icon ' . $icon . '"></span>';
241:
242: echo $e->getMessage();
243: if (true === $showTrace) {
244: echo '<pre style="overflow: auto">';
245: echo htmlentities($e->getTraceAsString(), ENT_COMPAT | ENT_HTML401, 'UTF-8');
246: echo '</pre>';
247: }
248: echo '</p>';
249: echo '</div>';
250: echo '</div>';
251: }
252:
253: 254: 255: 256: 257: 258: 259:
260: public static function notifyException(Exception $e) {
261: $cGuiNotification = new cGuiNotification();
262: $level = cGuiNotification::LEVEL_ERROR;
263: $message = $e->getMessage();
264:
265: return $cGuiNotification->returnNotification($level, $message);
266: }
267: }
268:
269:
270: $cfg['templates']['solr_right_bottom'] = $cfg['plugins'][Solr::getName()] . 'templates/template.right_bottom.tpl';
271:
272:
273: $pluginClassPath = 'contenido/plugins/' . Solr::getName() . '/';
274: cAutoload::addClassmapConfig(array(
275: 'SolrIndexer' => $pluginClassPath . 'classes/class.solr_indexer.php',
276: 'SolrSearcherAbstract' => $pluginClassPath . 'classes/class.solr_searcher_abstract.php',
277: 'SolrSearcherSimple' => $pluginClassPath . 'classes/class.solr_searcher_simple.php',
278: 'SolrSearchModule' => $pluginClassPath . 'classes/class.solr_search_module.php',
279: 'SolrRightBottomPage' => $pluginClassPath . 'classes/class.solr.gui.php',
280: 'SolrException' => $pluginClassPath . 'classes/class.solr_exception.php',
281: 'SolrWarning' => $pluginClassPath . 'classes/class.solr_warning.php'
282: ));
283: unset($pluginClassPath);
284:
285:
286:
287: cRegistry::getCecRegistry()->addChainFunction('Contenido.Action.con_saveart.AfterCall', 'SolrIndexer::handleStoringOfArticle');
288:
289: cRegistry::getCecRegistry()->addChainFunction('Contenido.Content.AfterStore', 'SolrIndexer::handleStoringOfContentEntry');
290: