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

  • cContentTypePifaForm
  • DefaultFormModule
  • DefaultFormProcessor
  • ExampleOptionsDatasource
  • MailedFormProcessor
  • Pifa
  • PifaAbstractFormModule
  • PifaAbstractFormProcessor
  • PifaAjaxHandler
  • PifaExporter
  • PifaExternalOptionsDatasourceInterface
  • PifaField
  • PifaFieldCollection
  • PifaForm
  • PifaFormCollection
  • PifaImporter
  • PifaLeftBottomPage
  • PifaRightBottomFormDataPage
  • PifaRightBottomFormExportPage
  • PifaRightBottomFormFieldsPage
  • PifaRightBottomFormImportPage
  • PifaRightBottomFormPage
  • SolrRightBottomPage

Exceptions

  • PifaDatabaseException
  • PifaException
  • PifaIllegalStateException
  • PifaMailException
  • PifaNotImplementedException
  • PifaNotYetStoredException
  • PifaValidationException
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo
  1: <?php
  2: 
  3: /**
  4:  *
  5:  * @package Plugin
  6:  * @subpackage FormAssistant
  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 Pifa {
 21: 
 22:     /**
 23:      * These constants describe if forms have a timestamp.
 24:      *
 25:      * @var string
 26:      */
 27:     const TIMESTAMP_NEVER = 'never';
 28: 
 29:     const TIMESTAMP_BYFORM = 'byform';
 30: 
 31:     const TIMESTAMP_ALWAYS = 'always';
 32: 
 33:     /**
 34:      * name of this plugin
 35:      *
 36:      * @var string
 37:      */
 38:     private static $_name = 'form_assistant';
 39: 
 40:     /**
 41:      *
 42:      * @var int
 43:      */
 44:     private static $_timestampSetting = NULL;
 45: 
 46:     /**
 47:      */
 48:     public static function getName() {
 49:         return self::$_name;
 50:     }
 51: 
 52:     /**
 53:      * Return path to this plugins folder.
 54:      *
 55:      * @return string
 56:      */
 57:     public static function getPath() {
 58:         $cfg = cRegistry::getConfig();
 59: 
 60:         $path = cRegistry::getBackendPath() . $cfg['path']['plugins'];
 61:         $path .= self::$_name . '/';
 62: 
 63:         return $path;
 64:     }
 65: 
 66:     /**
 67:      * Return URL to this plugins folder.
 68:      *
 69:      * @return string
 70:      */
 71:     public static function getUrl() {
 72:         $cfg = cRegistry::getConfig();
 73: 
 74:         $path = cRegistry::getBackendUrl() . $cfg['path']['plugins'];
 75:         $path .= self::$_name . '/';
 76: 
 77:         return $path;
 78:     }
 79: 
 80:     /**
 81:      *
 82:      * @param string $key
 83:      * @return string
 84:      */
 85:     public static function i18n($key) {
 86:         $trans = i18n($key, self::$_name);
 87:         return $trans;
 88:     }
 89: 
 90:     /**
 91:      *
 92:      * @param string $level
 93:      * @param string $note
 94:      */
 95:     public static function getNote($level, $note) {
 96:         $note = self::i18n($note);
 97:         $notification = new cGuiNotification();
 98:         return $notification->returnNotification($level, $note);
 99:     }
100: 
101:     /**
102:      *
103:      * @param string $note
104:      */
105:     public static function getError($note) {
106:         return self::getNote(cGuiNotification::LEVEL_ERROR, $note);
107:     }
108: 
109:     /**
110:      *
111:      * @param Exception $e
112:      */
113:     public static function logException(Exception $e) {
114: 
115:         if (getSystemProperty('debug', 'debug_for_plugins') == 'true') {
116:             $cfg = cRegistry::getConfig();
117: 
118:             $log = new cLog(cLogWriter::factory('file', array(
119:                 'destination' => $cfg['path']['contenido_logs'] . 'errorlog.txt'
120:             )), cLog::ERR);
121: 
122:             $log->err($e->getMessage());
123:             $log->err($e->getTraceAsString());
124:         }
125:     }
126: 
127:     /**
128:      * TODO build method to display erro & info box and just call it from here
129:      *
130:      * @param Exception $e
131:      * @param bool $showTrace if trace should be displayed too
132:      */
133:     public static function displayException(Exception $e, $showTrace = false) {
134:         header($_SERVER['SERVER_PROTOCOL'] . ' 500 ' . self::i18n('INTERNAL_SERVER_ERROR'), true, 500);
135: 
136:         if (true) {
137:             // error box
138:             $class = "ui-state-error";
139:             $icon = "ui-icon-alert";
140:         } else {
141:             // info box
142:             $class = "ui-state-highlight";
143:             $icon = "ui-icon-info";
144:         }
145: 
146:         echo '<div class="ui-widget">';
147:         echo '<div class="' . $class . ' ui-corner-all">';
148:         echo '<p>';
149:         echo '<span class="ui-icon ' . $icon . '"></span>';
150:         echo $e->getMessage();
151:         if (true === $showTrace) {
152:             echo '<pre style="overflow: auto">';
153:             echo htmlentities($e->getTraceAsString(), ENT_COMPAT | ENT_HTML401, 'UTF-8');
154:             echo '</pre>';
155:         }
156:         echo '</p>';
157:         echo '</div>';
158:         echo '</div>';
159:     }
160: 
161:     /**
162:      * Creates a notification widget in order to display an exception message in
163:      * backend.
164:      *
165:      * @param Exception $e
166:      * @return string
167:      */
168:     public static function notifyException(Exception $e) {
169:         $cGuiNotification = new cGuiNotification();
170:         $level = cGuiNotification::LEVEL_ERROR;
171:         $message = $e->getMessage();
172: 
173:         return $cGuiNotification->returnNotification($level, $message);
174:     }
175: 
176:     /**
177:      * Returns array of extension classes that subclass the given $parentClass.
178:      *
179:      * @param string $parentClass
180:      * @throws PifaException
181:      * @return array
182:      */
183:     public static function getExtensionClasses($parentClass) {
184: 
185:         // ignore if extensions folder is missing
186:         if (false === ($handle = cDirHandler::read(self::getPath() . 'extensions/'))) {
187:             return array();
188:         }
189: 
190:         $extensionClasses = array();
191:         foreach ($handle as $file) {
192:             // skip files that don't match regex
193:             $matches = array();
194:             $matchCount = preg_match('/^class\.pifa\.([^\.]+)\.php$/', $file, $matches);
195: 
196:             // REGEX failure ... just call Mr. T!
197:             if (false === $matchCount) {
198:                 $msg = self::i18n('EXTENSION_REGEX_ERROR');
199:                 throw new PifaException($msg);
200:             }
201: 
202:             // some other file .. just skip it
203:             if (0 === $matchCount) {
204:                 continue;
205:             }
206: 
207:             // this is a proper PHP class
208:             $optionClass = self::toCamelCase($matches[1], true);
209: 
210:             include_once(self::getPath() . 'extensions/' . $file);
211: 
212:             $reflection = new ReflectionClass($optionClass);
213:             if (false === $reflection->isSubclassOf($parentClass)) {
214:                 continue;
215:             }
216: 
217:             $extensionClasses[] = array(
218:                 'value' => $optionClass,
219:                 'label' => $optionClass
220:             );
221:         }
222: 
223:         return $extensionClasses;
224:     }
225: 
226:     /**
227:      * Returns array of client templates that that adhere to the naming
228:      * convention cms_pifaform_FOOBAR.tpl where FOOBAR is any character but a
229:      * dot.
230:      *
231:      * @throws PifaException
232:      * @return array
233:      */
234:     public static function getTemplates($re = '/cms_pifaform_[^\.]+\.tpl/') {
235:         $clientConfig = cRegistry::getClientConfig(cRegistry::getClientId());
236: 
237:         // ignore if template folder is missing
238:         if (false === ($handle = cDirHandler::read($clientConfig['template']['path']))) {
239:             return array();
240:         }
241: 
242:         $templates = array();
243:         foreach ($handle as $file) {
244: 
245:             // skip folders
246:             if (true === is_dir($file)) {
247:                 continue;
248:             }
249: 
250:             // skip files that don't match regex
251:             $matches = array();
252:             $matchCount = preg_match($re, $file, $matches);
253: 
254:             // REGEX failure ... just call Mr. T!
255:             if (false === $matchCount) {
256:                 $msg = self::i18n('TEMPLATE_REGEX_ERROR');
257:                 throw new PifaException($msg);
258:             }
259: 
260:             // some other file .. just skip it
261:             if (0 === $matchCount) {
262:                 continue;
263:             }
264: 
265:             $templates[] = array(
266:                 'value' => $file,
267:                 'label' => $file
268:             );
269:         }
270: 
271:         return $templates;
272:     }
273: 
274:     // /**
275:     // */
276:     // public static function afterLoadPlugins() {
277: 
278:     // // return;
279:     // if (!isset($_GET['securimage'])) {
280:     // return;
281:     // }
282: 
283:     // $e = error_get_last();
284: 
285:     // $img = new Securimage(array(
286:     // 'image_height' => (int) getEffectiveSetting('pifa', 'captcha-image-height', 80),
287:     // 'image_width' => (int) getEffectiveSetting('pifa', 'captcha-image-width', 215),
288:     // 'perturbation' => (int) getEffectiveSetting('pifa', 'captcha-perturbation', 0),
289:     // 'num_lines' => (int) getEffectiveSetting('pifa', 'captcha-num-lines', 3),
290:     // 'session_name' => cRegistry::getClientId() . 'frontend'
291:     // ));
292: 
293:     // $img->show();
294:     // }
295: 
296:     /**
297:      * Translates a camel case string into a string with underscores
298:      * (e.g.
299:      * firstName -&gt; first_name)
300:      *
301:      * @see http://www.paulferrett.com/2009/php-camel-case-functions/
302:      * @param string $str String in camel case format
303:      * @return string $str Translated into underscore format
304:      */
305:     public static function fromCamelCase($str) {
306:         $str[0] = strtolower($str[0]);
307:         $func = create_function('$c', 'return "_" . strtolower($c[1]);');
308:         return preg_replace_callback('/([A-Z])/', $func, $str);
309:     }
310: 
311:     /**
312:      * Translates a string with underscores into camel case (e.g.
313:      * first_name -&gt; firstName)
314:      *
315:      * @see http://www.paulferrett.com/2009/php-camel-case-functions/
316:      * @param string $str String in underscore format
317:      * @param bool $capitalise_first_char If true, capitalise the first
318:      *        char in $str
319:      * @return string $str translated into camel caps
320:      */
321:     public static function toCamelCase($str, $capitalise_first_char = false) {
322:         if ($capitalise_first_char) {
323:             $str[0] = strtoupper($str[0]);
324:         }
325:         $func = create_function('$c', 'return strtoupper($c[1]);');
326:         return preg_replace_callback('/_([a-z])/', $func, $str);
327:     }
328: 
329:     /**
330:      * Translates a string with underscores into camel case (e.g.
331:      * first_name -&gt; firstName)
332:      *
333:      * @see http://www.paulferrett.com/2009/php-camel-case-functions/
334:      * @param string $str String in underscore format
335:      * @param bool $capitalise_first_char If true, capitalise the first
336:      *        char in $str
337:      * @return string $str translated into camel caps
338:      */
339:     public static function getTimestampSetting($force = false) {
340:         if (is_null(self::$_timestampSetting) || $force) {
341:             self::$_timestampSetting = getEffectiveSetting('pifa', 'timestamp', self::TIMESTAMP_ALWAYS);
342:             if (!in_array(self::$_timestampSetting, array(
343:                 self::TIMESTAMP_NEVER,
344:                 self::TIMESTAMP_BYFORM,
345:                 self::TIMESTAMP_ALWAYS
346:             ))) {
347:                 self::$_timestampSetting = self::TIMESTAMP_ALWAYS;
348:             }
349:         }
350:         return self::$_timestampSetting;
351:     }
352: 
353:     /**
354:      * Determine if page is called via HTTPS.
355:      *
356:      * @return boolean
357:      */
358:     public static function isHttps() {
359:         $isHttps = false;
360:         $isHttps |= 443 === $_SERVER['SERVER_PORT'];
361:         $isHttps |= array_key_exists('HTTP_X_SSL_CIPHER', $_SERVER);
362:         return $isHttps;
363:     }
364: }
365: 
366: // define plugin path
367: $cfg['plugins'][Pifa::getName()] = Pifa::getPath();
368: 
369: // define template names
370: // $cfg['templates']['form_left_bottom'] = $cfg['plugins']['form'] .
371: // 'templates/template.left_bottom.html';
372: $cfg['templates']['pifa_right_bottom_form'] = $cfg['plugins'][Pifa::getName()] . 'templates/template.right_bottom_form.tpl';
373: $cfg['templates']['pifa_right_bottom_fields'] = $cfg['plugins'][Pifa::getName()] . 'templates/template.right_bottom_fields.tpl';
374: $cfg['templates']['pifa_right_bottom_data'] = $cfg['plugins'][Pifa::getName()] . 'templates/template.right_bottom_data.tpl';
375: $cfg['templates']['pifa_right_bottom_export'] = $cfg['plugins'][Pifa::getName()] . 'templates/template.right_bottom_export.tpl';
376: $cfg['templates']['pifa_right_bottom_import'] = $cfg['plugins'][Pifa::getName()] . 'templates/template.right_bottom_import.tpl';
377: $cfg['templates']['pifa_ajax_field_form'] = $cfg['plugins'][Pifa::getName()] . 'templates/template.ajax_field_form.tpl';
378: $cfg['templates']['pifa_ajax_field_row'] = $cfg['plugins'][Pifa::getName()] . 'templates/template.ajax_field_row.tpl';
379: $cfg['templates']['pifa_ajax_option_row'] = $cfg['plugins'][Pifa::getName()] . 'templates/template.ajax_option_row.tpl';
380: 
381: // define table names
382: $cfg['tab']['pifa_form'] = $cfg['sql']['sqlprefix'] . '_pifa_form';
383: $cfg['tab']['pifa_field'] = $cfg['sql']['sqlprefix'] . '_pifa_field';
384: 
385: // define action translations
386: global $lngAct;
387: $lngAct['form']['pifa_show_form'] = Pifa::i18n('pifa_show_form');
388: $lngAct['form']['pifa_store_form'] = Pifa::i18n('pifa_store_form');
389: $lngAct['form']['pifa_delete_form'] = Pifa::i18n('pifa_delete_form');
390: $lngAct['form_fields']['pifa_show_fields'] = Pifa::i18n('pifa_show_fields');
391: $lngAct['form_data']['pifa_show_data'] = Pifa::i18n('pifa_show_data');
392: $lngAct['form_import']['pifa_import_form'] = Pifa::i18n('pifa_import_form');
393: $lngAct['form_ajax']['pifa_export_form'] = Pifa::i18n('pifa_export_form');
394: $lngAct['form_ajax']['pifa_get_field_form'] = Pifa::i18n('pifa_get_field_form');
395: $lngAct['form_ajax']['pifa_post_field_form'] = Pifa::i18n('pifa_post_field_form');
396: $lngAct['form_ajax']['pifa_reorder_fields'] = Pifa::i18n('pifa_reorder_fields');
397: $lngAct['form_ajax']['pifa_export_data'] = Pifa::i18n('pifa_export_data');
398: $lngAct['form_ajax']['pifa_get_file'] = Pifa::i18n('pifa_get_file');
399: $lngAct['form_ajax']['pifa_delete_field'] = Pifa::i18n('pifa_delete_field');
400: $lngAct['form_ajax']['pifa_get_option_row'] = Pifa::i18n('pifa_get_option_row');
401: 
402: // include necessary sources, setup autoloader for plugin
403: // @todo Use config variables for $pluginClassPath below!
404: $pluginClassPath = 'contenido/plugins/' . Pifa::getName() . '/';
405: cAutoload::addClassmapConfig(array(
406:     'cContentTypePifaForm' => $pluginClassPath . 'classes/class.content.type.pifa_form.php',
407:     'PifaExternalOptionsDatasourceInterface' => $pluginClassPath . 'classes/class.pifa.external_options_datasource_interface.php',
408:     'PifaExporter' => $pluginClassPath . 'classes/class.pifa.exporter.php',
409:     'PifaImporter' => $pluginClassPath . 'classes/class.pifa.importer.php',
410:     'PifaLeftBottomPage' => $pluginClassPath . 'classes/class.pifa.gui.php',
411:     'PifaRightBottomFormPage' => $pluginClassPath . 'classes/class.pifa.gui.php',
412:     'PifaRightBottomFormFieldsPage' => $pluginClassPath . 'classes/class.pifa.gui.php',
413:     'PifaRightBottomFormDataPage' => $pluginClassPath . 'classes/class.pifa.gui.php',
414:     'PifaRightBottomFormExportPage' => $pluginClassPath . 'classes/class.pifa.gui.php',
415:     'PifaRightBottomFormImportPage' => $pluginClassPath . 'classes/class.pifa.gui.php',
416:     'PifaFormCollection' => $pluginClassPath . 'classes/class.pifa.form.php',
417:     'PifaForm' => $pluginClassPath . 'classes/class.pifa.form.php',
418:     'PifaFieldCollection' => $pluginClassPath . 'classes/class.pifa.field.php',
419:     'PifaField' => $pluginClassPath . 'classes/class.pifa.field.php',
420:     'PifaAbstractFormModule' => $pluginClassPath . 'classes/class.pifa.abstract_form_module.php',
421:     'PifaAbstractFormProcessor' => $pluginClassPath . 'classes/class.pifa.abstract_form_processor.php',
422:     'PifaAjaxHandler' => $pluginClassPath . 'classes/class.pifa.ajax_handler.php',
423:     'PifaException' => $pluginClassPath . 'classes/class.pifa.exceptions.php',
424:     'PifaDatabaseException' => $pluginClassPath . 'classes/class.pifa.exceptions.php',
425:     'PifaNotImplementedException' => $pluginClassPath . 'classes/class.pifa.exceptions.php',
426:     'PifaIllegalStateException' => $pluginClassPath . 'classes/class.pifa.exceptions.php',
427:     // 'Securimage' => $pluginClassPath . 'securimage/securimage.php',
428:     'PifaNotYetStoredException' => $pluginClassPath . 'classes/class.pifa.exceptions.php',
429:     'PifaValidationException' => $pluginClassPath . 'classes/class.pifa.exceptions.php',
430:     'PifaMailException' => $pluginClassPath . 'classes/class.pifa.exceptions.php'
431: ));
432: unset($pluginClassPath);
433: 
434: // define chain functions
435: //cRegistry::getCecRegistry()->addChainFunction('Contenido.Frontend.AfterLoadPlugins', 'Pifa::afterLoadPlugins');
436: 
CMS CONTENIDO 4.9.11 API documentation generated by ApiGen 2.8.0