Overview

Packages

  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Datatype
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationMain
    • NavigationTop
  • 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
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo
  1: <?php
  2: 
  3: /**
  4:  *
  5:  * @package Plugin
  6:  * @subpackage SearchSolr
  7:  * @version SVN Revision $Rev:$
  8:  * @author marcus.gnass
  9:  * @copyright four for business AG
 10:  * @link http://www.4fb.de
 11:  */
 12: 
 13: // assert CONTENIDO framework
 14: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
 15: 
 16: /**
 17:  * Helper class for this plugin.
 18:  *
 19:  * @author marcus.gnass
 20:  */
 21: class Solr {
 22: 
 23:     /**
 24:      * name of this plugin
 25:      *
 26:      * @var string
 27:      */
 28:     private static $_name = 'search_solr';
 29: 
 30:     /**
 31:      *
 32:      * @param mixed $whatever
 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:         // create name of logfile
 55:         $cfg = cRegistry::getConfig();
 56:         $filename = $cfg['path']['contenido_logs'] . 'errorlog.txt';
 57: 
 58:         // extend message with optional prefix
 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:         // log message
 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:      * Return path to this plugins folder.
 83:      *
 84:      * @return string
 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:      * @param string $key
 98:      * @return string
 99:      */
100:     public static function i18n($key) {
101:         $trans = i18n($key, self::$_name);
102:         return $trans;
103:     }
104: 
105:     /**
106:      * Returns array of options used to create a SolClient object.
107:      *
108:      * The option values are read from system or client settings. Required
109:      * settings are solr/hostname, solr/port, solr/path, solr/login,
110:      * solr/password.
111:      *
112:      * @return array
113:      */
114:     public static function getClientOptions() {
115:         $options = array();
116: 
117:         // Boolean value indicating whether or not to connect in secure mode.
118:         $options['secure'] = (bool) getSystemProperty('solr', 'secure');
119: 
120:         // Required. The hostname for the Solr server.
121:         $options['hostname'] = getSystemProperty('solr', 'hostname');
122: 
123:         // Required. The port number.
124:         $options['port'] = getSystemProperty('solr', 'port');
125: 
126:         // Required. The path to solr.
127:         $options['path'] = getSystemProperty('solr', 'path');
128: 
129:         // The name of the response writer e.g. xml, phpnative.
130:         $options['wt'] = getSystemProperty('solr', 'wt');
131: 
132:         // Required. The username used for HTTP Authentication, if any.
133:         $options['login'] = getSystemProperty('solr', 'login');
134: 
135:         // Required. The HTTP Authentication password.
136:         $options['password'] = getSystemProperty('solr', 'password');
137: 
138:         // The hostname for the proxy server, if any.
139:         $options['proxy_host'] = getSystemProperty('solr', 'proxy_host');
140: 
141:         // The proxy port.
142:         $options['proxy_port'] = getSystemProperty('solr', 'proxy_port');
143: 
144:         // The proxy username.
145:         $options['proxy_login'] = getSystemProperty('solr', 'proxy_login');
146: 
147:         // The proxy password.
148:         $options['proxy_password'] = getSystemProperty('solr', 'proxy_password');
149: 
150:         // This is maximum time in seconds allowed for the http data transfer
151:         // operation. Default is 30 seconds.
152:         $options['timeout'] = getSystemProperty('solr', 'timeout');
153: 
154:         // File name to a PEM-formatted file containing the private key +
155:         // private certificate (concatenated in that order).
156:         // Please note the if the ssl_cert file only contains the private
157:         // certificate, you have to specify a separate ssl_key file.
158:         $options['ssl_cert'] = getSystemProperty('solr', 'ssl_cert');
159: 
160:         // File name to a PEM-formatted private key file only.
161:         $options['ssl_key'] = getSystemProperty('solr', 'ssl_key');
162: 
163:         // Password for private key.
164:         // The ssl_keypassword option is required if the ssl_cert or ssl_key
165:         // options are set.
166:         $options['ssl_keypassword'] = getSystemProperty('solr', 'ssl_keypassword');
167: 
168:         // Name of file holding one or more CA certificates to verify peer with.
169:         $options['ssl_cainfo'] = getSystemProperty('solr', 'ssl_cainfo');
170: 
171:         // Name of directory holding multiple CA certificates to verify peer
172:         // with.
173:         $options['ssl_capath'] = getSystemProperty('solr', 'ssl_capath');
174: 
175:         // remove unset options (TODO could be done via array_filter too)
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:      * @param array $options
188:      * @throws SolrWarning
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:      * @param Exception $e
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:      * TODO build method to display erro & info box and just call it from here
220:      *
221:      * @param Exception $e
222:      * @param bool $showTrace if trace should be displayed too
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:             // error box
229:             $class = "ui-state-error";
230:             $icon = "ui-icon-alert";
231:         } else {
232:             // info box
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:         // echo '<strong>Exception</strong>';
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:      * Creates a notification widget in order to display an exception message in
255:      * backend.
256:      *
257:      * @param Exception $e
258:      * @return string
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: // define template names
270: $cfg['templates']['solr_right_bottom'] = $cfg['plugins'][Solr::getName()] . 'templates/template.right_bottom.tpl';
271: 
272: // include necessary sources, setup autoloader for plugin
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: // == add chain functions
286: // reindex article after article properties are updated
287: cRegistry::getCecRegistry()->addChainFunction('Contenido.Action.con_saveart.AfterCall', 'SolrIndexer::handleStoringOfArticle');
288: // reindex article after any content entry is updated
289: cRegistry::getCecRegistry()->addChainFunction('Contenido.Content.AfterStore', 'SolrIndexer::handleStoringOfContentEntry');
290: 
CMS CONTENIDO 4.9.0 API documentation generated by ApiGen 2.8.0