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 FormAssistant
  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:  * Creates a page to be displayed in the right bottom frame.
 18:  *
 19:  * secure
 20:  * hostname
 21:  * port
 22:  * path
 23:  * wt
 24:  * login
 25:  * password
 26:  * proxy_host
 27:  * proxy_port
 28:  * proxy_login
 29:  * proxy_password
 30:  * timeout
 31:  * ssl_cert
 32:  * ssl_key
 33:  * ssl_keypassword
 34:  * ssl_cainfo
 35:  * ssl_capath
 36:  *
 37:  * @author marcus.gnass
 38:  */
 39: class SolrRightBottomPage extends cGuiPage {
 40: 
 41:     /**
 42:      *
 43:      * @var array
 44:      */
 45:     private $_clientOptions;
 46: 
 47:     /**
 48:      * @global string $action to be performed
 49:      */
 50:     public function __construct() {
 51: 
 52:         global $action;
 53: 
 54:         parent::__construct('right_bottom', Solr::getName());
 55: 
 56:         $this->addStyle('smoothness/jquery-ui-1.8.20.custom.css');
 57:         $this->addStyle('right_bottom.css');
 58:         $this->addScript('right_bottom.js');
 59: 
 60:         $this->set('s', 'CONTENIDO', cRegistry::getBackendSessionId());
 61: 
 62:         $this->set('s', 'I18N_CLIENT_OPTIONS', Solr::i18n('CLIENT_OPTIONS'));
 63:         $this->set('s', 'I18N_OPTION', Solr::i18n('OPTION'));
 64:         $this->set('s', 'I18N_VALUE', Solr::i18n('VALUE'));
 65:         $this->set('s', 'I18N_DESCRIPTION', Solr::i18n('DESCRIPTION'));
 66:         $this->set('s', 'I18N_DESCR_HOSTNAME', Solr::i18n('DESCR_HOSTNAME'));
 67:         $this->set('s', 'I18N_DESCR_PORT', Solr::i18n('DESCR_PORT'));
 68:         $this->set('s', 'I18N_DESCR_PATH', Solr::i18n('DESCR_PATH'));
 69:         $this->set('s', 'I18N_DESCR_LOGIN', Solr::i18n('DESCR_LOGIN'));
 70:         $this->set('s', 'I18N_DESCR_PASSWORD', Solr::i18n('DESCR_PASSWORD'));
 71:         $this->set('s', 'I18N_DESCR_SECURE', Solr::i18n('DESCR_SECURE'));
 72:         $this->set('s', 'I18N_DESCR_TIMEOUT', Solr::i18n('DESCR_TIMEOUT'));
 73:         $this->set('s', 'I18N_DESCR_WT', Solr::i18n('DESCR_WT'));
 74:         $this->set('s', 'I18N_DESCR_PROXY_HOST', Solr::i18n('DESCR_PROXY_HOST'));
 75:         $this->set('s', 'I18N_DESCR_PROXY_PORT', Solr::i18n('DESCR_PROXY_PORT'));
 76:         $this->set('s', 'I18N_DESCR_PROXY_LOGIN', Solr::i18n('DESCR_PROXY_LOGIN'));
 77:         $this->set('s', 'I18N_DESCR_PROXY_PASSWORD', Solr::i18n('DESCR_PROXY_PASSWORD'));
 78:         $this->set('s', 'I18N_DESCR_SSL_CERT', Solr::i18n('DESCR_SSL_CERT'));
 79:         $this->set('s', 'I18N_DESCR_SSL_KEY', Solr::i18n('DESCR_SSL_KEY'));
 80:         $this->set('s', 'I18N_DESCR_SSL_KEYPASSWORD', Solr::i18n('DESCR_SSL_KEYPASSWORD'));
 81:         $this->set('s', 'I18N_DESCR_SSL_CAINFO', Solr::i18n('DESCR_SSL_CAINFO'));
 82:         $this->set('s', 'I18N_DESCR_SSL_CAPATH', Solr::i18n('DESCR_SSL_CAPATH'));
 83:         $this->set('s', 'I18N_DESCR_RELOAD', Solr::i18n('DESCR_RELOAD'));
 84:         $this->set('s', 'I18N_DESCR_REINDEX', Solr::i18n('DESCR_REINDEX'));
 85:         $this->set('s', 'I18N_DESCR_DELETE', Solr::i18n('DESCR_DELETE'));
 86: 
 87:         // get client options
 88:         $idclient = cRegistry::getClientId();
 89:         $idlang = cRegistry::getLanguageId();
 90:         $this->_clientOptions = Solr::getClientOptions($idclient, $idlang);
 91:         $this->set('s', 'HOSTNAME', $this->_clientOptions['hostname']);
 92:         $this->set('s', 'PORT', $this->_clientOptions['port']);
 93:         $this->set('s', 'PATH', $this->_clientOptions['path']);
 94:         $this->set('s', 'LOGIN', $this->_clientOptions['login']);
 95:         $this->set('s', 'PASSWORD', $this->_clientOptions['password']);
 96:         $this->set('s', 'SECURE', 'true' == $this->_clientOptions['secure'] ? 'checked="checked"' : '');
 97:         $this->set('s', 'TIMEOUT', $this->_clientOptions['timeout']);
 98:         $this->set('s', 'WT', $this->_clientOptions['wt']);
 99:         $this->set('s', 'PROXY_HOST', $this->_clientOptions['proxy_host']);
100:         $this->set('s', 'PROXY_PORT', $this->_clientOptions['proxy_port']);
101:         $this->set('s', 'PROXY_LOGIN', $this->_clientOptions['proxy_login']);
102:         $this->set('s', 'PROXY_PASSWORD', $this->_clientOptions['proxy_password']);
103:         $this->set('s', 'SSL_CERT', $this->_clientOptions['ssl_cert']);
104:         $this->set('s', 'SSL_KEY', $this->_clientOptions['ssl_key']);
105:         $this->set('s', 'SSL_KEYPASSWORD', $this->_clientOptions['ssl_keypassword']);
106:         $this->set('s', 'SSL_CAINFO', $this->_clientOptions['ssl_cainfo']);
107:         $this->set('s', 'SSL_CAPATH', $this->_clientOptions['ssl_capath']);
108: 
109:         // dispatch action
110:         try {
111:             $this->_dispatch($action);
112: 
113:             // actions will be disabled if any required client option is missing
114:             try {
115:                 Solr::validateClientOptions($this->_clientOptions);
116:                 $validClientOptions = true;
117:             } catch (SolrWarning $e) {
118:                 $validClientOptions = false;
119:             }
120:             $this->set('s', 'DISABLED_RELOAD', $validClientOptions ? '' : 'disabled="disabled"');
121:             $this->set('s', 'DISABLED_REINDEX', $validClientOptions ? '' : 'disabled="disabled"');
122:             $this->set('s', 'DISABLED_DELETE', $validClientOptions ? '' : 'disabled="disabled"');
123: 
124:         } catch (InvalidArgumentException $e) {
125:             $cGuiNotification = new cGuiNotification();
126:             $notification = $cGuiNotification->returnNotification(cGuiNotification::LEVEL_ERROR, $e->getMessage());
127:             $this->set('s', 'notification', $notification);
128:         }
129:     }
130: 
131:     /**
132:      * Dispatches the given action.
133:      *
134:      * @param string $action to be executed
135:      * @throws InvalidArgumentException if the given action is unknown
136:      */
137:     protected function _dispatch($action) {
138:         global $area;
139: 
140:         // check for permission
141:         $perm = cRegistry::getPerm();
142:         if (!$perm->have_perm_area_action($area, $action)) {
143:             throw new IllegalStateException('no permissions');
144:         }
145: 
146:         if (NULL === $action) {
147:             $this->set('s', 'notification', '');
148:             $this->set('s', 'content', '');
149:             return;
150:         }
151: 
152:         // dispatch action
153:         try {
154:             switch ($action) {
155:                 case 'store_client_options':
156:                     $this->set('s', 'notification', $this->_storeClientOptions());
157:                     break;
158:                 case 'reload':
159:                     $this->set('s', 'notification', $this->_reload());
160:                     break;
161:                 case 'reindex':
162:                     $this->set('s', 'notification', $this->_reindex());
163:                     break;
164:                 case 'delete':
165:                     $this->set('s', 'notification', $this->_delete());
166:                     break;
167:                 default:
168:                     throw new InvalidArgumentException('unknown action ' . $action);
169:             }
170:         } catch (Exception $e) {
171:             $notification = Solr::notifyException($e);
172:         }
173:     }
174: 
175:     /**
176:      *
177:      * @return string
178:      */
179:     private function _storeClientOptions() {
180:         $settings = 'secure,hostname,port,path,wt,login,password,timeout,';
181:         $settings .= 'proxy_host,proxy_port,proxy_login,proxy_password,';
182:         $settings .= 'ssl_cert,ssl_key,ssl_keypassword,ssl_cainfo,ssl_capath';
183:         foreach (explode(',', $settings) as $setting) {
184:             $value = $_POST[$setting];
185:             if (0 < strlen(trim($value))) {
186:                 setSystemProperty('solr', $setting, $value);
187:             } else {
188:                 // Solr system properties w/o values are not stored to prevent
189:                 // property pollution
190:                 deleteSystemProperty('solr', $setting);
191:             }
192:         }
193:         $cGuiNotification = new cGuiNotification();
194:         return $cGuiNotification->returnNotification(cGuiNotification::LEVEL_INFO, 'client options were stored');
195:     }
196: 
197:     /**
198:      * Call the relaod action.
199:      *
200:      * http://client-uat70.4fb.net:8080/solr/admin/cores?action=STATUS
201:      * http://client-uat70.4fb.net:8080/solr/admin/cores?action=RENAME&core=collection1&other=contenido
202:      * http://client-uat70.4fb.net:8080/solr/admin/cores?action=RELOAD&core=contenido
203:      * Cannot be done with Solr extension (or can it?).
204:      *
205:      * @return string
206:      */
207:     private function _reload() {
208: 
209:         // build URL
210:         // @see https://en.wikipedia.org/wiki/Basic_access_authentication
211:         $url = 'http://';
212:         $url .= $this->_clientOptions['login'] . ':' . $this->_clientOptions['password'] . '@';
213:         $url .= $this->_clientOptions['hostname'] . ':' . $this->_clientOptions['port'];
214:         $url .= '/solr/admin/cores?' . http_build_query(array(
215:                     'action' => 'RELOAD',
216:                     'core' => array_pop(explode('/', $this->_clientOptions['path']))
217:         ));
218: 
219:         // create curl resource
220:         $ch = curl_init();
221: 
222:         $data = false;
223:         if (false !== $ch) {
224: 
225:             $opt = array(
226:                 // set url
227:                 CURLOPT_URL => $url,
228:                 // TRUE to reset the HTTP request method to GET.
229:                 CURLOPT_HTTPGET => true,
230:                 // The contents of the "User-Agent: " header to be used
231:                 // in a HTTP request.
232:                 CURLOPT_USERAGENT => 'CONTENIDO Solr Plugin v1.0',
233:                 // The maximum number of milliseconds to allow cURL
234:                 // functions to execute.
235:                 CURLOPT_TIMEOUT_MS => 5000,
236:                 // The number of milliseconds to wait while trying to
237:                 // connect.
238:                 CURLOPT_CONNECTTIMEOUT_MS => 5000,
239:                 // return the transfer as a string
240:                 CURLOPT_RETURNTRANSFER => 1,
241:                 // TRUE to include the header in the output.
242:                 CURLOPT_HEADER => false
243:             );
244: 
245:             curl_setopt_array($ch, $opt);
246: 
247:             // $data contains the output string
248:             $data = curl_exec($ch);
249: 
250:             // get curl info
251:             $curlInfo = curl_getinfo($ch);
252: 
253:             // close curl resource to free up system resources
254:             curl_close($ch);
255: 
256:             if (200 !== (int) $curlInfo['http_code']) {
257:                 $msg = 'HTTP status code ' . $curlInfo['http_code'];
258:                 // may contain an error message
259:                 // $msg .= '\ndata: ' . $sData;
260:                 $msg .= "\n(complete cUrl-Info:";
261:                 foreach ($curlInfo as $key => $value) {
262:                     $msg .= "\n\t" . $key . ' => ' . $value;
263:                 }
264:                 $msg .= "\n)";
265: 
266:                 throw new cException($msg);
267:             }
268:         }
269: 
270:         if (false === $data) {
271:             throw new cException('server did not answer');
272:         }
273: 
274:         $cGuiNotification = new cGuiNotification();
275:         return $cGuiNotification->returnNotification(cGuiNotification::LEVEL_INFO, 'core was reloaded');
276:     }
277: 
278:     /**
279:      *
280:      * @return string
281:      */
282:     private function _reindex() {
283:         $cfg = cRegistry::getConfig();
284: 
285:         $idclient = cRegistry::getClientId();
286:         $idclient = cSecurity::toInteger($idclient);
287: 
288:         $idlang = cRegistry::getLanguageId();
289:         $idlang = cSecurity::toInteger($idlang);
290: 
291:         // statement is not correct if articles are related to more than one category.
292:         $db = cRegistry::getDb();
293:         $db->query("-- SolrRightBottomPage->_reindex()
294:             SELECT
295:                 art.idclient
296:                 , art_lang.idlang
297:                 , cat_art.idcat
298:                 , cat_lang.idcatlang
299:                 , art_lang.idart
300:                 , art_lang.idartlang
301:             FROM
302:                 `{$cfg['tab']['art_lang']}` AS art_lang
303:             INNER JOIN
304:                 `{$cfg['tab']['art']}` AS art
305:             ON
306:                 art_lang.idart = art.idart
307:             INNER JOIN
308:                 `{$cfg['tab']['cat_art']}` AS cat_art
309:             ON
310:                 art_lang.idart = cat_art.idart
311:             INNER JOIN
312:                 `{$cfg['tab']['cat_lang']}` AS cat_lang
313:             ON
314:                 cat_art.idcat = cat_lang.idcat
315:                 AND art_lang.idlang = cat_lang.idlang
316:             WHERE
317:                 art.idclient = $idclient
318:                 -- AND art_lang.idlang = $idlang
319:             ORDER BY
320:                 art_lang.idartlang
321:             ;");
322: 
323:         $articleIds = array();
324:         while ($db->nextRecord()) {
325:             array_push($articleIds, array(
326:                 'idclient' => $db->f('idclient'),
327:                 'idlang' => $db->f('idlang'),
328:                 'idcat' => $db->f('idcat'),
329:                 'idcatlang' => $db->f('idcatlang'),
330:                 'idart' => $db->f('idart'),
331:                 'idartlang' => $db->f('idartlang')
332:             ));
333:         }
334: 
335:         $indexer = new SolrIndexer($articleIds);
336:         $indexer->updateArticles();
337: 
338:         $cGuiNotification = new cGuiNotification();
339:         return $cGuiNotification->returnNotification(cGuiNotification::LEVEL_INFO, 'core was reindexed');
340:     }
341: 
342:     /**
343:      *
344:      * @return string
345:      */
346:     private function _delete() {
347: 
348:         $cfg = cRegistry::getConfig();
349: 
350:         // statement is not correct if articles are related to more than one category.
351:         $db = cRegistry::getDb();
352:         $db->query("-- SolrRightBottomPage->_delete()
353:             SELECT
354:                 art.idclient
355:                 , art_lang.idlang
356:                 , cat_art.idcat
357:                 , cat_lang.idcatlang
358:                 , art_lang.idart
359:                 , art_lang.idartlang
360:             FROM
361:                 `{$cfg['tab']['art_lang']}` AS art_lang
362:             INNER JOIN
363:                 `{$cfg['tab']['art']}` AS art
364:             ON
365:                 art_lang.idart = art.idart
366:             INNER JOIN
367:                 `{$cfg['tab']['cat_art']}` AS cat_art
368:             ON
369:                 art_lang.idart = cat_art.idart
370:             INNER JOIN
371:                 `{$cfg['tab']['cat_lang']}` AS cat_lang
372:             ON
373:                 cat_art.idcat = cat_lang.idcat
374:                 AND art_lang.idlang = cat_lang.idlang
375:             ORDER BY
376:                 art_lang.idartlang
377:             ;");
378: 
379:         $articleIds = array();
380:         while ($db->nextRecord()) {
381:             array_push($articleIds, array(
382:                 'idclient' => $db->f('idclient'),
383:                 'idlang' => $db->f('idlang'),
384:                 'idcat' => $db->f('idcat'),
385:                 'idcatlang' => $db->f('idcatlang'),
386:                 'idart' => $db->f('idart'),
387:                 'idartlang' => $db->f('idartlang')
388:             ));
389:         }
390: 
391:         $indexer = new SolrIndexer($articleIds);
392:         $indexer->deleteArticles();
393: 
394:         $cGuiNotification = new cGuiNotification();
395:         return $cGuiNotification->returnNotification(cGuiNotification::LEVEL_INFO, 'core was deleted');
396:     }
397: 
398: }
399: 
CMS CONTENIDO 4.9.7 API documentation generated by ApiGen