20
20
// Initiate class to hold plugin events
21
21
class plgK2Example extends K2Plugin
22
22
{
23
-
24
- // Some params
25
- var $ pluginName = 'example ' ;
26
- var $ pluginNameHumanReadable = 'Example K2 Plugin ' ;
27
-
28
- function __construct (&$ subject , $ params )
29
- {
30
- parent ::__construct ($ subject , $ params );
31
-
32
- }
33
-
34
- /**
35
- * Below we list all available FRONTEND events, to trigger K2 plugins.
36
- * Watch the different prefix "onK2" instead of just "on" as used in Joomla! already.
37
- * Most functions are empty to showcase what is available to trigger and output. A few are used to actually output some code for example reasons.
38
- */
39
-
40
- function onK2PrepareContent (&$ item , &$ params , $ limitstart )
41
- {
42
- $ mainframe = JFactory::getApplication ();
43
- //$item->text = 'It works! '.$item->text;
44
- }
45
-
46
- function onK2AfterDisplay (&$ item , &$ params , $ limitstart )
47
- {
48
- $ mainframe = JFactory::getApplication ();
49
- return '' ;
50
- }
51
-
52
- function onK2BeforeDisplay (&$ item , &$ params , $ limitstart )
53
- {
54
- $ mainframe = JFactory::getApplication ();
55
- return '' ;
56
- }
57
-
58
- function onK2AfterDisplayTitle (&$ item , &$ params , $ limitstart )
59
- {
60
- $ mainframe = JFactory::getApplication ();
61
- return '' ;
62
- }
63
-
64
- function onK2BeforeDisplayContent (&$ item , &$ params , $ limitstart )
65
- {
66
- $ mainframe = JFactory::getApplication ();
67
- return '' ;
68
- }
69
-
70
- // Event to display (in the frontend) the YouTube URL as entered in the item form
71
- function onK2AfterDisplayContent (&$ item , &$ params , $ limitstart )
72
- {
73
- $ mainframe = JFactory::getApplication ();
74
-
75
- // Get the output of the K2 plugin fields (the data entered by your site maintainers)
76
- $ plugins = new K2Parameter ($ item ->plugins , '' , $ this ->pluginName );
77
-
78
- $ videoURL = $ plugins ->get ('videoURL_item ' );
79
-
80
- // Check if we have a value entered
81
- if (empty ($ videoURL ))
82
- return ;
83
-
84
- // Output
85
- preg_match ('/youtube\.com\/watch\?v=([a-z0-9-_]+)/i ' , $ videoURL , $ matches );
86
- $ video_id = $ matches [1 ];
87
-
88
- $ output = '
23
+ // Some params
24
+ public $ pluginName = 'example ' ;
25
+ public $ pluginNameHumanReadable = 'Example K2 Plugin ' ;
26
+
27
+ public function __construct (&$ subject , $ params )
28
+ {
29
+ parent ::__construct ($ subject , $ params );
30
+ }
31
+
32
+ /**
33
+ * Below we list all available FRONTEND events, to trigger K2 plugins.
34
+ * Watch the different prefix "onK2" instead of just "on" as used in Joomla! already.
35
+ * Most functions are empty to showcase what is available to trigger and output. A few are used to actually output some code for example reasons.
36
+ */
37
+
38
+ public function onK2PrepareContent (&$ item , &$ params , $ limitstart )
39
+ {
40
+ $ mainframe = JFactory::getApplication ();
41
+ //$item->text = 'It works! '.$item->text;
42
+ }
43
+
44
+ public function onK2AfterDisplay (&$ item , &$ params , $ limitstart )
45
+ {
46
+ $ mainframe = JFactory::getApplication ();
47
+ return '' ;
48
+ }
49
+
50
+ public function onK2BeforeDisplay (&$ item , &$ params , $ limitstart )
51
+ {
52
+ $ mainframe = JFactory::getApplication ();
53
+ return '' ;
54
+ }
55
+
56
+ public function onK2AfterDisplayTitle (&$ item , &$ params , $ limitstart )
57
+ {
58
+ $ mainframe = JFactory::getApplication ();
59
+ return '' ;
60
+ }
61
+
62
+ public function onK2BeforeDisplayContent (&$ item , &$ params , $ limitstart )
63
+ {
64
+ $ mainframe = JFactory::getApplication ();
65
+ return '' ;
66
+ }
67
+
68
+ // Event to display (in the frontend) the YouTube URL as entered in the item form
69
+ public function onK2AfterDisplayContent (&$ item , &$ params , $ limitstart )
70
+ {
71
+ $ mainframe = JFactory::getApplication ();
72
+
73
+ // Get the output of the K2 plugin fields (the data entered by your site maintainers)
74
+ $ plugins = new K2Parameter ($ item ->plugins , '' , $ this ->pluginName );
75
+
76
+ $ videoURL = $ plugins ->get ('videoURL_item ' );
77
+
78
+ // Check if we have a value entered
79
+ if (empty ($ videoURL )) {
80
+ return ;
81
+ }
82
+
83
+ // Output
84
+ preg_match ('/youtube\.com\/watch\?v=([a-z0-9-_]+)/i ' , $ videoURL , $ matches );
85
+ $ video_id = $ matches [1 ];
86
+
87
+ $ output = '
89
88
<p> ' .JText::_ ('Video rendered using the "Example K2 Plugin". ' ).'</p>
90
89
<object width=" ' .$ this ->params ->get ('width ' ).'" height=" ' .$ this ->params ->get ('height ' ).'">
91
90
<param name="movie" value="http://www.youtube.com/v/ ' .$ video_id .'&hl=en&fs=1"></param>
@@ -95,33 +94,39 @@ function onK2AfterDisplayContent(&$item, &$params, $limitstart)
95
94
</object>
96
95
' ;
97
96
98
- return $ output ;
99
- }
100
-
101
- // Event to display (in the frontend) the YouTube URL as entered in the category form
102
- function onK2CategoryDisplay (&$ category , &$ params , $ limitstart )
103
- {
104
- $ mainframe = JFactory::getApplication ();
97
+ return $ output ;
98
+ }
105
99
106
- // Get the output of the K2 plugin fields (the data entered by your site maintainers)
107
- $ plugins = new K2Parameter ($ category ->plugins , '' , $ this ->pluginName );
100
+ // Event to display (in the frontend) the YouTube URL as entered in the category form
101
+ public function onK2CategoryDisplay (&$ category , &$ params , $ limitstart )
102
+ {
103
+ $ mainframe = JFactory::getApplication ();
108
104
109
- $ output = $ plugins ->get ('videoURL_cat ' );
105
+ // Get the output of the K2 plugin fields (the data entered by your site maintainers)
106
+ $ plugins = new K2Parameter ($ category ->plugins , '' , $ this ->pluginName );
110
107
111
- return $ output ;
112
- }
108
+ $ output = $ plugins ->get ('videoURL_cat ' );
113
109
114
- // Event to display (in the frontend) the YouTube URL as entered in the user form
115
- function onK2UserDisplay (&$ user , &$ params , $ limitstart )
116
- {
117
- $ mainframe = JFactory::getApplication ();
110
+ return $ output ;
111
+ }
118
112
119
- // Get the output of the K2 plugin fields (the data entered by your site maintainers)
120
- $ plugins = new K2Parameter ($ user ->plugins , '' , $ this ->pluginName );
113
+ // Event to display (in the frontend) the YouTube URL as entered in the user form
114
+ public function onK2UserDisplay (&$ user , &$ params , $ limitstart )
115
+ {
116
+ $ mainframe = JFactory::getApplication ();
121
117
122
- $ output = $ plugins ->get ('videoURL_user ' );
118
+ // Get the output of the K2 plugin fields (the data entered by your site maintainers)
119
+ $ plugins = new K2Parameter ($ user ->plugins , '' , $ this ->pluginName );
123
120
124
- return $ output ;
125
- }
121
+ $ output = $ plugins ->get ('videoURL_user ' );
126
122
123
+ return $ output ;
124
+ }
125
+
126
+ // Event to replace default commenting system
127
+ public function K2CommentsBlock (&$ item , &$ params , $ limitstart )
128
+ {
129
+ $ mainframe = JFactory::getApplication ();
130
+ return '' ;
131
+ }
127
132
} // END CLASS
0 commit comments