1: <?php
2:
3: /**
4: * This file contains the file version class.
5: *
6: * @package Core
7: * @subpackage Versioning
8: * @author Bilal Arslan
9: * @author Timo Trautmann
10: * @copyright four for business AG <www.4fb.de>
11: * @license http://www.contenido.org/license/LIZENZ.txt
12: * @link http://www.4fb.de
13: * @link http://www.contenido.org
14: */
15:
16: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
17:
18: /**
19: * Class of File System
20: * We use super class Version to create a new Version.
21: *
22: * @package Core
23: * @subpackage Versioning
24: */
25: class cVersionFile extends cVersion {
26:
27: /**
28: * Content code of current file.
29: *
30: * @var string
31: */
32: public $sCode;
33:
34: /**
35: * Description folder of history sub nav.
36: * Its not required to use it.
37: *
38: * @var string
39: */
40: public $sDescription;
41:
42: /**
43: * The path of style file.
44: *
45: * @var string
46: */
47: public $sPath;
48:
49: /**
50: * The id of Type.
51: *
52: * @var string
53: */
54: public $sFileName;
55:
56: /**
57: * Constructor to create an instance of this class.
58: *
59: * Initializes class variables.
60: *
61: * @param string $iIdOfType
62: * The name of style file
63: * @param array $aFileInfo
64: * Get FileInformation from table file_information
65: * @param string $sFileName
66: * @param string $sTypeContent
67: * @param array $aCfg
68: * @param array $aCfgClient
69: * @param object $oDB
70: * @param int $iClient
71: * @param string $sArea
72: * @param int $iFrame
73: * @param string $sVersionFileName [optional]
74: */
75: public function __construct(
76: $iIdOfType, $aFileInfo, $sFileName, $sTypeContent, $aCfg, $aCfgClient,
77: $oDB, $iClient, $sArea, $iFrame, $sVersionFileName = ''
78: ) {
79:
80: // Set globals in super class constructer
81: parent::__construct($aCfg, $aCfgClient, $oDB, $iClient, $sArea, $iFrame);
82:
83: // Folder name is css or js ...
84: $this->sType = $sTypeContent;
85:
86: // File Name for xml node
87: $this->sFileName = $sFileName;
88:
89: // File Information, set for class Version to generate head xml nodes
90: $this->sDescription = $aFileInfo['description'];
91: $this->sAuthor = $aFileInfo['author'];
92: $this->dLastModified = $aFileInfo['lastmodified'];
93: $this->dCreated = $aFileInfo['created'];
94:
95: // Frontendpath to files
96: if ($sTypeContent == "templates") {
97: $sTypeContent = "tpl";
98: }
99:
100: $this->sPath = $this->aCfgClient[$this->iClient][$sTypeContent]["path"];
101:
102: // Identity the Id of Content Type
103: $this->iIdentity = $iIdOfType;
104:
105: // This function looks if maximum number of stored versions is achieved
106: $this->prune();
107:
108: // Take revision files if exists
109: $this->initRevisions();
110:
111: // Get code of style
112: $this->initFileContent();
113:
114: // Set Layout Table Iformation, currently not in use!
115: // this->setLayoutTable();
116:
117: if ($sVersionFileName == '') {
118: $sVersionFileName = $this->sFileName;
119: }
120:
121: // Create Body Node of Xml File
122: $this->setData("name", $sVersionFileName);
123: $this->setData("code", $this->sCode);
124: $this->setData("description", $this->sDescription);
125: }
126:
127: /**
128: * This function init the class member sCode with current file content
129: */
130: protected function initFileContent() {
131: if (cFileHandler::exists($this->sPath . $this->sFileName)) {
132: $this->sCode = cFileHandler::read($this->sPath . $this->sFileName);
133: } else {
134: echo "<br>File not exists " . $this->sPath . $this->sFileName;
135: }
136: }
137:
138: /**
139: * This function read an xml file nodes
140: *
141: * @param string $sPath
142: * Path to file
143: * @return array
144: * returns array width nodes
145: */
146: public function initXmlReader($sPath) {
147: $aResult = array();
148: if ($sPath != "") {
149: $xml = new cXmlReader();
150: $xml->load($sPath);
151:
152: $aResult['name'] = $xml->getXpathValue('/version/body/name');
153: $aResult['desc'] = $xml->getXpathValue('/version/body/description');
154: $aResult['code'] = $xml->getXpathValue('/version/body/code');
155: }
156:
157: return $aResult;
158: }
159:
160: /**
161: * This function reads the path of file
162: *
163: * @return string
164: * the path of file
165: */
166: public function getPathFile() {
167: return $this->sPath;
168: }
169:
170: /**
171: * Function returns javascript which refreshes CONTENIDO frames for file
172: * list an subnavigation.
173: * This is necessary, if filenames where changed, when a history entry is
174: * restored
175: *
176: * @param string $sArea
177: * name of CONTENIDO area in which this procedure should be done
178: * @param string $sFilename
179: * new filename of file which should be updated in other frames
180: * @param object $sess
181: * CONTENIDO session object
182: * @return string
183: * Javascript for refrehing frames
184: */
185: public function renderReloadScript($sArea, $sFilename, $sess) {
186: $urlRightTop = $sess->url("main.php?area=$sArea&frame=3&file=$sFilename&history=true");
187: $urlLeftBottom = $sess->url("main.php?area=$sArea&frame=2&file=$sFilename");
188: $sReloadScript = <<<JS
189: <script type="text/javascript">
190: (function(Con, $) {
191: var right_top = Con.getFrame('right_top'),
192: left_bottom = Con.getFrame('left_bottom');
193:
194: if (right_top) {
195: right_top.location.href = '{$urlRightTop}';
196: }
197:
198: if (left_bottom) {
199: left_bottom.location.href = '{$urlLeftBottom}';
200: }
201: })(Con, Con.$);
202: </script>
203: JS;
204: return $sReloadScript;
205: }
206:
207: }
208: