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
  • Smarty
    • Cacher
    • Compiler
    • Config
    • Debug
    • PluginsBlock
    • PluginsFilter
    • PluginsFunction
    • PluginsInternal
    • PluginsModifier
    • PluginsModifierCompiler
    • PluginsShared
    • Security
    • Template
    • TemplateResources
  • Swift
    • ByteStream
    • CharacterStream
    • Encoder
    • Events
    • KeyCache
    • Mailer
    • Mime
    • Plugins
    • Transport

Classes

  • Swift_FailoverTransport
  • Swift_LoadBalancedTransport
  • Swift_MailTransport
  • Swift_Plugins_Loggers_ArrayLogger
  • Swift_Plugins_Loggers_EchoLogger
  • Swift_SendmailTransport
  • Swift_SmtpTransport
  • Swift_Transport_AbstractSmtpTransport
  • Swift_Transport_Esmtp_Auth_CramMd5Authenticator
  • Swift_Transport_Esmtp_Auth_LoginAuthenticator
  • Swift_Transport_Esmtp_Auth_PlainAuthenticator
  • Swift_Transport_Esmtp_AuthHandler
  • Swift_Transport_EsmtpTransport
  • Swift_Transport_FailoverTransport
  • Swift_Transport_LoadBalancedTransport
  • Swift_Transport_MailTransport
  • Swift_Transport_SendmailTransport
  • Swift_Transport_SimpleMailInvoker
  • Swift_Transport_StreamBuffer

Interfaces

  • Swift_Plugins_Logger
  • Swift_Plugins_Pop_Pop3Exception
  • Swift_Transport
  • Swift_Transport_Esmtp_Authenticator
  • Swift_Transport_EsmtpHandler
  • Swift_Transport_IoBuffer
  • Swift_Transport_MailInvoker
  • Swift_Transport_SmtpAgent
  • Swift_TransportException
  • Overview
  • Package
  • Function
  • Todo
  • Download
  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.
109:      * Required settings are solr/hostname, solr/port, solr/path.
110:      *
111:      * @return array
112:      */
113:     public static function getClientOptions($idclient, $idlang) {
114: 
115:         //$queryOption = 'getSystemProperty';
116:         $queryOption = 'getEffectiveSetting';
117: 
118:         $options = array();
119: 
120:         // Boolean value indicating whether or not to connect in secure mode.
121:         $options['secure'] = (bool) $queryOption('solr', 'secure');
122: 
123:         // Required. The hostname for the Solr server.
124:         $options['hostname'] = $queryOption('solr', 'hostname');
125: 
126:         // Required. The port number.
127:         $options['port'] = $queryOption('solr', 'port');
128: 
129:         // Required. The path to solr.
130:         $options['path'] = $queryOption('solr', 'path');
131: 
132:         // load path from clientLanguage, client or system
133:         $clientLanguage = new cApiClientLanguage();
134:         $clientLanguage->loadByMany(array(
135:             'idclient' => $idclient,
136:             'idlang' => $idlang
137:         ));
138:         $value = $clientLanguage->isLoaded() ? $clientLanguage->getProperty($type, $name) : false;
139:         if (false === $value) {
140:             $client = new cApiClient($idclient);
141:             $value = $client->isLoaded() ? $client->getProperty($type, $name) : false;
142:         }
143:         if (false === $value) {
144:             $value = getSystemProperty($type, $name);
145:         }
146: 
147:         // The name of the response writer e.g. xml, phpnative.
148:         $options['wt'] = $queryOption('solr', 'wt');
149: 
150:         // Required. The username used for HTTP Authentication, if any.
151:         $options['login'] = $queryOption('solr', 'login');
152: 
153:         // Required. The HTTP Authentication password.
154:         $options['password'] = $queryOption('solr', 'password');
155: 
156:         // The hostname for the proxy server, if any.
157:         $options['proxy_host'] = $queryOption('solr', 'proxy_host');
158: 
159:         // The proxy port.
160:         $options['proxy_port'] = $queryOption('solr', 'proxy_port');
161: 
162:         // The proxy username.
163:         $options['proxy_login'] = $queryOption('solr', 'proxy_login');
164: 
165:         // The proxy password.
166:         $options['proxy_password'] = $queryOption('solr', 'proxy_password');
167: 
168:         // This is maximum time in seconds allowed for the http data transfer
169:         // operation. Default is 30 seconds.
170:         $options['timeout'] = $queryOption('solr', 'timeout');
171: 
172:         // File name to a PEM-formatted file containing the private key +
173:         // private certificate (concatenated in that order).
174:         // Please note the if the ssl_cert file only contains the private
175:         // certificate, you have to specify a separate ssl_key file.
176:         $options['ssl_cert'] = $queryOption('solr', 'ssl_cert');
177: 
178:         // File name to a PEM-formatted private key file only.
179:         $options['ssl_key'] = $queryOption('solr', 'ssl_key');
180: 
181:         // Password for private key.
182:         // The ssl_keypassword option is required if the ssl_cert or ssl_key
183:         // options are set.
184:         $options['ssl_keypassword'] = $queryOption('solr', 'ssl_keypassword');
185: 
186:         // Name of file holding one or more CA certificates to verify peer with.
187:         $options['ssl_cainfo'] = $queryOption('solr', 'ssl_cainfo');
188: 
189:         // Name of directory holding multiple CA certificates to verify peer
190:         // with.
191:         $options['ssl_capath'] = $queryOption('solr', 'ssl_capath');
192: 
193:         // remove unset options (TODO could be done via array_filter too)
194:         foreach ($options as $key => $value) {
195:             if (0 == strlen(trim($value))) {
196:                 unset($options[$key]);
197:             }
198:         }
199: 
200:         return $options;
201:     }
202: 
203:     /**
204:      * Check if required options exist.
205:      * Required settings are solr/hostname, solr/port, solr/path.
206:      *
207:      * @param array $options
208:      * @throws SolrWarning when required options don't exist
209:      */
210:     public static function validateClientOptions(array $options) {
211:         $valid = true;
212:         $valid &= array_key_exists('hostname', $options);
213:         $valid &= array_key_exists('port', $options);
214:         $valid &= array_key_exists('path', $options);
215: 
216:         // login & password are optional!
217:         // $valid &= array_key_exists('login', $options);
218:         // $valid &= array_key_exists('password', $options);
219: 
220:         if (!$valid) {
221:             throw new SolrWarning(Solr::i18n('WARNING_INVALID_CLIENT_OPTIONS'));
222:         }
223:     }
224: 
225:     /**
226:      *
227:      * @param Exception $e
228:      */
229:     public static function logException(Exception $e) {
230:         $cfg = cRegistry::getConfig();
231: 
232:         $log = new cLog(cLogWriter::factory('file', array(
233:             'destination' => $cfg['path']['contenido_logs'] . 'errorlog.txt'
234:         )), cLog::ERR);
235: 
236:         $log->err($e->getMessage());
237:         $log->err($e->getTraceAsString());
238:     }
239: 
240:     /**
241:      * TODO build method to display erro & info box and just call it from here
242:      *
243:      * @param Exception $e
244:      * @param bool $showTrace if trace should be displayed too
245:      */
246:     public static function displayException(Exception $e, $showTrace = false) {
247:         header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error', true, 500);
248: 
249:         if (true) {
250:             // error box
251:             $class = "ui-state-error";
252:             $icon = "ui-icon-alert";
253:         } else {
254:             // info box
255:             $class = "ui-state-highlight";
256:             $icon = "ui-icon-info";
257:         }
258: 
259:         echo '<div class="ui-widget">';
260:         echo '<div class="' . $class . ' ui-corner-all">';
261:         echo '<p>';
262:         echo '<span class="ui-icon ' . $icon . '"></span>';
263:         // echo '<strong>Exception</strong>';
264:         echo $e->getMessage();
265:         if (true === $showTrace) {
266:             echo '<pre style="overflow: auto">';
267:             echo htmlentities($e->getTraceAsString(), ENT_COMPAT | ENT_HTML401, 'UTF-8');
268:             echo '</pre>';
269:         }
270:         echo '</p>';
271:         echo '</div>';
272:         echo '</div>';
273:     }
274: 
275:     /**
276:      * Creates a notification widget in order to display an exception message in
277:      * backend.
278:      *
279:      * @param Exception $e
280:      * @return string
281:      */
282:     public static function notifyException(Exception $e) {
283:         $cGuiNotification = new cGuiNotification();
284:         $level = cGuiNotification::LEVEL_ERROR;
285:         $message = $e->getMessage();
286: 
287:         return $cGuiNotification->returnNotification($level, $message);
288:     }
289: }
290: 
291: // define template names
292: $cfg['templates']['solr_right_bottom'] = $cfg['plugins'][Solr::getName()] . 'templates/template.right_bottom.tpl';
293: 
294: // include necessary sources, setup autoloader for plugin
295: $pluginClassPath = 'contenido/plugins/' . Solr::getName() . '/';
296: cAutoload::addClassmapConfig(array(
297:     'SolrIndexer' => $pluginClassPath . 'classes/class.solr_indexer.php',
298:     'SolrSearcherAbstract' => $pluginClassPath . 'classes/class.solr_searcher_abstract.php',
299:     'SolrSearcherSimple' => $pluginClassPath . 'classes/class.solr_searcher_simple.php',
300:     'SolrSearchModule' => $pluginClassPath . 'classes/class.solr_search_module.php',
301:     'SolrRightBottomPage' => $pluginClassPath . 'classes/class.solr.gui.php',
302:     'SolrException' => $pluginClassPath . 'classes/class.solr_exception.php',
303:     'SolrWarning' => $pluginClassPath . 'classes/class.solr_warning.php'
304: ));
305: unset($pluginClassPath);
306: 
307: // == add chain functions
308: // reindex article after article properties are updated
309: cRegistry::getCecRegistry()->addChainFunction('Contenido.Action.con_saveart.AfterCall', 'SolrIndexer::handleStoringOfArticle');
310: // reindex article after any content entry is updated
311: cRegistry::getCecRegistry()->addChainFunction('Contenido.Content.AfterStore', 'SolrIndexer::handleStoringOfContentEntry');
312: 
CMS CONTENIDO 4.9.7 API documentation generated by ApiGen