Overview

Packages

  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Datatype
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationMain
    • NavigationTop
  • 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
  • PifaExternalOptionsDatasourceInterface
  • PifaField
  • PifaFieldCollection
  • PifaForm
  • PifaFormCollection
  • PifaLeftBottomPage
  • PifaRightBottomFormDataPage
  • PifaRightBottomFormFieldsPage
  • PifaRightBottomFormPage
  • SolrRightBottomPage

Exceptions

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