Пример #1
0
 public function reset()
 {
     // Reset values
     $this->embedCode = '';
     $this->oembed = null;
     $this->attributes([], true);
     $this->params([], true);
     $this->config = new Data($this->base_config->toArray());
 }
Пример #2
0
 public function __construct(Data $package, $package_type = null)
 {
     $data = new Data($package->blueprints()->toArray());
     parent::__construct($data, $package_type);
     $this->settings = $package->toArray();
     $html_description = \Parsedown::instance()->line($this->description);
     $this->data->set('slug', $package->slug);
     $this->data->set('description_html', $html_description);
     $this->data->set('description_plain', strip_tags($html_description));
     $this->data->set('symlink', is_link(USER_DIR . $package_type . DS . $this->slug));
 }
 /**
  * @param Page $page
  * @return \Grav\Common\Data\Data
  * @codeCoverageIgnore
  */
 protected function getConfig(Page $page = null)
 {
     if ($this->cfg && empty($page)) {
         return $this->cfg;
     }
     if (!$this->cfg) {
         $this->cfg = new Data((array) $this->config->get('plugins.videoembed', []));
     }
     if (!empty($page)) {
         $headers = $page->header();
         if (isset($headers->videoembed)) {
             $this->cfg = new Data($this->mergeOptions($this->cfg->toArray(), (array) $headers->videoembed));
         }
     }
     return $this->cfg;
 }
Пример #4
0
 /**
  * Initialize object by loading all the configuration files.
  *
  * @param array $files
  */
 protected function init(array $files)
 {
     $this->updated = true;
     // Combine all configuration files into one larger lookup table (only keys matter).
     $allFiles = $files['user'] + $files['plugins'] + $files['system'];
     // Then sort the files to have all parent nodes first.
     // This is to make sure that child nodes override parents content.
     uksort($allFiles, function ($a, $b) {
         $diff = substr_count($a, '/') - substr_count($b, '/');
         return $diff ? $diff : strcmp($a, $b);
     });
     $systemBlueprints = new Blueprints(SYSTEM_DIR . 'blueprints');
     $pluginBlueprints = new Blueprints(USER_DIR);
     $items = array();
     foreach ($allFiles as $name => $dummy) {
         $lookup = array('system' => SYSTEM_DIR . 'config/' . $name . YAML_EXT, 'plugins' => USER_DIR . $name . '/' . basename($name) . YAML_EXT, 'user' => USER_DIR . 'config/' . $name . YAML_EXT);
         if (strpos($name, 'plugins/') === 0) {
             $blueprint = $pluginBlueprints->get("{$name}/blueprints");
         } else {
             $blueprint = $systemBlueprints->get($name);
         }
         $data = new Data(array(), $blueprint);
         foreach ($lookup as $key => $path) {
             if (is_file($path)) {
                 $data->merge(File\Yaml::instance($path)->content());
             }
         }
         //            $data->validate();
         //            $data->filter();
         // Find the current sub-tree location.
         $current =& $items;
         $parts = explode('/', $name);
         foreach ($parts as $part) {
             if (!isset($current[$part])) {
                 $current[$part] = array();
             }
             $current =& $current[$part];
         }
         // Handle both updated and deleted configuration files.
         $current = $data->toArray();
     }
     $this->items = $items;
     $this->files = $files;
 }
Пример #5
0
 /**
  * Handle form processing on POST action.
  */
 public function post()
 {
     $grav = Grav::instance();
     $uri = $grav['uri']->url;
     $session = $grav['session'];
     if (isset($_POST)) {
         $this->values = new Data(isset($_POST) ? (array) $_POST : []);
         $data = $this->values->get('data');
         // Add post data to form dataset
         if (!$data) {
             $data = $this->values->toArray();
         }
         if (method_exists('Grav\\Common\\Utils', 'getNonce')) {
             if (!$this->values->get('form-nonce') || !Utils::verifyNonce($this->values->get('form-nonce'), 'form')) {
                 $event = new Event(['form' => $this, 'message' => $grav['language']->translate('PLUGIN_FORM.NONCE_NOT_VALIDATED')]);
                 $grav->fireEvent('onFormValidationError', $event);
                 return;
             }
         }
         $i = 0;
         foreach ($this->items['fields'] as $key => $field) {
             $name = isset($field['name']) ? $field['name'] : $key;
             if (!isset($field['name'])) {
                 if (isset($data[$i])) {
                     //Handle input@ false fields
                     $data[$name] = $data[$i];
                     unset($data[$i]);
                 }
             }
             if ($field['type'] == 'checkbox') {
                 $data[$name] = isset($data[$name]) ? true : false;
             }
             $i++;
         }
         $this->data->merge($data);
     }
     // Validate and filter data
     try {
         $this->data->validate();
         $this->data->filter();
         $grav->fireEvent('onFormValidationProcessed', new Event(['form' => $this]));
     } catch (\RuntimeException $e) {
         $event = new Event(['form' => $this, 'message' => $e->getMessage(), 'messages' => $e->getMessages()]);
         $grav->fireEvent('onFormValidationError', $event);
         if ($event->isPropagationStopped()) {
             return;
         }
     }
     // Process previously uploaded files for the current URI
     // and finally store them. Everything else will get discarded
     $queue = $session->getFlashObject('files-upload');
     $queue = $queue[base64_encode($uri)];
     if (is_array($queue)) {
         foreach ($queue as $key => $files) {
             foreach ($files as $destination => $file) {
                 if (!rename($file['tmp_name'], $destination)) {
                     throw new \RuntimeException(sprintf($grav['language']->translate('PLUGIN_FORM.FILEUPLOAD_UNABLE_TO_MOVE', null, true), '"' . $file['tmp_name'] . '"', $destination));
                 }
                 unset($files[$destination]['tmp_name']);
             }
             $this->data->merge([$key => $files]);
         }
     }
     $process = isset($this->items['process']) ? $this->items['process'] : [];
     if (is_array($process)) {
         $event = null;
         foreach ($process as $action => $data) {
             if (is_numeric($action)) {
                 $action = \key($data);
                 $data = $data[$action];
             }
             $previousEvent = $event;
             $event = new Event(['form' => $this, 'action' => $action, 'params' => $data]);
             if ($previousEvent) {
                 if (!$previousEvent->isPropagationStopped()) {
                     $grav->fireEvent('onFormProcessed', $event);
                 } else {
                     break;
                 }
             } else {
                 $grav->fireEvent('onFormProcessed', $event);
             }
         }
     } else {
         // Default action.
     }
 }