* @package cms * @access public */ require_once '../includes/common.php'; if( PROFILER ) $profiler->start(); if( !defined('IN_PLANS_CODE') ) define('IN_PLANS_CODE', 1); require_once '../includes/Smarty_CMS.php'; require_once '../includes/common_activities.php'; require_once '../includes/site/custom_funcs.php'; // For converting the date require_once '../includes/common_vote.php'; // For displaying the messages require_once '../includes/ajax/ajax_functions.php'; // For displaying the messages db_connect(); // login optional $showLogin = FALSE; require_once '../login.php'; /** * Update hit counter for a post id * * This runs an SQL query that will update the `hits` column in the * `activities_objects` table for a given post id. * {@source} * * @access public * @param int $post_id Post ID to update hit counter */ function update_activity_hitcount($post_id) { global $_db, $profiler; if( PROFILER ) $profiler->enterSection('update_activity_hitcount'); $sql = "UPDATE activities_objects SET hits=hits+1" . " WHERE post_id=$post_id"; $result = $_db->query($sql); if( DB::isError($result) ) die('update_activity_hitcount() failed: ' . $result->getMessage()); if( PROFILER ) $profiler->leaveSection('update_activity_hitcount'); } /** * Display contents of an activity * * This function will get the activity's data from the database and display * that data. * {@source} * * @access public * @see array_unshift_assoc() * @param int $post_id ID of activity to display */ function display_activity( $post_id, $page=1 ) { global $_db, $_auth, $profiler; if( PROFILER ) $profiler->enterSection('display_activity'); if( is_null($page) ) $page = 1; $act_data = get_activity_data( $post_id ); $tpl = new Smarty_CMS; if( is_null($act_data) ) { die( "
This post has been deleted
"); } // Grab off the referring page and if it is activities_list.php // provide a link back to the search results if( isset($_SERVER['HTTP_REFERER']) ) { $ref_url = parse_url($_SERVER['HTTP_REFERER']); if( $ref_url['path'] == "/plans/activities_list.php" ) { $tpl->assign('back_to_search', $_SERVER['HTTP_REFERER']); } } // Grab off the date_posted $foo = array(); $bar = array(); $date_posted = convertDate('display_object_no_time', $act_data['date_posted'], NULL, NULL, $foo, $bar); $tpl->assign('date_posted', $date_posted); // Grab off the created_user_name and id $owner_name = $act_data['username']; $owner_id = $act_data['user_id']; if( isset($act_data['avatar']) ) $tpl->assign('owner_avatar', $act_data['avatar']); if( isset($act_data['hits']) ) $tpl->assign('hit_count', $act_data['hits']); // REPLY/MESSAGE CODE HERE $messages = get_activity_discussion_messages($post_id, $page); $numrows = $_db->getOne('SELECT FOUND_ROWS()'); if( DB::isError($numrows) ) die('display_activity() failed: ' . $numrows->getMessage()); $pager = pager(DISCUSSION_PER_PAGE, $numrows, false, null, "view_activity.php?post_id=$post_id&page=%d#messages", "page", $page); $num_messages = count($messages); $tpl->assign('message_count', $num_messages); $tpl->assign('page', $page); $attendees = array(); for( $i=0; $i < $num_messages; $i++ ) { $foo = array(); $bar = array(); $messages[$i]['submission_date'] = convertDate('display_object', $messages[$i]['submission_date'], NULL, NULL, $foo, $bar); // Convert newlines to
s if( isset($messages[$i]['message_body']) ) $messages[$i]['message_body'] = nl2br($messages[$i]['message_body']); if( $messages[$i]['will_attend'] == 1 ) $attendees[$messages[$i]['user_id']] = $messages[$i]['username']; } $tpl->assign('attendees', $attendees); $tpl->assign('num_attendees', count($attendees) ); $tpl->assign('messages', $messages); $tpl->assign('pager', $pager['html']); if( $_auth->getAuth() ) $cur_user_id = $_auth->getAuthData('user_id'); if ( isset($cur_user_id) ) $tpl->assign('user_id', $cur_user_id); // Grab the display data from the db $cols = get_activity_display_cols(); foreach( $cols as $col_data ) { $view[] = array( 'attribute_col_name' => $col_data['attribute_col_name'], 'attribute_display_name' => $col_data['attribute_display_name'] ); $view_data[] = array( $col_data['attribute_col_name'] => $act_data[$col_data['attribute_col_name']]); } //Latitude and Longitide become one variable: lat/long $latitude = 0; $longitude = 0; if ( isset($act_data['latitude']) && isset($act_data['longitude']) ) { $latitude = $act_data['latitude']; //Save these to be sent to the template $longitude = $act_data['longitude']; } // Reformat the "continent, country, and state_province" into one data // structure called Location if( isset($act_data['state_province']) && isset($act_data['country']) ) { array_unshift($view, array('attribute_col_name' => 'location', 'attribute_display_name' => 'Location')); array_unshift($view_data, array('location' => $act_data['location'] = str_replace(', ', '/', $act_data['state_province']) . ', ' . str_replace(', ', '/', $act_data['country']))); } elseif( isset($act_data['state_province']) ) { array_unshift($view, array('attribute_col_name' => 'location', 'attribute_display_name' => 'Location')); array_unshift($view_data, array('location' => $act_data['location'] = str_replace(', ', '/', $act_data['state_province']))); } elseif( isset($act_data['country']) ) { array_unshift($view, array('attribute_col_name' => 'location', 'attribute_display_name' => 'Location')); array_unshift($view_data, array('location' => $act_data['location'] = str_replace(', ', '/', $act_data['country']))); } // Take care of the "when" data if ( $act_data['range_type'] == "Anytime" ) { array_unshift($view, array('attribute_col_name' => 'date', 'attribute_display_name'=>'Date')); array_unshift($view_data, array('date' => $act_data['date'] = $act_data['range_type']) ); } elseif ( $act_data['range_type'] == "Between" ) { $foo = array(); $bar = array(); $begin_date = convertDate('display_object_no_time', $act_data['begin_date'], NULL, NULL, $foo, $bar); $end_date = convertDate('display_object_no_time', $act_data['end_date'], NULL, NULL, $foo, $bar); array_unshift($view, array('attribute_col_name' => 'date', 'attribute_display_name'=>'Dates')); array_unshift($view_data, array('date' => $act_data['date'] = $begin_date . ' through ' . $end_date)); } else { $foo = array(); $bar = array(); $date = convertDate('display_object_no_time', $act_data['begin_date'], NULL, NULL, $foo, $bar); array_unshift($view, array('attribute_col_name' => 'date', 'attribute_display_name'=>'Date')); array_unshift($view_data, array('date' => $act_data['date'] = $act_data['range_type'] . ' ' . $date)); } foreach( $view as $col_data ) { $name = $col_data['attribute_col_name']; if( $name == 'body' || $name == 'title' || $name == 'latitude' || $name == 'longitude' || $name == 'state_province' || $name == 'country' || $name == 'continent') { continue; } $view_column_names[] = $col_data['attribute_display_name']; } foreach( $view_data as $act_data ) { foreach( $act_data as $key => $value ) { if( $key == 'body' ) { $body = nl2br($value); continue; } elseif( $key == 'title' ) { $title = $value; continue; } elseif( $key == 'latitude' || $key == 'longitude' || $key == 'state_province' || $key == 'country' || $key == 'continent') { continue; } $view_column_values[] = $value; } } $tpl->assign('post_id', $post_id); $tpl->assign('latitude', $latitude); $tpl->assign('longitude', $longitude); $tpl->assign('view_column_names', $view_column_names); $tpl->assign('view_column_values', $view_column_values); $tpl->assign('title', $title); $tpl->assign('body', $body); $tpl->assign('owner_id', $owner_id); $tpl->assign('owner_name', $owner_name); $tpl->assign('system_quote', get_random_quote($owner_id)); $tpl->assign('map_key', GOOGLE_MAPS_KEY); if( $_auth->getAuth() ) { $is_owner = is_owner($post_id, $_auth->getAuthData('user_id')); $is_elf = is_elf(); $tpl->assign('logged_in', true); $tpl->assign('user_id', $_auth->getAuthData('user_id')); $tpl->assign('is_owner', $is_owner); $tpl->assign('is_elf', $is_elf); if( $owner_id == (int)$_auth->getAuthData('user_id') ) $tpl->assign('is_deletable', true); if( !$is_owner && !($owner_id == (int)$_auth->getAuthData('user_id')) ) update_activity_hitcount($post_id); } else { $tpl->assign('logged_in', 0); update_activity_hitcount($post_id); } $tpl->display('view_activity.tpl'); if( PROFILER ) $profiler->leaveSection('display_activity'); } $tpl = new Smarty_CMS; $tpl->assign('logged_in', $_auth->getAuth()); $tpl->assign('site_name', SITE_NAME); $tpl->assign('ajax_js', 1); $tpl->assign('use_map', 1); if( $_auth->getAuth() ) { $priv_msgs = get_phpbb_private_messages($_auth->getAuthData('user_id')); $tpl->assign('num_priv_msgs', $priv_msgs['count']); $tpl->assign('username', $priv_msgs['username']); } if( $_SERVER['REQUEST_METHOD'] == 'GET' && isset($_GET['post_id']) ) { $temp_user_id = $_auth->getAuthData('user_id'); if( isset($_GET['post_id']) ) if( isset($_GET['action']) && $_GET['action'] == 'delete' ) if( is_elf() || is_owner($_GET['post_id'], $temp_user_id) ) delete_activity((int)$_GET['post_id']); // Grab off the confirmation number to know what message // to display MDM 12-19-05 if( isset($_GET['confirm_post']) ) $tpl->assign('confirm_post', $_GET['confirm_post']); $post_id = (int)$_GET['post_id']; $activity_title = get_activity_title($post_id); $tpl->assign('title_string', $activity_title); #SEO Additions Matt 10-22-2010 $tpl->assign('canonical_url', SITE_URL . "/plans/" . make_optimized_html_link($activity_title) . "/" . $post_id); $meta_description = "$activity_title : MBPost.com : Mountain Biking, Downhill, Trails, Parks, Areas"; $keywords = preg_split("/\s+/", $activity_title); $meta_keywords = ""; foreach( $keywords as $index => $data ) { $meta_keywords .= $data . ", "; } $meta_keywords .= "partners, group, mountain biking, downlhilling, bike riding, riding, mountains, trails, mbpost, mtbpost"; $tpl->assign('meta_description', $meta_description); $tpl->assign('meta_keywords', $meta_keywords); $tpl->display('site/header_partners.tpl'); display_activity($post_id, isset($_GET['page']) ? (int)$_GET['page'] : NULL ); } if( $_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['post_message']) && isset($_POST['post_id']) ) { // Add flags to display messages for new G-mail style messaging system MDM 12-19-05 $posted = false; if( trim($_POST['title']) != "" && trim($_POST['message']) != "" ) { $disc_id = insert_activity_discussion((int)$_POST['post_id'], $_POST['title'], $_POST['message'], isset($_POST['will_attend']) ? (int)$_POST['will_attend'] : NULL, isset($_POST['parent_id']) ? (int)$_POST['parent_id'] : 0); $posted = true; } if( $posted ) $confirm = 4; else $confirm = 6; header('Location: /plans/view_activity.php?post_id=' . $_POST['post_id'] . '&confirm_post=' . $confirm); } if( PROFILER ) { $profiler->stop(); $profiler->display(); }