Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
design_area_linked_css.inc
1 <?php
18 require_once SQ_CORE_PACKAGE_PATH.'/designs/design_area/design_area.inc';
19 
32 {
33 
34 
41  function __construct($assetid=0)
42  {
43  parent::__construct($assetid);
44 
45  }//end constructor
46 
47 
57  public function setAttrValue($name, $value)
58  {
59  // if they are trying to set the type_codes, split the string
60  if ($name == 'type_codes') {
61  if (!is_array($value)) {
62  $value = preg_split('/[ ,]+/', (string) $value);
63  }
64  foreach ($value as $type_code) {
65  if (!$GLOBALS['SQ_SYSTEM']->am->installed($type_code)) {
66  trigger_localised_error('CORE0145', E_USER_WARNING, $type_code);
67  return FALSE;
68  }
69  }
70  }
71 
72  return parent::setAttrValue($name, $value);
73 
74  }//end setAttrValue()
75 
76 
89  public function _getAllowedLinks()
90  {
91 
92  return Array(
93  SQ_LINK_TYPE_1 => Array(),
94  SQ_LINK_TYPE_2 => Array(),
95  SQ_LINK_TYPE_3 => Array(),
96  SQ_LINK_NOTICE => Array(
97  'asset' => Array(
98  'card' => 1,
99  'exclusive' => FALSE,
100  ),
101  ),
102  );
103 
104  }//end _getAllowedLinks()
105 
106 
118  public function getLinkedCSSInfo($field)
119  {
120  if (empty($this->_tmp['css_assetid']) || (!isset($this->_tmp['css_assetid']))) {
121  $this->_tmp['css_assetid'] = $GLOBALS['SQ_SYSTEM']->am->getLink($this->id, SQ_LINK_NOTICE, '', TRUE, 'linked_css_asset');
122  }
123  return (empty($this->_tmp['css_assetid'])) ? NULL : $this->_tmp['css_assetid'][$field];
124 
125  }//end getLinkedCSSInfo()
126 
127 
134  public function linksUpdated()
135  {
136  parent::linksUpdated();
137  unset($this->_tmp['css_assetid']);
138 
139  }//end linksUpdated()
140 
141 
152  protected function _printPaintingCode()
153  {
154  $css_assetid = (int) $this->getLinkedCSSInfo('minorid');
155 
156  // return true because it just means that they haven't set anything yet
157  if (empty($css_assetid)) return TRUE;
158 
159  $css_asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($css_assetid);
160  $cache_file_assetid = $css_asset->getCacheFileId();
161 
162  // The code we are about to add to the design file will check if caching
163  // is enabled for the css asset and if so will try to get a URL
164  // from the cache file asset. But if for any reason it didn't get a
165  // URL for the cache file asset it will use the URL of the CSS asset itself.
166 
167  echo '<', '?php
168  $linked_css_'.$this->attr('id_name').'_url = $GLOBALS[\'SQ_SYSTEM\']->am->getAssetURL('.$cache_file_assetid.');
169  $css_attr = $GLOBALS[\'SQ_SYSTEM\']->am->getAllAttributeValues('.$css_assetid.', \'design_css\');
170 
171  if (!empty($linked_css_'.$this->attr('id_name').'_url)) {
172  $served_by_apache = strpos($linked_css_'.$this->attr('id_name').'_url, \'/__data/\') !== FALSE || (SQ_CONF_STATIC_ROOT_URL && strpos($linked_css_'.$this->attr('id_name').'_url, SQ_CONF_STATIC_ROOT_URL.\'/\') !== FALSE);
173  if ($served_by_apache && (isset($css_attr[\'static_url_versioning\'][\'value\']) && ($css_attr[\'static_url_versioning\'][\'value\'] == 1))) {
174  $cache_file_version = $GLOBALS[\'SQ_SYSTEM\']->am->getAssetInfo('.$cache_file_assetid.', Array(), TRUE, \'version\');
175  if (!empty($cache_file_version['.$cache_file_assetid.'])) $linked_css_'.$this->attr('id_name').'_url .= \'?v=\'.$cache_file_version['.$cache_file_assetid.'];
176  }
177  }
178 
179  if (empty($linked_css_'.$this->attr('id_name').'_url) || (isset($css_attr[\'cache_css\'][\'value\']) && ($css_attr[\'cache_css\'][\'value\'] == 0))) {
180  $linked_css_'.$this->attr('id_name').'_url = $GLOBALS[\'SQ_SYSTEM\']->am->getAssetURL('.$css_assetid.');
181  }
182 
183  if (!empty($linked_css_'.$this->attr('id_name').'_url)) {
184  ','?', '>
185  ';
186 
187  switch ($this->attr('tag_type')) {
188  case 'link_tag' :
189  echo '<link rel="stylesheet" type="text/css" href="', '<', '?php echo $linked_css_'.$this->attr('id_name').'_url; ?', '>', '"';
190  echo ' media="', $this->attr('media'), '" />
191  ';
192  break;
193  case 'import_tag' :
194  echo '@import url(', '<', '?php echo $linked_css_'.$this->attr('id_name').'_url; ?', '>);
195  ';
196  break;
197  } //end switch
198 
199  echo '<', '?php
200  }
201  ?', '>';
202 
203  }//end _printPaintingCode()
204 
205 
206 }//end class
207 ?>