Overview

Packages

  • CONTENIDO
  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentRssCreator
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
    • ScriptCookieDirective
  • mpAutoloaderClassMap
  • None
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • SearchSolr
    • SmartyWrapper
    • UrlShortener
    • UserForum
    • Workflow
  • PluginManager
  • Setup
    • Form
    • GUI
    • Helper
      • Environment
      • Filesystem
      • MySQL
      • PHP
    • UpgradeJob

Classes

  • Solr
  • SolrIndexer
  • SolrSearcherAbstract
  • SolrSearcherSimple
  • SolrSearchModule

Exceptions

  • SolrException
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo
  1: <?php
  2: 
  3: /**
  4:  *
  5:  * @package Plugin
  6:  * @subpackage SearchSolr
  7:  * @author Marcus Gnaß <marcus.gnass@4fb.de>
  8:  * @copyright four for business AG
  9:  * @link http://www.4fb.de
 10:  */
 11: 
 12: // assert CONTENIDO framework
 13: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
 14: 
 15: /**
 16:  * Helper class for this plugin.
 17:  *
 18:  * @author Marcus Gnaß <marcus.gnass@4fb.de>
 19:  */
 20: class Solr {
 21: 
 22:     /**
 23:      * name of this plugin
 24:      *
 25:      * @var string
 26:      */
 27:     private static $_name = 'search_solr';
 28: 
 29:     /**
 30:      *
 31:      * @param mixed $whatever
 32:      */
 33:     public static function log($whatever, $file = NULL, $line = NULL) {
 34:         $msg = '';
 35:         if ($whatever instanceof Exception) {
 36:             $msg .= '========================' . PHP_EOL;
 37:             $msg .= '=== LOGGED EXCEPTION ===' . PHP_EOL;
 38:             $msg .= 'REFERER: ' . $_SERVER['HTTP_REFERER'] . PHP_EOL;
 39:             $msg .= 'URI: ' . $_SERVER['REQUEST_URI'] . PHP_EOL;
 40:             $msg .= 'MSG: ' . $whatever->getMessage() . PHP_EOL;
 41:             $msg .= 'TRACE: ' . $whatever->getTraceAsString() . PHP_EOL;
 42:             $msg .= '========================';
 43:         } else {
 44:             $msg = $whatever;
 45:         }
 46: 
 47:         static $start = 0;
 48:         if (0 == $start) {
 49:             $start = microtime(true);
 50:         }
 51:         $delta = microtime(true) - $start;
 52: 
 53:         // create name of logfile
 54:         $cfg = cRegistry::getConfig();
 55:         $filename = $cfg['path']['contenido_logs'] . 'errorlog.txt';
 56: 
 57:         // extend message with optional prefix
 58:         $prefix = number_format($delta * 1000, 0) . 'ms: ';
 59:         if (NULL !== $file) {
 60:             $prefix .= $file;
 61:             if (NULL !== $line) {
 62:                 $prefix .= ':' . $line;
 63:             }
 64:             $prefix .= ' ';
 65:         }
 66: 
 67:         // log message
 68:         $log = new cLog(cLogWriter::factory('file', array(
 69:             'destination' => $filename
 70:         )));
 71:         $log->info($prefix . $whatever);
 72:     }
 73: 
 74:     /**
 75:      */
 76:     public static function getName() {
 77:         return self::$_name;
 78:     }
 79: 
 80:     /**
 81:      * Return path to this plugins folder.
 82:      *
 83:      * @return string
 84:      */
 85:     public static function getPath() {
 86:         $cfg = cRegistry::getConfig();
 87: 
 88:         $path = cRegistry::getBackendPath() . $cfg['path']['plugins'];
 89:         $path .= self::$_name . '/';
 90: 
 91:         return $path;
 92:     }
 93: 
 94:     /**
 95:      *
 96:      * @param string $key
 97:      * @return string
 98:      */
 99:     public static function i18n($key) {
100:         $trans = i18n($key, self::$_name);
101:         return $trans;
102:     }
103: 
104:     /**
105:      * Returns array of options used to create a SolClient object.
106:      *
107:      * The option values are read from system or client settings.
108:      * Required settings are solr/hostname, solr/port, solr/path.
109:      *
110:      * @return array
111:      */
112:     public static function getClientOptions($idclient, $idlang) {
113: 
114:         //$queryOption = 'getSystemProperty';
115:         $queryOption = 'getEffectiveSetting';
116: 
117:         $options = array();
118: 
119:         // Boolean value indicating whether or not to connect in secure mode.
120:         $options['secure'] = (bool) $queryOption('solr', 'secure');
121: 
122:         // Required. The hostname for the Solr server.
123:         $options['hostname'] = $queryOption('solr', 'hostname');
124: 
125:         // Required. The port number.
126:         $options['port'] = $queryOption('solr', 'port');
127: 
128:         // Required. The path to solr.
129:         $options['path'] = $queryOption('solr', 'path');
130: 
131:         // load path from clientLanguage, client or system
132:         $clientLanguage = new cApiClientLanguage();
133:         $clientLanguage->loadByMany(array(
134:             'idclient' => $idclient,
135:             'idlang' => $idlang
136:         ));
137:         $value = $clientLanguage->isLoaded() ? $clientLanguage->getProperty($type, $name) : false;
138:         if (false === $value) {
139:             $client = new cApiClient($idclient);
140:             $value = $client->isLoaded() ? $client->getProperty($type, $name) : false;
141:         }
142:         if (false === $value) {
143:             $value = getSystemProperty($type, $name);
144:         }
145: 
146:         // The name of the response writer e.g. xml, phpnative.
147:         $options['wt'] = $queryOption('solr', 'wt');
148: 
149:         // Required. The username used for HTTP Authentication, if any.
150:         $options['login'] = $queryOption('solr', 'login');
151: 
152:         // Required. The HTTP Authentication password.
153:         $options['password'] = $queryOption('solr', 'password');
154: 
155:         // The hostname for the proxy server, if any.
156:         $options['proxy_host'] = $queryOption('solr', 'proxy_host');
157: 
158:         // The proxy port.
159:         $options['proxy_port'] = $queryOption('solr', 'proxy_port');
160: 
161:         // The proxy username.
162:         $options['proxy_login'] = $queryOption('solr', 'proxy_login');
163: 
164:         // The proxy password.
165:         $options['proxy_password'] = $queryOption('solr', 'proxy_password');
166: 
167:         // This is maximum time in seconds allowed for the http data transfer
168:         // operation. Default is 30 seconds.
169:         $options['timeout'] = $queryOption('solr', 'timeout');
170: 
171:         // File name to a PEM-formatted file containing the private key +
172:         // private certificate (concatenated in that order).
173:         // Please note the if the ssl_cert file only contains the private
174:         // certificate, you have to specify a separate ssl_key file.
175:         $options['ssl_cert'] = $queryOption('solr', 'ssl_cert');
176: 
177:         // File name to a PEM-formatted private key file only.
178:         $options['ssl_key'] = $queryOption('solr', 'ssl_key');
179: 
180:         // Password for private key.
181:         // The ssl_keypassword option is required if the ssl_cert or ssl_key
182:         // options are set.
183:         $options['ssl_keypassword'] = $queryOption('solr', 'ssl_keypassword');
184: 
185:         // Name of file holding one or more CA certificates to verify peer with.
186:         $options['ssl_cainfo'] = $queryOption('solr', 'ssl_cainfo');
187: 
188:         // Name of directory holding multiple CA certificates to verify peer
189:         // with.
190:         $options['ssl_capath'] = $queryOption('solr', 'ssl_capath');
191: 
192:         // remove unset options (TODO could be done via array_filter too)
193:         foreach ($options as $key => $value) {
194:             if (0 == strlen(trim($value))) {
195:                 unset($options[$key]);
196:             }
197:         }
198: 
199:         return $options;
200:     }
201: 
202:     /**
203:      * Check if required options exist.
204:      * Required settings are solr/hostname, solr/port, solr/path.
205:      *
206:      * @param array $options
207:      * @throws SolrWarning when required options don't exist
208:      */
209:     public static function validateClientOptions(array $options) {
210:         $valid = true;
211:         $valid &= array_key_exists('hostname', $options);
212:         $valid &= array_key_exists('port', $options);
213:         $valid &= array_key_exists('path', $options);
214: 
215:         // login & password are optional!
216:         // $valid &= array_key_exists('login', $options);
217:         // $valid &= array_key_exists('password', $options);
218: 
219:         if (!$valid) {
220:             throw new SolrWarning(Solr::i18n('WARNING_INVALID_CLIENT_OPTIONS'));
221:         }
222:     }
223: 
224:     /**
225:      *
226:      * @param Exception $e
227:      */
228:     public static function logException(Exception $e) {
229:         $cfg = cRegistry::getConfig();
230: 
231:         $log = new cLog(cLogWriter::factory('file', array(
232:             'destination' => $cfg['path']['contenido_logs'] . 'errorlog.txt'
233:         )), cLog::ERR);
234: 
235:         $log->err($e->getMessage());
236:         $log->err($e->getTraceAsString());
237:     }
238: 
239:     /**
240:      * TODO build method to display erro & info box and just call it from here
241:      *
242:      * @param Exception $e
243:      * @param bool $showTrace if trace should be displayed too
244:      */
245:     public static function displayException(Exception $e, $showTrace = false) {
246:         header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error', true, 500);
247: 
248:         if (true) {
249:             // error box
250:             $class = "ui-state-error";
251:             $icon = "ui-icon-alert";
252:         } else {
253:             // info box
254:             $class = "ui-state-highlight";
255:             $icon = "ui-icon-info";
256:         }
257: 
258:         echo '<div class="ui-widget">';
259:         echo '<div class="' . $class . ' ui-corner-all">';
260:         echo '<p>';
261:         echo '<span class="ui-icon ' . $icon . '"></span>';
262:         // echo '<strong>Exception</strong>';
263:         echo $e->getMessage();
264:         if (true === $showTrace) {
265:             echo '<pre style="overflow: auto">';
266:             echo htmlentities($e->getTraceAsString(), ENT_COMPAT | ENT_HTML401, 'UTF-8');
267:             echo '</pre>';
268:         }
269:         echo '</p>';
270:         echo '</div>';
271:         echo '</div>';
272:     }
273: 
274:     /**
275:      * Creates a notification widget in order to display an exception message in
276:      * backend.
277:      *
278:      * @param Exception $e
279:      * @return string
280:      */
281:     public static function notifyException(Exception $e) {
282:         $cGuiNotification = new cGuiNotification();
283:         $level = cGuiNotification::LEVEL_ERROR;
284:         $message = $e->getMessage();
285: 
286:         return $cGuiNotification->returnNotification($level, $message);
287:     }
288: }
289: 
290: // define template names
291: $cfg['templates']['solr_right_bottom'] = $cfg['plugins'][Solr::getName()] . 'templates/template.right_bottom.tpl';
292: 
293: // include necessary sources, setup autoloader for plugin
294: $pluginClassPath = 'contenido/plugins/' . Solr::getName() . '/';
295: cAutoload::addClassmapConfig(array(
296:     'SolrIndexer' => $pluginClassPath . 'classes/class.solr_indexer.php',
297:     'SolrSearcherAbstract' => $pluginClassPath . 'classes/class.solr_searcher_abstract.php',
298:     'SolrSearcherSimple' => $pluginClassPath . 'classes/class.solr_searcher_simple.php',
299:     'SolrSearchModule' => $pluginClassPath . 'classes/class.solr_search_module.php',
300:     'SolrRightBottomPage' => $pluginClassPath . 'classes/class.solr.gui.php',
301:     'SolrException' => $pluginClassPath . 'classes/class.solr_exception.php',
302:     'SolrWarning' => $pluginClassPath . 'classes/class.solr_warning.php'
303: ));
304: unset($pluginClassPath);
305: 
306: // == add chain functions
307: // reindex article after article properties are updated
308: cRegistry::getCecRegistry()->addChainFunction('Contenido.Action.con_saveart.AfterCall', 'SolrIndexer::handleStoringOfArticle');
309: // reindex article after any content entry is updated
310: cRegistry::getCecRegistry()->addChainFunction('Contenido.Content.AfterStore', 'SolrIndexer::handleStoringOfContentEntry');
311: 
CMS CONTENIDO 4.9.11 API documentation generated by ApiGen 2.8.0