19 private $_modTimeCachePrefix =
'__modTime__';
36 $mainAttributes = array(
45 if ($this->usePersonalisation) {
46 return array_merge($mainAttributes, $this->personalisationFields);
48 return $mainAttributes;
62 if ($this->_haveNewestVersion($path)) {
63 return $this->_takeFromFileSystem($path);
65 return $this->_takeAndSaveFromApi($path);
69 public function getStartPage($folderPath, $locale)
71 $localizedAttributeName = Yii::app()->getModule(
'contentSource')->localizedAttributeName. $locale;
73 $folderObject = $this->
getRepositoryApi()->getContentAttributes($folderPath, array($localizedAttributeName));
75 return $folderObject[$localizedAttributeName];
87 private function _takeAndSaveFromApi($path)
90 if ( Yii::app()->request->getParam(
'refresh') ==
true) {
93 $this->
getRepositoryApi()->clearCache($cmsObject[
'attributes'][
'contentid']);
98 $this->_createFile($path, $cmsObject[
'attributes'][
'content'], $cmsObject[
'attributes'][
'updatetimestamp']);
100 $content =
new Content($this, $path);
101 unset($cmsObject[
'attributes'][
'content']);
102 $content->setAttributes($cmsObject[
'attributes']);
116 private function _haveNewestVersion($path)
123 if (!file_exists($contentFile) || Yii::app()->request->getParam(
'refresh',
false)) {
129 if ( ( Yii::app()->cache->get(
"lastcheck_".$this->_modTimeCachePrefix . $path) === false ) ||
130 ( Yii::app()->session->get(
'feSid',
false) && Yii::app()->session->get(
'feSid',
false) ) ) {
133 Yii::app()->cache->set(
"lastcheck_".$this->_modTimeCachePrefix . $path , time(), Yii::app()->getModule(
'contentSource')->cacheTime);
136 if ($lastModificationTime = $this->
getRepositoryApi()->getLastModificationTime($path)) {
137 Yii::trace(
"$lastModificationTime " . Yii::app()->cache->get($this->_modTimeCachePrefix . $path) .
" " . filemtime($this->
contentFile($path)),
"myoutput");
139 if ( Yii::app()->cache->get(
"lastcheck_".$this->_modTimeCachePrefix . $path) == $lastModificationTime || filemtime($this->
contentFile($path)) == $lastModificationTime ) {
142 @unlink( $contentFile );
150 @unlink( $contentFile );
161 private function _takeFromFileSystem($path)
165 $content =
new Content($this, $path);
184 private function _createFile($path, $content, $time)
187 if (file_exists($contentFile) && !$this->
fileAccessible($contentFile, $this->cacheFolder)) {
191 $dirPath = pathinfo($contentFile, PATHINFO_DIRNAME);
192 if (!file_exists($dirPath)) {
193 if (!@mkdir($dirPath, 0777,
true)) {
194 throw new Exception(
"Can't create dir $dirPath");
197 if (!file_put_contents($contentFile, $content)) {
198 throw new Exception(
"Can't create file $contentFile");
200 if (!touch($contentFile, $time)) {
201 throw new Exception(
"Can't touch() file $contentFile");
203 if (!chmod($contentFile, 0666)) {
204 throw new Exception(
"Can't chmod() file $contentFile");
208 unlink($contentFile);
212 Yii::app()->cache->set($this->_modTimeCachePrefix . $path, $time, Yii::app()->getModule(
'contentSource')->cacheTime);
226 return $this->cacheFolder . $path;