Пример #1
0
 public function runAction()
 {
     Bites::callHooks('beforeAjaxAction', $this->module, $this->action, FALSE, $this->var_array, array());
     include_once sprintf('%s/bites/%s/actions.ajax.class.php', ROOT, $this->module);
     $namespace = $this->module . '\\Ajax\\Actions';
     $action = new $namespace();
     return $action->{$this->action}($this->var_array);
 }
 public function loadAction()
 {
     if (array_key_exists(0, $this->url_array) && !empty($this->url_array[0])) {
         //Check for hyphenated string and convert to camel case
         $action = preg_replace('/-(.?)/e', "strtoupper('\$1')", array_shift($this->url_array));
         if (method_exists($this->action_class, $action)) {
             $this->action = $action;
             $this->var_array = $this->url_array;
         } else {
             header('Location: /oops-cannot-find-page');
             exit;
         }
     }
     // Check for any hooks that may need to run before the action is executed
     Bites::callHooks('beforeAction', $this->module, $this->action, false, $this->var_array);
 }
    public function render()
    {
        if (!isset($_SESSION['token'])) {
            $_SESSION['token'] = array();
        }
        $_SESSION['token'][] = Useful::randomString(20);
        $fields = '';
        $error = $this->valid ? '' : '<p class="error">Sorry there were some errors in the form, problem fields have been highlighted</p>';
        $format = (object) $this->formats[$this->format];
        foreach ($this->fields as $key => $value) {
            $format = (object) $this->formats[$this->format];
            $temp = isset($this->data[$key]) ? $value->returnField($key, $this->data[$key]) : $value->returnField($key);
            if ($temp['html']['close_field'] !== false) {
                $format->close_field = $temp['html']['close_field'];
            }
            if ($temp['html']['close_html'] !== false) {
                $format->close_html = $temp['html']['close_html'];
            }
            if ($temp['html']['open_field'] !== false) {
                $format->open_field = $temp['html']['open_field'];
            }
            if ($temp['html']['open_html'] !== false) {
                $format->open_html = $temp['html']['open_html'];
            }
            $fields .= $format->open_field;
            if ($temp['label']) {
                $fields .= $format->open_html . $temp['label'] . $format->close_html;
            }
            foreach ($temp['messages'] as $message) {
                if ($this->message_type == 'inline') {
                    $fields .= $format->open_html . '<p class="error">This field ' . $message . '</p>' . $format->close_html;
                } else {
                    $this->setMessages($message, $key);
                }
                if (!$this->multiple_errors) {
                    break;
                }
            }
            $fields .= $format->open_html . $temp['field'] . $format->close_html . $format->close_field;
        }
        if (!empty($this->messages)) {
            $this->buildMessages();
        } else {
            $this->messages = false;
        }
        $token = $_SESSION['token'][count($_SESSION['token']) - 1];
        self::$instance = false;
        $form = <<<FORM
    {$error}
    {$this->messages}
    <form class="form" action="{$this->action}" method="{$this->method}" enctype="multipart/form-data">
      {$format->open_form}
        {$format->open_form_body}
          <input type="hidden" value="{$token}" name="token" />
          {$fields}
        {$format->close_form_body}
        {$format->open_submit}
          <input type="submit" name="submit" value="{$this->submit_value}" />
        {$format->close_submit}
      {$format->close_form}
    </form>
FORM;
        if ($this->render_class_instance) {
            Bites::callHooks('onForm', $this->render_class_instance->module, $this->render_class_instance->view, false, $form);
        }
        return $form;
    }
Пример #4
0
 /**
  * @desc This function extracts all variables created by the function and includes the view
  */
 public function renderView()
 {
     Bites::callHooks('onVariables', $this->module, $this->view, false, $this->variables);
     extract($this->variables);
     ob_start();
     require_once sprintf('%s/bites/%s/views/%s.%s.php', ROOT, $this->module, APP, $this->view);
     $contents = ob_get_contents();
     ob_end_clean();
     Bites::callHooks('onView', $this->module, $this->view, false, $contents, array_merge(array('view name' => $this->view), $this->variables));
     echo $contents;
 }
 public function managePlugins($var_array = array())
 {
     \Bites::checkBites();
     $this->awake_bites = \R::getAll("select * from bites where status = 1");
     $this->asleep_bites = \R::getAll("select * from bites where status != 1");
 }