00001 <?php
00010 class tpHtml extends Plugin
00011 {
00012 var $guid = 1;
00013
00017 function tpHtml() {
00018 $this->Plugin();
00019 }
00020
00027 function head($key, $val) {
00028 $this->web->queue_html_head($key, $val);
00029 }
00030
00042 function js_run($key, $code, $overwrite=true) {
00043 $this->web->queue_js_run($key, $code, $overwrite);
00044 }
00045
00055 function js_load($key, $path='') {
00056 if($path == '') $path = $key;
00057
00058 if(strpos($path, '://') === false && substr($path, 0, 1) != '/') {
00059 $path = $this->url('/js/'.$path.'.js', true);
00060 }
00061 $this->web->queue_js_load($key, $path);
00062 }
00063
00073 function css_load($key, $path='') {
00074 if($path == '') $path = $key;
00075
00076 if(strpos($path, '://') === false && substr($path, 0, 1) != '/') {
00077 $path = $this->url('/css.php?c='.$path, true);
00078 }
00079 $this->web->queue_css_load($key, $path);
00080 }
00081
00089 function css($path)
00090 {
00091
00092 if(strpos($path, '://') === false && substr($path, 0, 1) != '/') {
00093 $path = $this->url('/css.php?c='.$path, true);
00094 }
00095 return '<link rel="stylesheet" type="text/css" href="'.$path.'" />'."\n";
00096 }
00097
00105 function js($path)
00106 {
00107
00108 if(strpos($path, '://') === false && substr($path, 0, 1) != '/') {
00109 $path = $this->url('/js/'.$path.'.js', true);
00110 }
00111 return '<script type="text/javascript" src="'.$path.'"></script>'."\n";
00112 }
00113
00121 function favicon($path)
00122 {
00123
00124 if(strpos($path, '://') === false && substr($path, 0, 1) != '/') {
00125 $path = $this->url('/img/'.$path.'.ico', true);
00126 }
00127 return '<link rel="shortcut icon" href="'.$path.'" type="image/x-icon" />'."\n";
00128 }
00129
00137 function rss_feed($url, $title)
00138 {
00139
00140 if(strpos($path, '://') === false && substr($path, 0, 1) != '/') {
00141 $url = $this->full_url($url, true);
00142 }
00143 return '<link rel="alternate" type="application/rss+xml" title="'.$title.'" href="'.$url.'" />'."\n";
00144 }
00145
00155 function image($path, $alt='', $attribs=array())
00156 {
00157
00158 if(is_array($alt)) {
00159 $attribs = $alt;
00160 $alt = '';
00161 }
00162
00163 if(strpos($path, '://') === false && substr($path, 0, 1) != '/') {
00164 $path = $this->url('/img/'.$path, true);
00165 }
00166 $ret = '<img src="'.$path.'" alt="'.$alt.'" border="0"';
00167 $ret .= $this->_attribs($attribs);
00168 return $ret.' />';
00169 }
00170
00181 function url($url, $static=false)
00182 {
00183 return url($url, $static);
00184 }
00185
00196 function full_url($url, $static=false)
00197 {
00198 return absolute_url($url, $static);
00199 }
00200
00210 function composite_url($args, $base_url='')
00211 {
00212 if(!is_array($args)) {
00213
00214 $t = $args;
00215 $args = $base_url;
00216 $base_url = $t;
00217 }
00218
00219 if(empty($base_url)) $base_url = $_SERVER['REQUEST_URI'];
00220
00221
00222 $parts = parse_url($base_url);
00223 $query = array();
00224 foreach(explode('&', $parts['query']) as $q) {
00225 $p = explode('=', $q);
00226 $query[$p[0]] = $p[1];
00227 }
00228
00229
00230 foreach($args as $k=>$v) $query[$k] = $v;
00231
00232
00233 $final = $parts['path'].'?';
00234 foreach($query as $k=>$v) $final .= "$k=$v&";
00235
00236 $final = substr($final, 0, -1);
00237
00238 return $final;
00239 }
00240
00253 function link($text, $url, $confirm='', $popup=false, $attribs=array())
00254 {
00255 if($popup) {
00256 $ret = '<a href="'.$this->_popup_href($popup, $url).'"';
00257 } else {
00258 $ret = '<a href="'.$url.'"';
00259 }
00260 if($confirm) {
00261 $confirm = str_replace("'", "\\'", $confirm);
00262 $ret .= ' onClick="if(!confirm(\''.$confirm.'\')){event.cancelBubble=true;return false;};"';
00263 }
00264 $ret .= $this->_attribs($attribs);
00265 $ret .= '>'.$text.'</a>';
00266 return $ret;
00267 }
00268
00282 function link_button($text, $url, $icon='', $confirm='', $popup=false, $attribs=array())
00283 {
00284 if($popup) {
00285 $lnk = '<a href="'.$this->_popup_href($popup, $url).'"';
00286 } else {
00287 $lnk = '<a href="'.$url.'"';
00288 }
00289 if($confirm) {
00290 $lnk .= ' onClick="return confirm(\''.$confirm.'\')"';
00291 }
00292 $lnk .= '>';
00293 $ret = '<div class="link_button"';
00294 $ret .= $this->_attribs($attribs);
00295 $ret .= ">$lnk";
00296 if($icon) {
00297 $ret .= $this->image($icon, array('align'=>'bottom'));
00298 $ret .= "<span>$text</span></a></div>";
00299 } else {
00300 $ret .= "<span style=\"width:100%\">$text</span></a></div>";
00301 }
00302 return $ret;
00303 }
00304
00317 function button($text, $url='', $confirm='', $popup=false, $formname='', $attribs=array())
00318 {
00319 $onclick = '';
00320 if($confirm) {
00321 $onclick .= 'if(confirm(\''.$confirm.'\')) {';
00322 }
00323 if($popup) {
00324 $onclick .= "a=window.open('".$url."','newWin',";
00325 $onclick .= "'toolbar=no,location=no,directories=no,status=yes,menubar=no,";
00326 $onclick .= "resizable=yes,copyhistory=no,scrollbars=yes,width=640,height=480');";
00327 $onclick .= "a.focus();";
00328 } else if($url) {
00329 if($formname) {
00330 $onclick .= "document.forms.$formname.action='".$url."';document.forms.$formname.submit();";
00331 } else {
00332 $onclick .= "location.href='".$url."';";
00333 }
00334 }
00335 if($confirm) {
00336 $onclick .= "}";
00337 }
00338
00339 $ret = "<input type=\"button\" class=\"submit\" value=\"$text\"";
00340 if(!empty($onclick)) $ret .= " onClick=\"$onclick\"";
00341 $ret .= $this->_attribs($attribs);
00342 $ret .= " />";
00343 return $ret;
00344 }
00345
00360 function tabs($tabs)
00361 {
00362 $guid = ++$this->guid;
00363
00364 $this->css_load('tabs');
00365 $this->js_load('jq/jquery.tabs');
00366
00367 $out = '<div id="tab_container'.$guid.'">';
00368 $out .= '<ul>';
00369 foreach($tabs as $tabid=>$tab) {
00370 $active = $tab['active'] ? ' class="tabs-selected"' : '';
00371 $out .= '<li'.$active.'><a href="#'.$tabid.'">'.$tab['label'].'</a></li>';
00372 }
00373 $out .= '</ul>';
00374
00375 foreach($tabs as $tabid=>$tab) {
00376 $out .= '<div id="'.$tabid.'" style="background:#fff;">';
00377 $out .= '<div class="clearfix">';
00378 $out .= $tab['content'];
00379 $out .= '</div></div>';
00380 }
00381 $out .= '</div>';
00382
00383 $this->js_run('', "$('#tab_container{$guid}').tabs();");
00384 return $out;
00385 }
00386
00387 /*
00388 * Generate the necessary javascript to open a link in a new popup window.
00389 */
00390 function _popup_href($popup, $url)
00391 {
00392 if($popup === true) {
00393 $x = 640;
00394 $y = 480;
00395 } else {
00396 $dims = explode('x', $popup);
00397 $x = $dims[0];
00398 $y = $dims[1];
00399 }
00400 $lnk = "javascript:a=window.open('".$url."','newWin',";
00401 $lnk .= "'toolbar=no,location=no,directories=no,status=yes,menubar=no,";
00402 $lnk .= "resizable=yes,copyhistory=no,scrollbars=yes,width=$x,height=$y');";
00403 $lnk .= "a.focus();";
00404 return $lnk;
00405 }
00406
00407 function _attribs($attribs)
00408 {
00409 $ret = '';
00410 foreach($attribs as $k=>$v) {
00411 $ret .= " $k=\"$v\"";
00412 }
00413 return $ret;
00414 }
00415
00416 }
00417
00418 ?>