/
twitter-news-feed-admin.php
executable file
·158 lines (139 loc) · 5.8 KB
/
twitter-news-feed-admin.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<?php
/**
* Create Clean String
*
* Returns a clean comma separated array with no
* trailing comma and all white space removed
*
* @return string
**/
function create_clean_string($str) {
$myarr = explode(",", $str);
foreach ($myarr as $key => $value) {
$value = trim($value);
$value = str_replace(" ", "", $value);
if (is_null($value) || $value=="") {
unset($myarr[$key]);
} else {
$myarr[$key] = $value;
};
};
$myarr = ( implode(",", array_values($myarr)) );
return $myarr;
}
// Process $_POST for form id="tnf_options_form"
if($_POST["tnf_hidden"] == "Y") {
$hashtags = create_clean_string($_POST["tnf_hashtags"]);
$usernames = create_clean_string($_POST["tnf_usernames"]);
$category = $_POST["tnf_category"];
$user = $_POST["tnf_user"];
$post_type = $_POST["tnf_post_type"];
if($_POST["tnf_add_news_as_post"] == "Y") {
$add_news_to_db = "checked";
$add_news_to_db_boolean = TRUE;
} else {
$add_news_to_db = "";
$add_news_to_db_boolean = FALSE;
};
if($hashtags !="" || $usernames !="") {
update_option("tnf_hashtags", $hashtags);
update_option("tnf_usernames", $usernames);
update_option("tnf_category", $category);
update_option("tnf_user", $user);
update_option("tnf_add_news_to_db", $add_news_to_db_boolean);
update_option("tnf_post_type", $post_type);
$flash_success = "Twitter News Feed Options Updated";
} else {
$flash_error = "Please enter at least one Hashtag and one Twitter username";
};
} else {
// Get the options from the wp-options table using get_option($key);
$hashtags = get_option("tnf_hashtags");
$usernames = get_option("tnf_usernames");
$exceptions = get_option("tnf_exceptions");
$category = get_option("tnf_category");
$user = get_option("tnf_user");
$post_type = get_option("tnf_post_type");
// Add news as post?
if(get_option("tnf_add_news_to_db")) {
$add_news_to_db = "checked";
};
};
// Process $_POST for form id="tnf_get_news_form"
if($_POST["tnf_get_news_hidden"] == "Y" && get_option("tnf_add_news_to_db")) {
$retval = tnf_get_news(TRUE);
$flash_success = $retval." Tweet(s) added as Posts";
};
// If tnf_add_news_to_db == TRUE get the last 10 log entries
if(get_option("tnf_add_news_to_db")) {
global $wpdb;
$sql = "SELECT id, time, comment FROM ".$wpdb->prefix."tnf_log"." ORDER BY time DESC LIMIT 5";
$data = $wpdb->get_results($sql);
};
?>
<?php if(!$flash_success==""): ?>
<div class="updated">
<p><?php _e($flash_success); ?></p>
</div>
<?php endif ?>
<?php if(!$flash_error==""): ?>
<div class="error">
<p><?php _e($flash_error); ?></p>
</div>
<?php endif ?>
<div class="wrap">
<div id="icon-options-general" class="icon32"><br /></div>
<h2>Twitter News Feed Admin</h2>
<form name="tnf_options_form" method="post" action="<?php echo str_replace( "%7E", "~", $_SERVER["REQUEST_URI"]); ?>">
<input type="hidden" name="tnf_hidden" value="Y">
<h3>Settings</h3>
<table class="form-table">
<tr>
<th><label for="tnf_hashtags">Hashtag(s):</label></th>
<td><input type="text" name="tnf_hashtags" id="tnf_hashtags" value="<?php echo $hashtags; ?>" size="40"></input> <em>ex: news, events</em></input>
</tr>
<tr>
<th><label for="tnf_usernames">Twitter Username(s):</label></th>
<td><input type="text" name="tnf_usernames" id="tnf_usernames" value="<?php echo $usernames; ?>" size="40"> <em>ex: keirwhitaker, mikekus, gelimehouse</em></td>
</tr>
<tr>
<th><label for="tnf_add_news_as_post" name="tnf_add_news_as_post">Add Tweets as Posts:</label></th>
<td><input type="checkbox" name="tnf_add_news_as_post" id="tnf_add_news_as_post" value="Y" id="tnf_add_news_as_post" <?php echo $add_news_to_db ?>></input>
</tr>
<tr>
<th><label for="tnf_post_type">Post type:</label></th>
<td><input type="text" name="tnf_post_type" id="tnf_post_type" value="<?php echo $post_type; ?>" size="40"> <em>ex: post, page</em></td>
</tr>
<tr>
<th><label for="tnf_category" name="tnf_category">Post Category:</label></td>
<td><?php
$dropdown_options = array("show_option_all" => __("View all categories"), "hide_empty" => 0, "hierarchical" => 1, "show_count" => 1, "orderby" => "name", "name" => "tnf_category", "selected" => $category);
wp_dropdown_categories($dropdown_options);
?>
</td>
<tr>
<th><label for="tnf_user" name="tnf_user">Default User:</label></td>
<td><?php
$dropdown_options = array("name" => "tnf_user", "selected" => $user);
wp_dropdown_users($dropdown_options);
?>
</td>
</tr>
</tr>
</table>
<p class="submit"><input type="submit" name="Submit" value="Update Settings" /></p>
</form>
<?php if(get_option("tnf_add_news_to_db")): ?>
<form name="tnf_get_news_form" method="post" action="<?php echo str_replace( "%7E", "~", $_SERVER["REQUEST_URI"]); ?>">
<input type="hidden" name="tnf_get_news_hidden" value="Y">
<h3>Update History</h3>
<ul>
<?php foreach ($data as $item) : ?>
<li><?php echo $item->comment; ?></li>
<?php endforeach; ?>
</ul>
<p><em>...The next update is scheduled for <?php echo date("l jS \of F Y - H:i:s", wp_next_scheduled("tnf_hourly_update")); ?></em></p>
<p class="submit"><input type="submit" name="tnf_get_news" value="Run Twitter News Feed Update" /></p>
<?php endif ?>
</form>
</div>