18 require_once SQ_INCLUDE_PATH.
'/asset.inc';
58 if (!$assetid)
return;
59 list($this->_imageid, $this->_varietyid) = explode(
':v', $assetid);
61 $image = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($this->_imageid);
62 if (is_null($image))
return;
65 $this->data_path = $image->data_path.
'/varieties';
66 $this->data_path_suffix = $image->data_path_suffix.
'/varieties';
67 $this->data_path_public = $image->data_path_public.
'/varieties';
70 if (!$this->_varietyid)
return;
74 foreach ($data as $attr_name => $attr_value) {
75 if (!isset($this->vars[$attr_name]))
continue;
76 $this->vars[$attr_name][
'value'] = ($this->vars[$attr_name][
'type'] ==
'serialise') ? unserialize($attr_value) : $attr_value;
81 $this->short_name = $this->
_getName(
'short_name');
82 $this->status = $image->status;
83 $this->version =
'0.1';
103 if (trim($this->
attr(
'name')) !=
'') {
104 trigger_localised_error(
'CORE0116', E_USER_WARNING);
106 }
else if (trim($value) ==
'') {
107 trigger_localised_error(
'CORE0120', E_USER_WARNING);
110 require_once SQ_INCLUDE_PATH.
'/general_occasional.inc';
111 list($value) = make_valid_web_paths(Array(trim($value)));
117 if ((
int) $value < 0) {
118 trigger_localised_error(
'CORE0101', E_USER_WARNING, $name, $this->name, $this->
id);
121 if ((
int) $value == 0 && ($this->
attr(
'constrain') ==
'none' || ($this->
attr(
'constrain') == $name && $this->
attr(
'variety_type') ==
'resize'))) {
122 trigger_localised_error(
'CORE0102', E_USER_WARNING, $name, $this->name, $this->
id);
126 if ($this->
attr(
'constrain') ==
'dimension') {
135 return parent::setAttrValue($name, $value);
173 if (!$this->
id)
return TRUE;
174 if (empty($this->_tmp[
'vars_set']))
return TRUE;
176 if (!$GLOBALS[
'SQ_REVERT_TO_SYSTEM_VERSION'] && !$this->
writeAccess(
'attributes')) {
177 trigger_localised_error(
'CORE0121', E_USER_WARNING, $this->name, $this->
id);
181 if ($this->
attr(
'variety_type') ==
'resize' && $this->
attr(
'constrain') !=
'none') {
182 if ((
int) $this->
attr($this->
attr(
'constrain')) == 0) {
183 trigger_localised_error(
'CORE0096', E_USER_WARNING, $this->name, $this->
id, $this->
attr(
'constrain'));
188 $image = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($this->_imageid);
189 return (
bool) $image->saveVariety($this);
211 $this->short_name = $this->
_getName(
'short_name');
241 return $this->
attr(
'name');
256 $image = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($this->_imageid);
257 if (is_null($image))
return FALSE;
259 if ($this->
attr(
'variety_type') ==
'resize') {
261 if ($file_versioning) {
262 require_once SQ_FUDGE_PATH.
'/general/file_system.inc';
263 require_once SQ_FUDGE_PATH.
'/image/image_manip.inc';
264 $fv = $GLOBALS[
'SQ_SYSTEM']->getFileVersioning();
267 if (!is_dir($this->data_path) && !create_directory($this->data_path)) {
271 $source_image_info = $image->getExistingFile();
272 if (empty($source_image_info))
return TRUE;
274 $ext = get_file_type($image->name);
276 $s_file = $source_image_info[
'path'];
278 $d_old_filename = $this->
attr(
'filename');
279 $d_new_filename = $this->name.
'.'.$ext;
280 $d_old_file = $this->data_path.
'/'.$d_old_filename;
281 $d_new_file = $this->data_path.
'/'.$d_new_filename;
282 $d_width = (int) $this->
attr(
'width');
283 $d_height = (int) $this->
attr(
'height');
284 $d_dimension = (int) $this->
attr(
'dimension');
287 switch ($this->
attr(
'constrain')) {
290 trigger_localised_error(
'CORE0007', E_USER_WARNING);
294 $d_height = round((
int) $source_image_info[
'height'] * ($d_width / (
int) $source_image_info[
'width']));
298 if ($d_height <= 0) {
299 trigger_localised_error(
'CORE0006', E_USER_WARNING);
302 $d_width = round((
int) $source_image_info[
'width'] * ($d_height / (
int) $source_image_info[
'height']));
306 $old_width = (int) $source_image_info[
'width'];
307 $old_height = (int) $source_image_info[
'height'];
309 if ($old_width > $old_height) {
310 $proportion = $d_dimension / $old_width;
312 $proportion = $d_dimension / $old_height;
314 $d_width = round($old_width * $proportion);
315 $d_height = round($old_height * $proportion);
319 if ($d_width <= 0 || $d_height <= 0) {
320 trigger_localised_error(
'CORE0005', E_USER_WARNING);
325 if ($d_old_filename != $d_new_filename) {
329 if ($file_versioning) {
331 $up_to_date = $fv->upToDate($d_new_file);
332 if ($up_to_date & FUDGE_FV_OLD_VERSION) {
333 if (!$fv->checkOut($this->data_path_suffix.
'/'.$d_new_filename, $this->data_path)) {
334 trigger_localised_error(
'COR0103', E_USER_WARNING);
342 require_once(SQ_FUDGE_PATH.
'/image/image_manip.inc');
347 if ($file_versioning) {
348 $up_to_date = $fv->upToDate($d_new_file);
351 if ($up_to_date & FUDGE_FV_NOT_CHECKED_OUT) {
352 if (!$fv->add($this->data_path_suffix, $d_new_file,
'')) {
356 if (!$fv->checkOut($this->data_path_suffix.
'/'.$d_new_filename, $this->data_path)) {
357 trigger_localised_error(
'COR0103', E_USER_WARNING);
361 }
else if ($up_to_date & FUDGE_FV_MODIFIED) {
362 if (!$fv->commit($d_new_file,
'', FALSE))
return FALSE;
368 if ($d_old_filename != $d_new_filename) {
369 if (!$this->
setAttrValue(
'filename', $d_new_filename)) {
393 require_once SQ_FUDGE_PATH.
'/general/file_system.inc';
395 if (!is_dir($this->data_path))
return TRUE;
397 $d_filename = $this->
attr(
'filename');
398 $d_file = $this->data_path.
'/'.$d_filename;
400 if (empty($d_filename))
return TRUE;
405 $fv = $GLOBALS[
'SQ_SYSTEM']->getFileVersioning();
406 $up_to_date = $fv->upToDate($d_file);
409 if (!$updated)
return FALSE;
412 if (($up_to_date & FUDGE_FV_NOT_CHECKED_OUT)) {
413 if (file_exists($d_file)) {
414 if (!unlink($d_file))
return FALSE;
418 if (!($fv->remove($d_file,
'') & FUDGE_FV_OK)) {
419 trigger_localised_error(
'CORE0041', E_USER_WARNING, $d_filename);
441 require_once SQ_FUDGE_PATH.
'/general/file_system.inc';
443 $fv = $GLOBALS[
'SQ_SYSTEM']->getFileVersioning();
445 $filename = $this->
attr(
'filename');
446 if (!$filename)
return TRUE;
447 $unrestricted = $this->data_path_public.
'/'.$filename;
453 if (!create_directory($this->data_path_public)) {
458 if ($fv->upToDate($unrestricted) & (FUDGE_FV_NOT_CHECKED_OUT | FUDGE_FV_OLD_VERSION)) {
459 if (!$fv->checkOut($this->data_path_suffix.
'/'.$filename, $this->data_path_public)) {
460 trigger_localised_error(
'COR0103', E_USER_WARNING);
466 if (is_file($unrestricted)) {
467 if (!$fv->clearOut($unrestricted) & FUDGE_FV_OK) {
468 trigger_localised_error(
'COR0104', E_USER_WARNING);
488 $filename = $this->
attr(
'filename');
489 if (!$filename)
return TRUE;
491 $unrestricted = $this->data_path_public.
'/'.$filename;
492 if (is_file($unrestricted)) {
493 $fv = $GLOBALS[
'SQ_SYSTEM']->getFileVersioning();
494 if (!$fv->clearOut($unrestricted) & FUDGE_FV_OK) {
495 trigger_localised_error(
'COR0104', E_USER_WARNING);
514 require_once SQ_FUDGE_PATH.
'/general/file_system.inc';
516 $filename = $this->
attr(
'filename');
517 if (!$filename)
return TRUE;
519 $unrestricted = $this->data_path_public.
'/'.$filename;
522 if (!create_directory($this->data_path_public)) {
526 $fv = $GLOBALS[
'SQ_SYSTEM']->getFileVersioning();
528 if ($fv->upToDate($unrestricted) & (FUDGE_FV_NOT_CHECKED_OUT | FUDGE_FV_OLD_VERSION)) {
529 if (!$fv->checkOut($this->data_path_suffix.
'/'.$filename, $this->data_path_public)) {
530 trigger_localised_error(
'COR0103', E_USER_WARNING);
550 $image = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($this->_imageid);
551 if (!empty($image)) {
552 $public = $image->usePublicPath();
554 if (!$public)
return parent::updateLookups();
556 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
558 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
560 unset($this->_tmp[
'lookups']);
561 unset($this->_tmp[
'url']);
562 unset($this->_tmp[
'href']);
566 $bind_vars = Array(
'assetid' => $this->
id);
569 throw new Exception(
'Unable to delete lookups of asset "'.$this->name.
'" (#'.$this->id.
') due to database error: '.$e->getMessage());
572 $filename = $this->
attr(
'filename');
576 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
577 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
581 $web_path = str_replace(sq_web_path(
'root_url').
'/',
'', $this->
getWebDataPath()).
'/'.$filename;
585 $save_urls = Array();
586 $root_urls = explode(
"\n", trim(SQ_CONF_SYSTEM_ROOT_URLS));
588 if (!SQ_CONF_STATIC_ROOT_URL ==
'') {
589 if (!$GLOBALS[
'SQ_SYSTEM']->am->assetInTrash($this->id, TRUE)){
591 $web_path = str_replace(sq_web_path(
'data').
'/',
'', $web_path);
592 $save_urls[SQ_CONF_STATIC_ROOT_URL] = Array(
'http' => SQ_CONF_STATIC_ROOT_HTTP,
'https' => SQ_CONF_STATIC_ROOT_HTTPS);
596 $site_parents = $GLOBALS[
'SQ_SYSTEM']->am->getParents($this->
id,
'site', FALSE);
597 foreach ($site_parents as $assetid => $type_code) {
598 $site = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid, $type_code);
599 if (is_null($site))
continue;
600 $urls = $site->getSiteURLS();
602 foreach ($urls as $urlid => $data) {
606 foreach ($root_urls as $tmp_url) {
607 if (substr($data[
'url'], 0, strlen($tmp_url)) == $tmp_url) {
608 $root_url = $tmp_url;
613 if (empty($root_url))
continue;
615 if (isset($save_urls[$root_url])) {
616 if (empty($save_urls[$root_url][
'http'])) {
617 $save_urls[$root_url][
'http'] = $data[
'http'];
619 if (empty($save_urls[$root_url][
'https'])) {
620 $save_urls[$root_url][
'https'] = $data[
'https'];
623 $save_urls[$root_url] = Array(
'http' => $data[
'http'],
'https' => $data[
'https']);
632 foreach ($save_urls as $url => $url_data) {
636 'url' => $url.
'/'.$web_path,
637 'assetid' => $this->id,
638 'http' => ($this->force_secure ===
'1') ?
'0' : $url_data[
'http'],
639 'https' => ($this->force_secure ===
'-') ?
'0' : $url_data[
'https'],
645 throw new Exception(
'Unable to delete lookups of asset "'.$this->name.
'" (#'.$this->id.
') due to database error: '.$e->getMessage());
654 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
655 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
660 if (empty($save_urls)){
681 $image = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($this->_imageid);
682 if (is_null($image))
return FALSE;
684 return $image->getWebDataPath().
'/varieties';
697 $filename = $this->
attr(
'filename');
699 return Array($filename);
717 if (!isset($_REQUEST[
'asset_ei_screen'])) {
718 return parent::paintBackend($o);
720 switch ($_REQUEST[
'asset_ei_screen']) {
722 $image = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($this->_imageid);
723 if (is_null($image)) exit();
725 include_once SQ_FUDGE_PATH.
'/var_serialise/var_serialise.inc';
727 $filename = $this->data_path.
'/'.$this->
attr(
'filename');
728 $size = getimagesize($filename);
731 $output[
'alt'] = $image->attr(
'alt');
732 $output[
'width'] = $size[0];
733 $output[
'height'] = $size[1];
734 $output[
'name'] = $this->name;
735 echo var_serialise($output);
738 return parent::paintBackend($o);
757 if (SQ_IN_LIMBO && !(isset($_REQUEST[
'a']) && $_REQUEST[
'a'] == $this->
id)) {
758 return parent::printFrontend();
762 $GLOBALS[
'SQ_SYSTEM']->paintLogin(translate(
'login'), translate(
'cannot_access_asset', $this->name));
766 $GLOBALS[
'SQ_SYSTEM']->setGlobalDefine(
'SQ_REPLACE_MYSOURCE_LEVEL_KEYWORDS', FALSE);
768 $image = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($this->_imageid);
769 if (is_null($image))
return FALSE;
771 if (($this->status & SQ_SC_STATUS_SAFE_EDITING) && ($GLOBALS[
'SQ_SYSTEM']->user instanceof
Public_User)) {
772 if (is_file($image->data_path.
'/varieties/sq_system_version_no')) {
773 include ($image->data_path.
'/varieties/sq_system_version_no');
774 $file_version = isset($versions[$this->
attr(
'filename')]) ? $versions[$this->
attr(
'filename')] : NULL;
775 $fv = $GLOBALS[
'SQ_SYSTEM']->getFileVersioning();
776 $rep_file = $this->data_path_suffix.
'/'.$this->
attr(
'filename');
777 $info = $fv->_checkOutCheck($rep_file, $file_version);
779 $filename = $info[
'filename'];
780 $ext = get_file_type($filename);
781 $file = $info[
'source_file'];
784 $ext = get_file_type($image->name);
785 $filename = $this->name.
'.'.$ext;
786 $file = $this->data_path.
'/'.$filename;
789 if (isset($file) && file_exists($file)) {
790 require_once SQ_FUDGE_PATH.
'/standards_lists/mime_types.inc';
791 require_once SQ_FUDGE_PATH.
'/general/file_system.inc';
792 $type = (empty($standards_lists_mime_types[$ext])) ?
'text/plain' : $standards_lists_mime_types[$ext];
795 $ssl_connection = FALSE;
796 $url_info = parse_url(current_url());
797 $protocol = (isset($url_info[
'scheme'])) ? $url_info[
'scheme'] : NULL;
798 if (!is_null($protocol) && $protocol ==
'https') {
799 $ssl_connection = TRUE;
802 $cm = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'cache_manager');
803 $using_ie6 = strpos($_SERVER[
'HTTP_USER_AGENT'],
'MSIE 6.') !== FALSE;
806 if (basename($_SERVER[
'PHP_SELF']) != SQ_CONF_NOCACHE_SUFFIX && SQ_CONF_SEND_CACHEABLE_HEADER && ($GLOBALS[
'SQ_SYSTEM']->user instanceof Public_User) && empty($_POST) && $cm->cacheableHeadersEnabledForCurrentProtocol() && $this->status >= SQ_STATUS_LIVE && $this->
readAccess()) {
807 header(
'Cache-Control: '.$cm->cacheControlLevel());
808 header(
'Pragma: cache');
809 header(
'Expires: '.gmdate(
'D, d M Y H:i:s', (time()+86400)).
' GMT');
810 header(
'Last-Modified: '.gmdate(
'D, d M Y H:i:s', filemtime($file)).
' GMT');
811 }
else if (!$using_ie6 || !$ssl_connection) {
812 header(
'Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
813 header(
'Pragma: no-cache');
814 header(
'Expires: '.gmdate(
'D, d M Y H:i:s', time()-3600).
' GMT');
820 header(
'Cache-Control: max-age=0, must-revalidate');
821 header(
'Pragma: private');
822 header(
'Expires: '.gmdate(
'D, d M Y H:i:s', time()-3600).
' GMT');
825 header(
'Content-Type: '.$type);
826 header(
'Content-Disposition: inline; filename='.$filename.
';');
827 header(
'Content-Length: '.filesize($file));
851 $filename = $this->
attr(
'filename');
852 if (!$filename)
return;
853 $size = getimagesize($this->data_path.
'/'.$filename);
855 $tag =
'<img src="'.$this->getURL().
'" '.$size[3].
' alt="'.$alt.
'" title="'.$title.
'" />';
856 if ($return)
return $tag;
875 $full_keyword = $keyword;
876 $keyword = parse_keyword($keyword, $modifiers);
877 $contextid = extract_context_modifier($modifiers);
879 if ($contextid !== NULL) {
884 if ((
int)$contextid !== $GLOBALS[
'SQ_SYSTEM']->getContextId()) {
885 $GLOBALS[
'SQ_SYSTEM']->changeContext($contextid);
886 $contexted_asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($this->
id);
889 $replacement = $contexted_asset->getKeywordReplacement($keyword);
892 apply_keyword_modifiers($replacement, $modifiers, Array(
'assetid' => $contexted_asset->id));
894 unset($contexted_asset);
895 $GLOBALS[
'SQ_SYSTEM']->restoreContext();
905 $replacement = parent::getKeywordReplacement($keyword);
906 if (empty($replacement)) {
908 case 'asset_name_linked' :
909 $replacement =
'<a href="'.$this->getUrl().
'">'.$this->name.
'</a>';
911 case 'asset_contents' :
912 $replacement = $this->
printImageTag($this->name, $this->name, TRUE);
920 if (count($modifiers) > 0) {
921 apply_keyword_modifiers($replacement, $modifiers, Array(
'assetid' => $this->
id));
943 if (!$this->
id)
return TRUE;
945 $image = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($this->_imageid);
946 if (is_null($image))
return FALSE;
948 return $image->readAccess($assetids);
967 if (!$this->
id)
return TRUE;
969 $image = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($this->_imageid);
970 if (is_null($image))
return FALSE;
972 return $image->writeAccess($lock_type, $assetids);
991 if (!$this->
id)
return TRUE;
993 $image = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($this->_imageid);
994 if (is_null($image))
return FALSE;
996 return $image->adminAccess($lock_type, $assetids);
1015 $image = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($this->_imageid);
1016 if (is_null($image))
return FALSE;
1018 return $image->liveEditAccess($lock_type);
1040 $image = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($this->_imageid);
1041 if (is_null($image))
return FALSE;
1043 return $image->checkAccess($perm, $lock_type, $assetids);
1061 $image = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($this->_imageid);
1062 if (is_null($image))
return FALSE;
1064 return $image->_checkPermissionAccess($perm, $assetids);