Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
content_type.inc
1 <?php
18 require_once SQ_INCLUDE_PATH.'/asset.inc';
19 require_once SQ_FUDGE_PATH.'/general/text.inc';
20 
32 class Content_Type extends Asset
33 {
34 
35 
42  function __construct($assetid=0)
43  {
44  parent::__construct($assetid);
45 
46  }//end constructor
47 
48 
59  protected function _preCreateCheck(Array &$link)
60  {
61  if (!parent::_preCreateCheck($link)) return FALSE;
62 
63  $name = trim($this->attr('name'));
64  if ($name == '') {
65  trigger_localised_error('CORE0083', E_USER_WARNING, $GLOBALS['SQ_SYSTEM']->am->getTypeInfo($this->type(), 'name'));
66  return FALSE;
67  }
68 
69  return TRUE;
70 
71  }//end _preCreateCheck()
72 
73 
81  public function _getAllowedLinks()
82  {
83  return Array();
84 
85  }//end _getAllowedLinks()
86 
87 
98  protected function _getName($short_name=FALSE, $contextid=NULL)
99  {
100  // No context specified, using the current context
101  if ($contextid === NULL) {
102  $contextid = $GLOBALS['SQ_SYSTEM']->getContextId();
103  }//end if
104 
105  // Obtain the attribute value for Name from the specified Context
106  $values = $GLOBALS['SQ_SYSTEM']->am->getAttributeValuesByName('name', $this->type(), Array($this->id), $contextid);
107  if (empty($values) === TRUE) {
108  return parent::_getName($short_name, $contextid);
109  } else {
110  return $values[$this->id];
111  }
112 
113  }//end _getName()
114 
115 
122  public function isEmpty()
123  {
124  $html = trim($this->attr('html'));
125  return empty($html);
126 
127  }//end isEmpty()
128 
129 
136  public function getContent()
137  {
138  return trim($this->attr('html'));
139 
140  }//end getContent()
141 
142 
151  public function setContent($content)
152  {
153  $this->setAttrValue('html', $content);
154  $this->saveAttributes();
155 
156  return TRUE;
157 
158  }//end setContent()
159 
160 
171  public function saveAttributes($dont_run_updated=FALSE)
172  {
173  $contents_changed = isset($this->_tmp['vars_set']['html']);
174 
175  // Want to see if the content has been changed.
176  if ($contents_changed) {
177  // Yep, so we need to (re)generate our bodycopy container's content file
178  $bc_container_link = $GLOBALS['SQ_SYSTEM']->am->getLinks($this->id, SQ_LINK_TYPE_2, 'bodycopy_container', FALSE, 'minor');
179  if (!empty($bc_container_link)) {
180  $container = $GLOBALS['SQ_SYSTEM']->am->getAsset($bc_container_link[0]['majorid']);
181  $contextid = (int)$GLOBALS['SQ_SYSTEM']->getContextId();
182  $datapath = $container->data_path;
183 
184  // if default context attribute value changed
185  // remove all content files for alternate contexts to stay in sync with new attributes #3967
186  if($contextid === 0 && !empty($datapath)) {
187  $contextids = array_keys($GLOBALS['SQ_SYSTEM']->getAllContexts());
188  foreach ($contextids as $id) {
189  $file = $datapath.'/content_file.'.$id.'.php';
190  if(file_exists($file)) unlink($file);
191  }
192 
193  }
194  // generate content file now
195  $edit_fns = $container->getEditFns();
196  $edit_fns->generateContentFile($container);
197  }
198  }
199 
200  $success = parent::saveAttributes($dont_run_updated);
201 
202  if ($contents_changed && $success) {
203  $em = $GLOBALS['SQ_SYSTEM']->getEventManager();
204  $em->broadcastEvent($this, 'ContentsUpdated');
205 
206  // broadcast conetnt chnaged trigger event for its top level parent
207  $top_level_parents = $GLOBALS['SQ_SYSTEM']->am-> getDependantParents($this->id, '', TRUE, FALSE);
208  foreach ($top_level_parents as $parentid) {
209  $parent = $GLOBALS['SQ_SYSTEM']->am->getAsset($parentid);
210  $GLOBALS['SQ_SYSTEM']->broadcastTriggerEvent('trigger_event_asset_content_changed', $parent);
211  }
212  }
213 
214  return $success;
215 
216  }//end saveAttributes()
217 
218 
225  public function linksUpdated()
226  {
227  // Bug Fix 1541
228  // Paintlayout bodycopy is not updated if the content type is updated but its attributes
229  // was not changed. For instance, the nested content type, it does not change any of its attributes
230  // although you change the asset to nest within. Consequently, saveAttributes() function can not
231  // propagate to all the parents resulting in paint layout bodycopy unchanged.
232  $am = $GLOBALS['SQ_SYSTEM']->am;
233  $bc_container_link = $am->getLink($this->id, SQ_LINK_TYPE_2, 'bodycopy_container', FALSE, NULL, 'minor');
234 
235  if (!empty($bc_container_link)) {
236  $bc_container = $am->getAsset($bc_container_link['majorid']);
237  $bc_link = $am->getLink($bc_container->id, SQ_LINK_TYPE_2, 'paint_layout_bodycopy', TRUE, NULL, 'minor');
238 
239  if (!empty($bc_link)) {
240  $bodycopy = $am->getAsset($bc_link['majorid']);
241  $bodycopy->_updated();
242  }
243  }
244  return TRUE;
245 
246  }//end linksUpdated()
247 
248 
255  public static function getAvailableContentTypes() {
256  $content_types = $GLOBALS['SQ_SYSTEM']->am->getAssetTypeHierarchy('content_type');
257 
258  if (isset($content_types['content_type_markdown'])) {
259  //if markdown is not enabled, remove it from the content type
260  $disable_markdown = TRUE;
261  require_once SQ_DATA_PATH.'/private/conf/tools.inc';
262  if (SQ_TOOL_MARKDOWN_ENABLED && is_file(SQ_TOOL_MARKDOWN_PATH)) {
263  include_once SQ_TOOL_MARKDOWN_PATH;
264  if (function_exists('Markdown')) {
265  $disable_markdown = FALSE;
266  }
267  }
268  if ($disable_markdown) {
269  unset($content_types['content_type_markdown']);
270  }
271  }
272 
273  return $content_types;
274 
275  }//end getAvailableContentTypes()
276 
287  function setAttrValue($name, $value)
288  {
289  if($this instanceof Content_Type_Nest_Content) return parent::setAttrValue($name, $value);
290 
291  $live_link_only = $GLOBALS['SQ_SYSTEM']->getUserPrefs('content_type_wysiwyg', 'SQ_LIVE_LINK_ONLY');
292  if ($live_link_only && $this->status == SQ_STATUS_LIVE && $name === 'html') {
293  require_once SQ_FUDGE_PATH.'/general/www.inc';
294  $outcome = check_non_live_link($value, $this->id);
295  if ($outcome !== FALSE) $value = $outcome;
296  }
297  return parent::setAttrValue($name, $value);
298 
299  }//end setAttrValue()
300 
301 }//end class
302 
303 ?>