<?php
/*
+--------------------------------------------------------------------+
- | CiviCRM version 4.3 |
+ | CiviCRM version 4.4 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2013 |
+--------------------------------------------------------------------+
*/
static protected $_session;
+ /**
+ * What to return to the client if in ajax mode (snippet=json)
+ *
+ * @var array
+ */
+ public $ajaxResponse = array();
+
/**
* class constructor
*
self::$_session = CRM_Core_Session::singleton();
}
- if (isset($_REQUEST['snippet']) && $_REQUEST['snippet']) {
- if ($_REQUEST['snippet'] == 3) {
+ // FIXME - why are we messing with 'snippet'? Why not just pass it directly into $this->_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;
}
self::$_template->assign('mode', $this->_mode);
- $pageTemplateFile = $this->getTemplateFileName();
+ $pageTemplateFile = $this->getHookedTemplateFileName();
self::$_template->assign('tplFile', $pageTemplateFile);
// invoke the pagRun hook, CRM-3906
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 {
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;
}
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 <a href="%1">system settings</a>. This should not be enabled on production servers.', array(1 => CRM_Utils_System::url('civicrm/admin/setting/debug', 'reset=1')));
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.
*
) . '.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