3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2017 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
30 * Given an argument list, invoke the appropriate CRM function
31 * Serves as a wrapper between the UserFrameWork and Core CRM
34 * @copyright CiviCRM LLC (c) 2004-2017
36 class CRM_Core_Invoke
{
39 * This is the main front-controller that integrates with the CMS. Any
40 * page-request that is sent to the CMS and intended for CiviCRM should
41 * be processed by invoke().
44 * The parts of the URL which identify the intended CiviCRM page
45 * (e.g. array('civicrm', 'event', 'register')).
47 * HTML. For non-HTML content, invoke() may call print() and exit().
50 public static function invoke($args) {
52 return self
::_invoke($args);
54 catch (Exception
$e) {
55 CRM_Core_Error
::handleUnhandledException($e);
60 * This is the same as invoke(), but it does *not* include exception
64 * The parts of the URL which identify the intended CiviCRM page
65 * (e.g. array('civicrm', 'event', 'register')).
67 * HTML. For non-HTML content, invoke() may call print() and exit().
69 public static function _invoke($args) {
70 if ($args[0] !== 'civicrm') {
73 // CRM-15901: Turn off PHP errors display for all ajax calls
74 if (CRM_Utils_Array
::value(1, $args) == 'ajax' || CRM_Utils_Array
::value('snippet', $_REQUEST)) {
75 ini_set('display_errors', 0);
78 if (!defined('CIVICRM_SYMFONY_PATH')) {
79 // Traditional Civi invocation path
80 self
::hackMenuRebuild($args); // may exit
82 self
::hackStandalone($args);
83 $item = self
::getItem($args);
84 return self
::runItem($item);
87 // Symfony-based invocation path
88 require_once CIVICRM_SYMFONY_PATH
. '/app/bootstrap.php.cache';
89 require_once CIVICRM_SYMFONY_PATH
. '/app/AppKernel.php';
90 $kernel = new AppKernel('dev', TRUE);
91 $kernel->loadClassCache();
92 $response = $kernel->handle(Symfony\Component\HttpFoundation\Request
::createFromGlobals());
93 if (preg_match(':^text/html:', $response->headers
->get('Content-Type'))) {
94 // let the CMS handle the trappings
95 return $response->getContent();
105 * Hackish support /civicrm/menu/rebuild
108 * List of path parts.
111 static public function hackMenuRebuild($args) {
112 if (array('civicrm', 'menu', 'rebuild') == $args ||
array('civicrm', 'clearcache') == $args) {
113 // ensure that the user has a good privilege level
114 if (CRM_Core_Permission
::check('administer CiviCRM')) {
115 self
::rebuildMenuAndCaches();
116 CRM_Core_Session
::setStatus(ts('Cleared all CiviCRM caches (database, menu, templates)'), ts('Complete'), 'success');
117 return CRM_Utils_System
::redirect(); // exits
120 CRM_Core_Error
::fatal('You do not have permission to execute this url');
126 * Perform general setup.
129 * List of path parts.
132 static public function init($args) {
133 // first fire up IDS and check for bad stuff
134 $config = CRM_Core_Config
::singleton();
136 // also initialize the i18n framework
137 require_once 'CRM/Core/I18n.php';
138 $i18n = CRM_Core_I18n
::singleton();
142 * Hackish support for /standalone/*
145 * List of path parts.
148 static public function hackStandalone($args) {
149 $config = CRM_Core_Config
::singleton();
150 if ($config->userFramework
== 'Standalone') {
151 $session = CRM_Core_Session
::singleton();
152 if ($session->get('new_install') !== TRUE) {
153 CRM_Core_Standalone
::sidebarLeft();
155 elseif ($args[1] == 'standalone' && $args[2] == 'register') {
156 CRM_Core_Menu
::store();
162 * Determine which menu $item corresponds to $args
165 * List of path parts.
166 * @return array; see CRM_Core_Menu
168 static public function getItem($args) {
169 if (is_array($args)) {
170 // get the menu items
171 $path = implode('/', $args);
176 $item = CRM_Core_Menu
::get($path);
178 // we should try to compute menus, if item is empty and stay on the same page,
179 // rather than compute and redirect to dashboard.
181 CRM_Core_Menu
::store(FALSE);
182 $item = CRM_Core_Menu
::get($path);
189 * Given a menu item, call the appropriate controller and return the response
193 * @return string, HTML
195 static public function runItem($item) {
196 $ids = new CRM_Core_IDS();
199 $config = CRM_Core_Config
::singleton();
200 if ($config->userFramework
== 'Joomla' && $item) {
201 $config->userFrameworkURLVar
= 'task';
203 // joomla 1.5RC1 seems to push this in the POST variable, which messes
205 unset($_POST['option']);
206 CRM_Core_Joomla
::sidebarLeft();
209 // set active Component
210 $template = CRM_Core_Smarty
::singleton();
211 $template->assign('activeComponent', 'CiviCRM');
212 $template->assign('formTpl', 'default');
215 // CRM-7656 - make sure we send a clean sanitized path to create printer friendly url
216 $printerFriendly = CRM_Utils_System
::makeURL(
217 'snippet', FALSE, FALSE,
218 CRM_Utils_Array
::value('path', $item)
220 $template->assign('printerFriendly', $printerFriendly);
222 if (!array_key_exists('page_callback', $item)) {
223 CRM_Core_Error
::debug('Bad item', $item);
224 CRM_Core_Error
::fatal(ts('Bad menu record in database'));
227 // check that we are permissioned to access this page
228 if (!CRM_Core_Permission
::checkMenuItem($item)) {
229 CRM_Utils_System
::permissionDenied();
233 // check if ssl is set
234 if (!empty($item['is_ssl'])) {
235 CRM_Utils_System
::redirectToSSL();
238 if (isset($item['title'])) {
239 CRM_Utils_System
::setTitle($item['title']);
242 if (isset($item['breadcrumb']) && !isset($item['is_public'])) {
243 CRM_Utils_System
::appendBreadCrumb($item['breadcrumb']);
247 if (!empty($item['page_arguments'])) {
248 $pageArgs = CRM_Core_Menu
::getArrayForPathArgs($item['page_arguments']);
251 $template = CRM_Core_Smarty
::singleton();
252 if (!empty($item['is_public'])) {
253 $template->assign('urlIsPublic', TRUE);
256 $template->assign('urlIsPublic', FALSE);
257 self
::statusCheck($template);
260 if (isset($item['return_url'])) {
261 $session = CRM_Core_Session
::singleton();
262 $args = CRM_Utils_Array
::value(
267 $session->pushUserContext(CRM_Utils_System
::url($item['return_url'], $args));
271 // WISHLIST: Refactor this. Instead of pattern-matching on page_callback, lookup
272 // page_callback via Civi\Core\Resolver and check the implemented interfaces. This
273 // would require rethinking the default constructor.
274 if (is_array($item['page_callback']) ||
strpos($item['page_callback'], ':')) {
275 $result = call_user_func(Civi\Core\Resolver
::singleton()->get($item['page_callback']));
277 elseif (strstr($item['page_callback'], '_Form')) {
278 $wrapper = new CRM_Utils_Wrapper();
279 $result = $wrapper->run(
280 CRM_Utils_Array
::value('page_callback', $item),
281 CRM_Utils_Array
::value('title', $item),
282 isset($pageArgs) ?
$pageArgs : NULL
286 $newArgs = explode('/', $_GET[$config->userFrameworkURLVar
]);
288 if (isset($pageArgs['mode'])) {
289 $mode = $pageArgs['mode'];
290 unset($pageArgs['mode']);
292 $title = CRM_Utils_Array
::value('title', $item);
293 if (strstr($item['page_callback'], '_Page') ||
strstr($item['page_callback'], '\\Page\\')) {
294 $object = new $item['page_callback']($title, $mode);
295 $object->urlPath
= explode('/', $_GET[$config->userFrameworkURLVar
]);
297 elseif (strstr($item['page_callback'], '_Controller') ||
strstr($item['page_callback'], '\\Controller\\')) {
298 $addSequence = 'false';
299 if (isset($pageArgs['addSequence'])) {
300 $addSequence = $pageArgs['addSequence'];
301 $addSequence = $addSequence ?
'true' : 'false';
302 unset($pageArgs['addSequence']);
304 $object = new $item['page_callback']($title, TRUE, $mode, NULL, $addSequence);
307 CRM_Core_Error
::fatal();
309 $result = $object->run($newArgs, $pageArgs);
312 CRM_Core_Session
::storeSessionObjects();
316 CRM_Core_Menu
::store();
317 CRM_Core_Session
::setStatus(ts('Menu has been rebuilt'), ts('Complete'), 'success');
318 return CRM_Utils_System
::redirect();
322 * This function contains the default action.
326 * @param $contact_type
327 * @param $contact_sub_type
330 public static function form($action, $contact_type, $contact_sub_type) {
331 CRM_Utils_System
::setUserContext(array('civicrm/contact/search/basic', 'civicrm/contact/view'));
332 $wrapper = new CRM_Utils_Wrapper();
334 $properties = CRM_Core_Component
::contactSubTypeProperties($contact_sub_type, 'Edit');
336 $wrapper->run($properties['class'], ts('New %1', array(1 => $contact_sub_type)), $action, TRUE);
339 $wrapper->run('CRM_Contact_Form_Contact', ts('New Contact'), $action, TRUE);
344 * Show status in the footer (admin only)
346 * @param CRM_Core_Smarty $template
348 public static function statusCheck($template) {
349 if (CRM_Core_Config
::isUpgradeMode() ||
!CRM_Core_Permission
::check('administer CiviCRM')) {
352 // always use cached results - they will be refreshed by the session timer
353 $status = Civi
::settings()->get('systemStatusCheckResult');
354 $template->assign('footer_status_severity', $status);
355 $template->assign('footer_status_message', CRM_Utils_Check
::toStatusLabel($status));
359 * @param bool $triggerRebuild
360 * @param bool $sessionReset
364 public static function rebuildMenuAndCaches($triggerRebuild = FALSE, $sessionReset = FALSE) {
365 $config = CRM_Core_Config
::singleton();
366 $config->clearModuleList();
368 // also cleanup all caches
369 $config->cleanupCaches($sessionReset || CRM_Utils_Request
::retrieve('sessionReset', 'Boolean', CRM_Core_DAO
::$_nullObject, FALSE, 0, 'GET'));
371 CRM_Core_Menu
::store();
373 // also reset navigation
374 CRM_Core_BAO_Navigation
::resetNavigation();
376 // also cleanup module permissions
377 $config->cleanupPermissions();
379 // rebuild word replacement cache - pass false to prevent operations redundant with this fn
380 CRM_Core_BAO_WordReplacement
::rebuild(FALSE);
382 Civi
::service('settings_manager')->flush();
384 CRM_Core_Resources
::singleton()->flushStrings()->resetCacheCode();
385 CRM_Case_XMLRepository
::singleton(TRUE);
387 // also rebuild triggers if requested explicitly
390 CRM_Utils_Request
::retrieve('triggerRebuild', 'Boolean', CRM_Core_DAO
::$_nullObject, FALSE, 0, 'GET')
392 CRM_Core_DAO
::triggerRebuild();
394 CRM_Core_DAO_AllCoreTables
::reinitializeCache(TRUE);
395 CRM_Core_ManagedEntities
::singleton(TRUE)->reconcile();