helper() public static method

Returns a helper object
public static helper ( $helper ) : object
return object
Esempio n. 1
0
File: get.php Progetto: Borvik/Munla
 /**
  * Gets an instance of each of the helpers for the specified type.
  * 
  * @param string $type The type of helpers to get.
  * @param string|array $skip (repeating) When a string can repeat, else if it's an array must be the last parameter.  The list of helpers to skip.
  * 
  * @return array An array containing all the helpers for the specified type.
  */
 public static function cache_helpers($type)
 {
     $skip = func_get_args();
     array_shift($skip);
     if (count($skip) == 1 && is_array($skip[0])) {
         $skip = $skip[0];
     }
     $ret = array();
     if (isset(config::$defaultHelpers) && is::existset(config::$defaultHelpers, $type)) {
         foreach (config::$defaultHelpers[$type] as $varName => $helperName) {
             if (in_array($helperName, $skip)) {
                 continue;
             }
             $key = is_string($varName) ? $varName : $helperName;
             $ret[$key] = get::helper($helperName);
         }
     }
     return $ret;
 }
Esempio n. 2
0
$html = get::helper('html');
$ver = explode('.', phpversion());
get::$isPhp523orNewer = $ver[0] >= 5 && ($ver[1] > 2 || $ver[1] == 2 && $ver[2] >= 3);
$form = new formHelper();
$mo = new moaController();
if (isset($_GET['export']) && isset($mo->mongo['listRows'])) {
    $rows = array();
    foreach ($mo->mongo['listRows'] as $row) {
        $rows[] = serialize($row);
    }
    $filename = get::htmlentities($_GET['db']);
    if (isset($_GET['collection'])) {
        $filename .= '~' . get::htmlentities($_GET['collection']);
    }
    $filename .= '.json';
    get::helper('json')->echoJson($rows, $filename);
    exit(0);
}
/**
 * moaDB front-end view-element
 */
//Change to local path or url
$headerArgs = ['title' => 'MoaDB', 'css' => ['//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css', './resources/css/base.css', '//netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.min.css', 'http://fonts.googleapis.com/css?family=Exo:900'], 'js' => ['//netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js', './resources/js/main.js', './resources/js/classyWiggle.js']];
//Load Google jQuery from URL.
echo $html->jsLoad(array('jquery', 'jqueryui'));
echo $html->header($headerArgs);
$baseUrl = $_SERVER['SCRIPT_NAME'];
$db = isset($_GET['db']) ? $_GET['db'] : (isset($_POST['db']) ? $_POST['db'] : 'admin');
//admin is in every Mongo DB
$dbUrl = urlencode($db);
if (isset($_GET['collection'])) {
Esempio n. 3
0
 /**
  * Gets the form to process, or given the form to process - processes it.
  * 
  * @param string|null $form
  *   The form identifier of the form to process.
  * 
  * @return string|bool|null 
  *   When $form is null, returns either null or a string form identifier.
  *   When a form identifier is passed, returns a boolean indicating the success or failure of the form processing.
  */
 public static function process($form = null)
 {
     if (isset(self::$processed)) {
         log::warning('Invalid call to formHelper::process() - the form has already been processed.');
         return false;
     }
     if (!isset($form)) {
         if (is::existset(munla::$session, 'forms')) {
             foreach (munla::$session['forms'] as $csrfName => $csrfForms) {
                 foreach ($csrfForms as $formid => $f) {
                     if (!is::existset($f, 'callback') || !is_callable($f['callback'])) {
                         continue;
                     }
                     $_FORM = array();
                     switch (strtolower($f['method'])) {
                         case 'post':
                             $_FORM =& $_POST;
                             break;
                         case 'get':
                             $_FORM =& $_GET;
                             break;
                     }
                     if (!is::existset($_FORM, 'mnl_formid')) {
                         unset($_FORM);
                         continue;
                     }
                     if (substr($_FORM['mnl_formid'], 0, strlen($csrfName) + 1) == $csrfName . '-' && substr($_FORM['mnl_formid'], strlen($csrfName) + 1) == $formid) {
                         unset($_FORM);
                         return sprintf('%s::%s', $csrfName, $formid);
                     }
                     unset($_FORM);
                 }
             }
         }
         $mnl_formaction = self::validateAction(is::existset($_POST, 'mnl_formaction') ? $_POST['mnl_formaction'] : (is::existset($_GET, 'mnl_formaction') ? $_GET['mnl_formaction'] : null));
         if ($mnl_formaction) {
             return 'simpleForm::' . $mnl_formaction;
         }
         return $form;
     }
     if (!is_string($form) || strpos($form, '::') === false) {
         log::error(sprintf('Invalid form identifier "%s"', $form));
         return false;
     }
     list($csrfName, $formid) = explode('::', $form, 2);
     if ($csrfName == 'simpleForm' && is_callable($formid)) {
         //$formid(); //trigger the callback - we don't know the values or form definition so no parameters
         $_FORM = array();
         if (is::existset($_POST, 'mnl_formaction')) {
             $_FORM =& $_POST;
         }
         if (is::existset($_GET, 'mnl_formaction')) {
             $_FORM =& $_GET;
         }
         self::fixArrays();
         unset($_FORM['mnl_formaction']);
         //normalize the file listing into a better array if any files were uploaded
         self::fixFileArray($_FORM);
         self::$processed = array('errors' => array(), 'fielderrors' => array(), 'msg' => null);
         self::$processed['form']['formid'] = $formid;
         $p = get::helper('form');
         $processed = call_user_func($formid, $p, $_FORM);
         if ($processed === false) {
             self::$processed['errors'][] = 'Failed to process the form.';
         } elseif ($processed !== true) {
             if (is_array($processed)) {
                 foreach ($processed as $err) {
                     $success = false;
                     switch (substr($err, 0, 1)) {
                         case '+':
                             $err = substr($err, 1);
                             $success = true;
                             break;
                         case '-':
                             $err = substr($err, 1);
                             break;
                     }
                     self::$processed[$success ? 'msg' : 'errors'][] = $err;
                 }
             } else {
                 $success = false;
                 switch (substr($processed, 0, 1)) {
                     case '+':
                         $processed = substr($processed, 1);
                         $success = true;
                         break;
                     case '-':
                         $processed = substr($processed, 1);
                         break;
                 }
                 self::$processed[$success ? 'msg' : 'errors'][] = $processed;
             }
         }
         return count(self::$processed['errors']) < 1;
     }
     if (!is::existset(munla::$session, 'forms') || !is::existset(munla::$session['forms'], $csrfName) || !is::existset(munla::$session['forms'][$csrfName], $formid)) {
         log::error(sprintf('Specified form definition "%s" was not found', $form));
         return false;
     }
     $form = munla::$session['forms'][$csrfName][$formid];
     if (!is::existset($form, 'callback') || !is_callable($form['callback'])) {
         log::error(sprintf('Form does not have a valid callback.'));
         return false;
     }
     $callback = explode('::', $form['callback']);
     $_FORM = array();
     switch (strtolower($form['method'])) {
         case 'post':
             $_FORM =& $_POST;
             break;
         case 'get':
             $_FORM =& $_GET;
             break;
     }
     self::fixArrays();
     self::$processed = array('errors' => array(), 'fielderrors' => array(), 'msg' => null);
     self::$processed['form'] = $form;
     if (is::existset($_FORM, 'mnl_formid')) {
         unset($_FORM['mnl_formid']);
     }
     //normalize the file listing into a better array if any files were uploaded
     self::fixFileArray($_FORM);
     //fix up special field types
     foreach ($form['fields'] as $field) {
         $type = get_class($field);
         if ($type == 'fe_image') {
             $name = $field->getName();
             if (!is::existset($_FORM, $name) && is::existset($_FORM, $name . '_x')) {
                 $_FORM[$name] = true;
             }
         } elseif ($type == 'fe_session') {
             $_FORM[$field->getName()] = $field->get_value();
         }
     }
     $fields = new formFieldList($form['fields']);
     $validating = array($callback[0], $callback[1] . '_validating');
     $validate = array($callback[0], $callback[1] . '_validate');
     if (is_callable($validating)) {
         $validating($this, $fields, $_FORM);
     }
     $valid = is_callable($validate) ? $validate($_FORM) : self::validate($fields, $_FORM, strtolower($form['method']) == 'post' && !$form['nocsrf']);
     if ($valid) {
         $processed = $callback($_FORM);
         if (isset($processed)) {
             if ($processed === false) {
                 self::$processed['errors'][] = 'Failed to process the form.';
             } elseif ($processed !== true) {
                 if (is_array($processed)) {
                     foreach ($processed as $err) {
                         $success = false;
                         switch (substr($err, 0, 1)) {
                             case '+':
                                 $err = substr($err, 1);
                                 $success = true;
                                 break;
                             case '-':
                                 $err = substr($err, 1);
                                 break;
                         }
                         self::$processed[$success ? 'msg' : 'errors'][] = $err;
                     }
                 } else {
                     $success = false;
                     switch (substr($processed, 0, 1)) {
                         case '+':
                             $processed = substr($processed, 1);
                             $success = true;
                             break;
                         case '-':
                             $processed = substr($processed, 1);
                             break;
                     }
                     self::$processed[$success ? 'msg' : 'errors'][] = $processed;
                 }
             }
         }
     } elseif (count(self::$processed['errors']) < 1) {
         self::$processed['errors'][] = 'Failed form validation.';
     }
     return count(self::$processed['errors']) < 1;
 }
 /**
  * Used for text, textarea, hidden, password, file, button, image and submit
  *
  * Valid args are any properties valid within an HTML input as well as label
  *
  * @param array $args
  * @return string
  */
 public function input(array $args)
 {
     $args['type'] = isset($args['type']) ? $args['type'] : 'text';
     switch ($args['type']) {
         case 'select':
             return $this->select($args);
             break;
         case 'checkbox':
             return $this->checkboxes($args);
             break;
         case 'radio':
             return $this->radios($args);
             break;
     }
     if ($args['type'] == 'textarea' && isset($args['maxlength'])) {
         if (!isset($args['id']) && isset($args['name'])) {
             $args['id'] = $args['name'];
         }
         if (isset($args['id'])) {
             $maxlength = $args['maxlength'];
         }
         unset($args['maxlength']);
     }
     if ($args['type'] == 'submit' && !isset($args['class'])) {
         $args['class'] = $args['type'];
     }
     $takeFocus = isset($args['focus']) && $args['focus'] && $args['type'] != 'hidden';
     if ($takeFocus && !isset($args['id'])) {
         if (isset($args['name'])) {
             $args['id'] = $args['name'];
         } else {
             $takeFocus = false;
             if (DEBUG_MODE) {
                 $errorMsg = 'Either name or id is required to use the focus option on a form input';
                 trigger_error($errorMsg, E_USER_NOTICE);
             }
         }
     }
     $properties = $this->_getProperties($args, array('type', 'maxlength'));
     if ($args['type'] == 'image') {
         $properties['src'] = $args['src'];
         $properties['alt'] = isset($args['alt']) ? $args['alt'] : '';
         $optionalProperties = array('height', 'width');
         foreach ($optionalProperties as $optionalProperty) {
             if (isset($args[$optionalProperty])) {
                 $properties[$optionalProperty] = $args[$optionalProperty];
             }
         }
     }
     if ($args['type'] != 'textarea') {
         $return[] = '<input ' . htmlHelper::formatProperties($properties) . ' />';
     } else {
         unset($properties['type']);
         if (isset($properties['value'])) {
             $value = $properties['value'];
             unset($properties['value']);
         }
         if (isset($args['preview']) && $args['preview'] && !isset($properties['id'])) {
             $properties['id'] = 'textarea_' . rand(100, 999);
         }
         $properties['rows'] = isset($args['rows']) ? $args['rows'] : 13;
         $properties['cols'] = isset($args['cols']) ? $args['cols'] : 55;
         $return[] = '<textarea ' . htmlHelper::formatProperties($properties);
         if (isset($maxlength)) {
             $return[] = ' onkeyup="document.getElementById(\'' . $properties['id'] . 'errorwrapper\').innerHTML = (this.value.length > ' . $maxlength . ' ? \'Form content exceeds maximum length of ' . $maxlength . ' characters\' : \'Length: \' + this.value.length + \' (maximum: ' . $maxlength . ' characters)\')"';
         }
         $return[] = '>';
         if (isset($value)) {
             $return[] = get::htmlentities($value, null, null, true);
             //double-encode allowed
         }
         $return[] = '</textarea>';
         if (isset($maxlength) && (!isset($args['validatedInput']) || !$args['validatedInput'])) {
             $return[] = $this->getErrorMessageContainer($properties['id']);
         }
     }
     if (!isset($args['addBreak'])) {
         $args['addBreak'] = true;
     }
     if ($takeFocus) {
         $html = get::helper('html');
         $return[] = $html->jsInline($html->jsTools(true) . 'dom("' . $args['id'] . '").focus();');
     }
     if (isset($args['preview']) && $args['preview']) {
         $js = 'document.writeln(\'<div class="htmlpreviewlabel">' . '<label for="livepreview_' . $properties['id'] . '">Preview:</label></div>' . '<div id="livepreview_' . $properties['id'] . '" class="htmlpreview"></div>\');' . PHP_EOL . 'if (dom("livepreview_' . $properties['id'] . '")) {' . PHP_EOL . '    var updateLivePreview_' . $properties['id'] . ' = ' . 'function() {dom("livepreview_' . $properties['id'] . '").innerHTML = ' . 'dom("' . $properties['id'] . '").value};' . PHP_EOL . '    dom("' . $properties['id'] . '").onkeyup = updateLivePreview_' . $properties['id'] . ';' . ' updateLivePreview_' . $properties['id'] . '();' . PHP_EOL . '}';
         if (!isset($html)) {
             $html = get::helper('html');
         }
         $return[] = $html->jsInline($html->jsTools(true) . $js);
     }
     return $this->_getLabel($args, implode($return));
 }
Esempio n. 5
0
 /**
  * Gets whether this field had an error during form processing.
  * 
  * @return bool True if the field has an error, false otherwise.
  */
 public function hasError()
 {
     $id = $this->getId();
     return get::helper('form')->hasFieldError($id);
 }