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