author | Dan |
Wed, 26 Aug 2009 23:21:56 -0400 | |
changeset 37 | 3afbd6374442 |
parent 26 | 023a21c8f47c |
child 42 | 7c6e2e97aa08 |
permissions | -rw-r--r-- |
26
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
1 |
<?php |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
2 |
|
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
3 |
/* |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
4 |
* Snapr |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
5 |
* Version 0.1 beta 1 |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
6 |
* Copyright (C) 2007 Dan Fuhry |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
7 |
* |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
8 |
* This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
9 |
* as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
10 |
* |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
11 |
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
12 |
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details. |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
13 |
*/ |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
14 |
|
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
15 |
// Add an [[:Image:foo]] tag handler to the wiki formatter |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
16 |
$plugins->attachHook('render_wikiformat_pre', 'snapr_process_image_tags($text);'); |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
17 |
|
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
18 |
function snapr_process_image_tags(&$text) |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
19 |
{ |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
20 |
$text = snapr_image_tags_stage1($text, $taglist); |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
21 |
$text = snapr_image_tags_stage2($text, $taglist); |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
22 |
} |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
23 |
|
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
24 |
/* |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
25 |
* Functions copied from render.php |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
26 |
*/ |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
27 |
|
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
28 |
/** |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
29 |
* Changes wikitext image tags to HTML. |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
30 |
* @param string The wikitext to process |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
31 |
* @param array Will be overwritten with the list of HTML tags (the system uses tokens for TextWiki compatibility) |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
32 |
* @return string |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
33 |
*/ |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
34 |
|
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
35 |
function snapr_image_tags_stage1($text, &$taglist) |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
36 |
{ |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
37 |
global $db, $session, $paths, $template, $plugins; // Common objects |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
38 |
|
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
39 |
static $idcache = array(); |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
40 |
|
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
41 |
$s_delim = "\xFF"; |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
42 |
$f_delim = "\xFF"; |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
43 |
$taglist = array(); |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
44 |
|
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
45 |
// Wicked huh? |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
46 |
$regex = '/\[\[:' . str_replace('/', '\\/', preg_quote($paths->nslist['Gallery'])) . '([\w\s0-9_\(\)!@%\^\+\|\.-]+?)((\|thumb)|(\|([0-9]+)x([0-9]+)))?(\|left|\|right)?(\|raw|\|(.+))?\]\]/i'; |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
47 |
|
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
48 |
preg_match_all($regex, $text, $matches); |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
49 |
|
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
50 |
foreach ( $matches[0] as $i => $match ) |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
51 |
{ |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
52 |
$full_tag =& $matches[0][$i]; |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
53 |
$imagename =& $matches[1][$i]; |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
54 |
$scale_type =& $matches[2][$i]; |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
55 |
$width =& $matches[5][$i]; |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
56 |
$height =& $matches[6][$i]; |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
57 |
$clear =& $matches[7][$i]; |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
58 |
$caption =& $matches[8][$i]; |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
59 |
|
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
60 |
// determine the image name |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
61 |
$imagename = sanitize_page_id($imagename); |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
62 |
if ( isset($idcache[$imagename]) ) |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
63 |
{ |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
64 |
$found_image_id = true; |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
65 |
$filename =& $idcache[$imagename]; |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
66 |
} |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
67 |
else |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
68 |
{ |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
69 |
$found_image_id = false; |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
70 |
// get the image ID |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
71 |
// Ech... he sent us a string... parse it and see what we get |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
72 |
if ( strstr($imagename, '/') ) |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
73 |
{ |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
74 |
$folders = explode('/', $imagename); |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
75 |
} |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
76 |
else |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
77 |
{ |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
78 |
$folders = array($imagename); |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
79 |
} |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
80 |
foreach ( $folders as $i => $_crap ) |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
81 |
{ |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
82 |
$folder =& $folders[$i]; |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
83 |
$folder = dirtify_page_id($folder); |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
84 |
$folder = str_replace('_', ' ', $folder); |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
85 |
} |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
86 |
unset($folder); |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
87 |
|
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
88 |
$folders = array_reverse($folders); |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
89 |
// This is one of the best MySQL tricks on the market. We're going to reverse-travel a folder path using LEFT JOIN and the incredible power of metacoded SQL |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
90 |
$sql = 'SELECT g0.img_id, g0.img_title, g0.img_desc, g0.print_sizes, g0.img_time_upload, g0.img_time_mod, g0.img_filename, g0.folder_parent, g0.img_tags FROM '.table_prefix.'gallery AS g0'; |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
91 |
$where = "\n " . 'WHERE g0.img_title=\'' . $db->escape($folders[0]) . '\''; |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
92 |
foreach ( $folders as $i => $folder ) |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
93 |
{ |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
94 |
if ( $i == 0 ) |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
95 |
continue; |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
96 |
$i_dec = $i - 1; |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
97 |
$folder = $db->escape($folder); |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
98 |
$sql .= "\n LEFT JOIN ".table_prefix."gallery AS g{$i}\n ON ( g{$i}.img_id=g{$i_dec}.folder_parent AND g{$i}.img_title='$folder' )"; |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
99 |
$where .= "\n ".'AND g'.$i.'.img_id IS NOT NULL'; |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
100 |
} |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
101 |
$where .= "\n AND g{$i}.folder_parent IS NULL"; |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
102 |
$sql .= $where . ';'; |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
103 |
|
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
104 |
if ( !$db->sql_query($sql) ) |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
105 |
{ |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
106 |
$db->_die('The image metadata could not be loaded.'); |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
107 |
} |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
108 |
|
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
109 |
if ( $db->numrows() > 0 ) |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
110 |
{ |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
111 |
$found_image_id = true; |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
112 |
$row = $db->fetchrow(); |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
113 |
$db->free_result(); |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
114 |
$idcache[$imagename] = $row['img_id']; |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
115 |
$filename =& $idcache[$imagename]; |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
116 |
} |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
117 |
} |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
118 |
|
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
119 |
if ( !$found_image_id ) |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
120 |
{ |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
121 |
$text = str_replace($full_tag, '[[' . makeUrlNS('Gallery', $imagename) . ']]', $text); |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
122 |
continue; |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
123 |
} |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
124 |
|
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
125 |
if ( $scale_type == '|thumb' ) |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
126 |
{ |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
127 |
$r_width = 225; |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
128 |
$r_height = 225; |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
129 |
|
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
130 |
$url = makeUrlNS('Special', 'GalleryFetcher/embed/' . $filename, 'width=' . $r_width . '&height=' . $r_height, true); |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
131 |
} |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
132 |
else if ( !empty($width) && !empty($height) ) |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
133 |
{ |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
134 |
$r_width = $width; |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
135 |
$r_height = $height; |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
136 |
|
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
137 |
$url = makeUrlNS('Special', 'GalleryFetcher/embed/' . $filename, 'width=' . $r_width . '&height=' . $r_height, true); |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
138 |
} |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
139 |
else |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
140 |
{ |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
141 |
$url = makeUrlNS('Special', 'GalleryFetcher/' . $filename); |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
142 |
} |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
143 |
|
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
144 |
$img_tag = '<img src="' . $url . '" '; |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
145 |
|
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
146 |
// if ( isset($r_width) && isset($r_height) && $scale_type != '|thumb' ) |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
147 |
// { |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
148 |
// $img_tag .= 'width="' . $r_width . '" height="' . $r_height . '" '; |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
149 |
// } |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
150 |
|
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
151 |
$img_tag .= 'style="border-width: 0px; /* background-color: white; */" '; |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
152 |
|
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
153 |
$code = $plugins->setHook('snapr_img_tag_parse_img'); |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
154 |
foreach ( $code as $cmd ) |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
155 |
{ |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
156 |
eval($cmd); |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
157 |
} |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
158 |
|
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
159 |
$img_tag .= '/>'; |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
160 |
|
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
161 |
$complete_tag = ''; |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
162 |
|
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
163 |
if ( !empty($scale_type) && $caption != '|raw' ) |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
164 |
{ |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
165 |
$complete_tag .= '<div class="thumbnail" '; |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
166 |
$clear_text = ''; |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
167 |
if ( !empty($clear) ) |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
168 |
{ |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
169 |
$side = ( $clear == '|left' ) ? 'left' : 'right'; |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
170 |
$opposite = ( $clear == '|left' ) ? 'right' : 'left'; |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
171 |
$clear_text .= "float: $side; margin-$opposite: 20px; width: {$r_width}px;"; |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
172 |
$complete_tag .= 'style="' . $clear_text . '" '; |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
173 |
} |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
174 |
$complete_tag .= '>'; |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
175 |
|
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
176 |
$complete_tag .= '<a href="' . makeUrlNS('Gallery', $filename) . '" style="display: block;">'; |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
177 |
$complete_tag .= $img_tag; |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
178 |
$complete_tag .= '</a>'; |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
179 |
|
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
180 |
$mag_button = '<a href="' . makeUrlNS('Gallery', $filename) . '" style="display: block; float: right; clear: right; margin: 0 0 10px 10px;"><img alt="[ + ]" src="' . scriptPath . '/images/thumbnail.png" style="border-width: 0px;" /></a>'; |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
181 |
|
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
182 |
if ( !empty($caption) ) |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
183 |
{ |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
184 |
$cap = substr($caption, 1); |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
185 |
$complete_tag .= $mag_button . $cap; |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
186 |
} |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
187 |
|
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
188 |
$complete_tag .= '</div>'; |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
189 |
} |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
190 |
else if ( $caption == '|raw' ) |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
191 |
{ |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
192 |
$complete_tag .= "$img_tag"; |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
193 |
$taglist[$i] = $complete_tag; |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
194 |
|
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
195 |
$repl = "{$s_delim}e_img_{$i}{$f_delim}"; |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
196 |
$text = str_replace($full_tag, $repl, $text); |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
197 |
continue; |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
198 |
} |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
199 |
else |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
200 |
{ |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
201 |
$complete_tag .= '<a href="' . makeUrlNS('Gallery', $filename) . '" style="display: block;"'; |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
202 |
$code = $plugins->setHook('snapr_img_tag_parse_link'); |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
203 |
foreach ( $code as $cmd ) |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
204 |
{ |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
205 |
eval($cmd); |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
206 |
} |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
207 |
$complete_tag .= '>'; |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
208 |
$complete_tag .= $img_tag; |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
209 |
$complete_tag .= '</a>'; |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
210 |
} |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
211 |
|
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
212 |
$complete_tag .= "\n\n"; |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
213 |
$taglist[$i] = $complete_tag; |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
214 |
|
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
215 |
$pos = strpos($text, $full_tag); |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
216 |
|
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
217 |
while(true) |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
218 |
{ |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
219 |
$check1 = substr($text, $pos, 3); |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
220 |
$check2 = substr($text, $pos, 1); |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
221 |
if ( $check1 == '<p>' || $pos == 0 || $check2 == "\n" ) |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
222 |
{ |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
223 |
// die('found at pos '.$pos); |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
224 |
break; |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
225 |
} |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
226 |
$pos--; |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
227 |
} |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
228 |
|
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
229 |
$repl = "{$s_delim}e_img_{$i}{$f_delim}"; |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
230 |
$text = substr($text, 0, $pos) . $repl . substr($text, $pos); |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
231 |
|
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
232 |
$text = str_replace($full_tag, '', $text); |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
233 |
|
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
234 |
unset($full_tag, $filename, $scale_type, $width, $height, $clear, $caption, $r_width, $r_height); |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
235 |
|
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
236 |
} |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
237 |
|
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
238 |
return $text; |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
239 |
} |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
240 |
|
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
241 |
/** |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
242 |
* Finalizes processing of image tags. |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
243 |
* @param string The preprocessed text |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
244 |
* @param array The list of image tags created by RenderMan::process_image_tags() |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
245 |
*/ |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
246 |
|
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
247 |
function snapr_image_tags_stage2($text, $taglist) |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
248 |
{ |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
249 |
$s_delim = "\xFF"; |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
250 |
$f_delim = "\xFF"; |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
251 |
foreach ( $taglist as $i => $tag ) |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
252 |
{ |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
253 |
$repl = "{$s_delim}e_img_{$i}{$f_delim}"; |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
254 |
$text = str_replace($repl, $tag, $text); |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
255 |
} |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
256 |
return $text; |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
257 |
} |
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
258 |
|
023a21c8f47c
Added support for embedding Snapr images as wikitext code into regular pages
Dan
parents:
diff
changeset
|
259 |
?> |