Repository navigation
Expand file tree
/
Copy path_star.plugin.php
More file actions
142 lines (120 loc) · 3.08 KB
/
Copy path_star.plugin.php
File metadata and controls
142 lines (120 loc) · 3.08 KB
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
<?php
/**
* This file implements the Star renderer plugin for b2evolution
*
* Star formatting, like [stars:2.3/5]
*
* b2evolution - {@link http://b2evolution.net/}
* Released under GNU GPL License - {@link http://b2evolution.net/about/gnu-gpl-license}
* @copyright (c)2003-2020 by Francois Planque - {@link http://fplanque.com/}
*
* @package plugins
*
* @version $
*/
if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
/**
* @package plugins
*/
class star_plugin extends Plugin
{
var $code = 'b2evStar';
var $name = 'Star renderer';
var $priority = 55;
var $version = '7.3.0';
var $group = 'rendering';
var $short_desc;
var $long_desc;
var $help_topic = 'star-plugin';
var $number_of_installs = 1;
/**
* Init
*/
function PluginInit( & $params )
{
$this->short_desc = T_('Star formatting e-g [stars:2.3/5]');
$this->long_desc = T_('This plugin allows to render star ratings inside blog posts and comments by using the syntax [stars:2.3/5] for example');
}
/**
* Define here default email settings that are to be made available in the backoffice.
*
* @param array Associative array of parameters.
* @return array See {@link Plugin::GetDefaultSettings()}.
*/
function get_email_setting_definitions( & $params )
{
// Set empty array to disable this plugin for Email Campaign:
return array();
}
/**
* Event handler: Called when ending the admin html head section.
*
* @param array Associative array of parameters
* @return boolean did we do something?
*/
function AdminEndHtmlHead( & $params )
{
$this->SkinBeginHtmlHead( $params );
}
/**
* Perform rendering
*
* @see Plugin::RenderItemAsHtml()
*/
function DisplayItemAsHtml( & $params )
{
$params['data'] = $this->render_stars( $params['data'] );
return true;
}
/**
* Do the same as for HTML.
*
* @see RenderItemAsHtml()
*/
function DisplayItemAsXml( & $params )
{
return $this->DisplayItemAsHtml( $params );
}
/**
* Render stars template from [[stars:3/7]
* to <span class="evo_stars_img" style="width:112px">
* <i>*</i>
* <i>*</i>
* <i class="evo_stars_img_empty"><i style="width:50%">%</i></i>
* <i class="evo_stars_img_empty">-</i>
* <i class="evo_stars_img_empty">-</i>
* </span>
*
* @param string Source content
* @return string Rendered content
*/
function render_stars( $content )
{
return replace_outside_code_tags( '#\[stars:([\d\.]+)(/\d+)?\]#', array( $this, 'get_stars_template' ), $content, 'replace_content_callback' );
}
/**
* Get HTML template for stars
*
* @param array Matches
* @return string HTML stars
*/
function get_stars_template( $matches )
{
global $b2evo_icons_type;
if( empty( $matches ) )
{ // No stars found
return;
}
$active_stars = $matches[1];
if( ! empty( $matches[2] ) )
{ // Get a number of stars from content
$number_stars = intval( substr( $matches[2], 1 ) );
}
if( empty( $number_stars ) )
{ // Use 5 stars by default
$number_stars = 5;
}
return get_star_rating( $active_stars, $number_stars );
}
}
?>