function add_elements($elements)
 {
     foreach ($elements as $id => $el) {
         $class = '\\Leeflets\\Form\\' . \Leeflets\String::camelize($el['type']);
         unset($el['type']);
         $obj = new $class($this, $id, $el);
         $this->elements[$id] = $obj;
     }
 }
Exemple #2
0
 function load_active()
 {
     $active_addons = $this->settings->get('active_addons');
     if (!$active_addons) {
         return false;
     }
     $deactivate = array();
     foreach ($active_addons as $addon) {
         $path = $this->config->addons_path . '/' . $addon . '/' . $addon . '.php';
         if (!file_exists($path)) {
             $deactivate[] = $addon;
         } else {
             Inc::class_file($path);
             $class_name = \Leeflets\String::camelize($addon);
             $class_name = '\\Leeflets\\User\\Addon\\' . $class_name;
             $this->instances[$addon] = $obj = new $class_name();
             $obj->load_objects($this->config, $this->settings, $this->hook, $this->admin_script, $this->admin_style, $this->template_script, $this->template_style, $this->filesystem, $this->router);
             $obj->init();
         }
     }
     if ($deactivate) {
         $this->deactivate($deactivate);
     }
 }
Exemple #3
0
 function valid_email($value)
 {
     return \Leeflets\String::valid_email($value);
 }
Exemple #4
0
 function remove_upload($field_name, $index)
 {
     $field = $this->_get_single_field($field_name);
     $ids = \Leeflets\String::parse_array_representation($field_name);
     $data = $this->content->get_data();
     $template_content = new \Leeflets\Template\Content($data);
     $files = $template_content->vget($ids);
     if ($field->has_multiple_values) {
         if (!isset($files[$index])) {
             echo json_encode(array('error' => 'File index not found.'));
             exit;
         }
         $file = $files[$index];
     } else {
         $file = $files;
     }
     // If this is a sample image in the template, don't try remove the file
     if (!isset($file['in_template']) || !$file['in_template']) {
         // Try removing the files
         @unlink($this->config->uploads_path . '/' . $file['path']);
         if (isset($file['versions'])) {
             foreach ($file['versions'] as $version) {
                 @unlink($this->config->uploads_path . '/' . $version['path']);
             }
         }
         // Check if any of the files are still there
         $all_removed = true;
         if (is_file($this->config->uploads_path . '/' . $file['path'])) {
             $all_removed = false;
         } elseif (isset($file['versions'])) {
             foreach ($file['versions'] as $version) {
                 if (is_file($this->config->uploads_path . '/' . $version['path'])) {
                     $all_removed = false;
                 }
             }
         }
     } else {
         $all_removed = true;
     }
     if ($all_removed) {
         // Remove file from data and save
         if ($field->has_multiple_values) {
             unset($files[$index]);
         } else {
             $files = array();
         }
         $files_array = \Leeflets\String::convert_representation_to_array($field_name, $files);
         $data = $this->content->get_data();
         $_data =& $data;
         foreach ($ids as $id) {
             $data =& $data[$id];
         }
         $data = $files;
         $this->content->set_data($_data);
         echo json_encode(array('success' => true));
     } else {
         echo json_encode(array('error' => 'Some files could not be removed.'));
     }
     exit;
 }