isNew()) { //feature_version with this id doesn't exist
error_404("Feature does not exist.");
}
} else if (not_empty_array_key_exists("PATH_INFO", $_SERVER)) {
$ftrv_identifier = substr($_SERVER["PATH_INFO"], 1);
if (preg_match("/^(.*)\/$/", $ftrv_identifier, $Matches)) {
$ftrv_identifier = $Matches[1];
}
if (strlen($ftrv_identifier) < 3) {
error_404("Bad PATH_INFO lookback string");
}
$feature_version = Feature_version::getActiveFtrvByIdentifier($ftrv_identifier);
if (empty($feature_version)) { //active feature_version with this
//identifier doesn't exist or is not active
error_404("Feature does not exist or is not active.");
}
} else {
//feature_version id is missing
error_404("Feature ID or identifier is missing.");
}
//If ftrv_url is populated, then send an HTTP redirect to ftrv_url
if (!empty($feature_version->ftrv_url)) {
print_header_redirect($feature_version->ftrv_url);
}
//get the display datetime from URL. Only internal users can choose a display_datetime
if (not_empty_array_key_exists("datetime", $_REQUEST) && is_login()) {
$display_datetime = urldecode($_REQUEST["datetime"]);
} else {
$display_datetime = date("Y-m-d H:i:s");
}
$smarty->assign('display_datetime',$display_datetime);
//get the collections associated with this particular feature version
$FeatureVersion_collections = $feature_version->getCollections();
$smarty->assign('FeatureVersion_collections',$FeatureVersion_collections);
// var_dump($FeatureVersion_collections);
/*
* Get all MPR News Topics for IBSys Underwriting.
* Topics are translated from collection IDs assigned to this feature.
* Topics are typically displayed on the front-end as meta tags in the header.
*/
$featureTopics = array();
foreach ($FeatureVersion_collections as $collection) {
// echo "This feature belongs to collection {$collection->coll_name} with collection ID of {$collection->coll_id}.
"; // debug
$item = new topicMap();
$item->id = $collection->coll_id;
// echo "{$item->describe()}
"; // debug
if($item->map() && !in_array($item->map(), $featureTopics)) {
$featureTopics[] = $item->map();
}
}
$smarty->assign('featureTopics', $featureTopics);
if (empty($feature_version->ftrv_ca_id)) {
error_404("Feature does not have an associated content area.");
} else if (!in_array($feature_version->ftrv_ca_id, $contentAreaIdArray)) {
//don't display this feature if it doesn't belong to the specified content areas.
error_404("Feature is not part of the regional content area");
}
//need to transfer the display datetime back to original DB datetime for smarty
$feature_version->ftrv_publish_dtim = display_date_to_any_date($feature_version->ftrv_publish_dtim,"Y-m-d H:i:s",true);
$ftrv_audios = $feature_version->getAudioDisplayInfo("", "fau_order","",$display_datetime);
if (count($ftrv_audios) > 0) {
$smarty->assign('is_audio', "yes");
} else {
$smarty->assign('is_audio', "no");
}
// Because these are different for NewsQ, define them here rather than use the globals
$newsq_feature_paragraph_image_type["default"] = array(APMG_STD_SMALL); //1
//$newsq_feature_paragraph_image_type["0"] = array(MPR_NEWSQ_STORY_BOOK_COVER); //57
$newsq_feature_paragraph_image_type["0"] = array(MPR_NEWSQ_STORY_BOOK_COVER,MPR_NEWSQ_STORY_PAGE); //39
$classical_feature_paragraph_image_type["default"] = array(APMG_STD_SMALL);
$classical_feature_paragraph_image_type["0"] = array(MPR_CLASSICAL_MAIN_HORIZ);
$current_feature_paragraph_image_type["default"] = array(APMG_STD_SMALL);
$current_feature_paragraph_image_type["0"] = array(MPR_CURRENT_MAIN_HORIZ);
//figure out subject codes for redirect below, and also for in the smarty templates
$subList = $feature_version->getPartnersByTableName('subject_codes', '', 'subj_description');
$ftrv_subjects = array();
foreach ($subList as $sub) {
$ftrv_subjects[$sub->subj_code] = $sub->subj_description;
}
$smarty->assign('ftrv_subjects', $ftrv_subjects);
/********************
Redirects for MPRnews.org feature/story pages
********************/
//Content area 2 is MPRNews
if (intval($feature_version->ftrv_ca_id) === 2){
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.mprnews.org/story/".$ftrv_identifier);
exit();
}
/********************
Redirects for ClassicalMPR.org feature/story pages
********************/
//Content area 99 is Classical MPR
if (intval($feature_version->ftrv_ca_id) === 99){
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.classicalmpr.org/story/".$ftrv_identifier);
exit();
}
/********************
Redirects for www.thecurrent.org being broken off from minnesota.publicradio.org
These need to be in php so we can send proper 301 headers.
********************/
//Content area 89 is The Current content area
if ($feature_version->ftrv_ca_id == 89 ||
array_key_exists(463, $ftrv_subjects) ||
array_key_exists(229, $ftrv_subjects) ||
array_key_exists(377, $ftrv_subjects) ||
array_key_exists(123, $ftrv_subjects) ||
array_key_exists(124, $ftrv_subjects) ||
array_key_exists(125, $ftrv_subjects)){
//redirect using slug/identifier
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.thecurrent.org/feature/".$ftrv_identifier);
exit();
}
/******* end www.thecurrent.org redirects */
$smarty->assign('feature_version', new SmartyDBMap($feature_version));
$smarty->assign('project_image_types', $g_project_image_types);
$smarty->assign('g_image_base_url', $g_image_base_url); //used in ftrv_project_header.tpl
$smarty->assign('g_slideshow_image_type', $g_slideshow_image_type);
$smarty->assign('g_new_slideshow_image_type', array(MPR_EXTRA_LARGE_SLIDE,APMG_STD_LARGE_HORIZ,APMG_STD_LARGE_VERT));
$smarty->assign('g_max_num_of_images_displayed_in_feature_sidebar', $g_max_num_of_images_displayed_in_feature_sidebar);
$smarty->assign('g_image_base_url', $g_image_base_url);
$smarty->assign('g_feature_paragraph_image_type', $g_feature_paragraph_image_type);
$smarty->assign('newsq_feature_paragraph_image_type', $newsq_feature_paragraph_image_type);
$smarty->assign('classical_feature_paragraph_image_type', $classical_feature_paragraph_image_type);
$smarty->assign('current_feature_paragraph_image_type', $current_feature_paragraph_image_type);
$smarty->assign('g_prefered_book_type', $g_prefered_book_type);
$smarty->assign('video_allowed_image_types', array(APMG_STD_LARGE_HORIZ));
$smarty->assign("minnesota_in_photos_slideshow_image_types", array(53));
$smarty->register_modifier('timecode_links','timecode_links'); //smarty filter we add to change timecodes into specially formatted links
$smarty->register_modifier('phone_format', 'smarty_modifier_phone_format'); //smarty filter we add to filter phone number
$smarty->register_modifier('first_sentence', 'smarty_modifier_first_sentence'); //smarty filter we add to help getting the first sentence of any text
if (strtoupper(substr($feature_version->ftrv_external_ref, 0, 4)) === 'NPR:') {
// This is an NPR feature and should be treated differently.
include_once('npr/npr.inc');
} else {
$smarty->display("web.tpl");
}
//No feature found, display error page instead
function error_404($message) {
global $smarty;
header("HTTP/1.0 404 Not Found");
$smarty->assign('message', $message);
$smarty->display('../error.tpl');
exit;
}
function timecode_links($text){
//finds timecodes in text and will replace it with a link
return preg_replace_callback("/(\d{1,2}:)?\d{1,3}:\d{2}/", 'calculate_seconds', $text);
}
function calculate_seconds($matches){
//callback called by timecode_links
$tc = explode(":",$matches[0]);
if (count($tc) == 2){
$secs = $tc[1] + ($tc[0]*60);
} else {
$secs = $tc[2] + ($tc[1]*60) + ($tc[0]*60*60);
}
return "".$matches[0]."";
}
/**
* @descSmarty plugin
* -------------------------------------------------------------
* File: modifier.phone_format.php
* Type: modifier
* Name: format_phone
* Purpose: format a US-style 10-digit phone number
* -------------------------------------------------------------
*
* @param string $number a phone number
* @param $format a printf style format string
* @return string $number, the number formatted if 10 digits, else original untouched.
* @author dmintz@davidmintz.org
*/
function smarty_modifier_phone_format($number, $format="%s-%s-%s") {
$original = $number;
$number = preg_replace("/\D/","",$number);
if (strlen($number) != 10) return $original;
return sprintf(
$format,
substr($number,0,3),
substr($number,3,3),
substr($number,6,4)
);
}
/**
* Smarty first_sentence modifier plugin
*
* Type: modifier
* Name: first_sentence
* Purpose: trim a string to the first sentence
* @link http://www.phpinsider.com/smarty-forum/viewtopic.php?t=10170
* @author Boots
* @param string
* @return integer
*/
function smarty_modifier_first_sentence($string)
{
// find periods with a word before but not after.
preg_match('/^.*[^\s]\.(?!\w)/U', $string, $match);
return $match[0];
}
?>