2015-10-15 19:28:56 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* API: loading categories and setting styles
|
|
|
|
*
|
2016-04-06 21:57:40 +02:00
|
|
|
* Usage: /egroupware/api/categories.php[?app=calendar]
|
2015-10-15 19:28:56 +02:00
|
|
|
*
|
|
|
|
* @link www.egroupware.org
|
|
|
|
* @author Nathan Gray
|
2016-04-06 21:57:40 +02:00
|
|
|
* @package api
|
2015-10-15 19:28:56 +02:00
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
* @version $Id$
|
|
|
|
*/
|
|
|
|
|
2016-04-06 21:57:40 +02:00
|
|
|
use EGroupware\Api;
|
|
|
|
|
2015-10-15 19:28:56 +02:00
|
|
|
// switch evtl. set output-compression off, as we cant calculate a Content-Length header with transparent compression
|
|
|
|
ini_set('zlib.output_compression', 0);
|
|
|
|
|
|
|
|
$GLOBALS['egw_info'] = array(
|
|
|
|
'flags' => array(
|
2016-04-06 21:57:40 +02:00
|
|
|
'currentapp' => 'api',
|
2015-10-15 19:28:56 +02:00
|
|
|
'noheader' => true,
|
|
|
|
'nocachecontrol' => true,
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
include '../header.inc.php';
|
|
|
|
|
|
|
|
// Get appname
|
2016-04-06 21:57:40 +02:00
|
|
|
$appname = $_GET['app'] && $GLOBALS['egw_info']['apps'][$_GET['app']] ? $_GET['app'] : Api\Categories::GLOBAL_APPNAME;
|
2015-10-15 19:28:56 +02:00
|
|
|
|
2016-04-06 21:57:40 +02:00
|
|
|
$cats = new Api\Categories('', $appname);
|
|
|
|
$categories = $cats->return_array('all',0, false, '', 'ASC','',$appname==Api\Categories::GLOBAL_APPNAME);
|
2015-10-15 19:28:56 +02:00
|
|
|
|
|
|
|
$content = "/* Category CSS for $appname */\n\n";
|
|
|
|
|
|
|
|
foreach($categories as $cat)
|
|
|
|
{
|
|
|
|
if($cat['data']['color'])
|
|
|
|
{
|
2016-01-19 22:50:13 +01:00
|
|
|
// Use slightly more specific selector that just class, to allow defaults
|
|
|
|
// if the category has no color
|
2016-02-10 10:45:33 +01:00
|
|
|
$content .= "tr.cat_{$cat['id']} {border-left:6px solid {$cat['data']['color']};} div.cat_{$cat['id']}, span.cat_{$cat['id']} { background-color: {$cat['data']['color']};} /*{$cat['name']}*/\n";
|
2015-10-15 19:28:56 +02:00
|
|
|
}
|
|
|
|
if($cat['data']['icon'])
|
|
|
|
{
|
|
|
|
$content .= ".cat_{$cat['id']} .cat_icon { background-image: url('". admin_categories::icon_url($cat['data']['icon']) ."');} /*{$cat['name']}*/\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// use an etag over categories
|
|
|
|
$etag = '"'.md5($content).'"';
|
|
|
|
|
|
|
|
// headers to allow caching, egw_framework specifies etag on url to force reload, even with Expires header
|
2016-04-06 21:57:40 +02:00
|
|
|
Api\Session::cache_control(86400); // cache for 1 day
|
2015-10-15 19:28:56 +02:00
|
|
|
Header('Content-Type: text/css; charset=utf-8');
|
|
|
|
Header('ETag: '.$etag);
|
|
|
|
|
|
|
|
// if servers send a If-None-Match header, response with 304 Not Modified, if etag matches
|
|
|
|
if (isset($_SERVER['HTTP_IF_NONE_MATCH']) && $_SERVER['HTTP_IF_NONE_MATCH'] == $etag)
|
|
|
|
{
|
|
|
|
header("HTTP/1.1 304 Not Modified");
|
2016-04-06 21:57:40 +02:00
|
|
|
exit;
|
2015-10-15 19:28:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// we run our own gzip compression, to set a correct Content-Length of the encoded content
|
|
|
|
if (in_array('gzip', explode(',',$_SERVER['HTTP_ACCEPT_ENCODING'])) && function_exists('gzencode'))
|
|
|
|
{
|
|
|
|
$content = gzencode($content);
|
|
|
|
header('Content-Encoding: gzip');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Content-Lenght header is important, otherwise browsers dont cache!
|
|
|
|
Header('Content-Length: '.bytes($content));
|
|
|
|
echo $content;
|