date_default_timezone_set('America/New_York');
set_time_limit(0);
ini_set('max_input_time',60);
define('SCRIPT_PATH','\\\\sxatl.loc\\tbo\\assets\\HI\\OWSScript\\');
define('DEBUG_PATH','\\\\sxatl.loc\\tbo\\assets\\HI\\OWSScript\\owsDebug\\default\\');
define('SITECODE', 'HI');
define('LOG_DEBUGINFO', false);
function normal_chars($string)
{
$string = htmlentities($string, ENT_QUOTES, 'UTF-8');
$string = preg_replace('~&([a-z]{1,2})(acute|cedil|circ|grave|lig|orn|ring|slash|th|tilde|uml);~i', '$1', $string);
$string = html_entity_decode($string, ENT_QUOTES, 'UTF-8');
$string = preg_replace(array('~[^0-9a-z]~i', '~[ -]+~'), ' ', $string);
return trim($string, ' -');
}
function var_to_str($in) {
if(is_bool($in)) {
if($in)
return "true";
else
return "false";
} else
return $in;
}
/***********************************************
* return the value of an extra field
*
***********************************************/
function getStoryExtraFieldValue($storyDoc, $extFieldName) {
$result = '';
$debugstring = 'Getting extraFieldvalue for ' . $extFieldName . '\r\n';
$extraFieldList = $storyDoc->xpath('/onl:story/onl:content/onl:extrafields/onl:extrafield');
if ($extraFieldList) {
try {
foreach($extraFieldList as $extraField) {
$myExtraFieldName = $extraField[0]->xpath('.//onl:key');
$myExtraFieldValueDebug = $extraField[0]->xpath('.//onl:value');
$debugstring = $debugstring . '$extraFieldName = ' . implode('', $myExtraFieldName) . ' $extraFieldValueDebug = ' . implode('', $myExtraFieldValueDebug) . '\r\n';
if ($myExtraFieldName[0] == $extFieldName){
//$debugstring = $debugstring . 'found extra fieldname with value: ' . $myExtraFieldValueDebug[0] . '\r\n';
$result = implode('', $myExtraFieldValueDebug);
break;
} else {
$debugstring = $debugstring . 'name did not match\r\n';
}
}
} catch (Exception $e) {
$debugstring = $debugstring . 'getStoryExtraFieldValue exception: ' . $e->getMessage();
}
}
if (LOG_DEBUGINFO) {
$SOSE->debug(DEBUG_PATH.'getStoryExtraFieldValue'.date('M_Y').'.txt', $debugstring);
}
return $result;
}
function simplexml_insert_after(SimpleXMLElement $insert, SimpleXMLElement $target)
{
$target_dom = dom_import_simplexml($target);
$insert_dom = $target_dom->ownerDocument->importNode(dom_import_simplexml($insert), true);
if ($target_dom->nextSibling) {
return $target_dom->parentNode->insertBefore($insert_dom, $target_dom->nextSibling);
} else {
return $target_dom->parentNode->appendChild($insert_dom);
}
}
/***************************************************
* getLead: Generate lead from the first 155 char in body
* since we can't use the summary field from MWC.
* 20120918: MY - Added new
**************************************************/
function convertFactBoxToExtraField($storyDoc) {
$debugstring = 'convertFactBoxToExtraField' . '\r\n';
$storyFactBoxes = $storyDoc->xpath('/onl:story/onl:content/onl:paragraphs/onl:paragraph/onl:factbox');
$extraField = $storyDoc->xpath('/onl:story/onl:content/onl:extrafields/onl:extrafield');
$newExtraFieldName = '';
if (isset($storyFactBoxes)) {
try {
foreach($storyFactBoxes as $factBox) {
$factBoxTitle = $factBox[0]->xpath('.//onl:heading');
$factBoxBody = $factBox[0]->xpath('.//onl:body');
$newExtraFieldName = '';
$newExtraFieldValue = $factBoxBody[0];
if ((preg_match('/Clarification/i', $factBoxTitle[0])) ||
(preg_match('/Correction/i', $factBoxTitle[0]))){
$newExtraFieldName = 'Corrections';
} elseif ((preg_match('/Weblinks/i', $factBoxTitle[0])) ||
(preg_match('/ExternalLinks/i', $factBoxTitle[0]))){
$newExtraFieldName = 'ExternalLinks';
} elseif (preg_match('/Infobox(.)/i', $factBoxTitle[0], $matches)){
$newExtraFieldName = $factBoxTitle[0];
// $newExtraFieldName = (substr($factBoxTitle, 0, 7); /* can we do this? what else wd need to change? */
}
try {
if ($newExtraFieldName != '') {
$story = $storyDoc->xpath('/onl:story/onl:content/onl:extrafields');
$newExtraField = $story[0]->addChild('' . $newExtraFieldName . '' . '');
}
} catch (Exception $e) {
$debugstring = $debugstring . 'factboxtoExtraField exception: ' . $e->getMessage();
$SOSE->debug(DEBUG_PATH.'factboxtoExtraField'.date('M_Y').'.txt', $debugstring);
}
}
} catch (Exception $e) {
$debugstring = $bodyelement . 'factboxtoExtraField exception: ' . $e->getMessage();
$SOSE->debug(DEBUG_PATH.'factboxtoExtraField'.date('M_Y').'.txt', $debugstring);
}
}
if (LOG_DEBUGINFO) {
$SOSE->debug(DEBUG_PATH.'factboxtoExtraField'.date('M_Y').'.txt', $debugstring);
}
return $storyDoc;
}
/***********************************************
* create SEO label based on print publication and net title
*
***********************************************/
function addSEOLabel($storyDoc, $onlnetheading, $StoryPublicationDate) {
$debugstring = 'Adding seoLabel publicationdate:' . $StoryPublicationDate . ' netheading: ' . $onlnetheading . '\r\n';
if ($onlnetheading <> '') {
try {
$newSEOLabel = '/' . str_replace(' ', '-', normal_chars($onlnetheading)) . '-' . str_replace('-', '-', substr($StoryPublicationDate, 0, 10)) . '/';
$debugstring .= 'New SEO Link:' . $newSEOLabel . '\r\n';
$seoList = $storyDoc->xpath('/onl:story/onl:metadata/onl:seolabels');
if (!$seoList) {
$debugstring .= $debugstring . 'Creating seolabels node\r\n';
$story = $storyDoc->xpath('/onl:story/onl:metadata');
if ($story) {
$seoList = $story[0]->addChild('onl:seolabels');
}
$seoList = $storyDoc->xpath('/onl:story/onl:metadata/onl:seolabels');
}
if ($seoList) {
$debugstring .= $debugstring . 'Creating seolabel node\r\n';
$seoLabel = $seoList[0]->addChild('onl:seolabel');
$dom = dom_import_simplexml($seoLabel);
$dom->nodeValue = $newSEOLabel;
$dom->setAttributeNode(new DOMAttr('main', '1'));
};
} catch (Exception $e) {
$debugstring .= $debugstring . 'addSEOLabel exception: ' . $e->getMessage();
}
}
if (LOG_DEBUGINFO) {
$SOSE->debug(DEBUG_PATH.'seoLabel'.date('M_Y').'.txt', $debugstring);
}
return $storyDoc;
}
/***********************************************
* replace Incopy tags with HTML tags based on an XML
* 20120511 SX.MY : Adding support to execute replace on multiple fields
* 20120514 SX.MY : Adding support for replacing multiple fields
* changing the structure of InCopyToHTML
* Now using InCopyToHTML-Version2.xml
***********************************************/
function convertInCopyToHTML($storyDoc){
/* read each /xml/fields/field
* id (the field in incopy xml),
* section (the section to read from conversion xml)
* for each id get
*/
$debugstring = '';
if (file_exists(SCRIPT_PATH.'InCopyToHTML.xml')) {
$InCopyToHMTL = simplexml_load_file(SCRIPT_PATH.'InCopyToHTML.xml');
$FieldsToReplaceList = $InCopyToHMTL->xpath('/xml/fields/field');
foreach($FieldsToReplaceList as $FieldsToReplace) {
$XpathInStoryDoc = $FieldsToReplace[0]->xpath('.//@xpath');
$ReplaceRegExp = $FieldsToReplace[0]->xpath('.//@section');
$InCopyReplaceList = $InCopyToHMTL->xpath($ReplaceRegExp[0]);
//$debugstring = $debugstring . 'xpath: ' . $XpathInStoryDoc[0] . '----- section: ' . $ReplaceRegExp[0] ;
$ElementsToReplaceList = $storyDoc->xpath($XpathInStoryDoc[0]);
foreach($ElementsToReplaceList as $ElementsToReplace) {
// $body = $storyParagraph[0]->xpath('.//onl:body');
$bodyelement = $ElementsToReplace[0];
// 20120523 TDang: ??????
//$bodyelement = htmlentities($bodyelement, ENT_QUOTES | ENT_IGNORE, "UTF-8");
$debugstring = $debugstring . $bodyelement . '#13#10';
foreach($InCopyReplaceList as $InCopyReplace) {
$searchfor = $InCopyReplace[0]->xpath('.//search');
$replacewith = $InCopyReplace[0]->xpath('.//replace');
$debugstring = $debugstring . 'looking for: ' . $searchfor[0] . ' replaceing with: ' . $replacewith[0] . '#13#10';
//$SOSE->debug(DEBUG_PATH.'testtest'.date('M_Y').'.txt', $debugstring);
$bodyelement = preg_replace($searchfor[0], $replacewith[0] , $bodyelement, -1);
$debugstring = $debugstring . $bodyelement;
}
try {
//$SOSE->debug(DEBUG_PATH.'convertError'.date('M_Y').'.txt', $ElementsToReplace[0]);
$dom = dom_import_simplexml($ElementsToReplace[0]);
if (isset($dom)) {
$cdata = $dom->ownerDocument->createCDataSection($bodyelement);
$SOSE->debug(DEBUG_PATH.'converted'.date('M_Y').'.txt', $bodyelement);
//$dom->nodeValue = '';
$bodyelementcleaned = str_replace(array("\r\n", "\r", "\n"), "", $bodyelement);
if ($bodyelementcleaned == '') {
$dom->appendChild($cdata);
$debugstring = $debugstring . 'currentOnlinesubheading is empty';
} else {
if (isset($dom->childNodes)) {
$dom->replaceChild($cdata, $dom->childNodes->item(0));
}
}
// if (isset($dom->childNodes)) {
// $dom->replaceChild($cdata, $dom->childNodes->item(0));
// }
}
} catch (Exception $e) {
$debugstring = $bodyelement . 'InCopyToHMTL exception: ' . $e->getMessage();
$SOSE->debug(DEBUG_PATH.'ErrorConvert'.date('M_Y').'.txt', $debugstring);
}
}
}
} else {
$debugstring = $debugstring . SCRIPT_PATH.'InCopyToHTML-Version2.xml' . '\r\n';
}
if (LOG_DEBUGINFO) {
$SOSE->debug(DEBUG_PATH.'InCopyTagReplace'.date('M_Y').'.txt', $debugstring);
}
return $storyDoc;
//return $debugstring;
}
/***************************************************
*
*
**************************************************/
function retainAllTaxonomy($NewstoryDoc, $OldStoryDoc){
$debugstring = '';
// check to verify that top node exists
$ToptaxonomyListNode = $NewstoryDoc->xpath('/onl:story/onl:taxonomywords');
if (!$ToptaxonomyListNode) {
$story = $NewstoryDoc->xpath('/onl:story');
if ($story) {
$taxonomywords = $story[0]->addChild('onl:taxonomywords');
}
$ToptaxonomyListNode = $NewstoryDoc->xpath('/onl:story/onl:taxonomywords');
}
$TaxonomyIDList = $NewstoryDoc->xpath('/onl:story/onl:taxonomywords/onl:taxonomyword');
$orgTaxonomyIDList = $OldStoryDoc->xpath('/onl:story/onl:taxonomywords/onl:taxonomyword');
foreach($orgTaxonomyIDList as $origTaxonomyID) {
$orgTaxonomyID = $origTaxonomyID['id'];
$debugstring = $debugstring . 'orgTaxId:' . $origTaxonomyID['id'] . ',';
$foundOrgTaxonomy = false;
foreach($TaxonomyIDList as $TaxonomyID) {
$taxonomyID = $TaxonomyID['id'];
$debugstring = $debugstring . 'TaxId:' . $TaxonomyID['id'] . ',';
if(strcasecmp($taxonomyID,$orgTaxonomyID)==0){
$foundOrgTaxonomy = true;
break 1;
}
}
// if the taxonomy from the online DB not found then add the taxonomy
if ($foundOrgTaxonomy == false) {
if ($orgTaxonomyID <> '') {
$taxonomyword = $ToptaxonomyListNode[0]->addChild("/onl:taxonomyword");
$taxonomyword->addAttribute('id', $orgTaxonomyID);
}
}
}
return $NewstoryDoc;
}
/***************************************************
* getLead: Generate lead from the first 155 char in body
* since we can't use the summary field from MWC.
* 20120531: TD - Added new
**************************************************/
function getLead($str) {
$str = strip_tags($str, '
');
$arr = explode ('.', $str);
$lead = '';
foreach ($arr as $l) {
$lead .= trim($l) . ".";
if (strlen($lead)>=150) break;
//print "==>$l.\n";
}
$lead = preg_replace('/
/s', ' ', $lead);
return trim($lead);
}
function switchSubheadingWithSummary($NewstoryDoc) {
try {
$debugstring = 'Processing subheading and summary -----';
$onlsummary = $NewstoryDoc->xpath('/onl:story/onl:content/onl:summary');
$onlsubheading = $NewstoryDoc->xpath('/onl:story/onl:content/onl:subheading');
if (!$onlsummary){
$onlContent = $NewstoryDoc->xpath('/onl:story/onl:content');
$newonlSummary = $onlContent[0]->addChild('onl:summary');
$debugstring = $debugstring . 'adding-onl:summary\r\n';
$onlsummary = $NewstoryDoc->xpath('/onl:story/onl:content/onl:summary');
}
if (!$onlsubheading){
$onlContent = $NewstoryDoc->xpath('/onl:story/onl:content');
$newonlSubHead = $onlContent[0]->addChild('onl:subheading');
$debugstring = $debugstring . 'adding-onl:subheading\r\n';
$onlsubheading = $NewstoryDoc->xpath('/onl:story/onl:content/onl:subheading');
}
if ($onlsummary) {
$currentOnlineSummary = $onlsummary[0];
}
if ($onlsubheading) {
$currentOnlinesubheading = $onlsubheading[0];
}
$currentOnlineSummary = str_replace(array("\r\n", "\r", "\n"), "", $currentOnlineSummary);
$currentOnlinesubheading = str_replace(array("\r\n", "\r", "\n"), "", $currentOnlinesubheading);
if ($currentOnlineSummary != '') {
$dom = dom_import_simplexml($onlsummary[0]);
if (isset($dom)) {
$cdata = $dom->ownerDocument->createCDataSection($currentOnlinesubheading);
//??????? does not work
if (isset($dom->childNodes)) {
$dom->replaceChild($cdata, $dom->childNodes->item(0));
}
}
}
if ($currentOnlineSummary != '') {
$dom = dom_import_simplexml($onlsubheading[0]);
if (isset($dom)) {
$cdata = $dom->ownerDocument->createCDataSection($currentOnlineSummary);
//??????? does not work
try {
if ($currentOnlinesubheading == '') {
$dom->appendChild($cdata);
$debugstring = $debugstring . 'currentOnlinesubheading is empty';
} else {
if (isset($dom->childNodes)) {
$dom->replaceChild($cdata, $dom->childNodes->item(0));
}
}
} catch (Exception $e) {
//$debugstring = $currentOnlineNetHeading . 'fixnetheading exception: ' . $e->getMessage();
$SOSE->debug(DEBUG_PATH.'ERROR_CRAP'.date('M_Y').'.txt', $dom->childNodes->item(0));
}
}
}
//$onlsummary[0][0] = '';
//$onlsubheading[0][0] = '';
$debugstring = $debugstring . 'summary:' . '"' . $currentOnlineSummary . '" subheading:' . '"' . $currentOnlinesubheading .'"' .'\r\n';
} catch (Exception $e) {
//$debugstring = $currentOnlineNetHeading . 'fixnetheading exception: ' . $e->getMessage();
$SOSE->debug(DEBUG_PATH.'ERROR_SwitchingSubheader'.date('M_Y').'.txt', $debugstring);
}
if (LOG_DEBUGINFO) {
$SOSE->debug(DEBUG_PATH.'FixingSwitchingSubheader'.date('M_Y').'.txt', $debugstring);
}
return $NewstoryDoc;
}
function fixnetheading($NewstoryDoc) {
try {
$debugstring = 'Processing netheading';
$onlnetheading = $NewstoryDoc->xpath('/onl:story/onl:content/onl:netheading');
if (!$onlnetheading){
$onlContent = $NewstoryDoc->xpath('/onl:story/onl:content');
$newOnlineHeading = $onlContent[0]->addChild('onl:netheading');
$debugstring = $debugstring . 'adding-onl:netheading\r\n';
$onlnetheading = $NewstoryDoc->xpath('/onl:story/onl:content/onl:netheading');
}
if ($onlnetheading) {
$currentOnlineNetHeading = $onlnetheading[0];
}
$currentOnlineNetHeading = str_replace(array("\r\n", "\r", "\n"), "", $currentOnlineNetHeading);
if (ltrim(rtrim($currentOnlineNetHeading)) == "") {
unset($onlnetheading[0][0]);
//$dom=dom_import_simplexml($onlnetheading);
//$dom[0]->nodeValue = $currentOnlineNetHeading;
//$dom->parentNode->replaceChild($currentOnlineNetHeading, $dom->item(0));
$debugstring = $debugstring . 'nettitle removed' . '"' . $currentOnlineNetHeading . '"' . '\r\n';
}
} catch (Exception $e) {
//$debugstring = $currentOnlineNetHeading . 'fixnetheading exception: ' . $e->getMessage();
$SOSE->debug(DEBUG_PATH.'FixnetHeadingError'.date('M_Y').'.txt', $debugstring);
}
if (LOG_DEBUGINFO) {
$SOSE->debug(DEBUG_PATH.'FixingHeading'.date('M_Y').'.txt', $debugstring);
}
return $NewstoryDoc;
}
// ******************************************************** //
// SLG: This function will take value from an extra //
// field and assign it to the article byline. //
// ******************************************************** //
function updateBylineFromExtrafield($NewstoryDoc, $ExtrafieldName) {
try {
$debugstring = 'Processing byline - ExtrafieldName: ' . $ExtrafieldName . '\r\n';
$onlinebyline = $NewstoryDoc->xpath('/onl:story/onl:content/onl:byline');
$metaData = $NewstoryDoc->xpath('/onl:story/onl:metadata');
$ExtrafieldValue = $metaData[0]['columnname'];
$debugstring = '$ExtrafieldValue = ' . $ExtrafieldValue;
//$ExtrafieldValue = 'testtest';
if (!$onlinebyline){
$onlContent = $NewstoryDoc->xpath('/onl:story/onl:content');
$newOnlineByline = $onlContent[0]->addChild('onl:byline');
$debugstring = $debugstring . 'adding-onl:byline\r\n';
$onlinebyline = $NewstoryDoc->xpath('/onl:story/onl:content/onl:byline');
}
if ($onlinebyline) {
$currentOnlineByline = $onlinebyline[0];
}
if (trim($ExtrafieldValue) != "") {
$debugstring = $debugstring . 'Updating byline from ' . '"' . $currentOnlineByline . '" to "' . $ExtrafieldValue . '"\r\n';
$onlinebyline[0][0] = "";
$domBylineNode = dom_import_simplexml($onlinebyline[0]);
$cdataNode = $domBylineNode->ownerDocument->createCDATASection($ExtrafieldValue);
$domBylineNode->appendChild($cdataNode);
$debugstring = $debugstring . 'Updated byline to "' . $onlinebyline[0] . '"\r\n';
}
} catch (Exception $e) {
$SOSE->debug(DEBUG_PATH.'UpdatingBylineError'.date('M_Y').'.txt', $debugstring);
}
if (LOG_DEBUGINFO) {
$SOSE->debug(DEBUG_PATH.'UpdatingByline'.date('M_Y').'.txt', $debugstring);
}
return $NewstoryDoc;
}
/***************************************************
*
* Move Location data to extrafield PubLocation
*
**************************************************/
function
convertLocationToExtraField($storyDoc) {
$debugstring = 'convertLocationToExtraField' . '\r\n';
$storyLocation = $storyDoc->xpath('/onl:story/onl:content/onl:location');
$extraField = $storyDoc->xpath('/onl:story/onl:content/onl:extrafields/onl:extrafield');
$newExtraFieldName = '';
if ($storyLocation[0] != '') {
try {
$newExtraFieldName = 'Publocation';
$newExtraFieldValue = $storyLocation[0];
$dom=dom_import_simplexml($storyLocation[0]);
$dom->nodeValue = '';
$storyLocation = '';
try {
if ($newExtraFieldName != '') {
$story = $storyDoc->xpath('/onl:story/onl:content/onl:extrafields');
$newExtraField = $story[0]->addChild('' . $newExtraFieldName . '' . '');
}
} catch (Exception $e) {
$debugstring = $debugstring . 'convertLocationToExtraField exception: ' . $e->getMessage();
$SOSE->debug(DEBUG_PATH.'convertLocationToExtraField'.date('M_Y').'.txt', $debugstring);
}
} catch (Exception $e) {
$debugstring = $bodyelement . 'convertLocationToExtraField exception: ' . $e->getMessage();
$SOSE->debug(DEBUG_PATH.'convertLocationToExtraField'.date('M_Y').'.txt', $debugstring);
}
}
if (LOG_DEBUGINFO) {
$SOSE->debug(DEBUG_PATH.'convertLocationToExtraField'.date('M_Y').'.txt', $debugstring);
}
return $storyDoc;
}
function checkIfStoryShouldBeRejected ($storyDoc) {
$storyMustBeReject = 0;
$debugstring = '';
$mainprofilefound = false;
$multiProfileList = $storyDoc->xpath('/onl:story/onl:metadata/onl:multipriorities');
if (count($multiProfileList) < 1) {
$storyMustBeReject = 1;
}
//$debugstring = "hello";
$storyMustBeRejectedStrValue = ($storyMustBeReject) ? 'true' : 'false';
$debugstring = "multiProfileList = " . (string) count($multiProfileList) . " -- storyMustBeReject =" . $storyMustBeRejectedStrValue;
if ($storyMustBeReject == 0) {
$profileIDList = $storyDoc->xpath('/onl:story/onl:metadata/onl:multipriorities/onl:multipriority');
if ($profileIDList) {
foreach($profileIDList as $multiProfile) {
if ($multiProfile['mainprofile'] == 'true') {
$mainprofilefound = true;
break;
}
}
}
if ($mainprofilefound == false) {
$storyMustBeReject = 2;
}
}
if (LOG_DEBUGINFO) {
$SOSE->debug(DEBUG_PATH.'rejectstory'.date('M_Y').'.txt', $debugstring);
}
return $storyMustBeReject;
}
/***************************************************
* Main function to modify incoming XML
* 20120424 MY : Adding support for SEO label
**************************************************/
function processIncomingXML() {
// Getting the Story XML and load it into a PHP simpleXML document
$debugstring = '';
$xmlStr = $SOSE->NewStory;
$OldStoryXmlStr = $SOSE->OriginalStory;
$rePublishedStory = ($OldStoryXmlStr != '');
libxml_use_internal_errors(true);
$storyDoc = simplexml_load_string($xmlStr);
$storyDoc->registerXPathNamespace('onl', 'http://www.saxotech.com/online');
$storyCategorynode = $storyDoc->xpath('/onl:story/onl:metadata/onl:category');
$storyCategory = $storyCategorynode[0]['id'];
$debugstring = $debugstring . 'story category: ' . $storyCategory . '\r\n';
$StorySlug = getStoryExtraFieldValue($storyDoc, 'SaxoSlug');
/*
if (LOG_DEBUGINFO) {
try {
$SOSE->debug(DEBUG_PATH.normal_chars($StorySlug) . '_PreSaveNoChanges.xml', $storyDoc->asXML());
} catch (Exception $e) {
$debugstring = $debugstring . 'wrong filename';
}
}
*/
$debugstring = $debugstring . ' should story be rejeced\r\n';
$rejectResult = checkIfStoryShouldBeRejected($storyDoc);
// Convert a Factbox to an extra field
try {
$storyDoc = convertFactBoxToExtraField($storyDoc);
$debugstring = $debugstring . 'finished convertFactBoxToExtraField.....\r\n';
} catch (Exception $e) {
$debugstring = $debugstring . 'Error in Factbox to extra field convertion.....\r\n';
}
// Assigns a value from an extra field to the article byline
try {
$storyDoc = updateBylineFromExtrafield($storyDoc, 'columnname');
$debugstring = $debugstring . 'finished updateBylineFromExtrafield.....\r\n';
} catch (Exception $e) {
$debugstring = $debugstring . 'Error in Byline to extra field conversion.....\r\n';
}
try {
$storyDoc = convertLocationToExtraField($storyDoc);
$debugstring = $debugstring . 'finished updateBylineFromExtrafield.....\r\n';
} catch (Exception $e) {
$debugstring = $debugstring . 'Error in Byline to extra field conversion.....\r\n';
}
if ($rejectResult > 0) {
if ($rejectResult == 1) {
throw new Exception('NO PROFILE ATTACHED TO THIS STORY', '100');
} else if ($rejectResult == 2) {
throw new Exception('NO MAIN-PROFILE ATTACHED TO THIS STORY', '100');
} else {
throw new Exception('UNKNOWN ERROR WHEN CHECKING FOR PROFILES', '100');
}
}
if (LOG_DEBUGINFO) {
try {
$SOSE->debug(DEBUG_PATH.normal_chars($StorySlug) . '_PreSaveChanged.xml', $storyDoc->asXML());
} catch (Exception $e) {
$debugstring = $debugstring . 'wrong filename';
}
$SOSE->debug(DEBUG_PATH.'processIncomingXML'.date('M_Y').'.txt', $debugstring);
}
// end Process profiles and taxonomy from the story (previously published)
return $storyDoc->asXml();
}
// presave script must always have $SOSE.ECHO(xml). It cannot return empty string
try {
// only run when saving using OWS
if ($SOSE->INVOKER == 'ows.dll') {
//$SOSE->ECHO($SOSE->NewStory);
$SOSE->ECHO(processIncomingXML());
$SOSE->debug(DEBUG_PATH.'processIncomingXML'.date('M_Y').'.txt', 'finished');
} else {
$SOSE->debug(DEBUG_PATH.'processIncomingXML'.date('M_Y').'.txt', 'ELSE');
$SOSE->ECHO($SOSE->NewStory);
}
} catch (Exception $e) {
if ($e->getCode() == 100) {
throw new Exception($e->getMessage());
} else {
$SOSE->debug(DEBUG_PATH.'processIncomingXML'.date('M_Y').'.txt', 'Exception');
$SOSE->ECHO($SOSE->NewStory);
}
}
?>