Exemple #1
0
 public function user_creation()
 {
     $dealer_class = get_class($this);
     $user = new WildfireUser();
     if ($this->client_id && !($found = $user->filter("username", $this->client_id)->first())) {
         $user_attrs = array('username' => $this->client_id, 'firstname' => $this->title, 'password' => $this->client_id . date("Y"));
         $this->wu = $user = $user->update_attributes($user_attrs);
         $allowed_modules = $dealer_class::$allowed_modules;
         foreach (CMSApplication::get_modules() as $name => $info) {
             //if the module isnt listed at all, then block access to it
             if (!$allowed_modules[$name]) {
                 $block = new WildfirePermissionBlacklist();
                 $block->update_attributes(array($user->table . "_id" => $user->primval, 'class' => $name, 'operation' => "index"));
             } else {
                 $class = "Admin" . Inflections::camelize($name, true) . "Controller";
                 $obj = new $class(false, false);
                 $operations = array_merge($obj->operation_actions, array('index'));
                 $mods = $allowed_modules[$name];
                 $section_class = $obj->model_class;
                 $section_model = new $section_class();
                 //find all possible tabs for the model
                 $tabs = array('details');
                 foreach ($section_model->columns as $col => $info) {
                     if ($info[1]['group']) {
                         $tabs[] = strtolower($info[1]['group']);
                     }
                 }
                 $tabs = array_unique($tabs);
                 //block operations or tabs
                 foreach ($operations as $op) {
                     //if its not set, block it
                     if (!isset($mods[$op])) {
                         $block = new WildfirePermissionBlacklist();
                         $block->update_attributes(array($user->table . "_id" => $user->primval, 'class' => $name, 'operation' => $op));
                     } else {
                         //if it is, block tabs that havent been listed
                         foreach ($tabs as $tab_i => $tab) {
                             if (in_array($tab, $mods[$op])) {
                                 unset($tabs[$tab_i]);
                             }
                         }
                     }
                 }
                 foreach ($tabs as $tab) {
                     $block = new WildfirePermissionBlacklist();
                     $block->update_attributes(array($user->table . "_id" => $user->primval, 'class' => $name, 'operation' => "tab-" . $tab));
                 }
             }
         }
         $block = new WildfirePermissionBlacklist();
         foreach ($this->pages as $page) {
             $block->update_attributes(array($user->table . "_id" => $user->primval, 'class' => CONTENT_MODEL, 'operation' => "tree", "value" => $page->primval));
         }
         WaxEvent::run($dealer_class . ".user_creation", $this);
     }
 }
Exemple #2
0
 /**
  * the setup function for this field is different, as this is a many to many relationship it takes into 
  * account both sides of the relationship, initialises the join table if its missing and preps the 
  * filter
  */
 public function setup()
 {
     $this->col_name = false;
     if (!$this->target_model) {
         $this->target_model = Inflections::camelize($this->field, true);
     }
     if ($this->model->primval) {
         $this->setup_join_model();
     }
 }
Exemple #3
0
 public function setup()
 {
     if (!$this->target_model) {
         $this->target_model = Inflections::camelize($this->field, true);
     }
     $link = new $this->target_model();
     // Overrides naming of field to model_id if col_name is not explicitly set
     if ($this->col_name == $this->field) {
         $this->col_name = Inflections::underscore($this->target_model) . "_" . $link->primary_key;
     }
 }
Exemple #4
0
 public function setup()
 {
     $this->col_name = false;
     $class_name = get_class($this->model);
     if (!$this->target_model) {
         $this->target_model = Inflections::camelize($this->field, true);
     }
     if (!$this->join_field) {
         $this->join_field = Inflections::underscore($class_name) . "_" . $this->model->primary_key;
     }
 }
 public function file_upload()
 {
     if ($url = $_POST["upload_from_url"]) {
         $str = "";
         foreach ($_POST as $k => $v) {
             $str .= "{$k}:{$v}\n";
         }
         WaxLog::log('error', 'running...' . $str);
         $path = $_POST['wildfire_file_folder'];
         $fs = new CmsFilesystem();
         $filename = basename($url);
         $ext = strtolower(array_pop(explode(".", $filename)));
         if ($_POST["wildfire_file_filename"]) {
             $filename = $_POST["wildfire_file_filename"] . "." . $ext;
         }
         $filename = $_POST["wildfire_file_filename"] = File::safe_file_save($fs->defaultFileStore . $path, $filename);
         $file = $fs->defaultFileStore . $path . "/" . $filename;
         $handle = fopen($file, 'x+');
         fwrite($handle, file_get_contents($url));
         fclose($handle);
         $fname = $fs->defaultFileStore . $path . "/" . $filename;
         chmod($fname, 0777);
         $dimensions = getimagesize($fname);
         if (AdminFilesController::$max_image_width && $dimensions[0] > AdminFilesController::$max_image_width) {
             $flag = File::resize_image($fname, $fname, AdminFilesController::$max_image_width, false, true);
             if (!$flag) {
                 WaxLog::log('error', '[resize] FAIL');
             }
         }
         $fs->databaseSync($fs->defaultFileStore . $path, $path);
         $file = new WildfireFile();
         $newfile = $file->filter(array("filename" => $filename, "rpath" => $path))->first();
         $newfile->description = $_POST["wildfire_file_description"];
         $newfile->save();
         //if these are set then attach the image to the doc!
         if (Request::post('content_id') && Request::post('model_string') && Request::post('join_field')) {
             $model_id = Request::post('content_id');
             $class = Inflections::camelize(Request::post('model_string'), true);
             $field = Request::post('join_field');
             $model = new $class($model_id);
             $model->{$field} = $newfile;
         }
         echo "Uploaded";
     } elseif ($_FILES) {
         error_log("Starting File upload");
         error_log(print_r($_POST, 1));
         $path = $_POST['wildfire_file_folder'];
         $fs = new CmsFilesystem();
         $_FILES['upload'] = $_FILES["Filedata"];
         $_FILES['upload']['name'] = str_replace(' ', '', $_FILES['upload']['name']);
         $fs->upload($path);
         $fs->databaseSync($fs->defaultFileStore . $path, $path);
         $fname = $fs->defaultFileStore . $path . "/" . $_FILES['upload']['name'];
         if ($dimensions = getimagesize($fname)) {
             if ($dimensions[2] == "7" || $dimensions[2] == "8") {
                 WaxLog::log("error", "Detected TIFF Upload");
                 $command = "mogrify " . escapeshellcmd($fname) . " -colorspace RGB -format jpg";
                 system($command);
                 $newname = str_replace(".tiff", ".jpg", $fname);
                 $newname = str_replace(".tif", ".jpg", $newname);
                 rename($fname, $newname);
             }
         }
         chmod($fname, 0777);
         $file = new WildfireFile();
         $newfile = $file->filter(array("filename" => $_FILES['upload']['name'], "rpath" => $path))->first();
         $newfile->description = $_POST["wildfire_file_description"];
         $newfile->save();
         //if these are set then attach the image to the doc!
         if (Request::post('content_id') && Request::post('model_string') && Request::post('join_field')) {
             $model_id = Request::post('content_id');
             $class = Inflections::camelize(Request::post('model_string'));
             $field = Request::post('join_field');
             $model = new $class($model_id);
             $model->{$field} = $newfile;
         }
         echo "Uploaded";
     } else {
         die("UPLOAD ERROR");
     }
     exit;
 }
Exemple #6
0
 public function runner($argv)
 {
     if (isset($argv[3]) && $argv[3] == "production") {
         define("ENV", "production");
         unset($argv[3]);
     }
     $this->app_setup();
     if (!isset($argv[1]) || !isset($argv[2])) {
         exit("[ERROR] You must supply at least two values, a model and a method" . "\n");
     }
     $model_name = Inflections::camelize($argv[1]);
     if (!class_exists($model_name) || !($model = new $model_name())) {
         exit("[ERROR] Cannot find class name {$model_name}" . "\n");
     }
     $commands = array($model_name, $argv[2]);
     array_shift($argv);
     array_shift($argv);
     array_shift($argv);
     if (call_user_func_array($commands, $argv)) {
         $this->add_output("...successfully ran command, and method returned true.");
     } else {
         $this->add_output("...successfully ran command but method returned false.");
     }
 }