Ejemplo n.º 1
0
 /**
  * build the form from the array created in the frontend, so an html string
  *
  * @param echo 	bool 	Should be return or echo the built content
  *
  * @author Paul Whitehead
  * @return string
  */
 public function build($echo = true)
 {
     //confirm we have anything to work with
     if (!count($this->form_gather)) {
         throw new MeagrException('build called on empty form');
     }
     //create our form string
     $this->structureFormOpen();
     //check for our nonce
     if (isset($this->form_attributes['_nonce']) and !empty($this->form_attributes['_nonce'])) {
         $this->form_build[] = Nonce::input($this->form_attributes['_nonce']);
     }
     //get the errors for this form if there are any
     $errors = Input::session($this->form_attributes['id'] . '.errors');
     //get the errors for this form if there are any
     $values = Input::session($this->form_attributes['id'] . '.values');
     //walk the form elements array and create our inputs
     array_walk($this->form_gather, function ($input, $key) use($errors, $values) {
         //check for errors for this input
         if (isset($errors[$input['id']])) {
             //assign the errors to the input before build
             $input['errors'] = $errors[$input['id']];
             //delete the session var after use
             Arr::delete($_SESSION[ID][$this->form_attributes['id']]['errors'], $input['id']);
         }
         //check for value for this input
         if (isset($values[$input['id']]) and !empty($values[$input['id']])) {
             //assign the errors to the input before build
             $input['value'] = $values[$input['id']];
             //delete the session var after use
             Arr::delete($_SESSION[ID][$this->form_attributes['id']]['values'], $input['id']);
         }
         //check for html first
         if (isset($input['html'])) {
             //add our decoded html string and continue
             $this->form_build[] = htmlspecialchars_decode($input['html']);
             return;
         }
         //merge our input values with our system defaults
         $input = self::parseArgs($input, $this->input_defaults);
         //create our class input method name, will be like inputText() or inputTextarea()
         $method_name = 'input' . ucwords($input['type']);
         if (!is_callable(array($this, $method_name))) {
             throw new MeagrException('No input method found for requested type "' . $input['type'] . '" ');
         }
         //assign our clas wide input variable
         $this->input = $input;
         //run the function
         $this->{$method_name}();
     });
     //close the form
     $this->structureFormClose();
     //echo / return
     if ($echo) {
         //use \n for source readability
         echo implode("\n", $this->form_build);
     } else {
         return $this->form_build;
     }
 }
Ejemplo n.º 2
0
 /**
  * internal function to translate the tags from the config route map adding additional items
  *
  * @return void
  */
 function routeMap()
 {
     $map_segments = array();
     //check if we have anything to work with
     if (empty($this->uri_segments)) {
         return false;
     }
     //define our segments
     $map_segments['{modules}'] = 'modules';
     $map_segments['{controllers}'] = 'controllers';
     $map_segments['{domain}'] = SITE_DOMAIN;
     $map_segments['{class}'] = $this->uri_segments[0];
     $map_segments['{module}'] = $this->uri_segments[0];
     $map_segments['{subclass}'] = $this->uri_segments[0] . '_' . $this->uri_segments[1];
     $map_segments['{method}'] = $this->uri_segments[1];
     $map_segments['{submethod}'] = $this->uri_segments[2];
     //check for a subdomain
     $url = parse_url('http://' . \Meagr\Input::server('http_host'));
     $url['host'] = explode('.', $url['host']);
     //if the first host segment is not www
     if ($url['host'][0] !== 'www' and !stripos(SITE_URL, $url['host'][0])) {
         //set the sites subdomain
         $map_segments['{subdomain}'] = $url['host'][0];
         //define for other site wide usage
         define('SITE_SUBDOMAIN', $url['host'][0]);
         //ammend our other map segments
         $map_segments['{modules}'] .= '/' . $map_segments['{subdomain}'];
     }
     //are we at the root level (home page)
     if ($this->uri_segments[0] == '/' and !defined('SITE_SUBDOMAIN')) {
         $this->is_root = true;
         $this->uri_segments[0] = '';
     }
     //clear the segments we have already used
     unset($this->uri_segments[1], $this->uri_segments[0]);
     //check if we have additional arguments
     if (!empty($this->uri_segments)) {
         $map_segments['{args}'] = implode('/', $this->uri_segments);
         //keep them for passing to the func call later
         $this->arguments = $this->uri_segments;
     }
     //combine our array with the existing route map
     $this->route_map = $this->route_map + $map_segments;
     return;
 }