3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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-2014
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().
53 public static function invoke($args) {
55 return self
::_invoke($args);
57 catch (Exception
$e) {
58 CRM_Core_Error
::handleUnhandledException($e);
63 * This is the same as invoke(), but it does *not* include exception
67 * The parts of the URL which identify the intended CiviCRM page
68 * (e.g. array('civicrm', 'event', 'register')).
70 * HTML. For non-HTML content, invoke() may call print() and exit().
72 public static function _invoke($args) {
73 if ($args[0] !== 'civicrm') {
77 if (!defined('CIVICRM_SYMFONY_PATH')) {
78 // Traditional Civi invocation path
79 self
::hackMenuRebuild($args); // may exit
81 self
::hackStandalone($args);
82 $item = self
::getItem($args);
83 return self
::runItem($item);
86 // Symfony-based invocation path
87 require_once CIVICRM_SYMFONY_PATH
. '/app/bootstrap.php.cache';
88 require_once CIVICRM_SYMFONY_PATH
. '/app/AppKernel.php';
89 $kernel = new AppKernel('dev', true);
90 $kernel->loadClassCache();
91 $response = $kernel->handle(Symfony\Component\HttpFoundation\Request
::createFromGlobals());
92 if (preg_match(':^text/html:', $response->headers
->get('Content-Type'))) {
93 // let the CMS handle the trappings
94 return $response->getContent();
103 * Hackish support /civicrm/menu/rebuild
106 * List of path parts.
109 static public function hackMenuRebuild($args) {
110 if (array('civicrm','menu','rebuild') == $args ||
array('civicrm', 'clearcache') == $args) {
111 // ensure that the user has a good privilege level
112 if (CRM_Core_Permission
::check('administer CiviCRM')) {
113 self
::rebuildMenuAndCaches();
114 CRM_Core_Session
::setStatus(ts('Cleared all CiviCRM caches (database, menu, templates)'), ts('Complete'), 'success');
115 return CRM_Utils_System
::redirect(); // exits
118 CRM_Core_Error
::fatal('You do not have permission to execute this url');
124 * Perform general setup
127 * List of path parts.
130 static public function init($args) {
131 // first fire up IDS and check for bad stuff
132 $config = CRM_Core_Config
::singleton();
133 if (!CRM_Core_Permission
::check('skip IDS check')) {
134 $ids = new CRM_Core_IDS();
138 // also initialize the i18n framework
139 require_once 'CRM/Core/I18n.php';
140 $i18n = CRM_Core_I18n
::singleton();
144 * Hackish support for /standalone/*
147 * List of path parts.
150 static public function hackStandalone($args) {
151 $config = CRM_Core_Config
::singleton();
152 if ($config->userFramework
== 'Standalone') {
153 $session = CRM_Core_Session
::singleton();
154 if ($session->get('new_install') !== TRUE) {
155 CRM_Core_Standalone
::sidebarLeft();
157 elseif ($args[1] == 'standalone' && $args[2] == 'register') {
158 CRM_Core_Menu
::store();
164 * Determine which menu $item corresponds to $args
167 * List of path parts.
168 * @return array; see CRM_Core_Menu
170 static public function getItem($args) {
171 if (is_array($args)) {
172 // get the menu items
173 $path = implode('/', $args);
178 $item = CRM_Core_Menu
::get($path);
180 // we should try to compute menus, if item is empty and stay on the same page,
181 // rather than compute and redirect to dashboard.
183 CRM_Core_Menu
::store(FALSE);
184 $item = CRM_Core_Menu
::get($path);
191 * Given a menu item, call the appropriate controller and return the response
195 * @return string, HTML
197 static public function runItem($item) {
198 $config = CRM_Core_Config
::singleton();
199 if ($config->userFramework
== 'Joomla' && $item) {
200 $config->userFrameworkURLVar
= 'task';
202 // joomla 1.5RC1 seems to push this in the POST variable, which messes
204 unset($_POST['option']);
205 CRM_Core_Joomla
::sidebarLeft();
208 // set active Component
209 $template = CRM_Core_Smarty
::singleton();
210 $template->assign('activeComponent', 'CiviCRM');
211 $template->assign('formTpl', 'default');
214 // CRM-7656 - make sure we send a clean sanitized path to create printer friendly url
215 $printerFriendly = CRM_Utils_System
::makeURL(
216 'snippet', FALSE, FALSE,
217 CRM_Utils_Array
::value('path', $item)
219 $template->assign('printerFriendly', $printerFriendly);
221 if (!array_key_exists('page_callback', $item)) {
222 CRM_Core_Error
::debug('Bad item', $item);
223 CRM_Core_Error
::fatal(ts('Bad menu record in database'));
226 // check that we are permissioned to access this page
227 if (!CRM_Core_Permission
::checkMenuItem($item)) {
228 CRM_Utils_System
::permissionDenied();
232 // check if ssl is set
233 if (!empty($item['is_ssl'])) {
234 CRM_Utils_System
::redirectToSSL();
237 if (isset($item['title'])) {
238 CRM_Utils_System
::setTitle($item['title']);
241 if (isset($item['breadcrumb']) && !isset($item['is_public'])) {
242 CRM_Utils_System
::appendBreadCrumb($item['breadcrumb']);
246 if (!empty($item['page_arguments'])) {
247 $pageArgs = CRM_Core_Menu
::getArrayForPathArgs($item['page_arguments']);
250 $template = CRM_Core_Smarty
::singleton();
251 if (!empty($item['is_public'])) {
252 $template->assign('urlIsPublic', TRUE);
255 $template->assign('urlIsPublic', FALSE);
256 self
::versionCheck($template);
259 if (isset($item['return_url'])) {
260 $session = CRM_Core_Session
::singleton();
261 $args = CRM_Utils_Array
::value(
266 $session->pushUserContext(CRM_Utils_System
::url($item['return_url'], $args));
270 if (is_array($item['page_callback'])) {
271 require_once (str_replace('_', DIRECTORY_SEPARATOR
, $item['page_callback'][0]) . '.php');
272 $result = call_user_func($item['page_callback']);
274 elseif (strstr($item['page_callback'], '_Form')) {
275 $wrapper = new CRM_Utils_Wrapper();
276 $result = $wrapper->run(
277 CRM_Utils_Array
::value('page_callback', $item),
278 CRM_Utils_Array
::value('title', $item),
279 isset($pageArgs) ?
$pageArgs : NULL
283 $newArgs = explode('/', $_GET[$config->userFrameworkURLVar
]);
284 require_once (str_replace('_', DIRECTORY_SEPARATOR
, $item['page_callback']) . '.php');
286 if (isset($pageArgs['mode'])) {
287 $mode = $pageArgs['mode'];
288 unset($pageArgs['mode']);
290 $title = CRM_Utils_Array
::value('title', $item);
291 if (strstr($item['page_callback'], '_Page')) {
292 $object = new $item['page_callback'] ($title, $mode);
293 $object->urlPath
= explode('/', $_GET[$config->userFrameworkURLVar
]);
295 elseif (strstr($item['page_callback'], '_Controller')) {
296 $addSequence = 'false';
297 if (isset($pageArgs['addSequence'])) {
298 $addSequence = $pageArgs['addSequence'];
299 $addSequence = $addSequence ?
'true' : 'false';
300 unset($pageArgs['addSequence']);
302 $object = new $item['page_callback'] ($title, true, $mode, null, $addSequence);
305 CRM_Core_Error
::fatal();
307 $result = $object->run($newArgs, $pageArgs);
310 CRM_Core_Session
::storeSessionObjects();
314 CRM_Core_Menu
::store();
315 CRM_Core_Session
::setStatus(ts('Menu has been rebuilt'), ts('Complete'), 'success');
316 return CRM_Utils_System
::redirect();
320 * This function contains the default action
324 * @param $contact_type
325 * @param $contact_sub_type
329 public static function form($action, $contact_type, $contact_sub_type) {
330 CRM_Utils_System
::setUserContext(array('civicrm/contact/search/basic', 'civicrm/contact/view'));
331 $wrapper = new CRM_Utils_Wrapper();
333 $properties = CRM_Core_Component
::contactSubTypeProperties($contact_sub_type, 'Edit');
335 $wrapper->run($properties['class'], ts('New %1', array(1 => $contact_sub_type)), $action, TRUE);
338 $wrapper->run('CRM_Contact_Form_Contact', ts('New Contact'), $action, TRUE);
343 * Show the message about CiviCRM versions
345 * @param CRM_Core_Smarty $template
347 public static function versionCheck($template) {
348 if (CRM_Core_Config
::isUpgradeMode()) {
351 $newerVersion = $securityUpdate = NULL;
352 if (CRM_Core_BAO_Setting
::getItem(CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
, 'versionAlert', NULL, 1) & 1) {
353 $newerVersion = CRM_Utils_VersionCheck
::singleton()->isNewerVersionAvailable();
355 if (CRM_Core_BAO_Setting
::getItem(CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
, 'securityUpdateAlert', NULL, 3) & 1) {
356 $securityUpdate = CRM_Utils_VersionCheck
::singleton()->isSecurityUpdateAvailable();
358 $template->assign('newer_civicrm_version', $newerVersion);
359 $template->assign('security_update', $securityUpdate);
363 * @param bool $triggerRebuild
364 * @param bool $sessionReset
368 public static function rebuildMenuAndCaches($triggerRebuild = FALSE, $sessionReset = FALSE) {
369 $config = CRM_Core_Config
::singleton();
370 $config->clearModuleList();
372 // also cleanup all caches
373 $config->cleanupCaches($sessionReset || CRM_Utils_Request
::retrieve('sessionReset', 'Boolean', CRM_Core_DAO
::$_nullObject, FALSE, 0, 'GET'));
375 CRM_Core_Menu
::store();
377 // also reset navigation
378 CRM_Core_BAO_Navigation
::resetNavigation();
380 // also cleanup module permissions
381 $config->cleanupPermissions();
383 // rebuild word replacement cache - pass false to prevent operations redundant with this fn
384 CRM_Core_BAO_WordReplacement
::rebuild(FALSE);
386 CRM_Core_BAO_Setting
::updateSettingsFromMetaData();
388 CRM_Core_Resources
::singleton()->flushStrings()->resetCacheCode();
389 CRM_Case_XMLRepository
::singleton(TRUE);
391 // also rebuild triggers if requested explicitly
394 CRM_Utils_Request
::retrieve('triggerRebuild', 'Boolean', CRM_Core_DAO
::$_nullObject, FALSE, 0, 'GET')
396 CRM_Core_DAO
::triggerRebuild();
398 CRM_Core_DAO_AllCoreTables
::reinitializeCache(TRUE);
399 CRM_Core_ManagedEntities
::singleton(TRUE)->reconcile();