📄 web.php
字号:
'ldlib' => 'Development Library', 'rtlib' => 'Runtime Library', 'os' => 'Operating System', 'websrv' => 'Web Server', 'sapi' => 'SAPI Backend', ); $result = " <dl>\n"; foreach($deps as $row) { // Print link if it's a PEAR package if ($row['type'] == 'pkg') { $row['name'] = sprintf('<a class="green" href="%s?command=remote-info&pkg=%s">%s</a>', $_SERVER['PHP_SELF'], $row['name'], $row['name']); } if (isset($rel_trans[$row['relation']])) { $rel = sprintf($rel_trans[$row['relation']], $row['version']); $result .= sprintf("%s: %s %s", $dep_type_desc[$row['type']], $row['name'], $rel); } else { $result .= sprintf("%s: %s", $dep_type_desc[$row['type']], $row['name']); } $lastversion = $row['version']; $result .= '<br>'; } if ($lastversion) { } $result .= " </dl>\n"; } return $result; } /** * Output details of one package * * @param array $data array containing all information about the package * * @access private * * @return boolean true (yep. i am an optimist) */ function _outputPackageInfo($data) { $tpl = $this->_initTemplate("package.info.tpl.html", 'Package Management :: '.$data['name'], 'pkglist'); $tpl->setVariable("Latest", $data['stable']); $tpl->setVariable("Installed", $data['installed']); $tpl->setVariable("Package", $data['name']); $tpl->setVariable("License", $data['license']); $tpl->setVariable("Category", $data['category']); $tpl->setVariable("Summary", nl2br($data['summary'])); $tpl->setVariable("Description", nl2br($data['description'])); $deps = $data['releases'][$data['stable']]['deps']; $tpl->setVariable("Dependencies", $this->_getPackageDeps($deps)); $compare = version_compare($data['stable'], $data['installed']); $images = array( 'install' => '<img src="'.$_SERVER["PHP_SELF"].'?img=install" width="13" height="13" border="0" alt="install">', 'uninstall' => '<img src="'.$_SERVER["PHP_SELF"].'?img=uninstall" width="18" height="17" border="0" alt="uninstall">', 'upgrade' => '<img src="'.$_SERVER["PHP_SELF"].'?img=install" width="13" height="13" border="0" alt="upgrade">', ); $opt_img = array(); $opt_text = array(); if (!$data['installed'] || $data['installed'] == "- no -") { $opt_img[] = sprintf( '<a href="%s?command=install&pkg=%s&redirect=info">%s</a>', $_SERVER["PHP_SELF"], $data['name'], $images['install']); $opt_text[] = sprintf( '<a href="%s?command=install&pkg=%s&redirect=info" class="green">Install package</a>', $_SERVER["PHP_SELF"], $data['name'], $_SERVER["PHP_SELF"]); } else if ($compare == 1) { $opt_img[] = sprintf( '<a href="%s?command=upgrade&pkg=%s&redirect=info">%s</a><br>', $_SERVER["PHP_SELF"], $data['name'], $images['upgrade']); $opt_text[] = sprintf( '<a href="%s?command=upgrade&pkg=%s&redirect=info" class="green">Upgrade package</a>', $_SERVER["PHP_SELF"], $data['name'], $_SERVER["PHP_SELF"]); if (!in_array($data['name'], $this->_no_delete_pkgs)) { $opt_img[] = sprintf( '<a href="%s?command=uninstall&pkg=%s&redirect=info" %s>%s</a>', $_SERVER["PHP_SELF"], $data['name'], 'onClick="return confirm(\'Do you really want to uninstall \\\''.$data['name'].'\\\'?\')"', $images['uninstall']); $opt_text[] = sprintf( '<a href="%s?command=uninstall&pkg=%s&redirect=info" class="green" %s>Uninstall package</a>', $_SERVER["PHP_SELF"], $data['name'], 'onClick="return confirm(\'Do you really want to uninstall \\\''.$data['name'].'\\\'?\')"', $_SERVER["PHP_SELF"]); }; } else { if (!in_array($data['name'], $this->_no_delete_pkgs)) { $opt_img[] = sprintf( '<a href="%s?command=uninstall&pkg=%s&redirect=info" %s>%s</a>', $_SERVER["PHP_SELF"], $data['name'], 'onClick="return confirm(\'Do you really want to uninstall \\\''.$data['name'].'\\\'?\')"', $images['uninstall']); $opt_text[] = sprintf( '<a href="%s?command=uninstall&pkg=%s&redirect=info" class="green" %s>Uninstall package</a>', $_SERVER["PHP_SELF"], $data['name'], 'onClick="return confirm(\'Do you really want to uninstall \\\''.$data['name'].'\\\'?\')"', $_SERVER["PHP_SELF"]); }; }; if (isset($opt_img[0])) { $tpl->setVariable("Opt_Img_1", $opt_img[0]); $tpl->setVariable("Opt_Text_1", $opt_text[0]); }; if (isset($opt_img[1])) { $tpl->setVariable("Opt_Img_2", $opt_img[1]); $tpl->setVariable("Opt_Text_2", $opt_text[1]); }; $tpl->show(); return true; } /** * Output all kinds of data depending on the command which called this method * * @param mixed $data datastructure containing the information to display * @param string $command (optional) command from which this method was called * * @access public * * @return mixed highly depends on the command */ function outputData($data, $command = '_default') { switch ($command) { case 'config-show': $prompt = array(); $default = array(); foreach($data['data'] as $group) { foreach($group as $row) { $prompt[$row[1]] = $row[0]; $default[$row[1]] = $row[2]; }; }; $title = 'Configuration :: '.$GLOBALS['pear_user_config']; $GLOBALS['_PEAR_Frontend_Web_Config'] = $this->userDialog($command, $prompt, array(), $default, $title, 'config'); return true; case 'list-all': return $this->_outputListAll($data); case 'search': return $this->_outputListAll($data, 'Package Search :: Result', 'pkgsearch', false, false); case 'remote-info': return $this->_outputPackageInfo($data); case 'install': case 'upgrade': case 'uninstall': return true; case 'login': if ($_SERVER["REQUEST_METHOD"] != "POST") $this->_data[$command] = $data; return true; case 'logout': $this->displayError($data, 'Logout', 'logout'); break; case 'package': echo $data; break; default: echo $data; }; return true; } /** * Display a formular and return the given input (yes. needs to requests) * * @param string $command command from which this method was called * @param array $prompts associative array. keys are the inputfieldnames * and values are the description * @param array $types (optional) array of inputfieldtypes (text, password, * etc.) keys have to be the same like in $prompts * @param array $defaults (optional) array of defaultvalues. again keys have * to be the same like in $prompts * @param string $title (optional) title of the page * @param string $icon (optional) iconhandle for this page * * @access public * * @return array input sended by the user */ function userDialog($command, $prompts, $types = array(), $defaults = array(), $title = '', $icon = '') { // If this is an POST Request, we can return the userinput if (isset($_GET["command"]) && $_GET["command"]==$command && $_SERVER["REQUEST_METHOD"] == "POST") { $result = array(); foreach($prompts as $key => $prompt) $result[$key] = $_POST[$key]; return $result; }; // If this is an Answer GET Request , we can return the userinput if (isset($_GET["command"]) && $_GET["command"]==$command && isset($_GET["userDialogResult"]) && $_GET["userDialogResult"]=='get') { $result = array(); foreach($prompts as $key => $prompt) $result[$key] = $_GET[$key]; return $result; }; // Assign title and icon to some commands switch ($command) { case 'login': $title = 'Login'; $icon = 'login'; break; }; $tpl = $this->_initTemplate("userDialog.tpl.html", $title, $icon); $tpl->setVariable("Command", $command); if (isset($this->_data[$command])) $tpl->setVariable("Headline", nl2br($this->_data[$command])); if (is_array($prompts)) { $maxlen = 0; foreach($prompts as $key => $prompt) { if (strlen($prompt) > $maxlen) { $maxlen = strlen($prompt); }; }; foreach($prompts as $key => $prompt) { $tpl->setCurrentBlock("InputField"); $type = (isset($types[$key]) ? $types[$key] : 'text'); $default = (isset($defaults[$key]) ? $defaults[$key] : ''); $tpl->setVariable("prompt", $prompt); $tpl->setVariable("name", $key); $tpl->setVariable("default", $default); $tpl->setVariable("type", $type); if ($maxlen > 25) $tpl->setVariable("width", 'width="275"'); $tpl->parseCurrentBlock(); }; }; $tpl->show(); exit; } /** * Write message to log * * @param string $text message which has to written to log * * @access public * * @return boolean true */ function log($text) { $GLOBALS['_PEAR_Frontend_Web_log'] .= $text."\n"; return true; } /** * Sends the required file along with Headers and exits the script * * @param string $handle handle of the requested file * @param string $group group of the requested file * * @access public * * @return null nothing, because script exits */ function outputFrontendFile($handle, $group) { $handles = array( "css" => array( "style" => "style.css", "dhtml" => "dhtml.css", ), "js" => array( "dhtml" => "dhtml.js", "nodhtml" => "nodhtml.js", ), "image" => array( "logout" => array( "type" => "gif", "file" => "logout.gif", ), "login" => array( "type" => "gif", "file" => "login.gif", ), "config" => array( "type" => "gif", "file" => "config.gif", ), "pkglist" => array( "type" => "png", "file" => "pkglist.png", ), "pkgsearch" => array( "type" => "png", "file" => "pkgsearch.png", ), "package" => array( "type" => "jpeg", "file" => "package.jpg", ), "category" => array( "type" => "jpeg", "file" => "category.jpg", ), "install" => array( "type" => "gif", "file" => "install.gif", ), "install_wait" => array( "type" => "gif", "file" => "install_wait.gif", ), "install_ok" => array( "type" => "gif", "file" => "install_ok.gif", ), "install_fail" => array( "type" => "gif", "file" => "install_fail.gif", ), "uninstall" => array( "type" => "gif", "file" => "trash.gif", ), "info" => array( "type" => "gif", "file" => "info.gif", ), "infoplus" => array( "type" => "gif", "file" => "infoplus.gif", ), "pear" => array( "type" => "gif", "file" => "pearsmall.gif", ), "error" => array( "type" => "gif", "file" => "error.gif", ), "manual" => array( "type" => "gif", "file" => "manual.gif", ), "download" => array( "type" => "gif", "file" => "download.gif", ), ), ); $file = $handles[$group][$handle]; switch ($group) { case 'css': Header("Content-Type: text/css"); readfile(dirname(__FILE__).'/Web/'.$file); exit; case 'image': $filename = dirname(__FILE__).'/Web/'.$file['file']; Header("Content-Type: image/".$file['type']); Header("Expires: ".gmdate("D, d M Y H:i:s \G\M\T", time() + 60*60*24*100)); Header("Last-Modified: ".gmdate("D, d M Y H:i:s \G\M\T", filemtime($filename))); Header("Cache-Control: public"); Header("Pragma: "); readfile($filename); exit; case 'js': Header("Content-Type: text/javascript"); readfile(dirname(__FILE__).'/Web/'.$file); exit; }; } // }}}}?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -