becomes \n\n function htmltotext($data) { $data = eregi_replace("

", "\n\n", $data); $data = eregi_replace("<[^>]*>", "", $data); return $data; } function htmlfriendly($var,$nl2br = false){ $chars = array( /* 128 => '€', 130 => '‚', 131 => 'ƒ', 132 => '„', 133 => '…', 134 => '†', 135 => '‡', 136 => 'ˆ', 137 => '‰', 138 => 'Š', 139 => '‹', 140 => 'Œ', 142 => 'Ž',*/ 145 => '‘', 146 => '’', 147 => '“', 148 => '”' /* 149 => '•', 150 => '–', 151 => '—', 152 => '˜', 153 => '™', 154 => 'š', 155 => '›', 156 => 'œ', 158 => 'ž', 159 => 'Ÿ' */); $var = str_replace(array_map('chr', array_keys($chars)), $chars, $var); if($nl2br){ return nl2br($var); } else { return $var; } } //pretty self explanitory--in alphabetical order by state name function stateName($statename) { $states = array ( "AL" => "Alabama", "AK" => "Alaska", "AZ" => "Arizona", "AR" => "Arkansas", "CA" => "California", "CO" => "Colorado", "CT" => "Connecticut", "DE" => "Delaware", "DC" => "District of Columbia", "FL" => "Florida", "GA" => "Georgia", "HI" => "Hawaii", "ID" => "Idaho", "IL" => "Illinois", "IN" => "Indiana", "IA" => "Iowa", "KS" => "Kansas", "KY" => "Kentucky", "LA" => "Louisiana", "ME" => "Maine", "MD" => "Maryland", "MA" => "Massachusetts", "MI" => "Michigan", "MN" => "Minnesota", "MO" => "Missouri", "MS" => "Mississippi", "MT" => "Montana", "NE" => "Nebraska", "NV" => "Nevada", "NH" => "New Hampshire", "NJ" => "New Jersey", "NM" => "New Mexico", "NY" => "New York", "NC" => "North Carolina", "ND" => "North Dakota", "OH" => "Ohio", "OK" => "Oklahoma", "OR" => "Oregon", "PA" => "Pennsylvania", "RI" => "Rhode Island", "SC" => "South Carolina", "SD" => "South Dakota", "TN" => "Tennessee", "TX" => "Texas", "UT" => "Utah", "VT" => "Vermont", "VA" => "Virginia", "WA" => "Washington", "WV" => "West Virginia", "WI" => "Wisconsin", "WY" => "Wyoming"); return $states[$statename]; } ?> "; return; } $row = mysql_fetch_array($result); return $row["displayname"]; } //end function getRaceName($race) // function getElectionAnalysis($election) // Return the election analysis from a query of the elections table // function getElectionAnalysis($election) { global $connection; $query = <<"; return; } $row = mysql_fetch_array($result); return $row["analysis"]; } //end function getElectionAnalysis($election) // function getState($election, $state) // getState returns a MYSQL query with either: a row from the races table corresponding // to the requested election and state, all rows from the races table corresponding to the // requested election, or nothing due to an error // function getState($election, $electionYear, $state) { global $connection; //the connection to the database //if $state=='' then give us all states and districts if ($state == '') { $query= <<\n"; echo "There are no races"; exit; return; } return $result; } //end function getState($state); // getStateCands returns a MYSQL query result of rows from the candidates table // that match the election, state and district // function getStateCands($race_id) { global $connection; //the connection to the database $query = <<"; return; } return $result; } // end function getStateCands($state, $district); // function displayState($election, $stateinfo, $candinfo) // returns text to show, doesn't actually display // 1. Load analysis updates into $updates // 2. Setup the state information // 3. Get the first analysis update (if it exists) // 4. Display the race analysis // 5. Display the rest of the analysis updates // 6. Clean up function displayState($election, $stateinfo, $candinfo) { //get the analysis updates, updated to use race_id $updates = getAnalysisUpdates($stateinfo["race_id"]); $statename = stateName($stateinfo["state"]); if ($stateinfo["district"] != "") $district = "($stateinfo[district])"; if ($stateinfo["open"] == "yes") $open = "(Open Seat)"; $out = <<

$statename $district $open

Outlook: $stateinfo[outlook]


EOE; $out .= $stateinfo["stickymessage"]; //get the first update if ($updates) { while($update = mysql_fetch_array($updates)) { $date = shorttolongdate($update["date_published"]); $out .= "

$date Update:

$update[analysis]\n
"; } $out .= <<
EOE; } $out .= $stateinfo["background"]; //the rest of the updates //while ($update = mysql_fetch_array($updates)) { // $date = shorttolongdate($update["updated"]); // $out .= "
\n

$date Update:

$update[analysis]\n"; // } //do that thing with the candidates $out.= <<

Candidates

EOE; while ($cands = mysql_fetch_array($candinfo)) { if ($cands["incumbent"] == "yes") $incumbent = "(I)"; else $incumbent = ""; if (strlen($cands["bio"]) > 2) $bio = "- $cands[bio]"; else $bio = ""; $out .= << $cands[candidate] $incumbent - $cands[party] $bio
EOE; if ($cands["website"]) { $out .= "Website"; } $out.= << EOE; } $out.= "\n\n\n\n\n"; return $out; } //end function displayState($election, $state, $cands) function displayStateRSS($election, $stateinfo, $raceYear) { $replaceThis = array("<", ">"); $replaceWith = array("<", ">"); //get the analysis updates, updated to use race_id $updates = getAnalysisUpdates2($stateinfo["race_id"]); $statename = stateName($stateinfo["state"]); if ($stateinfo["district"] != "") $district = "($stateinfo[district])"; if ($stateinfo["open"] == "yes") $open = "(Open Seat)"; $outlook = $stateinfo[outlook]; //get the first update if ($updates) { $returnMe = array(); while($update = mysql_fetch_array($updates)) { $dateshort = $update["date_published"]; $date = shorttolongdate($update["date_published"]); $content = ""; $content .= ""; $content .= "$statename $district - $date "; $content .= "http://centerforpolitics.org/crystalball/$raceYear/$election/?state=$stateinfo[state]"; $thisUpdate = $update[analysis]; $thisUpdate = str_replace($replaceThis, $replaceWith, $thisUpdate); $content .= "<p>Outlook: $outlook</p> $thisUpdate"; $content .= "$date"; $content .= ""; $arrayItem = array($dateshort => $content); array_push_associative($returnMe, $arrayItem); } } return $returnMe; } //end function displayStateRSS // function getAnalysisUpdates($election, $state, $district) // Return a MYSQL query result of rows from the analysisupdates table // that match the election, state and district function getAnalysisUpdates($race_id) { echo "\n"; global $connection; $query = <<\n"; return; } $num = mysql_num_rows($result); echo ""; return $result; } //end function getAnalysisUpdates($election, $state, $district) function getAnalysisUpdates2($race_id) { global $connection; $query = <<\n"; return; } return $result; } //end function getAnalysisUpdates($election, $state, $district) // function printArticle($id) // // function printArticle($id) { global $CONTENTPATH; $article = new Article ("$CONTENTPATH/articles/$id.xml"); global $connection; $query = <<"; return; } $row = mysql_fetch_array($result); //overly complex way to use the date function $date = shorttolongdate($article->date); $data = <<$article->title

$article->subtitle

$article->header

EOE; foreach($article->section as $key=>$value) { $data .= << $value EOE; } $data .= << $article->footer

EOE; $data = convertTags($data); return $data; } //end function printArticle($id) // function printRace($election, $state) // // function printRace($election, $stateinfo, $candinfo) { $updates = getAnalysisUpdates($election, $stateinfo["state"], $stateinfo["district"]); $statename = stateName($stateinfo["state"]); if ($stateinfo["district"] != "") $district = "($stateinfo[district])"; else $district = ""; if ($stateinfo["open"] == "yes") $open = "(Open Seat)"; else $open = ""; $out .= <<$statename $district $open

Outlook: $stateinfo[outlook]

EOE; //get the first update if ($updates) { $update = mysql_fetch_array($updates); $date = shorttolongdate($update["updated"]); $out .= "$date Update: $update[analysis]\n
\n\n"; } $out .= $stateinfo["analysis"]; //the rest of the updates while ($update = mysql_fetch_array($result)) $out .= "
\n$date Update: $update[analysis]\n"; //candidates $out.= <<Candidates

EOE; while ($cands = mysql_fetch_array($candinfo)) { if ($cands["incumbent"] == "yes") $incumbent = "(I)"; else $incumbent = ""; if (strlen($cands["bio"]) > 2) $bio = "- $cands[bio]"; else $bio = ""; $out .= << $cands[candidate] $incumbent - $cands[party] $bio
Website

EOE; } return $out; } //end function printRace($election, $state) function array_push_associative(&$arr) { $args = func_get_args(); foreach ($args as $arg) { if (is_array($arg)) { foreach ($arg as $key => $value) { $arr[$key] = $value; $ret++; } }else{ $arr[$arg] = ""; } } return $ret; } ?> ", "

", $text); $text = eregi_replace("", "

", $text); $text = eregi_replace("", "", $text); return $text; } //end function convertTags($text) // function displayPage($title, $keywords, $location $content, $email, $print, $resources, $category) // // function displayPage($title, $keywords, $location, $content, $email, $print, $resources, $category) { //pick up the path to the cb global $CBPATH; //convert xml to html $content = convertTags($content); echo << Newsroom, Crystal Ball, U.Va. EOE; require_once('/web/centerforpolitics.org/doc/crystalball/js/functions.js'); echo << EOE; require_once('/web/centerforpolitics.org/doc/crystalball/includes/header.php'); echo <<
$content EOE; require_once('/web/centerforpolitics.org/doc/crystalball/includes/signup.html'); require_once('/web/centerforpolitics.org/doc/crystalball/includes/book.html'); require_once('/web/centerforpolitics.org/doc/crystalball/includes/news.php'); echo <<
EOE; $footer = @file("/web/centerforpolitics.org/doc/crystalball/includes/footer.html"); $footer = join('', $footer); $exp = "//"; $mtime = date("l, d-M-Y h:i:s", filemtime(__FILE__)) . " EDT"; $footer = preg_replace($exp, $mtime, $footer); $exp = "/ */"; $the_year = date("Y"); $footer = preg_replace($exp, $the_year, $footer); echo $footer; echo << EOE; } //end function displayPage($content, $email, $print, $resources, $category) ?>