Exemplo n.º 1
0
 public function create($path_file_generate, $data = array(), $ext = '.php')
 {
     $trans = array();
     $options = $this->data;
     $path_template = __DIR__ . '/templates/' . $this->template . '.php';
     if (!is_file($path_template)) {
         throw new \Exception("La plantilla \"{$this->template}\" no existe para generar.");
     }
     ob_start();
     require $path_template;
     $content = ob_get_clean();
     $trans['##NAMESPACE##'] = $this->namespace ? $this->namespace : '';
     $trans['##CLASS##'] = $this->name_class ? $this->name_class : '';
     $trans['##EXTENDS##'] = $this->name_class_extend ? 'extends ' . $this->name_class_extend : '';
     $content = strtr($content, $trans);
     $content = str_replace(array('[?php', '[?=', '?]'), array('<?php', '<?php echo', '?>'), $content);
     \Kodazzi\Tools\File::write($path_file_generate . $ext, $content);
 }
Exemplo n.º 2
0
 public function valid()
 {
     $value = $this->value;
     $isValid = parent::valid();
     if ($isValid && (count($this->max_dimensions) || count($this->min_dimensions))) {
         $this->mkdir(Ki_PUBLIC . '/tmp');
         $name_tmp = date('h-m-s', time()) . '-' . $this->new_name;
         // Copia la imagen en el directorio temporal dentro de public_html/
         \Kodazzi\Tools\File::copy($value->getPathname(), Ki_PUBLIC . '/tmp/' . $name_tmp);
         if (is_file(Ki_PUBLIC . '/tmp/' . $name_tmp)) {
             $return = true;
             list($width, $height, $type) = getimagesize(Ki_PUBLIC . '/tmp/' . $name_tmp);
             if (count($this->min_dimensions)) {
                 /* Compara el ancho y alto de la imagen */
                 if ($width < $this->min_dimensions['width'] || $height < $this->min_dimensions['height']) {
                     $this->msg_error = strtr($this->I18n->get('form.min_dimensions'), array('%width%' => "{$this->min_dimensions['width']}", '%height%' => $this->min_dimensions['height']));
                     $return = false;
                 }
             }
             if (count($this->max_dimensions)) {
                 /* Compara el ancho y alto de la imagen */
                 if ($width > $this->max_dimensions['width'] || $height > $this->max_dimensions['height']) {
                     $this->msg_error = strtr($this->I18n->get('form.max_dimensions'), array('%width%' => $this->max_dimensions['width'], '%height%' => $this->max_dimensions['height']));
                     $return = false;
                 }
             }
             /* Elimina la imagen temporarl */
             unlink(Ki_PUBLIC . '/tmp/' . $name_tmp);
             return $return;
         } else {
             $this->msg_error = $this->I18n->get('form.upload');
             return false;
         }
         return false;
     }
     return $isValid;
 }