Open Monograph Press  1.1
 All Classes Namespaces Functions Variables Groups Pages
TemplateBasedFilter.inc.php
1 <?php
2 
17 import('lib.pkp.classes.filter.PersistableFilter');
18 
24  function TemplateBasedFilter($filterGroup) {
25  parent::PersistableFilter($filterGroup);
26  }
27 
28 
29  //
30  // Abstract template methods
31  //
38  function getBasePath() {
39  // Must be implemented by sub-classes.
40  assert(false);
41  }
42 
47  function getTemplateName() {
48  // Must be implemented by sub-classes.
49  assert(false);
50  }
51 
60  function addTemplateVars($templateMgr, &$input, $request, &$locale) {
61  // Must be implemented by sub-classes.
62  assert(false);
63  }
64 
65 
66  //
67  // Implement template methods from Filter
68  //
72  function &process(&$input) {
73  // Initialize view
74  $locale = AppLocale::getLocale();
75  $application = PKPApplication::getApplication();
76  $request = $application->getRequest();
77  $templateMgr = TemplateManager::getManager($request);
78 
79  // Add the filter's directory as additional template dir so that
80  // templates can include sub-templates in the same folder.
81  array_unshift($templateMgr->template_dir, $this->getBasePath());
82 
83  // Give sub-filters a chance to add their variables
84  // to the template.
85  $this->addTemplateVars($templateMgr, $input, $request, $locale);
86 
87  // Use a base path hash as compile id to make sure that we don't
88  // get namespace problems if several filters use the same
89  // template names.
90  $previousCompileId = $templateMgr->compile_id;
91  $templateMgr->compile_id = md5($this->getBasePath());
92 
93  // Let the template engine render the citation.
94  $output = $templateMgr->fetch($this->getTemplateName());
95 
96  // Remove the additional template dir
97  array_shift($templateMgr->template_dir);
98 
99  // Restore the compile id.
100  $templateMgr->compile_id = $previousCompileId;
101 
102  return $output;
103  }
104 }
105 ?>
static getLocale()
A filter that can be persisted to the database.
Abstract base class for all filters that transform their input via smarty templates.
addTemplateVars($templateMgr, &$input, $request, &$locale)