WebsiteFrame.php Source Code

From SaruWiki
Jump to navigation Jump to search

PHP Source Code

<source lang="php"> <?php

  1. to activate the extension, include it from your LocalSettings.php
  2. with: include_once("extensions/websiteFrame/websiteFrame.php");

$wgExtensionFunctions[] = "wfwebsiteFrame";


// Credits $wgExtensionCredits['parserhook'][] = array(

       'name'           => 'websiteFrame',
       'author'         => array( 'unknown', 'Jan Schoonderbeek' ),
       'version'        => '0.1.0',
       'url'            => 'https://www.saruman.biz/wiki/index.php/The_websiteFrame_PHP_extension',
       'description'    => 'Allow inclusion of iFrames.',
       'descriptionmsg' => 'websiteframe-desc',

);

function wfwebsiteFrame() {

       global $wgParser;
       $wgParser->setHook( "websiteFrame", "websiteFrame" );

}

  1. the callback function for converting the input text to HTML output

function websiteFrame($input) {

       # set default arguments
       $allParams['height'] = 800;
       $allParams['width'] = 800;
       $allParams['scroll'] = "no";
       $allParams['border'] = "0";
       $allParams['name'] = "Page1";
       $allParams['align'] = "middle";
       $allParams['allowtransparency'] = "false";
       # get input args
       $aParams = explode("\n", $input);
       foreach($aParams as $sParam) {
               $aParam = explode("=", $sParam, 2);
               if( count( $aParam ) < 2 )
               continue;
               $sType = $aParam[0];
               $sArg = $aParam[1];
               switch ($sType) {
                       case 'website':
                               $sType = trim($sType);
                               $sArg = trim($sArg);
                               $allParams['website'] = $sArg;
                       break;
                       case 'height':
                               $sType = trim($sType);
                               $sArg = trim($sArg);
                               $allParams['height'] = $sArg;
                       break;
                       case 'width':
                               $sType = trim($sType);
                               $sArg = trim($sArg);
                               $allParams['width'] = $sArg;
                       break;
                       case 'scroll':
                               $sType = trim($sType);
                               $sArg = trim($sArg);
                               $allParams['scroll'] = $sArg;
                       break;
                       case 'border':
                               $sType = trim($sType);
                               $sArg = trim($sArg);
                               $allParams['border'] = $sArg;
                       break;
                       case 'name':
                               $sType = trim($sType);
                               $sArg = trim($sArg);
                               $allParams['name'] = $sArg;
                       break;
                       case 'align':
                               $sType = trim($sType);
                               $sArg = trim($sArg);
                               $allParams['align'] = $sArg;
                       break;
                       case 'allowtransparency':
                               $sType = trim($sType);
                               $sArg = trim($sArg);
                               $allParams['allowtransparency'] = $sArg;
                       break;
               }
       }
       $output = "<iframe src=\"".$allParams['website']."\" align=\"".$allParams['align']."\" name=\"".$allParams['name']."\" frameborder=\"".$allParams['border']."\" height=\"".$allParams['height']."\" scrolling=\"".$allParams['scroll']."\" width=\"".$allParams['width']."\" allowtransparency=\"".$allParams['allowtransparency']."\"></iframe>";
       return $output;

} ?> </source>

Notes:

  • I DO NOT KNOW the original author(s). I'd love to include him/her/them in the credits (I did almost nothing to the code myself). If you are or know the author(s), please contact me!
  • it isn't hard to add support for another attribute; however, security can be an issue, especially when you allow anonymous editors to use this.