<?php
function redeen_event($events_list)
{
$event_pattern="~.*<td>(.*)</td>.*<td>(.*)</td>.*~Uims";
preg_match_all($event_pattern,$events_list,$event_matches);
$r_line="";
for($i=0;$i<count($event_matches[1]);$i++)
{
$r_line.="<p>".implode("Where: ",explode("",$event_matches[2][$i]))."</p>";
$w_split=explode("",$event_matches[1][$i]);
$r_line.="<p>".$w_split[1]."</p>";
}
return $r_line;
}
function count_event($events_list)
{
$event_pattern="~.*<td>(.*)</td>.*<td>(.*)</td>.*~Uims";
preg_match_all($event_pattern,$events_list,$event_matches);
return count($event_matches[1]);
}
function check_sidebar_cache()
{
$tod_day=date("Y-m-d",strtotime(current_time('mysql')));
$cache_file=get_template_directory()."/event_cache/sidebar_cache";
if(!is_file($cache_file))return false;
$cache=file_get_contents($cache_file);
$file_split=explode("<|>",$cache);
$query="SELECT * FROM 'wp_posts' WHERE post_type = 'event' ORDER BY post_modified DESC LIMIT 1";
$check_req=mysql_query($query);
$check_res=mysql_fetch_assoc($check_req);
$full_cache_date=date("Y-m-d H:i:s",$file_split[0]);
if($check_res['post_date'] > $full_cache_date || $check_res['post_modified'] > $full_cache_date) return false;
$cache_day=date("Y-m-d",$file_split[0]);
if($cache_day!=$tod_day)return false;
else return $cache;
}
$cache=check_sidebar_cache();
$file_split=explode("<|>",$cache);
if($cache===false) $em_cache=strtotime(current_time('mysql'));
?>
<h3 class="types_header"><a href="#">events by type</a></h3>
<div id="types_content" class="types_conent">
<?php
if($cache===false)
{
$termchildren = get_term_children( 51,$taxonomyName);
$d="";
$d.='
<ul>';
foreach ($termchildren as $child) {
$term = get_term_by( 'id', $child,$taxonomyName );
if($term->count==0) continue;
$d.='<li><a href="/events/categories/type/'. $term->slug.'">' . $term->name ." (".$term->count.")".'</a></li>';
}
$d.='</ul>
';
$em_cache.="<|>".$d;
echo $d;
$cache_file=get_template_directory()."/event_cache/sidebar_cache";
$a_key=fopen($cache_file,"w");
fwrite( $a_key,$em_cache,strlen($em_cache));
fclose($a_key);
}
else echo $file_split[4];
?>
</div>
</div>