VersionControl_SVN
[ class tree: VersionControl_SVN ] [ index: VersionControl_SVN ] [ all elements ]

Source for file example_tree.php

Documentation is available at example_tree.php

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4: */
  3. // +----------------------------------------------------------------------+
  4. // | PHP version 5                                                        |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 2004, Clay Loveless                                    |
  7. // | All rights reserved.                                                 |
  8. // +----------------------------------------------------------------------+
  9. // | This LICENSE is in the BSD license style.                            |
  10. // | http://www.opensource.org/licenses/bsd-license.php                   |
  11. // |                                                                      |
  12. // | Redistribution and use in source and binary forms, with or without   |
  13. // | modification, are permitted provided that the following conditions   |
  14. // | are met:                                                             |
  15. // |                                                                      |
  16. // |  * Redistributions of source code must retain the above copyright    |
  17. // |    notice, this list of conditions and the following disclaimer.     |
  18. // |                                                                      |
  19. // |  * Redistributions in binary form must reproduce the above           |
  20. // |    copyright notice, this list of conditions and the following       |
  21. // |    disclaimer in the documentation and/or other materials provided   |
  22. // |    with the distribution.                                            |
  23. // |                                                                      |
  24. // |  * Neither the name of Clay Loveless nor the names of contributors   |
  25. // |    may be used to endorse or promote products derived from this      |
  26. // |    software without specific prior written permission.               |
  27. // |                                                                      |
  28. // | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS  |
  29. // | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT    |
  30. // | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS    |
  31. // | FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE      |
  32. // | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,  |
  33. // | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
  34. // | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;     |
  35. // | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER     |
  36. // | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT   |
  37. // | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN    |
  38. // | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE      |
  39. // | POSSIBILITY OF SUCH DAMAGE.                                          |
  40. // +----------------------------------------------------------------------+
  41. // | Author: Clay Loveless <clay@killersoft.com>                          |
  42. // +----------------------------------------------------------------------+
  43. //
  44. // $Id$
  45. //
  46.  
  47. /*
  48.     This is a more complex example, that also illustrates the use of 
  49.     HTML_TreeMenu.
  50.     
  51.     In this example, we'll get a recusive list of files in a repository.
  52.     We will then loop through the files and build a dynamic HTML_TreeMenu
  53.     object for easy navigation.
  54. */
  55.  
  56. error_reporting(E_ALL ~E_DEPRECATED);
  57.  
  58. require_once 'VersionControl/SVN.php';
  59.  
  60. // Default options
  61. $base_url 'https://github.com/pear/VersionControl_SVN/trunk';
  62. $base_add '';
  63. if (isset($_SERVER['PATH_INFO'])) {
  64.     $base_add $_SERVER['PATH_INFO'];
  65. }
  66.  
  67. $cmd '';
  68. $cmd = isset($_GET['cmd']$_GET['cmd''list';
  69.  
  70. $options = array('fetchmode' => VERSIONCONTROL_SVN_FETCHMODE_ASSOC);
  71. $switches = array('R' => true);
  72. $args = array("{$base_url}{$base_add}");
  73.  
  74. try {
  75.     // Create svn object with subcommands we'll want
  76.     $svn VersionControl_SVN::factory(array('list''cat')$options);
  77.  
  78.     // A quickie sample of browsing a Subversion repository
  79.     if ($base_add != ''{
  80.         $source $svn->cat->run($args);
  81.         if (substr($base_add-4== '.php'{
  82.             highlight_string($source);
  83.         else {
  84.             echo '<pre>'.htmlentities($sourceENT_NOQUOTES)."</pre>\n";
  85.         }
  86.  
  87.     else {
  88.  
  89.         // TreeMenu setup
  90.         require_once 'HTML/TreeMenu.php';
  91.         // Change icons to appropriate names
  92.         // See HTML_TreeMenu docs for more details.
  93.         $foldericon 'aquafolder.gif';
  94.         $docicon 'bbedit_doc.gif';
  95.         $menu = new HTML_TreeMenu();
  96.         $node1 = new HTML_TreeNode(array('text' => 'VersionControl_SVN',
  97.                                         'icon' => $foldericon));
  98.  
  99.         $list $svn->list->run($args$switches);
  100.         foreach ($list['list'][0]['entry'as $item{
  101.             $dir dirname($item['name']);
  102.             if ($item['kind'!== 'file'{
  103.                 $icon $foldericon;
  104.                 $link '';
  105.             else {
  106.                 $icon $docicon;
  107.                 $link $_SERVER['PHP_SELF']."/" $item['name'];
  108.                 // don't need the link for the .
  109.                 $link str_replace('/.'''$link);
  110.             }
  111.             
  112.             if ($dir == '.'{
  113.                 // Adding to root level
  114.                 $obj basename($item['name']);
  115.                 $$obj $node1->addItem(new HTML_TreeNode(array('text' => $item['name']'icon' => $icon'link' => $link)));
  116.             else {
  117.                 // Get parent item
  118.                 $parent basename($dir);
  119.                 $obj basename($item['name']);
  120.                 $$obj = $$parent->addItem(new HTML_TreeNode(array('text' => $item['name']'icon' => $icon'link' => $link)));
  121.             }
  122.         }
  123.  
  124.         $menu->addItem($node1);
  125.  
  126.         // Create presentation class
  127.         $treeMenu = new HTML_TreeMenu_DHTML($menuarray('images' => 'images',
  128.                                                         'defaultClass' => 'treeMenuDefault'));
  129.  
  130.         ?>
  131.     <html>
  132.     <head>
  133.         <title>VersionControl_SVN Source Listing</title>
  134.         <script language="javascript" type="text/javascript" src="TreeMenu.js"></script>
  135.         <style type="text/css">
  136.         body, td, th {
  137.             font-family: verdana,arial,helvetica,sans-serif;
  138.             font-size: 80%;
  139.         }
  140.         .squeeze { line-height: 96%; font-size: xx-small; font-family:Verdana,Geneva,Arial; color: #999999; }
  141.         </style>
  142.     </head>
  143.     <body>
  144.     <h3>VersionControl_SVN Source Listing</h3>
  145.     <?php
  146.     $treeMenu->printMenu();
  147.     ?>
  148.  
  149.     <p>
  150.     <span class="squeeze">
  151.     Source listing driven by <a href="http://pear.php.net/package/HTML_TreeMenu">HTML_TreeMenu</a> and <a href="VersionControl_SVN_docs/index.html">VersionControl_SVN</a>
  152.     </span>
  153.     </p>
  154.     </body>
  155.     </html>
  156.     <?php
  157.     }
  158. catch (VersionControl_SVN_Exception $e{
  159.     echo "<pre>\n";
  160.     print_r($e->getMessage());
  161.     echo "</pre>\n";
  162. }
  163.  
  164. ?>

Documentation generated on Mon, 11 Mar 2019 15:58:56 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.