PageRenderTime 49ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/scripts/index.php

https://github.com/agnesrambaud/yacs
PHP | 197 lines | 48 code | 37 blank | 112 comment | 12 complexity | 7bc0f3817ddda4ca2259e018159576e1 MD5 | raw file
  1. <?php
  2. /**
  3. * handling PHP scripts
  4. *
  5. * While YACS is aiming to ease content publishing and sharing, we are thinking that the same objective
  6. * should be targeted for the software itself.
  7. *
  8. * More specifically, we have designed this module with the manipulation of numerous php script files in mind:
  9. * - to derive on-line documentation from php comments
  10. * - to list reference scripts that are shared on a server
  11. * - to visualize differences between reference and running scripts
  12. * - to suggest on software updates from a reference server
  13. *
  14. * This module is based on several simple patterns:
  15. * - the remote reference pattern is used to synchronize one server with one reference server
  16. * - the local reference pattern is used to build the documentation and to publish shared scripts
  17. *
  18. * [title]Update your scripts from a remote reference repository[/title]
  19. *
  20. * The remote reference pattern consists of scanning a remote server to build a set of staging files.
  21. * After having setup the address of the reference server (through [script]scripts/configure.php[/script]), the webmaster
  22. * will have to activate the staging script ([script]scripts/stage.php[/script]).
  23. * The script will fetch the index of reference scripts (in [code]footprints.php[/code]), and compare its content
  24. * to the actual set of running scripts.
  25. * For each running script having a diverging md5 signature, the script will cache the reference version
  26. * into [code]scripts/staging[/code].
  27. * As a result, at the end of the staging process:
  28. * - all running scripts will have been compared to the reference scripts
  29. * - for each non-matching file, a staging version will have been prepared
  30. *
  31. * After the staging step the update itself can take place by launching [script]scripts/update.php[/script].
  32. * First of all, this script displays the list of staging files, and offer the opportunity to read the new version
  33. * or to list differences.
  34. * The diff algorithm has been implemented into [script]scripts/scripts.php[/script] for that purpose.
  35. * To actually update the system, [script]scripts/update.php[/script] rename old versions as '.bak', and move
  36. * new versions from the staging directory to their final location.
  37. *
  38. * Aside from the new scripts other updates will take place thanks to following steps:
  39. * - [script]scripts/update.php[/script] also switches the server off
  40. * - [script]control/scan.php[/script] will rebuild all hooks, to possibly take into account new hooks downloaded from the reference server
  41. * - [script]control/setup.php[/script] will check the database structure, and create it if necessary
  42. * - [script]scripts/run_once.php[/script] is launched, to possibly apply big changes to an existing database
  43. * - [script]control/index.php[/script] displays the control panel and gives the opportunity to switch the server on again.
  44. *
  45. * [title]Make a reference repository of your running scripts[/title]
  46. *
  47. * The local reference pattern consists of building a safe repository of scripts and of related information
  48. * page. Once one server has been setup correctly, maybe after some script modifications, skin updates, etc., the
  49. * webmaster (actually, any associate) may wish to freeze this configuration as the reference one.
  50. * By activating the building script ([script]scripts/build.php[/script]), he (or she) will copy reference scripts to a safe place
  51. * (scripts/reference). These scripts will be scanned for structured comments (see [script]scripts/phpdoc.php[/script]) and the
  52. * related documentation will be generated automatically.
  53. * An index of reference scripts, including file names, dates and an md5 hash code, will be generated as well
  54. * for further checking by other servers.
  55. * As a result, at the end of the building process:
  56. * - a complete set of reference scripts is saved in their 'sand box'
  57. * - the documentation for these scripts is published
  58. * - an inventory of these files is published (scripts/reference/footprints.php)
  59. *
  60. * How to define that a script is to be included in the reference set? Simple: put the keyword &arobas;reference
  61. * on a single line of the first php comment of the script.
  62. *
  63. * [title]How to use these mechanisms in your particular situation?[/title]
  64. *
  65. * Despite the simplicity of these patterns, we are quite confindent that most webmasters will appreciate them over time.
  66. * At least, they enable smooth updates of running scripts for most (minor) modifications.
  67. * Moreover, these patterns will successfully frequent models of web deployments:
  68. *
  69. * - Standalone servers will benefit from the building script to at least generate and update a (tiny?) set
  70. * of useful pages to document the software. Note that these pages are fully indexed to enable free-text searches.
  71. *
  72. * - Servers connected to the Internet will have the opportunity to track YACS enhancements quite easily, simply by
  73. * checking from time to time one the public reference servers.
  74. *
  75. * - Groups of servers managed by a single webmasters may be linked to a single private reference server. It is likely
  76. * that various organizations will develop additional scripts on the YACS platform. They may use the remote reference
  77. * pattern to distribute these scripts internally to slave servers.
  78. *
  79. * @author Bernard Paques
  80. * @author GnapZ
  81. * @reference
  82. * @license http://www.gnu.org/copyleft/lesser.txt GNU Lesser General Public License
  83. */
  84. // include the global declarations
  85. include_once '../shared/global.php';
  86. include_once 'scripts.php';
  87. // address of the reference server, if any
  88. Safe::load('parameters/scripts.include.php');
  89. // load localized strings
  90. i18n::bind('scripts');
  91. // load the skin
  92. load_skin('scripts');
  93. // the title of the page
  94. $context['page_title'] = i18n::s('Server software');
  95. // associates may trigger incremental upgrades, but not at reference servers
  96. if(Surfer::is_associate() && !file_exists('reference/footprints.php')) {
  97. // upgrade
  98. $context['text'] .= Skin::build_block(i18n::s('Incremental upgrades'), 'title');
  99. // the status message
  100. Safe::load('footprints.php');
  101. if(isset($generation['date']) && $generation['date'])
  102. $context['text'] .= '<p>'.sprintf(i18n::s('Last update took place on %s'), $generation['date']).'</p>'."\n";
  103. unset($generation);
  104. // ensure we have a reference server
  105. if(!isset($context['reference_server']) || !$context['reference_server'])
  106. $context['reference_server'] = i18n::s('www.yacs.fr');
  107. // offer to upgrade
  108. $context['text'] .= '<p>'.Skin::build_link('scripts/stage.php', i18n::s('Update the software'))."</p>\n";
  109. }
  110. // get the page from the php documentation, if any
  111. include_once 'phpdoc.php';
  112. $item = PhpDoc::get('index');
  113. if($item) {
  114. $items = array();
  115. // the list of things to do
  116. $items[] = Skin::build_link(Scripts::get_url('todo'), i18n::s('To do'), 'basic');
  117. // the list of testers
  118. $items[] = Skin::build_link(Scripts::get_url('testers'), i18n::s('Testers'), 'basic');
  119. // the list of authors
  120. $items[] = Skin::build_link(Scripts::get_url('authors'), i18n::s('Authors'), 'basic');
  121. // the list of licenses
  122. $items[] = Skin::build_link(Scripts::get_url('licenses'), i18n::s('Licenses'), 'basic');
  123. $context['components']['tools'] = Skin::build_box(i18n::s('See also'), Skin::finalize_list($items, 'tools'), 'extra');
  124. // splash message
  125. $text = '<p>'.i18n::s('Click on any link below to access the documentation extracted from each script (phpDoc).')."</p>\n";
  126. // tree of links to documentation pages
  127. $text .= Codes::beautify($item['content']);
  128. // link to some other server
  129. } else {
  130. $text = '<p>'.i18n::s('The complete documentation is available at the following server:').'</p>';
  131. // link to the existing reference server, or to the original server
  132. if(!isset($context['reference_server']) || !$context['reference_server'])
  133. $context['reference_server'] = i18n::s('www.yacs.fr');
  134. $text .= '<p>'.Skin::build_link('http://'.$context['reference_server'].'/', $context['reference_server'], 'external')."</p>\n";
  135. }
  136. // documentation box
  137. $context['text'] .= Skin::build_box(i18n::s('On-line Documentation'), $text);
  138. // page tools
  139. if(Surfer::is_associate()) {
  140. // patch the server
  141. $context['page_tools'][] = Skin::build_link('scripts/upload.php', i18n::s('Apply a patch'), 'basic');
  142. // signal scripts to run once, if any
  143. if(Safe::glob($context['path_to_root'].'scripts/run_once/*.php') !== FALSE)
  144. $context['page_tools'][] = Skin::build_link('scripts/run_once.php', i18n::s('Run once'), 'basic');
  145. // stage from reference server
  146. $context['page_tools'][] = Skin::build_link('scripts/stage.php', i18n::s('Update the software'), 'basic');
  147. // set the reference server
  148. $context['page_tools'][] = Skin::build_link('scripts/configure.php', i18n::s('Configure'), 'basic');
  149. // check script signatures
  150. $context['page_tools'][] = Skin::build_link('scripts/check.php', i18n::s('Check software integrity'), 'basic');
  151. // validate scripts
  152. $context['page_tools'][] = Skin::build_link('scripts/validate.php', i18n::s('Validate PHP syntax'), 'basic');
  153. // build the reference here
  154. $context['page_tools'][] = Skin::build_link('scripts/build.php', i18n::s('Build the software'), 'basic');
  155. }
  156. // referrals, if any
  157. $context['components']['referrals'] = Skin::build_referrals('scripts/index.php');
  158. // render the skin
  159. render_skin();
  160. ?>