Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Qybercom/quark
Browse files Browse the repository at this point in the history
  • Loading branch information
chief93 committed Apr 1, 2018
2 parents f35cf5e + 6716e2a commit 5f35888
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 16 deletions.
61 changes: 60 additions & 1 deletion Extensions/PubNub/PubNub.php
Expand Up @@ -8,15 +8,25 @@
use Quark\IQuarkViewResourceWithDependencies;

use Quark\Quark;
use Quark\QuarkDate;
use Quark\QuarkDTO;
use Quark\QuarkHTTPClient;
use Quark\QuarkInlineJSViewResource;
use Quark\QuarkJSONIOProcessor;
use Quark\QuarkJSViewResourceType;
use Quark\QuarkURI;

/**
* Class PubNub
*
* @package Quark\Extensions\PubNub
*/
class PubNub implements IQuarkExtension, IQuarkSpecifiedViewResource, IQuarkViewResourceWithDependencies {
const URL_API = 'https://ps.pndsn.com/';
const URL_SDK = 'https://cdn.pubnub.com/';

const STATUS_SENT = 'Sent';

const VERSION_JS = '4.15.1';

/**
Expand Down Expand Up @@ -45,6 +55,55 @@ public function __construct ($config, $client = '', $version = self::VERSION_JS)
$this->_version = $version;
}

/**
* @return PubNubConfig
*/
public function &Config () {
return $this->_config;
}

/**
* @param string $url = ''
* @param array|object $data = []
* @param string $method = QuarkDTO::METHOD_GET
*
* @return bool|QuarkDTO
*/
public function API ($url = '', $data = [], $method = QuarkDTO::METHOD_GET) {
$request = new QuarkDTO(new QuarkJSONIOProcessor());
$request->Method($method);
$request->Data($data);

return QuarkHTTPClient::To(self::URL_API . $url, $request, new QuarkDTO(new QuarkJSONIOProcessor()));
}

/**
* @param string $channel = ''
* @param string $user = ''
* @param array|object $payload = []
* @param bool $store = false
*
* @return QuarkDate
*/
public function Publish ($channel = '', $user = '', $payload = [], $store = false) {
$query = array(
'uuid' => $user
);

if (func_num_args() == 4)
$query['store'] = $store;

$response = $this->API(
QuarkURI::Build('/publish/' . $this->_config->appKeyPub . '/' . $this->_config->appKeySub . '/0/' . $channel . '/0', $query),
$payload,
QuarkDTO::METHOD_POST
);

$data = $response->Data();

return is_array($data) && $data[1] == self::STATUS_SENT ? QuarkDate::FromTimestamp($data[2] / 1000000) : null;
}

/**
* @return IQuarkViewResourceType
*/
Expand All @@ -56,7 +115,7 @@ public function Type () {
* @return string
*/
public function Location () {
return 'https://cdn.pubnub.com/sdk/javascript/pubnub.' . $this->_version . '.min.js';
return self::URL_SDK . 'sdk/javascript/pubnub.' . $this->_version . '.min.js';
}

/**
Expand Down
28 changes: 19 additions & 9 deletions Quark.php
Expand Up @@ -952,9 +952,14 @@ class QuarkConfig {
private $_openSSLConfig = '';

/**
* @var callable $_ready = null
* @var bool $_ready = false
*/
private $_ready = null;
private $_ready = false;

/**
* @var callable $_readyCallback = null
*/
private $_readyCallback = null;

/**
* @var array $_location
Expand Down Expand Up @@ -1220,9 +1225,8 @@ public function Environment (IQuarkEnvironment $provider = null) {
* @return QuarkModel|IQuarkApplicationSettingsModel
*/
public function &ApplicationSettings (IQuarkApplicationSettingsModel $model = null) {
if (func_num_args() != 0 && $model != null)
$this->_settingsApp = new QuarkModel($model);
else $this->_loadSettings();
if (func_num_args() == 0 || $model == null) $this->_loadSettings();
else $this->_settingsApp = $this->_ready ? new QuarkModel($model) : $model;

return $this->_settingsApp;
}
Expand Down Expand Up @@ -1819,7 +1823,7 @@ public function ModelValidation ($mode = QuarkModel::CONFIG_VALIDATION_ALL) {
*/
public function ConfigReady (callable $callback = null) {
if (func_num_args() != 0) {
$this->_ready = $callback;
$this->_readyCallback = $callback;
return;
}

Expand All @@ -1830,7 +1834,7 @@ public function ConfigReady (callable $callback = null) {
if (!$file->Exists() && $this->_allowINIFallback) return;

$ini = $file->Load()->Decode(new QuarkINIIOProcessor());
$callback = $this->_ready;
$callback = $this->_readyCallback;

if ($callback != null)
$callback($this, $ini);
Expand Down Expand Up @@ -1936,6 +1940,10 @@ public function ConfigReady (callable $callback = null) {
$this->Dedicated($key, $value);

unset($environment, $environments, $extension, $extensions, $options, $callback, $ini, $key, $value);

$this->_ready = true;

$this->ApplicationSettings($this->_settingsApp);
}

/**
Expand Down Expand Up @@ -6612,12 +6620,14 @@ public function LoremIpsum ($amount = 5, $item = self::LII_PARAS, $start = true)
* @param string $name = 'timezone'
* @param string $selected = null
* @param string $format = QuarkCultureISO::TIME
* @param string $class = 'quark-input'
* @param string $id = ''
*
* @return string
*/
public function TimezoneSelector ($name = 'timezone', $selected = null, $format = QuarkCultureISO::TIME) {
public function TimezoneSelector ($name = 'timezone', $selected = null, $format = QuarkCultureISO::TIME, $class = 'quark-input', $id = '') {
$zones = QuarkDate::TimezoneList();
$out = '<select class="quark-input" name=' . $name . '>';
$out = '<select' . ($class ? ' class="' . $class . '"' : '') . ' ' . ($id ? ' id="' . $id . '"' : '') . ' name=' . $name . '>';

foreach ($zones as $zone => &$offset)
$out .= '<option value="' . $zone . '"' . ($selected === $zone ? ' selected="selected"' : '') . '>(UTC ' . $offset->Format($format, true) . ') ' . $zone . '</option>';
Expand Down
9 changes: 3 additions & 6 deletions ViewResources/Quark/QuarkControls/QuarkControls.js
Expand Up @@ -473,6 +473,8 @@ Quark.Controls.Toggle = function (selector, opt) {
elem.removeClass(enabled ? 'fa-toggle-off off' : 'fa-toggle-on on');
elem.addClass(enabled ? 'fa-toggle-on on' : 'fa-toggle-off off');
elem.attr('quark-enabled', enabled ? 'true' : 'false');
elem.attr('title', enabled ? opt.enabled.title : opt.disabled.title);
elem.html(enabled ? opt.enabled.html : opt.disabled.html);

if (elem.attr('disabled') === 'disabled')
that.Available(elem, false);
Expand Down Expand Up @@ -527,12 +529,7 @@ Quark.Controls.Toggle = function (selector, opt) {
* @param elem
*/
that.State = function (elem) {
var enabled = elem.attr('quark-enabled') !== 'true';

elem.attr('title', enabled ? opt.enabled.title : opt.disabled.title);
elem.html(enabled ? opt.enabled.html : opt.disabled.html);

that._attr(enabled, elem);
that._attr(elem.attr('quark-enabled') !== 'true', elem);
};
};

Expand Down

0 comments on commit 5f35888

Please sign in to comment.