model.php
4.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<?php
/**
* @copyright Copyright (c) 2009-2017 Ryan Demmer. All rights reserved
* @license GNU/GPL 2 or later - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* JCE is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses
*/
defined('_JEXEC') or die('RESTRICTED');
require_once dirname(__DIR__) . '/classes/model.php';
require_once dirname(__DIR__) . '/helpers/extension.php';
class WFModel extends WFModelBase
{
public static function authorize($task)
{
$user = JFactory::getUser();
// Joomla! 1.7+
if (method_exists('JUser', 'getAuthorisedViewLevels')) {
$action = ($task == 'admin' || $task == 'manage') ? 'core.' . $task : 'jce.' . $task;
if (!$user->authorise($action, 'com_jce')) {
return false;
}
} else {
// get rules from parameters
$component = JComponentHelper::getComponent('com_jce');
$params = json_decode($component->params);
$rules = isset($params->access) ? $params->access : null;
if (is_object($rules)) {
$action = ($task == 'admin' || $task == 'manage') ? 'core.' . $task : 'jce.' . $task;
if (isset($rules->$action)) {
$rule = $rules->$action;
$gid = $user->gid;
if (isset($rule->$gid) && $rule->$gid == 0) {
return false;
}
}
}
}
return true;
}
/**
* Get the current version.
*
* @return Version
*/
public function getVersion()
{
$xml = WFXMLHelper::parseInstallManifest(JPATH_ADMINISTRATOR . '/components/com_jce/jce.xml');
// return cleaned version number or date
$version = preg_replace('/[^0-9a-z]/i', '', $xml['version']);
if (!$version) {
return date('Y-m-d', strtotime('today'));
}
return $version;
}
public function getStyles()
{
$view = JRequest::getCmd('view');
$params = JComponentHelper::getParams('com_jce');
$theme = $params->get('theme', 'smoothness');
$path = JPATH_COMPONENT . '/media/css';
// Load styles
$styles = array();
$files = JFolder::files($path . '/' . $theme, '\.css');
foreach ($files as $file) {
$styles[] = $theme . '/' . $file;
}
$styles = array_merge($styles, array('styles.css', 'tips.css', 'icons.css', 'select.css'));
jimport('joomla.environment.browser');
$browser = JBrowser::getInstance();
if ($browser->getBrowser() == 'msie' && $browser->getMajor() < 8) {
$styles[] = 'styles_ie.css';
}
if (JFile::exists($path . '/' . $view . '.css')) {
$styles[] = $view . '.css';
}
return $styles;
}
public function loadStyles()
{
$styles = $this->getStyles();
foreach ($styles as $style) {
echo '<link rel="stylesheet" type="text/css" href="components/com_jce/media/css/' . $style . '" />' . "\n";
}
}
public static function getBrowserLink($element = null, $mediatype = '', $callback = '')
{
// load base classes
require_once JPATH_ADMINISTRATOR . '/components/com_jce/includes/base.php';
// set $url as empty string
$url = '';
wfimport('editor.libraries.classes.editor');
wfimport('editor.libraries.classes.token');
$wf = WFEditor::getInstance();
$app = JFactory::getApplication();
$profile = $wf->getProfile('browser');
// check the current user is in a profile
if ($profile) {
// get token
$token = WFToken::getToken();
$context = $wf->getContext();
$url = 'index.php?option=com_jce&view=editor&plugin=browser&standalone=1&' . $token . '=1&context=' . $context;
if ($element) {
$url .= '&element=' . $element;
}
if ($mediatype) {
$url .= '&mediatype=' . $mediatype;
}
if ($callback) {
$url .= '&callback=' . $callback;
}
}
return $url;
}
}