Autodoc
  • Namespace
  • Class
  • Tree

Namespaces

  • BlueTihi
    • Context
  • Brickrouge
    • Element
      • Nodes
    • Renderer
    • Widget
  • ICanBoogie
    • ActiveRecord
    • AutoConfig
    • CLDR
    • Composer
    • Core
    • Event
    • Exception
    • HTTP
      • Dispatcher
      • Request
    • I18n
      • Translator
    • Mailer
    • Modules
      • Taxonomy
        • Support
      • Thumbnailer
        • Versions
    • Object
    • Operation
      • Dispatcher
    • Prototype
    • Routes
    • Routing
      • Dispatcher
    • Session
  • Icybee
    • ActiveRecord
      • Model
    • ConfigOperation
    • Document
    • EditBlock
    • Element
      • ActionbarContextual
      • ActionbarSearch
      • ActionbarToolbar
    • FormBlock
    • Installer
    • ManageBlock
    • Modules
      • Articles
      • Cache
        • Collection
        • ManageBlock
      • Comments
        • ManageBlock
      • Contents
        • ManageBlock
      • Dashboard
      • Editor
        • Collection
      • Files
        • File
        • ManageBlock
      • Forms
        • Form
        • ManageBlock
      • I18n
      • Images
        • ManageBlock
      • Members
      • Modules
        • ManageBlock
      • Nodes
        • ManageBlock
        • Module
      • Pages
        • BreadcrumbElement
        • LanguagesElement
        • ManageBlock
        • NavigationBranchElement
        • NavigationElement
        • Page
        • PageController
      • Registry
      • Search
      • Seo
      • Sites
        • ManageBlock
      • Taxonomy
        • Terms
          • ManageBlock
        • Vocabulary
          • ManageBlock
      • Users
        • ManageBlock
        • NonceLogin
        • Roles
      • Views
        • ActiveRecordProvider
        • Collection
        • View
    • Operation
      • ActiveRecord
      • Constructor
      • Module
      • Widget
    • Rendering
  • None
  • Patron
  • PHP

Classes

  • ConfigBlock
  • ConfigOperation
  • DeleteOperation
  • DownloadOperation
  • EditBlock
  • File
  • FileUpload
  • GetOperation
  • ManageBlock
  • Model
  • Module
  • SaveOperation
  • UploadOperation
  1 <?php
  2 
  3 /*
  4  * This file is part of the Icybee package.
  5  *
  6  * (c) Olivier Laviale <olivier.laviale@gmail.com>
  7  *
  8  * For the full copyright and license information, please view the LICENSE
  9  * file that was distributed with this source code.
 10  */
 11 
 12 namespace Icybee\Modules\Files;
 13 
 14 use ICanBoogie\I18n;
 15 use ICanBoogie\Operation;
 16 use ICanBoogie\Uploaded;
 17 
 18 use Brickrouge\Element;
 19 use Brickrouge\Document;
 20 use Brickrouge\Form;
 21 
 22 use Icybee\Modules\Editor\RTEEditorElement;
 23 
 24 class EditBlock extends \Icybee\Modules\Nodes\EditBlock
 25 {
 26     const ACCEPT = '#files-accept';
 27     const UPLOADED = '#files-uploaded';
 28     const UPLOADER_CLASS = 'uploader class';
 29 
 30     protected $accept = null;
 31     protected $uploader_class = 'Icybee\Modules\Files\FileUpload';
 32 
 33     static protected function add_assets(Document $document)
 34     {
 35         parent::add_assets($document);
 36 
 37         $document->css->add(DIR . 'public/edit.css');
 38         $document->js->add(DIR . 'public/edit.js');
 39     }
 40 
 41     protected function lazy_get_values()
 42     {
 43         return parent::lazy_get_values() + array
 44         (
 45             File::NID => null,
 46             File::PATH => null,
 47             self::UPLOADED => null
 48         );
 49     }
 50 
 51     protected function lazy_get_children()
 52     {
 53         global $core;
 54 
 55         $folder = \ICanBoogie\REPOSITORY . 'tmp';
 56 
 57         if (!is_writable($folder))
 58         {
 59             return array
 60             (
 61                 Element::CHILDREN => array
 62                 (
 63                     I18n\t('The folder %folder is not writable !', array('%folder' => $folder))
 64                 )
 65             );
 66         }
 67 
 68         #
 69         # options
 70         #
 71 
 72         $options = array
 73         (
 74             self::ACCEPT => $this->accept,
 75             self::UPLOADER_CLASS => $this->uploader_class
 76         );
 77 
 78         $accept = $options[self::ACCEPT];
 79         $uploader_class = $options[self::UPLOADER_CLASS];
 80 
 81         #
 82         # UPLOADED is set when the file has already been updated
 83         # and is available on our host
 84         #
 85 
 86         $values = array();
 87         $properties = $this->values;
 88 
 89         $entry_nid = $properties[File::NID];
 90         $entry_path = $properties[File::PATH];
 91 
 92         $uploaded_path = $properties[self::UPLOADED];
 93         $uploaded_mime = null;
 94 
 95         #
 96         # check uploaded file
 97         #
 98 
 99         $file = new Uploaded(File::PATH, $accept);
100 
101         if ($file->location)
102         {
103             $values[File::TITLE] = $file->name;
104 
105             $uploaded_mime = $file->mime;
106             $uploaded_path = \ICanBoogie\REPOSITORY . 'tmp' . DIRECTORY_SEPARATOR . basename($file->location) . $file->extension;
107 
108             $file->move($uploaded_path, true);
109 
110             if (array_key_exists(self::UPLOADED, $options))
111             {
112                 $options[self::UPLOADED] = $file;
113             }
114         }
115 
116         // FIXME: now that we use a flash uploader, will the PATH defined in HIDDENS be a problem ?
117 
118         $values[File::PATH] = $uploaded_path ? $uploaded_path : $entry_path;
119 
120         #
121         # elements
122         #
123 
124         $this->attributes = \ICanBoogie\array_merge_recursive
125         (
126             $this->attributes, array
127             (
128                 Form::HIDDENS => array
129                 (
130                     File::PATH => $uploaded_path,
131                     File::MIME => $uploaded_mime,
132 
133                     self::UPLOADED => $uploaded_path
134                 ),
135 
136                 Form::VALUES => $values
137             )
138         );
139 
140         return array_merge(parent::lazy_get_children(), [
141 
142             File::PATH => new $uploader_class([
143 
144                 Form::LABEL => 'file',
145                 Element::REQUIRED => empty($entry_nid),
146                 \Brickrouge\File::FILE_WITH_LIMIT => $core->site->metas[$this->module->flat_id . '.max_file_size'],
147                 Element::WEIGHT => -100,
148                 \Brickrouge\File::T_UPLOAD_URL => Operation::encode($this->module->id . '/upload')
149 
150             ]),
151 
152             File::DESCRIPTION => new RTEEditorElement
153             (
154                 array
155                 (
156                     Form::LABEL => 'description',
157                     Element::WEIGHT => 50,
158 
159                     'rows' => 5
160                 )
161             )
162         ]);
163     }
164 }
Autodoc API documentation generated by ApiGen 2.8.0