Difference between revisions of "Extension:Livelets.php"
(start fixing) |
(function-hook code) |
||
Line 8: | Line 8: | ||
define('LIVELETS_VERSION', '0.2.1, 2007-07-09'); | define('LIVELETS_VERSION', '0.2.1, 2007-07-09'); | ||
− | $wgLiveletsMagic | + | $wgLiveletsMagic = "live"; # the parser-function name for doing live-transclusions |
− | $wgLiveletsMoo | + | $wgLiveletsMoo = ''; # Set this to the relative path of Mootools.js unless loaded elsewhere |
− | $wgLiveletsUseSWF | + | |
+ | $wgLiveletsUseSWF = false; # Set this to true to use SWF to make livelets fully event-driven (no polling for change) | ||
+ | $wgLiveletsSwfBg = '#ffffff"; # The background colour of the embedded SWF | ||
+ | $wgLiveletsPort = '1729' # The port that Livelets.pl can be reached on (using $wgServer:$wgLiveletsPort) | ||
$wgLiveletsPath = dirname(__FILE__); | $wgLiveletsPath = dirname(__FILE__); | ||
Line 32: | Line 35: | ||
# Constructor | # Constructor | ||
function Livelets() { | function Livelets() { | ||
− | global $IP,$wgParser,$wgServer,$wgLiveletsMagic,$wgLiveletsMoo,$ | + | global $IP,$wgParser,$wgServer,$wgLiveletsMagic,$wgLiveletsMoo,$wgLiveletsPath, |
+ | $wgLiveletsUseSwf,$wgLiveletsSwfBg,$wgLiveletsPort; | ||
# Activate the #live parser-function | # Activate the #live parser-function | ||
Line 45: | Line 49: | ||
# Embed the SWF if enabled (SWF must be requested from Livelets.pl) | # Embed the SWF if enabled (SWF must be requested from Livelets.pl) | ||
− | if ($ | + | if ($wgLiveletsUseSwf) { |
$swf = "$wgServer:$wgLiveletsPort/Livelets.swf"; | $swf = "$wgServer:$wgLiveletsPort/Livelets.swf"; | ||
− | $wgOut->addHTML("<object type=\"application/x-shockwave-flash\" data=\"$swf\" width=\" | + | $wgOut->addHTML("<object type=\"application/x-shockwave-flash\" data=\"$swf\" width=\"1\" height=\"1\"> |
− | <param name=\"movie\" value=\"$swf\" /><param name=\"bgcolor\" value=\" | + | <param name=\"movie\" value=\"$swf\" /><param name=\"bgcolor\" value=\"$wgLiveletsSwfBg\"/></object>"); |
} | } | ||
} | } | ||
# Render livelet container | # Render livelet container | ||
− | function functionHook(&$parser | + | function functionHook(&$parser) { |
global $wgScript,$wgLiveletsPath,$wgLiveletsDefaultContent; | global $wgScript,$wgLiveletsPath,$wgLiveletsDefaultContent; | ||
− | + | ||
− | + | # Process parameters | |
− | $ | + | $args = ''; |
− | + | $argv = array(); | |
− | + | foreach (func_get_args() as $arg) if (!is_object($arg)) { | |
− | + | if (preg_match('/^([a-z0-9_]+?)\\s*=(.+)$/is',$arg,$match)) $argv[trim($match[1])] = trim($match[2]); | |
− | + | else $argv['title'] = trim($arg); | |
− | $argv[' | ||
− | |||
} | } | ||
− | $argv[' | + | if (isset($argv['title'])) $argv['url'] = Title::newFromText($title)->getFullURL('action=render'); |
+ | if (isset($argv['update'])) { $update = $argv['update']; unset($argv['update']); } | ||
+ | if (isset($argv['type'])) { $type = $argv['type']; unset($argv['type']); } | ||
+ | foreach ($argv as $k => $v) $args .= " $k=\"$v\""; | ||
+ | |||
+ | # Render container | ||
+ | $id = 'livelet'.$this->id++; | ||
+ | $html = "<div$args id='$id'>$wgLiveletsDefaultContent</div>"; | ||
+ | if (isset($update)) $html .= "<script type='text/javascript'>updateLivelet('$id')</script>"; | ||
− | |||
− | |||
− | |||
return array($html,'isHTML' => true,'noparse' => true); | return array($html,'isHTML' => true,'noparse' => true); | ||
} | } |
Revision as of 00:11, 10 July 2007
<?
- Extension:LiveletsTemplate:Php
Scripts and articles related to Extension:Livelets, see also Wiklets
- - Allows articles to be transcluded which load after the main page content and can update dynamically with Ajax
- - See http://www.mediawiki.org/wiki/Extension:Livelets for installation and usage details
- - Licenced under LGPL (http://www.gnu.org/copyleft/lesser.html)
- - Author: http://www.organicdesign.co.nz/nad
define('LIVELETS_VERSION', '0.2.1, 2007-07-09');
$wgLiveletsMagic = "live"; # the parser-function name for doing live-transclusions $wgLiveletsMoo = ; # Set this to the relative path of Mootools.js unless loaded elsewhere
$wgLiveletsUseSWF = false; # Set this to true to use SWF to make livelets fully event-driven (no polling for change) $wgLiveletsSwfBg = '#ffffff"; # The background colour of the embedded SWF $wgLiveletsPort = '1729' # The port that Livelets.pl can be reached on (using $wgServer:$wgLiveletsPort)
$wgLiveletsPath = dirname(__FILE__);
$wgLiveletsDefaultContent = "
";
$wgExtensionFunctions[] = 'wfSetupLivelets'; $wgHooks['LanguageGetMagic'][] = 'wfLiveletsLanguageGetMagic';
$wgExtensionCredits['parserhook'][] = array( 'name' => 'Livelets', 'author' => 'User:Nad', 'description' => 'Allows articles to be transcluded which load after the main page content and can update dynamically with Ajax', 'url' => 'http://www.mediawiki.org/wiki/Extension:Livelets', 'version' => LIVELETS_VERSION );
class Livelets {
var $version = LIVELETS_VERSION; var $id = 0;
# Constructor function Livelets() { global $IP,$wgParser,$wgServer,$wgLiveletsMagic,$wgLiveletsMoo,$wgLiveletsPath, $wgLiveletsUseSwf,$wgLiveletsSwfBg,$wgLiveletsPort;
# Activate the #live parser-function $wgParser->setFunctionHook($wgLiveletsMagic,array($this,'functionHook'));
# Include Livelets.js $url = str_replace($wgLiveletsPath,$IP,).'/Livelets.js'; $wgOut->addScript("<script type=\"text/javascript\" src=\"$url\"></script>");
# Include Mootools.js is set if ($wgLiveletsMoo) $wgOut->addScript("<script type=\"text/javascript\" src=\"$wgLiveletsMoo\"></script>");
# Embed the SWF if enabled (SWF must be requested from Livelets.pl) if ($wgLiveletsUseSwf) { $swf = "$wgServer:$wgLiveletsPort/Livelets.swf"; $wgOut->addHTML("<object type=\"application/x-shockwave-flash\" data=\"$swf\" width=\"1\" height=\"1\"> <param name=\"movie\" value=\"$swf\" /><param name=\"bgcolor\" value=\"$wgLiveletsSwfBg\"/></object>"); } }
# Render livelet container function functionHook(&$parser) { global $wgScript,$wgLiveletsPath,$wgLiveletsDefaultContent;
# Process parameters $args = ; $argv = array(); foreach (func_get_args() as $arg) if (!is_object($arg)) { if (preg_match('/^([a-z0-9_]+?)\\s*=(.+)$/is',$arg,$match)) $argv[trim($match[1])] = trim($match[2]); else $argv['title'] = trim($arg); } if (isset($argv['title'])) $argv['url'] = Title::newFromText($title)->getFullURL('action=render'); if (isset($argv['update'])) { $update = $argv['update']; unset($argv['update']); } if (isset($argv['type'])) { $type = $argv['type']; unset($argv['type']); } foreach ($argv as $k => $v) $args .= " $k=\"$v\"";
# Render container $id = 'livelet'.$this->id++;
$html = "<div$args id='$id'>$wgLiveletsDefaultContent";
if (isset($update)) $html .= "<script type='text/javascript'>updateLivelet('$id')</script>";
return array($html,'isHTML' => true,'noparse' => true); }
}
- Called from $wgExtensionFunctions array when initialising extensions
function wfSetupLivelets() { global $wgLivelets,$wgScriptPath,$wgLiveletsPath; $wgLivelets = new Livelets(); if ($wgLiveletsPath == ) $wgLiveletsPath = "$wgScriptPath/extensions/livelets"; }
- Needed in MediaWiki >1.8.0 for magic word hooks to work properly
function wfLiveletsLanguageGetMagic(&$magicWords,$langCode = 0) { global $wgLiveletsMagic; $magicWords[$wgLiveletsMagic] = array(0,$wgLiveletsMagic); return true; } ?>