| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package VikBooking |
| 4 |
* @subpackage core |
| 5 |
* @author E4J s.r.l. |
| 6 |
* @copyright Copyright (C) 2019 E4J s.r.l. All Rights Reserved. |
| 7 |
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL |
| 8 |
* @link https://vikwp.com |
| 9 |
*/ |
| 10 |
|
| 11 |
// No direct access |
| 12 |
defined('ABSPATH') or die('No script kiddies please!'); |
| 13 |
|
| 14 |
JLoader::import('adapter.mvc.controllers.admin'); |
| 15 |
|
| 16 |
/** |
| 17 |
* VikBooking plugin RSS controller. |
| 18 |
* |
| 19 |
* @since 1.3.9 |
| 20 |
* @see JControllerAdmin |
| 21 |
*/ |
| 22 |
class VikBookingControllerRss extends JControllerAdmin |
| 23 |
{ |
| 24 |
/** |
| 25 |
* Sets the opt-in status for the RSS service of the user. |
| 26 |
* |
| 27 |
* @return void |
| 28 |
*/ |
| 29 |
public function optin() |
| 30 |
{ |
| 31 |
if (!JFactory::getUser()->authorise('core.admin', 'com_vikbooking')) |
| 32 |
{ |
| 33 |
// not authorised to view this resource |
| 34 |
throw new Exception(JText::translate('RESOURCE_AUTH_ERROR'), 403); |
| 35 |
} |
| 36 |
|
| 37 |
$input = JFactory::getApplication()->input; |
| 38 |
|
| 39 |
// get opt-in status |
| 40 |
$status = $input->getBool('status', false); |
| 41 |
|
| 42 |
// get RSS instance |
| 43 |
$rss = VikBookingBuilder::setupRssReader(); |
| 44 |
|
| 45 |
// update opt-in status |
| 46 |
$rss->optIn($status); |
| 47 |
|
| 48 |
if (wp_doing_ajax()) |
| 49 |
{ |
| 50 |
wp_die(); |
| 51 |
} |
| 52 |
|
| 53 |
// back to the dashboard |
| 54 |
$this->setRedirect('admin.php?page=vikbooking'); |
| 55 |
} |
| 56 |
|
| 57 |
/** |
| 58 |
* Dismesses the specified RSS feed. |
| 59 |
* |
| 60 |
* @return void |
| 61 |
*/ |
| 62 |
public function dismiss() |
| 63 |
{ |
| 64 |
if (!JFactory::getUser()->authorise('core.admin', 'com_vikbooking')) |
| 65 |
{ |
| 66 |
// not authorised to view this resource |
| 67 |
throw new Exception(JText::translate('RESOURCE_AUTH_ERROR'), 403); |
| 68 |
} |
| 69 |
|
| 70 |
$input = JFactory::getApplication()->input; |
| 71 |
|
| 72 |
// get ID of the feed to dismiss |
| 73 |
$id = $input->getString('id', ''); |
| 74 |
|
| 75 |
if (!$id) |
| 76 |
{ |
| 77 |
// make sure the feed ID is set |
| 78 |
throw new Exception('Missing feed ID', 400); |
| 79 |
} |
| 80 |
|
| 81 |
JLoader::import('adapter.rss.feed'); |
| 82 |
|
| 83 |
// get RSS feed instance |
| 84 |
$feed = new JRssFeed(array('id' => $id), 'vikbooking'); |
| 85 |
|
| 86 |
// dismiss the feed for this user |
| 87 |
$feed->dismiss(); |
| 88 |
|
| 89 |
if (wp_doing_ajax()) |
| 90 |
{ |
| 91 |
wp_die(); |
| 92 |
} |
| 93 |
|
| 94 |
// back to the dashboard |
| 95 |
$this->setRedirect('admin.php?page=vikbooking'); |
| 96 |
} |
| 97 |
|
| 98 |
/** |
| 99 |
* Delays the specified RSS feed. |
| 100 |
* |
| 101 |
* @return void |
| 102 |
*/ |
| 103 |
public function remind() |
| 104 |
{ |
| 105 |
if (!JFactory::getUser()->authorise('core.admin', 'com_vikbooking')) |
| 106 |
{ |
| 107 |
// not authorised to view this resource |
| 108 |
throw new Exception(JText::translate('RESOURCE_AUTH_ERROR'), 403); |
| 109 |
} |
| 110 |
|
| 111 |
$input = JFactory::getApplication()->input; |
| 112 |
|
| 113 |
// get ID of the feed to dismiss |
| 114 |
$id = $input->getString('id', ''); |
| 115 |
|
| 116 |
if (!$id) |
| 117 |
{ |
| 118 |
// make sure the feed ID is set |
| 119 |
throw new Exception('Missing feed ID', 400); |
| 120 |
} |
| 121 |
|
| 122 |
// get specified delay |
| 123 |
$delay = $input->getUint('delay', 60); |
| 124 |
|
| 125 |
JLoader::import('adapter.rss.feed'); |
| 126 |
|
| 127 |
// get RSS feed instance |
| 128 |
$feed = new JRssFeed(array('id' => $id), 'vikbooking'); |
| 129 |
|
| 130 |
// delay the feed for this user |
| 131 |
$feed->delay($delay); |
| 132 |
|
| 133 |
if (wp_doing_ajax()) |
| 134 |
{ |
| 135 |
wp_die(); |
| 136 |
} |
| 137 |
|
| 138 |
// back to the dashboard |
| 139 |
$this->setRedirect('admin.php?page=vikbooking'); |
| 140 |
} |
| 141 |
} |
| 142 |
|