Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
PHP Examples for the Saxotech Online object (Now Newscycle Digital). The official documentation is lacking php examples, so we put together a script showing each SOSE Property, Method and ENV variables in PHP format. See script results at http://www.tamberra.com/section/phpexamples
// ==========================================================================================
// File: /samples/phpexamples.php5
// Desc: To give users PHP examples of using the SOSE object
// https://docs.newscyclesolutions.com/display/Onl/The+SAXOTECH+Online+object
// Author: Stacey Jenkins
// Date: 1/13/2013
//
// ==========================================================================================
// ===== Properties ==========================
// Site
$SOSE->Echo("<hr><h1>Properties</h1>");
$SOSE->Echo("<p>Site = " . $SOSE->Site ."</p>");
// Pubdate
$SOSE->Echo ("<p>Pubdate = " .$SOSE->Pubdate . "</p>");
// Now
$SOSE->Echo ("<p>Now = " .$SOSE->Now . "</p>");
// ExecTime
$SOSE->Echo ("<p>Exectime = " .$SOSE->Exectime . "</p>");
// ===== Methods ==========================
$SOSE->Echo("<hr><h1>Methods</h1>");
//ECHO
$SOSE->Echo("<h3>ECHO</h3>");
$SOSE->Echo("<p></p><b>Any text can be output using echo</b></p>");
//GETVAR
//Note that any property on the script tag itself, any posted fields, and any
//parameters supplied in the URL are accessible through the GETVAR call.
$SOSE->Echo("<hr><h3>GETVAR</h3>");
$URLParam = $SOSE->GetVar("URLParam");
$SOSE->Echo("<p>URLParam = " . $URLParam . "</p>");
//SETVAR
$SOSE->Echo("<hr><h3>SETVAR</h3>");
$SOSE->SetVar("MyVariable","This is the content of MyVariable");
$SOSE->Echo("<p>MyVariable = " . $SOSE->GetVar("MyVariable") . "</p>");
//TRANSLATEURI
$SOSE->Echo("<hr><h3>TRANSLATEURI</h3>");
$fileLocation = $SOSE->TranslateURI("/example.txt");
$SOSE->Echo("<p>fileLocation = " . $fileLocation . "</p>");
//PBOSCRIPT
$SOSE->Echo("<hr><h3>PBOSCRIPT</h3>");
$SOSE->SetVar("testVar", "abc");
$myPBO = "<p>This is an object file just like normal Saxotech Online PBO files. This is the content of testVar: <%testVar%></p>";
$myPBO2 = '<p>This is another object file. All object script modifiers are available on testVar: <%testVar$u%></p>';
// NOTE: because php allows you to render $ vars inside double quotes, you must use single quotes if using a PBO variable modifier like $u
$SOSE->Echo($SOSE->PBOScript($myPBO));
$SOSE->Echo($SOSE->PBOScript($myPBO2));
//LOCATEOBJECT
$SOSE->Echo("<hr><h3>LOCATEOBJECT</h3>");
$objectClass = 1;
$designClass = "";
$position = "-1";
$myObjectTemplate = $SOSE->LocateObject("example",$objectClass,$designClass,$position);
$SOSE->Echo($SOSE->PBOScript($myObjectTemplate));
//WRITESESSION
$SOSE->Echo("<hr><h3>WRITESESSION</h3>");
$SOSE->WriteSession("Count", 0, "Other");
//READSESSION
$SOSE->Echo("<hr><h3>READSESSION</h3>");
$count = $SOSE->ReadSession("Count", 100, "Other");
$SOSE->Echo("<p>count from session = $count</p>");
//DELETESESSIONSECTION
$SOSE->Echo("<hr><h3>DELETESESSIONSECTION</h3>");
$SOSE->DeleteSessionSection("Other");
$count = $SOSE->ReadSession("Count", 100, "Other");
$SOSE->Echo("<p>count from session after deletesectionsession = $count</p>");
//REDIRECT
//$SOSE->Echo("<hr><h3>REDIRECT</h3>");
//$SOSE->Redirect("http://www.google.com");
//SETCOOKIE
$SOSE->Echo("<hr><h3>SETCOOKIE</h3>");
$SOSE->SetCookie("setcookie", " HelloWorld", "/");
//GETCOOKIE
$SOSE->Echo("<hr><h3>GETCOOKIE</h3>");
$SOSE->Echo ("<p>This is the value of the cookie PBCSSESSIONID: " . $SOSE->GetCookie("PBCSSESSIONID") . "</p>");
//DELETESESSIONKEY
$SOSE->Echo("<hr><h3>DELETESESSIONKEY</h3>");
$SOSE->DeleteSessionKey("Count","Other");
$count = $SOSE->ReadSession("Count", 250, "Other");
$SOSE->Echo("<p>count from session after DELETESESSIONKEY = $count</p>");
//CLEARVARLIST
$SOSE->Echo("<hr><h3>CLEARVARLIST</h3>");
$SOSE->ClearVarList();
$SOSE->Echo("<p>MyVariable after ClearVarList = " . $SOSE->GetVar("MyVariable") . "</p>");
//SETPERSISTENTVAR
$SOSE->Echo("<hr><h3>SETPERSISTENTVAR</h3>");
$SOSE->SetPersistentVar ("MyVariable2", "This is the content of MyVariable in memory bank1");
$SOSE->Echo("<p>" . $SOSE->GetVar("MyVariable2","membank1") . "</p>");
//BUILDARTPARAMS
$SOSE->Echo("<hr><h3>BUILDARTPARAMS</h3>");
$SOSE->Echo ("<p>Without FullLink: " . $SOSE->BuildArtParams("20070101", "NEWS01", 123456) . "</p>");
$SOSE->Echo ("<p>With FullLink: " . $SOSE->BuildArtParams("20070101", "NEWS01", 123456, True) . "</p>");
$SOSE->Echo ("<p>Without FullLink, with profile: " . $SOSE->BuildArtParams("20070101", "NEWS01", 123456, False, 1001) . "</p>");
//SHOWTEXT
$SOSE->Echo("<hr><h3>SHOWTEXT</h3>");
$MyText = "This is a paragraph of some length and it contains several sentences and a line break after this very long sentence that will show how the ellipses are being inserted. \n\r";
$MyText .= "This is some text that appears after the line break. Notice how show text never goes past a line break.";
$SOSE->Echo ("<p>" . str_replace("\n\r", "<br>", $MyText) . "</p>");
$SOSE->Echo ("<p>Length set to 50 characters: " . $SOSE->ShowText(50, $MyText) . "</p>");
$SOSE->Echo ("<p>Length set to 150 characters: " . $SOSE->ShowText(150, $MyText) . "</p>");
$SOSE->Echo ("<p>Length set to 500 characters: " . $SOSE->ShowText(500, $MyText) . "</p>");
//FORMATDATETIME
$SOSE->Echo("<hr><h3>FORMATDATETIME</h3>");
$SOSE->Echo ("<p>Dateformat d. mmmm, yyyy: " . $SOSE->FormatDateTime("d. mmmm, yyyy") . "</p>");
$SOSE->Echo ("<p>Dateformat ddd h:mm ampm: " . $SOSE->FormatDateTime("ddd h:mm ampm") . "</p>");
$SOSE->Echo ("<p>Dateformat dddd mmmm d - yyyy hh:mm: " . $SOSE->FormatDateTime("dddd mmmm d- yyyy hh:mm") . "</p>");
$SOSE->Echo ("<p>Dateformat mm/dd/yy: " . $SOSE->FormatDateTime("mm/dd/yy") . "</p>");
//EVAL
$SOSE->Echo("<hr><h3>EVAL</h3>");
$SOSE->Echo("<p>Is today Sunday? " . $SOSE->Eval($SOSE->FormatDateTime("ddd")=="Sun", "Yes", "No") . "</p>");
$SOSE->Echo("<p>Is today Monday? " . $SOSE->Eval($SOSE->FormatDateTime("ddd")=="Mon", "Yes", "No") . "</p>");
$SOSE->Echo("<p>Is today Tuesday? " . $SOSE->Eval($SOSE->FormatDateTime("ddd")=="Tue", "Yes", "No") . "</p>");
$SOSE->Echo("<p>Is today Wednesday? " . $SOSE->Eval($SOSE->FormatDateTime("ddd")=="Wed", "Yes", "No") . "</p>");
$SOSE->Echo("<p>Is today Thursday? " . $SOSE->Eval($SOSE->FormatDateTime("ddd")=="Thu", "Yes", "No") . "</p>");
$SOSE->Echo("<p>Is today Friday? " . $SOSE->Eval($SOSE->FormatDateTime("ddd")=="Fri", "Yes", "No") . "</p>");
$SOSE->Echo("<p>Is today Saturday? " . $SOSE->Eval($SOSE->FormatDateTime("ddd")=="Sat", "Yes", "No") . "</p>");
//COALESCE
$SOSE->Echo("<hr><h3>COALESCE</h3>");
$SOSE->Echo("<p><i>For whatever reason, this doesn't seem to work per documentation</i></p>");
$SOSE->Echo("<p>Today's day is " . $SOSE->Coalesce(
$SOSE->Eval($SOSE->FormatDateTime("ddd")=="Sun", "Sunday"),
$SOSE->Eval($SOSE->FormatDateTime("ddd")=="Mon", "Monday"),
$SOSE->Eval($SOSE->FormatDateTime("ddd")=="Tue", "Tuesday"),
$SOSE->Eval($SOSE->FormatDateTime("ddd")=="Wed", "Wednesday"),
$SOSE->Eval($SOSE->FormatDateTime("ddd")=="Thu", "Thursday"),
$SOSE->Eval($SOSE->FormatDateTime("ddd")=="Fri", "Friday"),
$SOSE->Eval($SOSE->FormatDateTime("ddd")=="Sat", "Saturday")
) . "</p>");
$SOSE->Echo($SOSE->Eval($SOSE->FormatDateTime("ddd")=="Tue", "Tuesday"));
//TODATE
$SOSE->Echo("<hr><h3>TODATE</h3>");
$SOSE->Echo ("<p>Now = " . $SOSE->Now . "</p>");
$SOSE->Echo ("<p>Now as date = " . $SOSE->ToDate($SOSE->Now) . "</p>");
//VAREXISTS
$SOSE->Echo("<hr><h3>VAREXISTS</h3>");
$MyTemplate = "<p>This is a pbo template with <%Variable%><br>";
$MyTemplate .= "We can use the VarExists method to check for the presence of <%AnotherVariable%></p>";
if ($SOSE->VarExists($MyTemplate, "Variable")){
$SOSE->SetVar("Variable", "some variables.");
}
if ($SOSE->VarExists($MyTemplate, "AnotherVariable")){
$SOSE->SetVar("AnotherVariable", "a specific variable.");
}
if ($SOSE->VarExists($MyTemplate, "ThirdVariable")){
$SOSE->SetVar("ThirdVariable", "should not be set.");
}
$SOSE->Echo ($SOSE->PBOScript($MyTemplate));
$SOSE->Echo ("<p>Notice that ThirdVariable = " . $SOSE->GetVar("ThirdVariable") . "</p>");
// ===== ENV Method and Environment Variables ==========================
$SOSE->Echo("<hr><h1>ENV Method and Environment Variables</h1>");
$SOSE->Echo("<p>Hostname = " . $SOSE->Env("HOSTNAME") . "</p>");
$SOSE->Echo("<p>ClientIP = " . $SOSE->Env("CLIENTIP") . "</p>");
$SOSE->Echo("<p>UserName = " . $SOSE->Env("USERNAME") . "</p>");
$SOSE->Echo("<p>TempFileName = " . $SOSE->Env("TEMPFILENAME") . "</p>");
$SOSE->Echo("<p>UserAgent = " . $SOSE->Env("USERAGENT") . "</p>");
$SOSE->Echo("<p>SessionID = " . $SOSE->Env("SESSIONID") . "</p>");
$SOSE->Echo("<p>Action = " . $SOSE->Env("ACTION") . "</p>");
$SOSE->Echo("<p>Referer = " . $SOSE->Env("REFERER") . "</p>");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment