From 6ce10527595d01335a1dd3ed77c460d956482792 Mon Sep 17 00:00:00 2001 From: Brad Shuttleworth Date: Tue, 10 Jan 2006 12:37:12 +0000 Subject: [PATCH] new help environment. --- browse.php | 1 + help.php | 107 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ index.html | 3 +++ lib/dispatcher.inc.php | 2 ++ lib/help/help.inc.php | 124 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------- lib/help/helpreplacement.inc.php | 4 ++++ lib/templating/kt3template.inc.php | 12 ++++++++++++ plugins/ktcore/admin/manageHelp.php | 32 ++++++++++++++++++++++++-------- resources/css/kt-framing.css | 15 +++++++++++++++ sql/mysql/install/structure.sql | 3 ++- sql/mysql/upgrade/2.99.7/help_replacement.sql | 2 ++ templates/kt3/standard_page.smarty | 4 +++- templates/ktcore/help_with_edit.smarty | 6 ++++++ templates/ktcore/manage_help.smarty | 29 ++++++----------------------- templates/ktcore/manage_help_item.smarty | 1 + thirdparty/icon-theme/16x16/apps/help-browser.png | Bin 0 -> 219 bytes 16 files changed, 290 insertions(+), 55 deletions(-) create mode 100644 help.php create mode 100644 sql/mysql/upgrade/2.99.7/help_replacement.sql create mode 100644 templates/ktcore/help_with_edit.smarty create mode 100644 thirdparty/icon-theme/16x16/apps/help-browser.png diff --git a/browse.php b/browse.php index 2b28258..c99a10b 100755 --- a/browse.php +++ b/browse.php @@ -51,6 +51,7 @@ class BrowseDispatcher extends KTStandardDispatcher { var $browse_mode = null; var $query = null; var $resultURL; + var $sHelpPage = 'ktcore/browse/browse.html'; function BrowseDispatcher() { $this->aBreadcrumbs = array( diff --git a/help.php b/help.php new file mode 100644 index 0000000..3a18b08 --- /dev/null +++ b/help.php @@ -0,0 +1,107 @@ +bIsReplacement; } + + function do_main() { + $pathinfo = KTUtil::arrayGet($_SERVER, 'PATH_INFO'); + if (empty($pathinfo)) { + $this->oPage->setTitle(_('No help page specified.')); + $this->oPage->addError(_('No help page specified.')); + return ' '; + } + + $can_edit = Permission::userIsSystemAdministrator($_SESSION['userID']); + + $help_path = KTHelp::getHelpSubPath($pathinfo); + if ($help_path == false) { + $this->oPage->setTitle(_('Invalid help location specified.')); + $this->oPage->addError(_('Invalid help location specified.')); + return ' '; + } + + // We now check for substitute help files. try to generate an error. + $oReplacementHelp = KTHelpReplacement::getByName($help_path); + + // OK. we know its an image, or html. + if (KTHelp::isImageFile($help_path)) { + KTHelp::outputHelpImage($help_path); + } else { + // not an image, so: + $aHelpInfo = KTHelp::getHelpFromFile($pathinfo); + } + + + // NORMAL users never see edit-option. + if (!$can_edit) { + if (!PEAR::isError($oReplacementHelp)) { + $this->oPage->setTitle($oReplacementHelp->getTitle()); + return $oReplacementHelp->getDescription(); + } elseif ($aHelpInfo != false) { + $this->oPage->setTitle($aHelpInfo['title']); + return $aHelpInfo['body']; + } else { + $this->oPage->setTitle(_('Invalid help location specified.')); + $this->oPage->addError(_('Invalid help location specified.')); + return ' '; + } + } + + if (!PEAR::isError($oReplacementHelp)) { + $aHelpInfo['title'] = $oReplacementHelp->getTitle(); + $aHelpInfo['body'] = $oReplacementHelp->getDescription(); + } + // we now _can_ edit. + + $this->oPage->setTitle($aHelpInfo['title']); + + $oTemplating = new KTTemplating; + $oTemplate = $oTemplating->loadTemplate("ktcore/help_with_edit"); + $aTemplateData = array( + "context" => $this, + "help_body" => $aHelpInfo['body'], + "target_name" => $_SERVER['PATH_INFO'], + ); + return $oTemplate->render($aTemplateData); + } + +} + +$oDispatcher = new HelpDispatcher(); +$oDispatcher->dispatch(); + +?> + diff --git a/index.html b/index.html index 0e77600..095ff53 100644 --- a/index.html +++ b/index.html @@ -2,4 +2,7 @@ + +You should automatically be redirected to the login / dashboard page. + diff --git a/lib/dispatcher.inc.php b/lib/dispatcher.inc.php index 13ed0af..ca768a4 100644 --- a/lib/dispatcher.inc.php +++ b/lib/dispatcher.inc.php @@ -123,6 +123,7 @@ class KTStandardDispatcher extends KTDispatcher { var $aBreadcrumbs = array(); var $sSection = false; var $oPage = false; + var $sHelpPage = null; function KTStandardDispatcher() { global $main; @@ -190,6 +191,7 @@ class KTStandardDispatcher extends KTDispatcher { $this->oPage->setBreadcrumbs($this->aBreadcrumbs); $this->oPage->setPageContents($data); $this->oPage->setUser($this->oUser); + $this->oPage->setHelp($this->sHelpPage); // handle errors that were set using KTErrorMessage. $errors = KTUtil::arrayGet($_SESSION, 'KTErrorMessage', array()); diff --git a/lib/help/help.inc.php b/lib/help/help.inc.php index 6d1e5f0..e0fff4e 100644 --- a/lib/help/help.inc.php +++ b/lib/help/help.inc.php @@ -1,34 +1,114 @@ help_table AS hlp WHERE hlp.fSection = ?"; - $aParams = array($sSection); - $sHelpFile = DBUtil::getOneResultKey(array($sQuery, $aParams), 'helpinfo'); - if (PEAR::isError($sHelpFile)) { - return $sHelpFile; - } - $sQuery = "SELECT hlprp.description AS contents FROM - $default->help_replacement_table AS hlprp WHERE - hlprp.name = ?"; - $aParams = array($sHelpFile); - $sHelpContents = DBUtil::getOneResultKey(array($sQuery, - $aParams), 'contents'); - if (PEAR::isError($sHelpContents)) { - return $sHelpContents; + + function getHelpSubPath($sHelpFile) { + if (empty($sHelpFile)) { return false; } + $path_segments = explode("/", $sHelpFile); + // cannot be empty, must contain at _least_ 1 item. + if (empty($path_segments[0])) { + $path_segments = array_slice($path_segments,1); } - if (!(is_null($sHelpContents) || trim($sHelpContents) === "")) { - return $sHelpContents; + + if (empty($path_segments) or (count($path_segments) < 2)) { + return false; // FIXME use PEAR::Error } - return file_get_contents("$default->uiDirectory/help/" . $sHelpFile); + + // we now assume that path_segments[0] is the module + // path_segments[1..] is the subpath. we need to insert the LANG + + $lang_code = 'EN'; // FIXME extract the lang from the environ (?) + + $final_path = array(null,'kthelp', $path_segments[0]); + $final_path[] = $lang_code; + $final_path = array_merge($final_path, array_slice($path_segments, 1)); + + $help_path = implode('/',$final_path); + + return $help_path; } function getHelpFromFile($sHelpFile) { - global $default; - return file_get_contents("$default->uiDirectory/help/" . $sHelpFile); + if (empty($sHelpFile)) { return false; } + $help_path = KTHelp::getHelpSubPath($sHelpFile); + + $fspath = KT_DIR . $help_path; // FIXME use OS.path_sep equivalent? + + if (!file_exists($fspath)) { + return false; + } + + if (KTHelp::isImageFile($help_path)) { + return false; // can't - not what users expect. + } + + // now we ASSUME its html: we'll fail anyway if we aren't. + $handle = fopen($fspath, "r"); + $contents = fread($handle, filesize($fspath)); + fclose($handle); + + $info = KTHelp::_parseHTML($contents); + + $body = KTUtil::arrayGet($info,'body'); + if (empty($body)) { + return false; + } + + $info['name'] = $help_path; // set so we can save into db if needed. + + return $info; + } + + // world's simplest (and possibly worst) regex-split. + function _parseHTML($sHTML) { + $title_array = preg_split('##',$sHTML,-1,PREG_SPLIT_NO_EMPTY); + $body_array = preg_split('##',$sHTML,-1,PREG_SPLIT_NO_EMPTY); + + $res = array(); + if (count($title_array) > 2) { + $res['title'] = $title_array[1]; + } + + if (count($body_array) > 2) { + $res['body'] = $body_array[1]; + } + + //var_dump($body_array); + return $res; } + + function isImageFile($sHelpPath) { + // from pluginutil.inc.php + $fspath = KT_DIR . $sHelpPath; + + $pi = pathinfo($fspath); + $mime_type = ""; + $sExtension = KTUtil::arrayGet($pi, 'extension'); + if (!empty($sExtension)) { + $mime_type = DBUtil::getOneResultKey(array("SELECT mimetypes FROM " . KTUtil::getTableName('mimetypes') . " WHERE LOWER(filetypes) = ?", $sExtension), "mimetypes"); + } + + if (($mime_type == 'image/png') || ($mime_type == 'image/gif') || ($mime_type == 'image/jpeg')) { + + } + + return false; + } + + function outputHelpImage($sHelpPath) { + $fspath = KT_DIR . $sHelpPath; + + + header("Content-Type: $mime_type"); + header("Content-Length: " . filesize($fspath)); + readfile($fspath); // does this output it?! + exit(0); + } + } ?> diff --git a/lib/help/helpreplacement.inc.php b/lib/help/helpreplacement.inc.php index 50ce738..7898cfb 100644 --- a/lib/help/helpreplacement.inc.php +++ b/lib/help/helpreplacement.inc.php @@ -9,11 +9,13 @@ class KTHelpReplacement extends KTEntity { var $sName; /** replacement string */ var $sDescription; + var $sTitle; var $_aFieldToSelect = array( "iId" => "id", "sName" => "name", "sDescription" => "description", + "sTitle" => 'title', ); var $_bUsePearError = true; @@ -21,9 +23,11 @@ class KTHelpReplacement extends KTEntity { function getID() { return $this->iId; } function getName() { return $this->sName; } function getDescription() { return $this->sDescription; } + function getTitle() { return $this->sTitle; } function setID($iId) { $this->iId = $iId; } function setName($sName) { $this->sName = $sName; } function setDescription($sDescription) { $this->sDescription = $sDescription; } + function setTitle($sTitle) { $this->sTitle= $sTitle; } function _table () { global $default; diff --git a/lib/templating/kt3template.inc.php b/lib/templating/kt3template.inc.php index a5c3b1d..f8c0ab0 100644 --- a/lib/templating/kt3template.inc.php +++ b/lib/templating/kt3template.inc.php @@ -33,6 +33,7 @@ class KTPage { var $breadcrumbSection = false; var $menu = null; var $userMenu = null; + var $helpPage = null; /** the "component". Used to set the page header (see documentation for explanation). */ var $componentLabel = 'Browse Collections'; @@ -262,6 +263,17 @@ class KTPage { return $aTuple; } + function setHelp($sHelpPage) { + $this->helpPage = $sHelpPage; + } + + function getHelpURL() { + if (empty($this->helpPage)) { + return null; + } + + return '/help.php/' . $this->helpPage; // FIXME handle auto-url + } } /* set $main - this is used by the rest of the system. */ diff --git a/plugins/ktcore/admin/manageHelp.php b/plugins/ktcore/admin/manageHelp.php index 476a1b8..4436cfd 100755 --- a/plugins/ktcore/admin/manageHelp.php +++ b/plugins/ktcore/admin/manageHelp.php @@ -19,14 +19,14 @@ class ManageHelpDispatcher extends KTAdminDispatcher { function getData() { $this->aBreadcrumbs[] = array('action' => 'manageHelp', 'name' => _('Help Administration')); $this->oPage->setBreadcrumbDetails(_('select a section')); - + $this->oPage->setTitle(_('Help Administration')); $oTemplating = new KTTemplating; $aHelpReplacements =& KTHelpReplacement::getList(); - $aHelps =& KTHelpEntity::getList(); + //$aHelps =& KTHelpEntity::getList(); $oTemplate = $oTemplating->loadTemplate("ktcore/manage_help"); $aTemplateData = array( "context" => &$this, - "helps" => $aHelps, + //"helps" => $aHelps, "helpreplacements" => $aHelpReplacements, ); @@ -35,6 +35,7 @@ class ManageHelpDispatcher extends KTAdminDispatcher { function getReplacementItemData($oHelpReplacement) { $this->aBreadcrumbs[] = array('action' => 'manageHelp', 'name' => _('Help Administration')); + $this->oPage->setTitle(_('Editing: ') . $oHelpReplacement->getTitle()); $oTemplating = new KTTemplating; $oTemplate = $oTemplating->loadTemplate("ktcore/manage_help_item"); $aTemplateData = array( @@ -80,6 +81,13 @@ class ManageHelpDispatcher extends KTAdminDispatcher { return $this->errorRedirectToMain(_("No description given")); } $oHelpReplacement->setDescription($description); + + $title = KTUtil::arrayGet($_REQUEST, 'title'); + if (empty($title)) { + return $this->errorRedirectToMain(_("No title given")); + } + $oHelpReplacement->setTitle($title); + $res = $oHelpReplacement->update(); if (PEAR::isError($res)) { return $this->errorRedirectToMain(_("Error updating item")); @@ -89,21 +97,29 @@ class ManageHelpDispatcher extends KTAdminDispatcher { function do_customise() { $name = KTUtil::arrayGet($_REQUEST, 'name'); + $name = KTHelp::getHelpSubPath($name); $oHelpReplacement = KTHelpReplacement::getByName($name); // XXX: Check against "already exists" if (!PEAR::isError($oHelpReplacement)) { // Already exists... - return $this->redirectTo('editReplacement', 'id=' . $oHelpReplacement->getId()); + return $this->errorRedirectTo('editReplacement', _('Replacement already exists.'),'id=' . $oHelpReplacement->getId()); + } + $info = KTHelp::getHelpFromFile($name); + if ($info === false) { + $info = array('name' => $name); + $info['title'] = _('New Help File'); + $info['body'] = _('New Help File'); } - $description = KTHelp::getHelpFromFile($name); $oHelpReplacement = KTHelpReplacement::createFromArray(array( - 'name' => $name, - 'description' => $description, + 'name' => $info['name'], + 'description' => $info['body'], + 'title' => $info['title'], )); + if (PEAR::isError($oHelpReplacement)) { return $this->errorRedirectToMain(_("Unable to create replacement")); } - return $this->successRedirectTo('editReplacement', 'id=' . $oHelpReplacement->getId()); + return $this->successRedirectTo('editReplacement', _('Created replacement.'), 'id=' . $oHelpReplacement->getId()); } } diff --git a/resources/css/kt-framing.css b/resources/css/kt-framing.css index d2bac2e..be3f3a2 100644 --- a/resources/css/kt-framing.css +++ b/resources/css/kt-framing.css @@ -611,6 +611,21 @@ The text will be hidden for screen view. The generic fahrner-ish approach comes width: 16px; cursor: pointer; } + +.ktHelp { + background: transparent url(../../thirdparty/icon-theme/16x16/apps/help-browser.png) top left no-repeat; + float: right; + display: block; + text-decoration: none; + overflow: hidden; + border: 0 !important; + padding: 0; + padding-top: 16px; + height: 0px !important; + height /**/: 16px; + width: 16px; + cursor: pointer; +} /* FIXME when available icon-naming-conformant sets have better coverage, make these more accurate. */ .ktAction.ktDelete { background: transparent url(../../thirdparty/icon-theme/16x16/mimetypes/x-directory-trash.png) top left no-repeat; } diff --git a/sql/mysql/install/structure.sql b/sql/mysql/install/structure.sql index 3a7ab16..a54a7e8 100644 --- a/sql/mysql/install/structure.sql +++ b/sql/mysql/install/structure.sql @@ -719,7 +719,8 @@ CREATE TABLE `help` ( CREATE TABLE `help_replacement` ( `id` int(11) NOT NULL default '0', - `name` varchar(100) NOT NULL default '', + `name` varchar(255) NOT NULL default '', + `title` varchar(255) NOT NULL default '', `description` text NOT NULL, PRIMARY KEY (`id`) ) TYPE=InnoDB ; diff --git a/sql/mysql/upgrade/2.99.7/help_replacement.sql b/sql/mysql/upgrade/2.99.7/help_replacement.sql new file mode 100644 index 0000000..3f3d943 --- /dev/null +++ b/sql/mysql/upgrade/2.99.7/help_replacement.sql @@ -0,0 +1,2 @@ +ALTER TABLE help_replacement CHANGE name name VARCHAR(255) NOT NULL default ''; +ALTER TABLE help_replacement ADD title VARCHAR(255) NOT NULL default ''; \ No newline at end of file diff --git a/templates/kt3/standard_page.smarty b/templates/kt3/standard_page.smarty index a71f81f..6918f8f 100644 --- a/templates/kt3/standard_page.smarty +++ b/templates/kt3/standard_page.smarty @@ -118,7 +118,9 @@
-

{$page->componentLabel}

+

{$page->componentLabel} +{if ($page->getHelpURL() != null)} Help {/if} +

{if (!empty($page->errStack))} diff --git a/templates/ktcore/help_with_edit.smarty b/templates/ktcore/help_with_edit.smarty new file mode 100644 index 0000000..6bd227f --- /dev/null +++ b/templates/ktcore/help_with_edit.smarty @@ -0,0 +1,6 @@ +

Edit this help page.

+{if (!$help_body)} +

No content specified for this help file yet. Edit it first.

+{else} +{$help_body} +{/if} \ No newline at end of file diff --git a/templates/ktcore/manage_help.smarty b/templates/ktcore/manage_help.smarty index b930467..18d8d6f 100644 --- a/templates/ktcore/manage_help.smarty +++ b/templates/ktcore/manage_help.smarty @@ -1,28 +1,7 @@

Current help assignments

- - - - - - - - -{foreach item=oHelpEntity from=$helps } - - - - - -{ /foreach } -
SectionFilenameCustomise
{ $oHelpEntity->sSection } { $oHelpEntity->sFilename } -{ assign var="replacement" value=$oHelpEntity->checkReplacement() } -{ if $replacement } -Edit -{ else } -Customise -{ /if } -
+

{i18n}To customise a help file, please visit that file +via the help system, and click on customise this help file.{/i18n}

{ if $helpreplacements }

Existing customised help pages

@@ -45,5 +24,9 @@ { /foreach } + +{else} +

No Help files have to customised.

+ { /if } diff --git a/templates/ktcore/manage_help_item.smarty b/templates/ktcore/manage_help_item.smarty index 963e1b8..139cc48 100644 --- a/templates/ktcore/manage_help_item.smarty +++ b/templates/ktcore/manage_help_item.smarty @@ -12,6 +12,7 @@ tinyMCE.init({
+

diff --git a/thirdparty/icon-theme/16x16/apps/help-browser.png b/thirdparty/icon-theme/16x16/apps/help-browser.png new file mode 100644 index 0000000..3a5dbe7 Binary files /dev/null and b/thirdparty/icon-theme/16x16/apps/help-browser.png differ -- libgit2 0.21.4