diff options
Diffstat (limited to '')
-rw-r--r-- | include/calendar_base.class.php | 8 | ||||
-rw-r--r-- | include/calendar_monthly.class.php | 13 | ||||
-rw-r--r-- | include/category_default.inc.php | 2 | ||||
-rw-r--r-- | include/category_recent_cats.inc.php | 8 | ||||
-rw-r--r-- | include/common.inc.php | 2 | ||||
-rw-r--r-- | include/functions.inc.php | 10 | ||||
-rw-r--r-- | include/functions_category.inc.php | 6 | ||||
-rw-r--r-- | include/functions_html.inc.php | 25 | ||||
-rw-r--r-- | include/functions_rate.inc.php | 140 | ||||
-rw-r--r-- | include/functions_session.inc.php | 19 | ||||
-rw-r--r-- | include/page_tail.php | 27 | ||||
-rw-r--r-- | include/picture_metadata.inc.php | 12 | ||||
-rw-r--r-- | include/picture_rate.inc.php | 10 | ||||
-rw-r--r-- | include/section_init.inc.php | 63 | ||||
-rw-r--r-- | include/template.php | 119 |
15 files changed, 263 insertions, 201 deletions
diff --git a/include/calendar_base.class.php b/include/calendar_base.class.php index 5d358f4ad..ee17c1ac7 100644 --- a/include/calendar_base.class.php +++ b/include/calendar_base.class.php @@ -261,8 +261,14 @@ SELECT DISTINCT('.$this->calendar_levels[$level]['sql'] } } + $dates = $page['chronology_date']; + while ($level<count($dates)) + { + array_pop($dates); + } + $nav_bar = $this->get_nav_bar_from_items( - $page['chronology_date'], + $dates, $level_items, null, 'calItem', diff --git a/include/calendar_monthly.class.php b/include/calendar_monthly.class.php index 0d70ea4c6..1f26e1275 100644 --- a/include/calendar_monthly.class.php +++ b/include/calendar_monthly.class.php @@ -224,7 +224,7 @@ function build_global_calendar() $query.= $this->get_date_where(); $query.= ' GROUP BY period - ORDER BY YEAR('.$this->date_field.') DESC'; + ORDER BY YEAR('.$this->date_field.') DESC, MONTH('.$this->date_field.')'; $result = pwg_query($query); $items=array(); @@ -350,7 +350,9 @@ SELECT file,tn_ext,path, width, height, DAYOFWEEK('.$this->date_field.')-1 as do $row = mysql_fetch_array(pwg_query($query)); $items[$day]['tn_path'] = get_thumbnail_src($row['path'], @$row['tn_ext']); - $items[$day]['tn_file'] = $row['file']; + $items[$day]['file'] = $row['file']; + $items[$day]['path'] = $row['path']; + $items[$day]['tn_ext'] = @$row['tn_ext']; $items[$day]['width'] = $row['width']; $items[$day]['height'] = $row['height']; $items[$day]['dow'] = $row['dow']; @@ -445,7 +447,10 @@ SELECT file,tn_ext,path, width, height, DAYOFWEEK('.$this->date_field.')-1 as do } else {// item not an image (tn is either mime type or an image) - $tn_size = @getimagesize($items[$day]['tn_path']); + $thumb = get_thumbnail_src( + $items[$day]['path'], @$items[$day]['tn_ext'], false + ); + $tn_size = @getimagesize($thumb); } $tn_width = $tn_size[0]; $tn_height = $tn_size[1]; @@ -548,7 +553,7 @@ SELECT file,tn_ext,path, width, height, DAYOFWEEK('.$this->date_field.')-1 as do 'thumbnails.line.thumbnail', array( 'IMAGE'=>$data['tn_path'], - 'IMAGE_ALT'=>$data['tn_file'], + 'IMAGE_ALT'=>$data['file'], 'IMAGE_TITLE'=>$thumbnail_title, 'U_IMG_LINK'=>$url ) diff --git a/include/category_default.inc.php b/include/category_default.inc.php index e7c4b8ddc..47f8fcd27 100644 --- a/include/category_default.inc.php +++ b/include/category_default.inc.php @@ -126,7 +126,7 @@ foreach ($pictures as $row) } case 'search' : { - $name = replace_search($name, $_GET['search']); + $name = replace_search($name, $page['search']); break; } } diff --git a/include/category_recent_cats.inc.php b/include/category_recent_cats.inc.php index 2bc028ced..a0510db25 100644 --- a/include/category_recent_cats.inc.php +++ b/include/category_recent_cats.inc.php @@ -28,7 +28,7 @@ /** * This file is included by the main page to show thumbnails for recent_cats * category - * + * */ // retrieving categories recently update, ie containing pictures added @@ -71,7 +71,7 @@ while ( $row = mysql_fetch_array( $result ) ) 'IMAGE' => get_thumbnail_src($row['path'], @$row['tn_ext']), 'IMAGE_ALT' => $row['file'], 'IMAGE_TITLE' => $lang['hint_category'], - + 'U_IMG_LINK' => make_index_url( array( 'category' => $row['category_id'], @@ -83,10 +83,10 @@ while ( $row = mysql_fetch_array( $result ) ) $template->assign_block_vars( 'thumbnails.line.thumbnail.category_name', array( - 'NAME' => get_cat_display_name_cache($row['uppercats'], '', false), + 'NAME' => get_cat_display_name_cache($row['uppercats'], null, false), ) ); - + // create a new line ? if (++$row_number == $user['nb_image_line']) { diff --git a/include/common.inc.php b/include/common.inc.php index 27949fd17..2b7757819 100644 --- a/include/common.inc.php +++ b/include/common.inc.php @@ -61,7 +61,7 @@ if( !get_magic_quotes_gpc() ) } @reset($_GET); } - + if( is_array($_POST) ) { while( list($k, $v) = each($_POST) ) diff --git a/include/functions.inc.php b/include/functions.inc.php index 68ba765fe..eb27ce51d 100644 --- a/include/functions.inc.php +++ b/include/functions.inc.php @@ -202,7 +202,7 @@ function get_dirs($directory) and $file != '..' and is_dir($directory.'/'.$file) and $file != 'CVS' - and $file != '.svn') + and $file != '.svn') { array_push($sub_dirs, $file); } @@ -356,7 +356,7 @@ function pwg_log( $file, $category, $picture = '' ) if ($conf['log']) { if ( ($conf['history_admin'] ) or ( (! $conf['history_admin']) and (!is_admin()) ) ) - { + { $login = ($user['id'] == $conf['guest_id']) ? 'guest' : addslashes($user['username']); @@ -1141,11 +1141,13 @@ function make_picture_URL($params) $url = get_root_url().'picture.php?' - .'/'.$params['image_id'] .'/'.make_section_in_URL($params) ; - $url = add_well_known_params_in_url($url, $params); + $url.= '/'. + $params['image_id']//.'-'. + //get_filename_wo_extension($params['image_file']).'.htm' + ; return $url; } diff --git a/include/functions_category.inc.php b/include/functions_category.inc.php index 21560454d..601ec1b64 100644 --- a/include/functions_category.inc.php +++ b/include/functions_category.inc.php @@ -47,9 +47,9 @@ function check_restrictions($category_id) if (in_array($category_id, explode(',', $user['forbidden_categories']))) { $login_url = - './identification.php?redirect=' + get_root_url().'identification.php?redirect=' .urlencode(urlencode($_SERVER['REQUEST_URI'])); - + if (!$user['is_the_guest']) { die('Fatal: you are trying to reach a forbidden category'); @@ -278,7 +278,7 @@ function display_select_categories($categories, if ($fullname) { $option = get_cat_display_name_cache($category['uppercats'], - '', + null, false); } else diff --git a/include/functions_html.inc.php b/include/functions_html.inc.php index 8cd69b5ba..37f4d8a59 100644 --- a/include/functions_html.inc.php +++ b/include/functions_html.inc.php @@ -66,6 +66,7 @@ function get_icon($date) $title .= $user['recent_period']; $title .= ' '.$lang['days']; $size = getimagesize( $icon_url ); + $icon_url = get_root_url().$icon_url; $output = '<img title="'.$title.'" src="'.$icon_url.'" class="icon" style="border:0;'; $output.= 'height:'.$size[1].'px;width:'.$size[0].'px" alt="(!)" />'; } @@ -244,7 +245,7 @@ function language_select($default, $select_name = "language") * * categories string returned contains categories as given in the input * array $cat_informations. $cat_informations array must be an association - * of {category_id => category_name}. If url input parameter is empty, + * of {category_id => category_name}. If url input parameter is null, * returns only the categories name without links. * * @param array cat_informations @@ -253,7 +254,7 @@ function language_select($default, $select_name = "language") * @return string */ function get_cat_display_name($cat_informations, - $url = 'category.php?/category/', + $url = '', $replace_space = true) { global $conf; @@ -271,10 +272,16 @@ function get_cat_display_name($cat_informations, $output.= $conf['level_separator']; } - if ($url == '') + if ( !isset($url) ) { $output.= $name; } + elseif ($url == '') + { + $output.= '<a class=""'; + $output.= ' href="'.make_index_url( array('category'=>$id) ).'">'; + $output.= $name.'</a>'; + } else { $output.= '<a class=""'; @@ -306,7 +313,7 @@ function get_cat_display_name($cat_informations, * @return string */ function get_cat_display_name_cache($uppercats, - $url = 'category.php?/category/', + $url = '', $replace_space = true) { global $cat_names, $conf; @@ -339,10 +346,16 @@ SELECT id,name $output.= $conf['level_separator']; } - if ($url == '') + if ( !isset($url) ) { $output.= $name; } + elseif ($url == '') + { + $output.= ' +<a class="" + href="'.make_index_url( array('category'=>$category_id) ).'">'.$name.'</a>'; + } else { $output.= ' @@ -474,7 +487,7 @@ function parse_comment_content($content) } function get_cat_display_name_from_id($cat_id, - $url = 'category.php?/category/', + $url = '', $replace_space = true) { $cat_info = get_cat_info($cat_id); diff --git a/include/functions_rate.inc.php b/include/functions_rate.inc.php index 6eef19af6..32722118f 100644 --- a/include/functions_rate.inc.php +++ b/include/functions_rate.inc.php @@ -6,10 +6,9 @@ // +-----------------------------------------------------------------------+ // | branch : BSF (Best So Far) // | file : $RCSfile$ -// | last update : $Date: 2006-03-15 03:26:25 +0100 (mer, 15 mar 2006) $ -// | last modifier : $Author: rvelices $ -// | revision : $Revision: 1081 $ -// | revision : $Revision: 1081 $ +// | last update : $Date$ +// | last modifier : $Author$ +// | revision : $Revision$ // +-----------------------------------------------------------------------+ // | This program is free software; you can redistribute it and/or modify | // | it under the terms of the GNU General Public License as published by | @@ -29,137 +28,126 @@ /** * rate a picture by a user * - * @param int user identifier * @param int image identifier * @param int rate * @return void */ -function rate_picture($user_id, $image_id, $rate) +function rate_picture($image_id, $rate) { - global $conf; + global $conf, $user; - $query = ' -SELECT status - FROM '.USER_INFOS_TABLE.' - WHERE user_id = '.$user_id.' -;'; - list($user_status) = mysql_fetch_array(pwg_query($query)); - - if ('guest' == $user_status - or 'generic' == $user_status) + if (!isset($rate) + or !$conf['rate'] + or !in_array($rate, $conf['rate_items'])) { - $user_anonymous = true; + return; } - else + + $user_anonymous = is_autorize_status(ACCESS_CLASSIC) ? false : true; + + if ($user_anonymous and !$conf['rate_anonymous']) { - $user_anonymous = false; + return; } - - if (isset($rate) - and $conf['rate'] - and (!$user_anonymous or $conf['rate_anonymous']) - and in_array($rate, $conf['rate_items'])) + + if ($user_anonymous) { - if ($user_anonymous) + $ip_components = explode('.', $_SERVER["REMOTE_ADDR"]); + if (count($ip_components) > 3) { - $ip_components = explode('.', $_SERVER["REMOTE_ADDR"]); - if (count($ip_components) > 3) - { - array_pop($ip_components); - } - $anonymous_id = implode ('.', $ip_components); - - if (isset($_COOKIE['pwg_anonymous_rater'])) - { - if ($anonymous_id != $_COOKIE['pwg_anonymous_rater']) - { // client has changed his IP adress or he's trying to fool us - $query = ' + array_pop($ip_components); + } + $anonymous_id = implode ('.', $ip_components); + + if (isset($_COOKIE['pwg_anonymous_rater'])) + { + if ($anonymous_id != $_COOKIE['pwg_anonymous_rater']) + { // client has changed his IP adress or he's trying to fool us + $query = ' SELECT element_id FROM '.RATE_TABLE.' WHERE user_id = '.$user['id'].' AND anonymous_id = \''.$anonymous_id.'\' ;'; - $already_there = array_from_query($query, 'element_id'); - - if (count($already_there) > 0) - { - $query = ' + $already_there = array_from_query($query, 'element_id'); + + if (count($already_there) > 0) + { + $query = ' DELETE FROM '.RATE_TABLE.' WHERE user_id = '.$user['id'].' AND anonymous_id = \''.$_COOKIE['pwg_anonymous_rater'].'\' AND element_id NOT IN ('.implode(',', $already_there).') ;'; - pwg_query($query); - } + pwg_query($query); + } - $query = ' + $query = ' UPDATE '.RATE_TABLE.' SET anonymous_id = \'' .$anonymous_id.'\' WHERE user_id = '.$user['id'].' AND anonymous_id = \'' . $_COOKIE['pwg_anonymous_rater'].'\' ;'; - pwg_query($query); + pwg_query($query); - setcookie( + setcookie( 'pwg_anonymous_rater', $anonymous_id, strtotime('+10 years'), cookie_path() - ); - } - } - else - { - setcookie( + ); + } // end client changed ip + } // end client has cookie + else + { + setcookie( 'pwg_anonymous_rater', $anonymous_id, strtotime('+10 years'), cookie_path() ); - } } - - $query = ' + } // end anonymous user + $query = ' DELETE FROM '.RATE_TABLE.' WHERE element_id = '.$image_id.' - AND user_id = '.$user_id.' + AND user_id = '.$user['id'].' '; - if (isset($anonymous_id)) - { - $query.= ' AND anonymous_id = \''.$anonymous_id.'\''; - } - pwg_query($query); - $query = ' + if (isset($anonymous_id)) + { + $query.= ' AND anonymous_id = \''.$anonymous_id.'\''; + } + pwg_query($query); + $query = ' INSERT INTO '.RATE_TABLE.' (user_id,anonymous_id,element_id,rate,date) VALUES (' - .$user_id.',' - .(isset($anonymous_id) ? '\''.$anonymous_id.'\'' : "''").',' - .$image_id.',' - .$rate - .',NOW()) + .$user['id'].',' + .(isset($anonymous_id) ? '\''.$anonymous_id.'\'' : "''").',' + .$image_id.',' + .$rate + .',NOW()) ;'; - pwg_query($query); - - // update of images.average_rate field - $query = ' + pwg_query($query); + + // update of images.average_rate field + $query = ' SELECT ROUND(AVG(rate),2) AS average_rate FROM '.RATE_TABLE.' WHERE element_id = '.$image_id.' ;'; - $row = mysql_fetch_array(pwg_query($query)); - $query = ' + $row = mysql_fetch_array(pwg_query($query)); + $query = ' UPDATE '.IMAGES_TABLE.' SET average_rate = '.$row['average_rate'].' WHERE id = '.$image_id.' ;'; - pwg_query($query); - } + pwg_query($query); } ?>
\ No newline at end of file diff --git a/include/functions_session.inc.php b/include/functions_session.inc.php index 9e1e3f152..482c76376 100644 --- a/include/functions_session.inc.php +++ b/include/functions_session.inc.php @@ -81,11 +81,26 @@ function cookie_path() if ( isset($_SERVER['REDIRECT_URL']) ) { // mod_rewrite is activated for upper level directories. we must set the // cookie to the path shown in the browser otherwise it will be discarded. - $scr = $_SERVER['REDIRECT_URL']; + if ( isset($_SERVER['PATH_INFO']) ) + { + $idx = strpos( $_SERVER['REDIRECT_URL'], $_SERVER['PATH_INFO'] ); + if ($idx !== false) + { + $scr = substr($_SERVER['REDIRECT_URL'], 0, $idx); + } + else + {//this should never happen + $scr='//'; + } + } + else + { + $scr = $_SERVER['REDIRECT_URL']; + } } else { - $scr = $_SERVER['PHP_SELF']; + $scr = $_SERVER['SCRIPT_NAME']; } return substr($scr,0,strrpos( $scr,'/')); } diff --git a/include/page_tail.php b/include/page_tail.php index 88c813e24..50b433f9e 100644 --- a/include/page_tail.php +++ b/include/page_tail.php @@ -29,12 +29,8 @@ $template->set_filenames(array('tail'=>'footer.tpl')); $template->assign_vars( array( 'VERSION' => $conf['show_version'] ? PHPWG_VERSION : '', - - 'L_GEN_TIME' => $lang['generation_time'], - 'L_SQL_QUERIES_IN' => $lang['sql_queries_in'], - 'L_SEND_MAIL' => $lang['send_mail'], + 'L_TITLE_MAIL' => urlencode($lang['title_send_mail']), - 'L_POWERED_BY'=>$lang['powered_by'] )); //--------------------------------------------------------------------- contact @@ -50,6 +46,7 @@ if (!$user['is_the_guest']) } //------------------------------------------------------------- generation time +$debug_vars = array(); if ($conf['show_gt']) { $time = get_elapsed_time($t2, get_moment()); @@ -59,20 +56,22 @@ if ($conf['show_gt']) $page['count_queries'] = 0; $page['queries_time'] = 0; } - - $template->assign_block_vars( - 'debug', + + $debug_vars = array_merge($debug_vars, array('TIME' => $time, 'NB_QUERIES' => $page['count_queries'], - 'SQL_TIME' => number_format($page['queries_time'],3,'.',' ').' s')); + 'SQL_TIME' => number_format($page['queries_time'],3,'.',' ').' s') + ); } -if ($conf['show_queries']) +if ($conf['show_queries']) { - $template->assign_block_vars( - 'debug', - array('QUERIES_LIST' => $debug) - ); + $debug_vars = array_merge($debug_vars, array('QUERIES_LIST' => $debug) ); +} + +if ( !empty($debug_vars) ) +{ + $template->assign_block_vars('debug',$debug_vars ); } // diff --git a/include/picture_metadata.inc.php b/include/picture_metadata.inc.php index de910ad07..508ed3a67 100644 --- a/include/picture_metadata.inc.php +++ b/include/picture_metadata.inc.php @@ -6,9 +6,9 @@ // +-----------------------------------------------------------------------+ // | branch : BSF (Best So Far) // | file : $RCSfile$ -// | last update : $Date: 2006-03-09 00:14:53 +0100 (jeu, 09 mar 2006) $ -// | last modifier : $Author: rub $ -// | revision : $Revision: 1070 $ +// | last update : $Date$ +// | last modifier : $Author$ +// | revision : $Revision$ // +-----------------------------------------------------------------------+ // | This program is free software; you can redistribute it and/or modify | // | it under the terms of the GNU General Public License as published by | @@ -27,10 +27,10 @@ /** * This file is included by the picture page to manage picture metadata - * + * */ -if ($metadata_showable and isset($_GET['show_metadata'])) +if ($metadata_showable and isset($_GET['metadata'])) { include_once(PHPWG_ROOT_PATH.'/include/functions_metadata.inc.php'); $template->assign_block_vars('metadata', array()); @@ -41,7 +41,7 @@ if ($metadata_showable and isset($_GET['show_metadata'])) die('Exif extension not available, admin should disable exif display'); } - if ($exif = @read_exif_data($picture['current']['src'])) + if ($exif = @read_exif_data($picture['current']['src_file_system'])) { $template->assign_block_vars( 'metadata.headline', diff --git a/include/picture_rate.inc.php b/include/picture_rate.inc.php index e994b3e44..86c2486ac 100644 --- a/include/picture_rate.inc.php +++ b/include/picture_rate.inc.php @@ -6,9 +6,9 @@ // +-----------------------------------------------------------------------+ // | branch : BSF (Best So Far) // | file : $RCSfile$ -// | last update : $Date: 2006-03-09 00:14:53 +0100 (jeu, 09 mar 2006) $ -// | last modifier : $Author: rub $ -// | revision : $Revision: 1070 $ +// | last update : $Date$ +// | last modifier : $Author$ +// | revision : $Revision$ // +-----------------------------------------------------------------------+ // | This program is free software; you can redistribute it and/or modify | // | it under the terms of the GNU General Public License as published by | @@ -54,7 +54,7 @@ SELECT COUNT(rate) AS count ); } - if ($conf['rate_anonymous'] or !$user['is_the_guest']) + if ($conf['rate_anonymous'] or is_autorize_status(ACCESS_CLASSIC) ) { if ($row['count']>0) { @@ -63,7 +63,7 @@ SELECT COUNT(rate) AS count WHERE element_id = '.$page['image_id'] . ' AND user_id = '.$user['id'] ; - if ($user['is_the_guest']) + if ( !is_autorize_status(ACCESS_CLASSIC) ) { $ip_components = explode('.', $_SERVER['REMOTE_ADDR']); if ( count($ip_components)>3 ) diff --git a/include/section_init.inc.php b/include/section_init.inc.php index d225e7871..80f853d17 100644 --- a/include/section_init.inc.php +++ b/include/section_init.inc.php @@ -6,9 +6,9 @@ // +-----------------------------------------------------------------------+ // | branch : BSF (Best So Far) // | file : $RCSfile$ -// | last update : $Date: 2006-01-27 02:11:43 +0100 (ven, 27 jan 2006) $ -// | last modifier : $Author: rvelices $ -// | revision : $Revision: 1014 $ +// | last update : $Date$ +// | last modifier : $Author$ +// | revision : $Revision$ // +-----------------------------------------------------------------------+ // | This program is free software; you can redistribute it and/or modify | // | it under the terms of the GNU General Public License as published by | @@ -84,17 +84,35 @@ $tokens = explode( $next_token = 0; if (basename($_SERVER['SCRIPT_NAME']) == 'picture.php') -{ - - // the first token must be the numeric identifier of the picture - preg_match('/(\d+)/', $tokens[$next_token], $matches); - if (!isset($matches[1])) +{ // the last token must be the identifier for the picture + $token = array_pop($tokens); + if ( is_numeric($token) ) { - die('Fatal: picture identifier is missing'); + $page['image_id'] = $token; + } + else + { + preg_match('/^(\d+-)?((.*)[_\.]html?)?$/', $token, $matches); + if ( isset($matches[1]) and is_numeric($matches[1]) ) + { + $page['image_id'] = $matches[1]; + if ( !empty($matches[3]) ) + { + $page['image_file'] = $matches[3]; + } + } + else + { + if ( !empty($matches[3]) ) + { + $page['image_file'] = $matches[3]; + } + else + { + die('Fatal: picture identifier is missing'); + } + } } - $page['image_id'] = $matches[1]; - - $next_token++; } if (0 === strpos($tokens[$next_token], 'cat')) @@ -273,11 +291,11 @@ if ('categories' == $page['section']) 'cat_id_uppercat' => $result['id_uppercat'], 'uppercats' => $result['uppercats'], - 'title' => get_cat_display_name($result['name'], '', false), + 'title' => get_cat_display_name($result['name'], null, false), ) ); - if (!isset($_GET['calendar'])) + if (!isset($page['chronology_field'])) { $query = ' SELECT image_id @@ -321,7 +339,7 @@ else SELECT DISTINCT(id) FROM '.IMAGES_TABLE.' INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id = ic.image_id - WHERE '.get_sql_search_clause($_GET['search']).' + WHERE '.get_sql_search_clause($page['search']).' AND '.$forbidden.' '.$conf['order_by'].' ;'; @@ -489,4 +507,19 @@ if (isset($page['chronology_field'])) initialize_calendar(); } +if (basename($_SERVER['SCRIPT_NAME']) == 'picture.php' + and !isset($page['image_id']) ) +{ + $query = ' +SELECT id,file + FROM '.IMAGES_TABLE .' + WHERE id IN ('.implode(',',$page['items']).') + AND file LIKE "' . $page['image_file'] . '.%" ESCAPE "|"' +; + $result = pwg_query($query); + if (mysql_num_rows($result)>0) + { + list($page['image_id'], $page['image_file']) = mysql_fetch_row($result); + } +} ?>
\ No newline at end of file diff --git a/include/template.php b/include/template.php index 674e08659..5f2cf7a2c 100644 --- a/include/template.php +++ b/include/template.php @@ -34,7 +34,7 @@ class Template { var $classname = "Template"; - + // variable that holds all the data we'll be substituting into // the compiled templates. // ... @@ -43,22 +43,22 @@ class Template { // if it's a root-level variable, it'll be like this: // $this->_tpldata[.][0][varname] == value var $_tpldata = array(); - + // Hash of filenames for each template handle. var $files = array(); - + // Root template directory. var $root = ""; // this will hash handle names to the compiled code for that handle. var $compiled_code = array(); - + // This will hold the uncompiled code for that handle. var $uncompiled_code = array(); // output var $output = ''; - + /** * Constructor. Simply sets the root dir. * @@ -67,7 +67,7 @@ class Template { { $this->set_rootdir($root); } - + /** * Destroys this template object. Should be called when you're done with * it, in order to clear out the template data so you can load/parse a new @@ -87,11 +87,11 @@ class Template { { return false; } - + $this->root = $dir; return true; } - + /** * Sets the template filenames for handles. $filename_array should be a * hash of handle => filename pairs. @@ -102,17 +102,17 @@ class Template { { return false; } - + reset($filename_array); while(list($handle, $filename) = each($filename_array)) { $this->files[$handle] = $this->make_filename($filename); } - + return true; } - - + + /** * Load the file for the handle, compile the file, and run the compiled * code. This will print out the results of executing the template. @@ -123,7 +123,7 @@ class Template { { die("Template->pparse(): Couldn't load template file for handle $handle"); } - + // actually compile the template now. if (!isset($this->compiled_code[$handle]) || empty($this->compiled_code[$handle])) { @@ -146,7 +146,7 @@ class Template { { die("Template->pparse(): Couldn't load template file for handle $handle"); } - + // actually compile the template now. if (!isset($this->compiled_code[$handle]) || empty($this->compiled_code[$handle])) { @@ -169,7 +169,7 @@ class Template { { echo $this->output; } - + /** * Inserts the uncompiled code for $handle as the value of $varname in the * root-level. This can be used to effectively include a template in the @@ -184,19 +184,19 @@ class Template { { die("Template->assign_var_from_handle(): Couldn't load template file for handle $handle"); } - + // Compile it, with the "no echo statements" option on. $_str = ""; $code = $this->compile($this->uncompiled_code[$handle], true, '_str'); - + // evaluate the variable assignment. eval($code); // assign the value of the generated variable to the given varname. $this->assign_var($varname, $_str); - + return true; } - + /** * Block-level variable assignment. Adds a new block iteration with the * given variable assignments. Note that this should only be called once @@ -220,7 +220,7 @@ class Template { // We're adding a new iteration to this block with the given // variable assignments. $str .= '[\'' . $blocks[$blockcount] . '.\'][] = $vararray;'; - + // Now we evaluate this assignment we've built up. eval($str); } @@ -230,10 +230,10 @@ class Template { // variable assignments we were given. $this->_tpldata[$blockname . '.'][] = $vararray; } - + return true; } - + /** * Root-level variable assignment. Adds to current assignments, overriding * any existing variable assignment with the same name. @@ -245,10 +245,10 @@ class Template { { $this->_tpldata['.'][0][$key] = $val; } - + return true; } - + /** * Root-level variable assignment. Adds to current assignments, overriding * any existing variable assignment with the same name. @@ -256,11 +256,11 @@ class Template { function assign_var($varname, $varval) { $this->_tpldata['.'][0][$varname] = $varval; - + return true; } - - + + /** * Generates a full path+filename for the given filename, which can either * be an absolute name, or a name relative to the rootdir for this @@ -274,7 +274,7 @@ class Template { { $filename = $this->root.'/'.$filename; } - + if (!file_exists($filename)) { die("Template->make_filename(): Error - file $filename does not exist"); @@ -282,8 +282,8 @@ class Template { return $filename; } - - + + /** * If not already done, load the file for the given handle and populate * the uncompiled_code[] hash with its code. Do not compile. @@ -297,15 +297,15 @@ class Template { { return true; } - + // If we don't have a file assigned to this handle, die. if (!isset($this->files[$handle])) { die("Template->loadfile(): No file specified for handle $handle"); } - + $filename = $this->files[$handle]; - + $str = implode("", @file($filename)); if (empty($str)) { @@ -328,17 +328,18 @@ class Template { */ function compile($code, $do_not_echo = false, $retvar = '') { + $code = preg_replace('/\{pwg_root\}/e', "get_root_url()", $code); // PWG specific : communication between template and $lang $code = preg_replace('/\{lang:([^}]+)\}/e', "l10n('$1')", $code); // PWG specific : expand themeconf.inc.php variables $code = preg_replace('/\{themeconf:([^}]+)\}/e', "get_themeconf('$1')", $code); - + // replace \ with \\ and then ' with \'. $code = str_replace('\\', '\\\\', $code); $code = str_replace('\'', '\\\'', $code); - + // change template varrefs into PHP varrefs - + // This one will handle varrefs WITH namespaces $varrefs = array(); preg_match_all('#\{(([a-z0-9\-_]+?\.)+?)([a-z0-9\-_]+?)\}#is', $code, $varrefs); @@ -348,20 +349,20 @@ class Template { $namespace = $varrefs[1][$i]; $varname = $varrefs[3][$i]; $new = $this->generate_block_varref($namespace, $varname); - + $code = str_replace($varrefs[0][$i], $new, $code); } - + // This will handle the remaining root-level varrefs $code = preg_replace('#\{([a-z0-9\-_]*?)\}#is', '\' . ( ( isset($this->_tpldata[\'.\'][0][\'\1\']) ) ? $this->_tpldata[\'.\'][0][\'\1\'] : \'\' ) . \'', $code); - + // Break it up into lines. $code_lines = explode("\n", $code); - + $block_nesting_level = 0; $block_names = array(); $block_names[0] = "."; - + // Second: prepend echo ', append ' . "\n"; to each line. $line_count = sizeof($code_lines); for ($i = 0; $i < $line_count; $i++) @@ -371,7 +372,7 @@ class Template { { $n[0] = $m[0]; $n[1] = $m[1]; - + // Added: dougk_ff7-Keeps templates from bombing if begin is on // the same line as end.. I think. :) if ( preg_match('#<!-- END (.*?) -->#', $code_lines[$i], $n) ) @@ -388,7 +389,7 @@ class Template { else { // This block is nested. - + // Generate a namespace string for this block. $namespace = implode('.', $block_names); // strip leading period from root level.. @@ -401,7 +402,7 @@ class Template { $code_lines[$i] .= "\n" . 'for ($_' . $n[1] . '_i = 0; $_' . $n[1] . '_i < $_' . $n[1] . '_count; $_' . $n[1] . '_i++)'; $code_lines[$i] .= "\n" . '{'; } - + // We have the end of a block. unset($block_names[$block_nesting_level]); $block_nesting_level--; @@ -424,7 +425,7 @@ class Template { else { // This block is nested. - + // Generate a namespace string for this block. $namespace = implode('.', $block_names); // strip leading period from root level.. @@ -455,18 +456,18 @@ class Template { } else { - $code_lines[$i] = '$' . $retvar . '.= \'' . $code_lines[$i] . '\' . "\\n";'; + $code_lines[$i] = '$' . $retvar . '.= \'' . $code_lines[$i] . '\' . "\\n";'; } } } - + // Bring it back into a single string of lines of code. $code = implode("\n", $code_lines); return $code ; - + } - - + + /** * Generates a reference to the given variable inside the given (possibly * nested) block namespace. This is a string of the form: ' @@ -478,21 +479,21 @@ class Template { { // Strip the trailing period. $namespace = substr($namespace, 0, strlen($namespace) - 1); - + // Get a reference to the data block for this namespace. $varref = $this->generate_block_data_ref($namespace, true); // Prepend the necessary code to stick this in an echo line. - + // Append the variable reference. $varref .= '[\'' . $varname . '\']'; - + $varref = '\' . ( ( isset(' . $varref . ') ) ? ' . $varref . ' : \'\' ) . \''; - + return $varref; - + } - - + + /** * Generates a reference to the array of data values for the given * (possibly nested) block namespace. This is a string of the form: @@ -520,10 +521,10 @@ class Template { { $varref .= '[$_' . $blocks[$blockcount] . '_i]'; } - + return $varref; } - + } ?> |