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
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
    • ScriptCookieDirective
  • mpAutoloaderClassMap
  • None
  • PHP
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • 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

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:      * Translates a camel case string into a string with underscores
276:      * (e.g.
277:      * firstName -&gt; first_name)
278:      *
279:      * @see http://www.paulferrett.com/2009/php-camel-case-functions/
280:      * @param string $str String in camel case format
281:      * @return string $str Translated into underscore format
282:      */
283:     public static function fromCamelCase($str) {
284:         $str[0] = cString::toLowerCase($str[0]);
285:         return preg_replace_callback('/([A-Z])/', function($c) {
286:             return '_' . cString::toLowerCase($c[1]);
287:         }, $str);
288:     }
289: 
290:     /**
291:      * Translates a string with underscores into camel case (e.g.
292:      * first_name -&gt; firstName)
293:      *
294:      * @see http://www.paulferrett.com/2009/php-camel-case-functions/
295:      * @param string $str String in underscore format
296:      * @param bool $capitalise_first_char If true, capitalise the first
297:      *        char in $str
298:      * @return string $str translated into camel caps
299:      */
300:     public static function toCamelCase($str, $capitalise_first_char = false) {
301:         if ($capitalise_first_char) {
302:             $str[0] = cString::toUpperCase($str[0]);
303:         }
304:         return preg_replace_callback('/_([a-z])/', function($c) {
305:             return cString::toUpperCase($c[1]);
306:         }, $str);
307:     }
308: 
309:     /**
310:      * Translates a string with underscores into camel case (e.g.
311:      * first_name -&gt; firstName)
312:      *
313:      * @see http://www.paulferrett.com/2009/php-camel-case-functions/
314:      * @param string $str String in underscore format
315:      * @param bool $capitalise_first_char If true, capitalise the first
316:      *        char in $str
317:      * @return string $str translated into camel caps
318:      */
319:     public static function getTimestampSetting($force = false) {
320:         if (is_null(self::$_timestampSetting) || $force) {
321:             self::$_timestampSetting = getEffectiveSetting('pifa', 'timestamp', self::TIMESTAMP_ALWAYS);
322:             if (!in_array(self::$_timestampSetting, array(
323:                 self::TIMESTAMP_NEVER,
324:                 self::TIMESTAMP_BYFORM,
325:                 self::TIMESTAMP_ALWAYS
326:             ))) {
327:                 self::$_timestampSetting = self::TIMESTAMP_ALWAYS;
328:             }
329:         }
330:         return self::$_timestampSetting;
331:     }
332: 
333:     /**
334:      * Determine if page is called via HTTPS.
335:      *
336:      * @return boolean
337:      */
338:     public static function isHttps() {
339:         $isHttps = false;
340:         $isHttps |= 443 === $_SERVER['SERVER_PORT'];
341:         $isHttps |= array_key_exists('HTTP_X_SSL_CIPHER', $_SERVER);
342:         return $isHttps;
343:     }
344: }
345: 
346: // define plugin path
347: $cfg['plugins'][Pifa::getName()] = Pifa::getPath();
348: 
349: // define template names
350: // $cfg['templates']['form_left_bottom'] = $cfg['plugins']['form'] .
351: // 'templates/template.left_bottom.html';
352: $cfg['templates']['pifa_right_bottom_form'] = $cfg['plugins'][Pifa::getName()] . 'templates/template.right_bottom_form.tpl';
353: $cfg['templates']['pifa_right_bottom_fields'] = $cfg['plugins'][Pifa::getName()] . 'templates/template.right_bottom_fields.tpl';
354: $cfg['templates']['pifa_right_bottom_data'] = $cfg['plugins'][Pifa::getName()] . 'templates/template.right_bottom_data.tpl';
355: $cfg['templates']['pifa_right_bottom_export'] = $cfg['plugins'][Pifa::getName()] . 'templates/template.right_bottom_export.tpl';
356: $cfg['templates']['pifa_right_bottom_import'] = $cfg['plugins'][Pifa::getName()] . 'templates/template.right_bottom_import.tpl';
357: $cfg['templates']['pifa_ajax_field_form'] = $cfg['plugins'][Pifa::getName()] . 'templates/template.ajax_field_form.tpl';
358: $cfg['templates']['pifa_ajax_field_row'] = $cfg['plugins'][Pifa::getName()] . 'templates/template.ajax_field_row.tpl';
359: $cfg['templates']['pifa_ajax_option_row'] = $cfg['plugins'][Pifa::getName()] . 'templates/template.ajax_option_row.tpl';
360: 
361: // define table names
362: $cfg['tab']['pifa_form'] = $cfg['sql']['sqlprefix'] . '_pifa_form';
363: $cfg['tab']['pifa_field'] = $cfg['sql']['sqlprefix'] . '_pifa_field';
364: 
365: // define action translations
366: global $lngAct;
367: $lngAct['form']['pifa_show_form'] = Pifa::i18n('pifa_show_form');
368: $lngAct['form']['pifa_store_form'] = Pifa::i18n('pifa_store_form');
369: $lngAct['form']['pifa_delete_form'] = Pifa::i18n('pifa_delete_form');
370: $lngAct['form_fields']['pifa_show_fields'] = Pifa::i18n('pifa_show_fields');
371: $lngAct['form_data']['pifa_show_data'] = Pifa::i18n('pifa_show_data');
372: $lngAct['form_import']['pifa_import_form'] = Pifa::i18n('pifa_import_form');
373: $lngAct['form_ajax']['pifa_export_form'] = Pifa::i18n('pifa_export_form');
374: $lngAct['form_ajax']['pifa_get_field_form'] = Pifa::i18n('pifa_get_field_form');
375: $lngAct['form_ajax']['pifa_post_field_form'] = Pifa::i18n('pifa_post_field_form');
376: $lngAct['form_ajax']['pifa_reorder_fields'] = Pifa::i18n('pifa_reorder_fields');
377: $lngAct['form_ajax']['pifa_export_data'] = Pifa::i18n('pifa_export_data');
378: $lngAct['form_ajax']['pifa_get_file'] = Pifa::i18n('pifa_get_file');
379: $lngAct['form_ajax']['pifa_delete_field'] = Pifa::i18n('pifa_delete_field');
380: $lngAct['form_ajax']['pifa_get_option_row'] = Pifa::i18n('pifa_get_option_row');
381: 
382: // include necessary sources, setup autoloader for plugin
383: // @todo Use config variables for $pluginClassPath below!
384: $pluginClassPath = 'contenido/plugins/' . Pifa::getName() . '/';
385: cAutoload::addClassmapConfig(array(
386:     'cContentTypePifaForm' => $pluginClassPath . 'classes/class.content.type.pifa_form.php',
387:     'PifaExternalOptionsDatasourceInterface' => $pluginClassPath . 'classes/class.pifa.external_options_datasource_interface.php',
388:     'PifaExporter' => $pluginClassPath . 'classes/class.pifa.exporter.php',
389:     'PifaImporter' => $pluginClassPath . 'classes/class.pifa.importer.php',
390:     'PifaLeftBottomPage' => $pluginClassPath . 'classes/class.pifa.gui.php',
391:     'PifaRightBottomFormPage' => $pluginClassPath . 'classes/class.pifa.gui.php',
392:     'PifaRightBottomFormFieldsPage' => $pluginClassPath . 'classes/class.pifa.gui.php',
393:     'PifaRightBottomFormDataPage' => $pluginClassPath . 'classes/class.pifa.gui.php',
394:     'PifaRightBottomFormExportPage' => $pluginClassPath . 'classes/class.pifa.gui.php',
395:     'PifaRightBottomFormImportPage' => $pluginClassPath . 'classes/class.pifa.gui.php',
396:     'PifaFormCollection' => $pluginClassPath . 'classes/class.pifa.form.php',
397:     'PifaForm' => $pluginClassPath . 'classes/class.pifa.form.php',
398:     'PifaFieldCollection' => $pluginClassPath . 'classes/class.pifa.field.php',
399:     'PifaField' => $pluginClassPath . 'classes/class.pifa.field.php',
400:     'PifaAbstractFormModule' => $pluginClassPath . 'classes/class.pifa.abstract_form_module.php',
401:     'PifaAbstractFormProcessor' => $pluginClassPath . 'classes/class.pifa.abstract_form_processor.php',
402:     'PifaAjaxHandler' => $pluginClassPath . 'classes/class.pifa.ajax_handler.php',
403:     'PifaException' => $pluginClassPath . 'classes/class.pifa.exceptions.php',
404:     'PifaDatabaseException' => $pluginClassPath . 'classes/class.pifa.exceptions.php',
405:     'PifaNotImplementedException' => $pluginClassPath . 'classes/class.pifa.exceptions.php',
406:     'PifaIllegalStateException' => $pluginClassPath . 'classes/class.pifa.exceptions.php',
407:     'PifaNotYetStoredException' => $pluginClassPath . 'classes/class.pifa.exceptions.php',
408:     'PifaValidationException' => $pluginClassPath . 'classes/class.pifa.exceptions.php',
409:     'PifaMailException' => $pluginClassPath . 'classes/class.pifa.exceptions.php'
410: ));
411: unset($pluginClassPath);
CMS CONTENIDO 4.10.0 API documentation generated by ApiGen 2.8.0