PageRenderTime 52ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/components/com_jfusionplugins/dokuwiki/helper.php

http://jfusion.googlecode.com/
PHP | 161 lines | 93 code | 21 blank | 47 comment | 19 complexity | 5c2f56b200bbedb1acf60269f2e3fc6d MD5 | raw file
Possible License(s): Apache-2.0
  1. <?php
  2. /**
  3. *
  4. * PHP version 5
  5. *
  6. * @category JFusion
  7. * @package JFusionPlugins
  8. * @subpackage Dokuwiki
  9. * @author JFusion Team <webmaster@jfusion.org>
  10. * @copyright 2008 JFusion. All rights reserved.
  11. * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
  12. * @link http://www.jfusion.org
  13. */
  14. // no direct access
  15. defined('_JEXEC') or die('Restricted access');
  16. if (!class_exists('Dokuwiki')) {
  17. require_once dirname(__FILE__) . DS . 'dokuwiki.php';
  18. }
  19. /**
  20. * JFusion Helper Class for Dokuwiki
  21. *
  22. * @category JFusion
  23. * @package JFusionPlugins
  24. * @subpackage Dokuwiki
  25. * @author JFusion Team <webmaster@jfusion.org>
  26. * @copyright 2008 JFusion. All rights reserved.
  27. * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
  28. * @link http://www.jfusion.org
  29. */
  30. class JFusionHelper_dokuwiki
  31. {
  32. /**
  33. * Returns the name for this plugin
  34. *
  35. * @return string
  36. */
  37. function getJname() {
  38. return 'dokuwiki';
  39. }
  40. /**
  41. * Defines constants required by Dokuwiki
  42. *
  43. * @param $nosession boolean to set the NOSESSION constant; false by default
  44. */
  45. function defineConstants($nosession = false) {
  46. $share =& Dokuwiki::getInstance($this->getJname());
  47. $conf =& $share->getConf();
  48. $params = JFusionFactory::getParams($this->getJname());
  49. $source_url = $params->get('source_url');
  50. $doku_rel = preg_replace('#(\w{0,10}://)(.*?)/(.*?)#is', '$3', $source_url);
  51. $doku_rel = preg_replace('#//+#', '/', "/$doku_rel/");
  52. if (!defined('DOKU_REL')) {
  53. define('DOKU_REL', $doku_rel);
  54. }
  55. if (!defined('DOKU_URL')) {
  56. define('DOKU_URL', $source_url);
  57. }
  58. if (!defined('DOKU_BASE')) {
  59. define('DOKU_BASE', DOKU_URL);
  60. }
  61. if ($nosession && !defined('NOSESSION')) {
  62. define('NOSESSION', 1);
  63. }
  64. if (!defined('DOKU_COOKIE')) {
  65. define('DOKU_COOKIE', 'DW'.md5(DOKU_REL.(($conf['securecookie'])?$_SERVER['SERVER_PORT']:'')));
  66. }
  67. }
  68. /**
  69. * Retrieves, sets, and returns Dokuwiki's cookie salt
  70. * @return string cookie salt
  71. */
  72. function getCookieSalt() {
  73. static $dokuwiki_cookie_salt;
  74. if (empty($dokuwiki_cookie_salt)) {
  75. $params = JFusionFactory::getParams($this->getJname());
  76. $source_path = $params->get('source_path');
  77. $share =& Dokuwiki::getInstance($this->getJname());
  78. $conf =& $share->getConf();
  79. $data_dir = (isset($conf['savedir'])) ? $source_path . DS . $conf['savedir'] : $source_path . DS . 'data';
  80. //get the cookie salt file
  81. $saltfile = $data_dir . DS . 'meta' . DS .'_htcookiesalt';
  82. jimport('joomla.filesystem.file');
  83. $dokuwiki_cookie_salt = JFile::read($saltfile);
  84. if(empty($dokuwiki_cookie_salt)){
  85. $dokuwiki_cookie_salt = uniqid(rand(),true);
  86. JFile::write($saltfile,$dokuwiki_cookie_salt);
  87. }
  88. }
  89. return $dokuwiki_cookie_salt;
  90. }
  91. /**
  92. * Retrieves, sets, and returns Dokuwiki's Version
  93. * @return string version
  94. */
  95. function getVersion($v='version') {
  96. static $dokuwiki_version;
  97. if (empty($dokuwiki_version)) {
  98. $params = JFusionFactory::getParams($this->getJname());
  99. $source_path = $params->get('source_path');
  100. jimport('joomla.filesystem.file');
  101. $file_version = JFile::read($source_path.DS.'VERSION');
  102. $matches = array();
  103. if (preg_match('#([a-z]*)([0-9]*-[0-9]*-[0-9]*)([a-z]*)#is' , $file_version, $matches)) {
  104. list($fullversion, $rc, $version, $sub) = $matches;
  105. $dokuwiki_version['full'] = $fullversion;
  106. $dokuwiki_version['version'] = $version.$rc.$sub;
  107. }
  108. }
  109. if (isset($dokuwiki_version[$v])) {
  110. return $dokuwiki_version[$v];
  111. }
  112. return null;
  113. }
  114. function getConfigPath($path = false) {
  115. static $config_path;
  116. if (empty($config_path)) {
  117. $params =& JFusionFactory::getParams($this->getJname());
  118. $source_path = $params->get('source_path');
  119. $config_path = (empty($path)) ? $source_path : $path;
  120. //make sure the source path ends with a DS
  121. if (substr($path, -1) != DS) {
  122. $config_path .= DS;
  123. }
  124. //standard config path
  125. $config_path .= 'conf' . DS;
  126. //check to see if conf directory is located somewhere else
  127. if (file_exists($source_path . DS . 'inc' . DS . 'preload.php')) {
  128. include_once $source_path . DS . 'inc' . DS . 'preload.php';
  129. if (defined('DOKU_CONF')) {
  130. $config_path = DOKU_CONF;
  131. //make sure we have a ending DS
  132. if (substr($config_path, -1) != DS) {
  133. $config_path .= DS;
  134. }
  135. }
  136. }
  137. }
  138. return $config_path;
  139. }
  140. }