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\Uploaded;
 15 
 16 class Module extends \Icybee\Modules\Nodes\Module
 17 {
 18     const OPERATION_UPLOAD = 'upload';
 19 
 20     /**
 21      * Overrides the method to create the "/repository/tmp/" and "/repository/files/" directories,
 22      * and add a ".htaccess" file in the "/repository/tmp/" direcotry which denies all access and
 23      * a ".htaccess" file in the "/repository/files/" directory which allows all access.
 24      */
 25     public function install(\ICanBoogie\Errors $errors)
 26     {
 27         global $core;
 28 
 29         $repository = \ICanBoogie\REPOSITORY;
 30 
 31         #
 32         # $repository/tmp
 33         #
 34 
 35         $path = $repository . 'tmp';
 36 
 37         if (!file_exists($path))
 38         {
 39             $parent = dirname($path);
 40 
 41             if (is_writable($parent))
 42             {
 43                 mkdir($path);
 44 
 45                 file_put_contents($path . DIRECTORY_SEPARATOR . '.htaccess', 'Deny from all');
 46             }
 47             else
 48             {
 49                 $errors[$this->id] = $errors->format('Unable to create %directory directory, its parent is not writtable.', [ '%directory' => $path ]);
 50             }
 51         }
 52 
 53         #
 54         # $repository/files
 55         #
 56 
 57         $path = $repository . 'files';
 58 
 59         if (!file_exists($path))
 60         {
 61             $parent = dirname($path);
 62 
 63             if (is_writable($parent))
 64             {
 65                 mkdir($path);
 66 
 67                 file_put_contents($path . DIRECTORY_SEPARATOR . '.htaccess', 'Allow from all');
 68             }
 69             else
 70             {
 71                 $errors[$this->id] = $errors->format('Unable to create %directory directory, its parent is not writtable', [ '%directory' => $path ]);
 72             }
 73         }
 74 
 75         #
 76         # config: max_file_size
 77         #
 78 
 79         $core->registry["{$this->flat_id}.max_file_size"] = 16000;
 80 
 81         return parent::install($errors);
 82     }
 83 
 84     /**
 85      * Checks that the "tmp" and "files" directories exist in the repository.
 86      */
 87     public function is_installed(\ICanBoogie\Errors $errors)
 88     {
 89         global $core;
 90 
 91         $repository = \ICanBoogie\REPOSITORY;
 92 
 93         #
 94         # $repository/tmp
 95         #
 96 
 97         $path = $repository . 'tmp';
 98 
 99         if (!is_dir($path))
100         {
101             $errors[$this->id] = $errors->format('The %directory directory is missing.', [ '%directory' => $path ]);
102         }
103 
104         #
105         # $repository/files
106         #
107 
108         $path = $repository . 'files';
109 
110         if (!is_dir($path))
111         {
112             $errors[$this->id] = $errors->format('The %directory directory is missing.', [ '%directory' => $path ]);
113         }
114 
115         return parent::is_installed($errors);
116     }
117 
118     public function clean_temporary_files($lifetime=3600)
119     {
120         $path = \ICanBoogie\REPOSITORY . 'tmp';
121 
122         if (!is_dir($path))
123         {
124             \ICanBoogie\log_error('The directory %directory does not exists', [ '%directory' => $path ]);
125 
126             return;
127         }
128 
129         if (!is_writable($path))
130         {
131             \ICanBoogie\log_error('The directory %directory is not writtable', [ '%directory' => $path ]);
132 
133             return;
134         }
135 
136         $dh = opendir($path);
137 
138         if (!$dh)
139         {
140             return;
141         }
142 
143         $now = time();
144         $location = getcwd();
145 
146         chdir($path);
147 
148         while ($file = readdir($dh))
149         {
150             if ($file{0} == '.')
151             {
152                 continue;
153             }
154 
155             $stat = stat($file);
156 
157             if ($now - $stat['ctime'] > $lifetime)
158             {
159                 unlink($file);
160 
161                 \ICanBoogie\log('The temporary file %file has been deleted form the repository %directory', [
162 
163                     '%file' => $file,
164                     '%directory' => $path
165 
166                 ]);
167             }
168         }
169 
170         chdir($location);
171 
172         closedir($dh);
173     }
174 }
Autodoc API documentation generated by ApiGen 2.8.0