- Index: PHPConfig.php
- ===================================================================
- RCS file: /repository/pear/Gtk2_PHPConfig/PHPConfig.php,v
- retrieving revision 1.2
- diff -u -b -B -r1.2 PHPConfig.php
- --- PHPConfig.php 8 Feb 2006 17:26:55 -0000 1.2
- +++ PHPConfig.php 3 Oct 2008 23:38:31 -0000
- -3,6 +3,8 @@
- /**
- * Class for GUI-based configuration of a php.ini file
- *
- + * PHP Version 5
- + *
- * This class is based on the PHP-Gtk2 extension and provides a
- * user-friendly interface for editing php.ini files. All the possible
- * configuration options have been defined in a separate XML file .
- -28,9 +30,19 @@
- * @package PHPConfig
- * @author Anant Narayanan <anant@php.net>
- * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
- + * @link http://pear.php.net/package/Gtk2_PHPConfig
- *
- */
- +/**
- + * Gtk2_PHPConfig
- + *
- + * @category Gtk2
- + * @package PHPConfig
- + * @author Anant Narayanan <anant@php.net>
- + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
- + * @link http://pear.php.net/package/Gtk2_PHPConfig
- + */
- class Gtk2_PHPConfig extends GtkWindow
- {
- // {{{ properties
- -194,20 +206,24 @@
- * Sets the classes' properties and calls the creation of the GUI
- * interface.
- *
- - * @param string $fileName Filename of the ini file to be
- - * edited. Will be null if a new
- - * file is to be created.
- + * @param string $fileName Filename of the ini file to be edited.
- + * Will be null if a new file is to be created.
- + *
- + * @return void
- */
- function __construct($fileName)
- {
- parent::__construct();
- - require_once "PEAR/Config.php";
- + include_once "PEAR/Config.php";
- $this->fileName = $fileName;
- $this->saved = false;
- $this->xmlDefs = new DomDocument();
- - $dataDir = PEAR_Config::singleton()->get("data_dir").DIRECTORY_SEPARATOR."Gtk2_PHPConfig";
- + //where data is stored
- + $dataDir = PEAR_Config::singleton()->get("data_dir") .
- + DIRECTORY_SEPARATOR . "Gtk2_PHPConfig";
- $this->xmlDefs->load($dataDir."/phpinidefs.xml");
- $this->xpath = new DOMXPath($this->xmlDefs);
- + //optionIndex
- $this->optionIndex = $this->getValues();
- $this->buildGUI();
- }
- -219,6 +235,8 @@
- * Creates the user interface to facilitate editing of the ini files.
- * Also calls other functions that parse the XML definition file and
- * then displays the configuration options.
- + *
- + * @return void
- */
- function buildGUI()
- {
- -231,13 +249,17 @@
- /* Displaying the configuration sections */
- $sectionList = $this->buildSectionList();
- $this->sectionTree = $sectionList;
- + // add sectionList to a scrolled window
- $leftScroll = new GtkScrolledWindow();
- $leftScroll->set_policy(Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
- $leftScroll->add($sectionList);
- /* Creating the tree that will display configuration options */
- - $model = new GtkListStore(Gtk::TYPE_STRING, Gtk::TYPE_STRING, Gtk::TYPE_STRING);
- + $model = new GtkListStore(Gobject::TYPE_STRING,
- + Gobject::TYPE_STRING,
- + Gobject::TYPE_STRING);
- $tree = new GtkTreeView($model);
- + // set the optionTree
- $this->optionTree = $tree;
- $rightScroll = new GtkScrolledWindow();
- -367,15 +389,19 @@
- $valueEntry = new GtkEntry();
- $valueEntry->connect_simple("activate", array($this, "onValueSubmit"));
- $this->optionEntry = $valueEntry;
- + //unset button
- $valueUnset = new GtkButton(null);
- - $unsetIcon = GtkImage::new_from_stock(Gtk::STOCK_CANCEL, Gtk::ICON_SIZE_BUTTON);
- + $unsetIcon = GtkImage::new_from_stock(Gtk::STOCK_CANCEL,
- + Gtk::ICON_SIZE_BUTTON);
- $valueUnset->set_image($unsetIcon);
- $entryBox->pack_start($valueEntry, true, true);
- $entryBox->pack_start($valueUnset, false, false);
- $valueSubmit = new GtkButton("Set Value");
- - $commentLabel = new GtkLabel("Comments are also added\nUse the red cross to unset.");
- - $setIcon = GtkImage::new_from_stock(Gtk::STOCK_OK, Gtk::ICON_SIZE_BUTTON);
- + $commentLabel = new GtkLabel("Comments are also added\n" .
- + "Use the red cross to unset.");
- + $setIcon = GtkImage::new_from_stock(Gtk::STOCK_OK,
- + Gtk::ICON_SIZE_BUTTON);
- $valueSubmit->set_image($setIcon);
- $valueSubmit->connect_simple("clicked", array($this, "onValueSubmit"));
- -402,14 +428,17 @@
- function buildSectionList()
- {
- /* Creating a new model to store configuration sections */
- - $model = new GtkListStore(Gtk::TYPE_STRING);
- + $model = new GtkListStore(Gobject::TYPE_STRING);
- $listItems = $this->getSections();
- foreach ($listItems as $item) {
- $model->append(array($item));
- }
- $tree = new GtkTreeView($model);
- $renderer = new GtkCellRendererText();
- - $tree->append_column(new GtkTreeViewColumn("Sections", $renderer, "text", 0));
- + $tree->append_column(new GtkTreeViewColumn("Sections",
- + $renderer,
- + "text",
- + 0));
- $itemSelect = $tree->get_selection();
- $itemSelect->set_mode(Gtk::SELECTION_SINGLE);
- -423,6 +452,10 @@
- /**
- * Sets the description of the configuration option currently selected
- * and displays it along with comments, if any.
- + *
- + * @param object $selected selected object
- + *
- + * @return void
- */
- function onOptionSelect($selected)
- {
- -463,6 +496,8 @@
- *
- * @param GtkTreeSelection $selected Selection object corresponding to the
- * currently selected configuration section.
- + *
- + * @return void
- */
- function onSectionSelect($selected)
- {
- -485,6 +520,7 @@
- }
- }
- $cell = new GtkCellRendererText();
- + //what to name the column?
- if ($section = "Dynamic Extensions") {
- $nameColumn = new GtkTreeViewColumn("Extension", $cell, "text", 0);
- } else {
- -541,6 +577,7 @@
- * @param string $section Name of the configuration section for
- * which the configuration options must be
- * returned.
- + *
- * @return Array
- */
- function getOptions($section)
- -556,7 +593,8 @@
- }
- } else {
- $optionNodes =
- - $this->xpath->query('/php-config-options/section[@name="'.$section.'"]/option');
- + $this->xpath->query('/php-config-options/section[@name="' .
- + $section . '"]/option');
- foreach ($optionNodes as $optionNode) {
- $optionName = $optionNode->getAttribute("id");
- $optionList[] =
- -574,6 +612,10 @@
- /**
- * Saves the current state of configuration into a file. Filename will
- * be prompted for if a new file is to be generated.
- + *
- + * @param bool $saveas is this a 'saveas' operation. default to false.
- + *
- + * @return void
- */
- function saveFile($saveas = false)
- {
- -604,14 +646,17 @@
- }
- if ($value[self::DIR_CURRENT] != "Disabled" &&
- trim($value[self::DIR_CURRENT]) != "") {
- - if(trim($value[self::COMMENT_NORMAL]) != "") {
- + if (trim($value[self::COMMENT_NORMAL]) != "") {
- $theFile[$lineNumber] = "\n;/ ".str_replace("\n", "\n;/ ",
- $value[self::COMMENT_NORMAL])."\n";
- }
- - $theFile[$lineNumber] = $option." = ".$value[self::DIR_CURRENT].$inline;
- + $theFile[$lineNumber] = $option . " = " .
- + $value[self::DIR_CURRENT] . $inline;
- } elseif ($value[self::DIR_CURRENT] == "Disabled" ||
- trim($value[self::DIR_CURRENT]) == "") {
- - $theFile[$lineNumber] = ";".$option." = ".$value[self::DIR_DEFAULT].$inline;
- + $theFile[$lineNumber] = ";"
- + . $option . " = "
- + . $value[self::DIR_DEFAULT] . $inline;
- }
- }
- -637,9 +682,13 @@
- } else {
- /* New file to be saved, prompt for filename */
- - $filePrompt = new GtkFileChooserDialog("Save file as:", $this,
- - Gtk::FILE_CHOOSER_ACTION_SAVE, array(Gtk::STOCK_CANCEL, Gtk::RESPONSE_CANCEL,
- - Gtk::STOCK_SAVE, Gtk::RESPONSE_ACCEPT));
- + $filePrompt = new GtkFileChooserDialog("Save file as:",
- + $this,
- + Gtk::FILE_CHOOSER_ACTION_SAVE,
- + array(Gtk::STOCK_CANCEL,
- + Gtk::RESPONSE_CANCEL,
- + Gtk::STOCK_SAVE,
- + Gtk::RESPONSE_ACCEPT));
- if ($filePrompt->run() == Gtk::RESPONSE_ACCEPT) {
- $this->onSaveFile($filePrompt, $saveas);
- -661,6 +710,9 @@
- * @param GtkFileSelection $filePrompt File selection dialog
- * object that called
- * this function.
- + * @param bool $saveas is this a 'saveas' operation.
- + *
- + * @return void
- */
- function onSaveFile($filePrompt, $saveas)
- {
- -679,6 +731,8 @@
- /**
- * Called in case the "Save As..." option is selected. The function
- * will prompt for a filename to save the file as.
- + *
- + * @return void
- */
- function onSaveFileAs()
- {
- -697,12 +751,16 @@
- /**
- * Sets the new user-defined value for the configuration option in the
- * buffer.
- + *
- + * @return void
- */
- function onValueSubmit()
- {
- $selection = $this->optionTree->get_selection();
- + //set what's selected
- list($model, $iter) = $selection->get_selected();
- - list($sModel, $sIter) = $this->sectionTree->get_selection()->get_selected();
- + list($sModel, $sIter) =
- + $this->sectionTree->get_selection()->get_selected();
- if (!$iter || !$sIter) {
- return;
- }
- -714,7 +772,8 @@
- /* Retreive the comments, if any, in the buffer */
- $comments = $this->optionComments;
- - $comments = $comments->get_text($comments->get_start_iter(), $comments->get_end_iter());
- + $comments = $comments->get_text($comments->get_start_iter(),
- + $comments->get_end_iter());
- if ($section == "Dynamic Extensions") {
- $this->extensions[$option][self::DIR_CURRENT] = $value;
- -739,6 +798,8 @@
- /**
- * Unsets the value of the currently selected configuration directive to
- * disabled so that it does not appear in the configuration file.
- + *
- + * @return void
- */
- function onValueUnset()
- {
- -788,16 +849,19 @@
- }
- $this->showProgress();
- - foreach ($options as $no=>$optionData) {
- + foreach ($options as $no => $optionData) {
- $total = count($options);
- - if ($this->fileName!=null) {
- + if ($this->fileName != null) {
- $optionName = $optionData[0];
- $optionDef = $optionData[1];
- /* Set all configuration options to disabled. These values
- * will be rewritten after parsing the INI file
- */
- - $index[$optionName] = array(self::DIR_CURRENT=>"Disabled", self::DIR_DEFAULT=>$optionDef,
- - self::COMMENT_NORMAL=>"", self::COMMENT_INLINE=>"", self::DIR_NUMBER=>"");
- + $index[$optionName] = array(self::DIR_CURRENT=>"Disabled",
- + self::DIR_DEFAULT => $optionDef,
- + self::COMMENT_NORMAL => "",
- + self::COMMENT_INLINE => "",
- + self::DIR_NUMBER => "");
- $this->updateProgress(($no/$total)/10);
- } else {
- /* Set all configuration options to default values since a
- -805,35 +869,42 @@
- */
- $optionName = $optionData[0];
- $optionDef = $optionData[1];
- - $index[$optionName] = array(self::DIR_CURRENT=>$optionDef, self::DIR_DEFAULT=>$optionDef,
- - self::COMMENT_NORMAL=>"", self::COMMENT_INLINE=>"", self::DIR_NUMBER=>"");
- + // set option name
- + $index[$optionName] = array(self::DIR_CURRENT => $optionDef,
- + self::DIR_DEFAULT => $optionDef,
- + self::COMMENT_NORMAL => "",
- + self::COMMENT_INLINE => "",
- + self::DIR_NUMBER => "");
- $this->updateProgress($no/$total);
- }
- }
- - if ($this->fileName!=null) {
- + if ($this->fileName != null) {
- $status = file($this->fileName);
- $total = count($status);
- foreach ($status as $no=>$line) {
- - $this->updateProgress(0.1+(0.9*($no/$total)));
- - foreach ($options as $opNo=>$data) {
- - if (strpos($line, "extension")!==false) {
- - if (substr($line, 0 , 9) == "extension") {
- + $this->updateProgress(0.1 + (0.9 * ($no / $total)));
- + foreach ($options as $opNo => $data) {
- + if (strpos($line, "extension") !== false) {
- + if (substr($line, 0, 9) == "extension") {
- $extStatus = self::EXT_ENABLED;
- } elseif (substr($line, 1, 9) == "extension") {
- $extStatus = self::EXT_DISABLED;
- }
- if (isset($extStatus)) {
- $check = explode("=", $line);
- - if (trim($check[0])=="extension" || trim($check[0])==";extension") {
- + if (trim($check[0]) == "extension" ||
- + trim($check[0]) == ";extension") {
- $extValue = $check[1];
- $remComments = explode(";", $extValue);
- $extName = trim($remComments[0]);
- if (array_key_exists(1, $remComments)) {
- - $extensions[$extName][self::COMMENT_INLINE] = $remComments[1];
- + $extensions[$extName][self::COMMENT_INLINE] =
- + $remComments[1];
- } else {
- $extensions[$extName][self::COMMENT_INLINE] = "";
- }
- - $extensions[$extName][self::DIR_CURRENT] = $extStatus;
- + $extensions[$extName][self::DIR_CURRENT] =
- + $extStatus;
- $extensions[$extName][self::DIR_NUMBER] = $no;
- }
- }
- -847,28 +918,37 @@
- if ($optionShown == $optionName) {
- $whereis = strpos($line, "=");
- $directive = substr($line, 0, $whereis);
- - $values = substr($line, $whereis+1, strlen($line)-$whereis);
- + $values = substr($line,
- + $whereis + 1,
- + strlen($line) - $whereis);
- $values = explode(";", $values);
- /* Check if this is not part of a bigger extension */
- - if (strlen(trim($directive)) == strlen(trim($optionName))) {
- - $index[$optionName][self::DIR_CURRENT] = trim($values[0]);
- - $index[$optionName][self::COMMENT_NORMAL] = $comment;
- - $index[$optionName][self::DIR_NUMBER] = $no;
- + if (strlen(trim($directive)) ==
- + strlen(trim($optionName))) {
- + $index[$optionName][self::DIR_CURRENT] =
- + trim($values[0]);
- + $index[$optionName][self::COMMENT_NORMAL] =
- + $comment;
- + $index[$optionName][self::DIR_NUMBER] =
- + $no;
- if (array_key_exists(1, $values)) {
- - $index[$optionName][self::COMMENT_INLINE] = trim($values[1]);
- + $index[$optionName][self::COMMENT_INLINE] =
- + trim($values[1]);
- }
- }
- $comment = "";
- $delFlag = true;
- - } elseif ($optionHidden == $optionName && $optionHidden != "extension") {
- + } elseif ($optionHidden == $optionName
- + && $optionHidden != "extension") {
- $index[$optionName][self::DIR_CURRENT] == "Disabled";
- $index[$optionName][self::COMMENT_NORMAL] = "";
- $index[$optionName][self::DIR_NUMBER] = $no;
- + //reset flag
- $delFlag = true;
- - } elseif (substr($line, 0, 2)==";/" && $optionHi) {
- + } elseif (substr($line, 0, 2) == ";/" && $optionHi) {
- if ($line != $current) {
- $current = $line;
- - if(substr($line, 2, 1)==" ") {
- + if (substr($line, 2, 1) == " ") {
- $comment .= substr($line, 3, strlen($line)-3);
- } else {
- $comment .= substr($line, 2, strlen($line)-2);
- -894,6 +974,8 @@
- /**
- * Creates and displays a progress bar that indicates
- * by what amount a file has been parsed.
- + *
- + * @return void
- */
- function showProgress()
- {
- -908,7 +990,7 @@
- $progressBar->set_orientation(Gtk::PROGRESS_LEFT_TO_RIGHT);
- $progressWin->add($progressBar);
- $this->progress = $progressWin;
- - $this->progress->set_size_request(300,50);
- + $this->progress->set_size_request(300, 50);
- $this->progress->set_position(Gtk::WIN_POS_CENTER);
- $this->progress->show_all();
- -922,7 +1004,10 @@
- * Updates the progress by the fraction received as an argument by
- * the function.
- *
- - * @param int $fraction The fraction by which the progress bar must be updated.
- + * @param int $fraction The fraction by which the progress bar must
- + * be updated.
- + *
- + * @return true
- */
- function updateProgress($fraction)
- {
- -942,13 +1027,17 @@
- /**
- * Prompts for saving of file that is currently opened and opens a
- * dialog that prompts for the next file the user wishes to open.
- + *
- + * @return void
- */
- function openFile()
- {
- - if($this->savePrompt()) {
- + if ($this->savePrompt()) {
- $filePrompt = new GtkFileChooserDialog("Open Existing file:", $this,
- - Gtk::FILE_CHOOSER_ACTION_OPEN, array(Gtk::STOCK_CANCEL, Gtk::RESPONSE_CANCEL,
- - Gtk::STOCK_OPEN, Gtk::RESPONSE_ACCEPT));
- + Gtk::FILE_CHOOSER_ACTION_OPEN, array(Gtk::STOCK_CANCEL,
- + Gtk::RESPONSE_CANCEL,
- + Gtk::STOCK_OPEN,
- + Gtk::RESPONSE_ACCEPT));
- }
- if ($filePrompt->run() == Gtk::RESPONSE_ACCEPT) {
- -971,6 +1060,8 @@
- /**
- * Creates a new file to be edited after prompting for saving of the
- * existing file that is open.
- + *
- + * @return void
- */
- function newFile()
- {
- -997,23 +1088,25 @@
- return true;
- } else {
- /* Display confirmation dialog since buffer is not saved */
- - $saveDialog = new GtkMessageDialog($this, 1,
- - Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_NONE, "Do you want to save your existing INI file?");
- + $saveDialog = new GtkMessageDialog($this,
- + 1,
- + Gtk::MESSAGE_QUESTION,
- + Gtk::BUTTONS_NONE,
- + "Do you want to save your existing INI file?");
- $saveDialog->add_button(Gtk::STOCK_CANCEL, Gtk::RESPONSE_CANCEL);
- $saveDialog->add_button(Gtk::STOCK_NO, Gtk::RESPONSE_NO);
- $saveDialog->add_button(Gtk::STOCK_YES, Gtk::RESPONSE_YES);
- $response = $saveDialog->run();
- $saveDialog->destroy();
- - if($response == Gtk::RESPONSE_YES) {
- + if ($response == Gtk::RESPONSE_YES) {
- /* Save file */
- $this->saveFile();
- return true;
- } elseif ($response == Gtk::RESPONSE_NO) {
- /* Don't save file */
- return true;
- - }
- - elseif ($response == Gtk::RESPONSE_CANCEL) {
- + } elseif ($response == Gtk::RESPONSE_CANCEL) {
- /* Don't quit */
- return false;
- }
- -1050,6 +1143,8 @@
- /**
- * Quits the main Gtk loop after checking whether the current state of
- * the buffer has been saved to a file or not.
- + *
- + * @return void
- */
- function quit()
- {