1<?php
2/**
3 * @package tikiwiki
4 */
5// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project
6//
7// All Rights Reserved. See copyright.txt for details and a complete list of authors.
8// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
9// $Id$
10
11/**
12 * Cypht Integration
13 *
14 * Some of the following constants are automatically filled in when
15 * the build process is run. If you change them in site/index.php
16 * and rerun the build process your changes will be lost
17 *
18 * APP_PATH   absolute path to the php files of the app
19 * DEBUG_MODE flag to enable easier debugging and development
20 * CACHE_ID   unique string to bust js/css browser caching for a new build
21 * SITE_ID    random site id used for page keys
22 */
23
24require_once("tiki-setup.php");
25
26$access->check_feature('feature_webmail');
27$access->check_permission_either(['tiki_p_use_webmail', 'tiki_p_use_group_webmail']);
28$access->check_user($user);
29
30if (empty($_SESSION['cypht']['username']) || $_SESSION['cypht']['username'] != $user) {
31  unset($_SESSION['cypht']);
32  $headerlib = TikiLib::lib('header');
33  $headerlib->add_js('
34document.cookie = "hm_reload_folders=1";
35for(var i =0; i < sessionStorage.length; i++){
36    var key = sessionStorage.key(i);
37    if (key.indexOf(window.location.pathname) > -1) {
38        sessionStorage.removeItem(key);
39    }
40}
41  ');
42}
43
44if (empty($_SESSION['cypht']['preference_name']) || $_SESSION['cypht']['preference_name'] != 'cypht_user_config'
45  || (! empty($_SESSION['cypht']['username']) && $_SESSION['cypht']['username'] != $user)) {
46  // resetting the session on purpose - could be coming from PluginCypht
47  $_SESSION['cypht'] = [];
48  $_SESSION['cypht']['preference_name'] = 'cypht_user_config';
49}
50
51define('VENDOR_PATH', $tikipath.'/vendor_bundled/vendor/');
52define('APP_PATH', VENDOR_PATH.'jason-munro/cypht/');
53define('WEB_ROOT', $tikiroot.'vendor_bundled/vendor/jason-munro/cypht/');
54define('DEBUG_MODE', false);
55
56define('CACHE_ID', 'FoHc85ubt5miHBls6eJpOYAohGhDM61Vs%2Fm0BOxZ0N0%3D'); // Cypht uses for asset cache busting but we run the assets through Tiki pipeline, so no need to generate a unique key here
57define('SITE_ID', 'Tiki-Integration');
58
59/* get includes */
60require_once APP_PATH.'lib/framework.php';
61require_once $tikipath.'/lib/cypht/integration/classes.php';
62
63if (empty($_SESSION['cypht']['request_key'])) {
64  $_SESSION['cypht']['request_key'] = Hm_Crypt::unique_id();
65}
66$_SESSION['cypht']['username'] = $user;
67
68/* get configuration */
69$config = new Tiki_Hm_Site_Config_File(APP_PATH.'hm3.rc');
70
71/* process the request */
72$dispatcher = new Hm_Dispatch($config);
73
74$smarty->assign('output_data', '<div class="inline-cypht"><input type="hidden" id="hm_page_key" value="'.Hm_Request_Key::generate().'" />'
75	. $dispatcher->output
76	. "</div>");
77$smarty->assign('mid', 'tiki-webmail.tpl');
78$smarty->display('tiki.tpl');
79