2015-10-05 18:01:39 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* EGroupware - Tutorial
|
|
|
|
*
|
|
|
|
* @link http://www.egroupware.org
|
2016-05-01 11:57:48 +02:00
|
|
|
* @package api
|
|
|
|
* @subpackage framework
|
2015-10-05 18:01:39 +02:00
|
|
|
* @author Hadi Nategh [hn@stylite.de]
|
2016-05-01 11:57:48 +02:00
|
|
|
* @copyright (c) 2015-16 by Stylite AG <info-AT-stylite.de>
|
2015-10-05 18:01:39 +02:00
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
2015-10-24 13:15:17 +02:00
|
|
|
* @version $Id$
|
2015-10-05 18:01:39 +02:00
|
|
|
*/
|
2015-10-24 13:15:17 +02:00
|
|
|
|
2016-05-01 11:57:48 +02:00
|
|
|
namespace EGroupware\Api\Framework;
|
|
|
|
|
2016-04-28 20:06:46 +02:00
|
|
|
use EGroupware\Api;
|
|
|
|
use EGroupware\Api\Etemplate;
|
|
|
|
|
2016-05-01 11:57:48 +02:00
|
|
|
class Tutorial
|
2015-10-24 13:15:17 +02:00
|
|
|
{
|
2015-10-05 18:01:39 +02:00
|
|
|
/**
|
|
|
|
* Methods callable via menuaction
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
public $public_functions = array(
|
|
|
|
'popup' => true
|
|
|
|
);
|
2015-10-24 13:15:17 +02:00
|
|
|
|
2015-10-05 18:01:39 +02:00
|
|
|
/**
|
|
|
|
* Popup window to display youtube video
|
2015-10-24 13:15:17 +02:00
|
|
|
*
|
|
|
|
* @param array $content
|
2015-10-05 18:01:39 +02:00
|
|
|
*/
|
2015-10-09 17:09:34 +02:00
|
|
|
function popup ($content=null)
|
2015-10-05 18:01:39 +02:00
|
|
|
{
|
2015-10-28 09:36:37 +01:00
|
|
|
// check and if not done register tutorial_menu hook
|
2016-05-01 11:57:48 +02:00
|
|
|
if (!Api\Hooks::exists('sidebox_all', 'api') ||
|
|
|
|
Api\Hooks::exists('sidebox_all', 'api', true) != 'EGroupware\\Api\\Framework\\Tutorial::tutorial_menu')
|
2015-10-28 09:36:37 +01:00
|
|
|
{
|
2016-04-28 20:06:46 +02:00
|
|
|
Api\Hooks::read(true);
|
2015-10-28 09:36:37 +01:00
|
|
|
}
|
|
|
|
|
2015-10-05 18:01:39 +02:00
|
|
|
//Allow youtube frame to pass the CSP check
|
2016-04-28 20:06:46 +02:00
|
|
|
Api\Header\ContentSecurityPolicy::add('frame-src', array('https://www.youtube.com'));
|
2015-10-24 13:15:17 +02:00
|
|
|
|
2016-05-01 11:57:48 +02:00
|
|
|
$tmpl = new Etemplate('api.tutorial');
|
2015-10-07 17:49:51 +02:00
|
|
|
if (!is_array($content))
|
|
|
|
{
|
2015-10-14 16:17:09 +02:00
|
|
|
// Get tutorial object id
|
|
|
|
$tuid_indx = explode('-',$_GET['tuid']);
|
|
|
|
$appName = $tuid_indx[0];
|
|
|
|
$lang = $tuid_indx[1];
|
|
|
|
$id = $tuid_indx[2];
|
|
|
|
}
|
|
|
|
else // set the first video of selected app
|
|
|
|
{
|
|
|
|
$appName = $content['list']['apps'];
|
|
|
|
$lang = $GLOBALS['egw_info']['user']['preferences']['common']['lang'];
|
|
|
|
$id ="0";
|
|
|
|
}
|
|
|
|
// read tutorials json file to fetch data
|
|
|
|
$tutorials = json_decode(self::getJsonData(), true);
|
|
|
|
$apps = array('introduction' => lang('Introduction'));
|
2015-10-24 13:15:17 +02:00
|
|
|
foreach (array_keys($tutorials) as $app)
|
2015-10-14 16:17:09 +02:00
|
|
|
{
|
|
|
|
// show only apps user has access to them
|
|
|
|
if (in_array($app, array_keys($GLOBALS['egw_info']['user']['apps']))) $apps [$app] = $app;
|
|
|
|
}
|
|
|
|
$sel_options = array(
|
|
|
|
'apps' => $apps,
|
|
|
|
);
|
|
|
|
// Check if the user has right to see the app's tutorial
|
|
|
|
if (in_array($appName, array_keys($GLOBALS['egw_info']['user']['apps'])) || $appName === "introduction")
|
|
|
|
{
|
|
|
|
// fallback to english video
|
|
|
|
$tutorial = $tutorials[$appName][$lang][$id]? $tutorials[$appName][$lang][$id]:
|
|
|
|
$tutorials[$appName]['en'][$id];
|
|
|
|
|
|
|
|
$list = array(
|
|
|
|
'apps' => $appName,
|
|
|
|
'0' => ''
|
2015-10-07 17:49:51 +02:00
|
|
|
);
|
2015-10-27 18:13:01 +01:00
|
|
|
foreach (isset($tutorials[$appName][$lang]) ? $tutorials[$appName][$lang] : $tutorials[$appName]['en'] as $v)
|
2015-10-09 09:31:35 +02:00
|
|
|
{
|
2018-11-14 09:57:40 +01:00
|
|
|
$v ['onclick'] = 'etemplate2.getByApplication("api")[0].widgetContainer.getWidgetById("src").set_value("'.$v['src'].'")';
|
2015-10-14 16:17:09 +02:00
|
|
|
array_push($list, $v);
|
2015-10-09 09:31:35 +02:00
|
|
|
}
|
2015-10-14 16:17:09 +02:00
|
|
|
$content = array (
|
|
|
|
'src' => $tutorial['src'],
|
|
|
|
'title' => $tutorial['title'],
|
2015-10-19 17:00:42 +02:00
|
|
|
'desc' => $tutorial['desc'],
|
2015-10-14 16:17:09 +02:00
|
|
|
'list' => $list
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$content = array();
|
2016-05-01 11:57:48 +02:00
|
|
|
Api\Framework::message(lang('You do not have permission to see this tutorial!'));
|
2015-10-14 16:17:09 +02:00
|
|
|
}
|
2015-10-24 13:15:17 +02:00
|
|
|
|
2016-05-01 11:57:48 +02:00
|
|
|
$tmpl->exec('api.EGroupware\\Api\\Framework\\Tutorial.popup', $content, $sel_options, array(), array(), 2);
|
2015-10-07 17:49:51 +02:00
|
|
|
}
|
2015-10-24 13:15:17 +02:00
|
|
|
|
2015-10-05 18:01:39 +02:00
|
|
|
/**
|
|
|
|
* Ajax function to get videos links as json
|
|
|
|
*/
|
2016-05-01 11:57:48 +02:00
|
|
|
public static function ajax_data()
|
2015-10-05 18:01:39 +02:00
|
|
|
{
|
2016-04-28 20:06:46 +02:00
|
|
|
$response = Api\Json\Response::get();
|
2015-10-05 18:01:39 +02:00
|
|
|
$response->data(json_decode(self::getJsonData()));
|
|
|
|
}
|
2015-10-24 13:15:17 +02:00
|
|
|
|
2015-10-05 18:01:39 +02:00
|
|
|
/**
|
|
|
|
* Function to fetch data from tutorials.json file
|
|
|
|
*
|
2015-10-24 13:15:17 +02:00
|
|
|
* @return string returns json string
|
2015-10-05 18:01:39 +02:00
|
|
|
*/
|
|
|
|
static function getJsonData()
|
|
|
|
{
|
2016-05-01 11:57:48 +02:00
|
|
|
if (!($json = Api\Cache::getCache(Api\Cache::TREE, __CLASS__, 'egw_tutorial_json')))
|
2015-10-05 18:01:39 +02:00
|
|
|
{
|
2018-08-23 14:54:37 +02:00
|
|
|
$json = file_get_contents('https://www.egroupware.org/videos/tutorials.json',
|
2018-03-12 11:10:02 +01:00
|
|
|
false, Api\Framework::proxy_context());
|
2015-10-19 17:00:42 +02:00
|
|
|
// Fallback tutorials.json
|
2016-05-01 11:57:48 +02:00
|
|
|
if (!$json) $json = file_get_contents('api/setup/tutorials.json');
|
2015-10-09 17:09:34 +02:00
|
|
|
// Cache the json object for two hours
|
2016-05-01 11:57:48 +02:00
|
|
|
Api\Cache::setCache(Api\Cache::TREE, __CLASS__, 'egw_tutorial_json', $json, 7200);
|
2015-10-05 18:01:39 +02:00
|
|
|
}
|
2015-10-24 13:15:17 +02:00
|
|
|
|
2015-10-05 18:01:39 +02:00
|
|
|
return $json;
|
|
|
|
}
|
2015-10-28 09:36:37 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Static function to build egw tutorial sidebox menu
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public static function tutorial_menu()
|
|
|
|
{
|
2016-04-28 20:06:46 +02:00
|
|
|
if (Api\Header\UserAgent::mobile()) return;
|
2015-10-28 09:36:37 +01:00
|
|
|
$tutorials = json_decode(self::getJsonData(),true);
|
|
|
|
$appname = $GLOBALS['egw_info']['flags']['currentapp'];
|
|
|
|
if (!is_array($tutorials[$appname])) return false;
|
2015-11-03 17:15:56 +01:00
|
|
|
if (!$GLOBALS['egw_info']['server']['egw_tutorial_disable']
|
|
|
|
|| $GLOBALS['egw_info']['server']['egw_tutorial_disable'] == 'intro')
|
2015-10-28 09:36:37 +01:00
|
|
|
{
|
|
|
|
$file = Array (
|
|
|
|
array(
|
|
|
|
'text' => '<div id="egw_tutorial_'.$appname.'_sidebox" class="egwTutorial"/>',
|
|
|
|
'no_lang' => true,
|
|
|
|
'link' => false,
|
|
|
|
'icon' => false,
|
2015-10-29 14:45:16 +01:00
|
|
|
)
|
2015-10-28 09:36:37 +01:00
|
|
|
);
|
|
|
|
display_sidebox($appname, lang('Video Tutorials'), $file);
|
|
|
|
}
|
|
|
|
}
|
2015-10-24 13:15:17 +02:00
|
|
|
}
|