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);
85 // Symfony-based invocation path
86 require_once CIVICRM_SYMFONY_PATH
. '/app/bootstrap.php.cache';
87 require_once CIVICRM_SYMFONY_PATH
. '/app/AppKernel.php';
88 $kernel = new AppKernel('dev', true);
89 $kernel->loadClassCache();
90 $response = $kernel->handle(Symfony\Component\HttpFoundation\Request
::createFromGlobals());
91 if (preg_match(':^text/html:', $response->headers
->get('Content-Type'))) {
92 // let the CMS handle the trappings
93 return $response->getContent();
101 * Hackish support /civicrm/menu/rebuild
103 * @param array $args list of path parts
106 static public function hackMenuRebuild($args) {
107 if (array('civicrm','menu','rebuild') == $args ||
array('civicrm', 'clearcache') == $args) {
108 // ensure that the user has a good privilege level
109 if (CRM_Core_Permission
::check('administer CiviCRM')) {
110 self
::rebuildMenuAndCaches();
111 CRM_Core_Session
::setStatus(ts('Cleared all CiviCRM caches (database, menu, templates)'), ts('Complete'), 'success');
112 return CRM_Utils_System
::redirect(); // exits
115 CRM_Core_Error
::fatal('You do not have permission to execute this url');
121 * Perform general setup
123 * @param array $args list of path parts
126 static public function init($args) {
127 // first fire up IDS and check for bad stuff
128 $config = CRM_Core_Config
::singleton();
129 if (!CRM_Core_Permission
::check('skip IDS check')) {
130 $ids = new CRM_Core_IDS();
134 // also initialize the i18n framework
135 require_once 'CRM/Core/I18n.php';
136 $i18n = CRM_Core_I18n
::singleton();
140 * Hackish support for /standalone/*
142 * @param array $args list of path parts
145 static public function hackStandalone($args) {
146 $config = CRM_Core_Config
::singleton();
147 if ($config->userFramework
== 'Standalone') {
148 $session = CRM_Core_Session
::singleton();
149 if ($session->get('new_install') !== TRUE) {
150 CRM_Core_Standalone
::sidebarLeft();
152 elseif ($args[1] == 'standalone' && $args[2] == 'register') {
153 CRM_Core_Menu
::store();
159 * Determine which menu $item corresponds to $args
161 * @param array $args list of path parts
162 * @return array; see CRM_Core_Menu
164 static public function getItem($args) {
165 if (is_array($args)) {
166 // get the menu items
167 $path = implode('/', $args);
171 $item = CRM_Core_Menu
::get($path);
173 // we should try to compute menus, if item is empty and stay on the same page,
174 // rather than compute and redirect to dashboard.
176 CRM_Core_Menu
::store(FALSE);
177 $item = CRM_Core_Menu
::get($path);
184 * Given a menu item, call the appropriate controller and return the response
186 * @param array $item see CRM_Core_Menu
187 * @return string, HTML
189 static public function runItem($item) {
190 $config = CRM_Core_Config
::singleton();
191 if ($config->userFramework
== 'Joomla' && $item) {
192 $config->userFrameworkURLVar
= 'task';
194 // joomla 1.5RC1 seems to push this in the POST variable, which messes
196 unset($_POST['option']);
197 CRM_Core_Joomla
::sidebarLeft();
200 // set active Component
201 $template = CRM_Core_Smarty
::singleton();
202 $template->assign('activeComponent', 'CiviCRM');
203 $template->assign('formTpl', 'default');
206 // CRM-7656 - make sure we send a clean sanitized path to create printer friendly url
207 $printerFriendly = CRM_Utils_System
::makeURL(
208 'snippet', FALSE, FALSE,
209 CRM_Utils_Array
::value('path', $item)
211 $template->assign('printerFriendly', $printerFriendly);
213 if (!array_key_exists('page_callback', $item)) {
214 CRM_Core_Error
::debug('Bad item', $item);
215 CRM_Core_Error
::fatal(ts('Bad menu record in database'));
218 // check that we are permissioned to access this page
219 if (!CRM_Core_Permission
::checkMenuItem($item)) {
220 CRM_Utils_System
::permissionDenied();
224 // check if ssl is set
225 if (!empty($item['is_ssl'])) {
226 CRM_Utils_System
::redirectToSSL();
229 if (isset($item['title'])) {
230 CRM_Utils_System
::setTitle($item['title']);
233 if (isset($item['breadcrumb']) && !isset($item['is_public'])) {
234 CRM_Utils_System
::appendBreadCrumb($item['breadcrumb']);
238 if (!empty($item['page_arguments'])) {
239 $pageArgs = CRM_Core_Menu
::getArrayForPathArgs($item['page_arguments']);
242 $template = CRM_Core_Smarty
::singleton();
243 if (!empty($item['is_public'])) {
244 $template->assign('urlIsPublic', TRUE);
247 $template->assign('urlIsPublic', FALSE);
248 self
::versionCheck($template);
251 if (isset($item['return_url'])) {
252 $session = CRM_Core_Session
::singleton();
253 $args = CRM_Utils_Array
::value(
258 $session->pushUserContext(CRM_Utils_System
::url($item['return_url'], $args));
262 if (is_array($item['page_callback'])) {
263 require_once (str_replace('_', DIRECTORY_SEPARATOR
, $item['page_callback'][0]) . '.php');
264 $result = call_user_func($item['page_callback']);
266 elseif (strstr($item['page_callback'], '_Form')) {
267 $wrapper = new CRM_Utils_Wrapper();
268 $result = $wrapper->run(
269 CRM_Utils_Array
::value('page_callback', $item),
270 CRM_Utils_Array
::value('title', $item),
271 isset($pageArgs) ?
$pageArgs : NULL
275 $newArgs = explode('/', $_GET[$config->userFrameworkURLVar
]);
276 require_once (str_replace('_', DIRECTORY_SEPARATOR
, $item['page_callback']) . '.php');
278 if (isset($pageArgs['mode'])) {
279 $mode = $pageArgs['mode'];
280 unset($pageArgs['mode']);
282 $title = CRM_Utils_Array
::value('title', $item);
283 if (strstr($item['page_callback'], '_Page')) {
284 $object = new $item['page_callback'] ($title, $mode );
285 $object->urlPath
= explode('/', $_GET[$config->userFrameworkURLVar
]);
287 elseif (strstr($item['page_callback'], '_Controller')) {
288 $addSequence = 'false';
289 if (isset($pageArgs['addSequence'])) {
290 $addSequence = $pageArgs['addSequence'];
291 $addSequence = $addSequence ?
'true' : 'false';
292 unset($pageArgs['addSequence']);
294 $object = new $item['page_callback'] ($title, true, $mode, null, $addSequence );
297 CRM_Core_Error
::fatal();
299 $result = $object->run($newArgs, $pageArgs);
302 CRM_Core_Session
::storeSessionObjects();
306 CRM_Core_Menu
::store();
307 CRM_Core_Session
::setStatus(ts('Menu has been rebuilt'), ts('Complete'), 'success');
308 return CRM_Utils_System
::redirect();
312 * This function contains the default action
316 * @param $contact_type
317 * @param $contact_sub_type
321 public static function form($action, $contact_type, $contact_sub_type) {
322 CRM_Utils_System
::setUserContext(array('civicrm/contact/search/basic', 'civicrm/contact/view'));
323 $wrapper = new CRM_Utils_Wrapper();
325 $properties = CRM_Core_Component
::contactSubTypeProperties($contact_sub_type, 'Edit');
327 $wrapper->run($properties['class'], ts('New %1', array(1 => $contact_sub_type)), $action, TRUE);
330 $wrapper->run('CRM_Contact_Form_Contact', ts('New Contact'), $action, TRUE);
335 * Show the message about CiviCRM versions
337 * @param CRM_Core_Smarty $template
339 public static function versionCheck($template) {
340 if (CRM_Core_Config
::isUpgradeMode()) {
343 $newerVersion = $securityUpdate = NULL;
344 if (CRM_Core_BAO_Setting
::getItem(CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
, 'versionAlert', NULL, 1) & 1) {
345 $newerVersion = CRM_Utils_VersionCheck
::singleton()->isNewerVersionAvailable();
347 if (CRM_Core_BAO_Setting
::getItem(CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
, 'securityUpdateAlert', NULL, 3) & 1) {
348 $securityUpdate = CRM_Utils_VersionCheck
::singleton()->isSecurityUpdateAvailable();
350 $template->assign('newer_civicrm_version', $newerVersion);
351 $template->assign('security_update', $securityUpdate);
355 * @param bool $triggerRebuild
356 * @param bool $sessionReset
360 public static function rebuildMenuAndCaches($triggerRebuild = FALSE, $sessionReset = FALSE) {
361 $config = CRM_Core_Config
::singleton();
362 $config->clearModuleList();
364 // also cleanup all caches
365 $config->cleanupCaches($sessionReset || CRM_Utils_Request
::retrieve('sessionReset', 'Boolean', CRM_Core_DAO
::$_nullObject, FALSE, 0, 'GET'));
367 CRM_Core_Menu
::store();
369 // also reset navigation
370 CRM_Core_BAO_Navigation
::resetNavigation();
372 // also cleanup module permissions
373 $config->cleanupPermissions();
375 // rebuild word replacement cache - pass false to prevent operations redundant with this fn
376 CRM_Core_BAO_WordReplacement
::rebuild(FALSE);
378 CRM_Core_BAO_Setting
::updateSettingsFromMetaData();
380 CRM_Core_Resources
::singleton()->flushStrings()->resetCacheCode();
381 CRM_Case_XMLRepository
::singleton(TRUE);
383 // also rebuild triggers if requested explicitly
386 CRM_Utils_Request
::retrieve('triggerRebuild', 'Boolean', CRM_Core_DAO
::$_nullObject, FALSE, 0, 'GET')
388 CRM_Core_DAO
::triggerRebuild();
390 CRM_Core_DAO_AllCoreTables
::reinitializeCache(TRUE);
391 CRM_Core_ManagedEntities
::singleton(TRUE)->reconcile();