예제 #1
0
 /**
  * Save a group
  */
 public function save()
 {
     $grav = Grav::instance();
     $config = $grav['config'];
     $blueprints = new Blueprints();
     $blueprint = $blueprints->get('user/group');
     $fields = $blueprint->fields();
     $config->set("groups.{$this->groupname}", []);
     foreach ($fields as $field) {
         if ($field['type'] == 'text') {
             $value = $field['name'];
             if (isset($this->items['data'][$value])) {
                 $config->set("groups.{$this->groupname}.{$value}", $this->items['data'][$value]);
             }
         }
         if ($field['type'] == 'array') {
             $value = $field['name'];
             $arrayValues = Utils::getDotNotation($this->items['data'], $field['name']);
             if ($arrayValues) {
                 foreach ($arrayValues as $arrayIndex => $arrayValue) {
                     $config->set("groups.{$this->groupname}.{$value}.{$arrayIndex}", $arrayValue);
                 }
             }
         }
     }
     $type = 'groups';
     $blueprints = $this->blueprints("config/{$type}");
     $obj = new Data($config->get($type), $blueprints);
     $file = CompiledYamlFile::instance($grav['locator']->findResource("config://{$type}.yaml"));
     $obj->file($file);
     $obj->save();
 }
예제 #2
0
 /**
  * Internal method to normalize the $_FILES array
  *
  * @param array  $data $_FILES starting point data
  * @param string $key
  * @return object a new Object with a normalized list of files
  */
 protected function normalizeFiles($data, $key = '')
 {
     $files = new \stdClass();
     $files->field = $key;
     $files->file = new \stdClass();
     foreach ($data as $fieldName => $fieldValue) {
         // Since Files Upload are always happening via Ajax
         // we are not interested in handling `multiple="true"`
         // because they are always handled one at a time.
         // For this reason we normalize the value to string,
         // in case it is arriving as an array.
         $value = (array) Utils::getDotNotation($fieldValue, $key);
         $files->file->{$fieldName} = array_shift($value);
     }
     return $files;
 }
예제 #3
0
파일: UtilsTest.php 프로젝트: getgrav/grav
 public function testGetDotNotation()
 {
     $array = ['test' => ['test2' => 'test2Value', 'test3' => ['test4' => 'test4Value']]];
     $this->assertEquals('test2Value', Utils::getDotNotation($array, 'test.test2'));
     $this->assertEquals('test4Value', Utils::getDotNotation($array, 'test.test3.test4'));
     $this->assertEquals('defaultValue', Utils::getDotNotation($array, 'test.non_existent', 'defaultValue'));
 }
 /**
  * Handle deleting a file from a blueprint
  *
  * @return bool True if the action was performed.
  */
 protected function taskRemoveFileFromBlueprint()
 {
     $uri = $this->grav['uri'];
     $blueprint = base64_decode($uri->param('blueprint'));
     $path = base64_decode($uri->param('path'));
     $proute = base64_decode($uri->param('proute'));
     $type = $uri->param('type');
     $field = $uri->param('field');
     $event = $this->grav->fireEvent('onAdminCanSave', new Event(['controller' => &$this]));
     if (!$event['can_save']) {
         return false;
     }
     $this->taskRemoveMedia();
     if ($type == 'pages') {
         $page = $this->admin->page(true, $proute);
         $keys = explode('.', preg_replace('/^header./', '', $field));
         $header = (array) $page->header();
         $data_path = implode('.', $keys);
         $data = Utils::getDotNotation($header, $data_path);
         if (isset($data[$path])) {
             unset($data[$path]);
             Utils::setDotNotation($header, $data_path, $data);
             $page->header($header);
         }
         $page->save();
     } else {
         $blueprint_prefix = $type == 'config' ? '' : $type . '.';
         $blueprint_name = str_replace('/blueprints', '', str_replace('config/', '', $blueprint));
         $blueprint_field = $blueprint_prefix . $blueprint_name . '.' . $field;
         $files = $this->grav['config']->get($blueprint_field);
         if ($files) {
             foreach ($files as $key => $value) {
                 if ($key == $path) {
                     unset($files[$key]);
                 }
             }
         }
         $this->grav['config']->set($blueprint_field, $files);
         switch ($type) {
             case 'config':
                 $data = $this->grav['config']->get($blueprint_name);
                 $config = $this->admin->data($blueprint, $data);
                 $config->save();
                 break;
             case 'themes':
                 Theme::saveConfig($blueprint_name);
                 break;
             case 'plugins':
                 Plugin::saveConfig($blueprint_name);
                 break;
         }
     }
     $this->admin->json_response = ['status' => 'success', 'message' => $this->admin->translate('PLUGIN_ADMIN.REMOVE_SUCCESSFUL')];
     return true;
 }
예제 #5
0
파일: User.php 프로젝트: dweelie/grav
 /**
  * Checks user authorization to the action.
  *
  * @param  string $action
  *
  * @return bool
  */
 public function authorize($action)
 {
     if (empty($this->items)) {
         return false;
     }
     if (isset($this->state) && $this->state !== 'enabled') {
         return false;
     }
     $return = false;
     //Check group access level
     $groups = $this->get('groups');
     if ($groups) {
         foreach ((array) $groups as $group) {
             $permission = Grav::instance()['config']->get("groups.{$group}.access.{$action}");
             $return = Utils::isPositive($permission);
             if ($return === true) {
                 break;
             }
         }
     }
     //Check user access level
     if ($this->get('access')) {
         if (Utils::getDotNotation($this->get('access'), $action) !== null) {
             $permission = $this->get("access.{$action}");
             $return = Utils::isPositive($permission);
         }
     }
     return $return;
 }