Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
file_bridge.inc
1 <?php
17 require_once SQ_INCLUDE_PATH.'/asset.inc';
18 require_once SQ_FUDGE_PATH.'/general/file_system.inc';
19 require_once SQ_CORE_PACKAGE_PATH.'/interfaces/bridge/bridge.inc';
20 
32 class File_Bridge extends Asset implements Bridge
33 {
34 
35 
42  function File_Bridge($assetid=0)
43  {
44  parent::__construct($assetid);
45 
46  }//end constructor
47 
48 
58  protected function _getName($short_name=FALSE)
59  {
60  return $this->attr('name');
61 
62  }//end _getName()
63 
64 
75  protected function _createAdditional(Array &$link)
76  {
77  if (!parent::_createAdditional($link)) return FALSE;
78 
79  return $this->makeAndSaveInitialWebPath(strtolower($this->attr('name')), $link);
80 
81  }//end _createAdditional()
82 
83 
92  private function _listFiles($path)
93  {
94 
95  $list = Array();
96 
97  $dirs = list_dirs($path, TRUE, Array('CVS', '.svn'));
98  $files = list_files($path, TRUE);
99 
100  sort($dirs);
101  sort($files);
102 
103  $temp = array_merge($dirs, $files);
104  $list = Array();
105 
106  // Cleanup by removing hidden files
107  foreach ($temp as $element) {
108  $filename = basename($element);
109  if (strpos($filename, '.') !== 0) {
110  $list[] = $element;
111  }//end if
112  }//end foreach
113 
114  return $list;
115 
116  }//end _listFiles()
117 
118 
127  private function _isValidFile($path)
128  {
129  if (file_exists($path) && is_readable($path)) {
130  return TRUE;
131  }//end if
132 
133  return FALSE;
134 
135  }//end _isValidFile()
136 
137 
138 //-- BRIDGE INTERFACE --//
139 
140 
156  function getAsset($assetid, $type_code='', $mute_errors=FALSE)
157  {
158  $asset = NULL;
159  $id_parts = explode(':', $assetid);
160 
161  if (isset($id_parts[1])) {
162  $shadowid = $id_parts[1];
163  } else {
164  return $asset;
165  }
166 
167  // The shadow id is the path from the location of the bridge
168  require_once (SQ_DATA_PATH.'/private/conf/file_bridge.inc');
169  $location = FILE_BRIDGE_PATH;
170  $location = rtrim($location, '/');
171  if ($this->_isValidFile($location.'/'.$shadowid)) {
172  if (is_dir($location.'/'.$shadowid)) {
173  $GLOBALS['SQ_SYSTEM']->am->includeAsset('physical_folder');
174  $asset = new Physical_Folder($this->id.':'.$shadowid);
175  } else {
176  $GLOBALS['SQ_SYSTEM']->am->includeAsset('physical_file');
177  $asset = new Physical_File($this->id.':'.$shadowid);
178  }//end if
179  }//end if
180 
181  return $asset;
182 
183  }//end getAsset()
184 
185 
206  function getLinks($assetid, $link_types, $type_code='', $strict_type_code=TRUE, $side_of_link='major', $sort_by=NULL)
207  {
208  // only TYPE_2 links are ever returned
209  if (!($link_types & SQ_LINK_TYPE_2)) {
210  return Array();
211  }
212 
213  if (!is_array($type_code)) {
214  if (empty($type_code)) {
215  $type_code = Array();
216  } else {
217  $type_code = Array($type_code);
218  }
219  }
220 
221  if (!isset($this->_tmp['getLinks'][$assetid][$side_of_link])) {
222 
223  $links = Array();
224  // if we are looking from this asset and not a shadow asset
225  if ($this->id == $assetid) {
226  if ($side_of_link == 'minor') {
227  // should never happen...but anyway
228  trigger_localised_error('CORE0089', E_USER_ERROR);
229 
230  } else {
231  require_once (SQ_DATA_PATH.'/private/conf/file_bridge.inc');
232  $location = FILE_BRIDGE_PATH;
233  $location = rtrim($location, '/');
234  $files = $this->_listFiles($location);
235  $i = 0;
236  foreach ($files as $file) {
237  $varid = str_replace($location.'/', '', $file);
238  $type_code = (is_dir($file)) ? 'physical_folder' : 'physical_file';
239  $links[] = Array(
240  'linkid' => 0,
241  'minorid' => $this->id.':'.$varid,
242  'minor_type_code' => $type_code,
243  'majorid' => $this->id,
244  'value' => '',
245  'link_type' => SQ_LINK_TYPE_2,
246  'is_dependant' => FALSE,
247  'is_exclusive' => FALSE,
248  'sort_order' => $i,
249  );
250  $i++;
251  }// end foreach
252 
253  }// endif
254 
255 
256  // looking from shadow asset
257  } else {
258  list($bridgeid,$shadowid) = explode(':', $assetid);
259  require_once (SQ_DATA_PATH.'/private/conf/file_bridge.inc');
260  $location = FILE_BRIDGE_PATH;
261  $location = rtrim($location, '/');
262 
263  // The file is invalid why proceed?
264  if (!$this->_isValidFile($location.'/'.$shadowid)) {
265  return Array();
266  }//end if
267 
268  // because the varieties are only ever going to be one level down
269  // if we are looking up the tree all we can see is this bridge asset
270  if ($side_of_link == 'minor') {
271  $links[] = Array(
272  'linkid' => 0,
273  'majorid' => $this->id,
274  'major_type_code' => $this->type(),
275  'value' => '',
276  'link_type' => SQ_LINK_TYPE_2,
277  'is_dependant' => TRUE,
278  'is_exclusive' => TRUE,
279  'sort_order' => 0,
280  );
281  } else {
282  // Looking down the tree
283  if (is_dir($location.'/'.$shadowid)) {
284  $files = $this->_listFiles($location.'/'.$shadowid);
285  $i = 0;
286  foreach ($files as $file) {
287  $varid = str_replace($location.'/', '', $file);
288  $type_code = (is_dir($file)) ? 'physical_folder' : 'physical_file';
289  $links[] = Array(
290  'linkid' => 0,
291  'minorid' => $this->id.':'.$varid,
292  'minor_type_code' => $type_code,
293  'majorid' => $this->id,
294  'value' => '',
295  'link_type' => SQ_LINK_TYPE_2,
296  'is_dependant' => TRUE,
297  'is_exclusive' => TRUE,
298  'sort_order' => $i,
299  );
300  $i++;
301  }// end foreach
302  } else {
303  // Just a file, nothing underneath
304  return Array();
305  }//end if
306  }//endif
307 
308  }//end else - looking from shadow asset
309 
310  if (!is_null($sort_by)) {
311  uasort($links, create_function('$a,$b', 'return $a["'.$sort_by.'"] < $b["'.$sort_by.'"];'));
312  }
313 
314  $this->_tmp['getLinks'][$assetid][$side_of_link] = $links;
315 
316  }//end if
317 
318  return $this->_tmp['getLinks'][$assetid][$side_of_link];
319 
320  }//end getLinks()
321 
322 
344  public function getChildren($assetid, $type_code='', $strict_type_code=TRUE, $dependant=NULL, $sort_by=NULL)
345  {
346  // now that we have an array in the format we wanted (sorted or not)
347  // we can go through and construct our children array
348  $children = Array();
349  $links = $this->getLinks($assetid, SQ_LINK_TYPE_2, $type_code, $strict_type_code, 'major', NULL);
350  if (!empty($links)) {
351  foreach ($links as $link) {
352  $children[$link['minorid']][0]['type_code'] = $link['minor_type_code'];
353  }
354  }
355  return $children;
356 
357  }//end getChildren()
358 
359 
375  function getParents($assetid, $type_code='', $strict_type_code=TRUE)
376  {
377  $id_parts = explode(':', $assetid);
378  $parents = $GLOBALS['SQ_SYSTEM']->am->getParents($id_parts[0]);
379  // after getting its own parent, the bridge adds itself as a parent into the array as the shadow asset is its child
380  $parents[$this->id] = $this->type();
381  return $parents;
382 
383  }//end getParents()
384 
385 
392  function printBody()
393  {
394 
395  }//end printBody()
396 
397 
413  {
414  $keywords = parent::getAvailableKeywords();
415 
416  return $keywords;
417 
418  }//end getAvailableKeywords()
419 
420 
435  function getKeywordReplacement($keyword)
436  {
437  return parent::getKeywordReplacement($keyword);
438 
439  }//end getKeywordReplacement()
440 
441 
452  function getLineageFromURL($assetid, $protocol, $url)
453  {
454  return Array();
455 
456  }//end getLineageFromURL()
457 
458 
479  function getPermission($assetid, $permission, $granted=NULL, $and_greater=TRUE, $expand_groups=FALSE, $all_info=FALSE)
480  {
481  // All users underneath this bridge inherit the permissions of the bridge
482  return $GLOBALS['SQ_SYSTEM']->am->getPermission($this->id, $permission, $granted, $and_greater, $expand_groups, $all_info);
483 
484  }//end getPermission()
485 
486 
498  function setPermission($assetid, $userid, $permission, $granted)
499  {
500  return FALSE;
501 
502  }//end setPermission()
503 
504 
515  function deletePermission($assetid, $userid, $permission)
516  {
517  return FALSE;
518 
519  }//end deletePermission()
520 
521 
536  function getAssetInfo($assetids, $type_code=Array(), $strict_type_code=TRUE, $field='')
537  {
538  $info = Array();
539  foreach ($assetids as $assetid) {
540  $asset = $this->getAsset($assetid);
541 
542  if (!empty($field)) {
543  if ($field == 'assetid') {
544  $info[$assetid] = $assetid;
545  } else if ($field == 'type_code') {
546  $info[$assetid] = $asset->type();
547  } else if (in_array($field , Array('version', 'name', 'short_name', 'status'))) {
548  $info[$assetid] = $asset->$field;
549  } else {
550  $info[$assetid] = $this->$field;
551  }
552  } else {
553  $info[$assetid] = Array(
554  'assetid' => $assetid,
555  'type_code' => $asset->type(),
556  'version' => $asset->version,
557  'name' => $asset->name,
558  'short_name' => $asset->short_name,
559  'status' => $asset->status,
560  'languages' => $asset->languages,
561  'charset' => $asset->charset,
562  'force_secure' => $this->force_secure,
563  'created' => $asset->created,
564  'created_userid' => $asset->created_userid,
565  'updated' => $asset->updated,
566  'updated_userid' => $asset->updated_userid,
567  'published' => $asset->published,
568  'published_userid' => $asset->published_userid,
569  'status_changed' => $asset->status_changed,
570  'status_changed_userid' => $asset->status_changed_userid,
571  );
572  }
573 
574  }//end foreach
575 
576  return $info;
577 
578  }//end getAssetInfo()
579 
580 
592  function assetExists($assetids)
593  {
594  return FALSE;
595 
596  }//end assetExists()
597 
598 
620  function getLink($assetid, $link_type=NULL, $type_code='', $strict_type_code=TRUE, $value=NULL, $side_of_link='major', $exclusive=NULL)
621  {
622  return Array();
623 
624  }//end getLink()
625 
626 
638  function getLinkById($linkid, $assetid=0, $side_of_link='major')
639  {
640  return Array();
641 
642  }//end getLinkById()
643 
644 
666  function countLinks($assetid, $side_of_link='major', $link_types=0, $type_code='', $strict_type_code=TRUE, $ignore_linkid=0)
667  {
668  return 0;
669 
670  }//end countLinks()
671 
672 
693  function getLinkByAsset($assetid, $other_assetid, $link_types=NULL, $value=NULL, $side_of_link='major', $force_array=FALSE, $dependant=NULL, $exclusive=NULL)
694  {
695  return Array();
696 
697  }//end getLinkByAsset()
698 
699 
709  function getAllChildLinks($assetid, $link_type=0)
710  {
711  return Array();
712 
713  }//end getAllChildLinks()
714 
715 
730  function updateLink($linkid, $link_type=NULL, $value=NULL, $sort_order=NULL)
731  {
732  return FALSE;
733 
734  }//end updateLink()
735 
736 
746  function deleteAssetLink($linkid, $moving=FALSE)
747  {
748  return FALSE;
749 
750  }//end deleteAssetLink()
751 
752 
769  function createAssetLink(&$major, &$minor, $link_type, $value='', $sort_order=NULL, $dependant='0', $exclusive='0', $moving=FALSE)
770  {
771  return 0;
772 
773  }//end createAssetLink()
774 
775 
784  function getAssetMapAssetInfo($assetid)
785  {
786  return Array();
787 
788  }//end getAssetMapAssetInfo()
789 
790 
791 }//end class
792 
793 ?>