Wednesday March 29, 2017

Php api example

From Skoffer One Click Screencasting

Jump to: navigation, search

The idea of the code example below is this:
you build in a new button on the page of your website-software where the user inputs texts. When the user click on this button a popup-window opens which loads the PHP-file below.
If you have looked trough the code-example below you will have noticed that the PHP-file looks if a GET variable "skofferid" exists, and if not it outputs HTML to load the screencast-recorder.
If there is a GET variable "skofferid" it inserts the content of it to the form where the user can input the texts for the website, and closes itself (the popup).

please keep in mind: via javascript it is only possible to insert text into forms from popups on the same domain.
www.yourdomain.tld and yourdomain.tld are two differnt domains for javascript, too.

When the user clicks the button (that opens up the popup), the screen-recorder opens (since there is no GET variable "skofferid" present till now), and when the user finished the recording the Java applet redirects him to the document from which the applet was started, but with the GET variable "skofferid". And the PHP file doesn´t start the screen-recorder again, but inserts the video ID to the text field and closes the popup.

The below example is for the website-software MediaWiki (MediaWiki´s textfield has the Element-ID "wpTextbox1"), but can be used for most software when the Element ID in Javascript code that inserts the text

opener.document.getElementById('wpTextbox1').value=opener.document.getElementById('wpTextbox1').value+\"<TEXT TO INSERT>\";

is adapted to the Element-ID of the desired software.

PHP Example:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
 body {
	background-color: #000000;
	color: #e8f4f8;
	:link {
	color: #FFFFFF;
<title>screen-recorder initiator</title></head>
$skofferid = $_GET['skofferid'];
// removing possible wrong chars from the id
$skofferid= preg_replace ("/[^A-Za-z0-9.-]/","",$skofferid);
// if there is a GET variable "skofferid" this PHP file should generate HTML code with a Javascript to insert the ID into the Mediawiki text-field
 if (isset($_GET["skofferid"]))   
  if($skofferid == "")   
// if $skofferid is empty: insert nothing (happens when the user clicks the screen-recorder´s close button.
echo "<script language=\"javascript\" type=\"text/javascript\">    
// if $skofferid is not empty: insert the ID
echo "<script language=\"javascript\" type=\"text/javascript\">    
opener.document.getElementById('wpTextbox1').value=opener.document.getElementById('wpTextbox1').value+\"[skoffer $skofferid]\";
// if there is no GET variable "id", the JAVA applet should be started. When the user finished a new recording, the applet saves the new recording and this PHP file is called again with the ID of the new recording as GET var "skofferid" (so this PHP file inserts the ID into the text-input field of the website-software)
echo "<script type=\"text/javascript\">
if (navigator.javaEnabled() != true) {
alert(\"Sorry, the screen-recorder can´t start. Java has to be enabled in your browser. Please go to to download the latest version.\");
document.write(\"Sorry, Java is not enabled in your browser.<br />Java is available from <a href='' target='_blank'></a>\");
<center><applet code=\"com.skoffer.SkofferApplet\" archive=\"\" name=\" Screencast Recorder\" width=\"200\" height=\"180\" MAYSCRIPT></center>";

You now have to find a way to parse the inputed text that the Skoffer video player shows the video.
You should not insert the Skoffer ID alone.
You should let your popup insert for example (like the above code does)

[skoffer $skofferid]

which would look like

[skoffer 123456789]

Now you have to write code that your plugin exchanges such text on every side load to
<embed src={"playlist":[{"url":"","autoPlay":false,"autoBuffering":true,"scaling":"fit"}]} type="application/x-shockwave-flash" wmode="transparent" width="425" height="350" allowFullScreen="true" allowScriptAccess="always" allowNetworking="all" pluginspage=""></embed> Where ###URL### has to be the ID of the screencast ($skofferid).

If you are writting a plugin for a popular website-software, there will exist a YouTube or other video-platform-plugin that works similar (which shows for example a YouTube video when you enter [youtube <youtube_videoid>]
So you should search if you find one with an appropriate free license (like the GPL) and adapt the code, which will save you time.

If you have a question or want to suggest an improvement, please feel free to use the contact form.