ubb-class-zeer-uitgebreid

Gesponsorde koppelingen

PHP script bestanden

  1. ubb-class-zeer-uitgebreid

« Lees de omschrijving en reacties

zie ook http://casteleyn.no-ip.info:8080/~Hipska/Extra/classes/UBB/index.php

class.ubb.php

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
<?php

/***********************************************
    
    Name: UBB parser
    Version: 1.1
    Author: Hipska, thanks to Jelmer and Willem-Jan
    License: GNU/GPL
    
***********************************************/


class ubb {
    
    var
$code    = array();
    var
$smiley    = array(
        "&lt;:-P"    => 'Angry-Tongue.png',
        "&lt;:P"    => 'Angry-Tongue.png',
        "&lt;:-("    => 'Angry.png',
        "&lt;:("    => 'Angry.png',
        ":-]"    => 'Blushing.png',
        ":]"    => 'Blushing.png',
        ":-?"    => 'Confused.png',
        ":?"    => 'Confused.png',
        "B-)"    => 'Cool.png',
        "B)"    => 'Cool.png',
        "8-)"    => 'Cool.png',
        "8)"    => 'Cool.png',
        ":'("    => 'Crying.png',
        ":'-("    => 'Crying.png',
        ":-["    => 'Embarrassed.png',
        ":["    => 'Embarrassed.png',
        "&lt;:-D"    => 'Evil.png',
        "&lt;:D"    => 'Evil.png',
        ":-("    => 'Frown.png',
        ":("    => 'Frown.png',
        ":-O"    => 'Gasp.png',
        ":O"    => 'Gasp.png',
        "X-("    => 'Grimmace.png',
        "X("    => 'Grimmace.png',
        ":-D"    => 'Grin.png',
        ":D"    => 'Grin.png',
        ";-D"    => 'Grinning-Wink.png',
        ";D"    => 'Grinning-Wink.png',
        "O:-)"    => 'Innocent.png',
        "0:)"    => 'Innocent.png',
        ":-*"    => 'Kiss.png',
        ":*"    => 'Kiss.png',
        ":-X"    => 'Lips-Are-Sealed.png',
        ":X"    => 'Lips-Are-Sealed.png',
        "&lt;:-)"    => 'Mischievous.png',
        "&lt;:)"    => 'Mischievous.png',
        ':-$'    => 'Money-Mouth.png',
        ':$'    => 'Money-Mouth.png',
        "&lt;:-|"    => 'Not-Amused.png',
        "&lt;:|"    => 'Not-Amused.png',
        ":-!"    => 'Oops.png',
        ":!"    => 'Oops.png',
        ":-@"    => 'Shouting.png',
        ":@"    => 'Shouting.png',
        "|-)"    => 'Sleeping.png',
        "I-)"    => 'Sleeping.png',
        ":-)"    => 'Smile.png',
        ":)"    => 'Smile.png',
        ":-&lt;"    => 'Smirk.png',
        ":&lt;"    => 'Smirk.png',
        ":-|"    => 'Straight-Faced.png',
        ":|"    => 'Straight-Faced.png',
        ":-I"    => 'Straight-Faced.png',
        ":I"    => 'Straight-Faced.png',
        ":-P"    => 'Tongue.png',
        ":P"    => 'Tongue.png',
        ":-\\"    => 'Undecided.png',
        ":\\"    => 'Undecided.png',
        ";-P"    => 'Wink-Tongue.png',
        ";P"    => 'Wink-Tongue.png',
        ";-)"    => 'Wink.png',
        ";)"    => 'Wink.png'
    ); // standard smileys
    var $text    = '';
    var
$size    = 300; // standard thumbnail size (px)
    
    function ubb($size = null, $smileys = null){
        if(is_array($smileys))    $this->smiley = $smileys;
        if(is_numeric($size))    $this->size = $size;
    }
    
    function
ubb_ignore($string = '', $return = false){
        
        if(!empty($string)) $this->setText($string);
        $this->text = preg_replace('#\[ignore\](.*?)\[/ignore\]#sie',"\$this->_ignore('\\1')",$this->text);
        if($return) return $this->getText();
    }
    function
ubb_code($string = '', $return = false){
        
        if(!empty($string)) $this->setText($string);
        
        $this->text = preg_replace('#\[code\](.*?)\[/code\]#sie',"\$this->_highlight('\\1')",$this->text);
        $this->text = preg_replace('#\[code=(.+?)\](.*?)\[/code\]#sie',"\$this->_highlight('\\2','\\1')",$this->text);
        $this->text = preg_replace('#<\?(.*?)\?>#sie',"\$this->_highlight('<?\\1?>')",$this->text);
        
        if($return) return $this->getText();
    }
    function
ubb_html($string = '', $return = false){
        
        if(!empty($string)) $this->setText($string);
        
        // HTML codes wegwerken
         $this->text = htmlspecialchars($this->text);
         // newlines maken
         $this->text = nl2br($this->text);
         
         if($return) return $this->getText();
    }
    function
ubb_opmaak($string = '', $return = false){
        
        if(!empty($string)) $this->setText($string);
        
        // Cursief
        $this->text = preg_replace('#\[i\](.+?)\[/i\]#si','<span style="font-style: italic;">\\1</span>',$this->text);
        // Onderstreept
        $this->text = preg_replace('#\[u\](.+?)\[/u\]#si','<span style="text-decoration: underline;">\\1</span>',$this->text);
        // Vetgedrukt
        $this->text = preg_replace('#\[b\](.+?)\[/b\]#si','<span style="font-weight: bold;">\\1</span>',$this->text);
        // Doorstreept
        $this->text = preg_replace('#\[s\](.+?)\[/s\]#si','<span style="text-decoration: line-through;">\\1</span>',$this->text);
        // Kleur
        $this->text = preg_replace('#\[color=(.+?)\](.+?)\[/color\]#si','<span style="color: \\1;">\\2</span>',$this->text);
        // Grootte
        $this->text = preg_replace('#\[size=([1-9]{1})\](.+?)\[/size\]#si','<span style="font-size: \\1ex;">\\2</span>',$this->text);
        $this->text = preg_replace('#\[size=([a-z\-]{5,8})\](.+?)\[/size\]#si','<span style="font-size: \\1;">\\2</span>',$this->text);
        // Uitlijning
        $this->text = preg_replace('#\[align=([a-z]{4,7})\](.+?)\[/align\]#si','<div style="text-align: \\1;">\\2</div>',$this->text);

        if($return) return $this->getText();
    }
    function
ubb_url($string = '', $return = false){
        
        if(!empty($string)) $this->setText($string);
        
        // Links maken met behulp van tags
        $this->text = preg_replace('#\[url\]((([a-z0-9]{1,6}:[/]{2}|\#|\?)|([a-z0-9]{1,6}:))(.+?))\[/url\]#si','<a href="\\1">\\3\\5</a>',$this->text);
        $this->text = preg_replace('#\[url\](.+?)\[/url\]#si','<a href="http://\\1">\\1</a>',$this->text);
        // Links maken met titel
        $this->text = preg_replace('#\[url=([a-z0-9]{1,6}:(.+?))\](.+?)\[/url\]#si','<a href="\\1">\\3</a>',$this->text);
        $this->text = preg_replace('#\[url=(.+?)\](.+?)\[/url\]#si','<a href="http://\\1">\\2</a>',$this->text);
        // Mailto links
        $this->text = preg_replace('#\[mail\](.+?)\[/mail\]#si','<a href="mailto:\\1">\\1</a>',$this->text);
        // Skype links
        $this->text = preg_replace('#\[skype\](.+?)\[/skype\]#si','<a href="callto:\\1">\\1</a>',$this->text);
        if($return) return $this->getText();
    }
    function
ubb_autourl($string = '', $return = false){
        
        if(!empty($string)) $this->setText($string);
        
        // Automatisch links maken
        $this->text = preg_replace('#(^|[ \n\r\t])([a-z0-9]{1,6}://([a-z0-9\-]{1,}(\.?)){1,}[a-z]{2,5}(:[0-9]{2,5}){0,1}((\/|~|\#|\?|=|&amp;|&|\+){1}[a-z0-9\-._%]{0,}){0,})#si', '\\1<a href="\\2">\\2</a>',$this->text);
        $this->text = preg_replace('#(^|[ \n\r\t])((www\.){1}([a-z0-9\-]{1,}(\.?)){1,}[a-z]{2,5}(:[0-9]{2,5}){0,1}((\/|~|\#|\?|=|&amp;|&|\+){1}[a-z0-9\-._%]{0,}){0,})#si', '\\1<a href="http://\\2">\\2</a>',$this->text);
        $this->text = preg_replace('#(^|[ \n\r\t])(([a-z0-9\-_]{1,}(\.?)){1,}@([a-z0-9\-]{1,}(\.?)){1,}[a-z]{2,5})#si', '\\1<a href="mailto:\\2">\\2</a>',$this->text);
        
        if($return) return $this->getText();
    }
    function
ubb_img($string = '', $return = false){
        
        if(!empty($string)) $this->setText($string);
        
        // Plaatjes
        $this->text = preg_replace('#\[img\](.+?)\[/img\]#si','<a href="\\1" rel="lightbox"><img src="'.INCLUDES.'image.php?file=[img]\\1[/img]&amp;size='.$this->size.'" alt="Afbeelding"/></a>',$this->text);
        $this->text = preg_replace('#\[img=(.+?)\](.+?)\[/img\]#si','<a href="\\2" rel="lightbox" title="\\1"><img src="'.INCLUDES.'image.php?file=[img]\\2[/img]&amp;size='.$this->size.'" alt="\\1"/></a>',$this->text);
        $this->text = preg_replace('#\[img\](.+?)\[/img\]#sie','urlencode("\\1")',$this->text);
        
        if($return) return $this->getText();
    }
    function
ubb_smiley($string = '', $return = false){
        
        if(!empty($string)) $this->setText($string);
        
        // Smileys
        foreach ($this->smiley as $key => $img) {
            $this->text = str_replace(' '.$key,' <img src="'.INCLUDES.'images/smilies/'.$img.'" alt="'.$key.'"/>',$this->text);
            $this->text = str_replace($key.' ','<img src="'.INCLUDES.'images/smilies/'.$img.'" alt="'.$key.'"/> ',$this->text);
        //    $this->text = preg_replace('#(^|[ \n\r\t]?)('.quotemeta($key).')(^|[ \n\r\t]?)#is','\\1<img src="'.INCLUDES.'images/smilies/'.$img.'" alt="'.$key.'" />\\3',$this->text);    // commented because it gives a max execution time limit error ...
        }
        
        if($return) return $this->getText();
    }
    function
ubb_quote($string = '', $return = false){
        if(!empty($string)) $this->setText($string);
        
        // qoute
        $this->text = preg_replace('#\[quote\](<br />)(.+?)\[/quote\]#si','<div class="Block"><small>Quote</small><div class="Quote">\\2</div></div>',$this->text);
         $this->text = preg_replace('#\[quote=(.+?)\](<br />)(.+?)\[/quote\]#si','<div class="Block"><small>Quote: <b>\\1</b></small><div class="Quote">\\3</div></div>',$this->text);
        
        if($return) return $this->getText();
    }
    function
ubb_list($string = '', $return = false){
        if(!empty($string)) $this->setText($string);
        
        // make an ordered or un-ordered list
        $this->text = preg_replace('#\[ul\](<br />){0,}(.+?)\[/ul\](<br />){0,}#si','<ul>\\2</ul>',$this->text);
        $this->text = preg_replace('#\[ol\](<br />){0,}(.+?)\[/ol\]#si','<ol>\\2</ol>',$this->text);
        
        $this->text = preg_replace('#\[li\](.+?)\[/li\](<br />){0,}#si','<li>\\1</li>',$this->text);
        
        if($return) return $this->getText();
    }
    function
ubb_search($string = '', $return = false){
        if(!empty($string)) $this->setText($string);
        
        // search words (word1+word2)
        $search = array();
         $this->text = preg_replace('#\[search=((([a-z_0-9]{1,})(\+?)){1,})\](.+?)\[/search\]#sie','$this->_search("\\1","\\5")',$this->text);
        
        if($return) return $this->getText();
    }
    function
ubb_spoil($string = '', $return = false){
        if(!empty($string)) $this->setText($string);
        
        // spoiler
         $this->text = preg_replace('#\[spoiler=(.+?)\](.+?)\[/spoiler\]#sie',"'<input type=\"button\" value=\"\\1\" onclick=\"javascript:ShowHide(\'spoil_'.md5('\\1').'\');\" /><div class=\"Block\"><div id=\"spoil_'.md5('\\1').'\" class=\"Spoiler\">'.stripslashes('\\2').'</div></div>'",$this->text);
        
        if($return) return $this->getText();
    }
    
    function
parse($string = '', $tags = array()){
        if(!empty($string)) $this->setText($string);
        foreach ($tags as $tag){
            $method = 'ubb_'.$tag;
            if(method_exists($this,$method)) $this->$method();
        }

        return $this->getText();
    }
    function
parse_all($string = ''){
        if(!empty($string)) $this->setText($string);
        
        $methods = get_class_methods($this);
        foreach ($methods as $method){
            $sub = explode('_',$method);
            if($sub[0] == 'ubb' and count($sub) > 1) $this->$method();
        }

        return $this->getText();
    }
    
    function
setText($string){
        $this->text = $string;
        $this->code = array();
    }
    function
getText(){
        $this->text = preg_replace('#\[highlight\]([0-9])\[/highlight\]#sie','$this->_highlight(\\1)',$this->text);
        $this->text = preg_replace('#\[highlight=(.+?)\]([0-9])\[/highlight\]#sie','$this->_highlight(\\2,"\\1")',$this->text);
        $this->text = preg_replace('#\[ignore\]([0-9])\[/ignore\]#sie','$this->_ignore(\\1)',$this->text);
        return $this->text;
    }
    
    function
_highlight($code, $file = false){
        if(is_numeric($code)){
            $highlight = '<div class="Block"><small>Code';
            if($file) $highlight .= ': <b>'.$file.'</b>';
            $highlight .= '</small><div class="Code"><div class="CodeLines">';        
            $n = 0; $lines = explode("\n",$this->code[$code]);
            
            $code = highlight_string($this->code[$code], true);
               $code = str_replace(array('<font ', '</font>', '<code>', '</code>'), array('<span ', '</span>', '', ''), $code);
               $code = preg_replace('#color="(.*?)"#', 'style="color: \\1;"', $code);
               
            while ($n < count($lines)) $highlight .= ++$n.'<br />';
            $highlight .= '</div><div class="CodeCode">'.
            substr($code,30,-8)
            .
'</div></div></div>';
            return $highlight;
            
        }
else{
            $n = array_push($this->code,trim(str_replace("\\\"", "\"", $code)));
            if($file) return '[highlight='.$file.']'.--$n.'[/highlight]';
            else return '[highlight]'.--$n.'[/highlight]';
        }
    }
    function
_ignore($code){
        if(is_numeric($code)){
            return $this->code[$code];
        }
else{
            $n = array_push($this->code,nl2br(htmlspecialchars($code)));
            return '[ignore]'.--$n.'[/ignore]';
        }
    }
    function
_search($search,$text){
        $search = explode('+',$search);
        foreach ($search as $word){
            $color = '#';
            for ($i = 0; $i < 3; $i++ )
                $color .= str_pad(dechex(( round(rand(0,255)/51) * 51 )), 2, '0', STR_PAD_LEFT);
            $text = preg_replace('#(^|[ \n\r\t])(' . trim($word) . ')(^|[ \n\r\t\,\.\;\:])#si', '\\1<span style="background-color: '.$color.';">\\2</span>\\3', $text);
        }

        return $text;
    }
    
}

?>


image.php

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php

$default_img
= 'images/no-image.jpg';
//var_dump(gd_info()); // look if you have libGD installed <-- zeker eens doen!

// set the default image

$img = getimagesize($default_img);
list($width, $height, $type) = $img;
$default_img = array(    'width' => $width, 'height' => $height,
                        'new_width' => $width, 'new_height' => $height,
                        'mime' => $img['mime'], 'type' => $type,
                        'file' => $default_img );

// set the max size
if(isset($_GET['size'])) $max = (int) $_GET['size'];
else $max = $width;

// prepare image sizes
if(isset($_GET['file']) and $img = @getimagesize($_GET['file'])){
    
    list($width, $height, $type) = $img;
    
    if($width > $max){
        $nwidth = $max;
        $nheight = (int) round($height/($width/$max));
    }
else {
        $nwidth = $width;
        $nheight = $height;
    }

    
    $img = array(    'width' => $width, 'height' => $height,
                    'new_width' => $nwidth, 'new_height' => $nheight,
                    'mime' => $img['mime'], 'type' => $type,
                    'file' => $_GET['file'] );
    
}
else $img = $default_img;
//var_dump($img);

// load image
/* easier script found
switch ($img['type']){
    case IMG_JPEG: $data = imagecreatefromjpeg($img['file']); break;
    case IMG_GIF: $data = imagecreatefromgif($img['file']); break;
    case IMG_PNG: $data = imagecreatefrompng($img['file']); break;
} */

$data = imagecreatefromstring(file_get_contents($img['file']));

// resize image
$tmp_data = imagecreatetruecolor($img['new_width'], $img['new_height']);
imagecopyresampled($tmp_data, $data, 0,0,0,0, $img['new_width'], $img['new_height'], $img['width'], $img['height']);
imagedestroy($data);
$data = $tmp_data;

// return image
header('Content-type: image/png');
imagepng($data);
imagedestroy($data);

?>


css/ubb.css

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/* CSS voor UBB Code */
img {
    border-style: none;
    vertical-align: middle;
    margin: 2px;
}
.Block {
    margin: 10px 5%;
}
.Quote {
    border: 1px dashed; padding: 10px;
}
.Code {
    border: 1px dotted;
    background-color: #fcff9f;
    font: small "Courier New", Courier, mono;
    white-space: nowrap;
}
.CodeLines {
    text-align: right;
    float: left;
    padding: 4px 2px;
}
.CodeCode {
    overflow: auto;
    margin-right: 1px;
    padding: 4px;
    background-color: #fff;
}
.Spoiler {
    display: none;
    border: 1px dotted;
    padding: 10px;
}


voorbeeld.php

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
<?php
define('INCLUDES', './');
include('class.ubb.php');

$tags = array('ignore','html','opmaak','url','img','quote'); // deze tags zal hij uitvoeren ubb_TAG(); (kijk in de klasse wat het precies doet)
$text = 'Tekst met ubb code';

$ubb = new ubb();

echo $ubb->parse_all($text); // deze functie doet alle ubb code's
// of :

echo $ubb->parse($text, $tags); // deze functie doet enkel de code's die jij wil

?>

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.