Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
content_type_snippet.inc
1 <?php
18 require_once SQ_CORE_PACKAGE_PATH.'/content_type/content_type.inc';
19 
32 {
33 
34 
41  function __construct($assetid=0)
42  {
43  parent::__construct($assetid);
44 
45  }//end constructor
46 
47 
55  function _getAllowedLinks()
56  {
57  return Array(
58  SQ_LINK_NOTICE => Array(
59  'asset' => Array(
60  'card' => 1,
61  'exclusive' => FALSE,
62  ),
63  ),
64  );
65 
66  }//end _getAllowedLinks()
67 
68 
75  function linksUpdated()
76  {
77  // update content.php file once snippet notice link has been deleted
78  $bc_container_link = $GLOBALS['SQ_SYSTEM']->am->getLinks($this->id, SQ_LINK_TYPE_2, 'bodycopy_container', FALSE, 'minor');
79  if (!empty($bc_container_link)) {
80  $container = $GLOBALS['SQ_SYSTEM']->am->getAsset($bc_container_link[0]['majorid']);
81  $edit_fns = $container->getEditFns();
82  $edit_fns->generateContentFile($container);
83  }
84 
85  }//end linksUpdated()
86 
87 
94  function isEmpty()
95  {
96  $link = $GLOBALS['SQ_SYSTEM']->am->getLink($this->id, SQ_LINK_NOTICE, '', TRUE, 'snippet_asset');
97  return empty($link);
98 
99  }//end isEmpty()
100 
101 
108  function getSnippets()
109  {
110  $rootid = $GLOBALS['SQ_SYSTEM']->getUserPrefs($this->type(), 'SQ_SNIPPET_ROOT');
111  if (empty($rootid)) {
112  // snippet root preference not set
113  return Array();
114  }
115 
116  $containers = $GLOBALS['SQ_SYSTEM']->am->getChildren($rootid, 'bodycopy_container', FALSE);
117  if (empty($containers)) {
118  // no container found under the specified snippet root
119  return Array();
120  }
121 
122  // generate list of snippet name and content
123  $results = Array();
124  foreach ($containers as $id => $type_code) {
125 
126  $container = $GLOBALS['SQ_SYSTEM']->am->getAsset($id);
127  if (is_null($container)) continue;
128 
129  // only list what the current user has access to
130  if ($container->readAccess()) {
131  if (method_exists($container, 'getContentType')) {
132  $content_type = $container->getContentType();
133  // recursion check to prevent snippet from nesting itself
134  if (!isset($content_type->id) || $content_type->id == $this->id) continue;
135  $content_type_type = $content_type->type();
136  if (($content_type_type == $this->type()) && $content_type->isEmpty()) {
137  // exclude snippet that has not been initialised
138  continue;
139  }
140 
141  // special interface for nest content type
142  if($content_type_type == 'content_type_nest_content') {
143  $content = $content_type->getSnippetInterface();
144  } else {
145  // grab html source code of other content types
146  $content = $content_type->attr('html');
147  }
148 
149  $results[$id] = Array(
150  'name' => $container->name,
151  'content' => $content,
152  'type' => $content_type_type,
153  );
154  }
155  unset($content_type);
156  }
157 
158  $GLOBALS['SQ_SYSTEM']->am->forgetAsset($container);
159 
160  }//end foreach container
161  return $results;
162 
163  }//end getSnippets()
164 
165 
172  function &getCurrentSnippet()
173  {
174  $snippet_asset = NULL;
175  $snippet_link = $GLOBALS['SQ_SYSTEM']->am->getLink($this->id, SQ_LINK_NOTICE, '', TRUE, 'snippet_asset');
176  if (!empty($snippet_link)) {
177  $snippet_asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($snippet_link['minorid'], $snippet_link['minor_type_code'], TRUE);
178  }
179 
180  return $snippet_asset;
181 
182  }//end getCurrentSnippet()
183 
184 
193  function describeLink($linkid)
194  {
195  // provide a more descriptive message when user trash active snippet
196  $link = $GLOBALS['SQ_SYSTEM']->am->getLinkById($linkid);
197  if ($link['link_type'] == SQ_LINK_NOTICE && $link['value'] == 'snippet_asset') {
198  return translate('cms_ct_snippet_link_desc');
199  }
200  return parent::describeLink($linkid);
201 
202  }//end describeLink()
203 
204 
211  function getContent()
212  {
213  return '';
214 
215  }//end getContent()
216 
217 
224  function setContent()
225  {
226  return FALSE;
227 
228  }//end setContent()
229 
230 
253  public function cloneComponentsAdditional(Asset $clone, Array $components)
254  {
255  // update content.php file
256  $bc_container_link = $GLOBALS['SQ_SYSTEM']->am->getLinks($clone->id, SQ_LINK_TYPE_2, 'bodycopy_container', FALSE, 'minor');
257  if (!empty($bc_container_link)) {
258  $container = $GLOBALS['SQ_SYSTEM']->am->getAsset($bc_container_link[0]['majorid']);
259  $edit_fns = $container->getEditFns();
260  $edit_fns->generateContentFile($container);
261  }
262 
263  return parent::cloneComponentsAdditional($clone, $components);
264 
265  }//end cloneComponentsAdditional()
266 
267 
268 }//end class
269 
270 ?>