![]() |
Xataface 2.0
Xataface Application Framework
|
00001 <?php 00002 /*------------------------------------------------------------------------------- 00003 * Xataface Web Application Framework 00004 * Copyright (C) 2005-2008 Web Lite Solutions Corp (shannah@sfu.ca) 00005 * 00006 * This program is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU General Public License 00008 * as published by the Free Software Foundation; either version 2 00009 * of the License, or (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00019 *------------------------------------------------------------------------------- 00020 */ 00021 00022 import( 'Smarty/Smarty.class.php'); 00023 import( 'Dataface/LanguageTool.php'); 00081 class Dataface_SkinTool extends Smarty{ 00082 00083 00084 var $compile_dir; 00085 var $ENV; 00086 var $skins = array(); 00087 var $locals = array(); 00088 var $languageTool; 00089 var $app; 00090 var $resultController = null; 00091 00092 function Dataface_SkinTool() { 00093 00094 if ( is_writable($GLOBALS['Dataface_Globals_Local_Templates_c']) ){ 00095 00096 $this->compile_dir = $GLOBALS['Dataface_Globals_Local_Templates_c']; 00097 } else if ( is_writable($GLOBALS['Dataface_Globals_Templates_c'])){ 00098 $this->compile_dir = $GLOBALS['Dataface_Globals_Templates_c']; 00099 } else { 00100 throw new Exception("<h1>No appropriate directory could be found to save 00101 Dataface's compiled templates.</h1> 00102 00103 <p>Dataface uses the Smarty Template engine for its templates, which compiles 00104 templates and stores them on the server for improved performance. You can 00105 either store these templates in the Dataface directory or your application's 00106 directory.</p> 00107 00108 <p>To store the templates in the Dataface directory, please ensure that the 00109 <pre>$GLOBALS[Dataface_Globals_Templates_c]</pre> directory exists and is writable by the 00110 web server. </p> 00111 <p>You can make it writable by the web server on most unix and linux systems, 00112 by issuing the following command in the shell: 00113 <code><pre>chmod 777 $GLOBALS[Dataface_Globals_Templates_c] </pre></code>.</p> 00114 00115 <p>To store the templates in your application's directory, please ensure 00116 that the <pre>$GLOBALS[Dataface_Globals_Local_Templates_c]</pre> directory exists and is 00117 writable by the web server.</p>", E_USER_ERROR); 00118 } 00119 00120 $this->languageTool =& Dataface_LanguageTool::getInstance(); 00121 00122 00123 $this->register_skin('dataface', $GLOBALS['Dataface_Globals_Templates']); 00124 00125 $this->register_skin('default', $GLOBALS['Dataface_Globals_Local_Templates']); 00126 00127 $app =& Dataface_Application::getInstance(); 00128 $this->app =& $app; 00129 $conf =& $app->_conf; 00130 $resultSet =& $app->getResultSet(); 00131 if ( isset( $conf['auto_load_results'] ) and $conf['auto_load_results'] ){ 00132 $currentRecord =& $resultSet->loadCurrent(); 00133 } else { 00134 $currentRecord = null; 00135 } 00136 00137 if ( isset($app->_conf['_themes']) and is_array($app->_conf['_themes']) ){ 00138 foreach ( $app->_conf['_themes'] as $themename=>$themepath ){ 00139 $this->register_skin($themename, $themepath.'/templates'); 00140 } 00141 } 00142 00143 $this->ENV = array( 00144 'REQUEST' => &$_REQUEST, 00145 'SESSION' => &$_SESSION, 00146 'DATAFACE_PATH' => DATAFACE_PATH, 00147 'DATAFACE_URL' => DATAFACE_URL, 00148 'DATAFACE_SITE_PATH' => DATAFACE_SITE_PATH, 00149 'DATAFACE_SITE_URL' => DATAFACE_SITE_URL, 00150 'DATAFACE_SITE_HREF' => DATAFACE_SITE_HREF, 00151 'SCRIPT_NAME' => DATAFACE_SITE_URL.'/'.basename($_SERVER['SCRIPT_NAME']), 00152 'APPLICATION' => &$conf, 00153 'APPLICATION_OBJECT' => &$app, 00154 'SERVER' => &$_SERVER, 00155 'QUERY'=>&$app->_query, 00156 'action'=>@$app->_query['-action'], 00157 'table'=>@$app->_query['-table'], 00158 'table_object'=> Dataface_Table::loadTable($app->_query['-table']), 00159 'relationship'=>@$app->_query['-relationship'], 00160 'limit'=>@$app->_query['-limit'], 00161 'start'=>@$app->_query['-start'], 00162 'resultSet'=>&$resultSet, 00163 'record'=>&$currentRecord, 00164 'mode'=>&$app->_query['-mode'], 00165 'language'=>$app->_conf['lang'], 00166 'prefs'=>&$app->prefs, 00167 'search'=>@$_REQUEST['-search'] 00168 00169 ); 00170 00171 $authTool =& $app->getAuthenticationTool(); 00172 if ( isset($authTool) ){ 00173 $user =& $authTool->getLoggedInUser(); 00174 if ( isset($user) ){ 00175 $this->ENV['user'] = &$user; 00176 $this->ENV['username'] = $authTool->getLoggedInUsername(); 00177 } 00178 } 00179 $context = array(); 00180 $context['APP'] =& $this->app; 00181 $context['ENV'] =& $this->ENV; 00182 if ( $del = $app->getDelegate() and method_exists($del, 'getTemplateContext') ){ 00183 $c =& $del->getTemplateContext(); 00184 if ( is_array($c) ){ 00185 foreach ($c as $k=>$v){ 00186 $context[$k] = $v; 00187 } 00188 } 00189 } 00190 00191 $this->assign($context); 00192 $this->register_function('load_record', array(&$this, 'load_record')); 00193 $this->register_function('group',array(&$this,'group')); 00194 $this->register_function('img', array(&$this,'img')); 00195 $this->register_function('actions', array(&$this, 'actions')); 00196 $this->register_function('actions_menu', array(&$this, 'actions_menu')); 00197 $this->register_function('record_actions', array(&$this, 'record_actions')); 00198 $this->register_function('record_tabs', array(&$this, 'record_tabs')); 00199 $this->register_function('result_controller', array(&$this, 'result_controller')); 00200 $this->register_function('result_list', array(&$this,'result_list')); 00201 $this->register_function('filters', array(&$this, 'filters')); 00202 $this->register_function('related_list',array(&$this,'related_list')); 00203 $this->register_function('bread_crumbs', array(&$this, 'bread_crumbs')); 00204 $this->register_function('search_form', array(&$this, 'search_form')); 00205 $this->register_function('language_selector', array(&$this, 'language_selector')); 00206 $this->register_function('next_link', array(&$this, 'next_link')); 00207 $this->register_function('prev_link', array(&$this, 'prev_link')); 00208 $this->register_function('jump_menu', array(&$this, 'jump_menu')); 00209 $this->register_function('limit_field', array(&$this, 'limit_field')); 00210 $this->register_function('result_index', array(&$this, 'result_index')); 00211 $this->register_function('block', array(&$this, 'block')); 00212 $this->register_function('summary_list',array(&$this,'summary_list')); 00213 $this->register_function('sort_controller',array(&$this,'sort_controller')); 00214 $this->register_function('glance_list', array(&$this,'glance_list')); 00215 $this->register_function('record_view', array(&$this,'record_view')); 00216 $this->register_function('feed', array(&$this,'feed')); 00217 $this->register_function('records', array(&$this, 'records')); 00218 00219 $this->register_block('translate', array(&$this, 'translate')); 00220 $this->register_block('use_macro',array(&$this,'use_macro')); 00221 $this->register_block('define_slot', array(&$this,'define_slot')); 00222 $this->register_block('fill_slot', array(&$this,'fill_slot')); 00223 $this->register_block('if_allowed', array(&$this, 'if_allowed')); 00224 $this->register_block('editable', array(&$this, 'editable')); 00225 $this->register_block('abs', array(&$this, 'abs')); 00226 00227 00228 00229 } 00230 00231 00239 function &getResultController(){ 00240 if ( !isset($this->resultController) ){ 00241 import('Dataface/ResultController.php'); 00242 00243 $query =& $this->app->getQuery(); 00244 00245 $this->resultController = new Dataface_ResultController($query['-table'], $this->app->db(), DATAFACE_SITE_HREF); 00246 } 00247 00248 return $this->resultController; 00249 } 00250 00260 function _get_compile_path($resource_name) 00261 { 00262 $params = array('resource_name'=>$resource_name, 'resource_base_path' => $this->template_dir); 00263 $name = $this->_parse_resource_name($params); 00264 $template_dir = dirname($params['resource_name']); 00265 $skin = $this->skins[$template_dir]; 00266 if ( strlen($skin) > 0 and preg_match('/^[0-9a-zA-Z_]+$/', $skin) ){ 00267 $compile_dir = $this->compile_dir.'/'.$skin; 00268 if ( !file_exists($compile_dir) ){ 00269 $res = @mkdir($compile_dir); 00270 00271 if ( !$res ){ 00272 echo "<h2>Configuration Required</h2> 00273 <p>Dataface was unable to create the directory '$compile_dir' 00274 to store compiled template files.</p> 00275 <h3>Possible reasons for this:</h3> 00276 <ul> 00277 <li>The script does not have permission to create the directory.</li> 00278 <li>The server is operating in safe mode.</li> 00279 </ul> 00280 <h3>Possible Solutions for this:</h3> 00281 <ul> 00282 <li>Make the ".dirname($compile_dir)." writable by the web server. E.g. chmod 0777 ".dirname($compile_dir).".</li> 00283 <li>Manually create the '$compile_dir' directory and make it writable by the web server.</li> 00284 <li>If none of these solves the problem, visit the Dataface forum 00285 at <a href=\"http://xataface.com/forum\">http://xataface.com/forum</a> 00286 and ask for help. 00287 </li> 00288 </ul> 00289 "; 00290 exit; 00291 } 00292 00293 } 00294 if ( !file_exists($compile_dir) ){ 00295 error_log("Failed to create compile directory '$compile_dir'"); 00296 throw new Exception("Failed to compile templates due to a configuration problem. See error log for details.", E_USER_ERROR); 00297 } 00298 } else { 00299 $compile_dir = $this->compile_dir; 00300 } 00301 $fname= $this->_get_auto_filename($compile_dir, $resource_name, 00302 $this->_compile_id) . '.php'; 00303 00304 return $fname; 00305 } 00306 00307 00318 function display($context, $template=null, $compile_id=null){ 00319 if ( !is_array($context) ) { 00320 return parent::display($context); 00321 } 00322 $event = new StdClass; 00323 $event->context =& $context; 00324 Dataface_Application::getInstance()->fireEvent('filterTemplateContext', $event); 00325 $this->assign($context); 00326 return parent::display($template); 00327 00328 } 00329 00330 00331 00336 public static function &getInstance(){ 00337 static $instance = 0; 00338 static $count = 0; 00339 if ( $count++ < 1 ) { 00340 00341 $instance = new Dataface_SkinTool(); 00342 } 00343 00344 return $instance; 00345 } 00346 00347 00348 00358 function register_skin( $name, $template_dir){ 00359 if ( !is_array($this->template_dir) ){ 00360 if ( strlen($this->template_dir) > 0 ){ 00361 $this->template_dir = array($this->template_dir); 00362 } else { 00363 $this->template_dir = array(); 00364 } 00365 } 00366 array_unshift($this->template_dir, $template_dir); 00367 $this->skins[$template_dir] = $name; 00368 00369 } 00370 00371 00372 //------------------SMARTY TEMPLATE FUNCTIONS--------------------------- 00373 // These are functions to be used inside templates to get information 00374 // from the database. 00375 // 00376 00397 function load_record($params, &$smarty){ 00398 import( 'dataface-public-api.php'); 00399 if ( empty($params['table']) ){ 00400 $params['table'] = $this->ENV['table']; 00401 } 00402 00403 if ( empty($params['var']) ){ 00404 $params['var'] = null; 00405 } 00406 $table = $params['table']; 00407 unset($params['table']); 00408 $varname = $params['var']; 00409 unset($params['var']); 00410 $vars =& $smarty->get_template_vars(); 00411 00412 if ( count($params) <= 0 ){ 00413 if ( !$this->app->recordLoaded() ){ 00414 $record =& $this->ENV['resultSet']->loadCurrent(); 00415 } else { 00416 $record =& $this->app->getRecord(); 00417 } 00418 00419 } else { 00420 $record =& df_get_record($table, $params); 00421 00422 } 00423 if ( isset($varname) ) $vars[$varname] =& $record; 00424 else 00425 $vars['ENV']['record'] =& $record; 00426 00427 00428 } 00429 00430 00431 00432 00433 function record_view($params, &$smarty){ 00434 import('Dataface/RecordView.php'); 00435 00436 if ( empty($params['record']) ) $params['record'] =& $this->app->getRecord(); 00437 if ( empty($params['var']) ) $params['var'] = 'rv'; 00438 00439 $vars =& $smarty->get_template_vars(); 00440 $vars[$params['var']] = new Dataface_RecordView($params['record']); 00441 00442 } 00443 00456 function group($params, &$smarty){ 00457 00458 import( 'Dataface/Utilities.php'); 00459 if ( empty($params['from']) ){ 00460 throw new Exception('group: Please specify a from parameter.', E_USER_ERROR); 00461 } 00462 if ( empty($params['var']) ){ 00463 throw new Exception('group: Please specify a var parameter.', E_USER_ERROR); 00464 } 00465 if ( empty($params['on'])){ 00466 throw new Exception('group: Please specify a field parameter.', E_USER_ERROR); 00467 } 00468 00469 if ( !empty($params['order']) ){ 00470 $order = explode(',',$params['order']); 00471 } else { 00472 $order = array(); 00473 } 00474 00475 if ( !empty($params['titles']) ){ 00476 $titles = array_map('trim',explode(';', $params['titles'])); 00477 $titles2 = array(); 00478 foreach ($titles as $title){ 00479 list($titleKey, $titleValue) = array_map('trim',explode(':',$title)); 00480 $titles2[$titleKey] = $titleValue; 00481 } 00482 } else { 00483 $titles2 = array(); 00484 } 00485 00486 $cats = Dataface_Utilities::groupBy($params['on'], $params['from'], $order, $titles2); 00487 $context = array($params['var']=>&$cats); 00488 $smarty->assign($context); 00489 00490 } 00491 00504 function img($params, &$smarty){ 00505 00506 // We have to have at least the src parameter set 00507 if ( !isset( $params['src'] ) ) return ''; 00508 00509 00510 if ( isset( $params['width'] ) ){ 00511 $width= '&w='.$params['width']; 00512 unset($params['width']); 00513 } else { 00514 $width = ''; 00515 } 00516 00517 if ( isset( $params['height']) ){ 00518 $height= '&h='.$params['height']; 00519 unset($params['height']); 00520 } else { 00521 $height = ''; 00522 } 00523 00524 $url = DATAFACE_URL; 00525 if ( strlen($url) > 0 and $url{0} != '/' ){ 00526 $url = DATAFACE_SITE_URL.'/'.$url; 00527 } else if ( strlen($url) == 0 ){ 00528 $url = DATAFACE_SITE_URL; 00529 } else { 00530 $url = ''; 00531 } 00532 $src = $_SERVER['HOST_URI'].$url.'/lib/phpThumb/phpThumb.php?'.$width.$height.'&src='.urlencode($params['src']); 00533 unset($params['src']); 00534 00535 00536 00537 $tag = "<img src=\"$src\" "; 00538 foreach ( array_keys($params) as $key){ 00539 $tag .= $key.'="'.$params[$key].'" '; 00540 } 00541 00542 $tag .= "/>"; 00543 00544 return $tag; 00545 00546 } 00547 00548 00557 function actions($params, &$smarty){ 00558 if ( !isset($params['var']) ) throw new Exception('actions: var is a required parameter.', E_USER_ERROR); 00559 $varname = $params['var']; 00560 unset($params['var']); 00561 import( 'Dataface/ActionTool.php'); 00562 $actionTool =& Dataface_ActionTool::getInstance(); 00563 if ( !isset($params['record']) ){ 00564 $params['record'] =& $this->ENV['record']; 00565 } 00566 $actions = $actionTool->getActions($params); 00567 $context = array($varname=>$actions); 00568 $smarty->assign($context); 00569 00570 } 00571 00572 00573 function actions_menu($params, &$smarty){ 00574 00575 $context = array(); 00576 if ( isset( $params['id'] ) ) { 00577 $context['id'] = $params['id']; 00578 unset($params['id']); 00579 } else { 00580 $context['id'] = ''; 00581 } 00582 if ( isset( $params['class'] ) ) { 00583 $context['class'] = $params['class']; 00584 unset($params['class']); 00585 } else { 00586 $context['class'] = ''; 00587 } 00588 00589 if ( isset( $params['id_prefix'] ) ) { 00590 $context['id_prefix'] = $params['id_prefix']; 00591 unset($params['id_prefix']); 00592 } else { 00593 $context['id_prefix'] = ''; 00594 } 00595 00596 if ( isset( $params['selected_action'] ) ) { 00597 $context['selected_action'] = $params['selected_action']; 00598 unset($params['selected_action']); 00599 } else { 00600 $context['selected_action'] = ''; 00601 } 00602 00603 if ( isset( $params['actions'] ) ){ 00604 $addon_actions = & $params['actions']; 00605 } else { 00606 $addon_actions = null; 00607 } 00608 00609 00610 00611 00612 //$params['var'] = 'actions'; 00613 //$this->actions($params, $smarty); 00614 //print_r($ 00615 import( 'Dataface/ActionTool.php'); 00616 $actionTool =& Dataface_ActionTool::getInstance(); 00617 $actions = $actionTool->getActions($params); 00618 if ( $addon_actions !== null ){ 00619 $p2 = $params; 00620 unset($p2['category']); 00621 $actions = array_merge($actions, $actionTool->getActions($p2,$addon_actions)); 00622 usort($actions, array(&$actionTool, '_compareActions')); 00623 } 00624 00625 foreach ($actions as $k=>$a){ 00626 if ( @$a['subcategory'] ){ 00627 $p2 = $params; 00628 $p2['category'] = $a['subcategory']; 00629 $subactions = $actionTool->getActions($p2); 00630 00631 $actions[$k]['subactions'] = $subactions; 00632 00633 } 00634 00635 } 00636 //print_r($actions); 00637 $context['actions'] =& $actions; 00638 //$smarty->assign($context); 00639 if ( isset($params['mincount']) and intval($params['mincount']) > count($context['actions']) ) return; 00640 if ( isset($params['maxcount']) and intval($params['maxcount']) < count($context['actions']) ){ 00641 $more = array( 00642 'name'=>'more', 00643 'label'=> df_translate('actions_menu.more.label', 'More'), 00644 'subactions' => array(), 00645 'description' => df_translate('actions_menu.more.description','More actions...'), 00646 'url'=>'#' 00647 00648 00649 ); 00650 00651 $existing = array(); 00652 00653 $i = 0; 00654 $lastExistingKey = null; 00655 foreach ($actions as $k=>$a){ 00656 $i++; 00657 if ( $i< $params['maxcount'] ){ 00658 $existing[$k] = $a; 00659 $lastExistingKey = $k; 00660 } else { 00661 $more['subactions'][$k] = $a; 00662 00663 } 00664 } 00665 $existing['more'] = $more; 00666 $context['actions'] = $existing; 00667 } 00668 $smarty->display($context, 'Dataface_ActionsMenu.html'); 00669 00670 } 00671 00672 function record_actions($params, &$smarty){ 00673 $params['category'] = 'record_actions'; 00674 return $this->actions_menu($params, $smarty); 00675 } 00676 00677 function record_tabs($params, &$smarty){ 00678 $params['category'] = 'record_tabs'; 00679 if ( is_a($this->ENV['record'], 'Dataface_Record') ){ 00680 $params['record'] =& $this->ENV['record']; 00681 } 00682 $table =& Dataface_Table::loadTable($this->ENV['table']); 00683 $params2 = array(); 00684 00685 $params['actions'] = $table->getRelationshipsAsActions($params2); 00686 return $this->actions_menu($params, $smarty); 00687 00688 } 00689 00690 00691 function summary_list($params, &$smarty){ 00692 import('Dataface/SummaryList.php'); 00693 $sl = new Dataface_SummaryList($params['records']); 00694 return $sl->toHtml(); 00695 } 00696 00697 function glance_list($params, &$smarty){ 00698 import('Dataface/GlanceList.php'); 00699 $gl = new Dataface_GlanceList($params['records']); 00700 return $gl->toHtml(); 00701 } 00702 00703 function sort_controller($params, &$smarty){ 00704 import('Dataface/SortControl.php'); 00705 if ( !isset($params['fields']) ){ 00706 if ( !isset($params['table']) ) $params['table'] = $this->ENV['QUERY']['-table']; 00707 $params['fields'] = $params['table']; 00708 } 00709 00710 $fields = $params['fields']; 00711 if ( isset($params['prefix']) ){ 00712 $params['prefix'] = null; 00713 } 00714 $sc = new Dataface_SortControl($fields, $params['prefix']); 00715 return $sc->toHtml(); 00716 } 00717 00718 00719 function use_macro($params, $content, &$smarty){ 00720 if ( isset( $content ) ){ 00721 00722 $smarty->display($params['file']); 00723 $stack =& $smarty->get_template_vars('__macro_stack__'); 00724 array_pop($stack); 00725 00726 } else { 00727 $vars =& $smarty->get_template_vars(); 00728 if ( !isset($vars['__macro_stack__']) || !is_array($vars['__macro_stack__']) ){ 00729 $stack = array(); 00730 00731 $vars['__macro_stack__'] =& $stack; 00732 } 00733 array_push($vars['__macro_stack__'], array()); 00734 00735 } 00736 00737 } 00738 00739 function editable($params, $content, &$smarty){ 00740 if ( isset($content) ){ 00741 if ( $this->app->_conf['usage_mode'] == 'edit' ){ 00742 return <<<END 00743 <span id="{$params['id']}" class="editable">{$content}</span> 00744 END; 00745 } else { 00746 return $content; 00747 } 00748 00749 } 00750 } 00751 00752 00753 00754 function define_slot($params, $content, &$smarty, &$repeat){ 00755 if ( isset($content) ) { 00756 if ( $repeat) echo "We are repeating $params[name]"; 00757 if ( @$this->app->_conf['debug'] ) $content = '<!-- Begin Slot '.$params['name'].' -->'.$content.'<!-- End Slot '.$params['name'].' -->'; 00758 return $content; 00759 } 00760 00761 // From this point on we can assume we're in the first iteration 00762 $stack =& $smarty->get_template_vars('__macro_stack__'); 00763 $local_vars =& $stack[count($stack)-1]; 00764 foreach ( array_reverse(array_keys($stack) ) as $macroIndex) { 00765 $local_vars =& $stack[$macroIndex]; 00766 if ( isset( $local_vars['__slots__'][$params['name']]) ){ 00767 // we found a slot to display here. 00768 // tell smarty not to execute the inside of this 00769 $repeat=false; // 00770 echo $local_vars['__slots__'][$params['name']]; 00771 //display the slot and return 00772 return; 00773 } 00774 unset($local_vars); 00775 } 00776 if ( isset($params['table']) ) $tname = $params['table']; 00777 else $tname = $this->ENV['table']; 00778 00779 $table =& Dataface_Table::loadTable($tname); 00780 $out = $table->getBlockContent($params['name']); 00781 if ( isset($out) ) { 00782 // We found a block to display here. 00783 $repeat = false; // tell smarty not to execute inside of tag 00784 00785 // Display the block and return 00786 echo $out; 00787 return; 00788 } 00789 00790 00791 } 00792 00793 function fill_slot($params, $content, &$smarty){ 00794 if ( isset($content) ){ 00795 // we are opening the tag 00796 $stack =& $smarty->get_template_vars('__macro_stack__'); 00797 $vars =& $stack[count($stack)-1]; 00798 $vars['__slots__'][$params['name']] = $content; 00799 return ''; 00800 } 00801 00802 } 00803 00804 function translate($params, $content, &$smarty){ 00805 if ( isset($content) ){ 00806 if ( !isset($params['id']) ) return $content; 00807 $id = $params['id']; 00808 unset($params['id']); 00809 return $this->languageTool->translate($id, $content, $params); 00810 } 00811 } 00812 00813 function result_controller($params,&$smarty){ 00814 00815 if ( isset($params['table']) ){ 00816 import('Dataface/ResultController.php'); 00817 $base_url = ( isset($params['base_url']) ? $params['base_url'] : ''); 00818 $query = ( isset($params['query']) ? $params['query'] : array('-table'=>$params['table'])); 00819 $query['-table'] = $params['table']; 00820 $controller = new Dataface_ResultController($params['table'], '', $base_url, $query); 00821 00822 } else { 00823 $controller =& $this->getResultController(); 00824 } 00825 echo $controller->toHtml(); 00826 00827 } 00828 00829 00830 function next_link($params, &$smarty){ 00831 $controller =& $this->getResultController(); 00832 echo $controller->getNextLinkHtml(); 00833 00834 } 00835 00836 function prev_link($params, &$smarty){ 00837 $controller =& $this->getResultController(); 00838 echo $controller->getPrevLinkHtml(); 00839 } 00840 00841 function jump_menu($params,&$smarty){ 00842 $controller =& $this->getResultController(); 00843 echo $controller->jumpMenu(); 00844 } 00845 00846 function limit_field($params, &$smarty){ 00847 $controller =& $this->getResultController(); 00848 echo $controller->limitField(); 00849 } 00850 00851 function result_index($params, &$smarty){ 00852 $controller =& $this->getResultController(); 00853 echo $controller->getPageIndexHtml(); 00854 } 00855 function result_list($params, &$smarty){ 00856 import( 'Dataface/ResultList.php'); 00857 $query =& $this->app->getQuery(); 00858 00859 if ( isset($params['columns']) ){ 00860 $columns = explode(',',$params['columns']); 00861 } else { 00862 $columns = array(); 00863 } 00864 $list = new Dataface_ResultList( $query['-table'], $this->app->db(), $columns, $query); 00865 echo $list->toHtml(); 00866 00867 } 00868 00869 00870 function filters($params, &$smarty){ 00871 import( 'Dataface/ResultList.php'); 00872 $query =& $this->app->getQuery(); 00873 00874 if ( isset($params['columns']) ){ 00875 $columns = explode(',',$params['columns']); 00876 } else { 00877 $columns = array(); 00878 } 00879 $list = new Dataface_ResultList( $query['-table'], $this->app->db(), $columns, $query); 00880 echo $list->getResultFilters(); 00881 } 00882 00883 function records($params, &$smarty){ 00884 $table = null; 00885 if ( isset($params['table']) ){ 00886 $table = $params['table']; 00887 unset($params['table']); 00888 } 00889 00890 if ( isset($params['var']) ){ 00891 $varname = $params['var']; 00892 unset($params['var']); 00893 } else { 00894 throw new Exception("{records} tag requires the var parameter to be set."); 00895 } 00896 00897 $q = array_merge($this->app->getQuery(), $params); 00898 if ( isset($table) ) $q['-table'] = $table; 00899 $vars =& $smarty->get_template_vars(); 00900 $vars[$varname] = df_get_records_array($q['-table'], $q); 00901 } 00902 00903 function related_list($params, &$smarty){ 00904 import('Dataface/RelatedList.php'); 00905 $query =& $this->app->getQuery(); 00906 if ( isset($params['record']) ) $record =& $params['record']; 00907 else $record =& $this->ENV['resultSet']->loadCurrent(); 00908 00909 if ( !$record ) { 00910 throw new Exception('No record found from which to form related list.', E_USER_ERROR); 00911 } 00912 00913 if ( isset($params['relationship']) ){ 00914 $relationship = $params['relationship']; 00915 } else if ( isset($query['-relationship']) ){ 00916 $relationship = $query['-relationship']; 00917 } else { 00918 throw new Exception('No relationship specified for related list.', E_USER_ERROR); 00919 } 00920 00921 $relatedList = new Dataface_RelatedList($record, $relationship); 00922 echo $relatedList->toHtml(); 00923 } 00924 00925 function bread_crumbs($params, &$smarty){ 00926 $base = null; 00927 if ( $this->app->_query['-mode'] === 'browse' and $this->app->_query['-action'] != 'new'){ 00928 $record =& $this->app->getRecord(); 00929 $base = ''; 00930 if ( $record ){ 00931 foreach ( $record->getBreadCrumbs() as $label=>$url){ 00932 $base .= ' :: <a href="'.$url.'" id="bread-crumbs-'.str_replace(' ','_', $label).'">'.$label.'</a>'; 00933 } 00934 } 00935 $base = substr($base, 4); 00936 00937 } 00938 00939 $del = Dataface_Application::getInstance()->getDelegate(); 00940 if ( !$base and $del and method_exists($del, 'getBreadCrumbs') ){ 00941 $bc = $del->getBreadCrumbs(); 00942 if ($bc ){ 00943 $base = ''; 00944 00945 foreach ( $bc as $label=>$url){ 00946 $base .= ' :: <a href="'.$url.'" id="bread-crumbs-'.str_replace(' ','_', $label).'">'.$label.'</a>'; 00947 } 00948 } 00949 } 00950 if ( !$base ){ 00951 $table =& Dataface_Table::loadTable($this->ENV['table']); 00952 $base = $table->getLabel(); 00953 } 00954 00955 00956 00957 $action =& $this->app->getAction(); 00958 if ( PEAR::isError($action) ){ 00959 return ''; 00960 } 00961 $base .= ' :: '.Dataface_LanguageTool::translate( 00962 $action['label_i18n'], 00963 $action['label']); 00964 return "<b>".df_translate('scripts.Dataface_SkinTool.LABEL_BREADCRUMB', "You are here").":</b> ".$base; 00965 } 00966 00967 function search_form($params, &$smarty){ 00968 $query =& $this->app->getQuery(); 00969 $table = isset($params['table']) ? $params['table'] : $query['-table']; 00970 $form =& df_create_search_form($table, $query); 00971 ob_start(); 00972 $form->display(); 00973 $out = ob_get_contents(); 00974 ob_end_clean(); 00975 return $out; 00976 00977 } 00978 00990 function if_allowed($params, $content, &$smarty){ 00991 if ( isset( $content ) ){ 00992 if ( !isset( $params['permission'] ) ){ 00993 throw new Exception('Missing permission parameter in if_allowed tag.', E_USER_ERROR); 00994 } 00995 if ( isset( $params['record']) ) { 00996 $allowed = $params['record']->checkPermission($params['permission'],$params); 00997 } else if ( isset($params['table']) ){ 00998 $table =& Dataface_Table::loadTable($params['table']); 00999 01000 $perms = $table->getPermissions($params); 01001 $allowed = @$perms[$params['permission']]; 01002 } else { 01003 $perms = Dataface_Application::getInstance()->getPermissions(); 01004 if ( @$perms[$params['permission']] ) $allowed = true; 01005 else $allowed = false; 01006 } 01007 if ( $allowed ) return $content; 01008 return ''; 01009 } 01010 } 01011 01012 function language_selector($params, &$smarty){ 01013 $languageTool =& Dataface_LanguageTool::getInstance(); 01014 echo $languageTool->getLanguageSelectorHtml($params); 01015 } 01016 01017 function block($params, &$smarty){ 01018 ob_start(); 01019 df_block($params); 01020 $out = ob_get_contents(); 01021 ob_end_clean(); 01022 return $out; 01023 01024 } 01025 01026 function feed($params, &$smarty){ 01027 if ( isset($params['query']) ) parse_str($params['query'], $query); 01028 else $query = array(); 01029 unset($params['query']); 01030 01031 if ( isset($params['table']) ){ 01032 $query['-table'] = $params['table']; 01033 unset($params['table']); 01034 } 01035 01036 if ( isset($params['relationship']) ){ 01037 $query['-relationship'] = $params['relationship']; 01038 unset($params['relationship']); 01039 } 01040 01041 if ( isset($params['format']) ){ 01042 $query['--format'] = $params['format']; 01043 unset($params['format']); 01044 } 01045 01046 if ( isset($params['url']) ){ 01047 $url = $params['url']; 01048 } else { 01049 $url = DATAFACE_SITE_HREF; 01050 } 01051 01052 if ( isset($params['size']) and $params['size'] == 'large' ){ 01053 $icon = 'feed-icon-28x28.png'; 01054 } else { 01055 $icon = 'feed-icon-14x14.png'; 01056 } 01057 01058 $query['-action'] = 'feed'; 01059 $app =& Dataface_Application::getInstance(); 01060 $appq = $app->url($query); 01061 $url = $url .'?'.substr( $appq, strpos($appq,'?')+1); 01062 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>'; 01063 } 01064 01065 function abs($params, $url, &$smarty){ 01066 return df_absolute_url($url); 01067 } 01068 01069 01070 01071 01072 01073 01074 01075 }