WebsiteFrame.php Source Code: Difference between revisions

From SaruWiki
Jump to navigation Jump to search
(Source code listed)
 
m (updated with credits and version)
 
Line 1: Line 1:
==PHP Source Code==
==PHP Source Code==
<pre>
<source lang="php">
 
<?php
<?php
# to activate the extension, include it from your LocalSettings.php
# to activate the extension, include it from your LocalSettings.php
# with: include("extensions/websiteFrame.php");
# with: include_once("extensions/websiteFrame/websiteFrame.php");


$wgExtensionFunctions[] = "wfwebsiteFrame";
$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() {
function wfwebsiteFrame() {
         global $wgParser;
         global $wgParser;
         $wgParser->setHook( "websiteFrame", "websiteFrame" );
         $wgParser->setHook( "websiteFrame", "websiteFrame" );
}
}
Line 20: Line 29:
         $allParams['width'] = 800;
         $allParams['width'] = 800;
         $allParams['scroll'] = "no";
         $allParams['scroll'] = "no";
         $allParams['border'] = "0"; # actually 'frameborder'
         $allParams['border'] = "0";
         $allParams['name'] = "Page1";
         $allParams['name'] = "Page1";
         $allParams['align'] = "middle";
         $allParams['align'] = "middle";
Line 26: Line 35:


         # get input args
         # get input args
         $aParams = explode("\n", $input); # ie 'website=http://www.whatever.com'
         $aParams = explode("\n", $input);
         foreach($aParams as $sParam) {
         foreach($aParams as $sParam) {
                 $aParam = explode("=", $sParam); # ie $aParam[0] = 'website' and $aParam[1] = 'http://www.whatever.com'
                 $aParam = explode("=", $sParam, 2);
                 if( count( $aParam ) < 2 ) # no arguments passed
                 if( count( $aParam ) < 2 )
                 continue;
                 continue;


                 $sType = $aParam[0]; # ie 'website'
                 $sType = $aParam[0];
                 $sArg = $aParam[1]; # ie 'http://www.whatever.com'
                 $sArg = $aParam[1];


                 switch ($sType) {
                 switch ($sType) {
                         case 'website':
                         case 'website':
                                # clean up
                                 $sType = trim($sType);
                                 $sType = trim($sType);
                                 $sArg = trim($sArg);
                                 $sArg = trim($sArg);
                                 $allParams['website'] = $sArg; # http://www.whatever.com
                                 $allParams['website'] = $sArg;
                         break;
                         break;


                         case 'height':
                         case 'height':
                                # clean up
                                 $sType = trim($sType);
                                 $sType = trim($sType);
                                 $sArg = trim($sArg);
                                 $sArg = trim($sArg);
                                 $allParams['height'] = $sArg; # 80
                                 $allParams['height'] = $sArg;
                         break;
                         break;


                         case 'width':
                         case 'width':
                                # clean up
                                 $sType = trim($sType);
                                 $sType = trim($sType);
                                 $sArg = trim($sArg);
                                 $sArg = trim($sArg);
                                 $allParams['width'] = $sArg; # 100
                                 $allParams['width'] = $sArg;
                         break;
                         break;


                         case 'scroll':
                         case 'scroll':
                                # clean up
                                 $sType = trim($sType);
                                 $sType = trim($sType);
                                 $sArg = trim($sArg);
                                 $sArg = trim($sArg);
                                 $allParams['scroll'] = $sArg; # yes
                                 $allParams['scroll'] = $sArg;
                         break;
                         break;


                         case 'border':
                         case 'border':
                                # clean up
                                 $sType = trim($sType);
                                 $sType = trim($sType);
                                 $sArg = trim($sArg);
                                 $sArg = trim($sArg);
                                 $allParams['border'] = $sArg; # yes
                                 $allParams['border'] = $sArg;
                         break;
                         break;


                         case 'name':
                         case 'name':
                                # clean up
                                 $sType = trim($sType);
                                 $sType = trim($sType);
                                 $sArg = trim($sArg);
                                 $sArg = trim($sArg);
                                 $allParams['name'] = $sArg; # my iFrame
                                 $allParams['name'] = $sArg;
                         break;
                         break;


                         case 'align':
                         case 'align':
                                # clean up
                                 $sType = trim($sType);
                                 $sType = trim($sType);
                                 $sArg = trim($sArg);
                                 $sArg = trim($sArg);
                                 $allParams['align'] = $sArg; # my iFrame
                                 $allParams['align'] = $sArg;
                         break;
                         break;


                         case 'allowtransparency':
                         case 'allowtransparency':
                                # clean up
                                 $sType = trim($sType);
                                 $sType = trim($sType);
                                 $sArg = trim($sArg);
                                 $sArg = trim($sArg);
                                 $allParams['allowtransparency'] = $sArg; # my iFrame
                                 $allParams['allowtransparency'] = $sArg;
                         break;
                         break;
                 }
                 }
         }
         }


        # build output
         $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>";
         $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 the output
         return $output;
         return $output;
}
}
?>
?>
</pre>
</source>


Note that 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.
'''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 [[User:Saruman!|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.

Latest revision as of 13:52, 23 October 2009

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.