From 8d5c4138bc561ffc0bd782ee0391af1b4c84810b Mon Sep 17 00:00:00 2001 From: Nathan Gray Date: Tue, 24 Sep 2013 21:14:05 +0000 Subject: [PATCH] Attempt to show legacy home content in new portlets --- home/inc/class.home_legacy_portlet.inc.php | 118 +++++++++++++++++++++ home/inc/class.home_ui.inc.php | 54 +++++++++- 2 files changed, 170 insertions(+), 2 deletions(-) create mode 100644 home/inc/class.home_legacy_portlet.inc.php diff --git a/home/inc/class.home_legacy_portlet.inc.php b/home/inc/class.home_legacy_portlet.inc.php new file mode 100644 index 0000000000..9012685986 --- /dev/null +++ b/home/inc/class.home_legacy_portlet.inc.php @@ -0,0 +1,118 @@ +context = $context; + + // Try to load content here, so all needed info is available + $appname = $this->context['app']; + if(!$appname || !$GLOBALS['egw']->hooks->hook_exists('home', $appname)) + { + return; + } + // Set a fallback title for if we can't extract it + $this->title = lang($this->context['app']); + + // Execute hook to get content + ob_start(); + $_content = $GLOBALS['egw']->hooks->single('home',$appname); + if (!$_content || $_content == 1) // content has been echoed and not returned + { + $_content = ob_get_contents(); + ob_end_clean(); + } + if($_content) + { + // Now we have to extract the actual content + $dom = new DOMDocument(); + libxml_use_internal_errors(true); + $dom->loadHTML($_content,LIBXML_NOWARNING + LIBXML_NOERROR); + $finder = new DOMXPath($dom); + + // Find header for title + $title = $finder->query("//div[contains(@class,'divSideboxHeader')]/descendant::strong"); + if($title->length) + { + $this->title = $title->item(0)->textContent; + } + + // Remove header + $content = $finder->query("//div[contains(@class,'divSideboxHeader')]/descendant::strong/ancestor::tr"); + for($i = 0; $i < $content->length; $i++) + { + $content->item($i)->parentNode->removeChild($content->item($i)); + } + + // Content remains + $content = $dom->saveHTML(); + $this->content = $content; + } + } + + public function get_actions() + { + + } + + /** + * Get a fragment of HTML for display + * + * @param id String unique ID, provided to the portlet so it can make sure content is + * unique, if needed. + * @return string HTML fragment for display + */ + public function get_content($id = null) + { + return $this->content; + } + + /** + * Some descriptive information about the portlet, so that users can decide if + * they want it or not, and for inclusion in lists, hover text, etc. + * + * These should be already translated, no further translation will be done. + * + * @return Array with keys + * - displayName: Used in lists + * - title: Put in the portlet header + * - description: A short description of what this portlet does or displays + */ + public function get_description() + { + return array( + 'displayName'=> 'Legacy portlet', + 'title'=> $this->title, + 'description'=> 'Egroupware <= v1.9' + ); + } +} +?> diff --git a/home/inc/class.home_ui.inc.php b/home/inc/class.home_ui.inc.php index ac6230a57f..4926196df6 100644 --- a/home/inc/class.home_ui.inc.php +++ b/home/inc/class.home_ui.inc.php @@ -119,13 +119,19 @@ class home_ui foreach((array)$GLOBALS['egw_info']['user']['preferences']['home']['portlets'] as $id => $context) { + error_log("Portlet: $id"); + error_log(array2string($context)); + if(!$id || in_array($id, array_keys($GLOBALS['egw_info']['user']['apps']))) continue; $content = ''; $attrs = array(); $this->get_portlet($id, $context, $content, $attrs); $portlets[$id] = $content; $attributes[$id] = $attrs; - } + + // Add in legacy HTML home bits + $this->get_legacy_portlets($template, $portlets, $attributes); + foreach($portlets as $index => $portlet) { $template->setElementAttribute('portlets', $index, (array)$attributes[$index]); @@ -180,6 +186,50 @@ class home_ui } return $portlet; } + + /** + * Get a list of pre-etemplate2 home hook content according to the individual + * application preferences. If we find a preference that indicates the user + * wants some content, we make a portlet for that app using the home_legacy_portlet, + * which fetches content from the home hook. + */ + protected function get_legacy_portlets(&$etemplate, &$content, &$attributes) + { + $sorted_apps = array_keys($GLOBALS['egw_info']['user']['apps']); + $portal_oldvarnames = array('mainscreen_showevents', 'homeShowEvents','homeShowLatest','mainscreen_showmail','mainscreen_showbirthdays','mainscreen_show_new_updated', 'homepage_display'); + + foreach($sorted_apps as $appname) + { + // If there's already [new] settings, or no preference, skip it + if($content[$appname]) continue; + $no_pref = true; + foreach($portal_oldvarnames as $varcheck) + { + $thisd = $GLOBALS['egw_info']['user']['preferences'][$appname][$varcheck]; + if(!(int)$thisd && $thisd) + { + $no_pref = false; + break; + } + } + if($no_pref || !$GLOBALS['egw']->hooks->hook_exists('home', $appname)) + { + continue; + } + $context = array( + 'class' => 'home_legacy_portlet', 'app' => $appname, + 'width' => 8, 'height' => 3 + ); + $_content = ''; + $_attributes = array(); + $this->get_portlet($appname, $context, $_content, $_attributes); + if(trim($_content)) + { + $content[$appname] = $_content; + $attributes[$appname] = $_attributes; + } + } + } /** * Get a list of all available portlets for add menu @@ -211,7 +261,7 @@ class home_ui } } } - + if(!$classes[$appname]) continue; // Build 'Add' actions for each discovered portlet.