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
104 * List of path parts.
107 static public function hackMenuRebuild($args) {
108 if (array('civicrm','menu','rebuild') == $args ||
array('civicrm', 'clearcache') == $args) {
109 // ensure that the user has a good privilege level
110 if (CRM_Core_Permission
::check('administer CiviCRM')) {
111 self
::rebuildMenuAndCaches();
112 CRM_Core_Session
::setStatus(ts('Cleared all CiviCRM caches (database, menu, templates)'), ts('Complete'), 'success');
113 return CRM_Utils_System
::redirect(); // exits
116 CRM_Core_Error
::fatal('You do not have permission to execute this url');
122 * Perform general setup
125 * List of path parts.
128 static public function init($args) {
129 // first fire up IDS and check for bad stuff
130 $config = CRM_Core_Config
::singleton();
131 if (!CRM_Core_Permission
::check('skip IDS check')) {
132 $ids = new CRM_Core_IDS();
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);
175 $item = CRM_Core_Menu
::get($path);
177 // we should try to compute menus, if item is empty and stay on the same page,
178 // rather than compute and redirect to dashboard.
180 CRM_Core_Menu
::store(FALSE);
181 $item = CRM_Core_Menu
::get($path);
188 * Given a menu item, call the appropriate controller and return the response
192 * @return string, HTML
194 static public function runItem($item) {
195 $config = CRM_Core_Config
::singleton();
196 if ($config->userFramework
== 'Joomla' && $item) {
197 $config->userFrameworkURLVar
= 'task';
199 // joomla 1.5RC1 seems to push this in the POST variable, which messes
201 unset($_POST['option']);
202 CRM_Core_Joomla
::sidebarLeft();
205 // set active Component
206 $template = CRM_Core_Smarty
::singleton();
207 $template->assign('activeComponent', 'CiviCRM');
208 $template->assign('formTpl', 'default');
211 // CRM-7656 - make sure we send a clean sanitized path to create printer friendly url
212 $printerFriendly = CRM_Utils_System
::makeURL(
213 'snippet', FALSE, FALSE,
214 CRM_Utils_Array
::value('path', $item)
216 $template->assign('printerFriendly', $printerFriendly);
218 if (!array_key_exists('page_callback', $item)) {
219 CRM_Core_Error
::debug('Bad item', $item);
220 CRM_Core_Error
::fatal(ts('Bad menu record in database'));
223 // check that we are permissioned to access this page
224 if (!CRM_Core_Permission
::checkMenuItem($item)) {
225 CRM_Utils_System
::permissionDenied();
229 // check if ssl is set
230 if (!empty($item['is_ssl'])) {
231 CRM_Utils_System
::redirectToSSL();
234 if (isset($item['title'])) {
235 CRM_Utils_System
::setTitle($item['title']);
238 if (isset($item['breadcrumb']) && !isset($item['is_public'])) {
239 CRM_Utils_System
::appendBreadCrumb($item['breadcrumb']);
243 if (!empty($item['page_arguments'])) {
244 $pageArgs = CRM_Core_Menu
::getArrayForPathArgs($item['page_arguments']);
247 $template = CRM_Core_Smarty
::singleton();
248 if (!empty($item['is_public'])) {
249 $template->assign('urlIsPublic', TRUE);
252 $template->assign('urlIsPublic', FALSE);
253 self
::versionCheck($template);
256 if (isset($item['return_url'])) {
257 $session = CRM_Core_Session
::singleton();
258 $args = CRM_Utils_Array
::value(
263 $session->pushUserContext(CRM_Utils_System
::url($item['return_url'], $args));
267 if (is_array($item['page_callback'])) {
268 require_once (str_replace('_', DIRECTORY_SEPARATOR
, $item['page_callback'][0]) . '.php');
269 $result = call_user_func($item['page_callback']);
271 elseif (strstr($item['page_callback'], '_Form')) {
272 $wrapper = new CRM_Utils_Wrapper();
273 $result = $wrapper->run(
274 CRM_Utils_Array
::value('page_callback', $item),
275 CRM_Utils_Array
::value('title', $item),
276 isset($pageArgs) ?
$pageArgs : NULL
280 $newArgs = explode('/', $_GET[$config->userFrameworkURLVar
]);
281 require_once (str_replace('_', DIRECTORY_SEPARATOR
, $item['page_callback']) . '.php');
283 if (isset($pageArgs['mode'])) {
284 $mode = $pageArgs['mode'];
285 unset($pageArgs['mode']);
287 $title = CRM_Utils_Array
::value('title', $item);
288 if (strstr($item['page_callback'], '_Page')) {
289 $object = new $item['page_callback'] ($title, $mode );
290 $object->urlPath
= explode('/', $_GET[$config->userFrameworkURLVar
]);
292 elseif (strstr($item['page_callback'], '_Controller')) {
293 $addSequence = 'false';
294 if (isset($pageArgs['addSequence'])) {
295 $addSequence = $pageArgs['addSequence'];
296 $addSequence = $addSequence ?
'true' : 'false';
297 unset($pageArgs['addSequence']);
299 $object = new $item['page_callback'] ($title, true, $mode, null, $addSequence );
302 CRM_Core_Error
::fatal();
304 $result = $object->run($newArgs, $pageArgs);
307 CRM_Core_Session
::storeSessionObjects();
311 CRM_Core_Menu
::store();
312 CRM_Core_Session
::setStatus(ts('Menu has been rebuilt'), ts('Complete'), 'success');
313 return CRM_Utils_System
::redirect();
317 * This function contains the default action
321 * @param $contact_type
322 * @param $contact_sub_type
326 public static function form($action, $contact_type, $contact_sub_type) {
327 CRM_Utils_System
::setUserContext(array('civicrm/contact/search/basic', 'civicrm/contact/view'));
328 $wrapper = new CRM_Utils_Wrapper();
330 $properties = CRM_Core_Component
::contactSubTypeProperties($contact_sub_type, 'Edit');
332 $wrapper->run($properties['class'], ts('New %1', array(1 => $contact_sub_type)), $action, TRUE);
335 $wrapper->run('CRM_Contact_Form_Contact', ts('New Contact'), $action, TRUE);
340 * Show the message about CiviCRM versions
342 * @param CRM_Core_Smarty $template
344 public static function versionCheck($template) {
345 if (CRM_Core_Config
::isUpgradeMode()) {
348 $newerVersion = $securityUpdate = NULL;
349 if (CRM_Core_BAO_Setting
::getItem(CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
, 'versionAlert', NULL, 1) & 1) {
350 $newerVersion = CRM_Utils_VersionCheck
::singleton()->isNewerVersionAvailable();
352 if (CRM_Core_BAO_Setting
::getItem(CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
, 'securityUpdateAlert', NULL, 3) & 1) {
353 $securityUpdate = CRM_Utils_VersionCheck
::singleton()->isSecurityUpdateAvailable();
355 $template->assign('newer_civicrm_version', $newerVersion);
356 $template->assign('security_update', $securityUpdate);
360 * @param bool $triggerRebuild
361 * @param bool $sessionReset
365 public static function rebuildMenuAndCaches($triggerRebuild = FALSE, $sessionReset = FALSE) {
366 $config = CRM_Core_Config
::singleton();
367 $config->clearModuleList();
369 // also cleanup all caches
370 $config->cleanupCaches($sessionReset || CRM_Utils_Request
::retrieve('sessionReset', 'Boolean', CRM_Core_DAO
::$_nullObject, FALSE, 0, 'GET'));
372 CRM_Core_Menu
::store();
374 // also reset navigation
375 CRM_Core_BAO_Navigation
::resetNavigation();
377 // also cleanup module permissions
378 $config->cleanupPermissions();
380 // rebuild word replacement cache - pass false to prevent operations redundant with this fn
381 CRM_Core_BAO_WordReplacement
::rebuild(FALSE);
383 CRM_Core_BAO_Setting
::updateSettingsFromMetaData();
385 CRM_Core_Resources
::singleton()->flushStrings()->resetCacheCode();
386 CRM_Case_XMLRepository
::singleton(TRUE);
388 // also rebuild triggers if requested explicitly
391 CRM_Utils_Request
::retrieve('triggerRebuild', 'Boolean', CRM_Core_DAO
::$_nullObject, FALSE, 0, 'GET')
393 CRM_Core_DAO
::triggerRebuild();
395 CRM_Core_DAO_AllCoreTables
::reinitializeCache(TRUE);
396 CRM_Core_ManagedEntities
::singleton(TRUE)->reconcile();