forked from palasthotel/chiron
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wordpress_plugin.php
executable file
·703 lines (604 loc) · 22.3 KB
/
wordpress_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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
<?php
/**
* Plugin Name: Chiron
* Description: The Teacher of Heros
* Version: 0.1
* Author: Palasthotel (in Person: Benjamin Birkenhake, Enno Welbers)
* Author URI: http://www.palasthotel.de
*/
// First, like in all Implementations, get the Database Credentials
global $table_prefix;
define(CHIRON_DB_SRV,DB_HOST);
define(CHIRON_DB_USR,DB_USER);
define(CHIRON_DB_PWD,DB_PASSWORD);
define(CHIRON_DB_DBS,DB_NAME);
define(CHIRON_DB_PRE, $table_prefix);
define(CHIRON_IMPLEMENTATION, "Wordpress");
// Then bootstrap Chiron.
// This loads all Classes and creates Instances of the classes chiron_db and chiron_core.
require('core/classes/bootstrap.php');
function t($str){
return $str;
}
function db_query($querystring){
global $chiron_db;
$querystring = str_replace("{", $wpdb->prefix, $querystring);
$querystring = str_replace("}", "", $querystring);
$result = $chiron_db->query($querystring) or die($querystring." failed: ".$chiron_db->error);
return $result;
}
function chiron_wp_activate(){
global $wp_version;
static $secondCall=FALSE;
$chiron_db = new chiron_db(CHIRON_DB_SRV, CHIRON_DB_USR, CHIRON_DB_PWD, CHIRON_DB_DBS, CHIRON_DB_PRE);
$options=get_option("chiron",array());
if(!isset($options['installed'])){
// Run the Installation
// 1. Create the Databases based on the Schema
$chiron_db->execute_schema();
// Tell Wordpress that we have installed
$options['installed'] = TRUE;
update_option("chiron", $options);
}else{
//TODO: implement update support
}
}
register_activation_hook(__FILE__, "chiron_wp_activate");
function chiron_wp_admin_menu()
{
// Main Backend Menu Item
add_menu_page('Reader','Chiron','read','chiron_dashboard','chiron_wp_dashboard', 'dashicons-book-alt', '76');
// Submenu Items
add_submenu_page('chiron_dashboard', 'News-Dashboard', 'News-Dashboard', 'read', 'chiron_dashboard', 'chiron_wp_dashboard' );
add_submenu_page('chiron_dashboard', 'Your Subscriptions', 'Your Subscriptions', 'read', 'chiron_manage_subscriptions', 'chiron_wp_manage_subscriptions' );
add_submenu_page('chiron_dashboard', 'Your Categories', 'Your Categories', 'read', 'chiron_manage_categories', 'chiron_wp_manage_categories' );
add_submenu_page('chiron_dashboard', 'All Sources', 'All Sources', 'read', 'chiron_manage_sources', 'chiron_wp_manage_sources' );
add_submenu_page('chiron_dashboard', 'Settings', 'Settings', 'read', 'chiron_settings', 'chiron_wp_settings' );
add_submenu_page('chiron_dashboard', 'Debugging', 'Debugging', 'read', 'chiron_debugging', 'chiron_wp_debug' );
// Functions which need not be available via Wordpress' Admin Menu
add_submenu_page('null', 'Add new Source', 'Add new Source', 'read', 'chiron_add_source', 'chiron_wp_add_source' );
add_submenu_page('null', 'Refresh Sources', 'Refresh Sources', 'read', 'chiron_refresh_sources', 'chiron_wp_refresh_sources' );
add_submenu_page('null', 'Add new Category', 'Add new Category', 'read', 'chiron_add_category', 'chiron_wp_add_category' );
add_submenu_page('null', 'Edit Source', 'Edit Source', 'read', 'chiron_edit_source', 'chiron_wp_edit_source' );
add_submenu_page('null', 'Refresh Source', 'Refresh Source', 'read', 'chiron_refresh_source', 'chiron_wp_refresh_source' );
add_submenu_page('null', 'Edit Category', 'Edit Category', 'read', 'chiron_edit_category', 'chiron_wp_edit_category' );
add_submenu_page('null', 'Manage Subscription', 'Manage Subscription', 'read', 'chiron_manage_subscription', 'chiron_wp_manage_subscription' );
}
add_action("admin_menu","chiron_wp_admin_menu");
function chiron_wp_debug(){
global $wp_version;
print "<div class='wrap'>";
print "<h2>Debugging Chiron</h2>";
// Basic Data
print "<h3>Basic Data</h3>";
print "<ul>";
print "<li><strong>Wordpress Version:</strong> ".$wp_version."</li>";
print "</ul>";
// Schedules
print "<h3>Current Schedules</h3>";
print "<ul>";
$schedules = wp_get_schedules();
foreach($schedules as $slug => $plan){
print "<li><strong>".$plan['display']."</strong> runs every ".$plan['interval']." seconds. [".$slug."]</li>";
}
print "</ul>";
// Crons
print "<h3>Cron</h3>";
$cron = get_option('cron');
print "<ul>";
foreach($cron as $timestamp => $nextcron){
if($timestamp != "version"){
print "<li>On ".date("d-m-Y, h:i:s", (int) $timestamp)." shallst run ";
foreach($nextcron as $hook => $details){
print $hook." ";
}
print "</li>";
}
}
print "</ul>";
print "<pre>";
//print_r($cron);
print "</pre>";
print "</div> <!-- // .wrap -->";
}
function chiron_wp_settings(){
print "<div class='wrap'>";
print "<h2>Chiron Settings</h2>";
print "<p>Manage your Settings, young Hero or Heroine!</p>";
print "</div> <!-- // .wrap -->";
}
function chiron_wp_dashboard(){
global $chiron;
global $wp_version;
$user = wp_get_current_user();
$id_user = $user->data->ID;
print "<div class='wrap'>";
print "<h2>Welcome to your News-Dashboard, young Hero or Heroine!</h2>";
$sources_count = $chiron->sources_count();
$items_count = $chiron->items_count();
$version = explode(".", $wp_version);
if(!($version[0] >= "3" and $version[1]>=8)){
print "<p>WARNING: Chiron hasn't been tested with Wordpress ".$wp_version.". Please deactivate the Plugin or use it on your own risk!</p>";
}
print "<p><strong>".$items_count[0]." items</strong> from <strong>".$sources_count[0]." sources</strong> are waiting to be read by you.</p>";
if($_GET["day"]!=""){
if($_GET["day"]== date("Y-m-d",time())){
$date = date("Y-m-d", time()-60*60*24);
}else{
$date = $_GET["day"];
}
}else{
$date = date("Y-m-d", time()-60*60*24);
}
$timestamp = strtotime($date);
print('<div class="tablenav">');
print('<div class="tablenav-pages">');
$yesterday = date("Y-m-d", $timestamp - 60*60*24);
$tomorrow = date("Y-m-d", $timestamp + (60*60*24));
print '<div class="tablenav-pages">';
print " <a class='prev-page' href='?page=chiron_dashboard&day=".$yesterday."'>‹</a> ";
print '<span class="paging-input">'."News of ". date("l", $timestamp)." the ".date("j. F Y", $timestamp)."</span>";
if($tomorrow != date("Y-m-d", time())){
print " <a class='next-page' href='?page=chiron_dashboard&day=".$tomorrow."'>›</a>";
}
print ("</div>");
print ("</div>");
print ("</div>");
$day = date("Y-m-d", $timestamp);
$chiron->items_get_by_day_and_user($day, $id_user);
if(count($chiron->items)>0){
print "<table class='wp-list-table widefat'>";
print '<thead>';
print '<tr>';
print '<th>Source</th>';
print '<th>Title</th>';
print '</tr>';
print '</thead>';
$output = "";
foreach($chiron->categories as $category){
$output = "";
$found = 0;
$oddoreven = "odd";
foreach($chiron->subscriptions as $subscription){
if($category->id == $subscription->id_category){
foreach($chiron->items as $item){
if($item->source == $subscription->id_source){
$found ++;
$rowclasses = array();
if($oddoreven == "odd"){
$rowclasses[] = "alternate";
}
$classes = implode(" ", $rowclasses);
$output .= "<tr class='".$classes."'>";
$output .= "<td>".$chiron->sources[$item->source]->title."</td>";
$output .= "<td><a href='".$item->url."'>".$item->title."</a></td>";
$output .= "</tr>";
if($oddoreven == "odd"){
$oddoreven = "even";
}else{
$oddoreven = "odd";
}
}
}
}
}
if($found>0){
$header = "";
$header .= "<tr>";
$header .= "<td colspan='2'><h3 style='display:inline'>".$category->title."</h3> with ".$found." items</td>";
$header .= "</tr>";
print $header.$output;
}
}
print '<tfoot>';
print '<tr>';
print '<th>Source</th>';
print '<th>Title</th>';
print '</tr>';
print '</tfoot>';
print "</table>";
}
print "<p>".count($chiron->items)." yeasterdays news.</p>";
print "</div>";
}
// Sources from here on
function chiron_wp_manage_sources(){
global $chiron;
print "<div class='wrap'>";
print "<h2>Sources <a class='add-new-h2' href='?page=chiron_add_source'>Add New</a></h2>";
print "<p>Manage your Sources, young Hero or Heroine!</p>";
$no = $chiron->sources_get_all();
print "<p>You have ".$no." magnificent Sources of Information.</p>";
if($no>0){
print "<table class='wp-list-table widefat'>";
print '<thead>';
print '<tr>';
print '<th>Titel</th>';
print '<th>URL</th>';
print '<th>Last Checked</th>';
print '<th>Status</th>';
print "<th>Operations</th>";
print '</tr>';
print '</thead>';
$oddoreven = "odd";
foreach($chiron->sources as $source){
$rowclasses = array();
if($oddoreven == "odd"){
$rowclasses[] = "alternate";
}
$classes = implode(" ", $rowclasses);
print "<tr class='".$classes."'>";
print "<td>".$source->title."</td>";
print "<td>".$source->url."</td>";
if($source->lastchecked>0){
$date = date("d. m. Y H:i:s", $source->lastchecked);
}else{
$date = "never";
}
print "<td>".$date."</td>";
print "<td>".$source->status."</td>";
print "<td><a href='?page=chiron_edit_source&source_id=".$source->id."'>edit</a>";
print " | <a href='?page=chiron_refresh_source&source_id=".$source->id."'>refresh</a>";
print " | <a href='?page=chiron_manage_subscription&source_id=".$source->id."'>subscribe</a>";
print "</td>";
print "</tr>";
if($oddoreven == "odd"){
$oddoreven = "even";
}else{
$oddoreven = "odd";
}
}
print '<tfoot>';
print '<tr>';
print '<th>Titel</th>';
print '<th>URL</th>';
print '<th>Last Checked</th>';
print '<th>Status</th>';
print "<th>Operations</th>";
print '</tr>';
print '</tfoot>';
print "</table>";
}
print "</div> <!-- // .wrap -->";
}
function chiron_wp_add_source(){
global $chiron;
print "<div class='wrap'>";
print "<h2>Add a new Source</h2>";
if(isset($_POST) && !empty($_POST)){
$source = new chiron_source();
$source->title = $_POST['title'];
$source->url = $_POST['url'];
$result = $source->add();
if($result == "1"){
print '<div id="message" class="updated below-h2"><p>Source added successfully.</p></div>';
}
}
print "<div class='form-wrap'>";
print '<form method="post">';
print '<div class="form-field form-required"><label>URL of your new Source</label><input type="text" name="url" /><p>The URL under which your Source is awailable.</p></div>';
print '<div class="form-field form-required"><label>Title of your new Source</label><input type="text" name="title"><p>If you leave it blank, the Title will be created from the Source itself. You may edit it later on.</p></div>';
print '<input type="submit">';
print '</form>';
print "</div> <!-- // .form-wrap -->";
print "</div> <!-- // .wrap -->";
}
function chiron_wp_edit_source(){
global $chiron;
print "<div class='wrap'>";
print "<h2>Edit Source</h2>";
if(isset($_POST) && !empty($_POST)){
$source = new chiron_source();
$source->id = $_GET['source_id'];
$source->title = $_POST['title'];
$source->url = $_POST['url'];
$result = $source->update();
if($result == "1"){
print '<div id="message" class="updated below-h2"><p>Source updated successfully.</p></div>';
}else{
print '<div id="message" class="updated below-h2"><p>Source <strong>not</strong> updated.</p></div>';
}
}
if(isset($_GET['source_id']) && !empty($_GET['source_id'])){
$source_id = $_GET['source_id'];
$source = new chiron_source($source_id);
print "<div class='form-wrap'>";
print '<form method="post">';
print '<div class="form-field form-required"><label>New URL of your Source</label><input type="text" name="url" value="'.$source->url.'"/><p>The URL under which your Source is awailable.</p></div>';
print '<div class="form-field form-required"><label>New Title of your Source</label><input type="text" name="title" value="'.$source->title.'"><p>If you leave it blank, the Title will be created from the Source itself. You may edit it later on.</p></div>';
print '<input type="submit">';
print '</form>';
print "</div> <!-- // .form-wrap -->";
}else{
print "<p>No Source selected for editing.</p>";
}
print "</div> <!-- // .wrap -->";
}
function chiron_wp_refresh_sources(){
global $chiron;
print "<div class='wrap'>";
print "<h2>Refreshing some Sources</h2>";
$sources = $chiron->sources_run_cron();
foreach($sources as $source){
print "<p>Updating Source <strong>".$source->title."</strong> … added ".$source->lastadded." items.";
if($source->error!=""){
print "<br/>Error:</strong> ".$source->error."";
}
print "</p>";
}
print '<form method="post"><input class="button button-primary" type="submit" value="Refresh some more Sources" ></form>';
print "</div> <!-- // .wrap -->";
}
function chiron_wp_refresh_source(){
print "<div class='wrap'>";
print "<h2>Refresh Source</h2>";
if(isset($_GET['source_id']) && !empty($_GET['source_id'])){
$source_id = $_GET['source_id'];
$source = new chiron_source($source_id);
$source->refresh();
print "<p>Updating Source <strong>".$source->title."</strong> … added ".$source->lastadded." items.";
if($source->error!=""){
print "<br/>Error:</strong> ".$source->error."";
}
print "</p>";
}else{
print "<p>No Source selected for refreshing.</p>";
}
print "</div> <!-- // .wrap -->";
}
// Everything Categories beyond here
function chiron_wp_manage_categories(){
global $chiron;
$user = wp_get_current_user();
$uid = $user->data->ID;
print "<div class='wrap'>";
print "<h2>Categories of your Sources <a class='add-new-h2' href='?page=chiron_add_category'>Add New</a></h2>";
print "<p>Manage the Categories of your Sources, young Hero or Heroine!</p>";
$categories = $chiron->categories_get_all_by_user($uid);
$no = count($categories);
if($no>0){
print "<table class='wp-list-table widefat'>";
print '<thead>';
print '<tr>';
print '<th>Titel</th>';
print '<th>Weight</th>';
print "<th>Operations</th>";
print '</tr>';
print '</thead>';
$oddoreven = "odd";
foreach($categories as $category){
$rowclasses = array();
if($oddoreven == "odd"){
$rowclasses[] = "alternate";
}
$classes = implode(" ", $rowclasses);
print "<tr class='".$classes."'>";
print "<td>".$category->title."</td>";
print "<td>".$category->weight."</td>";
print "<td><a href='?page=chiron_edit_category&category_id=".$category->id."'>edit</a></td>";
print "</tr>";
if($oddoreven == "odd"){
$oddoreven = "even";
}else{
$oddoreven = "odd";
}
}
print '<tfoot>';
print '<tr>';
print '<th>Titel</th>';
print '<th>Weight</th>';
print "<th>Operations</th>";
print '</tr>';
print '</tfoot>';
print "</table>";
print "<p>Remember, these are your Categories. Other Users might have other Categories for the same sources.</p>";
}
print "</div> <!-- // .wrap -->";
}
function chiron_wp_add_category(){
global $chiron;
print "<div class='wrap'>";
print "<h2>Add a new Category</h2>";
$user = wp_get_current_user();
$uid = $user->data->ID;
if(isset($_POST) && !empty($_POST)){
$category = new chiron_category();
$category->user = $uid;
$category->title = $_POST['title'];
$category->weight = $_POST['weight'];
$result = $category->add();
if($result == "1"){
print '<div id="message" class="updated below-h2"><p>Category added successfully.</p></div>';
}
}
print "<div class='form-wrap'>";
print '<form method="post">';
print '<div class="form-field form-required"><label>Title of your new Category</label><input type="text" name="title"><p>The Title of your Category, actually there is nothing more to it.</p></div>';
print '<div class="form-field form-required"><label>Weight of your new Category</label><input type="text" name="weight" /><p>Weight of a Category, which defines the order or Categories</p></div>';
print '<input type="submit">';
print '</form>';
print "</div> <!-- // .form-wrap -->";
print "</div> <!-- // .wrap -->";
}
function chiron_wp_edit_category(){
global $chiron;
print "<div class='wrap'>";
print "<h2>Edit Category</h2>";
$user = wp_get_current_user();
$uid = $user->data->ID;
if(isset($_POST) && !empty($_POST)){
$category = new chiron_category();
$category->id = $_GET['category_id'];
$category->title = $_POST['title'];
$category->weight = $_POST['weight'];
$result = $category->update();
if($result == "1"){
print '<div id="message" class="updated below-h2"><p>Category added successfully.</p></div>';
}
}
if(isset($_GET['category_id']) && !empty($_GET['category_id'])){
$category_id = $_GET['category_id'];
$category = new chiron_category($category_id);
print "<div class='form-wrap'>";
print '<form method="post">';
print '<div class="form-field form-required"><label>Title of your new Category</label><input type="text" name="title" value="'.$category->title.'"><p>The new Title of your Category, actually there is nothing more to it.</p></div>';
print '<div class="form-field form-required"><label>Weight of your new Category</label><input type="text" name="weight" value="'.$category->weight.'"/><p>The new Weight of a Category, which defines the order or Categories</p></div>';
print '<input type="submit">';
print '</form>';
print "</div> <!-- // .form-wrap -->";
}else{
print "<p>No Category selected for editin.</p>";
}
print "</div> <!-- // .wrap -->";
}
function chiron_wp_manage_subscriptions(){
global $chiron;
$user = wp_get_current_user();
$uid = $user->data->ID;
$result = $chiron->subscriptions_get_all_by_user($uid);
$itemcount = $chiron->sources_get_item_count();
print "<div class='wrap'>";
print "<h2>Manage your Subscriptions</h2>";
$no = count($chiron->sources);
print "<p>You have subscribed ".$no." magnificent Sources of Information.</p>";
if($no>0){
print "<table class='wp-list-table widefat'>";
print '<thead>';
print '<tr>';
print '<th>Source</th>';
print '<th>Category</th>';
print '<th>URL</th>';
print '<th>Items</th>';
print '<th>Last Checked</th>';
print '<th>Status</th>';
print "<th>Operations</th>";
print '</tr>';
print '</thead>';
$oddoreven = "odd";
foreach($chiron->sources as $source){
$rowclasses = array();
if($oddoreven == "odd"){
$rowclasses[] = "alternate";
}
$classes = implode(" ", $rowclasses);
print "<tr class='".$classes."'>";
print "<td><strong>".$source->title."</strong></td>";
print "<td>".$chiron->categories[$chiron->subscriptions[$source->id]->id_category]->title."</td>";
print "<td>".$source->url."</td>";
print "<td>".$itemcount[$source->id]."</td>";
if($source->lastchecked>0){
$date = date("d. m. Y H:i:s", $source->lastchecked);
}else{
$date = "never";
}
print "<td>".$date."</td>";
print "<td>".$source->status."</td>";
print "<td>";
print " <a href='?page=chiron_refresh_source&source_id=".$source->id."'>refresh</a>";
print " | <a href='?page=chiron_manage_subscription&source_id=".$source->id."'>edit</a>";
print " | <a href='?page=chiron_delete_subscription&source_id=".$source->id."'>unsubscribe</a>";
print "</td>";
print "</tr>";
if($oddoreven == "odd"){
$oddoreven = "even";
}else{
$oddoreven = "odd";
}
}
print '<tfoot>';
print '<tr>';
print '<th>Source</th>';
print '<th>Category</th>';
print '<th>URL</th>';
print '<th>Items</th>';
print '<th>Last Checked</th>';
print '<th>Status</th>';
print "<th>Operations</th>";
print '</tr>';
print '</tfoot>';
print "</table>";
}
print "</div> <!-- // .wrap -->";
print "<pre>";
//print_r($chiron);
print "</pre>";
}
// Everything Subscriptions beyond here
function chiron_wp_manage_subscription(){
global $chiron;
$user = wp_get_current_user();
$uid = $user->data->ID;
print "<div class='wrap'>";
print "<h2>Manage a Subscription</h2>";
// First check, wether there are Post-Variables
if(isset($_POST) && !empty($_POST) && isset($_GET['source_id']) && !empty($_GET['source_id'])){
$subscription = new chiron_subscription();
$subscription->id_user = $uid;
$subscription->id_source = $_GET['source_id'];
$subscription->id_category = $_POST['category_id'];
if(!$subscription->exists()){
$result = $subscription->add();
if($result){
print '<div id="message" class="updated below-h2"><p>Subscription added successfully.</p></div>';
}else{
print '<div id="message" class="updated below-h2"><p>Sorry, but you already subscribed to that source.</p></div>';
}
}else{
$result = $subscription->edit_category();
if($result){
print '<div id="message" class="updated below-h2"><p>Successfully changed the Category of your Subscription.</p></div>';
}else{
print '<div id="message" class="updated below-h2"><p>Sorry, but you already subscribed to that source with that Category.</p></div>';
}
}
}
// Then Render the Form (again)
if(isset($_GET['source_id']) && !empty($_GET['source_id'])){
$source_id = $_GET['source_id'];
$source = new chiron_source($source_id);
$subscription = new chiron_subscription();
$subscription->id_source = $source_id;
$subscription->id_user = $uid;
if($subscription->exists()){
$subscription->load_by_source_and_user();
}
print "<p>Adding Subscrption of the Source <strong>'".$source->title."'</strong></p>";
$categories = $chiron->categories_get_all_by_user($uid);
print "<div class='form-wrap'>";
print '<form method="post">';
if(count($categories)>0){
print "<select name='category_id'>";
print "<option value='0'>Uncategorized</option>";
foreach($categories as $category){
if($subscription->id_category == $category->id){
$selected = " selected='selected'";
}else{
$selected = '';
}
print "<option value='".$category->id."' ".$selected.">".$category->title."</option>";
}
print "</select>";
}
print '<input type="submit">';
print '</form>';
print "</div> <!-- // .form-wrap -->";
}
print "</div> <!-- // .wrap -->";
}
// Everything WP-Cron-Job from here
function chiron_wp_add_cron_intervals( $schedules ) {
$schedules['5minutes']['interval'] = 300;
$schedules['5minutes']['display'] = __('Every 5 Minutes');
$schedules['1minute']['interval'] = 60;
$schedules['1minute']['display'] = __('Every Minute');
return $schedules; // Do not forget to give back the list of schedules!
}
add_filter( 'cron_schedules', 'chiron_wp_add_cron_intervals' );
add_action( 'chiron_cron_hook', 'chiron_wp_cron_exec' );
if( !wp_next_scheduled( 'chiron_cron_hook' ) ) {
wp_schedule_event( time(), '5minutes', 'chiron_cron_hook' );
}
function chiron_wp_cron_exec(){
global $chiron;
$sources = $chiron->sources_run_cron();
}