Gentics Portal.Node PHP API
 All Classes Namespaces Functions Variables Pages
ContentSourceModule.php
1 <?php
2 /**
3  * Gentics Portal.Node PHP
4  * Author & Copyright (c) by Gentics Software GmbH
5  * sales@gentics.com
6  * http://www.gentics.com
7  * Licenses can be found in the LICENSE.txt file in the root-folder of this installation
8  * You must not use this software without a valid license agreement.
9  *
10  * Module for working with File System Content Renderer and Dynamic Content Renderer.
11  * Configuration example:
12  *'contentSource' => array(
13  * 'class' => 'site.common.modules.contentSource.ContentSourceModule',
14  * 'sourceSettings' => array(
15  * 'DynamicContentSource' => array(
16  * 'storageFolder' => '/var/www/gPortal/DCR'
17  * ),
18  * 'FileSystemContentSource' => array(
19  * 'sourceFolder' => '/var/www/gPortal/FSCR'
20  * ),
21  * ),
22  * 'sourceClass' => 'DynamicContentSource'
23  * )
24  */
25 class ContentSourceModule extends CWebModule
26 {
27  /**
28  * @var array Content source settings
29  */
30  public $sourceSettings;
31  /**
32  * @var string Content source class
33  */
34  public $sourceClass;
35 
36  /**
37  * @var string home page
38  */
39  public $homePage;
40 
41  /**
42  * This value is used when startpage for some folder doesnt exists
43  *
44  * @public string
45  **/
46  public $startPageFallback = 'index.html';
47 
48  /**
49  * Method of displaying startpage to user. Can take following values:
50  * false - redirect user to the page
51  * true - (no redirect - just display/include the page without changing the URL)
52  *
53  * @public string
54  **/
55  public $startPageDynamic = true;
56 
57  /**
58  * Name of content attribute for locale
59  * $localizedAttributeName . $locale
60  *
61  * @public string
62  **/
63  public $localizedAttributeName = 'startpageurl_';
64 
65  /**
66  * the number of seconds in which the cached value will expire. 0 means never expire.
67  * used for caching content personalisation attributes and modification time
68  *
69  * @var
70  */
71  public $cacheTime;
72 
73  /**
74  * an array that specifies the cache-control header of static files, looks like:
75  *
76  * array (
77  * 'image/jpeg' => 60 * 60 * 24 * 7,
78  * 'text/css' => 60 * 60 * 24 * 7,
79  * 'application/javascript' => 60 * 60
80  * // etc.
81  * )
82  *
83  * @var array
84  */
85  public $staticFileCacheControl;
86 
87  /**
88  * @var string content source object
89  */
90  private $_contentSource;
91 
92  /**
93  * Get object which represents Content Source
94  *
95  * @return ContentSource
96  */
97  public function getContentSource()
98  {
99  if (!$this->_contentSource) {
100  $settings = $this->sourceSettings[$this->sourceClass];
101  $settings['class'] = $this->sourceClass;
102  $this->_contentSource = Yii::createComponent($settings);
103  $this->_contentSource->init();
104  }
105  return $this->_contentSource;
106  }
107 
108 
109  /**
110  * Get static resource content. For example images, css, js
111  *
112  * @param string $path content path
113  *
114  * @return Content content
115  */
116  public function getContent($path)
117  {
118  return $this->getContentSource()->getContent($path);
119  }
120 
121  /**
122  * Module initial function
123  *
124  * @return void
125  */
126  public function init()
127  {
128  parent::init();
129  $this->setImport(
130  array(
131  'contentSource.components.*'
132  )
133  );
134  }
135 
136 
137  /**
138  * Tries to find a browser cache time by path from the config, see $staticFileCacheControl
139  *
140  * @param string $filename
141  * @return int cachetime
142  */
143  public function getBrowserCacheTimeByFileName($filename = null)
144  {
145  // return -1 if we didn't find any valid cache time in the config
146  $defaultStaticCacheTime = -1;
147 
148  if (!AppHelper::isNullOrEmptyString($filename) && !empty($this->staticFileCacheControl) && is_array($this->staticFileCacheControl)) {
149 
150  // get file mimetype
151  $mimetype = CFileHelper::getMimeTypeByExtension($filename);
152  // if we found a valid mimetype we search if we got a cache time specifies in the browser cache config
153  if (isset($this->staticFileCacheControl[$mimetype]) && is_numeric($this->staticFileCacheControl[$mimetype])) {
154  $defaultStaticCacheTime = $this->staticFileCacheControl[$mimetype];
155  }
156  }
157 
158  return $defaultStaticCacheTime;
159  }
160 }