plugins/YouTubeIntegration: YouTubeIntegration.jplug.php

File YouTubeIntegration.jplug.php, 4.8 KB (added by driehle, 3 years ago)

Version 4

Line 
1<?php
2
3/**
4 * @name:        YouTubeIntegration
5 * @author:      Severin Vogt <http://www.severinvogt.ch>
6 * @version:     2.0
7 * @date:        2009-02-28
8 *
9 * This plugin integrates YouTube Videos
10 *
11 */
12
13define('YOUTUBE_INTEGRATION_CFG_FILE', JLOG_BASEPATH.'personal'.DIRECTORY_SEPARATOR.'settings.YouTubeIntegration.inc.php');
14
15// Load config file
16if (@file_exists(YOUTUBE_INTEGRATION_CFG_FILE)) {
17        include_once YOUTUBE_INTEGRATION_CFG_FILE;
18}
19
20
21// Apply BBCode
22function do_bbcode_youtube($action, $attributes, $content, $params, $node_object) {
23        if(!is_numeric(YOUTUBE_INTEGRATION_WIDTH)) {
24                $width = '401';
25        } else {
26                $width = YOUTUBE_INTEGRATION_WIDTH;
27        }
28               
29        if(!is_numeric(YOUTUBE_INTEGRATION_WIDTH)) {
30                $height = '330';
31        } else {
32                $height = YOUTUBE_INTEGRATION_HEIGHT;
33        }
34
35        $str_htmlcode = '
36                <object type="application/x-shockwave-flash" style="width: '.$width.'px; height: '.$height.'px;" data="http://www.youtube.com/v/'.$content.'"><param name="movie" value="http://www.youtube.com/v/'.$content.'"></object><br>
37                ';
38                       
39        return $str_htmlcode;
40}
41
42class YouTubeIntegration extends JlogPlugin {
43
44        // Define BB-Code parser
45        function hook_bbCode(&$obj_bbcode) {
46                $arr_youtube = array(
47                                                                "name" => "youtube",
48                                                                "callback_type" => "usecontent?",
49                                                                "callback_func" => "do_bbcode_youtube",
50                                                                "callback_params" => array("usecontent_param"=>"default"),
51                                                                "content_type" => "link",
52                                                                "allowed_within" => array("inline","block","listitem"),
53                                                                "not_allowed_within" => array(""),
54                                                                "flags" => array()
55                                                                       
56                                                        );
57   
58                $obj_bbcode->_codes['youtube'] = $arr_youtube;
59                               
60                return $obj_bbcode;
61        }
62       
63        // Add button to form
64        function hook_adminForm($form) {
65               
66                $additional_html = "
67               
68                <script type=\"text/javascript\">
69               
70                addLoadEvent(
71                        function () {
72                                if(jlog_bbcode_br || (typeof(jlog_admin) != 'undefined'))
73                                if (jlog_bbcode_br.insertBefore) {
74                                        jlog_bbcode_do_button('YouTube Video', '[youtube]', '[/youtube]');
75                                }
76                        }
77                );
78                </script>
79               
80                ";
81               
82                return $form.$additional_html;
83        }
84       
85        // Display configuration and some informations
86        function hook_adminContent($str_output) {               
87                if ($_POST['YOUTUBE_INTEGRATION_SAVE'] == '1') {
88                        if (is_numeric($_POST['YOUTUBE_INTEGRATION_WIDTH']) && is_numeric($_POST['YOUTUBE_INTEGRATION_HEIGHT'])) {
89                                if (($f = @fopen(YOUTUBE_INTEGRATION_CFG_FILE, 'wb'))) {
90                                        @fwrite($f, "<?php\n");
91                                        @fwrite($f, "define('YOUTUBE_INTEGRATION_WIDTH', '".$_POST['YOUTUBE_INTEGRATION_WIDTH']."');\n");
92                                        @fwrite($f, "define('YOUTUBE_INTEGRATION_HEIGHT', '".$_POST['YOUTUBE_INTEGRATION_HEIGHT']."');\n");
93                                        @fwrite($f, '?>');
94                                        @fclose($f);
95                                }
96
97                                $str_output = '
98                                        <br />
99                                        Die Werte wurden gespeichert.<br />
100                                        <br />
101                                        <a href="'.$_SERVER['REQUEST_URI'].'">&laquo;&nbsp;zur&uuml;ck</a>
102                                ';
103                        } else {
104                                $str_output = '
105                                        <br />
106                                        Die Werte m&uuml;ssen numerisch sein!<br />
107                                        <br />
108                                        <a href="javascript:history.back();">&laquo;&nbsp;zur&uuml;ck</a>
109                                ';
110                        }
111                } else {
112                        $str_output = '
113                               
114                                <br />
115                                Mit diesem Plugin k&ouml;nnen YouTube-Videos in den Blog integriert werden.<br />
116       
117                                <br />
118                                <hr />
119                                <br />
120                                <h2>Konfiguration</h2>
121                                <br />
122                               
123                                <form method="post" action="'.$_SERVER['REQUEST_URI'].'">
124                                        <table cellpadding="0" cellspacing="0">
125                                                <tr>
126                                                        <th>
127                                                                Bezeichnung
128                                                        </th>
129                                                        <th>
130                                                                Wert
131                                                        </th>
132                                                </tr>
133                                                <tr>
134                                                        <td>
135                                                                Breite:
136                                                        </td>
137                                                        <td>
138                                                                <input type="text" name="YOUTUBE_INTEGRATION_WIDTH" size="3" maxlength="4" value="'.$this->getWidth().'">&nbsp;px
139                                                        </td>
140                                                </tr>
141                                                <tr>
142                                                        <td>
143                                                                H&ouml;he:
144                                                        </td>
145                                                        <td>
146                                                                <input type="text" name="YOUTUBE_INTEGRATION_HEIGHT" size="3" maxlength="4" value="'.$this->getHeight().'">&nbsp;px
147                                                        </td>
148                                                </tr>
149                                                <tr>
150                                                        <td>
151                                                                &nbsp;
152                                                        </td>
153                                                        <td>
154                                                                <input type="hidden" name="YOUTUBE_INTEGRATION_SAVE" value="1">
155                                                                <input type="submit" value="speichern">
156                                                        </td>
157                                                </tr>
158                                        </table>
159                                </form>
160                               
161                                <br />
162                                <hr />
163                                <br />
164                                <h2>Beschreibung</h2>
165                                <br />
166                               
167                                Um ein YouTube-Video in den Blog einzuf$uuml;gen, muss die Video-ID von YouTube im entsprechenden BB-Code eingetragen werden.<br /><br />
168                                <b>Beispiel:</b><br />
169                                [youtube]<b>VIDEOID</b>*[/youtube]
170                                <br />
171                                <br />
172                                <i>*Die Video-ID sieht z.Bsp so aus: "LYhrYHmUPn0"</i>
173                        ';
174                }
175                               
176                return $str_output;
177        }
178       
179        // Gets width from defines
180        function getWidth() {
181                if(!is_numeric(YOUTUBE_INTEGRATION_WIDTH)) {
182                        $width = '401';
183                } else {
184                        $width = YOUTUBE_INTEGRATION_WIDTH;
185                }
186                return $width;
187        }
188       
189        // Gets height from defines
190        function getHeight() {                 
191                if(!is_numeric(YOUTUBE_INTEGRATION_WIDTH)) {
192                        $height = '330';
193                } else {
194                        $height = YOUTUBE_INTEGRATION_HEIGHT;
195                }
196                return $height;
197        }
198       
199}
200       
201?>