function __construct()
 {
     /**
      * authentication
      **/
     $auth = new WaxAuthDb(array("encrypt" => false, "db_table" => $this->auth_database_table, "session_key" => "wildfire_user_cookie"));
     $this->current_user = $auth->get_user();
     if ($this->current_user->usergroup == 30) {
         $this->is_admin = true;
     }
     /**
      * module setup
      **/
     $this->before_filter("all", "check_authorised", array("login"));
     $this->configure_modules();
     $this->all_modules = CMSApplication::get_modules(true);
     if (!array_key_exists($this->module_name, CMSApplication::get_modules())) {
         Session::add_message('This component is not registered with the application.');
         $this->redirect_to('/admin/home/index');
     }
     /**
      * model instanciation
      **/
     $this->cm_conf = CmsConfiguration::get("general");
     if ($this->model_class) {
         $this->model = new $this->model_class($this->cm_conf['campaign_monitor_ClientID']);
         $this->model_name = WXInflections::underscore($this->model_class);
     }
     $this->sub_links["create"] = "Create New " . $this->display_name;
     $this->sub_links["view_subscriber"] = "View Subscribers";
     $this->sub_links["view_segments"] = "View Segments";
     if (!($this->this_page = WaxUrl::get("page"))) {
         $this->this_page = 1;
     }
 }
 /**
  * MAIN FUNCTION - CALL IN YOUR controller_global
  * This chappy uses the url to find the section & content thats appropriate by calling a bunch of others
  *
  * If the url your requesting sets an action (ie the first part of the url after the controller) and that
  * action is a function within the controller then this will return false!
  */
 protected function cms()
 {
     //check if this is paginated
     if ($page = Request::get('page')) {
         $this->this_page = $page;
     }
     //add preview bar to output
     if (Request::get("preview")) {
         WaxTemplate::add_response_filter("layout", "cms-preview-bar", array("model" => "CMSApplicationController", "method" => "add_preview_bar"));
     }
     //method exists check
     if ($this->is_public_method($this, WXInflections::underscore($this->action))) {
         return false;
     }
     if (!$this->use_format) {
         $this->use_format = "html";
     }
     //get the content!
     $this->find_contents_by_path();
     //set the view
     $this->pick_view();
     //set the action
     if ($this->cms_content) {
         $this->action = "cms_content";
         $this->build_crumb();
     }
     //incremeant the page views counter
     if ($this->is_page()) {
         $this->cms_content->add_pageview();
     }
     //you've found a page, but no section (this happens for pages within the home section as technically there is no 'home' in the url stack)
     if ($this->is_page() && $this->cms_content->id && !$this->cms_section) {
         $this->cms_section = $this->cms_content->section;
     }
 }
Beispiel #3
0
 public function __construct($persist = false)
 {
     if ($persist) {
         $this->persist = true;
     }
     $this->form_name = "wx_form_" . WXInflections::underscore(get_class($this));
     $this->table = WXInflections::underscore(get_class($this));
     if ($vals = Session::get($this->form_name)) {
         $this->row = $vals;
     }
 }
Beispiel #4
0
 public function verify($username, $password)
 {
     $object = WXInflections::camelize($this->db_table, true);
     $user = new $object();
     $method = "find_by_" . $this->user_field . "_and_" . $this->password_field;
     if ($this->encrypt) {
         $password = $this->encrypt($password);
     }
     $result = $user->{$method}($username, $password);
     if ($result) {
         $this->user_object = $result;
         $this->user_id = $result->id;
         return true;
     }
     return false;
 }
Beispiel #5
0
 public function get_results($limit = false)
 {
     $setups = array();
     foreach (self::$search_array as $search) {
         if (is_array($search['field'])) {
             try {
                 WXActiveRecord::getDefaultPDO()->query("ALTER TABLE " . $search['table'] . " ADD FULLTEXT " . $search['field'] . " (" . implode(",", $search['field']) . ");");
             } catch (Exception $e) {
             }
         } else {
             try {
                 WXActiveRecord::getDefaultPDO()->query("ALTER TABLE " . $search['table'] . " ADD FULLTEXT " . $search['field'] . " (" . $search['field'] . ");");
             } catch (Exception $e) {
             }
         }
         if (is_array($search['field'])) {
             $query = "SELECT *, MATCH(";
             $query .= implode(",", $search['field']);
             $query .= ") AGAINST('" . $this->search_phrase . "') AS score FROM " . $search['table'];
             $query .= " WHERE MATCH(" . implode(",", $search['field']) . ") AGAINST('" . $this->search_phrase . "')";
             if ($search['order'] != "") {
                 $query .= "ORDER BY " . $search['order'];
             }
         } else {
             $query = "SELECT *, MATCH(" . $search['field'] . ") AGAINST('" . $this->search_phrase . "') AS score FROM " . $search['table'];
             $query .= " WHERE MATCH(" . $search['field'] . ") AGAINST('" . $this->search_phrase . "')";
             if ($search['order'] != "") {
                 $query .= "ORDER BY " . $search['order'];
             }
             if ($limit) {
                 $query .= " LIMIT {$limit}";
             }
         }
         $model = WXInflections::camelize($search['table'], true);
         $table = new $model();
         if (is_array($results[$search['key']])) {
             $results[$search['key']] = array_merge($results[$search['key']], $table->find_by_sql($query));
         } else {
             $results[$search['key']] = $table->find_by_sql($query);
         }
     }
     return $results;
 }
Beispiel #6
0
 public function new_migration($name, $table = null)
 {
     if (is_array($name)) {
         $name = $name[0];
     }
     $migrate = new WXMigrate();
     $migrate->increase_version_latest();
     $version = $migrate->get_version_latest();
     $class = WXInflections::camelize($name, true);
     $this->final_output .= $this->start_php_file($class, "WXMigrate");
     if ($table) {
         $this->final_output .= $this->add_function("up", sprintf('    \\$this->create_table(\\"%s\\");', $table) . "\n");
         $this->final_output .= $this->add_function("down", sprintf('    \\$this->drop_table(\\"%s\\");', $table) . "\n");
     } else {
         $this->final_output .= $this->add_function("up");
         $this->final_output .= $this->add_function("down");
     }
     $file = str_pad($version, 3, "0", STR_PAD_LEFT) . "_" . WXInflections::underscore($class);
     $res = $this->write_to_file(APP_DIR . "db/migrate/" . $file . ".php");
     if (!$res) {
         $this->add_perm_error("app/db/migrate/" . $file . ".php");
         return false;
     }
     $this->add_stdout("Created migration file at app/db/migrate/" . $file . ".php");
 }
Beispiel #7
0
 public function get_templates($action)
 {
     $view = WXInflections::underscore(get_class($this)) . "/" . $action;
     $html = VIEW_DIR . $view . ".html";
     $txt = VIEW_DIR . $view . ".txt";
     if (is_readable($html && is_readable($txt))) {
         $this->is_html(true);
         $this->body = WXControllerBase::view_to_string($view, $this);
         $this->alt_body = WXControllerBase::view_to_string($view, $this, "txt");
     } elseif (is_readable($html)) {
         $this->is_html(true);
         $this->body = WXControllerBase::view_to_string($view, $this);
     } elseif (!is_readable($html) && is_readable($txt)) {
         $this->body = WXControllerBase::view_to_string($view, $this, "txt");
     }
 }
Beispiel #8
0
 public function has_many_methods($operation, $column, $value = null, $order = "0")
 {
     if (is_array($value)) {
         if (isset($value[1])) {
             $order = $value[1];
         }
         $value = $value[0];
     }
     $current = $this->row[$this->primary_key];
     $rel = $this->has_many_throughs[$column][0];
     $join = $this->has_many_throughs[$column][1];
     switch ($operation) {
         case "findin":
             if (is_array($order)) {
                 $params = $order;
             }
             $params['distinct'] = "{$this->table}.*";
             $params['table'] = "`{$join}`, `{$rel}`";
             if ($params['conditions']) {
                 $params['conditions'] .= " AND {$join}.{$rel}_id = '{$value}' AND {$join}.{$this->table}_id = {$this->table}.id";
             } else {
                 $params['conditions'] = "{$join}.{$rel}_id = '{$value}' AND {$join}.{$this->table}_id = {$this->table}.id";
             }
             $result = $this->find_all($params);
             return $result;
         case "delete":
             return $this->pdo->query("DELETE FROM {$join} WHERE {$this->table}_id ={$current} and {$rel}_id = {$value}");
             break;
         case "add":
             $this->pdo->query("DELETE FROM {$join} WHERE {$this->table}_id ={$current} AND {$rel}_id = {$value}");
             return $this->pdo->query("INSERT INTO {$join} ({$this->table}_id, {$rel}_id, `order`) VALUES({$current}, {$value}, {$order})");
             break;
         case "clear":
             return $this->pdo->query("DELETE FROM {$join} WHERE {$this->table}_id ={$current}");
             break;
         case "get":
             $rel_class = WXInflections::camelize($rel, true);
             $table = new $rel_class();
             if ($current) {
                 return $table->find_by_sql("SELECT * FROM {$rel} RIGHT JOIN {$join} ON {$join}.{$rel}_id = {$rel}.id \n\t\t\t\t    WHERE {$join}.{$this->table}_id = {$current} ORDER BY `order` ASC");
             } else {
                 return false;
             }
         case "order":
             return $this->pdo->query("UPDATE {$join} SET `order`={$order} WHERE {$this->table}_id = {$current} AND {$value} {$rel}_id = {$value}");
     }
 }
Beispiel #9
0
 public function generate_url()
 {
     if (!$this->title || $this->status == 4 || $this->status == 5 || $this->status == 6) {
         return false;
     }
     //create the url from the title
     $this->url = WXInflections::to_url($this->title);
     //check to make sure the url does not clash with a section url (this would cause the content to be found as a section)
     $this->avoid_section_url_clash();
     //make sure the url is unique
     $this->url = $this->avoid_url_clash();
 }
Beispiel #10
0
 public function dynamic_finders($func, $args)
 {
     $func = WXInflections::underscore($func);
     $finder = explode("by", $func);
     $what = explode("and", $finder[1]);
     foreach ($what as $key => $val) {
         $what[$key] = rtrim(ltrim($val, "_"), "_");
     }
     if ($args) {
         if (count($what) == 2) {
             $this->filter(array($what[0] => $args[0], $what[1], $args[1]));
         } else {
             $this->filter(array($what[0] => $args[0]));
         }
         if (is_array($args[1])) {
             $params = $args[1];
         } elseif (is_array($args[2])) {
             $params = $args[2];
         }
         if ($finder[0] == "find_all_") {
             return $this->find_all($params);
         } else {
             return $this->find($params);
         }
     }
 }
Beispiel #11
0
 public function before_save()
 {
     $this->url = WXInflections::to_url($this->subject);
     $this->date_created = date("Y-m-d H:i:s");
 }
Beispiel #12
0
 /**
  * set the url up
  */
 public function before_save()
 {
     $this->url = WXInflections::to_url($this->name);
 }
Beispiel #13
0
 public function test_slashcamelize($slash_word, $upper_first = false)
 {
     $input = "camel/case/word";
     $this->assertEqual(WXInflections::slashcamelize($input, true), "CamelCaseWord");
 }
Beispiel #14
0
 public function verify($username, $password)
 {
     $object = WXInflections::camelize($this->db_table, true);
     $user = new $object();
     if ($this->encrypt) {
         $password = $this->encrypt($password);
     }
     $result = $user->filter(array($this->user_field => $username, $this->password_field => $password))->first();
     if ($result->primval) {
         $this->user_object = $result;
         $this->user_id = $result->primval;
         return true;
     }
     return false;
 }
Beispiel #15
0
 protected function get_class_from_file($file, $strip = true)
 {
     if ($strip) {
         $file = substr($file, 3);
     }
     return WXInflections::camelize(str_replace(".php", "", $file), true);
 }
Beispiel #16
0
 public function error_messages_for($object)
 {
     if ($object instanceof WaxForm) {
         if ($object->bound_to_model) {
             if ($object->bound_to_model->errors) {
                 $html = "<ul class='user_errors'>";
             }
             foreach ($object->bound_to_model->errors as $err => $mess) {
                 $html .= "<li>" . $mess[0];
             }
         } else {
             foreach ($object->elements as $el) {
                 foreach ($el->errors as $er) {
                     $html .= sprintf($er->error_template, $er);
                 }
             }
         }
         $html .= "</ul>";
         return $html;
     }
     if (strpos($object, "_")) {
         $object = camelize($object, 1);
     }
     $class = new $object();
     $errors = $class->get_errors();
     foreach ($errors as $error) {
         $html .= $this->content_tag("li", WXInflections::humanize($error['field']) . " " . $error['message'], array("class" => "user_error"));
     }
     if (count($errors) > 0) {
         return $this->content_tag("ul", $html, array("class" => "user_errors"));
     }
     return false;
 }
Beispiel #17
0
 public function before_save()
 {
     parent::before_save();
     $this->url = WXInflections::to_url($this->title);
 }
Beispiel #18
0
 /** 
  * Construct method, initialises authentication, default model and menu items
  **/
 function __construct()
 {
     /**
      * authentication
      **/
     $auth = new WaxAuthDb(array("encrypt" => false, "db_table" => $this->auth_database_table, "session_key" => "wildfire_user_cookie"));
     $this->current_user = $auth->get_user();
     if ($this->current_user->usergroup == 30) {
         $this->is_admin = true;
     }
     /**
      * module setup
      **/
     $this->before_filter("all", "check_authorised", array("login"));
     $this->configure_modules();
     $this->all_modules = CMSApplication::get_modules(true, $this->current_user->usergroup);
     if (!array_key_exists($this->module_name, CMSApplication::get_modules())) {
         Session::add_message('This component is not registered with the application.');
         $this->redirect_to('/admin/home/index');
     }
     /**
      * model instanciation
      **/
     if ($this->model_class) {
         $this->model = new $this->model_class();
         $this->model_name = WXInflections::underscore($this->model_class);
         if (!$this->scaffold_columns && is_array($this->model->column_info())) {
             $this->scaffold_columns = array_keys($this->model->column_info());
         }
     }
     $this->sub_links["create"] = "Create New " . $this->display_name;
     if (!($this->this_page = WaxUrl::get("page"))) {
         $this->this_page = 1;
     }
 }