XOOPS  2.6.0
main.php
Go to the documentation of this file.
1 <?php
2 /*
3  You may not change or alter any portion of this comment or credits
4  of supporting developers from this source code or any supporting source code
5  which is considered copyrighted (c) material of the original comment or credit authors.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 */
11 
13 
25 // Get main instance
27 $security = $xoops->security();
28 
29 // Check users rights
30 if (!$xoops->isUser() || !$xoops->isModule() || !$xoops->user->isAdmin($xoops->module->mid())) {
31  http_response_code(401);
33 }
34 
35 // any ajax requests land here
36 if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') {
37  $xoops->logger()->quiet();
38  // ajax post requests should have a valid token, but we don't clear it since the
39  // token is set on page load and we may need to make multiple requests from it.
40  // TODO - token has an expiration time, so eventually it will stop working, so
41  // we need to decide how to handle that. Right now, some js will redirect us from
42  // provider sort to service select just before the token should expire.
43  if (isset($_POST['token']) && $security->validateToken($_POST['token'], false)) {
44  if (isset($_POST['op']) && $_POST['op']=='order') {
45  if (isset($_POST['service'])) {
46  $service=$_POST['service'];
47  if (isset($_POST[$service]) && is_array($_POST[$service])) {
48  $service_order = array_flip($_POST[$service]);
49  $sm = Manager::getInstance();
50  $sm->saveChoice($service, $service_order);
51  exit("OK");
52  }
53  }
54  }
55  http_response_code(400);
56  exit("Parameter error");
57  }
58  http_response_code(403);
59  exit("Token error");
60 }
61 
62 $xoops->theme()->addBaseStylesheetAssets('@jqueryuicss');
63 $xoops->theme()->addStylesheet('modules/system/css/admin.css');
64 $xoops->theme()->addBaseScriptAssets('@jqueryui', '@jgrowl', 'modules/system/js/admin.js');
65 
66 $xoops->header('admin:system/system_services.tpl');
67 
68 $admin_page = new \Xoops\Module\Admin();
69 $admin_page->addBreadcrumbLink(SystemLocale::CONTROL_PANEL, \XoopsBaseConfig::get('url') . '/admin.php', true);
70 $admin_page->addBreadcrumbLink(
72  $system->adminVersion('services', 'adminpath')
73 );
74 $admin_page->addBreadcrumbLink(XoopsLocale::MAIN);
76 $admin_page->renderBreadcrumb();
77 $admin_page->renderTips();
78 
80 if (isset($_GET['service'])) {
81  $selected_service = strtolower(XoopsFilterInput::clean($_GET['service'], 'WORD'));
82 }
83 $xoops->tpl()->assign('selected_service', $selected_service);
84 
85 $sm = Manager::getInstance();
86 $filter = 'coreservicelocate';
87 $eventList = $xoops->events()->getEvents();
88 $l = strlen($filter);
89 $filteredList = array();
90 foreach ($eventList as $k => $v) {
91  if (strncasecmp($filter, $k, $l) == 0) {
92  $filteredList[] = strtolower(substr($k, $l));
93  }
94 }
95 
96 
97 $service_list = array();
98 sort($filteredList);
99 foreach ($filteredList as $v) {
100  $service_list[] = array(
101  'name' => $v,
102  'display' => ucfirst($v),
103  'active' => ($v==$selected_service),
104  );
105 }
106 $xoops->tpl()->assign('service_list', $service_list);
107 if (empty($filteredList)) {
108  $xoops->tpl()->assign('message', $xoops->alert('error', 'No service providers are installed.', 'No Services'));
109 }
110 
111 if (!empty($selected_service) && in_array($selected_service, $filteredList)) {
112  $providers = $xoops->service($selected_service)->getRegistered();
113  $service = ucfirst($selected_service);
114  $mode = reset($providers)->getMode();
115  switch ($mode) {
116  case Manager::MODE_EXCLUSIVE:
117  $modeDesc = 'This is an <em>Exclusive</em> mode service. Only the first provider on the list will be used.';
118  break;
119  case Manager::MODE_CHOICE:
120  $modeDesc = 'This is an <em>Choice</em> mode service. The first provider on the list will be the default.';
121  break;
122  case Manager::MODE_PREFERENCE:
123  $modeDesc = 'User Preference';
124  break;
125  case Manager::MODE_MULTIPLE:
126  $modeDesc = 'This is an <em>Multiple</em> mode service. '
127  . 'Each provider will be called in the sequence shown.';
128  break;
129  }
130  $xoops->tpl()->assign('message', $xoops->alert('info', $modeDesc, 'Service Mode'));
131 
132  $provider_list = array();
133  foreach ($providers as $p) {
134  $provider_list[] = array(
135  'name' => $p->getName(),
136  'description' => $p->getDescription(),
137  'priority' => $p->getPriority(),
138  );
139  }
140  $xoops->tpl()->assign('provider_list', $provider_list);
141  $xoops->tpl()->assign('token', $security->createToken(901));
142 
143 }
144 
145 $xoops->footer();
const SERVICES_TIPS
Definition: en_US.php:375
const SERVICES_MANAGER
Definition: en_US.php:374
$system
Definition: main.php:26
$l
Definition: main.php:88
static getInstance()
Definition: Xoops.php:160
$_SERVER['REQUEST_URI']
$security
Definition: main.php:27
$admin_page
Definition: main.php:34
foreach($eventList as $k=> $v) $service_list
Definition: main.php:97
exit
Definition: browse.php:104
$selected_service
Definition: main.php:79
static get($name)
$filter
Definition: main.php:40
const CONTROL_PANEL
Definition: en_US.php:247
const E_NO_ACCESS_PERMISSION
Definition: en_US.php:351
$filteredList
Definition: main.php:89
$xoops
Definition: main.php:25
$sm
Definition: main.php:85
$eventList
Definition: main.php:87
static clean($source, $type= 'string')