3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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-2015
38 class CRM_Core_Invoke
{
41 * This is the main front-controller that integrates with the CMS. Any
42 * page-request that is sent to the CMS and intended for CiviCRM should
43 * be processed by invoke().
46 * The parts of the URL which identify the intended CiviCRM page
47 * (e.g. array('civicrm', 'event', 'register')).
49 * HTML. For non-HTML content, invoke() may call print() and exit().
52 public static function invoke($args) {
54 return self
::_invoke($args);
56 catch (Exception
$e) {
57 CRM_Core_Error
::handleUnhandledException($e);
62 * This is the same as invoke(), but it does *not* include exception
66 * The parts of the URL which identify the intended CiviCRM page
67 * (e.g. array('civicrm', 'event', 'register')).
69 * HTML. For non-HTML content, invoke() may call print() and exit().
71 public static function _invoke($args) {
72 if ($args[0] !== 'civicrm') {
75 // CRM-15901: Turn off PHP errors display for all ajax calls
76 if (CRM_Utils_Array
::value(1, $args) == 'ajax' || CRM_Utils_Array
::value('snippet', $_REQUEST)) {
77 ini_set('display_errors', 0);
80 if (!defined('CIVICRM_SYMFONY_PATH')) {
81 // Traditional Civi invocation path
82 self
::hackMenuRebuild($args); // may exit
84 self
::hackStandalone($args);
85 $item = self
::getItem($args);
86 return self
::runItem($item);
89 // Symfony-based invocation path
90 require_once CIVICRM_SYMFONY_PATH
. '/app/bootstrap.php.cache';
91 require_once CIVICRM_SYMFONY_PATH
. '/app/AppKernel.php';
92 $kernel = new AppKernel('dev', TRUE);
93 $kernel->loadClassCache();
94 $response = $kernel->handle(Symfony\Component\HttpFoundation\Request
::createFromGlobals());
95 if (preg_match(':^text/html:', $response->headers
->get('Content-Type'))) {
96 // let the CMS handle the trappings
97 return $response->getContent();
107 * Hackish support /civicrm/menu/rebuild
110 * List of path parts.
113 static public function hackMenuRebuild($args) {
114 if (array('civicrm', 'menu', 'rebuild') == $args ||
array('civicrm', 'clearcache') == $args) {
115 // ensure that the user has a good privilege level
116 if (CRM_Core_Permission
::check('administer CiviCRM')) {
117 self
::rebuildMenuAndCaches();
118 CRM_Core_Session
::setStatus(ts('Cleared all CiviCRM caches (database, menu, templates)'), ts('Complete'), 'success');
119 return CRM_Utils_System
::redirect(); // exits
122 CRM_Core_Error
::fatal('You do not have permission to execute this url');
128 * Perform general setup.
131 * List of path parts.
134 static public function init($args) {
135 // first fire up IDS and check for bad stuff
136 $config = CRM_Core_Config
::singleton();
137 if (!CRM_Core_Permission
::check('skip IDS check')) {
138 $ids = new CRM_Core_IDS();
142 // also initialize the i18n framework
143 require_once 'CRM/Core/I18n.php';
144 $i18n = CRM_Core_I18n
::singleton();
148 * Hackish support for /standalone/*
151 * List of path parts.
154 static public function hackStandalone($args) {
155 $config = CRM_Core_Config
::singleton();
156 if ($config->userFramework
== 'Standalone') {
157 $session = CRM_Core_Session
::singleton();
158 if ($session->get('new_install') !== TRUE) {
159 CRM_Core_Standalone
::sidebarLeft();
161 elseif ($args[1] == 'standalone' && $args[2] == 'register') {
162 CRM_Core_Menu
::store();
168 * Determine which menu $item corresponds to $args
171 * List of path parts.
172 * @return array; see CRM_Core_Menu
174 static public function getItem($args) {
175 if (is_array($args)) {
176 // get the menu items
177 $path = implode('/', $args);
182 $item = CRM_Core_Menu
::get($path);
184 // we should try to compute menus, if item is empty and stay on the same page,
185 // rather than compute and redirect to dashboard.
187 CRM_Core_Menu
::store(FALSE);
188 $item = CRM_Core_Menu
::get($path);
195 * Given a menu item, call the appropriate controller and return the response
199 * @return string, HTML
201 static public function runItem($item) {
202 $config = CRM_Core_Config
::singleton();
203 if ($config->userFramework
== 'Joomla' && $item) {
204 $config->userFrameworkURLVar
= 'task';
206 // joomla 1.5RC1 seems to push this in the POST variable, which messes
208 unset($_POST['option']);
209 CRM_Core_Joomla
::sidebarLeft();
212 // set active Component
213 $template = CRM_Core_Smarty
::singleton();
214 $template->assign('activeComponent', 'CiviCRM');
215 $template->assign('formTpl', 'default');
218 // CRM-7656 - make sure we send a clean sanitized path to create printer friendly url
219 $printerFriendly = CRM_Utils_System
::makeURL(
220 'snippet', FALSE, FALSE,
221 CRM_Utils_Array
::value('path', $item)
223 $template->assign('printerFriendly', $printerFriendly);
225 if (!array_key_exists('page_callback', $item)) {
226 CRM_Core_Error
::debug('Bad item', $item);
227 CRM_Core_Error
::fatal(ts('Bad menu record in database'));
230 // check that we are permissioned to access this page
231 if (!CRM_Core_Permission
::checkMenuItem($item)) {
232 CRM_Utils_System
::permissionDenied();
236 // check if ssl is set
237 if (!empty($item['is_ssl'])) {
238 CRM_Utils_System
::redirectToSSL();
241 if (isset($item['title'])) {
242 CRM_Utils_System
::setTitle($item['title']);
245 if (isset($item['breadcrumb']) && !isset($item['is_public'])) {
246 CRM_Utils_System
::appendBreadCrumb($item['breadcrumb']);
250 if (!empty($item['page_arguments'])) {
251 $pageArgs = CRM_Core_Menu
::getArrayForPathArgs($item['page_arguments']);
254 $template = CRM_Core_Smarty
::singleton();
255 if (!empty($item['is_public'])) {
256 $template->assign('urlIsPublic', TRUE);
259 $template->assign('urlIsPublic', FALSE);
260 self
::statusCheck($template);
263 if (isset($item['return_url'])) {
264 $session = CRM_Core_Session
::singleton();
265 $args = CRM_Utils_Array
::value(
270 $session->pushUserContext(CRM_Utils_System
::url($item['return_url'], $args));
274 // WISHLIST: Refactor this. Instead of pattern-matching on page_callback, lookup
275 // page_callback via Civi\Core\Resolver and check the implemented interfaces. This
276 // would require rethinking the default constructor.
277 if (is_array($item['page_callback']) ||
strpos($item['page_callback'], ':')) {
278 $result = call_user_func(Civi\Core\Resolver
::singleton()->get($item['page_callback']));
280 elseif (strstr($item['page_callback'], '_Form')) {
281 $wrapper = new CRM_Utils_Wrapper();
282 $result = $wrapper->run(
283 CRM_Utils_Array
::value('page_callback', $item),
284 CRM_Utils_Array
::value('title', $item),
285 isset($pageArgs) ?
$pageArgs : NULL
289 $newArgs = explode('/', $_GET[$config->userFrameworkURLVar
]);
291 if (isset($pageArgs['mode'])) {
292 $mode = $pageArgs['mode'];
293 unset($pageArgs['mode']);
295 $title = CRM_Utils_Array
::value('title', $item);
296 if (strstr($item['page_callback'], '_Page') ||
strstr($item['page_callback'], '\\Page\\')) {
297 $object = new $item['page_callback']($title, $mode);
298 $object->urlPath
= explode('/', $_GET[$config->userFrameworkURLVar
]);
300 elseif (strstr($item['page_callback'], '_Controller') ||
strstr($item['page_callback'], '\\Controller\\')) {
301 $addSequence = 'false';
302 if (isset($pageArgs['addSequence'])) {
303 $addSequence = $pageArgs['addSequence'];
304 $addSequence = $addSequence ?
'true' : 'false';
305 unset($pageArgs['addSequence']);
307 $object = new $item['page_callback']($title, TRUE, $mode, NULL, $addSequence);
310 CRM_Core_Error
::fatal();
312 $result = $object->run($newArgs, $pageArgs);
315 CRM_Core_Session
::storeSessionObjects();
319 CRM_Core_Menu
::store();
320 CRM_Core_Session
::setStatus(ts('Menu has been rebuilt'), ts('Complete'), 'success');
321 return CRM_Utils_System
::redirect();
325 * This function contains the default action.
329 * @param $contact_type
330 * @param $contact_sub_type
333 public static function form($action, $contact_type, $contact_sub_type) {
334 CRM_Utils_System
::setUserContext(array('civicrm/contact/search/basic', 'civicrm/contact/view'));
335 $wrapper = new CRM_Utils_Wrapper();
337 $properties = CRM_Core_Component
::contactSubTypeProperties($contact_sub_type, 'Edit');
339 $wrapper->run($properties['class'], ts('New %1', array(1 => $contact_sub_type)), $action, TRUE);
342 $wrapper->run('CRM_Contact_Form_Contact', ts('New Contact'), $action, TRUE);
347 * Show status in the footer (admin only)
349 * @param CRM_Core_Smarty $template
351 public static function statusCheck($template) {
352 if (CRM_Core_Config
::isUpgradeMode() ||
!CRM_Core_Permission
::check('administer CiviCRM')) {
355 // always use cached results - they will be refreshed by the session timer
356 $status = Civi
::settings()->get('systemStatusCheckResult');
357 $template->assign('footer_status_severity', $status);
358 $template->assign('footer_status_message', CRM_Utils_Check
::toStatusLabel($status));
362 * @param bool $triggerRebuild
363 * @param bool $sessionReset
367 public static function rebuildMenuAndCaches($triggerRebuild = FALSE, $sessionReset = FALSE) {
368 $config = CRM_Core_Config
::singleton();
369 $config->clearModuleList();
371 // also cleanup all caches
372 $config->cleanupCaches($sessionReset || CRM_Utils_Request
::retrieve('sessionReset', 'Boolean', CRM_Core_DAO
::$_nullObject, FALSE, 0, 'GET'));
374 CRM_Core_Menu
::store();
376 // also reset navigation
377 CRM_Core_BAO_Navigation
::resetNavigation();
379 // also cleanup module permissions
380 $config->cleanupPermissions();
382 // rebuild word replacement cache - pass false to prevent operations redundant with this fn
383 CRM_Core_BAO_WordReplacement
::rebuild(FALSE);
385 Civi
::service('settings_manager')->flush();
387 CRM_Core_Resources
::singleton()->flushStrings()->resetCacheCode();
388 CRM_Case_XMLRepository
::singleton(TRUE);
390 // also rebuild triggers if requested explicitly
393 CRM_Utils_Request
::retrieve('triggerRebuild', 'Boolean', CRM_Core_DAO
::$_nullObject, FALSE, 0, 'GET')
395 CRM_Core_DAO
::triggerRebuild();
397 CRM_Core_DAO_AllCoreTables
::reinitializeCache(TRUE);
398 CRM_Core_ManagedEntities
::singleton(TRUE)->reconcile();
400 //CRM-16257 update Config.IDS.ini might be an old copy
401 CRM_Core_IDS
::createConfigFile(TRUE);