/** * Vectors project page front controller */ require('../common/db/vectors_v2.php'); require('../common/php_header.php'); include('../common/redirect_old_page_numbers.php'); require(DOCROOT.'/common/classes/Project.php'); require(DOCROOT.'/common/classes/Issue.php'); require(DOCROOT.'/common/classes/ForumUser.php'); $user = new ForumUser(); $project_id =@ (int) $_REQUEST['project']; $project_title =@ trim($_REQUEST['title']); $thread_anchor =@ trim($_REQUEST['thread']); // TODO :base this on the XML $thread_title = null; $source =@ trim($_REQUEST['source']); if (empty($source)) $source =@ $_SERVER['HTTP_REFERER']; $action =@ trim($_REQUEST['action']); $redirect_url =@ trim(urldecode($_REQUEST['redirect_url'])); $screen =@ trim($_REQUEST['screen']); $error = null; define('DEBUG', @(1==$_REQUEST['debug'])?true:false); if (empty($project_id)) header('Location: ../issues'); if ($action == 'add_thread' || $action == 'add_post') { if (!$user->is_logged_in) { $location = 'Location: '.$_SERVER['PHP_SELF'].'?'.returnGet('action', 'redirect_url').'&action=login&redirect_url='.urlencode($_SERVER['PHP_SELF'].'?'.returnGet('redirect_url')); header($location); } } try { $project = new Project($project_id); } catch (Exception $e) { $error = $e->getMessage(); echo '

Problem loading project data. '.$error.'. Please try again.

'; exit; } $issue = null; if ($project->issue_id > 0) { try { $issue = new Issue($project->issue_id); } catch (Exception $e) { $error = $e->getMessage(); // don't display error } } if ($action == 'do_logout') { try { $user->logout(); print_r($_GET); $redirect_url = (!empty($redirect_url)) ? $redirect_url : $_SERVER['PHP_SELF'].'?project='.$project_id; $location = "Location: $redirect_url"; header($location); } catch (Exception $e) { $error = $e->getMessage(); } } elseif ($action == 'do_login') { try { $user_id = $user->login(); $redirect_url = (!empty($redirect_url)) ? $redirect_url : $_SERVER['PHP_SELF'].'?project='.$project_id; $location = "Location: $redirect_url"; header($location); } catch (Exception $e) { $login_error = $e->getMessage(); } } elseif ($action == 'do_change_password') { $change_password_confirm = false; try { $user->change_password(); $change_password_confirm = true; } catch (Exception $e) { $change_password_error = $e->getMessage(); } } elseif ($action == 'do_update_profile') { $update_profile_confirm = false; try { $user->update_profile(); $update_profile_confirm = true; } catch (Exception $e) { $update_profile_error = $e->getMessage(); } } elseif ($action == 'do_forgot_login') { $forgot_login_confirm = false; try { $user->reset_password(true); $forgot_login_confirm = true; } catch (Exception $e) { $forgot_login_error = $e->getMessage(); } } elseif ($action == 'do_register') { try { $user_id = $user->register(); $user_id = $user->login(); $redirect_url = (!empty($redirect_url)) ? $redirect_url : $_SERVER['PHP_SELF'].'?project='.$project_id; $location = "Location: $redirect_url"; header($location); } catch (Exception $e) { $register_error = $e->getMessage(); } } elseif ($action == 'do_add_thread') { $thread_title = $_POST['thread_title']; $thread_firstpost = $_POST['thread_firstpost']; try { $anchor = $project->createNewThread($thread_title, $thread_firstpost); $location = 'Location: '.$_SERVER['PHP_SELF'].'?project='.$project_id.'&thread='.$anchor; header($location); } catch (Exception $e) { $error = $e->getMessage(); } } elseif ($action == 'do_add_post') { $content = $_POST['content']; try { $post_id = $project->createNewPost($thread_anchor, $content); $location = 'Location: '.$_SERVER['PHP_SELF'].'?project='.$project_id.'&thread='.$thread_anchor.'#post_'.$post_id; header($location); } catch (Exception $e) { $error = $e->getMessage(); } } // Validate page anchor and thread $anchors = array(); $threads = (is_object($project->threads)) ? $project->threads->thread : array(); foreach ($threads as $thread) { $anchors[] = (string) $thread['anchor']; } $current_thread_is_user_created = false; if (is_object($project->threads)) { $selected_thread = $project->threads->xpath("//thread[@anchor='".$thread_anchor."']"); // Special considerations for Project Credits (an auto-generated anchor) if ($thread_anchor == 'ProjectCredits') { $thread_title = 'Project Credits'; // if not a valid anchor passed, select the first from the thread array } elseif (count($selected_thread) == 0 || empty($selected_thread[0])) { $thread_title = $project->threads->thread[0]['title']; $thread_anchor = $project->threads->thread[0]['anchor']; // Grab the title for a valid anchor } else { $thread_title = $selected_thread[0]['title']; } // is the current thread being viewed (if any) user created? $current_thread_is_user_created = (isset($test[0]) && 1==$test[0]['is_user_created']) ? true : false; unset($selected_thread); } // Authors $primary_authors = $secondary_authors = array(); if (is_object($project->authors)) { $authors = $project->authors->xpath("//author[@is_primary='1']"); foreach ($authors as $author) { $primary_authors[] = (string) $author['fullname']; } $authors = $project->authors->xpath("//author[@is_secondary='1']"); foreach ($authors as $author) { $secondary_authors[] = (string) $author['fullname']; } } // Select a random excerpt $rand_excerpt = (is_object($project->excerpts)) ? $project->excerpts->excerpt[rand(0, (count($project->excerpts->excerpt)-1))] : array(); // Current page style sheet $screen_style_sheet_path =@ (string) $project->screen_style_sheet_path; $screen_style_sheet_path = (!empty($screen_style_sheet_path)) ? trim($screen_style_sheet_path) : 'inc/css/screen_dark.css'; // Last post? $user_last_post = 0; if ($user->is_logged_in) { $posts_by_user = $project->threads->xpath("//post[@created_by_fullname='$user->fullname']"); $user_last_post = (count($posts_by_user)>0) ? $posts_by_user[(count($posts_by_user)-1)]['post_id'] : 0; // TODO: expire after a few minutes unset($posts_by_user); } $thoughtmesh_document_id =@ (int) $project->meta->thoughtmesh_document_id; // Meta tag description $meta_desc = 'Conversation and information about the Vectors Journal project '.((!empty($project->title))?strip_tags(trim($project->title)):'').((!empty($project->subtitle))?': '.trim(strip_tags($project->subtitle)):''); if (is_object($project->threads)) { $test = $project->threads->xpath("//thread[@anchor='ProjectAbstract']"); if (count($test) > 0 && !empty($test[0])) { $meta_desc = (string) $test[0]->posts->post[0]; $meta_desc = str_replace("\r", '', str_replace("\n", ' ', str_replace('"', '"', strip_tags($meta_desc)))); } } // Insert issue template require($project->project_template_path); exit; ?>