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