push notifications fixes
This commit is contained in:
parent
02f0b155fb
commit
0700b69b2e
|
@ -59,7 +59,11 @@ var dash_push_push_load = function() {
|
|||
|
||||
var startBtn = this.findToolbarItemByProperty('action','begin');
|
||||
if (startBtn) {
|
||||
$(startBtn.element).text(t('Start sending')+' ('+this.options.data.subscribers+')');
|
||||
if (this.options.data.language.length > 0 && typeof(this.options.data.lang_subscribers[this.options.data.language])!="undefined") {
|
||||
$(startBtn.element).text(t('Start sending')+' ('+this.options.data.lang_subscribers[this.options.data.language]+')');
|
||||
} else {
|
||||
$(startBtn.element).text(t('Start sending')+' ('+this.options.data.subscribers+')');
|
||||
}
|
||||
}
|
||||
|
||||
this.sent = 0;
|
||||
|
@ -104,7 +108,7 @@ var dash_push_push_preview = function(){
|
|||
if (body.length > 0) preview += '<div>'+body.replace(/</g, '<').replace(/>/g, '>')+'</div>';
|
||||
$(this.content).find('.push-preview').html(preview);
|
||||
|
||||
if (title.length>0 && body.length>0){
|
||||
if (title.length>0){
|
||||
this.enableItemsByProperty('action','begin');
|
||||
} else {
|
||||
this.disableItemsByProperty('action','begin');
|
||||
|
@ -140,7 +144,7 @@ var dash_push_push_language = function(element) {
|
|||
var dash_push_push_begin = function() {
|
||||
var title = $(this.content).find('input.title_input').val();
|
||||
var body = $(this.content).find('input.body_input').val();
|
||||
if (title.length>0 && body.length>0) {
|
||||
if (title.length>0) {
|
||||
desk_modal_progress();
|
||||
this.sent = 0;
|
||||
this.push();
|
||||
|
@ -150,7 +154,9 @@ var dash_push_push_begin = function() {
|
|||
var dash_push_records_on_select = function() {
|
||||
var selected = this.getSelectedContentItems();
|
||||
this.disableItemsByProperty('typo','push');
|
||||
if (selected && selected.length == 1 && typeof(selected[0].typo)!="undefined" && selected[0].typo=="record") {
|
||||
if (selected && selected.length == 1 && typeof(selected[0].typo)!="undefined" && selected[0].typo=="record" &&
|
||||
typeof(selected[0].activated)!="undefined" && selected[0].activated==record_status_published_id
|
||||
) {
|
||||
this.enableItemsByProperty('typo','push');
|
||||
}
|
||||
};
|
||||
|
|
|
@ -36,7 +36,7 @@ const CAPTCHA_NAME = 'captcha';
|
|||
const CAPTCHA_FONT = 'DroidSans';
|
||||
const CAPTCHA_SLEEP_TIME = 60;
|
||||
const CAPTCHA_SLEEP_MAX_REQUESTS = 10;
|
||||
const CRON_MIN_INTERVAL = 3600;
|
||||
const CRON_MIN_INTERVAL = 60;
|
||||
const DEFAULT_TIMEZONE = 'UTC';
|
||||
const DEFAULT_LANGUAGE = 'en';
|
||||
const DEFAULT_MODULE = 'zira';
|
||||
|
|
|
@ -20,5 +20,6 @@ return array(
|
|||
'Start sending' => 'Начать рассылку',
|
||||
'Successfully finished. Notifications sent:' => 'Успешно завершено. Отправлено уведомлений:',
|
||||
'Send notifications' => 'Отправить уведомления',
|
||||
'Push notifications are not configured' => 'Push-уведомления не сконфигурированы'
|
||||
'Push notifications are not configured' => 'Push-уведомления не сконфигурированы',
|
||||
'Push subscription database cleaned up' => 'База push-уведомлений почищена'
|
||||
);
|
|
@ -67,6 +67,7 @@ return array(
|
|||
'Select your desired area' => 'Выберите желаемую область фотографии',
|
||||
'Photo size should be at least %s pixels' => 'Фотография должна быть размером не меньше %s пикселей',
|
||||
'Cron executed less than an hour ago' => 'Крон запускался меньше часа назад',
|
||||
'Cron executed less than an minute ago' => 'Крон запускался меньше минуты назад',
|
||||
'Database cleaned up' => 'База данных почищена',
|
||||
'Languages panel' => 'Языковая панель',
|
||||
'Logo' => 'Логотип',
|
||||
|
|
17
push/cron/cleaner.php
Normal file
17
push/cron/cleaner.php
Normal file
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
/**
|
||||
* Zira project.
|
||||
* cleaner.php
|
||||
* (c)2019 https://github.com/ziracms/zira
|
||||
*/
|
||||
|
||||
namespace Push\Cron;
|
||||
|
||||
use Zira;
|
||||
|
||||
class Cleaner implements Zira\Cron {
|
||||
public function run() {
|
||||
\Push\Models\Subscription::cleanUp();
|
||||
return Zira\Locale::tm('Push subscription database cleaned up','push');
|
||||
}
|
||||
}
|
|
@ -44,7 +44,7 @@ class Send extends Form
|
|||
$html .= $this->input(Locale::t('Title').'*', 'title', array('placeholder'=>Zira\Locale::t('max. %s characters', self::TITLE_MAX_SIZE), 'class'=>'form-control title_input'));
|
||||
$html .= $this->input(Locale::t('Description'), 'description', array('placeholder'=>Zira\Locale::t('max. %s characters', self::BODY_MAX_SIZE), 'class'=>'form-control body_input'));
|
||||
$html .= $this->input(Locale::t('Image'), 'image', array('class'=>'form-control image_input'));
|
||||
$html .= $this->input(Locale::t('Page'), 'url', array('class'=>'form-control url_input'));
|
||||
$html .= $this->input(Locale::t('URL'), 'url', array('class'=>'form-control url_input'));
|
||||
$html .= Zira\Helper::tag_open('div', array('class'=>'form-group'));
|
||||
$html .= Zira\Helper::tag_open('div', array('class'=>'col-sm-offset-4 col-sm-8'));
|
||||
$html .= Zira\Helper::tag('div', null, array('class'=>'push-preview'));
|
||||
|
@ -68,15 +68,8 @@ class Send extends Form
|
|||
$validator->registerNoTags('image',Locale::tm('Invalid value "%s"','dash',Locale::tm('Image','dash')));
|
||||
$validator->registerUtf8('image',Locale::tm('Invalid value "%s"','dash',Locale::tm('Image','dash')));
|
||||
|
||||
$validator->registerString('url',null,255,false,Locale::tm('Invalid value "%s"','dash',Locale::tm('Page','dash')));
|
||||
$validator->registerNoTags('url',Locale::tm('Invalid value "%s"','dash',Locale::tm('Page','dash')));
|
||||
$validator->registerUtf8('url',Locale::tm('Invalid value "%s"','dash',Locale::tm('Page','dash')));
|
||||
$validator->registerCustom(array(get_class(), 'checkURL'), array('url'), Locale::tm('Invalid value "%s"','dash',Locale::tm('Page','dash')));
|
||||
}
|
||||
|
||||
public static function checkURL($url) {
|
||||
$url = trim($url);
|
||||
if (strpos($url, 'http://') === 0 || strpos($url, 'https://') === 0) return false;
|
||||
return true;
|
||||
$validator->registerString('url',null,255,false,Locale::tm('Invalid value "%s"','dash',Locale::tm('URL','dash')));
|
||||
$validator->registerNoTags('url',Locale::tm('Invalid value "%s"','dash',Locale::tm('URL','dash')));
|
||||
$validator->registerUtf8('url',Locale::tm('Invalid value "%s"','dash',Locale::tm('URL','dash')));
|
||||
}
|
||||
}
|
|
@ -66,8 +66,9 @@ class Push extends Dash\Models\Model {
|
|||
try {
|
||||
if (!\Push\Push::pushNotification($subscription->endpoint, $subscription->pub_key, $subscription->auth_token, $subscription->encoding, $title, $body, $image, $url)) {
|
||||
\Push\Models\Subscription::disableSubscription($subscription->endpoint);
|
||||
} else {
|
||||
$sent++;
|
||||
}
|
||||
$sent++;
|
||||
} catch (\Exception $e) {
|
||||
Zira\Log::exception($e);
|
||||
}
|
||||
|
|
|
@ -93,4 +93,13 @@ class Subscription extends Orm {
|
|||
if (empty($subscription)) return false;
|
||||
return $subscription->active ? false : true;
|
||||
}
|
||||
|
||||
public static function cleanUp() {
|
||||
$trash_time = \Push\Push::TRASH_TIME;
|
||||
self::getCollection()
|
||||
->delete()
|
||||
->where('active', '=', 0)
|
||||
->and_where('date_created','<',date('Y-m-d H:i:s', time()-$trash_time))
|
||||
->execute();
|
||||
}
|
||||
}
|
|
@ -13,6 +13,8 @@ class Push {
|
|||
const ROUTE = 'subscribe';
|
||||
const PHP_MIN_VERSION = '7.1.0';
|
||||
|
||||
const TRASH_TIME = 2592000; // 30 days
|
||||
|
||||
private static $_instance;
|
||||
private static $_web_push_instance;
|
||||
|
||||
|
@ -115,7 +117,8 @@ class Push {
|
|||
$push_pub_key = Zira\Config::get('push_pub_key');
|
||||
$push_priv_key = Zira\Config::get('push_priv_key');
|
||||
if (empty($push_pub_key) || empty($push_priv_key)) return false;
|
||||
|
||||
|
||||
if (empty($url)) $url = '/';
|
||||
$notification = [
|
||||
'subscription' => self::createSubscription([
|
||||
'endpoint' => $endpoint,
|
||||
|
@ -127,7 +130,7 @@ class Push {
|
|||
'title' => Zira\Helper::html($title),
|
||||
'body' => Zira\Helper::html($body),
|
||||
'icon' => Zira\Helper::baseUrl(Zira\Helper::urlencode($image)),
|
||||
'url' => Zira\Helper::url(Zira\Helper::urlencode($url))
|
||||
'url' => Zira\Helper::urlencode($url, true)
|
||||
))
|
||||
];
|
||||
|
||||
|
@ -144,7 +147,8 @@ class Push {
|
|||
$sent = $webPush->sendNotification(
|
||||
$notification['subscription'],
|
||||
$notification['payload'],
|
||||
true
|
||||
true,
|
||||
['topic' => 'zira']
|
||||
);
|
||||
|
||||
if (!$sent->current()->isSuccess()) {
|
||||
|
|
|
@ -65,11 +65,12 @@ class Push extends Dash\Windows\Window {
|
|||
->get('co');
|
||||
|
||||
$data = array();
|
||||
|
||||
|
||||
$language = '';
|
||||
$item_id = (int)Zira\Request::post('item_id');
|
||||
if ($item_id > 0) {
|
||||
$record = Zira\Models\Record::getCollection()
|
||||
->select('id', 'name','author_id','title','description','image','thumb','creation_date','rating','comments')
|
||||
->select('id', 'name','author_id','title','description','image','thumb','creation_date','rating','comments','language')
|
||||
->left_join(Zira\Models\Category::getClass(), array('category_name'=>'name', 'category_title'=>'title'))
|
||||
->join(Zira\Models\User::getClass(), array('author_username'=>'username', 'author_firstname'=>'firstname', 'author_secondname'=>'secondname'))
|
||||
->where('id', '=', $item_id)
|
||||
|
@ -85,7 +86,12 @@ class Push extends Dash\Windows\Window {
|
|||
$data['description'] = mb_substr($data['description'], 0, \Push\Forms\Send::BODY_MAX_SIZE-3, CHARSET).'...';
|
||||
}
|
||||
$data['image'] = $record->image;
|
||||
$data['url'] = rawurldecode(Zira\Page::generateRecordUrl($record->category_name, $record->name));
|
||||
$_language = '';
|
||||
if (count(Zira\Config::get('languages'))>1) $_language = $record->language;
|
||||
Zira\Helper::setAddingLanguageToUrl(false);
|
||||
$data['url'] = Zira\Helper::url($_language.'/'.rawurldecode(Zira\Page::generateRecordUrl($record->category_name, $record->name)), true, true);
|
||||
Zira\Helper::setAddingLanguageToUrl(true);
|
||||
$language = $record->language;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -122,7 +128,7 @@ class Push extends Dash\Windows\Window {
|
|||
'subscribers' => $subscribers,
|
||||
'lang_subscribers' => $lang_subscribers,
|
||||
'offset' => 0,
|
||||
'language' => '',
|
||||
'language' => $language,
|
||||
'item_id' => $item_id
|
||||
));
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ class Cron extends Zira\Controller {
|
|||
$output = '';
|
||||
$last = Zira\Config::get('cron_run');
|
||||
if ($last && time()-$last<CRON_MIN_INTERVAL) {
|
||||
$output .= Zira\Locale::t('Cron executed less than an hour ago');
|
||||
$output .= Zira\Locale::t('Cron executed less than an minute ago');
|
||||
} else {
|
||||
$sys_modules = array('zira');
|
||||
$config_modules = Zira\Config::get('modules');
|
||||
|
|
|
@ -178,9 +178,10 @@ class Helper {
|
|||
return $path;
|
||||
}
|
||||
|
||||
public static function urlencode($url) {
|
||||
public static function urlencode($url, $isAbsolute = false) {
|
||||
$url = rawurlencode($url);
|
||||
$url = str_ireplace('%2F', '/', $url);
|
||||
if ($isAbsolute) $url = str_ireplace('%3A', ':', $url);
|
||||
return $url;
|
||||
}
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ namespace Zira;
|
|||
use Dash\Dash;
|
||||
|
||||
class Zira {
|
||||
const VERSION = '1.4.1';
|
||||
const VERSION = '1.5.0';
|
||||
private static $_instance;
|
||||
private static $_vendor_autoload_enabled = false;
|
||||
|
||||
|
|
Loading…
Reference in a new issue