Don't like ads? PRO users don't see any ads ;-)
Guest

kguest

By: a guest on Oct 3rd, 2008  |  syntax: None  |  size: 22.17 KB  |  hits: 73  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Index: PHPConfig.php
  2. ===================================================================
  3. RCS file: /repository/pear/Gtk2_PHPConfig/PHPConfig.php,v
  4. retrieving revision 1.2
  5. diff -u -b -B -r1.2 PHPConfig.php
  6. --- PHPConfig.php       8 Feb 2006 17:26:55 -0000       1.2
  7. +++ PHPConfig.php       3 Oct 2008 23:38:31 -0000
  8.  -3,6 +3,8 @@
  9.  /**
  10.   * Class for GUI-based configuration of a php.ini file
  11.   *
  12. + * PHP Version 5
  13. + *
  14.   * This class is based on the PHP-Gtk2 extension and provides a
  15.   * user-friendly interface for editing php.ini files. All the possible
  16.   * configuration options have been defined in a separate XML file .
  17.  -28,9 +30,19 @@
  18.   * @package     PHPConfig
  19.   * @author      Anant Narayanan <anant@php.net>
  20.   * @license     http://www.gnu.org/copyleft/lesser.html  LGPL License 2.1
  21. + * @link     http://pear.php.net/package/Gtk2_PHPConfig
  22.   *
  23.   */
  24.  
  25. +/**
  26. + * Gtk2_PHPConfig
  27. + *
  28. + * @category Gtk2
  29. + * @package  PHPConfig
  30. + * @author   Anant Narayanan <anant@php.net>
  31. + * @license  http://www.gnu.org/copyleft/lesser.html  LGPL License 2.1
  32. + * @link     http://pear.php.net/package/Gtk2_PHPConfig
  33. + */
  34.  class Gtk2_PHPConfig extends GtkWindow
  35.  {
  36.      // {{{ properties
  37.  -194,20 +206,24 @@
  38.       * Sets the classes' properties and calls the creation of the GUI
  39.       * interface.
  40.       *
  41. -     * @param   string  $fileName   Filename of the ini file to be
  42. -     *                              edited. Will be null if a new
  43. -     *                              file is to be created.
  44. +     * @param string $fileName Filename of the ini file to be edited.
  45. +     *                         Will be null if a new file is to be created.
  46. +     *
  47. +     * @return void
  48.       */
  49.      function __construct($fileName)
  50.      {
  51.          parent::__construct();
  52. -        require_once "PEAR/Config.php";
  53. +        include_once "PEAR/Config.php";
  54.          $this->fileName = $fileName;
  55.          $this->saved = false;
  56.          $this->xmlDefs = new DomDocument();
  57. -        $dataDir = PEAR_Config::singleton()->get("data_dir").DIRECTORY_SEPARATOR."Gtk2_PHPConfig";
  58. +        //where data is stored
  59. +        $dataDir = PEAR_Config::singleton()->get("data_dir") .
  60. +            DIRECTORY_SEPARATOR . "Gtk2_PHPConfig";
  61.          $this->xmlDefs->load($dataDir."/phpinidefs.xml");
  62.          $this->xpath = new DOMXPath($this->xmlDefs);
  63. +        //optionIndex
  64.          $this->optionIndex = $this->getValues();
  65.          $this->buildGUI();
  66.      }
  67.  -219,6 +235,8 @@
  68.       * Creates the user interface to facilitate editing of the ini files.
  69.       * Also calls other functions that parse the XML definition file and
  70.       * then displays the configuration options.
  71. +     *
  72. +     * @return void
  73.       */
  74.      function buildGUI()
  75.      {
  76.  -231,13 +249,17 @@
  77.          /* Displaying the configuration sections */
  78.          $sectionList = $this->buildSectionList();
  79.          $this->sectionTree = $sectionList;
  80. +        // add sectionList to a scrolled window
  81.          $leftScroll = new GtkScrolledWindow();
  82.          $leftScroll->set_policy(Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
  83.          $leftScroll->add($sectionList);
  84.  
  85.          /* Creating the tree that will display configuration options */
  86. -        $model = new GtkListStore(Gtk::TYPE_STRING, Gtk::TYPE_STRING, Gtk::TYPE_STRING);
  87. +        $model = new GtkListStore(Gobject::TYPE_STRING,
  88. +            Gobject::TYPE_STRING,
  89. +            Gobject::TYPE_STRING);
  90.          $tree = new GtkTreeView($model);
  91. +        // set the optionTree
  92.          $this->optionTree = $tree;
  93.  
  94.          $rightScroll = new GtkScrolledWindow();
  95.  -367,15 +389,19 @@
  96.          $valueEntry = new GtkEntry();
  97.          $valueEntry->connect_simple("activate", array($this, "onValueSubmit"));
  98.          $this->optionEntry = $valueEntry;
  99. +        //unset button
  100.          $valueUnset = new GtkButton(null);
  101. -        $unsetIcon = GtkImage::new_from_stock(Gtk::STOCK_CANCEL, Gtk::ICON_SIZE_BUTTON);
  102. +        $unsetIcon  = GtkImage::new_from_stock(Gtk::STOCK_CANCEL,
  103. +            Gtk::ICON_SIZE_BUTTON);
  104.          $valueUnset->set_image($unsetIcon);
  105.          $entryBox->pack_start($valueEntry, true, true);
  106.          $entryBox->pack_start($valueUnset, false, false);
  107.  
  108.          $valueSubmit = new GtkButton("Set Value");
  109. -        $commentLabel = new GtkLabel("Comments are also added\nUse the red cross to unset.");
  110. -        $setIcon = GtkImage::new_from_stock(Gtk::STOCK_OK, Gtk::ICON_SIZE_BUTTON);
  111. +        $commentLabel = new GtkLabel("Comments are also added\n" .
  112. +            "Use the red cross to unset.");
  113. +        $setIcon      = GtkImage::new_from_stock(Gtk::STOCK_OK,
  114. +            Gtk::ICON_SIZE_BUTTON);
  115.          $valueSubmit->set_image($setIcon);
  116.  
  117.          $valueSubmit->connect_simple("clicked", array($this, "onValueSubmit"));
  118.  -402,14 +428,17 @@
  119.      function buildSectionList()
  120.      {
  121.          /* Creating a new model to store configuration sections */
  122. -        $model = new GtkListStore(Gtk::TYPE_STRING);
  123. +        $model     = new GtkListStore(Gobject::TYPE_STRING);
  124.          $listItems = $this->getSections();
  125.          foreach ($listItems as $item) {
  126.              $model->append(array($item));
  127.          }
  128.          $tree = new GtkTreeView($model);
  129.          $renderer = new GtkCellRendererText();
  130. -        $tree->append_column(new GtkTreeViewColumn("Sections", $renderer, "text", 0));
  131. +        $tree->append_column(new GtkTreeViewColumn("Sections",
  132. +            $renderer,
  133. +            "text",
  134. +            0));
  135.  
  136.          $itemSelect = $tree->get_selection();
  137.          $itemSelect->set_mode(Gtk::SELECTION_SINGLE);
  138.  -423,6 +452,10 @@
  139.      /**
  140.       * Sets the description of the configuration option currently selected
  141.       * and displays it along with comments, if any.
  142. +     *
  143. +     * @param object $selected selected object
  144. +     *
  145. +     * @return void
  146.       */
  147.      function onOptionSelect($selected)
  148.      {
  149.  -463,6 +496,8 @@
  150.       *
  151.       * @param   GtkTreeSelection    $selected    Selection object corresponding to the
  152.       *                                           currently selected configuration section.
  153. +     *
  154. +     * @return void
  155.       */
  156.      function onSectionSelect($selected)
  157.      {
  158.  -485,6 +520,7 @@
  159.              }
  160.          }
  161.          $cell = new GtkCellRendererText();
  162. +        //what to name the column?
  163.          if ($section = "Dynamic Extensions") {
  164.              $nameColumn = new GtkTreeViewColumn("Extension", $cell, "text", 0);
  165.          } else {
  166.  -541,6 +577,7 @@
  167.       * @param   string  $section    Name of the configuration section for
  168.       *                              which the configuration options must be
  169.       *                              returned.
  170. +     *
  171.       * @return  Array
  172.       */
  173.      function getOptions($section)
  174.  -556,7 +593,8 @@
  175.              }
  176.          } else {
  177.              $optionNodes =
  178. -                $this->xpath->query('/php-config-options/section[@name="'.$section.'"]/option');
  179. +                $this->xpath->query('/php-config-options/section[@name="' .
  180. +                    $section . '"]/option');
  181.              foreach ($optionNodes as $optionNode) {
  182.                  $optionName = $optionNode->getAttribute("id");
  183.                  $optionList[] =
  184.  -574,6 +612,10 @@
  185.      /**
  186.       * Saves the current state of configuration into a file. Filename will
  187.       * be prompted for if a new file is to be generated.
  188. +     *
  189. +     * @param bool $saveas is this a 'saveas' operation. default to false.
  190. +     *
  191. +     * @return void
  192.       */
  193.      function saveFile($saveas = false)
  194.      {
  195.  -604,14 +646,17 @@
  196.                  }
  197.                  if ($value[self::DIR_CURRENT] != "Disabled" &&
  198.                      trim($value[self::DIR_CURRENT]) != "") {
  199. -                    if(trim($value[self::COMMENT_NORMAL]) != "") {
  200. +                    if (trim($value[self::COMMENT_NORMAL]) != "") {
  201.                          $theFile[$lineNumber] = "\n;/ ".str_replace("\n", "\n;/ ",
  202.                          $value[self::COMMENT_NORMAL])."\n";
  203.                      }
  204. -                    $theFile[$lineNumber] = $option." = ".$value[self::DIR_CURRENT].$inline;
  205. +                    $theFile[$lineNumber] = $option . " = " .
  206. +                        $value[self::DIR_CURRENT] . $inline;
  207.                  } elseif ($value[self::DIR_CURRENT] == "Disabled" ||
  208.                            trim($value[self::DIR_CURRENT]) == "") {
  209. -                        $theFile[$lineNumber] = ";".$option." = ".$value[self::DIR_DEFAULT].$inline;
  210. +                        $theFile[$lineNumber] = ";"
  211. +                            . $option . " = "
  212. +                            . $value[self::DIR_DEFAULT] . $inline;
  213.                  }
  214.              }
  215.  
  216.  -637,9 +682,13 @@
  217.  
  218.          } else {
  219.               /* New file to be saved, prompt for filename */
  220. -             $filePrompt = new GtkFileChooserDialog("Save file as:", $this,
  221. -             Gtk::FILE_CHOOSER_ACTION_SAVE, array(Gtk::STOCK_CANCEL, Gtk::RESPONSE_CANCEL,
  222. -             Gtk::STOCK_SAVE, Gtk::RESPONSE_ACCEPT));
  223. +            $filePrompt = new GtkFileChooserDialog("Save file as:",
  224. +                $this,
  225. +                Gtk::FILE_CHOOSER_ACTION_SAVE,
  226. +                array(Gtk::STOCK_CANCEL,
  227. +                    Gtk::RESPONSE_CANCEL,
  228. +                    Gtk::STOCK_SAVE,
  229. +                    Gtk::RESPONSE_ACCEPT));
  230.  
  231.               if ($filePrompt->run() == Gtk::RESPONSE_ACCEPT) {
  232.                  $this->onSaveFile($filePrompt, $saveas);
  233.  -661,6 +710,9 @@
  234.       * @param   GtkFileSelection    $filePrompt     File selection dialog
  235.       *                                              object that called
  236.       *                                              this function.
  237. +     * @param bool             $saveas     is this a 'saveas' operation.
  238. +     *
  239. +     * @return void
  240.       */
  241.      function onSaveFile($filePrompt, $saveas)
  242.      {
  243.  -679,6 +731,8 @@
  244.      /**
  245.       * Called in case the "Save As..." option is selected. The function
  246.       * will prompt for a filename to save the file as.
  247. +     *
  248. +     * @return void
  249.       */
  250.      function onSaveFileAs()
  251.      {
  252.  -697,12 +751,16 @@
  253.      /**
  254.       * Sets the new user-defined value for the configuration option in the
  255.       * buffer.
  256. +     *
  257. +     * @return void
  258.       */
  259.      function onValueSubmit()
  260.      {
  261.          $selection = $this->optionTree->get_selection();
  262. +        //set what's selected
  263.          list($model, $iter) = $selection->get_selected();
  264. -        list($sModel, $sIter) = $this->sectionTree->get_selection()->get_selected();
  265. +        list($sModel, $sIter) =
  266. +            $this->sectionTree->get_selection()->get_selected();
  267.          if (!$iter || !$sIter) {
  268.              return;
  269.          }
  270.  -714,7 +772,8 @@
  271.  
  272.          /* Retreive the comments, if any, in the buffer */
  273.          $comments = $this->optionComments;
  274. -        $comments = $comments->get_text($comments->get_start_iter(), $comments->get_end_iter());
  275. +        $comments = $comments->get_text($comments->get_start_iter(),
  276. +                                        $comments->get_end_iter());
  277.  
  278.          if ($section == "Dynamic Extensions") {
  279.              $this->extensions[$option][self::DIR_CURRENT] = $value;
  280.  -739,6 +798,8 @@
  281.      /**
  282.       * Unsets the value of the currently selected configuration directive to
  283.       * disabled so that it does not appear in the configuration file.
  284. +     *
  285. +     *  @return void
  286.       */
  287.      function onValueUnset()
  288.      {
  289.  -788,16 +849,19 @@
  290.          }
  291.          $this->showProgress();
  292.  
  293. -        foreach ($options as $no=>$optionData) {
  294. +        foreach ($options as $no => $optionData) {
  295.              $total = count($options);
  296. -            if ($this->fileName!=null) {
  297. +            if ($this->fileName != null) {
  298.                  $optionName = $optionData[0];
  299.                  $optionDef = $optionData[1];
  300.                  /* Set all configuration options to disabled. These values
  301.                   * will be rewritten after parsing the INI file
  302.                   */
  303. -                $index[$optionName] = array(self::DIR_CURRENT=>"Disabled", self::DIR_DEFAULT=>$optionDef,
  304. -                self::COMMENT_NORMAL=>"", self::COMMENT_INLINE=>"", self::DIR_NUMBER=>"");
  305. +                $index[$optionName] = array(self::DIR_CURRENT=>"Disabled",
  306. +                    self::DIR_DEFAULT => $optionDef,
  307. +                    self::COMMENT_NORMAL => "",
  308. +                    self::COMMENT_INLINE => "",
  309. +                    self::DIR_NUMBER => "");
  310.                  $this->updateProgress(($no/$total)/10);
  311.              } else {
  312.                  /* Set all configuration options to default values since a
  313.  -805,35 +869,42 @@
  314.                   */
  315.                  $optionName = $optionData[0];
  316.                  $optionDef = $optionData[1];
  317. -                $index[$optionName] = array(self::DIR_CURRENT=>$optionDef, self::DIR_DEFAULT=>$optionDef,
  318. -                self::COMMENT_NORMAL=>"", self::COMMENT_INLINE=>"", self::DIR_NUMBER=>"");
  319. +                // set option name
  320. +                $index[$optionName] = array(self::DIR_CURRENT => $optionDef,
  321. +                    self::DIR_DEFAULT => $optionDef,
  322. +                    self::COMMENT_NORMAL => "",
  323. +                    self::COMMENT_INLINE => "",
  324. +                    self::DIR_NUMBER => "");
  325.                  $this->updateProgress($no/$total);
  326.              }
  327.          }
  328. -        if ($this->fileName!=null) {
  329. +        if ($this->fileName != null) {
  330.              $status = file($this->fileName);
  331.              $total = count($status);
  332.              foreach ($status as $no=>$line) {
  333. -                $this->updateProgress(0.1+(0.9*($no/$total)));
  334. -                foreach ($options as $opNo=>$data) {
  335. -                    if (strpos($line, "extension")!==false) {
  336. -                        if (substr($line, 0 , 9) == "extension") {
  337. +                $this->updateProgress(0.1 + (0.9 * ($no / $total)));
  338. +                foreach ($options as $opNo => $data) {
  339. +                    if (strpos($line, "extension") !== false) {
  340. +                        if (substr($line, 0, 9) == "extension") {
  341.                              $extStatus = self::EXT_ENABLED;
  342.                          } elseif (substr($line, 1, 9) == "extension") {
  343.                              $extStatus = self::EXT_DISABLED;
  344.                          }
  345.                          if (isset($extStatus)) {
  346.                              $check = explode("=", $line);
  347. -                            if (trim($check[0])=="extension" || trim($check[0])==";extension") {
  348. +                            if (trim($check[0]) == "extension" ||
  349. +                                trim($check[0]) == ";extension") {
  350.                                  $extValue = $check[1];
  351.                                  $remComments = explode(";", $extValue);
  352.                                  $extName = trim($remComments[0]);
  353.                                  if (array_key_exists(1, $remComments)) {
  354. -                                    $extensions[$extName][self::COMMENT_INLINE] = $remComments[1];
  355. +                                    $extensions[$extName][self::COMMENT_INLINE] =
  356. +                                        $remComments[1];
  357.                                  } else {
  358.                                      $extensions[$extName][self::COMMENT_INLINE] = "";
  359.                                  }
  360. -                                $extensions[$extName][self::DIR_CURRENT] = $extStatus;
  361. +                                $extensions[$extName][self::DIR_CURRENT] =
  362. +                                    $extStatus;
  363.                                  $extensions[$extName][self::DIR_NUMBER] = $no;
  364.                              }
  365.                          }
  366.  -847,28 +918,37 @@
  367.                          if ($optionShown == $optionName) {
  368.                              $whereis = strpos($line, "=");
  369.                              $directive = substr($line, 0, $whereis);
  370. -                            $values = substr($line, $whereis+1, strlen($line)-$whereis);
  371. +                            $values    = substr($line,
  372. +                                $whereis + 1,
  373. +                                strlen($line) - $whereis);
  374.                              $values = explode(";", $values);
  375.                              /* Check if this is not part of a bigger extension */
  376. -                            if (strlen(trim($directive)) == strlen(trim($optionName))) {
  377. -                                $index[$optionName][self::DIR_CURRENT] = trim($values[0]);
  378. -                                $index[$optionName][self::COMMENT_NORMAL] = $comment;
  379. -                                $index[$optionName][self::DIR_NUMBER] = $no;
  380. +                            if (strlen(trim($directive)) ==
  381. +                                strlen(trim($optionName))) {
  382. +                                $index[$optionName][self::DIR_CURRENT]    =
  383. +                                    trim($values[0]);
  384. +                                $index[$optionName][self::COMMENT_NORMAL] =
  385. +                                    $comment;
  386. +                                $index[$optionName][self::DIR_NUMBER]     =
  387. +                                    $no;
  388.                                  if (array_key_exists(1, $values)) {
  389. -                                    $index[$optionName][self::COMMENT_INLINE] = trim($values[1]);
  390. +                                    $index[$optionName][self::COMMENT_INLINE] =
  391. +                                        trim($values[1]);
  392.                                  }
  393.                              }
  394.                              $comment = "";
  395.                              $delFlag = true;
  396. -                        } elseif ($optionHidden == $optionName && $optionHidden != "extension") {
  397. +                        } elseif ($optionHidden == $optionName
  398. +                               && $optionHidden != "extension") {
  399.                              $index[$optionName][self::DIR_CURRENT] == "Disabled";
  400.                              $index[$optionName][self::COMMENT_NORMAL] = "";
  401.                              $index[$optionName][self::DIR_NUMBER] = $no;
  402. +                            //reset flag
  403.                              $delFlag = true;
  404. -                        } elseif (substr($line, 0, 2)==";/" && $optionHi) {
  405. +                        } elseif (substr($line, 0, 2) == ";/" && $optionHi) {
  406.                              if ($line != $current) {
  407.                                  $current = $line;
  408. -                                if(substr($line, 2, 1)==" ") {
  409. +                                if (substr($line, 2, 1) == " ") {
  410.                                      $comment .= substr($line, 3, strlen($line)-3);
  411.                                  } else {
  412.                                      $comment .= substr($line, 2, strlen($line)-2);
  413.  -894,6 +974,8 @@
  414.      /**
  415.       * Creates and displays a progress bar that indicates
  416.       * by what amount a file has been parsed.
  417. +     *
  418. +     * @return void
  419.       */
  420.      function showProgress()
  421.      {
  422.  -908,7 +990,7 @@
  423.          $progressBar->set_orientation(Gtk::PROGRESS_LEFT_TO_RIGHT);
  424.          $progressWin->add($progressBar);
  425.          $this->progress = $progressWin;
  426. -        $this->progress->set_size_request(300,50);
  427. +        $this->progress->set_size_request(300, 50);
  428.          $this->progress->set_position(Gtk::WIN_POS_CENTER);
  429.          $this->progress->show_all();
  430.  
  431.  -922,7 +1004,10 @@
  432.       * Updates the progress by the fraction received as an argument by
  433.       * the function.
  434.       *
  435. -     * @param   int $fraction   The fraction by which the progress bar must be updated.
  436. +     * @param int $fraction The fraction by which the progress bar must
  437. +     *                      be updated.
  438. +     *
  439. +     * @return true
  440.       */
  441.      function updateProgress($fraction)
  442.      {
  443.  -942,13 +1027,17 @@
  444.      /**
  445.       * Prompts for saving of file that is currently opened and opens a
  446.       * dialog that prompts for the next file the user wishes to open.
  447. +     *
  448. +     * @return void
  449.       */
  450.      function openFile()
  451.      {
  452. -        if($this->savePrompt()) {
  453. +        if ($this->savePrompt()) {
  454.              $filePrompt = new GtkFileChooserDialog("Open Existing file:", $this,
  455. -            Gtk::FILE_CHOOSER_ACTION_OPEN, array(Gtk::STOCK_CANCEL, Gtk::RESPONSE_CANCEL,
  456. -            Gtk::STOCK_OPEN, Gtk::RESPONSE_ACCEPT));
  457. +            Gtk::FILE_CHOOSER_ACTION_OPEN, array(Gtk::STOCK_CANCEL,
  458. +                Gtk::RESPONSE_CANCEL,
  459. +                Gtk::STOCK_OPEN,
  460. +                Gtk::RESPONSE_ACCEPT));
  461.          }
  462.  
  463.          if ($filePrompt->run() == Gtk::RESPONSE_ACCEPT) {
  464.  -971,6 +1060,8 @@
  465.      /**
  466.       * Creates a new file to be edited after prompting for saving of the
  467.       * existing file that is open.
  468. +     *
  469. +     * @return void
  470.       */
  471.      function newFile()
  472.      {
  473.  -997,23 +1088,25 @@
  474.              return true;
  475.          } else {
  476.              /* Display confirmation dialog since buffer is not saved */
  477. -            $saveDialog = new GtkMessageDialog($this, 1,
  478. -            Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_NONE, "Do you want to save your existing INI file?");
  479. +            $saveDialog = new GtkMessageDialog($this,
  480. +                1,
  481. +                Gtk::MESSAGE_QUESTION,
  482. +                Gtk::BUTTONS_NONE,
  483. +                "Do you want to save your existing INI file?");
  484.              $saveDialog->add_button(Gtk::STOCK_CANCEL, Gtk::RESPONSE_CANCEL);
  485.              $saveDialog->add_button(Gtk::STOCK_NO, Gtk::RESPONSE_NO);
  486.              $saveDialog->add_button(Gtk::STOCK_YES, Gtk::RESPONSE_YES);
  487.              $response = $saveDialog->run();
  488.              $saveDialog->destroy();
  489.  
  490. -            if($response == Gtk::RESPONSE_YES) {
  491. +            if ($response == Gtk::RESPONSE_YES) {
  492.                  /* Save file */
  493.                  $this->saveFile();
  494.                  return true;
  495.              } elseif ($response == Gtk::RESPONSE_NO) {
  496.                  /* Don't save file */
  497.                  return true;
  498. -            }
  499. -            elseif ($response == Gtk::RESPONSE_CANCEL) {
  500. +            } elseif ($response == Gtk::RESPONSE_CANCEL) {
  501.                  /* Don't quit */
  502.                  return false;
  503.              }
  504.  -1050,6 +1143,8 @@
  505.      /**
  506.       * Quits the main Gtk loop after checking whether the current state of
  507.       * the buffer has been saved to a file or not.
  508. +     *
  509. +     * @return void
  510.       */
  511.      function quit()
  512.      {