18 require_once SQ_CORE_PACKAGE_PATH.
'/designs/design/design.inc';
45 parent::__construct($assetid);
48 $this->_tmp[
'updated_cache'] = FALSE;
59 $this->_tmp[
'updated_cache'] = FALSE;
76 if (!parent::_preCreateCheck($link))
return FALSE;
78 $new_name = strtolower(trim($this->
attr(
'id_name')));
81 $new_name = str_replace(
'&', SQ_CONF_WEB_PATH_SEPARATOR.
'and'.SQ_CONF_WEB_PATH_SEPARATOR, $new_name);
84 $new_name = preg_replace(
'/\\s+/', SQ_CONF_WEB_PATH_SEPARATOR, $new_name);
87 $new_name = preg_replace(
'/[^a-zA-Z0-9\-$_@.!*~(),]/',
'', $new_name);
90 if (substr($new_name, -4) !=
'.css') {
113 if (!parent::_createAdditional($link))
return FALSE;
116 $initial_path = strtolower($this->
attr(
'id_name'));
117 require_once SQ_INCLUDE_PATH.
'/general_occasional.inc';
118 $valid_paths = make_valid_web_paths(Array($initial_path));
119 $good_paths = $GLOBALS[
'SQ_SYSTEM']->am->webPathsInUse($link[
'asset'], $valid_paths, $this->
id, TRUE);
138 SQ_LINK_TYPE_1 => Array(),
139 SQ_LINK_TYPE_2 => Array(
140 'design_css_customisation' => Array(
142 'exclusive' => FALSE,
146 'exclusive' => FALSE,
149 SQ_LINK_TYPE_3 => Array(
150 'design_area' => Array(
152 'exclusive' => FALSE,
156 'exclusive' => FALSE,
159 SQ_LINK_NOTICE => Array(),
182 public function createLink(
Asset $minor, $link_type, $value=
'', $sort_order=NULL, $dependant=
'0', $exclusive=
'0')
184 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
185 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
187 $linkid = parent::createLink($minor, $link_type, $value, $sort_order, $dependant, $exclusive);
189 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
190 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
195 if ($minor instanceof
File) {
197 $am = $GLOBALS[
'SQ_SYSTEM']->am;
199 $customisation_links = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($this->
id, SQ_LINK_TYPE_2,
'design_css_customisation', TRUE,
'major',
'customisation');
200 foreach ($customisation_links as $link) {
201 $customisation = $am->getAsset($link[
'minorid'], $link[
'minor_type_code']);
202 if (is_null($customisation))
continue;
204 $file_link_ids = Array();
205 $file_links = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($customisation->id, SQ_LINK_TYPE_2,
'file', FALSE);
206 foreach ($file_links as $link) {
207 $file_link_ids[] = $link[
'minorid'];
209 $file_link_info = $am->getAssetInfo(array_unique($file_link_ids));
213 foreach ($file_link_info as $info) {
214 if ($info[
'name'] == $minor->name) {
215 $insert_link = FALSE;
220 if (!$customisation->createLink($minor, SQ_LINK_TYPE_3,
'', NULL, 1)) {
221 trigger_localised_error(
'CORE0162', E_USER_WARNING);
222 $am->forgetAsset($customisation);
223 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
224 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
229 $am->forgetAsset($customisation);
235 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
236 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
253 $delete_link = $GLOBALS[
'SQ_SYSTEM']->am->getLinkById($linkid, $this->
id);
254 if (empty($delete_link)) {
255 trigger_localised_error(
'CORE0155', E_USER_WARNING, $linkid);
259 $am = $GLOBALS[
'SQ_SYSTEM']->am;
260 $minor = $am->getAsset($delete_link[
'minorid'], $delete_link[
'minor_type_code']);
262 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
263 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
266 if ($minor instanceof
File) {
268 $customisation_links = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($this->
id, SQ_LINK_TYPE_2,
'design_css_customisation', TRUE,
'major',
'customisation');
269 foreach ($customisation_links as $link) {
270 $customisation = $am->getAsset($link[
'minorid'], $link[
'minor_type_code']);
271 if (is_null($customisation))
continue;
273 $file_link_ids = Array();
274 $file_links = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($customisation->id, SQ_LINK_TYPE_3,
'file', FALSE);
276 foreach ($file_links as $link) {
277 if ($link[
'minorid'] == $delete_link[
'minorid']) {
279 if (!$customisation->deleteLink($link[
'linkid'])) {
280 trigger_localised_error(
'CORE0165', E_USER_WARNING);
281 $am->forgetAsset($customisation);
282 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
283 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
289 $am->forgetAsset($customisation);
294 if (!parent::deleteLink($linkid)) {
295 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
296 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
300 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
301 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
322 $delete_link = $GLOBALS[
'SQ_SYSTEM']->am->getLinkById($linkid, $this->
id);
323 if (empty($delete_link)) {
324 trigger_localised_error(
'CORE0155', E_USER_WARNING, $linkid);
328 $am = $GLOBALS[
'SQ_SYSTEM']->am;
329 $minor = $am->getAsset($delete_link[
'minorid'], $delete_link[
'minor_type_code']);
331 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
332 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
334 if (!parent::deleteLink($linkid)) {
335 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
336 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
340 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
341 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
358 $GLOBALS[
'SQ_SYSTEM']->paintLogin(translate(
'login'), translate(
'cannot_access_asset', $this->name));
395 Developed by Squiz - http://www.squiz.net
396 Squiz, Squiz Matrix, MySource, MySource Matrix and Squiz.net are registered Trademarks of Squiz Pty Ltd
397 Page generated: <?php echo date(\'d F Y H:i:s\')."\n"; ?>
404 parent::printVar($var, $args);
419 return '<?php header("Content-type: text/css"); ?>
420 '.parent::_getDesignFileHeader();
436 $public_userid = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAssetid(
'public_user');
439 $cache = $this->
attr(
'cache_css');
440 $strip = $this->
attr(
'strip_whitespace');
442 $status = $this->status;
445 if (!parent::processBackend($o, $link))
return FALSE;
448 $status_changed = ($status != $this->status) && (($status == SQ_STATUS_LIVE) || ($this->status == SQ_STATUS_LIVE));
449 $read_access_changed = ($read_access != $this->
_checkPermissionAccess(SQ_PERMISSION_READ, Array($public_userid)));
451 $regen = $this->
attr(
'cache_css') && (($cache != $this->
attr(
'cache_css')) || ($strip != $this->
attr(
'strip_whitespace')) || $status_changed
452 || $read_access_changed);
457 if ($regen && !$this->_tmp[
'updated_cache']) {
459 $am = $GLOBALS[
'SQ_SYSTEM']->am;
460 $customisation_links = $am->getLinks($this->
id, SQ_LINK_TYPE_2,
'design_css_customisation', TRUE,
'major',
'customisation');
462 foreach ($customisation_links as $link) {
463 $customisation = $am->getAsset($link[
'minorid'], $link[
'minor_type_code']);
464 if (is_null($customisation))
continue;
465 $customisation->_updateCacheFile();
485 $success &= parent::generateDesignFile($do_customisations);
487 if ($this->
attr(
'cache_css')) {
502 $customisation_links = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($this->
id, SQ_LINK_TYPE_2,
'design_css_customisation', TRUE,
'major',
'customisation');
503 $am = $GLOBALS[
'SQ_SYSTEM']->am;
504 foreach ($customisation_links as $link) {
505 $customisation = $am->getAsset($link[
'minorid'], $link[
'minor_type_code']);
506 if (is_null($customisation))
continue;
507 if ($acquired = $GLOBALS[
'SQ_SYSTEM']->am->acquireLock($customisation->id,
'all')) {
508 $customisation->updateFromParent($this);
509 if ($acquired != 2) {
510 $GLOBALS[
'SQ_SYSTEM']->am->releaseLock($customisation->id,
'all');
526 $am = $GLOBALS[
'SQ_SYSTEM']->am;
530 $old_level = error_reporting();
534 $file_contents = ob_get_contents();
536 error_reporting($old_level);
538 $cache_link = $am->getLink($this->
id, SQ_LINK_TYPE_3,
'file', FALSE,
'css_cache');
539 if (empty($cache_link)) {
542 $cache_asset = $am->getAsset($cache_link[
'minorid']);
544 if ($cache_asset == NULL)
return FALSE;
547 if ($this->
attr(
'strip_whitespace')) {
548 $file_contents = preg_replace(
'/\s+/is',
' ', $file_contents);
550 $existing = $cache_asset->getExistingFile();
551 string_to_file($file_contents, $existing[
'path']);
553 $fv = $GLOBALS[
'SQ_SYSTEM']->getFileVersioning();
554 $file_status = $fv->upToDate($cache_asset->data_path.
'/'.$cache_asset->_getName());
555 if (FUDGE_FV_MODIFIED & $file_status) {
556 if (!$fv->commit($cache_asset->data_path.
'/'.$cache_asset->_getName())) {
557 trigger_localised_error(
'CORE0034', E_USER_WARNING);
561 $this->_tmp[
'updated_cache'] = TRUE;
562 return $cache_asset->_updated();
575 $am = $GLOBALS[
'SQ_SYSTEM']->am;
576 $cache_link = $am->getLink($this->
id, SQ_LINK_TYPE_3,
'file',
true,
'css_cache');
577 if (empty($cache_link))
return 0;
578 return $cache_link[
'minorid'];
595 if (substr($filename, -4) !=
'.css') {
598 if (!is_dir($this->data_path)) {
599 create_directory($this->data_path);
601 if (!string_to_file(
'', $this->data_path.
'/'.$filename)) {
605 $tmp_file = $this->data_path.
'/'.$filename;
607 $import_link = Array(
'asset' => &$this,
'link_type' => SQ_LINK_TYPE_3,
'value' =>
'css_cache',
'sort_order' => 1,
'is_dependant' => 1);
608 $temp_info = Array(
'name' => $filename,
'tmp_name' => $tmp_file,
'non_uploaded_file' => TRUE);
610 require_once SQ_CORE_PACKAGE_PATH.
'/files/file/file.inc';
611 $new_file =
new File();
612 $new_file->_tmp[
'uploading_file'] = TRUE;
613 $new_file->setAttrValue(
'name', $filename);
614 $new_file->setAttrValue(
'allow_unrestricted', FALSE);
616 if (!$new_file->create($import_link, $temp_info)) {
617 trigger_localised_error(
'CORE0058', E_USER_WARNING, $filename);
621 $new_file->saveWebPaths(Array());
640 return @$GLOBALS[
'SQ_SYSTEM']->am->getLink($this->
id, SQ_LINK_TYPE_3,
'design_area', FALSE, $id_name);
642 return @$GLOBALS[
'SQ_SYSTEM']->am->getLinks($this->
id, SQ_LINK_TYPE_3,
'design_area', FALSE);
662 $file_link_ids = Array();
663 $file_links = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($this->
id, SQ_LINK_TYPE_2 | SQ_LINK_TYPE_3,
'file', FALSE);
665 foreach ($file_links as $link) {
666 $file_link_ids[] = $link[
'minorid'];
669 $file_link_info = $GLOBALS[
'SQ_SYSTEM']->am->getAssetInfo(array_unique($file_link_ids));
670 $file_link_urls = $GLOBALS[
'SQ_SYSTEM']->am->getAssetURL(array_unique($file_link_ids));
672 $system_root_url = sq_web_path(
'root_url');
673 foreach ($file_link_info as $minorid => $file_info) {
674 $file_url = $file_link_urls[$minorid];
675 if ($file_url ==
'') {
676 $file_url = $system_root_url.
'/?a='.$minorid;
677 }
else if ($this->
attr(
'static_url_versioning')){
678 $served_by_apache = strpos($file_url,
'/__data/') !== FALSE || (SQ_CONF_STATIC_ROOT_URL && strpos($file_url, SQ_CONF_STATIC_ROOT_URL.
'/') !== FALSE);
679 if ($served_by_apache) $file_url .=
'?v='.$file_info[
'version'];
681 $FILE_URLS[$file_info[
'name']] = $file_url;
684 $DATA_PATH = sq_web_path(
'data');
685 $LIB_PATH = sq_web_path(
'lib');
688 if (SQ_ROLLBACK_VIEW) {
690 $fv = $GLOBALS[
'SQ_SYSTEM']->getFileVersioning();
691 $rep_file = $this->data_path_suffix.
'/design_file.php';
692 $then = iso8601_ts($_SESSION[
'sq_rollback_view'][
'rollback_time']);
693 $info = $fv->_checkOutCheck($rep_file, NULL, $then);
694 $file_path = $info[
'source_file'];
696 $file_path = $this->data_path.
'/design_file.php';
700 if (!file_exists($file_path)) {
702 $parents = $GLOBALS[
'SQ_SYSTEM']->am->getParents($this->
id,
'design_css', FALSE);
703 foreach ($parents as $id => $type) {
704 $parent = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($id);
706 $file_path = $parent->data_path.
'/design_file.php';
707 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($parent);
708 if (file_exists($file_path)) {
716 if (file_exists($file_path)) {
719 trigger_localised_error(
'CORE0259', E_USER_WARNING, $ASSET->name);
733 if (!parent::saveAttributes()) {
753 if (empty($cache_id)) {
754 $parents = $GLOBALS[
'SQ_SYSTEM']->am->getParents($this->
id);
755 if (empty($parents))
return;
757 $cache_id = $cache_file->id;
760 $cache_url = $GLOBALS[
'SQ_SYSTEM']->am->getAssetURL($cache_id);
761 if (empty($cache_url) == $enabled) {
763 $cache_file = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($cache_id);
764 $paths = $enabled ? Array($cache_file->name) : Array();
765 $cache_file->saveWebPaths($paths);
766 $cache_file->setAttrValue(
'allow_unrestricted', $enabled);
767 $cache_file->saveAttributes();