2013-05-22 22:13:12 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* EGroupware - Home - A simple portlet for displaying an entry
|
|
|
|
*
|
|
|
|
* @link www.egroupware.org
|
|
|
|
* @author Nathan Gray
|
|
|
|
* @copyright (c) 2013 by Nathan Gray
|
|
|
|
* @package home
|
|
|
|
* @subpackage portlet
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
* @version $Id$
|
|
|
|
*/
|
|
|
|
|
2016-04-28 20:06:46 +02:00
|
|
|
use EGroupware\Api\Link;
|
|
|
|
use EGroupware\Api\Framework;
|
|
|
|
use EGroupware\Api\Vfs;
|
|
|
|
use EGroupware\Api\Etemplate;
|
|
|
|
|
2014-11-19 00:46:58 +01:00
|
|
|
/**
|
|
|
|
* A single entry is displayed with its application icon and title
|
|
|
|
*/
|
2013-05-22 22:13:12 +02:00
|
|
|
class home_link_portlet extends home_portlet
|
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Context for this portlet
|
|
|
|
*/
|
|
|
|
protected $context = array();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Title of entry
|
|
|
|
*/
|
|
|
|
protected $title = 'Link';
|
|
|
|
|
2014-11-19 00:46:58 +01:00
|
|
|
/**
|
|
|
|
* Image shown. Leave at false to have it automatically set an icon based
|
|
|
|
* on the entry or customize it for the context.
|
|
|
|
*/
|
|
|
|
protected $image = false;
|
|
|
|
|
2014-11-06 22:40:03 +01:00
|
|
|
/**
|
|
|
|
* Base name for template
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $template_name = 'home.link';
|
|
|
|
|
2013-05-22 22:13:12 +02:00
|
|
|
/**
|
|
|
|
* Construct the portlet
|
|
|
|
*
|
2014-11-06 22:40:03 +01:00
|
|
|
* @param boolean $need_reload Flag to indicate that the portlet needs to be reloaded (exec will be called)
|
2013-05-22 22:13:12 +02:00
|
|
|
*/
|
2014-11-06 22:40:03 +01:00
|
|
|
public function __construct(Array &$context = array(), &$need_reload = false)
|
2013-05-22 22:13:12 +02:00
|
|
|
{
|
2013-05-23 00:44:27 +02:00
|
|
|
// Process dropped data into something useable
|
|
|
|
if($context['dropped_data'])
|
|
|
|
{
|
|
|
|
list($context['entry']['app'], $context['entry']['id']) = explode('::', $context['dropped_data'][0], 2);
|
|
|
|
unset($context['dropped_data']);
|
2014-11-06 22:40:03 +01:00
|
|
|
$need_reload = true;
|
2013-05-23 00:44:27 +02:00
|
|
|
}
|
2016-04-28 20:06:46 +02:00
|
|
|
if($context['entry'] && is_array($context['entry']))
|
2013-05-22 22:13:12 +02:00
|
|
|
{
|
2016-04-28 20:06:46 +02:00
|
|
|
$this->title = $context['entry']['title'] = Link::title($context['entry']['app'], $context['entry']['id']);
|
2014-11-10 19:44:11 +01:00
|
|
|
|
2014-11-19 00:46:58 +01:00
|
|
|
// Reload to get the latest title
|
|
|
|
// TODO: This is a performance hit, it would be good to do this less
|
2014-11-10 19:44:11 +01:00
|
|
|
$need_reload |= (boolean)$context['entry']['id'];
|
2013-05-22 22:13:12 +02:00
|
|
|
}
|
2013-05-23 00:44:27 +02:00
|
|
|
$this->context = $context;
|
2013-05-22 22:13:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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'=> 'Single Entry',
|
|
|
|
'title'=> $this->context['entry'] ? lang($this->context['entry']['app']) : lang('None'),
|
|
|
|
'description'=> lang('Show one entry')
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-11-06 22:40:03 +01:00
|
|
|
* Generate display
|
2013-05-22 22:13:12 +02:00
|
|
|
*
|
2013-05-29 21:25:12 +02:00
|
|
|
* @param id String unique ID, provided to the portlet so it can make sure content is
|
|
|
|
* unique, if needed.
|
2013-05-22 22:13:12 +02:00
|
|
|
*/
|
2016-04-28 20:06:46 +02:00
|
|
|
public function exec($id = null, Etemplate &$etemplate = null)
|
2013-05-22 22:13:12 +02:00
|
|
|
{
|
2014-11-06 22:40:03 +01:00
|
|
|
// Check for custom template for app
|
2014-11-19 00:46:58 +01:00
|
|
|
$custom_template = false;
|
2014-11-06 22:40:03 +01:00
|
|
|
if($this->context && $this->context['entry'] && $this->context['entry']['app'] &&
|
|
|
|
$etemplate->read($this->context['entry']['app'] . '.' . $this->template_name))
|
|
|
|
{
|
|
|
|
// No action needed, custom template loaded as side-effect
|
2014-11-19 00:46:58 +01:00
|
|
|
$custom_template = true;
|
2014-11-06 22:40:03 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$etemplate->read($this->template_name);
|
|
|
|
}
|
|
|
|
|
2014-11-19 00:46:58 +01:00
|
|
|
|
|
|
|
$etemplate->set_dom_id($id);
|
2016-04-28 20:06:46 +02:00
|
|
|
|
2014-11-19 00:46:58 +01:00
|
|
|
$content = array(
|
|
|
|
'image' => $this->image
|
|
|
|
);
|
|
|
|
|
|
|
|
// Try to load entry
|
|
|
|
if($this->context['entry'] && $this->context['entry']['app'])
|
|
|
|
{
|
2014-11-27 19:31:08 +01:00
|
|
|
|
|
|
|
// Always load app's css
|
2016-04-28 20:06:46 +02:00
|
|
|
Framework::includeCSS($this->context['entry']['app'], 'app-'.$GLOBALS['egw_info']['user']['preferences']['common']['theme']) ||
|
|
|
|
Framework::includeCSS($this->context['entry']['app'],'app');
|
|
|
|
|
2014-11-19 00:46:58 +01:00
|
|
|
try
|
|
|
|
{
|
|
|
|
$classname = $this->context['entry']['app'] . '_egw_record';
|
|
|
|
if(class_exists($classname))
|
|
|
|
{
|
|
|
|
$record = new $classname($this->context['entry']['id']);
|
2014-12-19 23:26:29 +01:00
|
|
|
if($record && $record->get_record_array())
|
2014-11-19 00:46:58 +01:00
|
|
|
{
|
|
|
|
// If there's a custom template, send the full record
|
|
|
|
if($custom_template)
|
|
|
|
{
|
|
|
|
$content += $record->get_record_array();
|
|
|
|
}
|
2015-03-05 00:13:36 +01:00
|
|
|
// Use calendar hover for calendar
|
|
|
|
if($this->context['entry']['app'] == 'calendar')
|
|
|
|
{
|
|
|
|
$etemplate->setElementAttribute('tooltip','class', 'tooltip calendar_uitooltip');
|
|
|
|
}
|
2014-11-19 00:46:58 +01:00
|
|
|
if($content['image'] == false)
|
|
|
|
{
|
|
|
|
$content['image'] = $record->get_icon();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch(Exception $e)
|
|
|
|
{
|
|
|
|
error_log("Problem loading record " . array2string($this->context['entry']));
|
|
|
|
throw $e;
|
|
|
|
}
|
2016-04-28 20:06:46 +02:00
|
|
|
|
2014-11-19 00:46:58 +01:00
|
|
|
// Set a fallback image
|
|
|
|
if($content['image'] == false)
|
|
|
|
{
|
|
|
|
if($this->context['entry'] && $this->context['entry']['app'])
|
|
|
|
{
|
|
|
|
$content['image'] = $this->context['entry']['app'] . '/navbar';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$content['image'] = 'home';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-17 23:18:24 +01:00
|
|
|
// Filemanager support - links need app = 'file' and type set
|
|
|
|
if($this->context && $this->context['entry'] && $this->context['entry']['app'] == 'filemanager')
|
|
|
|
{
|
|
|
|
$this->context['entry']['app'] = 'file';
|
|
|
|
$this->context['entry']['path'] = $this->context['entry']['title'] = $this->context['entry']['id'];
|
2016-04-28 20:06:46 +02:00
|
|
|
$this->context['entry']['type'] = Vfs::mime_content_type($this->context['entry']['id']);
|
|
|
|
$content['image'] = Framework::link('/api/thumbnail.php',array('path' => $this->context['entry']['id']));
|
2014-11-17 23:18:24 +01:00
|
|
|
}
|
|
|
|
|
2014-11-19 00:46:58 +01:00
|
|
|
$content += $this->context;
|
|
|
|
|
2014-11-06 22:40:03 +01:00
|
|
|
if(!is_array($content['entry']))
|
|
|
|
{
|
|
|
|
$content['entry'] = null;
|
|
|
|
}
|
2014-11-17 23:18:24 +01:00
|
|
|
|
2014-11-06 22:40:03 +01:00
|
|
|
$etemplate->exec('home.home_link_portlet.exec',$content);
|
2013-05-22 22:13:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a list of allowable actions for the portlet.
|
|
|
|
*
|
|
|
|
* These actions will be merged with the default porlet actions.
|
|
|
|
* We add an 'edit' action as default so double-clicking the widget
|
|
|
|
* opens the entry
|
|
|
|
*/
|
|
|
|
public function get_actions()
|
|
|
|
{
|
|
|
|
$actions = array(
|
|
|
|
'view' => array(
|
|
|
|
'icon' => 'view',
|
|
|
|
'caption' => lang('open'),
|
|
|
|
'default' => true,
|
|
|
|
'hideOnDisabled' => false,
|
|
|
|
'onExecute' => 'javaScript:app.home.open_link',
|
|
|
|
),
|
|
|
|
'edit_settings' => array(
|
|
|
|
'default' => false
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$actions['view']['enabled'] = (bool)$this->context['entry'];
|
2013-05-29 21:25:12 +02:00
|
|
|
|
2013-05-22 22:13:12 +02:00
|
|
|
return $actions;
|
|
|
|
}
|
2014-12-19 23:26:29 +01:00
|
|
|
/**
|
|
|
|
* This portlet accepts files and links
|
|
|
|
*
|
|
|
|
* @return boolean|String[]
|
|
|
|
*/
|
|
|
|
public function accept_drop()
|
|
|
|
{
|
|
|
|
return array('file','link');
|
|
|
|
}
|
2013-05-22 22:13:12 +02:00
|
|
|
}
|