18 require_once SQ_INCLUDE_PATH.
'/asset_edit/asset_edit_fns.inc';
38 public $tag_name =
'MySource';
47 $this->static_screens[
'details'][
'lock_type'] =
'parsing';
48 parent::__construct();
65 echo $asset->
attr(
'id_name');
82 $file_contents = str_replace(Array(
"\r\n",
"\r"),
"\n", $file_contents);
85 $e =
'|mysource_files\/([a-zA-Z0-9\._\-]+)|i';
86 $file_contents = preg_replace($e,
'<'.$this->tag_name.
'_PRINT id_name=\'__global__\' var=\'file_path\' filename=\'\\1\' />', $file_contents);
89 $e =
'|mysource_css\/([a-zA-Z0-9\._\-]+)|i';
90 $file_contents = preg_replace($e,
'<'.$this->tag_name.
'_PRINT id_name=\'__global__\' var=\'css_path\' filename=\'\\1\' />', $file_contents);
93 $e =
'/(<link[^>]*href=")\\.\\//i';
94 $file_contents = preg_replace($e,
'\\1', $file_contents);
97 $file_contents = preg_replace(
'/<\?(?!xml)(.*)(?=\?>)\?>/ims',
'<?$1?>', $file_contents);
98 $file_contents = preg_replace(
'|<\?(?=xml)(.+?)(?=\?>)\?>|',
'<?php echo "<"."?"; ?>\\1<?php echo "?".">"; ?>', $file_contents);
102 $file_contents = preg_replace(
'/<'.$this->tag_name.
'/i',
'<'.$this->tag_name, $file_contents);
103 $file_contents = preg_replace(
'/<\\/'.$this->tag_name.
'/i',
'</'.$this->tag_name, $file_contents);
130 $start_pos = $cur_pos;
134 $is_nested = ($nest_level > 0);
136 while ($next_tag = $this->
_tagToParse($file_contents, $cur_pos)) {
140 'contents' => substr($file_contents, $start_pos, $cur_pos - $start_pos),
143 if ($next_tag ==
'terminate') {
161 if ($tag[
'self_terminating']) {
162 $tag[
'contents'] = Array();
166 $this_nest_level = $nest_level;
171 if (is_null($tag[
'contents']))
return NULL;
175 if ($this_nest_level == $nest_level) {
180 $die_str = $this->tag_name;
181 $die_str .= (empty($tag[
'operation'])) ?
'' :
'_'.$tag[
'operation'];
183 foreach ($tag[
'attributes'] as $name => $value) {
184 $die_str .=
' '.$name.
'="'.$value.
'"';
187 trigger_localised_error(
'CORE0213', E_USER_WARNING, $this->tag_name, $die_str);
199 $start_pos = $cur_pos;
209 'contents' => substr ($file_contents, $cur_pos),
233 $next_open_pos = strpos($file_contents,
'<'.$this->tag_name, $cur_pos);
234 $next_open_tag = ($next_open_pos !== FALSE);
235 $next_terminate_pos = strpos($file_contents,
'</'.$this->tag_name, $cur_pos);
238 if ($next_terminate_pos !== FALSE) {
242 if (!$next_open_tag || ($next_open_tag && ($next_terminate_pos < $next_open_pos))) {
243 $cur_pos = $next_terminate_pos;
249 if ($next_open_tag) {
250 $cur_pos = $next_open_pos;
273 $cur_pos += strlen(
'<'.$this->tag_name);
276 $escape_slash = FALSE;
278 $currently_getting =
'';
283 $trans = array_flip(get_html_translation_table(HTML_ENTITIES));
285 $tag = Array(
'_type' =>
'TAG',
'attributes' => Array());
288 if ($file_contents{$cur_pos} ==
'_') {
290 $tag[
'operation'] =
'';
293 while ($file_contents{$cur_pos} !=
'>' && !$this->
_isWhitespace($file_contents{$cur_pos})) {
294 $tag[
'operation'] .= $file_contents{$cur_pos};
299 $tag[
'operation'] = strtolower($tag[
'operation']);
303 while ($file_contents{$cur_pos} !=
'>' || $in_quote) {
305 $escape_slash = (!$in_quote && $file_contents{$cur_pos} ==
'/');
306 if (!$escape_slash) {
310 if (!$currently_getting && !$this->
_isWhitespace($file_contents{$cur_pos})) {
311 $currently_getting =
'name';
315 if ($currently_getting ==
'name') {
317 if ($file_contents{$cur_pos} ==
'=') {
318 $currently_getting =
'value';
323 $currently_getting =
'';
327 $current_name .= $file_contents{$cur_pos};
330 }
else if ($currently_getting ==
'value') {
334 $is_quote = ($file_contents{$cur_pos} ==
'\'' || $file_contents{$cur_pos} ==
'"');
335 if (!$current_value && !$in_quote && $is_quote) {
336 $in_quote = $file_contents{$cur_pos};
340 }
else if (!$in_quote && !$this->
_isWhitespace($file_contents{$cur_pos})) {
341 $current_value .= $file_contents{$cur_pos};
344 }
else if ($in_quote && $file_contents{$cur_pos} != $in_quote) {
345 $current_value .= $file_contents{$cur_pos};
351 $tag[
'attributes'][strtolower($current_name)] = strtr($current_value, $trans);
352 $currently_getting =
'';
371 $tag[
'self_terminating'] = $escape_slash;
389 $cur_pos += strlen(
'</'.$this->tag_name);
391 $cur_pos = strpos($file_contents,
'>', $cur_pos);
408 return preg_match(
'/^[[:space:]]*$/', $str);
425 $GLOBALS[
'SQ_PROCESSED_DESIGN_AREAS'][$asset->
attr(
'id_name')] = TRUE;
451 $remove_indexes = Array();
453 $set_attrs = Array();
454 $var_references = Array();
455 foreach ($contents as $index => $element) {
457 if ($element[
'_type'] !=
'TAG' || $element[
'operation'] !=
'set') {
462 if (!empty($element[
'attributes'][
'id_name']) && !empty($element[
'attributes'][
'var'])) {
465 $var_references[$element[
'attributes'][
'name']] = Array(
466 'id_name' => $element[
'attributes'][
'id_name'],
467 'var' => $element[
'attributes'][
'var'],
471 }
else if (!empty($element[
'attributes'][
'id_name'])) {
474 $var_references[$element[
'attributes'][
'name']] = Array(
475 'id_name' => $element[
'attributes'][
'id_name'],
480 }
else if (isset($element[
'attributes'][
'value'])) {
482 if (stristr($element[
'attributes'][
'name'],
'image')) {
483 $element[
'attributes'][
'value'] = $this->
_removeFileRoot($element[
'attributes'][
'value']);
486 if (!$asset->
setAttrValue($element[
'attributes'][
'name'], $element[
'attributes'][
'value'])) {
487 trigger_localised_error(
'CORE0189', E_USER_WARNING, $element[
'attributes'][
'name'], $asset->
attr(
'id_name'));
490 $set_attrs[] = $element[
'attributes'][
'name'];
494 trigger_localised_error(
'CORE0188', E_USER_WARNING, $element[
'attributes'][
'name'], $asset->
attr(
'id_name'));
499 $remove_indexes[] = $index;
502 if (!$asset->
setAttrValue(
'var_references', $var_references)) {
507 rsort($remove_indexes, SORT_NUMERIC);
508 foreach ($remove_indexes as $i) {
509 array_splice($contents, $i, 1);
517 $current_asset_attrs = $GLOBALS[
'SQ_SYSTEM']->am->getAssetTypeAttributes($asset->
type(), Array(
'name'));
521 $set_to_default = array_diff($current_asset_attrs, $not_setable_attrs, $set_attrs);
525 foreach ($set_to_default as $i => $attr_name) {
526 $attr_to_set = $GLOBALS[
'SQ_SYSTEM']->am->getAttribute($asset->vars[$attr_name][
'attrid']);
527 $default_val = $attr_to_set->_default_value;
529 $default_val = unserialize($default_val);
551 return preg_replace(
'/^(\\.\\/)?mysource_files\/(.*)/i',
'\\2', $str);
572 array_unshift($parent_types, $asset->
type());
573 for ($i = 0, $total = count($parent_types); $i < $total; $i++) {
575 $file = SQ_SYSTEM_ROOT.
'/'.$GLOBALS[
'SQ_SYSTEM']->am->getTypeInfo($parent_types[$i],
'dir').
'/default_'.$content_type.
'_contents.html';
576 if (file_exists($file)) {
577 require_once SQ_FUDGE_PATH.
'/general/file_system.inc';
583 if ($parent_types[$i] ==
'design_area')
break;