PageRenderTime 45ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/master/administrator/components/com_multisites/patches/ccboard/check_config.php

https://github.com/sherdog/GitWitty
PHP | 180 lines | 63 code | 22 blank | 95 comment | 15 complexity | 9a008e4151a9550299ab7b0aa0e5a0c0 MD5 | raw file
  1. <?php
  2. /**
  3. * @file check_config.php
  4. * @brief Check if the CCBoard configuration wrapper is present.
  5. * @version 1.2.26
  6. * @author Edwin CHERONT (e.cheront@jms2win.com)
  7. * Edwin2Win sprlu (www.jms2win.com)
  8. * @copyright Joomla Multi Sites
  9. * Single Joomla! 1.5.x installation using multiple configuration (One for each 'slave' sites).
  10. * (C) 2008 Edwin2Win sprlu - all right reserved.
  11. * @license This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License
  13. * as published by the Free Software Foundation; either version 2
  14. * of the License, or (at your option) any later version.
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  22. * A full text version of the GNU GPL version 2 can be found in the LICENSE.php file.
  23. * @par History:
  24. * - V1.2.17 03-NOV-2009: Initial version
  25. */
  26. defined('JPATH_MUTLISITES_COMPONENT') or die( 'Restricted access' );
  27. //------------ jms2win_checkCCBoardCfgWrapper ---------------
  28. /**
  29. * check if following lines are present:
  30. * - if ( defined( 'MULTISITES_ID') ...
  31. * is present
  32. */
  33. function jms2win_checkCCBoardCfgWrapper( $model, $file)
  34. {
  35. $filename = JPath::clean( JPATH_ROOT.DS.$file);
  36. if ( !file_exists( $filename)) {
  37. return '[IGNORE]|File Not Found';
  38. }
  39. $str = file_get_contents( $filename);
  40. // if 'MULTISITES_ID' is present
  41. $pos = strpos( $str, 'MULTISITES_ID');
  42. if ($pos === false) $wrapperIsPresent = false;
  43. else $wrapperIsPresent = true;
  44. $result = "";
  45. $rc = '[OK]';
  46. if ( !$wrapperIsPresent) {
  47. $rc = '[NOK]';
  48. $result .= JText::_( 'The configuration wrapper is not present in the MASTER ccboard-config.php file.');
  49. $result .= '|[ACTION]';
  50. $result .= '|Add 6 lines containing the routing wrapper to the slave site.';
  51. }
  52. return $rc .'|'. $result;
  53. }
  54. //------------ jms2win_actionCCBoardCfgWrapper ---------------
  55. /**
  56. * @brief Install the patch
  57. */
  58. function jms2win_actionCCBoardCfgWrapper( $model, $file)
  59. {
  60. $parts = explode( DS, dirname(__FILE__));
  61. array_pop( $parts );
  62. $patch_dir = implode( DS, $parts );
  63. include_once( $patch_dir .DS. 'joomla' .DS. 'patchloader.php');
  64. $patchStr = jms2win_loadPatch( '..' .DS. 'ccboard' .DS. 'patch_config.php');
  65. if ( $patchStr === false) {
  66. return false;
  67. }
  68. // $filename = JPATH_ROOT.DS.$file;
  69. $filename = JPath::clean( JPATH_ROOT.DS.$file);
  70. $content = file_get_contents( $filename);
  71. if ( $content === false) {
  72. return false;
  73. }
  74. // Search/Replace the statement
  75. /*
  76. ===========
  77. Search for:
  78. ===========
  79. ........
  80. ........
  81. class ccboardConfig {
  82. {
  83. ........
  84. ........
  85. ........
  86. }
  87. ?>
  88. ===========
  89. and Replace by:
  90. ===========
  91. ........
  92. ........
  93. //_jms2win_begin v1.2.26
  94. if ( defined( 'MULTISITES_ID')
  95. && file_exists( dirname(__FILE__) .DS. 'ccboard-config.' .MULTISITES_ID. '.php')) {
  96. require_once( dirname(__FILE__) .DS. 'ccboard-config.' .MULTISITES_ID. '.php');
  97. } else if ( !class_exists( 'ccboardConfig')) {
  98. //_jms2win_end
  99. class ccboardConfig {
  100. {
  101. ........
  102. ........
  103. ........
  104. }
  105. //_jms2win_begin
  106. }
  107. //_jms2win_end
  108. ?>
  109. */
  110. // ------------- Patch definition ----------------
  111. /* ....\n
  112. \n .... class ccboardConfig { ...
  113. p0 p1
  114. \n .... ?>;
  115. p6 p7
  116. Produce
  117. begin -> p0 + INSERT PATCH + p0 -> p6 + "}" + p6 -> end
  118. */
  119. // p1: Search for "acesef_configuration"
  120. $p1 = strpos( $content, 'ccboardConfig');
  121. if ( $p1 === false) {
  122. return false;
  123. }
  124. // P0: Go to Begin of line
  125. for ( $p0 = $p1; $p0 > 0 && $content[$p0] != "\n"; $p0--);
  126. $p0++;
  127. // p7: Search for '? >'
  128. $p7 = strpos( $content, '?' . '>', $p1);
  129. if ( $p7 === false) {
  130. return false;
  131. }
  132. // P6: Go to Begin of line
  133. for ( $p6=$p7; $p6 > 0 && $content[$p6] != "\n"; $p6--);
  134. $p6++;
  135. // ------------- Compute the results ----------------
  136. // Here, we have found the statement to patch
  137. $result = substr( $content, 0, $p0)
  138. . $patchStr
  139. . substr( $content, $p0, $p6-$p0)
  140. . "//_jms2win_begin\n"
  141. . "}\n"
  142. . "//_jms2win_end\n"
  143. . substr( $content, $p6)
  144. ;
  145. // ------------- Write the PATCH results ----------------
  146. // Write the new content
  147. jimport('joomla.filesystem.file');
  148. if ( !JFile::write( $filename, $result)) {
  149. return false;
  150. }
  151. return true;
  152. }