MWZenphoto

MWZenphoto Git Source Tree

Root/MWZenphoto.php

1<?php
2// MWZenphoto.php
3// MediaWiki extension to allow images to be included from a local Zenphoto
4// gallery using a <zenphoto> tag within the wiki markup, e.g.:
5//
6// <zenphoto>albumname|filename.jpg</zenphoto>
7//
8// The image is embedded in a thumbnail size, and linked to the viewing page
9// within the gallery. The size defaults to 300, but can be specified, as can
10// the alignment. A more complex example:
11//
12// <zenphoto>album/subalbum|file.jpg|450px|right|alt=Some alt text</zenphoto>
13//
14// Version 0.11
15// Copyright (C) 2009 Ciaran Gultnieks <ciaran@ciarang.com>
16//
17// This program is free software: you can redistribute it and/or modify
18// it under the terms of the GNU Affero General Public License as published by
19// the Free Software Foundation, either version 3 of the License, or
20// (at your option) any later version.
21//
22// This program is distributed in the hope that it will be useful,
23// but WITHOUT ANY WARRANTY; without even the implied warranty of
24// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25// GNU Affero General Public License for more details.
26//
27// You should have received a copy of the GNU Affero General Public License
28// along with this program. If not, see <http://www.gnu.org/licenses/>.
29//
30
31
32// Base URL for Zenphoto - can be absolute or relative
33$ZP_baseURL='/gallery';
34
35// The image suffix used by Zenphoto for image pages. This is
36// set on your Zenphoto options page, as "mod_rewrite suffix"
37$ZP_imageSuffix='/view';
38
39$wgExtensionFunctions[]='wfMWZenphoto';
40$wgExtensionCredits['parserhook'][]=array(
41'path'=>__FILE__,
42'name'=>'MWZenphoto',
43'description'=>'Enables inclusion of images from Zenphoto',
44'version'=>0.11,
45'author'=>'Ciaran Gultnieks',
46'url'=>'http://ciarang.com/posts/mwzenphoto');
47
48function wfMWZenphoto() {
49global $wgParser;
50$wgParser->setHook('zenphoto','renderZenphoto');
51}
52
53function renderZenphoto($input) {
54global $ZP_baseURL;
55global $ZP_imageSuffix;
56
57// Check and handle all parameters...
58$params=explode('|',$input,5);
59if(sizeof($params)<2)
60return '<strong class="error">MWZenphoto: At least Album and Filename must be specified</strong>';
61$album=$params[0];
62$filename=$params[1];
63$params=array_slice($params,2);
64$align='';
65$size='';
66$alt='';
67foreach($params as $p) {
68if(in_array(strtolower($p),array('none','right','left','center'))) {
69$align=strtolower($p);
70} elseif(substr($p,-2)=='px' && is_numeric(substr($p,0,-2))) {
71$size=substr($p,0,-2);
72} elseif(substr($p,0,4)=='alt=') {
73$alt=substr($p,4);
74} else {
75return '<strong class="error">MWZenPhoto: Parameter not recognised - '.$p.'</strong>';
76}
77}
78if($align=='')
79$align='left';
80if($size=='')
81$size='300';
82
83// Generate HTML output...
84if($align=='left' || $align=='right') {
85$class='float'.$align;
86} else {
87$class='floatnone';
88}
89$out=<<<EOT
90<div class="$class"><a href="$ZP_baseURL/$album/$filename$ZP_imageSuffix" class="image" title="$alt"><img alt="$alt" src="$ZP_baseURL/$album/image/$size/$filename"></a></div>
91EOT;
92if($align=='center') {
93$out='<div class="center">'.$out.'</div>';
94}
95return $out;
96}
97
98?>
99

Archive Download this file

Branches