sTEFANs Subversion Web Contol (SWC)
Inc
[ class tree: Swc ] [ index: Swc ] [ all elements ]

Source for file utils.inc.php

Documentation is available at utils.inc.php

  1. <?php
  2. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  3. SVN Web Control
  4. Copyright ©2006 by sTEFANs
  5. Created on 27.02.2006
  6. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or
  10. (at your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Free Software
  19. Foundation, Inc., 59 Temple Place - Suite 330,
  20. Boston, MA 02111-1307, USA.
  21. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  22. */
  23.  
  24. /**
  25.  * This file provides some basic service routines.
  26.  * 
  27.  * @package Swc
  28.  * @subpackage Inc
  29.  * @author Stefan Schraml
  30.  * @copyright Copyright ©2006 by sTEFANs
  31.  * @license http://opensource.org/licenses/lgpl-license.php GNU General Public License
  32.  * @version v1.1.0
  33.  * @since v1.0.0
  34.  */
  35.  
  36. /** Common definitions */
  37. require_once('var.inc.php');
  38.  
  39.     /** 
  40.      * Returns the <b>SwcConfigFactory</b> that should be used.
  41.      * The config factory is placed within the file applied as
  42.      * <i>config</i> argument to swc URL. If SWC is invoked
  43.      * without argument, <b>STD_CONFIG_FILE</b> is used instead.
  44.      * The <b>SwcConfigFactory</b>as provided by <b>GetSwcConfigFactory</b>
  45.      * of the used file is returned.
  46.      * @return <b>SwcConfigFactory</b> Config factory.
  47.      * @see GetSwcConfigFactory
  48.      * @see SwcConfigFactory
  49.      * @see SwcConfig
  50.      * 
  51.      * @since v1.0.0
  52.      */
  53.     function GetConfigFactory(){
  54.         if (isset($_SESSION[IDX_CONFIG_FILE])){
  55.             $config_file $_SESSION[IDX_CONFIG_FILE];
  56.             require_once($config_file);
  57. //    echo "Requires $config_file<br/>";
  58.         else {
  59.             require_once(STD_CONFIG_FILE);
  60. //    echo 'Requires '.STD_CONFIG_FILE.'<br/>';
  61.         }
  62.         return GetSwcConfigFactory();
  63.     }
  64.     
  65.     /** 
  66.      * Returns the active <b>SwcConfig</b>.
  67.      * The active config is either retrieved by
  68.      * the current applied <b>SwcConfigFactory</b>.
  69.      * If more than one <b>SwcConfig</b> is found,
  70.      * the selected config is determined by project name
  71.      * given in <i>$_SESSION[IDX_SEL_PROJECT]</i>.
  72.      * @return <b>SwcConfig</b> Configuration of the active project
  73.      *  or NULL if no config was found.
  74.      * @see SwcConfig
  75.      * @see SwcConfigFactory
  76.      * @see GetConfigFactory
  77.      * 
  78.      * @since v1.0.0
  79.      */
  80.     function GetSelectedConfig(){        
  81.         $fab GetConfigFactory();
  82.         $configs $fab->GetSwcConfigs();
  83.         if (count($configs== 1){
  84.             return $configs[0];
  85.         }
  86.         
  87.         if (isset($_SESSION[IDX_SEL_PROJECT])){
  88.             $idx 0;
  89.             while ($idx count($configs&& 
  90.                         (strcmp($configs[$idx]->GetProjectName()$_SESSION[IDX_SEL_PROJECT]!= 0)){
  91.                 $idx++;
  92.             }
  93.             if ($idx count($configs)){
  94.                 return $configs[$idx];
  95.             }
  96.         }
  97.         return NULL;
  98.     }
  99.     
  100.     /** 
  101.      * Returns an array of all available <b>SwcConfig</b>s.
  102.      * @return array of <b>SwcConfig</b> All available configs
  103.      *  of the current <b>SwcConfigFactory</b>
  104.      *  or an empty array if no further configs are given.
  105.      * @see SwcConfig
  106.      * @see SwcConfigFactory
  107.      * @see GetConfigFactory
  108.      * 
  109.      * @since v1.0.0
  110.      */
  111.     function GetAllConfigs(){
  112.         // get config for selected project from config factory
  113.                 
  114.         $config_array array();
  115.         $fab GetConfigFactory();
  116.         if ($fab != NULL){
  117.             $configs $fab->GetSwcConfigs();
  118.             if ($configs != NULL && is_array($configs)){
  119.                 $idx 0;
  120.                 foreach($configs as $config){
  121.                         $config_array[$config;
  122.                 }
  123.             }
  124.         }
  125.         return $config_array;
  126.     }
  127.     
  128.     /** 
  129.      * Determines whether the webspace for the selected config
  130.      * is already checked aout and available.
  131.      * If no config is applied (<b>GetSelectedConfig</b> returns NULL)
  132.      * also false is returned.
  133.      * @return boolean True if the webspace is availble, false otherwise.
  134.      * @see GetSelectedConfig
  135.      * @see SwcConfig
  136.      * 
  137.      * @since v1.0.0
  138.      */
  139.     function IsWebspaceCheckedOut(){
  140.         $config GetSelectedConfig();
  141.         if ($config == NULL){
  142.             return false;
  143.         }
  144.         
  145.         $ws_root $config->GetWebspaceRootDir();
  146.         $ws_root trim($ws_root);
  147.         if ($ws_root != NULL && substr($ws_rootstrlen($ws_root)-11!= '/'){
  148.             $ws_root .= '/';
  149.         
  150.         return (file_exists($ws_root.'.svn'));
  151.     }
  152.     
  153.     /** 
  154.      * HTML friendly debug output of an array.
  155.      * @param array $array Array to print
  156.      * @param string $name Name of the array, also printed.
  157.      * 
  158.      * @since v1.0.0
  159.      */
  160.     function PrintDebugArray($array$name ""){
  161.         if (is_array($array)){
  162.             if (strlen($name)>0)
  163.                 echo "<b>$name:</b><br/>";
  164.             echo "<pre>\n";
  165.             print_r($array);
  166.             echo "\n</pre>\n";
  167.         else if ($array == NULL)
  168.             echo "Array $name is NULL.<br/>\n";
  169.         else if (count($array== 0)
  170.             echo "Array $name is empty.<br/>\n";
  171.         else
  172.             echo $array;
  173.     }
  174.     
  175.     /**
  176.      * Creates a string from given parameter that can
  177.      * savely be used for paths, repository names, etc.
  178.      * The transformed text contains only small letters
  179.      * from <i>a</i> to <i>z</i> and digits from
  180.      * <i>0</i> to <i>9</i>, other characters
  181.      * are changed to underscores.
  182.      * @param string $text String to be converted.
  183.      * @return string    Transformed text
  184.      * 
  185.      * @since v1.1.0
  186.      */
  187.     function CreateSystemFriendlyString($text){
  188.         $tmp_text trim($text);
  189.         $tmp_text strtolower($tmp_text);
  190.         $transformed_text preg_replace('/[^a-z0-9]/'' '$tmp_text);
  191.         $transformed_text trim($transformed_text);
  192.         $rep '_';
  193.         $transformed_text str_replace(' '$rep$transformed_text);    
  194.         return $transformed_text;
  195.     }
  196. ?>

Documentation generated on Fri, 03 Nov 2006 18:45:07 +0100 by phpDocumentor 1.3.0RC6
for sTEFANs POWERED BY eBC.bz