-
Notifications
You must be signed in to change notification settings - Fork 0
/
related-games-plugin.php
143 lines (125 loc) · 4.39 KB
/
related-games-plugin.php
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
<?php
/*
Plugin Name: Related Games
Plugin URI: http://www.games.com/
Description: A customizable widget which displays the latest related Games Tag/Category Based from http://www.games.com/.
Version: 1.0
Author: AOL Games
Author URI: http://www.games.com/
License: GPL3
Developer: Dhanu Gupta
*/
require_once("XMLParser.php");
function relatedgames()
{
$options = get_option("widget_relatedgames");
if (!is_array($options)){
$options = array(
'title' => 'Games News',
'news' => '3',
'chars' => '30'
);
}
global $post; //Define the global post object to access the post tags and categories
if($taxonomy == '') { $taxonomy = 'post_tag'; }
$tags = wp_get_post_terms($post->ID, $taxonomy);
$category = wp_get_post_terms($post->ID, 'category');
if($category){$first_category = $category[0]->slug;}
if($tags) { $first_tag = $tags[0]->slug; }
$query_term = "";
if(strlen($first_tag) >0) { $query_term = $first_tag;} else { $query_term =$first_category;}
//Feed URL
$url = "http://www.games.com/feeds/gamesBrowse/?q=".$query_term;
$xml = file_get_contents($url);
//Set up the parser object
$parser = new xmlToArrayParser($xml);
$domArr = $parser->array;
if(count($domArr['rss']['channel']['item']) == 7) {
$url = "http://www.games.com/feeds/gamesBrowse/?q=".$query_term."+games";
$xml = file_get_contents($url);
//Set up the parser object
$parser = new xmlToArrayParser($xml);
$domArr = $parser->array;
}
if(count($domArr['rss']['channel']['item']) ==0) {
$url = "http://www.games.com/feeds/gamesBrowse/";
$xml = file_get_contents($url);
//Set up the parser object
$parser = new xmlToArrayParser($xml);
$domArr = $parser->array;
}
//Stylesheet
echo "<link rel='stylesheet' type='text/css' href='wp-content/plugins/related-games/style.css' />";
if(count($domArr) >0) {
echo '<ul>';
$itemarr = $domArr['rss']['channel']['item'];
for ($i=0;$i<$options['news'];$i++){
$titl= $domArr['rss']['channel']['item'][$i]['title'];
$desc= $domArr['rss']['channel']['item'][$i]['description'];
$link= $domArr['rss']['channel']['item'][$i]['link'];
$desc = str_replace("<br/>","",$desc);
$desc = str_replace("Play Free Online","",$desc);
echo '<li><a href="'.$link.'" title="Play '.$titl.' Game">'.$desc.'</a></li>';
}
//echo '<p class="sitelink">powered by <a href="http://games.com" title="AOL Games"><img src="http://o.aolcdn.com/os/games/images/logos/gamesdotcom" alt="games.com"/></a></p>';
echo '</ul>';
}
}
function widget_relatedgames($args)
{
extract($args);
$options = get_option("widget_relatedgames");
if (!is_array($options)){
$options = array(
'title' => 'Related Games',
'news' => '3',
'chars' => '30'
);
}
echo $before_widget;
echo $before_title;
echo $options['title'];
echo $after_title;
relatedgames();
echo $after_widget;
}
function relatedgames_control()
{
$options = get_option("widget_relatedgames");
if (!is_array($options)){
$options = array(
'title' => 'Related Games',
'news' => '5',
'chars' => '30'
);
}
if($_POST['relatedgames-Submit'])
{
$options['title'] = htmlspecialchars($_POST['relatedgames-WidgetTitle']);
$options['news'] = htmlspecialchars($_POST['relatedgames-NewsCount']);
$options['chars'] = htmlspecialchars($_POST['relatedgames-CharCount']);
update_option("widget_relatedgames", $options);
}
?>
<p>
<label for="relatedgames-WidgetTitle">Widget Title: </label>
<input type="text" id="relatedgames-WidgetTitle" name="relatedgames-WidgetTitle" value="<?php echo $options['title'];?>" />
<br /><br />
<label for="relatedgames-NewsCount">Max. News: </label>
<input type="text" id="relatedgames-NewsCount" name="relatedgames-NewsCount" value="<?php echo $options['news'];?>" />
<br /><br />
<label for="relatedgames-CharCount">Max. Characters: </label>
<input type="text" id="relatedgames-CharCount" name="relatedgames-CharCount" value="<?php echo $options['chars'];?>" />
<br /><br />
<input type="hidden" id="relatedgames-Submit" name="relatedgames-Submit" value="1" />
</p>
<?php
}
function relatedgames_init()
{
register_sidebar_widget(__('Related Games'), 'widget_relatedgames');
register_widget_control('Related Games', 'relatedgames_control', 300, 200);
}
//plugin loaded
add_action("plugins_loaded", "relatedgames_init");
?>