22 import(
'Smarty/Smarty.class.php');
23 import(
'Dataface/LanguageTool.php');
94 if ( is_writable(
$GLOBALS[
'Dataface_Globals_Local_Templates_c']) ){
96 $this->compile_dir =
$GLOBALS[
'Dataface_Globals_Local_Templates_c'];
97 }
else if ( is_writable(
$GLOBALS[
'Dataface_Globals_Templates_c'])){
98 $this->compile_dir =
$GLOBALS[
'Dataface_Globals_Templates_c'];
100 throw new Exception(
"<h1>No appropriate directory could be found to save
101 Dataface's compiled templates.</h1>
103 <p>Dataface uses the Smarty Template engine for its templates, which compiles
104 templates and stores them on the server for improved performance. You can
105 either store these templates in the Dataface directory or your application's
108 <p>To store the templates in the Dataface directory, please ensure that the
109 <pre>$GLOBALS[Dataface_Globals_Templates_c]</pre> directory exists and is writable by the
111 <p>You can make it writable by the web server on most unix and linux systems,
112 by issuing the following command in the shell:
113 <code><pre>chmod 777 $GLOBALS[Dataface_Globals_Templates_c] </pre></code>.</p>
115 <p>To store the templates in your application's directory, please ensure
116 that the <pre>$GLOBALS[Dataface_Globals_Local_Templates_c]</pre> directory exists and is
117 writable by the web server.</p>", E_USER_ERROR);
130 $conf =&
$app->_conf;
131 $resultSet =&
$app->getResultSet();
132 if ( isset( $conf[
'auto_load_results'] ) and $conf[
'auto_load_results'] ){
133 $currentRecord =& $resultSet->loadCurrent();
135 $currentRecord = null;
138 if ( isset(
$app->_conf[
'_themes']) and is_array(
$app->_conf[
'_themes']) ){
139 foreach (
$app->_conf[
'_themes'] as $themename=>$themepath ){
145 'REQUEST' => &$_REQUEST,
146 'SESSION' => &$_SESSION,
147 'DATAFACE_PATH' => DATAFACE_PATH,
148 'DATAFACE_URL' => DATAFACE_URL,
149 'DATAFACE_SITE_PATH' => DATAFACE_SITE_PATH,
150 'DATAFACE_SITE_URL' => DATAFACE_SITE_URL,
151 'DATAFACE_SITE_HREF' => DATAFACE_SITE_HREF,
152 'SCRIPT_NAME' => DATAFACE_SITE_URL.
'/'.basename(
$_SERVER[
'SCRIPT_NAME']),
153 'APPLICATION' => &$conf,
154 'APPLICATION_OBJECT' => &
$app,
156 'QUERY'=>&
$app->_query,
157 'action'=>@
$app->_query[
'-action'],
158 'table'=>@
$app->_query[
'-table'],
160 'relationship'=>@
$app->_query[
'-relationship'],
161 'limit'=>@
$app->_query[
'-limit'],
162 'start'=>@
$app->_query[
'-start'],
163 'resultSet'=>&$resultSet,
164 'record'=>&$currentRecord,
165 'mode'=>&
$app->_query[
'-mode'],
166 'language'=>
$app->_conf[
'lang'],
167 'prefs'=>&
$app->prefs,
168 'search'=>@$_REQUEST[
'-search']
172 $authTool =&
$app->getAuthenticationTool();
173 if ( isset($authTool) ){
174 $user =& $authTool->getLoggedInUser();
176 $this->ENV[
'user'] = &$user;
177 $this->ENV[
'username'] = $authTool->getLoggedInUsername();
183 if ( $del =
$app->getDelegate() and method_exists($del,
'getTemplateContext') ){
184 $c =& $del->getTemplateContext();
186 foreach ($c as $k=>$v){
192 $this->assign($context);
193 $this->register_function(
'load_record', array(&$this,
'load_record'));
194 $this->register_function(
'group',array(&$this,
'group'));
195 $this->register_function(
'img', array(&$this,
'img'));
196 $this->register_function(
'actions', array(&$this,
'actions'));
197 $this->register_function(
'actions_menu', array(&$this,
'actions_menu'));
198 $this->register_function(
'record_actions', array(&$this,
'record_actions'));
199 $this->register_function(
'record_tabs', array(&$this,
'record_tabs'));
200 $this->register_function(
'result_controller', array(&$this,
'result_controller'));
201 $this->register_function(
'result_list', array(&$this,
'result_list'));
202 $this->register_function(
'filters', array(&$this,
'filters'));
203 $this->register_function(
'related_list',array(&$this,
'related_list'));
204 $this->register_function(
'bread_crumbs', array(&$this,
'bread_crumbs'));
205 $this->register_function(
'search_form', array(&$this,
'search_form'));
206 $this->register_function(
'language_selector', array(&$this,
'language_selector'));
207 $this->register_function(
'next_link', array(&$this,
'next_link'));
208 $this->register_function(
'prev_link', array(&$this,
'prev_link'));
209 $this->register_function(
'jump_menu', array(&$this,
'jump_menu'));
210 $this->register_function(
'limit_field', array(&$this,
'limit_field'));
211 $this->register_function(
'result_index', array(&$this,
'result_index'));
212 $this->register_function(
'block', array(&$this,
'block'));
213 $this->register_function(
'summary_list',array(&$this,
'summary_list'));
214 $this->register_function(
'sort_controller',array(&$this,
'sort_controller'));
215 $this->register_function(
'glance_list', array(&$this,
'glance_list'));
216 $this->register_function(
'record_view', array(&$this,
'record_view'));
217 $this->register_function(
'feed', array(&$this,
'feed'));
218 $this->register_function(
'records', array(&$this,
'records'));
219 $this->register_function(
'form_context', array(&$this,
'form_context'));
220 $this->register_block(
'translate', array(&$this,
'translate'));
221 $this->register_block(
'use_macro',array(&$this,
'use_macro'));
222 $this->register_block(
'define_slot', array(&$this,
'define_slot'));
223 $this->register_block(
'fill_slot', array(&$this,
'fill_slot'));
224 $this->register_block(
'if_allowed', array(&$this,
'if_allowed'));
225 $this->register_block(
'editable', array(&$this,
'editable'));
226 $this->register_block(
'abs', array(&$this,
'abs'));
242 if ( !isset($this->resultController) ){
243 import(
'Dataface/ResultController.php');
245 $query =& $this->app->getQuery();
264 $params = array(
'resource_name'=>$resource_name,
'resource_base_path' => $this->template_dir);
265 $name = $this->_parse_resource_name($params);
266 $template_dir = dirname($params[
'resource_name']);
267 $skin = $this->skins[$template_dir];
268 if ( strlen($skin) > 0 and preg_match(
'/^[0-9a-zA-Z_]+$/', $skin) ){
274 echo
"<h2>Configuration Required</h2>
275 <p>Dataface was unable to create the directory '$compile_dir'
276 to store compiled template files.</p>
277 <h3>Possible reasons for this:</h3>
279 <li>The script does not have permission to create the directory.</li>
280 <li>The server is operating in safe mode.</li>
282 <h3>Possible Solutions for this:</h3>
285 <li>Manually create the '$compile_dir' directory and make it writable by the web server.</li>
286 <li>If none of these solves the problem, visit the Dataface forum
287 at <a href=\"http://xataface.com/forum\">http://xataface.com/forum</a>
297 error_log(
"Failed to create compile directory '$compile_dir'");
298 throw new Exception(
"Failed to compile templates due to a configuration problem. See error log for details.", E_USER_ERROR);
303 $fname= $this->_get_auto_filename(
$compile_dir, $resource_name,
304 $this->_compile_id) .
'.php';
320 function display($context, $template=null, $compile_id=null){
321 if ( !is_array($context) ) {
324 $event =
new StdClass;
325 $event->context =& $context;
327 $this->assign($context);
339 static $instance = 0;
341 if ( $count++ < 1 ) {
361 if ( !is_array($this->template_dir) ){
362 if ( strlen($this->template_dir) > 0 ){
363 $this->template_dir = array($this->template_dir);
365 $this->template_dir = array();
368 array_unshift($this->template_dir, $template_dir);
369 $this->skins[$template_dir] = $name;
387 if ( !is_array($this->plugins_dir) ){
388 if ( strlen($this->plugins_dir) > 0 ){
389 $this->plugins_dir = array($this->plugins_dir);
391 $this->plugins_dir = array();
394 array_unshift($this->plugins_dir, $plugin_dir);
425 import(
'dataface-public-api.php');
426 if ( empty($params[
'table']) ){
427 $params[
'table'] = $this->ENV[
'table'];
430 if ( empty($params[
'var']) ){
431 $params[
'var'] = null;
433 $table = $params[
'table'];
434 unset($params[
'table']);
435 $varname = $params[
'var'];
436 unset($params[
'var']);
437 $vars =& $smarty->get_template_vars();
439 if ( count($params) <= 0 ){
440 if ( !$this->app->recordLoaded() ){
441 $record =& $this->ENV[
'resultSet']->loadCurrent();
443 $record =& $this->app->getRecord();
447 $record =& df_get_record(
$table, $params);
450 if ( isset($varname) ) $vars[$varname] =& $record;
452 $vars[
'ENV'][
'record'] =& $record;
461 import(
'Dataface/RecordView.php');
463 if ( empty($params[
'record']) ) $params[
'record'] =& $this->app->getRecord();
464 if ( empty($params[
'var']) ) $params[
'var'] =
'rv';
466 $vars =& $smarty->get_template_vars();
485 import(
'Dataface/Utilities.php');
486 if ( empty($params[
'from']) ){
487 throw new Exception(
'group: Please specify a from parameter.', E_USER_ERROR);
489 if ( empty($params[
'var']) ){
490 throw new Exception(
'group: Please specify a var parameter.', E_USER_ERROR);
492 if ( empty($params[
'on'])){
493 throw new Exception(
'group: Please specify a field parameter.', E_USER_ERROR);
496 if ( !empty($params[
'order']) ){
497 $order = explode(
',',$params[
'order']);
502 if ( !empty($params[
'titles']) ){
503 $titles = array_map(
'trim',explode(
';', $params[
'titles']));
505 foreach ($titles as $title){
506 list($titleKey, $titleValue) = array_map(
'trim',explode(
':',$title));
507 $titles2[$titleKey] = $titleValue;
514 $context = array($params[
'var']=>&$cats);
515 $smarty->assign($context);
531 function img($params, &$smarty){
534 if ( !isset( $params[
'src'] ) )
return '';
537 if ( isset( $params[
'width'] ) ){
538 $width=
'&w='.$params[
'width'];
539 unset($params[
'width']);
544 if ( isset( $params[
'height']) ){
545 $height=
'&h='.$params[
'height'];
546 unset($params[
'height']);
552 if ( strlen($url) > 0 and $url{0} !=
'/' ){
553 $url = DATAFACE_SITE_URL.
'/'.$url;
554 }
else if ( strlen($url) == 0 ){
555 $url = DATAFACE_SITE_URL;
559 $src =
$_SERVER[
'HOST_URI'].$url.
'/lib/phpThumb/phpThumb.php?'.$width.$height.
'&src='.urlencode($params[
'src']);
560 unset($params[
'src']);
564 $tag =
"<img src=\"$src\" ";
565 foreach ( array_keys($params) as $key){
566 $tag .= $key.
'="'.$params[$key].
'" ';
585 if ( !isset($params[
'var']) )
throw new Exception(
'actions: var is a required parameter.', E_USER_ERROR);
586 $varname = $params[
'var'];
587 unset($params[
'var']);
588 import(
'Dataface/ActionTool.php');
590 if ( !isset($params[
'record']) ){
591 $params[
'record'] =& $this->ENV[
'record'];
593 $actions = $actionTool->getActions($params);
594 $context = array($varname=>$actions);
595 $smarty->assign($context);
603 if ( isset( $params[
'id'] ) ) {
604 $context[
'id'] = $params[
'id'];
605 unset($params[
'id']);
609 if ( isset( $params[
'class'] ) ) {
610 $context[
'class'] = $params[
'class'];
611 unset($params[
'class']);
613 $context[
'class'] =
'';
616 if ( isset( $params[
'id_prefix'] ) ) {
617 $context[
'id_prefix'] = $params[
'id_prefix'];
618 unset($params[
'id_prefix']);
620 $context[
'id_prefix'] =
'';
623 if ( isset( $params[
'selected_action'] ) ) {
624 $context[
'selected_action'] = $params[
'selected_action'];
625 unset($params[
'selected_action']);
627 $context[
'selected_action'] =
'';
630 if ( isset( $params[
'actions'] ) ){
631 $addon_actions = & $params[
'actions'];
633 $addon_actions = null;
642 import(
'Dataface/ActionTool.php');
644 $actions = $actionTool->getActions($params);
645 if ( $addon_actions !== null ){
647 unset($p2[
'category']);
648 $actions = array_merge($actions, $actionTool->getActions($p2,$addon_actions));
649 usort($actions, array(&$actionTool,
'_compareActions'));
652 foreach ($actions as $k=>$a){
653 if ( @$a[
'subcategory'] ){
655 $p2[
'category'] = $a[
'subcategory'];
656 $subactions = $actionTool->getActions($p2);
658 $actions[$k][
'subactions'] = $subactions;
664 $context[
'actions'] =& $actions;
666 if ( isset($params[
'mincount']) and intval($params[
'mincount']) > count($context[
'actions']) )
return;
667 if ( isset($params[
'maxcount']) and intval($params[
'maxcount']) < count($context[
'actions']) ){
670 'label'=> df_translate(
'actions_menu.more.label',
'More'),
671 'subactions' => array(),
672 'description' => df_translate(
'actions_menu.more.description',
'More actions...'),
681 $lastExistingKey = null;
682 foreach ($actions as $k=>$a){
684 if ( $i< $params[
'maxcount'] ){
686 $lastExistingKey = $k;
688 $more[
'subactions'][$k] = $a;
692 $existing[
'more'] = $more;
693 $context[
'actions'] = $existing;
695 $smarty->display($context,
'Dataface_ActionsMenu.html');
700 $params[
'category'] =
'record_actions';
705 $params[
'category'] =
'record_tabs';
706 if ( is_a($this->ENV[
'record'],
'Dataface_Record') ){
707 $params[
'record'] =& $this->ENV[
'record'];
712 $params[
'actions'] =
$table->getRelationshipsAsActions($params2);
719 import(
'Dataface/SummaryList.php');
721 return $sl->toHtml();
725 import(
'Dataface/GlanceList.php');
727 return $gl->toHtml();
731 import(
'Dataface/SortControl.php');
732 if ( !isset($params[
'fields']) ){
733 if ( !isset($params[
'table']) ) $params[
'table'] = $this->ENV[
'QUERY'][
'-table'];
734 $params[
'fields'] = $params[
'table'];
738 if ( isset($params[
'prefix']) ){
739 $params[
'prefix'] = null;
742 return $sc->toHtml();
747 if ( isset( $content ) ){
749 $smarty->display($params[
'file']);
750 $stack =& $smarty->get_template_vars(
'__macro_stack__');
754 $vars =& $smarty->get_template_vars();
755 if ( !isset($vars[
'__macro_stack__']) || !is_array($vars[
'__macro_stack__']) ){
758 $vars[
'__macro_stack__'] =& $stack;
760 array_push($vars[
'__macro_stack__'], array());
767 if ( isset($content) ){
768 if ( $this->app->_conf[
'usage_mode'] ==
'edit' ){
770 <span
id=
"{$params['id']}" class=
"editable">{$content}</span>
782 if ( isset($content) ) {
783 if ( $repeat) echo
"We are repeating $params[name]";
784 if ( @$this->app->_conf[
'debug'] ) $content =
'<!-- Begin Slot '.$params[
'name'].
' -->'.$content.
'<!-- End Slot '.$params[
'name'].
' -->';
789 $stack =& $smarty->get_template_vars(
'__macro_stack__');
790 $local_vars =& $stack[count($stack)-1];
791 foreach ( array_reverse(array_keys($stack) ) as $macroIndex) {
792 $local_vars =& $stack[$macroIndex];
793 if ( isset( $local_vars[
'__slots__'][$params[
'name']]) ){
797 echo $local_vars[
'__slots__'][$params[
'name']];
803 if ( isset($params[
'table']) ) $tname = $params[
'table'];
804 else $tname = $this->ENV[
'table'];
807 $out =
$table->getBlockContent($params[
'name']);
821 if ( isset($content) ){
823 $stack =& $smarty->get_template_vars(
'__macro_stack__');
824 $vars =& $stack[count($stack)-1];
825 $vars[
'__slots__'][$params[
'name']] = $content;
832 if ( isset($content) ){
833 if ( !isset($params[
'id']) )
return $content;
835 unset($params[
'id']);
836 return $this->languageTool->translate($id, $content, $params);
842 if ( isset($params[
'table']) ){
843 import(
'Dataface/ResultController.php');
844 $base_url = ( isset($params[
'base_url']) ? $params[
'base_url'] :
'');
845 $query = ( isset($params[
'query']) ? $params[
'query'] : array(
'-table'=>$params[
'table']));
846 $query[
'-table'] = $params[
'table'];
852 echo $controller->toHtml();
859 echo $controller->getNextLinkHtml(null, @$params[
'mode']);
865 echo $controller->getPrevLinkHtml(null, @$params[
'mode']);
870 echo $controller->jumpMenu();
875 echo $controller->limitField();
880 echo $controller->getPageIndexHtml();
883 import(
'Dataface/ResultList.php');
884 $query =& $this->app->getQuery();
886 if ( isset($params[
'columns']) ){
887 $columns = explode(
',',$params[
'columns']);
898 import(
'Dataface/ResultList.php');
899 $query =& $this->app->getQuery();
901 if ( isset($params[
'columns']) ){
902 $columns = explode(
',',$params[
'columns']);
912 if ( isset($params[
'table']) ){
913 $table = $params[
'table'];
914 unset($params[
'table']);
917 if ( isset($params[
'var']) ){
918 $varname = $params[
'var'];
919 unset($params[
'var']);
921 throw new Exception(
"{records} tag requires the var parameter to be set.");
924 $q = array_merge($this->app->getQuery(), $params);
926 $vars =& $smarty->get_template_vars();
927 $vars[$varname] = df_get_records_array($q[
'-table'], $q);
931 import(
'Dataface/RelatedList.php');
932 $query =& $this->app->getQuery();
933 if ( isset($params[
'record']) ) $record =& $params[
'record'];
934 else $record =& $this->ENV[
'resultSet']->loadCurrent();
937 throw new Exception(
'No record found from which to form related list.', E_USER_ERROR);
940 if ( isset($params[
'relationship']) ){
941 $relationship = $params[
'relationship'];
942 }
else if ( isset($query[
'-relationship']) ){
943 $relationship = $query[
'-relationship'];
945 throw new Exception(
'No relationship specified for related list.', E_USER_ERROR);
949 echo $relatedList->toHtml();
954 if ( $this->app->_query[
'-mode'] ===
'browse' and $this->app->_query[
'-action'] !=
'new'){
955 $record =& $this->app->getRecord();
958 foreach ( $record->getBreadCrumbs() as $label=>$url){
959 $base .=
' :: <a href="'.$url.
'" id="bread-crumbs-'.str_replace(
' ',
'_', $label).
'">'.$label.
'</a>';
962 $base = substr($base, 4);
967 if ( !$base and $del and method_exists($del,
'getBreadCrumbs') ){
968 $bc = $del->getBreadCrumbs();
972 foreach ( $bc as $label=>$url){
973 $base .=
' :: <a href="'.$url.
'" id="bread-crumbs-'.str_replace(
' ',
'_', $label).
'">'.$label.
'</a>';
979 $base =
$table->getLabel();
984 $action =& $this->app->getAction();
988 $base .=
' :: '.Dataface_LanguageTool::translate(
989 $action[
'label_i18n'],
991 return "<b>".df_translate(
'scripts.Dataface_SkinTool.LABEL_BREADCRUMB',
"You are here").
":</b> ".$base;
995 $query =& $this->app->getQuery();
996 $table = isset($params[
'table']) ? $params[
'table'] : $query[
'-table'];
997 $form =& df_create_search_form(
$table, $query);
1000 $out = ob_get_contents();
1018 if ( isset( $content ) ){
1019 if ( !isset( $params[
'permission'] ) ){
1020 throw new Exception(
'Missing permission parameter in if_allowed tag.', E_USER_ERROR);
1022 if ( isset( $params[
'record']) ) {
1023 $allowed = $params[
'record']->checkPermission($params[
'permission'],$params);
1024 }
else if ( isset($params[
'table']) ){
1027 $perms =
$table->getPermissions($params);
1028 $allowed = @$perms[$params[
'permission']];
1031 if ( @$perms[$params[
'permission']] ) $allowed =
true;
1032 else $allowed =
false;
1034 if ( $allowed )
return $content;
1047 $out = ob_get_contents();
1054 if ( isset($params[
'query']) ) parse_str($params[
'query'], $query);
1055 else $query = array();
1056 unset($params[
'query']);
1058 if ( isset($params[
'table']) ){
1059 $query[
'-table'] = $params[
'table'];
1060 unset($params[
'table']);
1063 if ( isset($params[
'relationship']) ){
1064 $query[
'-relationship'] = $params[
'relationship'];
1065 unset($params[
'relationship']);
1068 if ( isset($params[
'format']) ){
1069 $query[
'--format'] = $params[
'format'];
1070 unset($params[
'format']);
1073 if ( isset($params[
'url']) ){
1074 $url = $params[
'url'];
1076 $url = DATAFACE_SITE_HREF;
1079 if ( isset($params[
'size']) and $params[
'size'] ==
'large' ){
1080 $icon =
'feed-icon-28x28.png';
1082 $icon =
'feed-icon-14x14.png';
1085 $query[
'-action'] =
'feed';
1087 $appq =
$app->url($query);
1088 $url = $url .
'?'.substr( $appq, strpos($appq,
'?')+1);
1089 echo
'<a style="display:inline !important" class="feed-link" href="'.htmlspecialchars($url).
'" title="Subscribe to feed"><img style="display:inline !important" src="'.DATAFACE_URL.
'/images/'.$icon.
'" alt="Feed"/></a>';
1092 function abs($params, $url, &$smarty){
1093 return df_absolute_url($url);
1099 if ( @$params[
'exclude'] ){
1100 $tmp = array_map(
'trim', explode(
',', $params[
'exclude']));
1101 foreach ($tmp as $t){
1106 foreach ($query as $k=>$v){
1107 if ( isset($exclude[$k]) )
continue;
1108 if ( is_string($v) and strlen($k)>1 and $k{0} ===
'-' and $k{1} !==
'-' ){
1109 $fields[] =
'<input type="hidden" name="'.htmlspecialchars($k).
'" value="'.htmlspecialchars($v).
'"/>';
1110 }
else if ( @$params[
'filters'] and is_string($v) and strlen($v)>0 and strlen($k)>0 and $k{0} !==
'-'){
1111 $fields[] =
'<input type="hidden" name="'.htmlspecialchars($k).
'" value="'.htmlspecialchars($v).
'"/>';
1116 return implode(
"\n",
$fields);