-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathopenattribute_widget.php
More file actions
138 lines (78 loc) · 3.37 KB
/
openattribute_widget.php
File metadata and controls
138 lines (78 loc) · 3.37 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
<?PHP
class OpenAttributeWidget extends WP_Widget {
function OpenAttributeWidget() {
$widgetSettings = array (
'classname' => 'OpenAttribute Widget',
'description' => 'Display a a license for your blog post or entire site in a widget'
);
$this->WP_Widget('openattribute_widget', 'OpenAttribute Widget', $widgetSettings, '');
}
function widget($args, $instance){
if(($instance['openattribute_link']) || $instance['openattribute_image']){
global $wp_query;
if(is_single()){
if(get_option('openattribute_widgetset')==1){
$disable = get_post_meta($wp_query->posts[0]->ID, 'disable_license');
if($disable[0]=="off"||$disable[0]==""){
$display = true;
if(get_option('openattribute_blogoverride')==1){
$content = $wp_query->posts[0]->post_content;
$author = explode("oaauthor",$content);
$title = explode("oatitle",$content);
$oashorthand = explode("oashorthand",$content);
if(count($author)!=1){
$display = false;
}
if(count($title)!=1){
$display = false;
}
if(count($oashorthand)!=1){
$display = false;
}
}
if($display){
echo $args['before_widget'];
echo $args['before_title'];
echo "Attribute me";
echo $args['after_title'];
if($instance['openattribute_image']){
echo "<a onclick=\"attribute_button(event)\" style=\"cursor:hand; cursor:pointer\"><img src=\"" . WP_PLUGIN_URL . "/" . str_replace(basename( __FILE__),'',plugin_basename(__FILE__)) . "attrib_button.png\" /></a>";
}
if($instance['openattribute_link']){
echo "<a onclick=\"attribute_button(event)\" style=\"cursor:hand; cursor:pointer\">Attribute this resource</a>";
}
echo $args['after_widget'];
}
}
}
}
}
}
public function update($new_instance, $old_instance) {
print_r($new_instance);
$instance = $old_instance;
$instance['openattribute_link'] = strip_tags($new_instance['openattribute_link']);
$instance['openattribute_image'] = strip_tags($new_instance['openattribute_image']);
return $instance;
}
function form($instance) {
?><p>Tick the respective box if you wish the following to appear in this widget:</p>
<input type="checkbox" name="<?PHP echo $this->get_field_name('openattribute_link'); ?>"<?PHP
if($instance['openattribute_link']==true){
echo " checked />";
}else{
echo " />";
}
?>
<label>"Attribute this resource"</label> <br />
<input type="checkbox" name="<?PHP echo $this->get_field_name('openattribute_image');?>" <?PHP
if($instance['openattribute_image']==true){
echo " checked />";
}else{
echo " />";
}
?>
<label>OpenAttribute image</label> <?PHP
}
}
?>