function locator($device) {
// Can we locate the device?
if ($device->token != "" && $device->expire <= $now) {
return false;
}
$modelNotifier = new ModelNotifier($device);
return $modelNotifier->go();
}
$device?
$device->expire
$now
? ?$modelNotifier->go()
?$device->expire
, . ModelNotifier->go()
, . , , token . , .token!=""
, . , , .function locator($device) {
// Can we locate the device?
if ($device->token != "" && $device->expire <= $now) {
return false;
}
$modelNotifier = new ModelNotifier($device);
return $modelNotifier->go();
}
function ModelDevice::isLocatable() {
return ($this->token != "" && $this->expire <= $now);
}
β¦
function locateAndNotifyDevice(ModelDevice $device) {
if (!$device->isLocatable()) {
return false;
}
$modelNotifier = new ModelNotifier($device);
return $modelNotifier->go();
}
function isDeviceExpired() {
return ($this->expireAtUnixtime >= $now);
}
function isOurTokenValid() {
return ($this->token != "");
}
function isLocatable() {
return ($this->isOurTokenValid() && !$this->isDeviceExpired());
}
isLocatable()
, . isDeviceExpired(), , .isLocatable()
, : , . β , . ββ locateDevice()
, ; , , . β , .function getConfig() {
if ($this->hasOption('configs')) {
$configs = $this->getOption('configs');
} else if ($this->hasOption('config')) {
$configs = [ $this->getOption('config') ];
}
if (isset($configs)) {
$root = $this->getOption('root', null);
if (!$root) {
if (isset($_SERVER['PWD'])) {
$root = $_SERVER['PWD'];
} else if (isset($_SERVER['DOCUMENT_ROOT'])) {
$root = $_SERVER['DOCUMENT_ROOT'];
}
}
$configs->root = $root;
}
return $configs;
}
function grabConfiguration() {
if ($this->hasOption('configs')) {
return $this->getOption('configs');
} else if ($this->hasOption('config')) {
return [ $this->getOption('config') ];
}
}
function figureOutRootFolder() {
$root = $this->getOption('root', null);
if (!$root) {
$root = $_SERVER['PWD'];
}
if (!$root) {
$root = $_SERVER['DOCUMENT_ROOT'];
}
return $root;
}
function getConfigs() {
$configs = $this->grabConfiguration();
if (!is_null($configs)) {
$configs->rootFolder = $this->figureOutRootFolder();
}
return $configs;
}
if ([imageEntry objectForKey:@"fullscreenUrl"]==nil) {
NSString *kind = [imageEntry objectForKey:@"kind"];
if ([kind isEqualToString:@"pdf"]) {
UIImage *i = [UIImage imageNamed:@"galleryPdfIcon"];
[self.uiImagesCache setObject:i forKey:@(photoIndex)];
*photoSize = NIPhotoScrollViewPhotoSizeOriginal;
return i;
} else if ([kind isEqualToString:@"video"]) {
UIImage *i = [UIImage imageNamed:@"galleryVideoIcon"];
[self.uiImagesCache setObject:i forKey:@(photoIndex)];
*photoSize = NIPhotoScrollViewPhotoSizeOriginal;
return i;
} else {
UIImage *i = [UIImage imageNamed:@"galleryBrokenImage"];
[self.uiImagesCache setObject:i forKey:@(photoIndex)];
*photoSize = NIPhotoScrollViewPhotoSizeOriginal;
return i;
}
}
- (UIImage *) genericImageForKind:(NSString *) imageKind {
UIImage *candidate = nil;
if ([kind isEqualToString:@"pdf"]) {
candidate = [UIImage imageNamed:@"galleryPdfIcon"];
} else if ([kind isEqualToString:@"video"]) {
candidate = [UIImage imageNamed:@"galleryVideoIcon"];
} else {
candidate = [UIImage imageNamed:@"galleryBrokenImage"];
}
return candidate;
}
β¦
if ([imageEntry objectForKey:@"fullscreenUrl"]==nil) {
NSString *kind = [imageEntry objectForKey:@"kind"];
UIImage *genericImage = [self genericImageForKind:kind];
if (genericImage) {
[self.uiImagesCache setObject:genericImage forKey:@(photoIndex)];
*photoSize = NIPhotoScrollViewPhotoSizeOriginal;
}
return nil;
}
function(err, dResults) {
if (err) {
console.log(err);
callback(err);
return;
}
var i=0, lastDownloaded = null;
var unixtimes = Object.keys(dResults);
for(i=0;i<unixtimes.length;i++) {
if (dResults[unixtimes[i]].isDownloaded) {
lastDownloaded = unixtimes[i];
}
}
for(i=0;i<unixtimes.length;i++) {
if (unixtimes[i]>lastDownloaded) {
delete dResults[unixtimes[i]];
}
}
self.getOpenPrice(symbol, function(err, openPrice) {
callback(err, dResults, openPrice);
});
}
function getLastDownloadedUnixtime(entries) {
var lastDownloadedUnixtime = null;
var unixtimes = Object.keys(entries);
unixtimes.forEach(function(unixtime) {
if (entries[unixtime].isDownloaded) {
lastDownloadedUnixtime = unixtime;
}
});
return lastDownloadedUnixtime;
}
function cleanupEntriesNewerThanLastDownloadedUnixtime(entries, lastDownloadedUnixtime) {
var unixtimes = Object.keys(entries);
for(var i=0;i<unixtimes.length;i++) {
if (unixtimes[i]>lastDownloadedUnixtime) {
delete entries[unixtimes[i]];
}
}
}
β¦
function(err, dResults) {
if (err) {
console.log(err);
callback(err);
return;
}
var lastDownloadedUnixtime = getLastDownloadedUnixtime(dResults);
cleanupEntriesNewerThanLastDownloadedUnixtime(dResults, lastDownloadedUnixtime);
self.getOpenPrice(symbol, function(err, openPrice) {
callback(err, dResults, openPrice);
});
}
strcat(xml, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
strcat(xml, "<Delete>\n");
strcat(xml, "<Quiet>true</Quiet>\n");
for (uint32_t i=0;i<batchCount;i++) {
char *escapedPath=Deleter::xmlEscape(batch[i]);
strcat(xml, "\t<Object><Key>");
strcat(xml, escapedPath);
free(escapedPath);
strcat(xml, "</Key></Object>\n");
LOG(LOG_DBG, "[Delete] %s", batch[i]);
}
strcat(xml, "</Delete>\n");
void addPathToDeleteXml(char *xml, char *path) {
char *escapedPath=Deleter::xmlEscape(path);
strcat(xml, "\t<Object><Key>");
strcat(xml, escapedPath);
strcat(xml, "</Key></Object>\n");
free(escapedPath);
}
void addBatchOfPathsToXml(char *xml, char **batch, uint32_t batchCount) {
for (uint32_t i=0;i<batchCount;i++) {
addPathToDeleteXml(xml, batch[i]);
LOG(LOG_DBG, "[Delete] %s", batch[i]);
}
}
β¦
strcat(xml, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
strcat(xml, "<Delete>\n");
strcat(xml, "<Quiet>true</Quiet>\n");
addBatchOfPathsToXml(xml, batch, batchCount);
strcat(xml, "</Delete>\n");
Source: https://habr.com/ru/post/150868/
All Articles