Quotes Collection - Version 1.0

Version Description

Download this release

Release Info

Developer SriniG
Plugin Icon 128x128 Quotes Collection
Version 1.0
Comparing to
See all releases

Version 1.0

quotes-collection-ajax.php ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ if(isset($_REQUEST['refresh'])) {
4
+ $blogdir = preg_replace('|/wp-content.*$|','', __FILE__);
5
+ include_once($blogdir.'/wp-config.php');
6
+ include_once($blogdir.'/wp-includes/wp-db.php');
7
+ include_once(str_replace("-ajax", "", __FILE__));
8
+ if($random_quote = quotescollection_get_randomquote($_REQUEST['exclude'])) {
9
+ $options = get_option('quotescollection');
10
+ $show_author = isset($options['show_author'])?$options['show_author']:0;
11
+ $show_source = isset($options['show_source'])?$options['show_source']:1;
12
+ $display = quotescollection_display_randomquote($show_author, $show_source, 2, $random_quote);
13
+ die( "document.getElementById('quotescollection_randomquote-".$_REQUEST['refresh']."').innerHTML = '".$display."'" );
14
+ }
15
+ else
16
+ die( "alert('$error')" );
17
+ }
18
+
19
+ if(isset($_REQUEST['js'])) {
20
+ ?>
21
+ function quotescollection_refresh(instance, exclude)
22
+ {
23
+ // function body defined below
24
+ var mysack = new sack(
25
+ "<?php echo $_SERVER['PHP_SELF']; ?>?refresh="+instance+"&exclude="+exclude );
26
+ mysack.execute = 1;
27
+
28
+ mysack.onError = function() { document.getElementById('quotescollection_randomquote-'+instance).innerHTML = 'Error getting quote'; };
29
+ mysack.onLoading = function() { document.getElementById('quotescollection_nextquote-'+instance).innerHTML = 'Loading...'; };
30
+ mysack.onLoaded = function() { document.getElementById('quotescollection_nextquote-'+instance).innerHTML = '<a style="cursor:pointer" onclick="quotescollection_refresh('+instance+');">Next quote »</a>'; };
31
+ // mysack.onInteractive = function() { document.getElementById('quotescollection_nextquote-'+instance).innerHTML += '...'; };
32
+ // mysack.onCompletion = function() { document.getElementById('quotescollection_randomquote-'+instance).innerHTML = mysack.response; };
33
+ mysack.runAJAX();
34
+ return true;
35
+ } // end of JavaScript function for randomquote
36
+ <?php
37
+ }
38
+ ?>
quotes-collection.css ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* Random quote */
2
+
3
+ .quotescollection_randomquote q {
4
+
5
+ }
6
+
7
+ .quotescollection_randomquote cite {
8
+
9
+ }
10
+
11
+
12
+ /* Quotes page */
13
+ blockquote.quotescollection {
14
+ border:0;
15
+ background:none;
16
+ padding:0;
17
+ margin:2em;
18
+ font-size:1em;
19
+ }
20
+
21
+ blockquote.quotescollection q {
22
+ color:#555;
23
+ }
24
+
25
+ blockquote.quotescollection cite {
26
+ display:inline;
27
+ font-size:0.83em;
28
+ color:#888;
29
+ }
quotes-collection.php ADDED
@@ -0,0 +1,614 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Plugin Name: Quotes Collection
4
+ Plugin URI: http://srinig.com/wordpress/plugins/quotes-collection/
5
+ Description: Quotes Collection plugin with Ajax powered Random Quote sidebar widget helps you collect and display your favourite quotes on your WordPress blog.
6
+ Author: Srini G
7
+ Version: 1.0
8
+ Author URI: http://srinig.com/wordpress/
9
+ */
10
+ /* Released under GPL:
11
+ http://www.opensource.org/licenses/gpl-license.php
12
+ */
13
+
14
+
15
+ function quotescollection_get_randomquote($exclude = 0)
16
+ {
17
+ global $wpdb;
18
+ if($exclude)
19
+ $exclude_condition = 'AND quote_id <> '.$exclude;
20
+ $sql = "SELECT quote_id, quote, author, source
21
+ FROM " . $wpdb->prefix . "quotescollection
22
+ WHERE visible = 'yes'
23
+ ".$exclude_condition."
24
+ ORDER BY RAND()
25
+ LIMIT 1";
26
+ $random_quote = $wpdb->get_row($sql, ARRAY_A);
27
+ if ( !empty($random_quote) ) {
28
+ return $random_quote;
29
+ }
30
+ else
31
+ return 0;
32
+ }
33
+
34
+ function quotescollection_count($condition = "")
35
+ {
36
+ global $wpdb;
37
+ $sql = "SELECT COUNT(*) FROM " . $wpdb->prefix . "quotescollection ".$condition;
38
+ $count = $wpdb->get_var($sql);
39
+ return $count;
40
+ }
41
+
42
+ function quotescollection_js_head() // this is a PHP function
43
+ {
44
+ // use JavaScript SACK library for AJAX
45
+ wp_print_scripts( array( 'sack' ));
46
+
47
+ // Define custom JavaScript function
48
+ ?>
49
+ <!-- Random Quote script -->
50
+ <script type="text/javascript" src="<?php bloginfo( 'wpurl' ); ?>/wp-content/plugins/quotes-collection/quotes-collection-ajax.php?js"></script>
51
+ <?php
52
+ } // end of PHP function myplugin_js_header
53
+
54
+ add_action('wp_head', 'quotescollection_js_head' );
55
+
56
+
57
+
58
+
59
+ function quotescollection_display_randomquote($show_author = 1, $show_source = 0, $ajax_refresh = 1, $random_quote = array())
60
+ {
61
+ global $quotescollection_instances;
62
+ if(!($instance = $quotescollection_instances))
63
+ $instance = $quotescollection_instances = 0;
64
+ $random_quote = $random_quote?$random_quote:quotescollection_get_randomquote($_REQUEST['exclude']);
65
+ if(!$random_quote) {
66
+ return;
67
+ }
68
+ $display = "<p><q>". wptexturize(str_replace(array("\r\n", "\r", "\n"), '', nl2br($random_quote['quote']))) ."</q>";
69
+ if( ($show_author && $random_quote['author']) || ($show_source && $random_quote['source']) )
70
+ $display .= " &mdash;&nbsp;";
71
+ if($show_author && $random_quote['author'])
72
+ $display .= "<cite>".$random_quote['author']."</cite> ";
73
+ if($show_source && $random_quote['source'])
74
+ $display .= "from <cite>".$random_quote['source']."</cite>";
75
+ $display .= "</p>";
76
+
77
+ // We don't want to display the 'next quote' link if there is no more than 1 quote
78
+ $quotes_count = quotescollection_count("WHERE visible='yes'");
79
+
80
+ if($ajax_refresh == 1 && $quotes_count > 1) {
81
+ $display .= "<script type=\"text/javascript\">\n<!--\ndocument.write(\"";
82
+ $display .= '<p id=\"quotescollection_nextquote-'.$instance.'\"><a style=\"cursor:pointer\" onclick=\"quotescollection_refresh('.$instance.', '.$random_quote["quote_id"].');\">Next quote &raquo;</a></p>';
83
+ $display .= "\")\n//-->\n</script>\n";
84
+ }
85
+ if ($ajax_refresh == 2 && $quotes_count > 1) {
86
+ $display .= "<p id=\"quotescollection_nextquote-".$_REQUEST['refresh']."\"><a style=\"cursor:pointer\" onclick=\"quotescollection_refresh(".$_REQUEST['refresh'].", ".$random_quote['quote_id'].");\">Next quote &raquo;</a></p>";
87
+ return $display;
88
+ }
89
+ $display = "<div id=\"quotescollection_randomquote-".$instance."\" class=\"quotescollection_randomquote\">{$display}</div>";
90
+ echo $display;
91
+ $quotescollection_instances++;
92
+ return;
93
+ }
94
+
95
+ function quotescollection_init()
96
+ {
97
+ if ( !function_exists('register_sidebar_widget') || !function_exists('register_widget_control') )
98
+ return;
99
+
100
+ function quotescollection_widget($args) {
101
+ if($random_quote = quotescollection_get_randomquote()) {
102
+ $options = get_option('quotescollection');
103
+ $title = isset($options['title'])?$options['title']:__('Random Quote');
104
+ $show_author = isset($options['show_author'])?$options['show_author']:1;
105
+ $show_source = isset($options['show_source'])?$options['show_source']:1;
106
+ $ajax_refresh = isset($options['ajax_refresh'])?$options['ajax_refresh']:1;
107
+ extract($args);
108
+ echo $before_widget;
109
+ if($title) echo $before_title . $title . $after_title . "\n";
110
+ quotescollection_display_randomquote($show_author, $show_source, $ajax_refresh, $random_quote);
111
+ echo $after_widget;
112
+ }
113
+ }
114
+
115
+ function quotescollection_widget_control()
116
+ {
117
+
118
+ // default values for options
119
+ $options = array(
120
+ 'title' => 'Random Quote',
121
+ 'show_author' => 1,
122
+ 'show_source' => 0,
123
+ 'ajax_refresh' => 1,
124
+ );
125
+
126
+ if($options_saved = get_option('quotescollection'))
127
+ $options = array_merge($options, $options_saved);
128
+
129
+ // Update options in db when user updates options in the widget page
130
+ if($_REQUEST['quotescollection-submit']) {
131
+ $options['title']
132
+ = strip_tags(stripslashes($_REQUEST['quotescollection-title']));
133
+ $options['show_author'] = $_REQUEST['quotescollection-show_author']?1:0;
134
+ $options['show_source'] = $_REQUEST['quotescollection-show_source']?1:0;
135
+ $options['ajax_refresh'] = $_REQUEST['quotescollection-ajax_refresh']?1:0;
136
+ update_option('quotescollection', $options);
137
+ }
138
+
139
+ // Now we define the display of widget options menu
140
+ $title = htmlspecialchars($options['title'], ENT_QUOTES);
141
+ if($options['show_author'])
142
+ $show_author_checked = ' checked="checked"';
143
+ if($options['show_source'])
144
+ $show_source_checked = ' checked="checked"';
145
+ if($options['ajax_refresh'])
146
+ $ajax_refresh_checked = ' checked="checked"';
147
+ echo "<p style=\"text-align:left;\"><label for=\"quotescollection-title\">Title: </label><input class=\"widefat\" type=\"text\" id=\"quotescollection-title\" name=\"quotescollection-title\" value=\"".htmlspecialchars($options['title'], ENT_QUOTES)."\" /></p>";
148
+ echo "<p style=\"text-align:left;\"><input type=\"checkbox\" id=\"quotescollection-show_author\" name=\"quotescollection-show_author\" value=\"1\"{$show_author_checked} /> <label for=\"quotescollection-show_author\">Show author?</label></p>";
149
+ echo "<p style=\"text-align:left;\"><input type=\"checkbox\" id=\"quotescollection-show_source\" name=\"quotescollection-show_source\" value=\"1\"{$show_source_checked} /> <label for=\"quotescollection-show_source\">Show source?</label></p>";
150
+ echo "<p style=\"text-align:left;\"><input type=\"checkbox\" id=\"quotescollection-ajax_refresh\" name=\"quotescollection-ajax_refresh\" value=\"1\"{$ajax_refresh_checked} /> <label for=\"quotescollection-ajax_refresh\">Ajax refresh feature</label></p>";
151
+ echo "<input type=\"hidden\" id=\"quotescollection-submit\" name=\"quotescollection-submit\" value=\"1\" />";
152
+ echo "<p style=\"text-align:left;\">Manage your collection of quotes at<br /><a href=\"edit.php?page=quotes-collection/quotes-collection.php\">Manage->Quotes Collection</a></p>";
153
+ }
154
+
155
+
156
+ register_sidebar_widget(array('Random Quote', 'widgets'), 'quotescollection_widget');
157
+ register_widget_control('Random Quote', 'quotescollection_widget_control', 250, 230);
158
+ }
159
+
160
+
161
+ function quotescollection_admin_menu()
162
+ {
163
+ add_management_page('Quotes Collection', 'Quotes Collection', 8, __FILE__, 'quotescollection_quotes_management');
164
+ }
165
+
166
+ function quotescollection_addquote($quote, $author = "", $source = "", $visible = 'yes')
167
+ {
168
+ if(!$quote) return "Nothing added to the database.";
169
+ global $wpdb;
170
+ $table_name = $wpdb->prefix . "quotescollection";
171
+ if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name)
172
+ return "Database not found";
173
+ else //Add the quote data to the database
174
+ {
175
+
176
+ if ( ini_get('magic_quotes_gpc') ) {
177
+ $quote = stripslashes($quote);
178
+ $author = stripslashes($author);
179
+ $source = stripslashes($source);
180
+ }
181
+ $quote = "'".$wpdb->escape($quote)."'";
182
+ $author = $author?"'".$wpdb->escape($author)."'":"NULL";
183
+ $source = $source?"'".$wpdb->escape($source)."'":"NULL";
184
+ if(!$visible) $visible = "'no'";
185
+ else $visible = "'yes'";
186
+ $insert = "INSERT INTO " . $table_name .
187
+ "(quote, author, source, visible, time_added)" .
188
+ "VALUES ({$quote}, {$author}, {$source}, {$visible}, NOW())";
189
+ $results = $wpdb->query( $insert );
190
+ if(FALSE === $results)
191
+ return "There was an error in the MySQL query";
192
+ else
193
+ return "Quote added";
194
+ }
195
+ }
196
+
197
+ function quotescollection_editquote($quote_id, $quote, $author = "", $source = "", $visible = 'yes')
198
+ {
199
+ if(!$quote) return "Quote not updated.";
200
+ if(!$quote_id) return srgq_addquote($quote, $author, $source, $visible);
201
+ global $wpdb;
202
+ $table_name = $wpdb->prefix . "quotescollection";
203
+ if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name)
204
+ return "Database not found";
205
+ else //Update database
206
+ {
207
+
208
+ if ( ini_get('magic_quotes_gpc') ) {
209
+ $quote = stripslashes($quote);
210
+ $author = stripslashes($author);
211
+ $source = stripslashes($source);
212
+ }
213
+ $quote = "'".$wpdb->escape($quote)."'";
214
+ $author = $author?"'".$wpdb->escape($author)."'":"NULL";
215
+ $source = $source?"'".$wpdb->escape($source)."'":"NULL";
216
+ if(!$visible) $visible = "'no'";
217
+ else $visible = "'yes'";
218
+ $update = "UPDATE " . $table_name . "
219
+ SET quote = {$quote},
220
+ author = {$author},
221
+ source = {$source},
222
+ visible = {$visible},
223
+ time_updated = NOW()
224
+ WHERE quote_id = $quote_id";
225
+ $results = $wpdb->query( $update );
226
+ if(FALSE === $results)
227
+ return "There was an error in the MySQL query";
228
+ else
229
+ return "Changes saved";
230
+ }
231
+ }
232
+
233
+
234
+ function quotescollection_deletequote($quote_id)
235
+ {
236
+ if($quote_id) {
237
+ global $wpdb;
238
+ $sql = "DELETE from " . $wpdb->prefix ."quotescollection" .
239
+ " WHERE quote_id = " . $quote_id;
240
+ if(FALSE === $wpdb->query($sql))
241
+ return "There was an error in the MySQL query";
242
+ else
243
+ return "Quote deleted";
244
+ }
245
+ else return "The quote cannot be deleted";
246
+ }
247
+
248
+ function quotescollection_getquotedata($quote_id)
249
+ {
250
+ global $wpdb;
251
+ $sql = "SELECT quote_id, quote, author, source, visible
252
+ FROM " . $wpdb->prefix . "quotescollection
253
+ WHERE quote_id = {$quote_id}";
254
+ $quote_data = $wpdb->get_row($sql, ARRAY_A);
255
+ return $quote_data;
256
+ }
257
+
258
+ function quotescollection_editform($quote_id = 0)
259
+ {
260
+ $visible_selected = " checked=\"checked\"";
261
+ $submit_value = "Add Quote";
262
+ $form_name = "addquote";
263
+
264
+ if($quote_id) {
265
+ $form_name = "editquote";
266
+ $quote_data = quotescollection_getquotedata($quote_id);
267
+ foreach($quote_data as $key => $value)
268
+ $quote_data[$key] = $quote_data[$key];
269
+ extract($quote_data);
270
+ $quote = htmlentities($quote);
271
+ $author = htmlentities($author);
272
+ $source = htmlentities($source);
273
+ $hidden_input = "<input type=\"hidden\" name=\"quote_id\" value=\"{$quote_id}\" />";
274
+ if($visible == 'no') $visible_selected = "";
275
+ $submit_value = "Save changes";
276
+ $back = "<input type=\"submit\" name=\"submit\" value=\"Back\" />&nbsp;";
277
+ }
278
+
279
+
280
+ $display .=<<< EDITFORM
281
+ <form name="{$form_name}" method="post" action="{$_SERVER['PHP_SELF']}?page=quotes-collection/quotes-collection.php">
282
+ {$hidden_input}
283
+ <table class="form-table" cellpadding="5" cellspacing="2" width="100%">
284
+ <tbody><tr class="form-field form-required">
285
+ <th style="text-align:left;" scope="row" valign="top"><label for="quotescollection_quote">The quote:</label></th>
286
+ <td><textarea id="quotescollection_quote" name="quote" rows="5" cols="50" style="width: 97%;">{$quote}</textarea></td>
287
+ </tr>
288
+ <tr class="form-field">
289
+ <th style="text-align:left;" scope="row" valign="top"><label for="quotescollection_author">Author: <small>(optional)</small></label></th>
290
+ <td><input type="text" id="quotescollection_author" name="author" size="40" value="{$author}" /></td>
291
+ </tr>
292
+ <tr class="form-field">
293
+ <th style="text-align:left;" scope="row" valign="top"><label for="quotescollection_source">Source: <small>(optional)</small></label></th>
294
+ <td><input type="text" id="quotescollection_source" name="source" size="40" value="{$source}" /></td>
295
+ </tr>
296
+ <tr>
297
+ <th style="text-align:left;" scope="row" valign="top"><label for="quotescollection_visible">Visible?</label></th>
298
+ <td><input type="checkbox" id="quotescollection_visible" name="visible"{$visible_selected} />
299
+ </tr></tbody>
300
+ </table>
301
+ <p class="submit">{$back}<input name="submit" value="{$submit_value}" type="submit" class="button" /></p>
302
+ </form>
303
+ EDITFORM;
304
+ return $display;
305
+ }
306
+
307
+ function quotescollection_changevisibility($quote_ids, $visibility = 'yes')
308
+ {
309
+ if(!$quote_ids)
310
+ return "Nothing done!";
311
+ global $wpdb;
312
+ $sql = "UPDATE ".$wpdb->prefix."quotescollection
313
+ SET visible = '".$visibility."',
314
+ time_updated = NOW()
315
+ WHERE quote_id IN (".implode(', ', $quote_ids).")";
316
+ $wpdb->query($sql);
317
+ return "Visibility status of selected quotes set to '{$visibility}'.";
318
+ }
319
+
320
+ function quotescollection_bulkdelete($quote_ids)
321
+ {
322
+ if(!$quote_ids)
323
+ return "Nothing done!";
324
+ global $wpdb;
325
+ $sql = "DELETE FROM ".$wpdb->prefix."quotescollection
326
+ WHERE quote_id IN (".implode(', ', $quote_ids).")";
327
+ $wpdb->query($sql);
328
+ return "Quote(s) deleted";
329
+ }
330
+
331
+
332
+
333
+ function quotescollection_quotes_management()
334
+ {
335
+ if($_REQUEST['submit'] == 'Add Quote') {
336
+ extract($_REQUEST);
337
+ $msg = quotescollection_addquote($quote, $author, $source, $visible);
338
+ }
339
+ else if($_REQUEST['submit'] == 'Save changes') {
340
+ extract($_REQUEST);
341
+ $msg = quotescollection_editquote($quote_id, $quote, $author, $source, $visible);
342
+ }
343
+ else if($_REQUEST['action'] == 'editquote') {
344
+ $display .= "<div class=\"wrap\">\n<h2>Edit quote</h2>";
345
+ $display .= quotescollection_editform($_REQUEST['id']);
346
+ $display .= "</div>";
347
+ echo $display;
348
+ return;
349
+ }
350
+ else if($_REQUEST['action'] == 'delquote') {
351
+ $msg = quotescollection_deletequote($_REQUEST['id']);
352
+ }
353
+ else if(isset($_REQUEST['bulkaction'])) {
354
+ if($_REQUEST['bulkaction'] == "Delete")
355
+ $msg = quotescollection_bulkdelete($_REQUEST['bulkcheck']);
356
+ if($_REQUEST['bulkaction'] == "Make visible") {
357
+ $msg = quotescollection_changevisibility($_REQUEST['bulkcheck'], 'yes');
358
+ }
359
+ if($_REQUEST['bulkaction'] == "Make invisible") {
360
+ $msg = quotescollection_changevisibility($_REQUEST['bulkcheck'], 'no');
361
+ }
362
+ }
363
+ $display .= "<div class=\"wrap\">";
364
+
365
+ if($msg)
366
+ $display .= "<div id=\"message\" class=\"updated fade\"><p>{$msg}</p></div>";
367
+
368
+ $display .= "<h2>Quotes Collection</h2>";
369
+
370
+ // anchor to add new quote
371
+ $display .= "<p><a href=\"#addnew\"><strong>Add new quote</strong></a></p>";
372
+
373
+ // Get all the quotes from the database
374
+ global $wpdb;
375
+
376
+ $sql = "SELECT quote_id, quote, author, source, visible
377
+ FROM " . $wpdb->prefix . "quotescollection";
378
+
379
+ if(isset($_REQUEST['orderby'])) {
380
+ $sql .= " ORDER BY " . $_REQUEST['criteria'] . " " . $_REQUEST['order'];
381
+ $option_selected[$_REQUEST['criteria']] = " selected=\"selected\"";
382
+ $option_selected[$_REQUEST['order']] = " selected=\"selected\"";
383
+ }
384
+ else {
385
+ $sql .= " ORDER BY quote_id ASC";
386
+ $option_selected['quote_id'] = " selected=\"selected\"";
387
+ $option_selected['ASC'] = " selected=\"selected\"";
388
+ }
389
+
390
+ $quotes = $wpdb->get_results($sql);
391
+
392
+ foreach($quotes as $quote_data) {
393
+ if($alternate) $alternate = "";
394
+ else $alternate = " class=\"alternate\"";
395
+ $quotes_list .= "<tr{$alternate}>";
396
+ $quotes_list .= "<td class=\"check-column\"><input type=\"checkbox\" name=\"bulkcheck[]\" value=\"".$quote_data->quote_id."\" /></td>";
397
+ $quotes_list .= "<td>" . $quote_data->quote_id . "</td>";
398
+ $quotes_list .= "<td>" . wptexturize(nl2br($quote_data->quote)) ."</td>";
399
+ $quotes_list .= "<td>" . $quote_data->author;
400
+ if($quote_data->author && $quote_data->source)
401
+ $quotes_list .= " / ";
402
+ $quotes_list .= $quote_data->source ."</td>";
403
+ $quotes_list .= "<td>" . $quote_data->visible ."</td>";
404
+ $quotes_list .= "<td><a href=\"" . $_SERVER['PHP_SELF'] . "?page=quotes-collection/quotes-collection.php&action=editquote&amp;id=".$quote_data->quote_id."\" class=\"edit\">Edit</a></td>
405
+ <td><a href=\"" . $_SERVER['PHP_SELF'] . "?page=quotes-collection/quotes-collection.php&action=delquote&amp;id=".$quote_data->quote_id."\" onclick=\"return confirm( 'Are you sure you want to delete this quote?');\" class=\"delete\">Delete</a> </td>";
406
+ $quotes_list .= "</tr>";
407
+ }
408
+
409
+ if($quotes_list) {
410
+ $display .= "<form id=\"quotescollection\" method=\"post\" action=\"{$_SERVER['PHP_SELF']}?page=quotes-collection/quotes-collection.php\">";
411
+ $display .= "<div class=\"tablenav\">";
412
+ $display .= "<input type=\"submit\" name=\"bulkaction\" value=\"Delete\" class=\"button-secondary\" />";
413
+ $display .= "<input type=\"submit\" name=\"bulkaction\" value=\"Make visible\" class=\"button-secondary\" />";
414
+ $display .= "<input type=\"submit\" name=\"bulkaction\" value=\"Make invisible\" class=\"button-secondary\" />";
415
+ $display .= "&nbsp;&nbsp;&nbsp;";
416
+ $display .= "Sort by: ";
417
+ $display .= "<select name=\"criteria\">";
418
+ $display .= "<option value=\"quote_id\"{$option_selected['quote_id']}>Quote ID</option>";
419
+ $display .= "<option value=\"quote\"{$option_selected['quote']}>Quote</option>";
420
+ $display .= "<option value=\"author\"{$option_selected['author']}>Author</option>";
421
+ $display .= "<option value=\"source\"{$option_selected['source']}>Source</option>";
422
+ $display .= "<option value=\"time_added\"{$option_selected['time_added']}>Date added</option>";
423
+ $display .= "<option value=\"time_updated\"{$option_selected['time_updated']}>Date updated</option>";
424
+ $display .= "<option value=\"visible\"{$option_selected['visible']}>Visibility</option>";
425
+ $display .= "</select>";
426
+ $display .= "<select name=\"order\"><option{$option_selected['ASC']}>ASC</option><option{$option_selected['DESC']}>DESC</option></select>";
427
+ $display .= "<input type=\"submit\" name=\"orderby\" value=\"Go\" class=\"button-secondary\" />";
428
+ $display .= "</div>";
429
+ $display .= "<br style=\"clear:both;\" />";
430
+
431
+ $display .= "<table class=\"widefat\">";
432
+ $display .= "<thead><tr><th class=\"check-column\"><input type=\"checkbox\" onclick=\"quotescollection_checkAll(document.getElementById('quotescollection'));\" /></th><th>ID</th><th>The quote</th><th>Author / Source</th><th>Visible?</th><th colspan=\"2\" style=\"text-align:center\">Action</th></tr></thead>";
433
+ $display .= "<tbody id=\"the-list\">{$quotes_list}</tbody>";
434
+ $display .= "</table>";
435
+
436
+ $display .= "<div class=\"tablenav\">";
437
+ $display .= "<input type=\"submit\" name=\"bulkaction\" value=\"Delete\" class=\"button-secondary\" />";
438
+ $display .= "<input type=\"submit\" name=\"bulkaction\" value=\"Make visible\" class=\"button-secondary\" />";
439
+ $display .= "<input type=\"submit\" name=\"bulkaction\" value=\"Make invisible\" class=\"button-secondary\" />";
440
+ $display .= "</div>";
441
+ $display .= "</form>";
442
+ $display .= "<br style=\"clear:both;\" />";
443
+
444
+ }
445
+ else
446
+ $display .= "<p>No quotes in the database</p>";
447
+
448
+ $display .= "</div>";
449
+
450
+ $display .= "<div id=\"addnew\" class=\"wrap\">\n<h2>Add new quote</h2>";
451
+ $display .= quotescollection_editform();
452
+ $display .= "</div>";
453
+
454
+
455
+ echo $display;
456
+
457
+ }
458
+
459
+ function quotescollection_admin_head()
460
+ {
461
+ ?>
462
+ <script type="text/javascript">
463
+ function quotescollection_checkAll(form) {
464
+ for (i = 0, n = form.elements.length; i < n; i++) {
465
+ if(form.elements[i].type == "checkbox" && !(form.elements[i].hasAttribute('onclick'))) {
466
+ if(form.elements[i].checked == true)
467
+ form.elements[i].checked = false;
468
+ else
469
+ form.elements[i].checked = true;
470
+ }
471
+ }
472
+ }
473
+ </script>
474
+ <?php
475
+ }
476
+
477
+ add_action('admin_head', 'quotescollection_admin_head');
478
+
479
+ function quotescollection_install()
480
+ {
481
+ global $wpdb;
482
+ $table_name = $wpdb->prefix . "quotescollection";
483
+ if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name)
484
+ {
485
+ //Creating the table
486
+ $sql = "CREATE TABLE " . $table_name . " (
487
+ quote_id mediumint(9) NOT NULL AUTO_INCREMENT,
488
+ quote text NOT NULL,
489
+ author varchar(255),
490
+ source varchar(255),
491
+ visible enum('yes', 'no') DEFAULT 'yes' NOT NULL,
492
+ time_added datetime NOT NULL,
493
+ time_updated datetime,
494
+ PRIMARY KEY (quote_id)
495
+ );";
496
+ $results = $wpdb->query( $sql );
497
+ }
498
+ $query = "ALTER TABLE `{$table_name}` charset=utf8";
499
+ $wpdb->query($query);
500
+ $query = "ALTER TABLE `{$table_name}` MODIFY `quote` TEXT CHARACTER SET utf8, MODIFY `author` TEXT CHARACTER SET utf8, MODIFY `source` TEXT CHARACTER SET utf8";
501
+ $wpdb->query($query);
502
+
503
+
504
+ }
505
+
506
+
507
+ function quotescollection_displayquote($quote_id = 0)
508
+ {
509
+ global $wpdb;
510
+ $sql = "SELECT quote_id, quote, author, source
511
+ FROM " . $wpdb->prefix . "quotescollection
512
+ WHERE visible = 'yes' ";
513
+ if(!$quote_id) {
514
+ $sql .= "ORDER BY RAND()
515
+ LIMIT 1";
516
+ }
517
+ else {
518
+ $sql .= "AND quote_id = {$quote_id}";
519
+ }
520
+ $quote_data = $wpdb->get_row($sql, ARRAY_A);
521
+ if ( !empty($quote_data) ) {
522
+ $display = "<blockquote class=\"quotescollection\"><q>".wptexturize(nl2br($quote_data['quote']))."</q>";
523
+ if($quote_data['author'] || $quote_data['source'])
524
+ $display .= " &mdash;&nbsp;";
525
+ if($quote_data['author'])
526
+ $display .= "<cite>{$quote_data['author']}</cite> ";
527
+ if($quote_data['source']) {
528
+ $display .="<cite>from {$quote_data['source']}</cite>";
529
+ }
530
+ $display .= "</blockquote>";
531
+ return $display;
532
+ }
533
+ else
534
+ return "";
535
+ }
536
+
537
+ function quotescollection_displayquotes($source = "")
538
+ {
539
+ global $wpdb;
540
+ $source = html_entity_decode($source);
541
+ $sql = "SELECT quote_id, quote, author, source
542
+ FROM " . $wpdb->prefix . "quotescollection
543
+ WHERE visible = 'yes' ";
544
+ if(!$source) {
545
+ $sql .= "ORDER BY quote";
546
+ }
547
+ else if($source == "Anonymous") {
548
+ $sql .= "AND (author = '' OR author ='Anonymous')";
549
+ }
550
+ else {
551
+ $sql .= "AND (source = '{$source}' OR author = '{$source}')";
552
+ }
553
+ $quotes = $wpdb->get_results($sql, ARRAY_A);
554
+ if ( !empty($quotes) ) {
555
+ foreach($quotes as $quote_data) {
556
+ $display .= "<blockquote class=\"quotescollection\"><q>".wptexturize(nl2br($quote_data['quote']))."</q>";
557
+ if($quote_data['author'] || $quote_data['source'])
558
+ $display .= " &mdash;&nbsp;";
559
+ if($quote_data['author'])
560
+ $display .= "<cite>{$quote_data['author']}</cite> ";
561
+ if($quote_data['source']) {
562
+ $display .="<cite>from {$quote_data['source']}</cite>";
563
+ }
564
+ $display .= "</blockquote>";
565
+ }
566
+ return $display;
567
+ }
568
+ else
569
+ return "";
570
+ }
571
+
572
+
573
+
574
+ function quotescollection_inpost( $text ) {
575
+ $start = strpos($text,"[quote|id=");
576
+ if ($start !== FALSE) {
577
+ $text = preg_replace( "/\[quote\|id=(\d+)\]/ie", "quotescollection_displayquote('\\1')", $text );
578
+ }
579
+ $start = strpos($text,"[quote|random]");
580
+ if ($start !== FALSE) {
581
+ $text = preg_replace( "/\[quote\|random\]/ie", "quotescollection_displayquote()", $text );
582
+ }
583
+ $start = strpos($text,"[quote|all]");
584
+ if ($start !== FALSE) {
585
+ $text = preg_replace( "/\[quote\|all\]/ie", "quotescollection_displayquotes()", $text );
586
+ }
587
+ $start = strpos($text,"[quote|author=");
588
+ if($start !== FALSE) {
589
+ $text = preg_replace("/\[quote\|author=(.{1,})?\]/ie", "quotescollection_displayquotes('\\1')", $text);
590
+ }
591
+ $start = strpos($text,"[quote|source=");
592
+ if($start !== FALSE) {
593
+ $text = preg_replace("/\[quote\|source=(.{1,})?\]/ie", "quotescollection_displayquotes('\\1')", $text);
594
+ }
595
+ return $text;
596
+ }
597
+
598
+ function quotescollection_css_head()
599
+ {
600
+ ?>
601
+ <link rel="stylesheet" type="text/css" href="<?php bloginfo( 'wpurl' ); ?>/wp-content/plugins/quotes-collection/quotes-collection.css"/>
602
+ <?php
603
+ }
604
+
605
+ add_action('wp_head', 'quotescollection_css_head' );
606
+
607
+
608
+ add_filter('the_content', 'quotescollection_inpost', 7);
609
+ add_filter('the_excerpt', 'quotescollection_inpost', 7);
610
+
611
+ add_action('activate_quotes-collection/quotes-collection.php', 'quotescollection_install');
612
+ add_action('admin_menu', 'quotescollection_admin_menu');
613
+ add_action('plugins_loaded', 'quotescollection_init');
614
+ ?>
readme.txt ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === Quotes Collection ===
2
+ Contributors: SriniG
3
+ Donate link: http://srinig.com/wordpress/plugins/quotes-collection/#donate
4
+ Tags: quotes collection, quotes, quotations, random quote, sidebar, widget, ajax
5
+ Requires at least: 2.1
6
+ Tested up to: 2.5
7
+ Stable tag: trunk
8
+
9
+ Quotes Collection plugin with Ajax powered Random Quote sidebar widget helps you collect and display your favourite quotes on your WordPress blog.
10
+
11
+ == Description ==
12
+
13
+ Quotes Collection plugin with Ajax powered Random Quote sidebar widget helps you collect, manage and display your favourite quotations on your WordPress blog. All quotes or a set of quotes can also be displayed on a page using a `[quote]` tag.
14
+
15
+ Main features and notes:
16
+
17
+ * Random Quote sidebar widget with Ajax refresh feature -- you will be able to get another random quote on the same space without refreshing the web page. This refresh feature can be optionally turned off. The widget also comes with few other options in the widget control panel.
18
+ * A nice admin interface to add, edit and manage quotes.
19
+ * Additional information that can be provided along with the quote: quote author, source (e.g., a book, or a website URL) and visibility.
20
+ * Quotes can be displayed in a page using one of the tags below.
21
+ * The tag `[quote|all]` displays all quotes.
22
+ * `[quote|author=Somebody]` displays quotes authored by Somebody.
23
+ * `[quote|source=Something]` displays quotes with source as ‘Something’
24
+ * `[quote|id=3]` displays quote with ID 3
25
+ * `[quote|random]` displays a random quote
26
+ * The code `<?php quotescollection_display_randomquote() ?>` can be used to display a random quote in places other than sidebar.
27
+
28
+ == Installation ==
29
+
30
+ 1. Unzip and upload the `quotes-collection` directory to the `/wp-content/plugins/` directory
31
+ 1. Go to `WP Admin » Plugins` and activate the ‘Quotes Collection’ plugin
32
+ 1. To add and manage the quotes go to `WP Admin » Manage » Quotes Collection`
33
+ 1. To display a random quote in the sidebar, go to `WP Admin » Presentation » Widgets`, drag ‘Random Quote’ widget into the sidebar
34
+
35
+ == Screenshots ==
36
+
37
+ 1. Admin interface (with WP 2.5)
38
+ 2. ‘Random Quote’ widget options
39
+ 3. Random quote as can be seen in the sidebar of [srinig.com](http://srinig.com/)
40
+
screenshot-1.png ADDED
Binary file
screenshot-2.png ADDED
Binary file
screenshot-3.png ADDED
Binary file