PageRenderTime 46ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/inc/bx/popoon/components/actions/bxcms.php

https://github.com/chregu/fluxcms
PHP | 331 lines | 216 code | 46 blank | 69 comment | 91 complexity | 985a6b57f7328f1569bc224276528538 MD5 | raw file
Possible License(s): GPL-2.0, BSD-3-Clause, Apache-2.0, LGPL-2.1
  1. <?php
  2. // +----------------------------------------------------------------------+
  3. // | popoon |
  4. // +----------------------------------------------------------------------+
  5. // | Copyright (c) 2001-2009 Liip AG |
  6. // +----------------------------------------------------------------------+
  7. // | Licensed under the Apache License, Version 2.0 (the "License"); |
  8. // | you may not use this file except in compliance with the License. |
  9. // | You may obtain a copy of the License at |
  10. // | http://www.apache.org/licenses/LICENSE-2.0 |
  11. // | Unless required by applicable law or agreed to in writing, software |
  12. // | distributed under the License is distributed on an "AS IS" BASIS, |
  13. // | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or |
  14. // | implied. See the License for the specific language governing |
  15. // | permissions and limitations under the License. |
  16. // +----------------------------------------------------------------------+
  17. // | Author: Christian Stocker <chregu@liip.ch> |
  18. // +----------------------------------------------------------------------+
  19. //
  20. // $Id$
  21. /**
  22. *
  23. * @author Christian Stocker <chregu@liip.ch>
  24. * @version $Id$
  25. * @package popoon
  26. */
  27. class popoon_components_actions_bxcms extends popoon_components_action {
  28. /**
  29. * Constructor
  30. *
  31. */
  32. function __construct(&$sitemap) {
  33. parent::__construct($sitemap);
  34. }
  35. function init($attribs) {
  36. parent::init($attribs);
  37. }
  38. function act() {
  39. // set YADIS Header
  40. if ($this->getParameterDefault("noAdminDisclosure") != "true") {
  41. $this->sitemap->setHeader("X-XRDS-Location", BX_WEBROOT . "admin/openid/xrds.xml");
  42. }
  43. // set X-PoweredBy
  44. if ($this->getParameterDefault("noPoweredBy") != "true") {
  45. $this->sitemap->setHeader("X-CMS-Powered-By", "Flux CMS " . BXCMS_VERSION.'/'.BXCMS_BUILD_DATE ." <http://flux-cms.org>");
  46. }
  47. // check for an id...
  48. $mode = "output";
  49. if (isset($_GET["admin"])) {
  50. $this->sitemap->options->popoonmap["admin"] = true;
  51. }
  52. if ($id = $this->getParameterDefault("id")) {
  53. $parts = bx_collections::getCollectionAndFileParts($id, $mode);
  54. $fulluri = $parts['coll']->getRequestById($parts['rawname']);
  55. $lang = $GLOBALS['POOL']->config->getOutputLanguage();
  56. } else {
  57. $fulluri = "/".$this->getAttrib("uri");
  58. //shorturl if it starts with a . or ~
  59. $firstChar = substr($fulluri,0,2);
  60. if ($firstChar == '/.' || $firstChar == '/~') {
  61. $sh = new bx_helpers_shorturl();
  62. $url = $sh->getUrlFromCode(substr($fulluri,2));
  63. if ($url) {
  64. header("Location: ".BX_WEBROOT."$url", true, 301);
  65. die();
  66. }
  67. }
  68. /* using _ as start of a (virtual)collection is not allowed for external requests
  69. * only for internal for example in bx_streams_blog
  70. * $xml = $p->getContentById("/","_all/index");
  71. */
  72. if (strpos($fulluri,"/__") !== false) {
  73. throw new BxPageNotFoundException(substr($_SERVER['REQUEST_URI'],1));
  74. }
  75. $mo = (strpos($fulluri, '/mo/') === 0);
  76. if ($GLOBALS['POOL']->config->mobileMode == 'true') {
  77. if ($mo || (isset($_COOKIE['isMobile']) && $_COOKIE['isMobile'] == "true")) {
  78. if (isset($_GET['isMobile']) && $_GET['isMobile'] == "false") {
  79. setcookie("isMobile", false, 0, "/");
  80. } else {
  81. setcookie("isMobile", "true", time() + 60 * 60 * 24 * 30 * 6, "/");
  82. $GLOBALS['POOL']->config->theme = "mobile";
  83. $GLOBALS['POOL']->config->themeCss = "main.css";
  84. }
  85. if ($mo) {
  86. $fulluri = substr($fulluri, 3);
  87. }
  88. }
  89. } else if ($mo) {
  90. //redirect to without $mo, if mobileMode is not enabled
  91. $fulluri = substr($fulluri, 3);
  92. header("Location: $fulluri", true, 301);
  93. die();
  94. }
  95. if (strpos($fulluri, ".") === false) {
  96. //if no / at the end of fulluri and no . in filename, we assume, it's a subcollection
  97. // and do redirect here
  98. if (substr($fulluri,-1) != "/") {
  99. header("Location: ".BX_WEBROOT.preg_replace("#^/#","",$fulluri)."/", true, 301);
  100. die();
  101. }
  102. $fulluri .= "index.html";
  103. }
  104. $req_fulluri = $fulluri;
  105. list($fulluri, $lang) = bx_collections::getLanguage($fulluri);
  106. if($GLOBALS['POOL']->config->getConfProperty('languageCookies') == 'true') {
  107. if(isset($_SESSION['lang']) && $_SESSION['lang'] != $lang) {
  108. header("Location: /" . $_SESSION['lang'] . $fulluri, true, 301);
  109. die();
  110. }
  111. // if the default language is requested specifically (if you change
  112. // from another language) redirect to the full uri without the language
  113. // prefix. If this is a POST request don't redirect, otherwise some existing
  114. // forms might break
  115. if((strpos($req_fulluri, '/'.BX_DEFAULT_LANGUAGE.'/') === 0
  116. || strpos($req_fulluri, BX_DEFAULT_LANGUAGE.'/') === 0)
  117. && empty($_POST)) {
  118. header("Location: " . $fulluri, true, 301);
  119. die();
  120. }
  121. }
  122. $GLOBALS['POOL']->config->setOutputLanguage($lang);
  123. //comma to GET parameter...
  124. if (($pos = strpos($fulluri,",")) !== false && !isset($_GET['nocomma']) && !$_GET['nocomma']) {
  125. $_gets = str_replace(",","&",substr($fulluri,$pos + 1));
  126. parse_str(str_replace('$_$',"/",$_gets),$vars);
  127. foreach($vars as $key => $value) {
  128. if (!isset($_REQUEST[$key])) {
  129. $_REQUEST[$key] = $value;
  130. $_GET[$key] = $value;
  131. }
  132. }
  133. $fulluri = substr($fulluri,0,$pos);
  134. }
  135. }
  136. $parts = bx_collections::getCollectionAndFileParts($fulluri, $mode);
  137. $collection = $parts['coll'] ;
  138. if (!$collection) {
  139. throw new Exception ("No collection object found");
  140. }
  141. if($GLOBALS['POOL']->config->advancedRedirect == 'true'){
  142. /*
  143. * userdir
  144. */
  145. $userdir = bx_resourcemanager::getFirstPropertyAndPath($fulluri,'redirect');
  146. if( $userdir !== NULL && $userdir['property'] == '{userdir}' ){
  147. $user = bx_helpers_perm::getUsername();
  148. if($user != ''){
  149. $fulluri = str_replace($userdir['path'], '', $fulluri);
  150. $fulluri = $userdir['path'].'/'.$user.$fulluri;
  151. $parts = bx_collections::getCollectionAndFileParts($fulluri, $mode);
  152. $collection = $parts['coll'];
  153. }
  154. }
  155. }
  156. /* Check for redirect
  157. * Old "normal" redirect ;)
  158. */
  159. $redirect = $collection->getProperty('redirect');
  160. if ( $redirect !== NULL && ($parts['rawname'] == 'index.html') && $redirect != '{userdir}' ) {
  161. // absolute path
  162. if (strpos($redirect, '/') === 0) {
  163. $fulluri = $redirect;
  164. } else {
  165. if(strpos($redirect, '.') === FALSE) {
  166. $fulluri = preg_replace("#[a-zA-Z_\-]+\.[a-z]+$#", sprintf("%s\\0", $redirect), $fulluri);
  167. } else {
  168. $fulluri = preg_replace("#[a-zA-Z_\-]+\.[a-z]+$#", $redirect, $fulluri);
  169. }
  170. }
  171. $parts = bx_collections::getCollectionAndFileParts($fulluri, $mode);
  172. $collection = $parts['coll'];
  173. }
  174. $filename = $parts['name'];
  175. $ext = $parts['ext'];
  176. $fileNumber = $parts['number'];
  177. $GLOBALS['POOL']->config->currentFileNumber = $fileNumber;
  178. if(!isset($_GET["admin"]) && ($collection === FALSE || !$collection->resourceExistsByRequest($filename,$ext) )) {
  179. /*
  180. * add <searchCollectionRecursive>true</searchCollectionRecursive>
  181. * to config.xml to turn on recursive search for existing collections
  182. */
  183. if($GLOBALS['POOL']->config->searchCollectionRecursive == 'true'){
  184. /**
  185. * lookuop recursive for an existing html collection
  186. */
  187. while($collection === FALSE || !$collection->resourceExistsByRequest($filename,$ext) ) {
  188. $tmp = explode('/',$fulluri);
  189. array_pop($tmp);
  190. $count = count($tmp);
  191. $fulluri = implode('/',$tmp);
  192. $checkuri = $fulluri.'/index.html';
  193. $parts = bx_collections::getCollectionAndFileParts($checkuri, $mode);
  194. $collection = $parts['coll'];
  195. $filename = $parts['name'];
  196. $ext = $parts['ext'];
  197. // break on top
  198. // some installation do not have a /index.html
  199. // so lets redirect to root
  200. if($count == 0) {
  201. header("Location: /");
  202. die();
  203. }
  204. }
  205. if($collection === FALSE || !$collection->resourceExistsByRequest($filename,$ext) ) {
  206. throw new BxPageNotFoundException($this->getAttrib("uri"));
  207. }
  208. $redirect = str_replace('index.html','',$checkuri);
  209. header("Location: $redirect");
  210. die();
  211. }
  212. throw new BxPageNotFoundException($this->getAttrib("uri"));
  213. } else {
  214. //call postHandles...
  215. //FIXME: to be implemented...
  216. if ($filename == "") {
  217. $plugins = $collection->getPluginMapByRequest("/",$ext);
  218. } else {
  219. $plugins = $collection->getPluginMapByRequest($filename,$ext);
  220. }
  221. $retcode = 0;
  222. if (isset($_POST['bx']) && isset($_POST['bx']['plugins'])){
  223. foreach($plugins as $id => $plugin) {
  224. if (isset($_POST['bx']['plugins'][$plugin['plugin']->name]) && isset($_POST['bx']['plugins'][$plugin['plugin']->name]['_all'])) {
  225. $data = bx_helpers_globals::stripMagicQuotes($_POST);
  226. foreach ($data['bx']['plugins'][$plugin['plugin']->name] as $name => $value) {
  227. $data[$name] = $value;
  228. unset ($data['bx']['plugins'][$plugin['plugin']->name][$name]);
  229. }
  230. unset($data['bx']['plugins'][$plugin['plugin']->name]);
  231. if (count($data['bx']['plugins']) == 0) {
  232. unset ($data['bx']['plugins']);
  233. if (count($data['bx']) == 0) {
  234. unset ($data['bx']);
  235. }
  236. }
  237. $retcode = $plugin['plugin']->handlePublicPost($collection->uri,$id,$data);
  238. } else if (isset($_POST['bx']['plugins'][$plugin['plugin']->name])) {
  239. $data = bx_helpers_globals::stripMagicQuotes($_POST['bx']['plugins'][$plugin['plugin']->name]);
  240. $retcode = $plugin['plugin']->handlePublicPost($collection->uri,$id,$data);
  241. }
  242. }
  243. }
  244. bx_helpers_uri::defineWebrootLang($lang);
  245. define('BX_WEBROOT_LANG_W', substr(BX_WEBROOT_LANG,0,-1));
  246. if ($GLOBALS['POOL']->config->dynamicHttpExpires == "true") {
  247. $expires = bx_resourcemanager::getFirstProperty($collection->uri,"expires");
  248. if ($expires === NULL) {
  249. $expires = 10;
  250. }
  251. } else {
  252. $expires = 10;
  253. }
  254. $GLOBALS['POOL']->config->uniqueId = bx_resourcemanager::getProperty($collection->uri,"unique-id");
  255. $GLOBALS['POOL']->config->expires = $expires;
  256. $a = array(
  257. "collection" => $collection,
  258. "collectionUri" => $collection->uri,
  259. "filename" => $filename,
  260. "ext" => $ext,
  261. "requestUri" => $fulluri,
  262. "mode" => $mode,
  263. 'lang' => $lang,
  264. 'locale' => $GLOBALS['POOL']->config->getOutputLocale(),
  265. 'webrootLang' => BX_WEBROOT_LANG,
  266. 'fileNumber' => $fileNumber
  267. );
  268. $a = array_merge($a,$collection->getPipelineParametersByRequest($filename,$ext));
  269. $a = array_merge($a,$collection->getPipelineProperties());
  270. //Do we need that?
  271. /*
  272. foreach( $collection->getFirstResource($filename,$ext)->getAllProperties(BX_PROPERTY_PIPELINE_NAMESPACE) as $p) {
  273. $a[$p['name']] = $p['value'];
  274. }*/
  275. if (!isset($a['xslt'])) {
  276. @session_start();
  277. if (!($_SESSION['_authsession']['registered'] && isset($_GET['XML']) && $_GET['XML'] == 1)) {
  278. throw new Exception ("No xslt provided. Either this URL should only be accessed internally and therefore correct,
  279. or the sysadmin made a mistake");
  280. }
  281. }
  282. return $a;
  283. }
  284. }
  285. }