Thread: [phpbbreloaded-checkins] SF.net SVN: phpbbreloaded: [231] phpBB Reloaded 2/includes
Status: Planning
Brought to you by:
tehphpmaster
From: <mar...@us...> - 2006-06-20 16:31:45
|
Revision: 231 Author: markthedaemon Date: 2006-06-20 09:31:38 -0700 (Tue, 20 Jun 2006) ViewCVS: http://svn.sourceforge.net/phpbbreloaded/?rev=231&view=rev Log Message: ----------- made teh CAPTCHA work again :D Modified Paths: -------------- phpBB Reloaded 2/includes/usercp_confirm.php phpBB Reloaded 2/includes/usercp_register.php Modified: phpBB Reloaded 2/includes/usercp_confirm.php =================================================================== --- phpBB Reloaded 2/includes/usercp_confirm.php 2006-06-19 23:27:34 UTC (rev 230) +++ phpBB Reloaded 2/includes/usercp_confirm.php 2006-06-20 16:31:38 UTC (rev 231) @@ -66,89 +66,98 @@ exit; } -// We can we will generate a single filtered png -// Thanks to DavidMJ for emulating zlib within the code :) -$_png = define_filtered_pngs(); +// If we can we will generate a single filtered png else we will have to simply +// output six seperate original pngs ... first way is preferable! +if (@extension_loaded('gd') || @extension_loaded('gd2')) +{ + require($root_path . "includes/functions_freecap.$phpEx"); -$total_width = 320; -$total_height = 50; -$img_height = 40; -$img_width = 0; -$l = 0; + // output final image :-) + sendImage($im); + // (sendImage also destroys all used images) +} +elseif (@extension_loaded('zlib')) +{ + $_png = define_filtered_pngs(); -list($usec, $sec) = explode(' ', microtime()); -mt_srand($sec * $usec); + $total_width = 320; + $total_height = 50; + $img_height = 40; + $img_width = 0; + $l = 0; -$char_widths = array(); -for ($i = 0; $i < strlen($code); $i++) -{ - $char = $code{$i}; + list($usec, $sec) = explode(' ', microtime()); + mt_srand($sec * $usec); - $width = mt_rand(0, 4); - $char_widths[] = $width; - $img_width += $_png[$char]['width'] - $width; -} + $char_widths = array(); + for ($i = 0; $i < strlen($code); $i++) + { + $char = $code{$i}; -$offset_x = mt_rand(0, $total_width - $img_width); -$offset_y = mt_rand(0, $total_height - $img_height); + $width = mt_rand(0, 4); + $char_widths[] = $width; + $img_width += $_png[$char]['width'] - $width; + } -$image = ''; -$hold_chars = array(); -for ($i = 0; $i < $total_height; $i++) -{ - $image .= chr(0); + $offset_x = mt_rand(0, $total_width - $img_width); + $offset_y = mt_rand(0, $total_height - $img_height); - if ($i > $offset_y && $i < $offset_y + $img_height) + $image = ''; + $hold_chars = array(); + for ($i = 0; $i < $total_height; $i++) { - $j = 0; + $image .= chr(0); - for ($k = 0; $k < $offset_x; $k++) + if ($i > $offset_y && $i < $offset_y + $img_height) { - $image .= chr(mt_rand(140, 255)); - } + $j = 0; - for ($k = 0; $k < strlen($code); $k++) - { - $char = $code{$k}; + for ($k = 0; $k < $offset_x; $k++) + { + $image .= chr(mt_rand(140, 255)); + } - if (empty($hold_chars[$char])) + for ($k = 0; $k < strlen($code); $k++) { - $hold_chars[$char] = explode("\n", chunk_split(base64_decode($_png[$char]['data']), $_png[$char]['width'] + 1, "\n")); + $char = $code{$k}; + + if (empty($hold_chars[$char])) + { + $hold_chars[$char] = explode("\n", chunk_split(base64_decode($_png[$char]['data']), $_png[$char]['width'] + 1, "\n")); + } + $image .= randomise(substr($hold_chars[$char][$l], 1), $char_widths[$j]); + $j++; } - $image .= randomise(substr($hold_chars[$char][$l], 1), $char_widths[$j]); - $j++; - } - for ($k = $offset_x + $img_width; $k < $total_width; $k++) + for ($k = $offset_x + $img_width; $k < $total_width; $k++) + { + $image .= chr(mt_rand(140, 255)); + } + + $l++; + } + else { - $image .= chr(mt_rand(140, 255)); + for ($k = 0; $k < $total_width; $k++) + { + $image .= chr(mt_rand(140, 255)); + } } - $l++; } - else - { - for ($k = 0; $k < $total_width; $k++) - { - $image .= chr(mt_rand(140, 255)); - } - } + unset($hold); -} -unset($hold); + $image = create_png(gzcompress($image), $total_width, $total_height); -$image = create_png($image, $total_width, $total_height); + // Output image + header('Content-Type: image/png'); + header('Cache-control: no-cache, no-store'); + echo $image; -// Output image -header('Content-Type: image/png'); -header('Cache-control: no-cache, no-store'); -echo $image; + unset($image); + unset($_png); + exit; -unset($image); -unset($_png); -exit; - - } else { @@ -212,7 +221,7 @@ // http://www.libpng.org/pub/png/spec/PNG-Contents.html we use // png because it's a fully recognised open standard and supported // by practically all modern browsers and OSs -function create_png($raw_image, $width, $height) +function create_png($gzimage, $width, $height) { // SIG $image = pack('C8', 137, 80, 78, 71, 13, 10, 26, 10); @@ -221,53 +230,8 @@ $raw .= pack('C4', $height >> 24, $height >> 16, $height >> 8, $height); $raw .= pack('C5', 8, 0, 0, 0, 0); $image .= png_chunk(13, 'IHDR', $raw); - if (@extension_loaded('zlib')) - { - $raw_image = gzcompress($raw_image); - $length = strlen($raw_image); - } - else - { - // The total length of this image, uncompressed, is just a calculation of pixels - $length = ($width + 1) * $height; - - // Adler-32 hash generation - // Optimized Adler-32 loop ported from the GNU Classpath project - $temp_length = $length; - $s1 = 1; - $s2 = $index = 0; - - while ($temp_length > 0) - { - // We can defer the modulo operation: - // s1 maximally grows from 65521 to 65521 + 255 * 3800 - // s2 maximally grows by 3800 * median(s1) = 2090079800 < 2^31 - $substract_value = ($temp_length < 3800) ? $temp_length : 3800; - $temp_length -= $substract_value; - - while (--$substract_value >= 0) - { - $s1 += ord($raw_image[$index]); - $s2 += $s1; - - $index++; - } - - $s1 %= 65521; - $s2 %= 65521; - } - $adler_hash = pack('N', ($s2 << 16) | $s1); - - // This is the same thing as gzcompress($raw_image, 0) but does not need zlib - $raw_image = pack('C3v2', 0x78, 0x01, 0x01, $length, ~$length) . $raw_image . $adler_hash; - - // The Zlib header + Adler hash make us add on 11 - $length += 11; - } - // IDAT - $image .= png_chunk($length, 'IDAT', $raw_image); - + $image .= png_chunk(strlen($gzimage), 'IDAT', $gzimage); // IEND $image .= png_chunk(0, 'IEND', ''); Modified: phpBB Reloaded 2/includes/usercp_register.php =================================================================== --- phpBB Reloaded 2/includes/usercp_register.php 2006-06-19 23:27:34 UTC (rev 230) +++ phpBB Reloaded 2/includes/usercp_register.php 2006-06-20 16:31:38 UTC (rev 231) @@ -319,13 +319,9 @@ if ($row = $db->sql_fetchrow($result)) { -// ---[ mod : FreeCap Visual Confirmation ]---------------------------------------- -// here we replace -// if ($row['code'] != $confirm_code) -//with - if (@extension_loaded('gd') || @extension_loaded('gd2')) +if (@extension_loaded('gd') || @extension_loaded('gd2')) { - $logic = 'return strtolower($row[\'code\'])) != strtolower($confirm_code);'; + $logic = 'return strtolower($row[\'code\']) != strtolower($confirm_code);'; } else { @@ -333,7 +329,7 @@ } if (eval($logic)) -// ---[ fin mod ]---------------------------------------- + { $error = TRUE; $error_msg .= ( ( isset($error_msg) ) ? '<br />' : '' ) . $lang['Confirm_code_wrong']; @@ -1157,7 +1153,8 @@ */ //-- add // fix a typo - $code = strtoupper(str_replace('0', 'o', substr($code, 2, 6))); + $code = strtoupper(str_replace('0', 'o', substr($code, 6))); + //-- fin mod : categories hierarchy -------------------------------------------- $code = strtolower(preg_replace('#(\d)#e', 'chr($1 + 96)', $code)); @@ -1172,12 +1169,10 @@ unset($code); -// ---[ mod : FreeCap Visual Confirmation ]---------------------------------------- -// here we replace -// $confirm_image = (@extension_loaded('zlib')) ? '<img src="' . append_sid("profile.$phpEx?mode=confirm&id=$confirm_id") . '" alt="" title="" />' : '<img src="' . append_sid("profile.$phpEx?mode=confirm&id=$confirm_id&c=1") . '" alt="" title="" /><img src="' . append_sid("profile.$phpEx?mode=confirm&id=$confirm_id&c=2") . '" alt="" title="" /><img src="' . append_sid("profile.$phpEx?mode=confirm&id=$confirm_id&c=3") . '" alt="" title="" /><img src="' . append_sid("profile.$phpEx?mode=confirm&id=$confirm_id&c=4") . '" alt="" title="" /><img src="' . append_sid("profile.$phpEx?mode=confirm&id=$confirm_id&c=5") . '" alt="" title="" /><img src="' . append_sid("profile.$phpEx?mode=confirm&id=$confirm_id&c=6") . '" alt="" title="" />'; -// with - $confirm_image = (@extension_loaded('gd') || @extension_loaded('gd2')) ? "<img src=\"" . append_sid("profile.$phpEx?mode=confirm&id=$confirm_id") . '" alt="" title="" />' : ((@extension_loaded('zlib')) ? '<img src="' . append_sid("profile.$phpEx?mode=confirm&id=$confirm_id") . '" alt="" title="" />' : '<img src="' . append_sid("profile.$phpEx?mode=confirm&id=$confirm_id&c=1") . '" alt="" title="" /><img src="' . append_sid("profile.$phpEx?mode=confirm&id=$confirm_id&c=2") . '" alt="" title="" /><img src="' . append_sid("profile.$phpEx?mode=confirm&id=$confirm_id&c=3") . '" alt="" title="" /><img src="' . append_sid("profile.$phpEx?mode=confirm&id=$confirm_id&c=4") . '" alt="" title="" /><img src="' . append_sid("profile.$phpEx?mode=confirm&id=$confirm_id&c=5") . '" alt="" title="" /><img src="' . append_sid("profile.$phpEx?mode=confirm&id=$confirm_id&c=6") . '" alt="" title="" />'); -// ---[ fin mod ]---------------------------------------- +$confirm_image = (@extension_loaded('zlib')) ? '<img src="' . append_sid("profile.$phpEx?mode=confirm&id=$confirm_id") . '" alt="" title="" />' : '<img src="' . append_sid("profile.$phpEx?mode=confirm&id=$confirm_id&c=1") . '" alt="" title="" /><img src="' . append_sid("profile.$phpEx?mode=confirm&id=$confirm_id&c=2") . '" alt="" title="" /><img src="' . append_sid("profile.$phpEx?mode=confirm&id=$confirm_id&c=3") . '" alt="" title="" /><img src="' . append_sid("profile.$phpEx?mode=confirm&id=$confirm_id&c=4") . '" alt="" title="" /><img src="' . append_sid("profile.$phpEx?mode=confirm&id=$confirm_id&c=5") . '" alt="" title="" /><img src="' . append_sid("profile.$phpEx?mode=confirm&id=$confirm_id&c=6") . '" alt="" title="" />'; + + + // ---[ fin mod ]---------------------------------------- $s_hidden_fields .= '<input type="hidden" name="confirm_id" value="' . $confirm_id . '" />'; $template->assign_block_vars('switch_confirm', array()); @@ -1354,8 +1349,9 @@ } } } -} + } + $template->pparse('body'); include($phpbb_root_path . 'includes/page_tail.'.$phpEx); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mar...@us...> - 2006-06-20 22:57:45
|
Revision: 247 Author: markthedaemon Date: 2006-06-20 15:57:36 -0700 (Tue, 20 Jun 2006) ViewCVS: http://svn.sourceforge.net/phpbbreloaded/?rev=247&view=rev Log Message: ----------- Added Paths: ----------- phpBB Reloaded 2/includes/class_calendar.php phpBB Reloaded 2/includes/class_calendar_topics.php Added: phpBB Reloaded 2/includes/class_calendar.php =================================================================== --- phpBB Reloaded 2/includes/class_calendar.php (rev 0) +++ phpBB Reloaded 2/includes/class_calendar.php 2006-06-20 22:57:36 UTC (rev 247) @@ -0,0 +1,914 @@ +<?php + +/*************************************************************************** + * class_calendar.php + * ------------------ + * begin : 01/12/2004 + * copyright : Ptirhiik + * email : pti...@cl... + * + * Version : 0.0.6 - 03/10/2005 + * + ***************************************************************************/ + +/*************************************************************************** + * + * 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 + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + ***************************************************************************/ + +if ( !defined('IN_PHPBB') ) +{ + die('Hacking attempt'); +} + +//------------------------------- +// registration of event type : +// class => file +//------------------------------- +$calendar_event_types = array( + 'calendar_event_topics' => 'class_calendar_topics', + 'calendar_event_birthday' => 'class_calendar_birthday', + 'calendar_event_hollyday' => 'class_calendar_hollyday', +); + +// read valid modules +$calendar_modules = array(); +foreach ( $calendar_event_types as $module_class => $module_file ) +{ + if ( !empty($module_file) ) + { + @include_once($config->url('includes/' . $module_file)); + } + if ( class_exists($module_class) ) + { + $calendar_modules[] = $module_class; + } +} +//------------------------------- +// output a user date +function format_user_date($time, $fmt) +{ + global $lang; + return strtr(date($fmt, $time), $lang['datetime']); +} + +// get user date day +function day_user_date($time, $inc=0) +{ + return mktime(0, 0, 0, date('m', $time), date('d', $time) + $inc, date('Y', $time)); +} +//------------------------------- + +class calendar_event_queue +{ + var $queue; + var $map; + + function calendar_event_queue() + { + $this->queue = array(); + $this->map = array(); + } + + // + // map events per day + // + function map($start_date, $end_date) + { + global $config, $user; + + // init + $this->map = array(); + if ( empty($this->queue) ) + { + return false; + } + + // fill the map with the date + $cur = day_user_date($start_date); + while ( $cur < $end_date ) + { + $this->map[$cur] = array(); + $cur = day_user_date($cur, +1); + } + if ( empty($this->map) ) + { + return false; + } + $count_map = count($this->map); + $map_keys = array_keys($this->map); + $rev_map_keys = array_flip($map_keys); + + // build a list per date + $event_classes = array_keys($this->queue); + $count_event_classes = count($event_classes); + for ( $i = 0; $i < $count_event_classes; $i++ ) + { + $event_class = $event_classes[$i]; + if ( !empty($this->queue[$event_class]) ) + { + $count_events = count($this->queue[$event_class]->data); + for ( $j = 0; $j < $count_events; $j++ ) + { + $row = &$this->queue[$event_class]->data[$j]; + $event_start = max($user->cvt_sys_to_user_date($row['event_start']), $start_date); + $event_end = min($user->cvt_sys_to_user_date($row['event_end']), $end_date); + + $offset_date = $event_start == $start_date ? $event_start : day_user_date($event_start); + + // find the first available spot in the mapped day + $count_map_offset_date = count($this->map[$offset_date]); + $map_offset = $count_map_offset_date; + $found = false; + if ( $count_map_offset_date ) + { + for ( $k = 0; ($k < $count_map_offset_date) && !$found; $k++) + { + if ( $this->map[$offset_date][$k] == -1 ) + { + $found = true; + $map_offset = $k; + } + } + } + + // mark the offset as used for the whole event period + $idx_offset = isset($rev_map_keys[$offset_date]) ? $rev_map_keys[$offset_date] : -1; + while ( ($idx_offset >= 0) && ($offset_date <= $event_end) ) + { + for ( $k = count($this->map[$offset_date]); $k <= $map_offset; $k++ ) + { + $this->map[$offset_date][$k] = -1; + } + $this->map[$offset_date][$map_offset] = array('event_class' => $event_class, 'event_idx' => $j); + $idx_offset++; + if ( $idx_offset >= $count_map ) + { + $idx_offset = -1; + } + $offset_date = $map_keys[$idx_offset]; + } + } + } + } + } + + // + // display a week row for the index, or the full month view page + // + function display($start_date, $selected_date, $nb_rows, $nb_cells, $full_month, $start_inc, $with_text, $with_bbcode) + { + global $template, $config, $user; + + // get the number of lines per cell + $nb_lines_per_cell = intval($config->data['calendar_nb_row']); + + // get the mapped dates + $map_dates = array_keys($this->map); + $count_map_dates = count($map_dates); + $offset_map_date = 0 - $start_inc; + + // get today offset for the user + $selected_date = day_user_date($selected_date); + + // display + for ( $i = 0; $i < $nb_rows; $i++ ) + { + $row_sent = false; + for ( $j = 0; $j < $nb_cells; $j++ ) + { + // date out of range + $blank_start = $offset_map_date < 0; + $blank_end = $offset_map_date >= $count_map_dates; + + // empty cells + if ( $blank_start || $blank_end ) + { + if ( $blank_start ) + { + // compute the cell to span + $span = $start_inc; + $j = $start_inc; + $offset_map_date = 0; + } + + // date greater than end + if ( $blank_end ) + { + // compute the cell to span + $span = $nb_cells-$j; + $j = $nb_cells; + } + + // send empty cells + if ( $blank_start || (($span > 0) && ($span < $nb_cells)) ) + { + if ( !$row_sent ) + { + $template->set_switch('cal_row'); + $row_sent = true; + } + $template->assign_block_vars('cal_row.cal_cell', array( + 'WIDTH' => floor(100 / $nb_cells) * $span, + 'SPAN' => $span, + )); + $template->set_switch('cal_row.cal_cell.empty'); + } + } + + // filled cells + if ( !$blank_end ) + { + if ( !$row_sent ) + { + $template->set_switch('cal_row'); + $row_sent = true; + } + $offset_date = $map_dates[$offset_map_date]; + $template->assign_block_vars('cal_row.cal_cell', array( + 'WIDTH' => floor(100 / $nb_cells), + 'DATE' => format_user_date($offset_date, $full_month ? $user->data['user_dateformat_short'] : $user->data['user_dateformat_medium'], false), + 'U_DATE' => $config->url('calendar_scheduler', array('date' => date('Ymd', $offset_date), POST_FORUM_URL => $forum_id), true), + + 'EVENT_DATE' => $offset_date, + 'TOGGLE_STATUS' => 'none', + 'TOGGLE_ICON' => $user->img('down_arrow'), + )); + $template->set_switch('cal_row.cal_cell.filled'); + + $template->set_switch('cal_row.cal_cell.active', $selected_date == $offset_date); + $template->set_switch('cal_row.cal_cell.filled.active', $selected_date == $offset_date); + + // send events + $count_map = count($this->map[$offset_date]); + for ( $k = 0; $k < $count_map; $k++ ) + { + $content = isset($this->map[$offset_date][$k]) && is_array($this->map[$offset_date][$k]); + if ( $content ) + { + $event_class = $this->map[$offset_date][$k]['event_class']; + $event_idx = $this->map[$offset_date][$k]['event_idx']; + $this->queue[$event_class]->display_one_item($event_idx, 'cal_row.cal_cell.filled._event', $with_text, $with_bbcode, false, false, false); + } + else + { + $template->set_switch('cal_row.cal_cell.filled._event'); + $template->set_switch('cal_row.cal_cell.filled._event._content', false); + } + + // we gonna have an overflow + if ( $count_map > $nb_lines_per_cell ) + { + // we are on the last line displayed + $template->set_switch('cal_row.cal_cell.filled._event._more', $k == ($nb_lines_per_cell - 1)); + if ( $k == ($nb_lines_per_cell - 1) ) + { + $template->set_switch('cal_row.cal_cell.filled._event._more.java', $with_bbcode); + } + + // we are on the first line hidden + $template->set_switch('cal_row.cal_cell.filled._event._more_header', $k == $nb_lines_per_cell); + + // we are on the last line hidden + $template->set_switch('cal_row.cal_cell.filled._event._more_footer', $k == ($count_map-1)); + } + } + } + + // next map cell + $offset_map_date++; + } + } + } +} + +class calendar_month_event_queue extends calendar_event_queue +{ + function display($start_date, $selected_date, $nb_rows, $nb_cells, $full_month, $start_inc, $with_text=true, $with_bbcode=true) + { + global $template, $config, $user; + + // get the mapped dates + $map_dates = array_keys($this->map); + $count_map_dates = count($map_dates); + $offset_map_date = 0 - $start_inc; + + // get today offset for the user + $selected_date = day_user_date($selected_date); + + // send java + $template->set_switch('java', $with_bbcode); + + // display + $color = false; + for ( $i = 0; $i < $nb_rows; $i++ ) + { + $color = !$color; + $row_sent = false; + for ( $j = 0; $j < $nb_cells; $j++ ) + { + // date out of range + $blank_start = $offset_map_date < 0; + $blank_end = $offset_map_date >= $count_map_dates; + + // empty cells + if ( $blank_start || $blank_end ) + { + if ( $blank_start ) + { + // compute the cell to span + $span = $start_inc; + $j = $start_inc; + $offset_map_date = 0; + } + + // date greater than end + if ( $blank_end ) + { + // compute the cell to span + $span = $nb_cells-$j; + $j = $nb_cells; + } + + // send empty cells + if ( $blank_start || (($span > 0) && ($span < $nb_cells)) ) + { + if ( !$row_sent ) + { + $template->set_switch('cal_row'); + $row_sent = true; + } + $template->assign_block_vars('cal_row.cal_cell', array( + 'WIDTH' => floor(100 / $nb_cells) * $span, + 'SPAN' => $span, + )); + $template->set_switch('cal_row.cal_cell.empty'); + } + } + + // filled cells + if ( !$blank_end ) + { + if ( !$row_sent ) + { + $template->set_switch('cal_row'); + $row_sent = true; + } + $offset_date = $map_dates[$offset_map_date]; + $template->assign_block_vars('cal_row.cal_cell', array( + 'WIDTH' => floor(100 / $nb_cells), + 'DAY' => format_user_date($offset_date, 'd'), + 'L_DATE' => format_user_date($offset_date, $user->data['user_dateformat_medium']), + 'U_DATE' => $config->url('calendar_scheduler', array('date' => date('Ymd', $offset_date), POST_FORUM_URL => _read(POST_FORUM_URL, TYPE_INT)), true), + )); + if ( $selected_date == $offset_date ) + { + $template->set_switch('cal_row.cal_cell.active'); + } + else + { + $template->set_switch('cal_row.cal_cell.light', $color); + } + + // send events + $count_map = count($this->map[$offset_date]); + $content = false; + for ( $k = 0; $k < $count_map; $k++ ) + { + if ( isset($this->map[$offset_date][$k]) && is_array($this->map[$offset_date][$k]) ) + { + $first = false; + if ( !$content ) + { + $content = true; + $first = true; + $template->set_switch('cal_row.cal_cell.filled'); + if ( $with_bbcode ) + { + $day_id = date('Ymd', $offset_date); + $tpl_var = array( + 'DAY_ID' => $day_id, + 'L_DATE' => format_user_date($offset_date, $user->data['user_dateformat_medium']), + 'U_DATE' => $config->url('calendar_scheduler', array('date' => date('Ymd', $offset_date), POST_FORUM_URL => _read(POST_FORUM_URL, TYPE_INT)), true), + ); + $template->assign_block_vars('java.day', $tpl_var); + $template->assign_block_vars('cal_row.cal_cell.filled.java', $tpl_var); + } + else + { + $template->set_switch('cal_row.cal_cell.filled.java', false); + } + } + $event_class = $this->map[$offset_date][$k]['event_class']; + $event_idx = $this->map[$offset_date][$k]['event_idx']; + $this->queue[$event_class]->display_one_item($event_idx, $with_bbcode ? 'cal_row.cal_cell.filled.java._event' : 'cal_row.cal_cell.filled.java_ELSE._event', $with_text, $with_bbcode, true, $day_id); + } + } + if ( !$content ) + { + $template->set_switch('cal_row.cal_cell.filled', false); + } + } + + // next map cell + $offset_map_date++; + } + } + + + // template + $template->set_filenames(array('_calendar_month_box' => 'calendar_month_box.tpl')); + $template->assign_block_vars('left_side', array( + 'BOX' => $template->get_pparse('_calendar_month_box'), + )); + $template->set_switch('left_side.first'); + } + + function display_list($start_time, $end_time) + { + global $user; + + // prepare the list + $event_classes = array_keys($this->queue); + $count_event_classes = count($event_classes); + $list = array(); + for ( $i = 0; $i < $count_event_classes; $i++ ) + { + $list[ $event_classes[$i] ] = array(); + } + + // get the day starting time + $offset_date = day_user_date($start_time); + $count_map = count($this->map[$offset_date]); + for ( $i = 0; $i < $count_map; $i++ ) + { + if ( isset($this->map[$offset_date][$i]) && is_array($this->map[$offset_date][$i]) ) + { + $event_class = $this->map[$offset_date][$i]['event_class']; + $event_idx = $this->map[$offset_date][$i]['event_idx']; + $event_start = $user->cvt_sys_to_user_date($this->queue[$event_class]->data[$event_idx]['event_start']); + $event_end = $user->cvt_sys_to_user_date($this->queue[$event_class]->data[$event_idx]['event_end']); + if ( ($event_start < $end_time) && ($event_end >= $start_time) ) + { + $list[$event_class][] = $event_idx; + } + } + } + for ( $i = 0; $i < $count_event_classes; $i++ ) + { + $this->queue[ $event_classes[$i] ]->display_list($start_time, $end_time, $list[ $event_classes[$i] ], $i == 0); + } + } +} + +class calendar_event +{ + var $data; + var $total; + var $tpl_loaded; + var $calendar_event_queue; + + function calendar_event(&$calendar_event_queue) + { + $this->data = array(); + $this->total = array(); + $this->tpl_loaded = false; + $this->calendar_event_queue = &$calendar_event_queue; + } +} + +class calendar +{ + var $start_date; + var $end_date; + var $with_text; + var $with_bbcode; + var $forum_id; + + var $full_month; + var $nb_cells; + var $nb_rows; + var $start_inc; + + function calendar() + { + global $config, $template, $user; + + // settings + $settings = array( + 'calendar_header_cells' => 7, + 'calendar_display_open' => false, + 'calendar_overview' => false, + 'calendar_use_java' => true, + 'calendar_title_length' => 30, + 'calendar_text_length' => 200, + 'calendar_week_start' => 1, + 'calendar_nb_row' => 5, + ); + + // create config values + if ( empty($config->data['calendar_title_length']) || empty($config->data['calendar_nb_row']) ) + { + $config->begin_transaction(); + foreach ( $settings as $key => $value ) + { + $config->set($key, $value, true); + } + $config->end_transaction(); + } + + // get user prefs + foreach ( $settings as $key => $value ) + { + if ( !empty($user->data['user_' . $key]) ) + { + $config->data[$key] = $user->data['user_' . $key]; + } + } + + // set the user date short format + $this->set_user_date_format(); + + // header + $template->assign_vars(array( + 'U_CALENDAR' => $config->url('calendar', '', true), + 'L_CALENDAR' => $user->lang('Calendar'), + 'I_CALENDAR' => $user->img('menu_calendar'), + 'L_CALENDAR_ALT' => $user->lang('Calendar_event'), + )); + $template->set_switch('topic_calendar'); + } + + // date is a user format date + function display($tpl_var, $date=0, $forum_id=0, $full_month=false) + { + global $config, $user, $template; + global $calendar_modules; + + $this->forum_id = intval($forum_id); + $this->full_month = $full_month; + $this->nb_cells = $this->full_month ? 7 : intval($config->data['calendar_header_cells']); + $this->with_text = $config->data['calendar_overview'] || $this->full_month; + $this->with_bbcode = $config->data['calendar_use_java']; + + // halt here if single row, no java and header closed + if ( (!$this->with_bbcode && !$config->data['calendar_display_open'] && !$this->full_month) || empty($this->nb_cells) ) + { + return ''; + } + + // the date entered is a user date : pull it to the begining of the day for the user + if ( empty($date) || (date('Ymd', $date) < 19700102) ) + { + $date = $user->cvt_sys_to_user_date(time()); + } + $date = day_user_date($date); + + // the full month is displayed + if ( $this->full_month ) + { + // pull the dates to the first of the month & next month + $this->start_date = mktime(0, 0, 0, date('m', $date), 01, date('Y', $date)); + $this->end_date = mktime(0, 0, 0, date('m', $this->start_date) + 1, 01, date('Y', $this->start_date)); + + // get the number of cells per line, the offset of the first day, and the number of rows (a day can have 23 to 25 hours : DST, so use round()) + $offset = isset($config->data['calendar_week_start']) ? intval($config->data['calendar_week_start']) : 1; + $this->start_inc = date('w', $this->start_date) - $offset; + if ( $this->start_inc < 0 ) + { + $this->start_inc = $this->nb_cells + $this->start_inc; + } + $this->nb_rows = intval(($this->start_inc + round(($this->end_date - $this->start_date) / 86400)) / $this->nb_cells) + 1; + } + + // only a row is displayed + else + { + // set the start date to the day before the date selected + $this->start_date = day_user_date($date, - 1); + $this->end_date = day_user_date($this->start_date, $this->nb_cells); + + // get the number of cells & rows per line, and the offset of the first day + $this->start_inc = 0; + $this->nb_rows = 1; + } + + // init event queue + $calendar_event_queue = new calendar_event_queue(); + + // browse calendar event types + $count_calendar_modules = count($calendar_modules); + for ( $i = 0; $i < $count_calendar_modules; $i++ ) + { + $event_type = $calendar_modules[$i]; + $$event_type = new $event_type($calendar_event_queue); + $$event_type->read($this->start_date, $this->end_date, $this->with_text, $this->forum_id); + } + + // map the events + $calendar_event_queue->map($this->start_date, $this->end_date); + + // display + $this->display_legend(); + $calendar_event_queue->display($this->start_date, $user->cvt_sys_to_user_date(time()), $this->nb_rows, $this->nb_cells, $this->full_month, $this->start_inc, $this->with_text, $this->with_bbcode); + + // template + $template->set_filenames(array('_calendar_body' => 'calendar_box.tpl')); + $template->assign_var_from_handle($tpl_var, '_calendar_body'); + } + + // $date is a user format date + function display_legend() + { + global $config, $template, $user, $forums; + + // set the full month & overview switch + $template->set_switch('full_month', $this->full_month); + $template->set_switch('java', $this->with_bbcode); + + // full month header + if ( $this->full_month ) + { + // day name header + $set_of_days = array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'); + $offset = intval($config->data['calendar_week_start']); + for ( $i = 0; $i < $this->nb_cells; $i++ ) + { + if ( $offset >= $this->nb_cells ) + { + $offset = 0; + } + $template->assign_block_vars('full_month.cal_cell', array( + 'WIDTH' => floor(100 / $this->nb_cells), + 'L_DAY' => $user->lang($set_of_days[$offset]), + )); + $offset++; + if ( $i == 0 ) + { + $template->set_switch('full_month.cal_cell.left'); + } + else if ( $i == ($this->nb_cells - 1) ) + { + $template->set_switch('full_month.cal_cell.right'); + } + else + { + $template->set_switch('full_month.cal_cell.regular'); + } + } + + // next/previous month + $prev = date('Ym', $this->start_date) > 197101 ? date('Ymd', mktime(0, 0, 0, date('m', $this->start_date), 00, date('Y', $this->start_date))) : date('Ymd', $this->start_date); + $next = date('Ym', $this->start_date) < 206912 ? date('Ymd', mktime(0, 0, 0, date('m', $this->start_date) + 1, 01, date('Y', $this->start_date))) : date('Ymd', $this->start_date); + + // header fields + $template->assign_vars(array( + 'S_MONTH' => $this->get_select_monthes($this->start_date), + 'S_YEAR' => $this->get_select_years($this->start_date), + 'S_FORUM_LIST' => $forums->get_jumpbox(true, $this->forum_id), + 'POST_FORUM_URL' => POST_FORUM_URL, + 'L_GO' => $user->lang('Go'), + 'I_GO' => $user->img('cmd_mini_submit'), + + 'U_PREC' => $config->url('calendar', array('date' => $prev, POST_FORUM_URL => $this->forum_id), true), + 'L_PREC' => $user->lang('Previous'), + 'I_PREC' => $user->img('cmd_previous'), + 'U_NEXT' => $config->url('calendar', array('date' => $next, POST_FORUM_URL => $this->forum_id), true), + 'L_NEXT' => $user->lang('Next'), + 'I_NEXT' => $user->img('cmd_next'), + )); + } + // single row header + else + { + $template->assign_vars(array( + 'I_CALENDAR_LRG' => $user->img('icon_calendar'), + )); + if ( $this->with_bbcode ) + { + $template->assign_vars(array( + 'TOGGLE_ICON' => $config->data['calendar_display_open'] ? $user->img('up_arrow') : $user->img('down_arrow'), + 'TOGGLE_STATUS' => $config->data['calendar_display_open'] ? '' : 'none', + )); + } + $template->set_switch('full_month_ELSE.java', $this->with_bbcode); + } + + // header + $template->assign_vars(array( + 'UP_ARROW' => $user->img('up_arrow'), + 'DOWN_ARROW' => $user->img('down_arrow'), + + 'ACTION' => $config->url('calendar', '', true), + 'SPAN_ALL' => $this->nb_cells, + 'WIDTH' => floor(100 / $this->nb_cells), + )); + } + + function get_select_monthes($date) + { + global $user; + + // build select list for month + $month = intval(date('m', $date)); + $options = ''; + $monthes = array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'); + for ( $i = 0; $i < 12; $i++ ) + { + $selected = ($month == ($i + 1)) ? ' selected="selected"' : ''; + $options .= '<option value="' . ($i + 1) . '"' . $selected . '>' . $user->lang($monthes[$i]) . '</option>'; + } + return $options; + } + + function get_select_years($date) + { + // buid select list for year + $year = intval(date('Y', $date)); + $options = ''; + for ( $i = 1971; $i < 2070; $i++ ) + { + $selected = ($year == $i) ? ' selected="selected"' : ''; + $options .= '<option value="' . $i . '"' . $selected . '>' . $i . '</option>'; + } + return $options; + } + + function set_user_date_format() + { + global $user; + + $user->data['user_date_order'] = array( + 'y' => strpos(' ' . strtolower($user->data['user_dateformat']), 'y')-1, + 'm' => (strpos(' ' . strtolower($user->data['user_dateformat']), 'm')-1 >= 0) ? strpos(' ' . strtolower($user->data['user_dateformat']), 'm')-1 : strpos(' ' . $user->data['user_dateformat'], 'n')-1, + 'd' => (strpos(' ' . $user->data['user_dateformat'], 'd')-1 >= 0) ? strpos(' ' . $user->data['user_dateformat'], 'd')-1 : strpos(' ' . $user->data['user_dateformat'], 'j')-1, + 'D' => strpos(' ' . $user->data['user_dateformat'], 'D')-1, + ); + asort($user->data['user_date_order']); + $user->data['user_date_order'] = array_flip(array_keys($user->data['user_date_order'])); + $pres = array('y' => 'Y', 'm' => 'M', 'd' => 'd', 'D' => 'D'); + $user->data['user_dateformat_short'] = ''; + $user->data['user_dateformat_medium'] = ''; + foreach ( $user->data['user_date_order'] as $key => $dummy ) + { + if ( $key != 'D' ) + { + $user->data['user_dateformat_short'] .= (empty($user->data['user_dateformat_short']) ? '' : ' ') . $pres[$key]; + } + $user->data['user_dateformat_medium'] .= (empty($user->data['user_dateformat_short']) ? '' : ' ') . $pres[$key]; + } + } +} + +class calendar_scheduler extends calendar +{ + var $start_time; + var $end_time; + + function calendar_scheduler() + { + parent::calendar(); + $this->with_text = false; + } + + // date is a user format date + function display($date=0, $hour=0, $forum_id=0) + { + global $config, $user; + global $calendar_modules; + + $this->forum_id = intval($forum_id); + $this->full_month = true; + $this->nb_cells = 7; + $this->with_text = false; + $this->with_bbcode = $config->data['calendar_use_java']; + + // the date entered is a user date : pull it to the begining of the day for the user + if ( empty($date) || (date('Ymd', $date) < 19700102) ) + { + $date = $user->cvt_sys_to_user_date(time()); + } + $date = day_user_date($date); + + // pull the dates to the first of the month & next month + $this->start_date = mktime(0, 0, 0, date('m', $date), 01, date('Y', $date)); + $this->end_date = mktime(0, 0, 0, date('m', $this->start_date) + 1, 01, date('Y', $this->start_date)); + + // whole day + if ( ($hour < 1) || ($hour > 24) ) + { + $this->start_time = day_user_date($date); + $this->end_time = day_user_date($date, +1); + } + // one hour in the day + else + { + $this->start_time = mktime($hour - 1, 0, 0, date('m', $date), date('d', $date), date('Y', $date)); + $this->end_time = $this->start_time + 3600; + } + + // + // display the month box + // + + // get the number of cells per line, the offset of the first day, and the number of rows (a day can have 23 to 25 hours : DST, so use round()) + $offset = isset($config->data['calendar_week_start']) ? intval($config->data['calendar_week_start']) : 1; + $this->start_inc = date('w', $this->start_date) - $offset; + if ( $this->start_inc < 0 ) + { + $this->start_inc = $this->nb_cells + $this->start_inc; + } + $this->nb_rows = intval(($this->start_inc + round(($this->end_date - $this->start_date) / 86400)) / $this->nb_cells) + 1; + + // init event queue + $calendar_event_queue = new calendar_month_event_queue(); + + // browse calendar event types + $count_calendar_modules = count($calendar_modules); + for ( $i = 0; $i < $count_calendar_modules; $i++ ) + { + $event_type = $calendar_modules[$i]; + $$event_type = new $event_type($calendar_event_queue); + $$event_type->read($this->start_date, $this->end_date, $this->with_text, $this->forum_id); + } + + // map the events + $calendar_event_queue->map($this->start_date, $this->end_date); + + // display + $this->display_legend($calendar_event_queue); + $calendar_event_queue->display($this->start_date, $this->start_time, $this->nb_rows, $this->nb_cells, $this->full_month, $this->start_inc, $this->with_text, $this->with_bbcode); + + // + // display the events lists + // + $calendar_event_queue->display_list($this->start_time, $this->end_time); + } + + // $date is a user format date + function display_legend(&$calendar_event_queue, $single=true) + { + global $config, $template, $user, $forums; + + // day name header + $set_of_months = array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'); + $set_of_days = array('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'); + $offset = intval($config->data['calendar_week_start']); + for ( $i = 0; $i < $this->nb_cells; $i++ ) + { + if ( $offset >= $this->nb_cells ) + { + $offset = 0; + } + $template->assign_block_vars('cal_cell', array( + 'WIDTH' => floor(100 / $this->nb_cells), + 'L_DAY' => $user->lang($set_of_days[$offset]), + )); + $offset++; + if ( $i == 0 ) + { + $template->set_switch('cal_cell.left'); + } + else if ( $i == ($this->nb_cells - 1) ) + { + $template->set_switch('cal_cell.right'); + } + else + { + $template->set_switch('cal_cell.regular'); + } + } + + // next/previous month + $prev = date('Ym', $this->start_date) > 197101 ? date('Ymd', mktime(0, 0, 0, date('m', $this->start_date), 00, date('Y', $this->start_date))) : date('Ymd', $this->start_date); + $next = date('Ym', $this->start_date) < 206912 ? date('Ymd', mktime(0, 0, 0, date('m', $this->start_date) + 1, 01, date('Y', $this->start_date))) : date('Ymd', $this->start_date); + + // header fields + $template->assign_vars(array( + 'L_MONTH' => $user->lang($set_of_months[ (date('m', $this->start_date) - 1) ]), + 'YEAR' => date('Y', $this->start_date), + )); + $template->assign_vars(array( + 'S_MONTH' => $this->get_select_monthes($this->start_date), + 'S_YEAR' => $this->get_select_years($this->start_date), + 'S_FORUM_LIST' => $forums->get_jumpbox(true, $this->forum_id), + 'POST_FORUM_URL' => POST_FORUM_URL, + 'L_GO' => $user->lang('Go'), + 'I_GO' => $user->img('cmd_mini_submit'), + + 'U_PREC' => $config->url('calendar_scheduler', array('date' => $prev, POST_FORUM_URL => $this->forum_id), true), + 'L_PREC' => $user->lang('Previous'), + 'I_PREC' => $user->img('cmd_previous'), + 'U_NEXT' => $config->url('calendar_scheduler', array('date' => $next, POST_FORUM_URL => $this->forum_id), true), + 'L_NEXT' => $user->lang('Next'), + 'I_NEXT' => $user->img('cmd_next'), + )); + $template->set_switch('selector', $single); + } +} + +?> \ No newline at end of file Added: phpBB Reloaded 2/includes/class_calendar_topics.php =================================================================== --- phpBB Reloaded 2/includes/class_calendar_topics.php (rev 0) +++ phpBB Reloaded 2/includes/class_calendar_topics.php 2006-06-20 22:57:36 UTC (rev 247) @@ -0,0 +1,515 @@ +<?php + +/*************************************************************************** + * class_calendar_topics.php + * ------------------------- + * begin : 12/02/2005 + * copyright : Ptirhiik + * email : pti...@cl... + * + * Version : 0.0.7 - 19/10/2005 + * + ***************************************************************************/ + +/*************************************************************************** + * + * 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 + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + ***************************************************************************/ + +if ( !defined('IN_PHPBB') ) +{ + die('Hacking attempt'); +} + +include_once($config->url('includes/functions_post')); +include_once($config->url('includes/bbcode')); +include_once($config->url('includes/class_topics')); + +class calendar_event_topics extends calendar_event +{ + var $topic_title_length; + var $topic_text_length; + var $front_title; + var $forum_id; + + var $calendar_event_queue; + + function calendar_event_topics(&$calendar_event_queue) + { + global $config; + + parent::calendar_event($calendar_event_queue); + + $this->topic_title_length = empty($config->data['calendar_title_length']) ? 30 : intval($config->data['calendar_title_length']); + $this->topic_text_length = empty($config->data['calendar_text_length']) ? 200 : intval($config->data['calendar_text_length']); + $this->front_title = new front_title(); + $this->user_data = array(); + } + + function read($start_date, $end_date, $with_text=true, $forum_id=0) + { + global $db, $config, $user, $forums; + + $this->calendar_event_queue->queue[POST_TOPIC_URL] = &$this; + $this->forum_id = intval($forum_id); + + // read forums and auths relative to + if ( empty($forums) ) + { + include_once($config->url('includes/class_forums')); + $forums = new forums(); + $forums->read(); + } + if ( !isset($user->cache[POST_FORUM_URL]) ) + { + $user->get_cache(POST_FORUM_URL); + } + + // get the list of authorized forums + $auth_sql = ''; + + // check forum id + if ( !isset($forums->data[$forum_id]) || !$user->auth(POST_FORUM_URL, 'auth_read', $forum_id) ) + { + return; + } + + // get min and max forum ids for the branch asked + $min_id = intval($forum_id); + $max_id = $forums->data[$forum_id]['last_child_id']; + + // get excluded forums + $tkeys = array_flip($forums->keys); + $min_idx = $tkeys[$min_id]; + $max_idx = $tkeys[$max_id]; + unset($tkeys); + $exclude_forums = array(); + $something = false; + for ( $i = $min_idx; $i <= $max_idx; $i++ ) + { + if ( !$user->auth(POST_FORUM_URL, 'auth_read', $forums->keys[$i]) ) + { + $exclude_forums[] = $forums->keys[$i]; + } + else + { + $something = true; + } + } + + // halt on no forum authed + if ( !$something ) + { + return; + } + + // set branch range + $auth_sql = empty($forum_id) ? '' : sprintf(' AND (f.forum_order BETWEEN %d AND %d)', intval($forums->data[$min_id]['forum_order']), intval($forums->data[$max_id]['forum_order'])); + + // exclude unreadable forums + if ( !empty($exclude_forums) ) + { + $auth_sql .= count($exclude_forums) > 1 ? ' AND t.forum_id NOT IN(' . implode(', ', $exclude_forums) . ')' : ' AND t.forum_id <> ' . $exclude_forums[0]; + unset($exclude_forums); + } + + // add the forums table if required + $fields = array( + 't.*', + ); + $sql_tables = empty($forum_id) ? '' : ', ' . FORUMS_TABLE . ' f'; + $sql_where = empty($forum_id) ? $auth_sql : ' AND f.forum_id = t.forum_id' . $auth_sql; + if ( $with_text ) + { + $fields = array_merge($fields, array( + 'p.enable_bbcode', + 'p.enable_html', + 'p.enable_smilies', + 'pt.post_text', + 'pt.bbcode_uid', + )); + $sql_tables .= ', ' . POSTS_TABLE . ' p, ' . POSTS_TEXT_TABLE . ' pt'; + $sql_where .= ' AND p.post_id = t.topic_first_post_id AND pt.post_id = t.topic_first_post_id'; + } + $sql = 'SELECT ' . implode(', ', $fields) . ' + FROM ' . TOPICS_TABLE . ' t' . $sql_tables . ' + WHERE t.topic_calendar_time <> 0 + AND t.topic_status <> ' . TOPIC_MOVED . ' + AND t.topic_calendar_time < ' . $user->cvt_user_to_sys_date(intval($end_date)) . ' + AND (t.topic_calendar_time + t.topic_calendar_duration) >= ' . $user->cvt_user_to_sys_date(intval($start_date)) . $sql_where . ' + ORDER BY t.topic_calendar_time, t.topic_calendar_duration DESC, t.topic_type DESC, t.topic_last_post_id DESC'; + $result = $db->sql_query($sql, false, __LINE__, __FILE__); + + // read data + $user_ids = array(); + while ( $row = $db->sql_fetchrow($result) ) + { + // if required, prepare the overview window + if ( $with_text && !empty($row['post_text']) && !empty($this->topic_text_length) ) + { + $message = $row['post_text']; + + // remove html escape + $message = unprepare_message($message); + $message = str_replace('<br />', "\n", $message); + + // remove bbcode uid + if ( !empty($row['bbcode_uid']) ) + { + $message = preg_replace('/\:(([a-z0-9]:)?)' . $row['bbcode_uid'] . '/s', '', $message); + + // replace img with url + $message = str_replace(array('[img]', '[/img]'), array('[url]', '[/url]'), $message); + } + + // short the message + $message = substr($message, 0, $this->topic_text_length); + + // re-add bbCode + $row['post_text'] = prepare_message($message, $row['enable_html'], $row['enable_bbcode'], $row['enable_smilies'], $row['bbcode_uid']); + } + + // do some standardization + $row['post_icon'] = $row['topic_icon']; + $row['event_start'] = $row['topic_calendar_time']; + $row['event_end'] = $row['topic_calendar_time'] + (empty($row['topic_calendar_duration']) ? 86399 : $row['topic_calendar_duration']); + + // get users + $row['topic_poster'] = intval($row['topic_poster']); + $row['topic_last_poster'] = intval($row['topic_last_poster']); + if ( !in_array($row['topic_poster'], array(0, ANONYMOUS)) && !isset($this->user_data[ $row['topic_poster'] ]) ) + { + $user_ids[ $row['topic_poster'] ] = true; + } + if ( !in_array($row['topic_last_poster'], array(0, ANONYMOUS)) && !isset($this->user_data[ $row['topic_last_poster'] ]) ) + { + $user_ids[ $row['topic_last_poster'] ] = true; + } + + // add this row + $this->data[] = $row; + $count++; + } + $db->sql_freeresult($result); + + // read users + $user->read_pool($user_ids); + } + + function display_one_item($idx, $tpl_level, $with_text, $with_bbcode, $title_only, $day_id) + { + global $config, $user, $template; + + if ( !isset($this->data[$idx]) ) + { + return false; + } + $title = _un_htmlspecialchars(_censor($this->data[$idx]['topic_title'])); + $short_title = (strlen($title) > $this->topic_title_length + 3) ? substr($title, 0, $this->topic_title_length) . '...' : $title; + $title = htmlspecialchars($title); + $short_title = htmlspecialchars($short_title); + + // basic values + $tpl_values = array( + 'U_EVENT' => $config->url('viewtopic', array(POST_TOPIC_URL => $this->data[$idx]['topic_id']), true), + 'I_EVENT' => $user->img('icon_tiny_topic'), + 'L_EVENT' => $user->lang('Topic'), + 'TITLE' => $short_title, + 'FULL_TITLE' => $title, + ); + + // overview + if ( $title_only ) + { + if ( $with_bbcode && $first ) + { + $template->assign_block_vars('java.day', array('DAY_ID' => $day_id)); + $template->assign_block_vars($tpl_level, array('DAY_ID' => $day_id)); + } + $template->assign_block_vars($with_bbcode ? 'java.day._event' : $tpl_level, $tpl_values); + } + else + { + $message = $this->get_message($idx, $with_text, $with_bbcode); + if ( $with_bbcode ) + { + $event_id = POST_TOPIC_URL . '_' . $idx; + $template->assign_block_vars($tpl_level, $tpl_values + array( + 'EVENT_ID' => $event_id, + )); + if ( !isset($this->data[$idx]['event_sent']) || !$this->data[$idx]['event_sent'] ) + { + $template->assign_block_vars('java.cal_event', array( + 'EVENT_ID' => $event_id, + 'MESSAGE' => $message, + )); + $this->data[$idx]['event_sent'] = true; + } + } + else + { + $template->assign_block_vars($tpl_level, $tpl_values + array( + 'MESSAGE' => $message, + )); + } + $template->set_switch($tpl_level . '._content'); + $template->set_switch($tpl_level . '._content.java', $with_bbcode); + } + } + + function get_message($idx, $with_text, $with_bbcode) + { + global $config, $template, $user, $forums, $icons, $topics_attr; + + // message parsing + $text = ''; + if ( $with_text && !empty($this->data[$idx]['post_text']) ) + { + if ( $with_bbcode ) + { + // parse the message + $text = $this->data[$idx]['post_text']; + if ( !$config->data['allow_html'] && $this->data[$idx]['enable_html'] ) + { + $text = preg_replace('#(<)([\/]?.*?)(>)#is', "<\\2>", $text); + } + if ( !empty($this->data[$idx]['bbcode_uid']) ) + { + $text = $config->data['allow_bbcode'] ? bbencode_second_pass($text, $this->data[$idx]['bbcode_uid']) : preg_replace('/\:[0-9a-z\:]+\]/si', ']', $text); + } + if ( $config->data['allow_smilies'] ) + { + $text = smilies_pass($text); + } + $text = _censor(preg_replace("/[\n\r]{1,2}/", '<br />', $text)); + } + else + { + $text = _clean_bbcode(_clean_html($this->data[$idx]['post_text'])); + $text = str_replace('"', '"', _censor(preg_replace("/[\n\r]{1,2}/", '<br />', $text))); + } + } + + // process the template + $sav_tpl = array(); + $template->save($sav_tpl); + $template->destroy(); + $template->assign_vars(array( + 'L_SUBJECT' => $user->lang('Subject'), + 'TOPIC_TITLE' => _censor($this->data[$idx]['topic_title']), + 'U_TOPIC' => $config->url('viewtopic', array(POST_TOPIC_URL => $this->data[$idx]['topic_id']), true), + 'L_AUTHOR' => $user->lang('Author'), + 'AUTHOR' => !empty($this->data[$idx]['topic_first_username']) ? $this->data[$idx]['topic_first_username'] : (($this->data[$idx]['topic_poster'] == ANONYMOUS) || !isset($user->pool[ $this->data[$idx]['topic_poster'] ]) ? $user->lang('Guest') : $user->pool[ $this->data[$idx]['topic_poster'] ]['username']), + 'L_TOPIC_DATE' => $user->lang('Date'), + 'TOPIC_DATE' => $user->date($this->data[$idx]['topic_time']), + 'L_FORUM' => $user->lang('Forum'), + 'MESSAGE' => $text, + 'L_VIEWS' => $user->lang('Views'), + 'VIEWS' => $this->data[$idx]['topic_views'], + 'L_REPLIES' => $user->lang('Replies'), + 'REPLIES' => $this->data[$idx]['topic_replies'], + )); + $template->set_switch('text', $with_text && !empty($text)); + + // enhance topic title + $this->front_title->set('', $this->data[$idx]); + $forums->display_nav($this->data[$idx]['forum_id'], 'nav', true); + + $no_debug = $template->no_debug; + $template->no_debug = true; + if ( !$this->tpl_loaded ) + { + $template->set_filenames(array('_cal_overview_topic' => $with_bbcode ? 'calendar_overview_topic.tpl' : 'calendar_overview_topic_txt.tpl')); + } + $message = $template->get_pparse('_cal_overview_topic'); + $template->no_debug = $no_debug; + if ( !$with_bbcode ) + { + // do some cleaning for the text-mode overview + $message = str_replace(array('<br />', ' ', '<', '>', '"'), array("\n", ' ', '<', '>', '"'), preg_replace("/[\n\r]{1,2}/", '', $message)); + } + $template->restore($sav_tpl); + + return $message; + } + + function display_list($start_date, $end_date, $event_idxs, $first) + { + global $template, $config, $user; + + $all_events = ($end_date - $start_date > 3600); + $topics = new calendar_topics_list('calendar_scheduler', $start_date, $all_events); + $topics->read($this->data, $event_idxs, $this->forum_id); + $upper_box = true; + $display_empty = true; + $forced_title = format_user_date($start_date, _read('hour', TYPE_INT) <= 0 ? $user->data['user_dateformat_medium'] : $user->data['user_dateformat']); + $template->assign_block_vars('right_side', array( + 'BOX' => $topics->get_display($upper_box, $display_empty, $forced_title), + )); + $template->set_switch('right_side.first', $first); + _hide('day', date('d', $start_date)); + } +} + +class calendar_topics_list extends topics +{ + var $date; + var $all_events; + var $forum_id; + + function calendar_topics_list($requester, $start_date, $all_events) + { + parent::topics($requester); + + $this->date = $start_date; + $this->all_events = $all_events; + } + + function read(&$data, $idxs, $forum_id=0) + { + global $db, $user; + + $this->forum_id = intval($forum_id); + + if ( empty($idxs) ) + { + return; + } + + // get the topics data + $this->data_ext = array(); + $count_idxs = count($idxs); + $user_ids = array(); + $chk_topics_own = array(); + for ( $i = 0; $i < $count_idxs; $i++ ) + { + $topic_id = $data[ $idxs[$i] ]['topic_id']; + $this->data_ext[$topic_id] = &$data[ $idxs[$i] ]; + + if ( !empty($this->data_ext[$topic_id]['topic_poster']) && ($this->data_ext[$topic_id]['topic_poster'] != ANONYMOUS) ) + { + $user_ids[ $this->data_ext[$topic_id]['topic_poster'] ][] = $topic_id; + } + if ( !empty($this->data_ext[$topic_id]['topic_last_poster']) && ($this->data_ext[$topic_id]['topic_last_poster'] != ANONYMOUS) ) + { + $user_ids[ $this->data_ext[$topic_id]['topic_last_poster'] ][] = $topic_id; + } + + // get the topics to check for "you have posted in this topic" + if ( $user->data['session_logged_in'] ) + { + $this->data_ext[$topic_id]['topic_own'] = ($this->data_ext[$topic_id]['topic_poster'] == $user->data['user_id']) || ($this->data_ext[$topic_id]['topic_last_poster'] == $user->data['user_id']); + if ( !$this->data_ext[$topic_id]['topic_own'] ) + { + $chk_topics_own[] = $topic_id; + } + } + } + + // read the pertinent users + $user->read_pool($user_ids); + + // search topics the viewer has posted in + if ( !empty($chk_topics_own) ) + { + $sql = 'SELECT DISTINCT topic_id + FROM ' . POSTS_TABLE . ' + WHERE poster_id = ' . intval($user->data['user_id']) . ' + AND topic_id IN(' . implode(', ', $chk_topics_own) . ')'; + $result = $db->sql_query($sql, false, __LINE__, __FILE__); + while ( $row = $db->sql_fetchrow($result) ) + { + $this->data_ext[ $row['topic_id'] ]['topic_own'] = true; + } + $db->sql_freeresult($result); + } + + // parms for pagination + $this->total_topics = count($this->data_ext); + $this->parms['ppage'] = $this->total_topics; + } + + function get_display($upper_box=false, $display_empty=false, $forced_title='') + { + global $template, $forums, $user; + + // prepare result + $res = ''; + + // check if we display something + if ( $display_empty || ($upper_box && !empty($this->data_ext)) || (!$upper_box && !empty($this->data)) ) + { + // save and reset template + $save_tpl = array(); + $template->save($save_tpl); + + // choose tpl + $template->set_filenames(array('topics_box' => 'topics_row_box.tpl')); + + // send display + $this->display($upper_box, $display_empty, $forced_title); + $template->assign_vars(array( + 'L_NO_TOPICS' => $user->lang('No_search_match'), + )); + + // get result + $res = $template->get_pparse('topics_box'); + + // restore template + $template->restore($save_tpl); + } + return $res; + } + + function bottom_line($empty=false) + { + global $template, $user, $forums; + + $template->set_switch('topicrow'); + $template->set_switch('topicrow.bottom'); + $template->set_switch('topicrow.bottom.no_topics', $empty); + $template->assign_vars(array( + 'L_SELECT_FORM' => $user->lang('Select'), + 'S_FORUM_LIST' => $forums->get_jumpbox(true, $this->forum_id), + 'POST_FORUM_URL' => POST_FORUM_URL, + 'L_GO' => $user->lang('Go'), + 'I_GO' => $user->img('cmd_mini_submit'), + 'S_HOURS' => $this->get_hours(), + )); + $template->set_filenames(array('bottom_row' => 'calendar_topics_bottom_sched.tpl')); + $template->assign_var_from_handle('BOTTOM_ROW', 'bottom_row'); + } + + function get_hours() + { + global $user; + + $fmt = 'H:00'; + if ( strpos(' ' . $user->data['user_dateformat'], 'a') ) + { + $fmt = 'h a'; + } + else if ( strpos(' ' . $user->data['user_dateformat'], 'A') ) + { + $fmt = 'h A'; + } + // let's set an arbitrary date + $date = mktime(0, 0, 0, 01, 01, 2005); + + $select = $this->all_events ? 0 : date('H', $this->date) + 1; + $options = '<option value="0"' . ( empty($select) ? ' selected="selected"' : '') . '>' . $user->lang('Calendar_all_events') . '</option>'; + for ( $i = 1; $i <= 24; $i++ ) + { + $selected = ($select == $i) ? ' selected="selected"' : ''; + $options .= '<option value="' . $i . '"' . $selected . '>' . format_user_date($date, $fmt) . '</option>'; + $date += 3600; + } + return $options; + } +} + +?> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |