Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
xml_file.inc
1 <?php
17 require_once SQ_CORE_PACKAGE_PATH.'/files/file/file.inc';
18 
27 class Xml_File extends File
28 {
29 
30 
36  public $allowed_extensions = Array('xml');
37 
38 
45  function __construct($assetid=0)
46  {
47  parent::__construct($assetid);
48 
49  }//end constructor
50 
51 
58  function getContent()
59  {
60  require_once SQ_FUDGE_PATH.'/general/file_system.inc';
61  $parse_file = $this->data_path.'/'.$this->name;
62  $content = file_to_string($parse_file);
63 
64  return trim($content);
65 
66  }//end getContent()
67 
68 
76  public function _getAllowedLinks()
77  {
78  return Array(
79  SQ_LINK_TYPE_1 => Array(),
80  SQ_LINK_TYPE_2 => Array(),
81  SQ_LINK_TYPE_3 => Array(),
82  SQ_LINK_NOTICE => Array(
83  'xsl_file' => Array(
84  'card' => '1',
85  'exclusive' => FALSE,
86  ),
87  'image' => Array(
88  'card' => '1',
89  'exclusive' => FALSE,
90  ),
91  'comment' => Array(
92  'card' => '1',
93  'exclusive' => FALSE,
94  ),
95  ),
96  );
97 
98  }//end _getAllowedLinks()
99 
100 
101  public function printFrontend()
102  {
103  $xsl_file = NULL;
104  $current = $GLOBALS['SQ_SYSTEM']->am->getLink($this->id, SQ_LINK_NOTICE, 'xsl_file', TRUE, 'transform');
105  $current_id = array_get_index($current, 'minorid', 0);
106  if (!empty($current_id)) {
107  $xsl_file = $GLOBALS['SQ_SYSTEM']->am->getAsset($current_id);
108  }//end if
109 
110  if (!is_null($xsl_file) && class_exists('XSLTProcessor')) {
112  } else {
113  parent::printFrontend();
114  }//end if
115 
116  }//end printFrontend()
117 
118 
125  public function printBody()
126  {
127  // Find the XSL Stylesheet
128  $xsl_file = NULL;
129  $current = $GLOBALS['SQ_SYSTEM']->am->getLink($this->id, SQ_LINK_NOTICE, 'xsl_file', TRUE, 'transform');
130  $current_id = array_get_index($current, 'minorid', 0);
131  if (!empty($current_id)) {
132  $xsl_file = $GLOBALS['SQ_SYSTEM']->am->getAsset($current_id);
133  }//end if
134 
135  if (!is_null($xsl_file)) {
136  // Do transformation
137  $xml = new DOMDocument();
138  $xml->loadXML($this->getContent());
139  $xsl = new DOMDocument();
140  $xsl->loadXML($xsl_file->getContent());
141 
142  $parser = new XSLTProcessor();
143  $parser->importStylesheet($xsl);
144 
145  $content = $parser->transformToXML($xml);
146  echo $content;
147  } else {
148  echo $this->getContent();
149  }//end if
150 
151  }//end printBody()
152 
153 
154 }//end class
155 ?>