WebsiteFrame.php Source Code: Difference between revisions
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== | ||
< | <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: | # 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"; | $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); | $aParams = explode("\n", $input); | ||
foreach($aParams as $sParam) { | foreach($aParams as $sParam) { | ||
$aParam = explode("=", $sParam); | $aParam = explode("=", $sParam, 2); | ||
if( count( $aParam ) < 2 ) | if( count( $aParam ) < 2 ) | ||
continue; | continue; | ||
$sType = $aParam[0]; | $sType = $aParam[0]; | ||
$sArg = $aParam[1]; | $sArg = $aParam[1]; | ||
switch ($sType) { | switch ($sType) { | ||
case 'website': | case 'website': | ||
$sType = trim($sType); | $sType = trim($sType); | ||
$sArg = trim($sArg); | $sArg = trim($sArg); | ||
$allParams['website'] = $sArg; | $allParams['website'] = $sArg; | ||
break; | break; | ||
case 'height': | case 'height': | ||
$sType = trim($sType); | $sType = trim($sType); | ||
$sArg = trim($sArg); | $sArg = trim($sArg); | ||
$allParams['height'] = $sArg; | $allParams['height'] = $sArg; | ||
break; | break; | ||
case 'width': | case 'width': | ||
$sType = trim($sType); | $sType = trim($sType); | ||
$sArg = trim($sArg); | $sArg = trim($sArg); | ||
$allParams['width'] = $sArg; | $allParams['width'] = $sArg; | ||
break; | break; | ||
case 'scroll': | case 'scroll': | ||
$sType = trim($sType); | $sType = trim($sType); | ||
$sArg = trim($sArg); | $sArg = trim($sArg); | ||
$allParams['scroll'] = $sArg; | $allParams['scroll'] = $sArg; | ||
break; | break; | ||
case 'border': | case 'border': | ||
$sType = trim($sType); | $sType = trim($sType); | ||
$sArg = trim($sArg); | $sArg = trim($sArg); | ||
$allParams['border'] = $sArg; | $allParams['border'] = $sArg; | ||
break; | break; | ||
case 'name': | case 'name': | ||
$sType = trim($sType); | $sType = trim($sType); | ||
$sArg = trim($sArg); | $sArg = trim($sArg); | ||
$allParams['name'] = $sArg; | $allParams['name'] = $sArg; | ||
break; | break; | ||
case 'align': | case 'align': | ||
$sType = trim($sType); | $sType = trim($sType); | ||
$sArg = trim($sArg); | $sArg = trim($sArg); | ||
$allParams['align'] = $sArg; | $allParams['align'] = $sArg; | ||
break; | break; | ||
case 'allowtransparency': | case 'allowtransparency': | ||
$sType = trim($sType); | $sType = trim($sType); | ||
$sArg = trim($sArg); | $sArg = trim($sArg); | ||
$allParams['allowtransparency'] = $sArg; | $allParams['allowtransparency'] = $sArg; | ||
break; | 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>"; | |||
$output | |||
return $output; | 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 [[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
- to activate the extension, include it from your LocalSettings.php
- 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" );
}
- 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.