Exemplo n.º 1
0
 /**
  * Gets/sets current environment's object
  *
  * @param $set_current mixed
  * @return Current
  */
 public static function current($set_current = null)
 {
     $called_class = get_called_class();
     // set current (ignore Reflection_Property : to enable use of @default Class::current)
     if ($set_current && !is_a($set_current, Reflection_Property::class)) {
         static::$current = $set_current;
         if (!is_a($called_class, Plugin::class, true)) {
             Session::current()->set($set_current, Builder::current()->sourceClassName($called_class));
         }
     } elseif (!isset(static::$current)) {
         // get current plugin from plugins manager
         if (is_a($called_class, Plugin::class, true)) {
             if ($called_class === Builder::class) {
                 static::$current = new Builder();
             } else {
                 $plugin = Session::current()->plugins->get(Builder::current()->sourceClassName($called_class));
                 if (!isset(static::$current)) {
                     static::$current = $plugin;
                 }
             }
         } else {
             static::$current = Session::current()->get($called_class);
         }
     }
     return static::$current;
 }
Exemplo n.º 2
0
 /**
  * @param $parameters Parameters
  * @param $form       array
  * @param $files      array
  * @return mixed
  */
 public function run(Parameters $parameters, $form, $files)
 {
     /** @var $session_files Files */
     $raw_parameters = $parameters->getRawParameters();
     $file_key = reset($raw_parameters);
     $session_files = Session::current()->get(Files::class);
     // numeric (session files index) file key
     if (isset($session_files->files[$file_key])) {
         $file = $session_files->files[$file_key];
     } else {
         foreach ($session_files->files as $file) {
             if ($file->name === $file_key) {
                 break;
             }
         }
     }
     // output
     if (isset($file)) {
         header('Content-Type: ' . $file->getType());
         if (isset($raw_parameters['size'])) {
             $image = Image::createFromString($file->content);
             $image->resize($raw_parameters['size'], $raw_parameters['size'])->display();
         } else {
             echo $file->content;
         }
     }
 }
Exemplo n.º 3
0
 /**
  * @param $parameters Parameters
  * @param $form       array
  * @param $files      array
  * @return mixed
  */
 public function run(Parameters $parameters, $form, $files)
 {
     $parameters = $parameters->getObjects();
     if (!reset($parameters) instanceof Menu) {
         array_unshift($parameters, Session::current()->plugins->get(Menu::class));
     }
     return View::run($parameters, $form, $files, Menu::class, Feature::F_OUTPUT);
 }
Exemplo n.º 4
0
 /**
  * @param Application $set_current
  * @return Application
  */
 public static function current(Application $set_current = null)
 {
     if ($set_current) {
         Session::current()->set($set_current, Application::class);
         return $set_current;
     }
     return Session::current()->get(Application::class);
 }
Exemplo n.º 5
0
 public function activate()
 {
     /** @var $application_updater Application_Updater */
     $application_updater = Session::current()->plugins->get(Application_Updater::class);
     $application_updater->addUpdatable($this);
     $this->cache_path = Application::current()->include_path->getSourceDirectory() . '/cache';
     /** @noinspection PhpIncludeInspection */
     @(include $this->cache_path . '/autoload.php');
     if (!$this->paths || !$this->full_class_names || $application_updater->mustUpdate()) {
         $this->update();
     }
 }
Exemplo n.º 6
0
 /**
  * Run method for a feature controller working for any class
  *
  * @param $parameters Parameters
  * @param $form       array
  * @param $files      array
  * @param $class_name string
  * @return mixed
  */
 public function run(Parameters $parameters, $form, $files, $class_name)
 {
     if (isset($form['login']) && isset($form['password'])) {
         $current = User::current();
         if ($current) {
             Authentication::disconnect(User::current());
         }
         $user = Authentication::login($form['login'], $form['password']);
         if (isset($user)) {
             Authentication::authenticate($user);
             return self::AUTH_OK . rParse(Session::sid(), '=');
         }
     }
     return self::AUTH_ERROR;
 }
Exemplo n.º 7
0
 /**
  * This will be called for this controller, always.
  *
  * @param $parameters Parameters
  * @param $form       array
  * @param $files      array
  * @param $class_name string
  * @return mixed
  */
 public function run(Parameters $parameters, $form, $files, $class_name)
 {
     set_time_limit(900);
     $import = Import_Builder_Form::build($form, Session::current()->get(Files::class)->files);
     $import->class_name = $class_name;
     $parameters->getMainObject($import);
     $parameters = $parameters->getObjects();
     foreach ($import->worksheets as $worksheet) {
         $array = $worksheet->file->getCsvContent();
         $import_array = new Import_Array($worksheet->settings, $import->class_name);
         $import_array->importArray($array);
     }
     $parameters[Template::TEMPLATE] = 'importDone';
     return View::run($parameters, $form, $files, $class_name, Feature::F_IMPORT);
 }
Exemplo n.º 8
0
 /**
  * This will be called for this controller, always.
  *
  * @param $parameters Parameters
  * @param $form       array
  * @param $files      array
  * @return mixed
  */
 public function run(Parameters $parameters, $form, $files)
 {
     $environment = Session::current()->get(Environment::class, true);
     $objects = $parameters->getObjects();
     $set_value = isset($objects['']) ? $objects[''] : (isset($objects[1]) ? $objects[1] : null);
     $name = $objects[0];
     $this->property = (new Reflection_Class($environment))->getProperty($name);
     if ($set_value) {
         $type = $this->property->getType();
         $environment->{$name} = $type->isClass() ? Dao::read($set_value, $type->asString()) : $set_value;
         $parameters->set('selected', true);
         return (new Output_Controller())->run($parameters, $form, $files);
     } else {
         $objects['controller'] = $this;
         $objects['name'] = $name;
         $objects = array_merge([get_class($environment) => $environment], $objects);
         return View::run($objects, $form, $files, get_class($environment), Feature::F_SELECT);
     }
 }
Exemplo n.º 9
0
 /**
  * Includes the php file that contains the given class (must contain namespace)
  *
  * @param $class_name string class name (with or without namespace)
  * @return boolean
  */
 public function autoload($class_name)
 {
     if ($i = strrpos($class_name, '\\')) {
         $namespace = strtolower(str_replace('\\', '/', substr($class_name, 0, $i)));
         $file_name = substr($class_name, $i + 1);
         // 'A\Class' stored into 'a/class/Class.php'
         if (file_exists($file1 = strtolower($namespace . '/' . $file_name) . '/' . $file_name . '.php')) {
             /** @noinspection PhpIncludeInspection */
             $result = (include_once Include_Filter::file($file1));
         } elseif (file_exists($file2 = strtolower($namespace) . '/' . $file_name . '.php')) {
             /** @noinspection PhpIncludeInspection */
             $result = (include_once Include_Filter::file($file2));
         } else {
             if (Builder::isBuilt($class_name)) {
                 $file = 'cache/compiled/' . str_replace(SL, '-', Names::classToPath($class_name));
                 if (file_exists($file)) {
                     /** @noinspection PhpIncludeInspection */
                     $result = (include_once $file);
                 }
             }
             if (!isset($result)) {
                 if (error_reporting()) {
                     trigger_error('Class not found ' . $class_name . ', should be into ' . $file1 . ' or ' . $file2, E_USER_ERROR);
                 }
                 $result = false;
             }
         }
     } else {
         /** @noinspection PhpIncludeInspection */
         $result = (include_once Include_Filter::file($class_name . '.php'));
     }
     // instantiate plugin
     if ($result && class_exists($class_name, false) && is_a($class_name, Plugin::class, true)) {
         if (Session::current()) {
             Session::current()->plugins->get($class_name);
         }
     }
 }
Exemplo n.º 10
0
 /**
  * @param $parameters Parameters
  * @param $form       array
  * @param $files      array
  * @param $class_name string
  * @return mixed
  * @todo factorize
  */
 public function run(Parameters $parameters, $form, $files, $class_name)
 {
     // convert form files to worksheets and session files
     if ($files) {
         /** @var $import Import */
         $import = $parameters->getMainObject(Import::class);
         $import->class_name = $class_name;
         $form = (new Post_Files())->appendToForm($form, $files);
         foreach ($form as $file) {
             if ($file instanceof File) {
                 if (!isset($session_files)) {
                     /** @var $session_files Files */
                     $session_files = Builder::create(Files::class);
                 }
                 $excel = Spreadsheet_File::fileToArray($file->temporary_file_name, $errors);
                 $worksheet_number = 0;
                 foreach ($excel as $temporary_file_name => $worksheet) {
                     if (filesize($temporary_file_name) > 1) {
                         $import_worksheet = Builder::create(Import_Worksheet::class, [$worksheet_number++, Import_Settings_Builder::buildArray($worksheet, $class_name), $csv_file = Builder::create(File::class, [$temporary_file_name])]);
                         $import_worksheet->errors = $errors;
                         $session_files->files[] = $csv_file;
                         $import->worksheets[] = $import_worksheet;
                     }
                 }
                 // only one file once
                 break;
             }
         }
         if (isset($session_files)) {
             Session::current()->set($session_files);
         }
     } else {
         /** @var $files File[] */
         $files = Session::current()->get(Files::class)->files;
         $parameters->unshift($import = Import_Builder_Form::build($form, $files));
         $import->class_name = $class_name;
     }
     // prepare parameters
     $parameters = $parameters->getObjects();
     $general_buttons = $this->getGeneralButtons($class_name);
     if (isset($parameters['constant_remove']) && strtoupper($parameters['constant_remove'][0]) === $parameters['constant_remove'][0]) {
         $parameters['constant_remove'] = rParse($parameters['constant_remove'], DOT);
     }
     foreach ($import->worksheets as $worksheet) {
         // apply controller parameters
         if (isset($parameters['constant_add']) && isset($worksheet->settings->classes[$parameters['constant_add']])) {
             $worksheet->settings->classes[$parameters['constant_add']]->addConstant();
         }
         if (isset($parameters['constant_remove']) && isset($worksheet->settings->classes[lLastParse($parameters['constant_remove'], DOT, 1, false)])) {
             $worksheet->settings->classes[lLastParse($parameters['constant_remove'], DOT, 1, false)]->removeConstant(rLastParse($parameters['constant_remove'], DOT, 1, true));
         }
         Custom_Settings_Controller::applyParametersToCustomSettings($worksheet->settings, array_merge($form, $parameters));
     }
     // recover empty Import_Settings (after loading empty one)
     /** @var $files File[] */
     $files = Session::current()->get(Files::class)->files;
     foreach ($import->worksheets as $worksheet_number => $worksheet) {
         if (empty($worksheet->settings->classes)) {
             $file = $files[$worksheet_number];
             $array = $file->getCsvContent();
             $import->worksheets[$worksheet_number] = new Import_Worksheet($worksheet_number, Import_Settings_Builder::buildArray($array, $class_name), $file);
         }
     }
     // get general buttons and customized import settings
     foreach ($import->worksheets as $worksheet_number => $worksheet) {
         $customized_import_settings = $worksheet->settings->getCustomSettings();
         $worksheet_general_buttons = $general_buttons;
         if (!isset($customized_import_settings[$worksheet->settings->name])) {
             unset($worksheet_general_buttons['delete']);
         }
         $parameters['custom'][$worksheet_number] = new StdClass();
         $parameters['custom'][$worksheet_number]->customized_lists = $customized_import_settings;
         $parameters['custom'][$worksheet_number]->general_buttons = $worksheet_general_buttons;
         $parameters['custom'][$worksheet_number]->settings = $worksheet->settings;
         $parameters['custom'][$worksheet_number]->aliases_property = Import_Array::getPropertiesAlias($worksheet->settings->getClassName());
         $parameters['custom'][$worksheet_number]->properties_alias = array_flip($parameters['custom'][$worksheet_number]->aliases_property);
     }
     // view
     $parameters[Template::TEMPLATE] = 'importPreview';
     return View::run($parameters, $form, $files, $class_name, Feature::F_IMPORT);
 }
Exemplo n.º 11
0
 /**
  * Returns application name
  *
  * @param $template Template
  * @return string
  */
 public function getApplication(Template $template)
 {
     return new Displayable(Session::current()->getApplicationName(), Displayable::TYPE_CLASS);
 }
Exemplo n.º 12
0
 /**
  * Remove current user from script and session
  *
  * Call this to disconnect user
  *
  * @param $user User
  */
 public static function disconnect(User $user)
 {
     User::current(new User());
     Session::current()->removeAny(get_class($user));
 }
Exemplo n.º 13
0
 /**
  * @param $file File
  * @return Anchor
  */
 protected function buildFileAnchor(File $file)
 {
     /** @var $session_files Files */
     $session_files = Session::current()->get(Files::class, true);
     $session_files->files[] = $file;
     $image = $file->getType()->is('image') ? new Image(View::link(Session_File::class, 'output', [$file->name], ['size' => 22])) : '';
     $anchor = new Anchor(View::link(Session_File::class, 'image', [$file->name]), $image . new Span($file->name));
     if ($file->getType()->is('image')) {
         $anchor->setAttribute('target', Target::BLANK);
         //$anchor->addClass('popup');
     }
     return $anchor;
 }
Exemplo n.º 14
0
 /**
  * @param $sources Reflection_Source[] Key is the file path
  * @return Reflection_Source[] added sources list
  */
 public function moreSourcesToCompile(&$sources)
 {
     $added = [];
     foreach ($sources as $file_path => $source) {
         if (!strpos($file_path, SL)) {
             $reload = true;
             break;
         }
     }
     if (isset($reload)) {
         $old_compositions = Builder::current()->getCompositions();
         $old_levels = Session::current()->plugins->getAll(true);
         if (isset(Main::$current)) {
             Main::$current->resetSession();
         }
         $new_compositions = Builder::current()->getCompositions();
         $new_levels = Session::current()->plugins->getAll(true);
         // add classes where builder composition changed
         foreach ($old_compositions as $class_name => $old_composition) {
             if (!isset($new_compositions[$class_name]) || $old_composition != $new_compositions[$class_name] || is_array($old_composition) && (array_diff($old_composition, $new_compositions[$class_name]) || array_diff($new_compositions[$class_name], $old_composition))) {
                 $this->moreSourcesAdd($class_name, $sources, $added);
             }
         }
         foreach ($new_compositions as $class_name => $new_composition) {
             if (!isset($old_compositions[$class_name])) {
                 $this->moreSourcesAdd($class_name, $sources, $added);
             }
         }
         // add classes of globally added/removed plugins
         foreach ($old_levels as $level => $old_plugins) {
             foreach ($old_plugins as $class_name => $old_plugin) {
                 if (!isset($new_levels[$level][$class_name])) {
                     $this->moreSourcesAdd($class_name, $sources, $added);
                 }
             }
         }
         foreach ($new_levels as $level => $new_plugins) {
             foreach ($new_plugins as $class_name => $new_plugin) {
                 if (!isset($old_levels[$level][$class_name])) {
                     $this->moreSourcesAdd($class_name, $sources, $added);
                 }
             }
         }
     }
     return $added;
 }
Exemplo n.º 15
0
 /**
  * This will be called for this controller, always.
  *
  * @param $parameters Parameters
  * @param $form       array
  * @param $files      array
  * @return mixed
  */
 public function run(Parameters $parameters, $form, $files)
 {
     $environment = Session::current()->get(Environment::class, true);
     $parameters = array_merge([get_class($environment) => $environment], $parameters->getObjects());
     return View::run($parameters, $form, $files, get_class($environment), Feature::F_OUTPUT);
 }
Exemplo n.º 16
0
 private function resumeSession()
 {
     $plugins = Session::current()->plugins;
     $plugins->addPlugins('top_core', $this->top_core_plugins);
     $plugins->activatePlugins('core');
 }
Exemplo n.º 17
0
 /**
  * Updates all registered updatable objects
  *
  * You should prefer call autoUpdate() to update the application only if needed
  *
  * @param $main_controller Main
  */
 public function update(Main $main_controller)
 {
     $last_update_time = $this->getLastUpdateTime();
     if (!isset($this->update_time)) {
         $this->update_time = time();
     }
     foreach ($this->updatables as $key => $updatable) {
         if (is_string($updatable)) {
             $updatable = Session::current()->plugins->get($updatable);
             $this->updatables[$key] = $updatable;
         }
         if ($updatable instanceof Needs_Main) {
             $updatable->setMainController($main_controller);
         }
         $updatable->update($last_update_time);
     }
 }
Exemplo n.º 18
0
 /**
  * @param $serialized string
  */
 public function unserialize($serialized)
 {
     $this->compilers = [];
     foreach (unserialize($serialized) as $wave_number => $compilers) {
         foreach ($compilers as $class_name) {
             $this->compilers[$wave_number][] = Session::current()->plugins->has($class_name) ? Session::current()->plugins->get($class_name) : Builder::create($class_name);
         }
     }
 }
Exemplo n.º 19
0
 /**
  * This will be called for this controller, always.
  *
  * @param $parameters Parameters
  * @param $form       array
  * @param $files      array
  * @return mixed
  */
 public function run(Parameters $parameters, $form, $files)
 {
     Session::current()->get(Settings::class, true)->add($parameters->getRawParameter('code'), $parameters->getRawParameter('value'));
 }
Exemplo n.º 20
0
 /**
  * @param $weaver IWeaver If not set, the current weaver plugin is used
  */
 public function __construct(IWeaver $weaver = null)
 {
     $this->weaver = $weaver ?: Session::current()->plugins->get(Weaver::class);
 }
Exemplo n.º 21
0
 /**
  * @param $class_name string
  * @return string
  */
 public function autoload($class_name)
 {
     $file_path = $this->getClassFilename($class_name);
     if ($file_path) {
         /** @noinspection PhpIncludeInspection */
         include_once Include_Filter::file($file_path);
         // if included file does not contain the good class : will need to scan for the right file
         if (!class_exists($class_name) && !interface_exists($class_name) && !trait_exists($class_name)) {
             unset($this->class_paths[$class_name]);
             $file_path = $this->autoload($class_name);
         } elseif (Session::current()->plugins->has($class_name)) {
             Session::current()->plugins->get($class_name);
         }
     }
     return $file_path;
 }