X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FCore%2FPage.php;h=4ac7d41c09e3ce249aa238c9424e7bf8b2324127;hb=fa6e7e67b3c515c36d390c75b7a4975408c4053f;hp=8d69a0a80782e2e00023c25aa86ff20dfe93c422;hpb=149e631532beb9953cde6af3e647bbc82ee2e3d5;p=civicrm-core.git diff --git a/CRM/Core/Page.php b/CRM/Core/Page.php index 8d69a0a807..4ac7d41c09 100644 --- a/CRM/Core/Page.php +++ b/CRM/Core/Page.php @@ -1,7 +1,7 @@ _print? + if (!empty($_REQUEST['snippet'])) { + if ($_REQUEST['snippet'] == CRM_Core_Smarty::PRINT_PDF) { $this->_print = CRM_Core_Smarty::PRINT_PDF; } - else if ($_REQUEST['snippet'] == 5) { + // FIXME - why does this number not match the constant? + elseif ($_REQUEST['snippet'] == 5) { $this->_print = CRM_Core_Smarty::PRINT_NOFORM; } + // Support 'json' as well as legacy value '6' + elseif (in_array($_REQUEST['snippet'], array(CRM_Core_Smarty::PRINT_JSON, 6))) { + $this->_print = CRM_Core_Smarty::PRINT_JSON; + } else { $this->_print = CRM_Core_Smarty::PRINT_SNIPPET; } @@ -155,7 +168,7 @@ class CRM_Core_Page { self::$_template->assign('mode', $this->_mode); - $pageTemplateFile = $this->getTemplateFileName(); + $pageTemplateFile = $this->getHookedTemplateFileName(); self::$_template->assign('tplFile', $pageTemplateFile); // invoke the pagRun hook, CRM-3906 @@ -163,7 +176,7 @@ class CRM_Core_Page { if ($this->_print) { if (in_array( $this->_print, array( CRM_Core_Smarty::PRINT_SNIPPET, - CRM_Core_Smarty::PRINT_PDF, CRM_Core_Smarty::PRINT_NOFORM ))) { + CRM_Core_Smarty::PRINT_PDF, CRM_Core_Smarty::PRINT_NOFORM, CRM_Core_Smarty::PRINT_JSON ))) { $content = self::$_template->fetch('CRM/common/snippet.tpl'); } else { @@ -183,6 +196,10 @@ class CRM_Core_Page { array('paper_size' => 'a3', 'orientation' => 'landscape') ); } + elseif ($this->_print == CRM_Core_Smarty::PRINT_JSON) { + $this->ajaxResponse['content'] = $content; + CRM_Core_Page_AJAX::returnJsonResponse($this->ajaxResponse); + } else { echo $content; } @@ -195,7 +212,7 @@ class CRM_Core_Page { if (empty($_GET['snippet'])) { // Version check and intermittent alert to admins CRM_Utils_VersionCheck::singleton()->versionAlert(); - + // Debug msg once per hour if ($config->debug && CRM_Core_Permission::check('administer CiviCRM') && CRM_Core_Session::singleton()->timer('debug_alert', 3600)) { $msg = ts('Warning: Debug is enabled in system settings. This should not be enabled on production servers.', array(1 => CRM_Utils_System::url('civicrm/admin/setting/debug', 'reset=1'))); @@ -273,6 +290,28 @@ class CRM_Core_Page { self::$_template->assign_by_ref($var, $value); } + /** + * appends values to template variables + * + * @param array|string $tpl_var the template variable name(s) + * @param mixed $value the value to append + * @param bool $merge + */ + function append($tpl_var, $value=NULL, $merge=FALSE) { + self::$_template->append($tpl_var, $value, $merge); + } + + /** + * Returns an array containing template variables + * + * @param string $name + * @param string $type + * @return array + */ + function get_template_vars($name=null) { + return self::$_template->get_template_vars($name); + } + /** * function to destroy all the session state of this page. * @@ -297,6 +336,16 @@ class CRM_Core_Page { ) . '.tpl'; } + /** + * A wrapper for getTemplateFileName that includes calling the hook to + * prevent us from having to copy & paste the logic of calling the hook + */ + function getHookedTemplateFileName() { + $pageTemplateFile = $this->getTemplateFileName(); + CRM_Utils_Hook::alterTemplateFile(get_class($this), $this, 'page', $pageTemplateFile); + return $pageTemplateFile; + } + /** * Default extra tpl file basically just replaces .tpl with .extra.tpl * i.e. we dont override