1: <?php
2: /**
3: * This file contains the file version class.
4: *
5: * @package Core
6: * @subpackage Versioning
7: * @version SVN Revision $Rev:$
8: *
9: * @author Bilal Arslan, 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: * @access public
31: */
32: public $sCode;
33:
34: /**
35: * Description folder of history sub nav.
36: * Its not required to use it.
37: *
38: * @access protected
39: */
40: public $sDescripion;
41:
42: /**
43: * The path of style file.
44: *
45: * @access public
46: */
47: public $sPath;
48:
49: /**
50: * The id of Type.
51: *
52: * @access public
53: */
54: public $sFileName;
55:
56: /**
57: * The class versionStyle object constructor, initializes class variables
58: *
59: * @param string $iIdOfType The name of style file
60: * @param array $aFileInfo Get FileInformation from table file_information
61: * @param array $aCfg
62: * @param array $aCfgClient
63: * @param object $oDB
64: * @param int $iClient
65: * @param string $sArea
66: * @param int $iFrame
67: */
68: public function __construct($iIdOfType, $aFileInfo, $sFileName, $sTypeContent, $aCfg, $aCfgClient, $oDB, $iClient, $sArea, $iFrame, $sVersionFileName = '') {
69: // Set globals in super class constructer
70: parent::__construct($aCfg, $aCfgClient, $oDB, $iClient, $sArea, $iFrame);
71:
72: // Folder name is css or js ...
73: $this->sType = $sTypeContent;
74:
75: // File Name for xml node
76: $this->sFileName = $sFileName;
77:
78: // File Information, set for class Version to generate head xml nodes
79: $this->sDescripion = $aFileInfo["description"];
80: $this->sAuthor = $aFileInfo["author"];
81: $this->dLastModified = $aFileInfo["lastmodified"];
82: $this->dCreated = $aFileInfo["created"];
83:
84: // Frontendpath to files
85: if ($sTypeContent == "templates") {
86: $sTypeContent = "tpl";
87: }
88:
89: $this->sPath = $this->aCfgClient[$this->iClient][$sTypeContent]["path"];
90:
91: // Identity the Id of Content Type
92: $this->iIdentity = $iIdOfType;
93:
94: // This function looks if maximum number of stored versions is achieved
95: $this->prune();
96:
97: // Take revision files if exists
98: $this->initRevisions();
99:
100: // Get code of style
101: $this->initFileContent();
102:
103: // Set Layout Table Iformation, currently not in use!
104: // this->setLayoutTable();
105:
106: if ($sVersionFileName == '') {
107: $sVersionFileName = $this->sFileName;
108: }
109:
110: // Create Body Node of Xml File
111: $this->setData("name", $sVersionFileName);
112: $this->setData("code", $this->sCode);
113: $this->setData("description", $this->sDescripion);
114: }
115:
116: /**
117: * This function init the class member sCode with current file content
118: */
119: protected function initFileContent() {
120: if (cFileHandler::exists($this->sPath . $this->sFileName)) {
121: $this->sCode = cFileHandler::read($this->sPath . $this->sFileName);
122: } else {
123: echo "<br>File not exists " . $this->sPath . $this->sFileName;
124: }
125: }
126:
127: /**
128: * This function read an xml file nodes
129: *
130: * @param string $sPath Path to file
131: *
132: * @return {array} returns array width nodes
133: */
134: public function initXmlReader($sPath) {
135: $aResult = array();
136: if ($sPath != "") {
137: $xml = new cXmlReader();
138: $xml->load($sPath);
139:
140: $aResult['name'] = $xml->getXpathValue('/version/body/name');
141: $aResult['desc'] = $xml->getXpathValue('/version/body/description');
142: $aResult['code'] = $xml->getXpathValue('/version/body/code');
143: }
144:
145: return $aResult;
146: }
147:
148: /**
149: * This function reads the path of file
150: *
151: * @param string $sPath Path to file
152: *
153: * @return string the path of file
154: */
155: public function getPathFile() {
156: return $this->sPath;
157: }
158:
159: /**
160: * Function returns javascript which refreshes CONTENIDO frames for file
161: * list an subnavigation.
162: * This is neccessary, if filenames where changed, when a history entry is
163: * restored
164: *
165: * @param integer $iIdClient - id of client which contains this file
166: * @param string $sArea - name of CONTENIDO area in which this procedure
167: * should be done
168: * @param string $sFilename - new filename of file which should be updated
169: * in other frames
170: * @param object $sess - CONTENIDO session object
171: *
172: * @return string - Javascript for refrehing frames
173: */
174: public function renderReloadScript($sArea, $sFilename, $sess) {
175: $sReloadScript = "<script type=\"text/javascript\">
176: var right_top = top.content.right.right_top;
177: var left_bottom = top.content.left.left_bottom;
178:
179: if (right_top) {
180: var href = '" . $sess->url("main.php?area=$sArea&frame=3&file=$sFilename&history=true") . "';
181: right_top.location.href = href;
182: }
183:
184: if (left_bottom) {
185: var href = '" . $sess->url("main.php?area=$sArea&frame=2&file=$sFilename") . "';
186: left_bottom.location.href = href;
187: }
188: </script>";
189: return $sReloadScript;
190: }
191:
192: }
193: