Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezstylepackagecreator.php
Go to the documentation of this file.
1 <?php
18 class eZStylePackageCreator extends eZPackageCreationHandler
19 {
20 public function __construct( $id )
21 {
22 $steps = array();
23 $steps[] = $this->packageThumbnailStep();
24 $steps[] = array( 'id' => 'cssfile',
25 'name' => ezpI18n::tr( 'kernel/package', 'CSS files' ),
26 'methods' => array( 'initialize' => 'initializeCSSFile',
27 'validate' => 'validateCSSFile',
28 'commit' => 'commitCSSFile' ),
29 'template' => 'cssfile.tpl' );
30 $steps[] = array( 'id' => 'imagefiles',
31 'name' => ezpI18n::tr( 'kernel/package', 'Image files' ),
32 'methods' => array( 'initialize' => 'initializeImageFiles',
33 'validate' => 'validateImageFiles',
34 'commit' => 'commitImageFiles' ),
35 'template' => 'imagefiles.tpl' );
36 $steps[] = $this->packageInformationStep();
37 $steps[] = $this->packageMaintainerStep();
38 $steps[] = $this->packageChangelogStep();
39 parent::__construct( $id, ezpI18n::tr( 'kernel/package', 'Site style' ), $steps );
40 }
41
42 function finalize( &$package, $http, &$persistentData )
43 {
44 $cleanupFiles = array();
45 $this->createPackage( $package, $http, $persistentData, $cleanupFiles, false );
46
47 $collections = array();
48
49 $siteCssfile = $persistentData['sitecssfile'];
50 $fileItem = array( 'file' => $siteCssfile['filename'],
51 'type' => 'file',
52 'role' => false,
53 'design' => false,
54 'path' => $siteCssfile['url'],
55 'collection' => 'default',
56 'file-type' => false,
57 'role-value' => false,
58 'variable-name' => 'sitecssfile' );
59
60 $package->appendFile( $fileItem['file'], $fileItem['type'], $fileItem['role'],
61 $fileItem['design'], $fileItem['path'], $fileItem['collection'],
62 null, null, true, null,
63 $fileItem['file-type'], $fileItem['role-value'], $fileItem['variable-name'] );
64 $cleanupFiles[] = $fileItem['path'];
65
66 $classesCssfile = $persistentData['classescssfile'];
67 $fileItem = array( 'file' => $classesCssfile['filename'],
68 'type' => 'file',
69 'role' => false,
70 'design' => false,
71 'path' => $classesCssfile['url'],
72 'collection' => 'default',
73 'file-type' => false,
74 'role-value' => false,
75 'variable-name' => 'classescssfile' );
76
77 $package->appendFile( $fileItem['file'], $fileItem['type'], $fileItem['role'],
78 $fileItem['design'], $fileItem['path'], $fileItem['collection'],
79 null, null, true, null,
80 $fileItem['file-type'], $fileItem['role-value'], $fileItem['variable-name'] );
81 $cleanupFiles[] = $fileItem['path'];
82
83 if ( !in_array( $fileItem['collection'], $collections ) )
84 $collections[] = $fileItem['collection'];
85
86 $imageFiles = $persistentData['imagefiles'];
87 foreach ( $imageFiles as $imageFile )
88 {
89 $fileItem = array( 'file' => $imageFile['filename'],
90 'type' => 'file',
91 'role' => false,
92 'design' => false,
93 'subdirectory' => 'images',
94 'path' => $imageFile['url'],
95 'collection' => 'default',
96 'file-type' => false,
97 'role-value' => false,
98 'variable-name' => 'imagefiles' );
99
100 $package->appendFile( $fileItem['file'], $fileItem['type'], $fileItem['role'],
101 $fileItem['design'], $fileItem['path'], $fileItem['collection'],
102 $fileItem['subdirectory'], null, true, null,
103 $fileItem['file-type'], $fileItem['role-value'], $fileItem['variable-name'] );
104 $cleanupFiles[] = $fileItem['path'];
105
106 if ( !in_array( $fileItem['collection'], $collections ) )
107 $collections[] = $fileItem['collection'];
108 }
109
110 foreach ( $collections as $collection )
111 {
112 $installItems = $package->installItemsList( 'ezfile', false, $collection, true );
113 if ( count( $installItems ) == 0 )
114 $package->appendInstall( 'ezfile', false, false, true,
115 false, false,
116 array( 'collection' => $collection ) );
117 $dependencyItems = $package->dependencyItems( 'provides',
118 array( 'type' => 'ezfile',
119 'name' => 'collection',
120 'value' => $collection ) );
121 if ( count( $dependencyItems ) == 0 )
122 $package->appendDependency( 'provides',
123 array( 'type' => 'ezfile',
124 'name' => 'collection',
125 'value' => $collection ) );
126 $installItems = $package->installItemsList( 'ezfile', false, $collection, false );
127 if ( count( $installItems ) == 0 )
128 $package->appendInstall( 'ezfile', false, false, false,
129 false, false,
130 array( 'collection' => $collection ) );
131 }
132
133 $package->setAttribute( 'is_active', true );
134 $package->store();
135
136 foreach ( $cleanupFiles as $cleanupFile )
137 {
138 unlink( $cleanupFile );
139 }
140 }
141
145 function packageInstallType( $package, &$persistentData )
146 {
147 return 'import';
148 }
149
153 function packageInitialState( $package, &$persistentData )
154 {
155 return 'stable';
156 }
157
161 function packageType( $package, &$persistentData )
162 {
163 return 'sitestyle';
164 }
165
166
167 function initializeCSSFile( $package, $http, $step, &$persistentData, $tpl )
168 {
169 }
170
174 function validateCSSFile( $package, $http, $currentStepID, &$stepMap, &$persistentData, &$errorList )
175 {
176 $hasSiteFile = eZHTTPFile::canFetch( 'PackageSiteCSSFile' );
177 $hasClassesFile = eZHTTPFile::canFetch( 'PackageClassesCSSFile' );
178
179 $result = true;
180 if ( !$hasSiteFile or !$hasClassesFile )
181 {
182 $errorList[] = array( 'field' => ezpI18n::tr( 'kernel/package', 'CSS file' ),
183 'description' => ezpI18n::tr( 'kernel/package', 'You must upload both CSS files' ) );
184 return false;
185 }
186
187 $siteFile = eZHTTPFile::fetch( 'PackageSiteCSSFile' );
188 $classesFile = eZHTTPFile::fetch( 'PackageClassesCSSFile' );
189 if ( !preg_match( "#\.css$#", strtolower( $siteFile->attribute( 'original_filename' ) ) ) or
190 !preg_match( "#\.css$#", strtolower( $classesFile->attribute( 'original_filename' ) ) ) )
191 {
192 $errorList[] = array( 'field' => ezpI18n::tr( 'kernel/package', 'CSS file' ),
193 'description' => ezpI18n::tr( 'kernel/package', 'File did not have a .css suffix, this is most likely not a CSS file' ) );
194 $result = false;
195 }
196 return $result;
197 }
198
199 function commitCSSFile( $package, $http, $step, &$persistentData, $tpl )
200 {
201 $siteFile = eZHTTPFile::fetch( 'PackageSiteCSSFile' );
202 $classesFile = eZHTTPFile::fetch( 'PackageClassesCSSFile' );
203 $siteMimeData = eZMimeType::findByFileContents( $siteFile->attribute( 'original_filename' ) );
204 $dir = eZSys::storageDirectory() . '/temp';
205 eZMimeType::changeDirectoryPath( $siteMimeData, $dir );
206 $siteFile->store( false, false, $siteMimeData );
207 $persistentData['sitecssfile'] = $siteMimeData;
208
209 $classesMimeData = eZMimeType::findByFileContents( $classesFile->attribute( 'original_filename' ) );
210 eZMimeType::changeDirectoryPath( $classesMimeData, $dir );
211 $classesFile->store( false, false, $classesMimeData );
212 $persistentData['classescssfile'] = $classesMimeData;
213 }
214
215 function initializeImageFiles( $package, $http, $step, &$persistentData, $tpl )
216 {
217 $persistentData['imagefiles'] = array();
218 }
219
223 function validateImageFiles( $package, $http, $currentStepID, &$stepMap, &$persistentData, &$errorList )
224 {
225 // If we don't have an image we continue as normal
226 if ( !eZHTTPFile::canFetch( 'PackageImageFile' ) )
227 return true;
228
229 if ( !self::httpFileIsImage( ezpI18n::tr( 'kernel/package', 'PackageImageFile' ), $errorList ) )
230 {
231 return false;
232 }
233
234 $file = eZHTTPFile::fetch( 'PackageImageFile' );
235
236 $result = true;
237 if ( $file )
238 {
239 $mimeData = eZMimeType::findByFileContents( $file->attribute( 'original_filename' ) );
240 $dir = eZSys::storageDirectory() . '/temp';
241 eZMimeType::changeDirectoryPath( $mimeData, $dir );
242 $file->store( false, false, $mimeData );
243 $persistentData['imagefiles'][] = $mimeData;
244 $result = false;
245 }
246 return $result;
247 }
248
249 function commitImageFiles( $package, $http, $step, &$persistentData, $tpl )
250 {
251 }
252
256 function generatePackageInformation( &$packageInformation, $package, $http, $step, &$persistentData )
257 {
258 $cssfile = $persistentData['sitecssfile'];
259 if ( $cssfile )
260 $cssfile = $persistentData['classescssfile'];
261
262 if ( $cssfile )
263 {
264 $packageInformation['name'] = $cssfile['basename'];
265 $packageInformation['summary'] = $cssfile['basename'] . ' site style';
266 $packageInformation['description'] = 'A site style called ' . $cssfile['basename'];
267 }
268 }
269 }
270
271 ?>
eZHTTPFile\canFetch
static canFetch( $httpName, $maxSize=false)
Definition: ezhttpfile.php:203
eZHTTPFile\fetch
static fetch( $http_name)
Definition: ezhttpfile.php:269
eZMimeType\changeDirectoryPath
static changeDirectoryPath(&$mimeInfo, $dirpath)
Definition: ezmimetype.php:155
eZMimeType\findByFileContents
static findByFileContents( $url, $returnDefault=true)
Definition: ezmimetype.php:308
eZPackageCreationHandler
The class eZPackageCreationHandler does.
Definition: ezpackagecreationhandler.php:19
eZPackageCreationHandler\packageInformationStep
packageInformationStep()
Definition: ezpackagecreationhandler.php:378
eZPackageCreationHandler\packageThumbnailStep
packageThumbnailStep()
Definition: ezpackagecreationhandler.php:424
eZPackageCreationHandler\packageChangelogStep
packageChangelogStep()
Definition: ezpackagecreationhandler.php:409
eZPackageCreationHandler\createPackage
createPackage(&$package, $http, &$persistentData, &$cleanupFiles, $storePackage=true)
Definition: ezpackagecreationhandler.php:493
eZPackageCreationHandler\packageMaintainerStep
packageMaintainerStep()
Definition: ezpackagecreationhandler.php:393
eZStylePackageCreator
The class eZStylePackageCreator does.
Definition: ezstylepackagecreator.php:19
eZStylePackageCreator\initializeImageFiles
initializeImageFiles( $package, $http, $step, &$persistentData, $tpl)
Definition: ezstylepackagecreator.php:215
eZStylePackageCreator\packageInitialState
packageInitialState( $package, &$persistentData)
Definition: ezstylepackagecreator.php:153
eZStylePackageCreator\packageType
packageType( $package, &$persistentData)
Definition: ezstylepackagecreator.php:161
eZStylePackageCreator\validateImageFiles
validateImageFiles( $package, $http, $currentStepID, &$stepMap, &$persistentData, &$errorList)
Definition: ezstylepackagecreator.php:223
eZStylePackageCreator\packageInstallType
packageInstallType( $package, &$persistentData)
Definition: ezstylepackagecreator.php:145
eZStylePackageCreator\generatePackageInformation
generatePackageInformation(&$packageInformation, $package, $http, $step, &$persistentData)
Definition: ezstylepackagecreator.php:256
eZStylePackageCreator\finalize
finalize(&$package, $http, &$persistentData)
Definition: ezstylepackagecreator.php:42
eZStylePackageCreator\commitCSSFile
commitCSSFile( $package, $http, $step, &$persistentData, $tpl)
Definition: ezstylepackagecreator.php:199
eZStylePackageCreator\commitImageFiles
commitImageFiles( $package, $http, $step, &$persistentData, $tpl)
Definition: ezstylepackagecreator.php:249
eZStylePackageCreator\validateCSSFile
validateCSSFile( $package, $http, $currentStepID, &$stepMap, &$persistentData, &$errorList)
Definition: ezstylepackagecreator.php:174
eZStylePackageCreator\initializeCSSFile
initializeCSSFile( $package, $http, $step, &$persistentData, $tpl)
Definition: ezstylepackagecreator.php:167
eZStylePackageCreator\__construct
__construct( $id)
Definition: ezstylepackagecreator.php:20
eZSys\storageDirectory
static storageDirectory()
Definition: ezsys.php:514
ezpI18n\tr
static tr( $context, $source, $comment=null, $arguments=null)
Definition: ezpi18n.php:86
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.