示例#1
0
<?php

require 'vendor/autoload.php';
def_accessor('pushover_token', null);
def_accessor('pushover_user', null);
def('bu\\pushover\\check_global_config', function () {
    $pth = getenv('HOME') . '/.pushoverrc';
    if (file_exists($pth)) {
        $cfg = json_decode(file_get_contents($pth), true);
        pushover_token($cfg['token']);
        pushover_user($cfg['user']);
    }
});
bu\pushover\check_global_config();
def_accessor('pushover_curl_timeout', 5);
def('bu\\pushover\\parse_args', function ($a) {
    $opts = array();
    if (is_array($a[0])) {
        $opts = $a[0];
    } else {
        $opts['message'] = $a[0];
        if (isset($a[1])) {
            $opts['title'] = $a[1];
        }
        if (isset($a[2])) {
            $opts['priority'] = $a[2];
        }
    }
    $opts['token'] = pushover_token();
    $opts['user'] = pushover_user();
    return $opts;
示例#2
0
<?php

def_alias('bu::layout', 'l');
def_accessor('title');
def_accessor('keywords');
def_accessor('description');
def('show_404', function () {
    write_log("404", RAW_HTTP_STRING);
    header("Status: 404 Not Found");
    draw_page('Страница не найдена', view('404'));
});
def('draw_page', function ($title, $content) {
    title($title);
    echo dview('layout/default', $content);
});
示例#3
0
文件: load.php 项目: bubujka/s4
<?php

def_accessor('s4_bucket');
def_accessor('s4_region', 'eu-west-1');
def_memo('s4', function () {
    return Aws\S3\S3Client::factory(array('region' => s4_region()));
});
def('s4_delete', function ($key) {
    return s4()->deleteObject(array('Bucket' => s4_bucket(), 'Key' => $key));
});
def('s4_url', function ($key) {
    return s4()->getObjectUrl(s4_bucket(), $key);
});
def('s4_put', function ($key, $body, $ct = null) {
    $t = array('Bucket' => s4_bucket(), 'Key' => $key, 'Body' => $body);
    if (!is_null($ct)) {
        $t['ContentType'] = $ct;
    }
    return s4()->putObject($t);
});
def('s4_get', function ($key) {
    $t = array('Bucket' => s4_bucket(), 'Key' => $key);
    $t = s4()->getObject($t);
    return $t['Body'];
});
def('s4_put_file', function ($key, $pth, $ct = null) {
    $t = array('Bucket' => s4_bucket(), 'Key' => $key, 'SourceFile' => $pth);
    if (!is_null($ct)) {
        $t['ContentType'] = $ct;
    }
    return s4()->putObject($t);
示例#4
0
<?php

def_accessor('data_directory', BASE_DIRECTORY . '/data');
function strip_data_direcotry($pth)
{
    return str_replace(data_directory() . '/', '', $pth);
}
/**
 * Функция для получения пути внутри каталога с данными
 */
def('data', function ($pth) {
    return data_directory() . '/' . $pth;
});
def('main_categories', function () {
    return Category::getSub();
});
/**
 * Этот путь - является ли категорией?
 */
def('is_category_path', function ($v) {
    if (!$v) {
        return false;
    }
    $t = explode('/', $v);
    foreach ($t as $vv) {
        if (!preg_match('@^[a-z_0-9.-]+$@i', $vv)) {
            return false;
        }
    }
    return true;
});
示例#5
0
文件: vkdr.php 项目: bubujka/vkdr
Array
(
    [access_token] => xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    [expires_in] => 85690
    [user_id] => xxxxxxxxx
)
*/
def('vkdr\\get_token_obj', function ($code) {
    $p = array();
    $p['client_id'] = vkdr\app_id();
    $p['client_secret'] = vkdr\app_secret();
    $p['redirect_uri'] = vkdr\redirect_uri();
    $p['code'] = $code;
    return json_decode(file_get_contents('https://oauth.vk.com/access_token?' . http_build_query($p)), true);
});
def_accessor('vkdr\\rate_limiting', false);
def('vkdr\\waaaait', function () {
    usleep(500000);
});
def('vkdr\\on_error', function () {
});
def('vkdr\\method', function ($method, $params = array()) {
    // Документация по доступу к апи: http://vk.com/dev/api_requests
    if (vkdr\rate_limiting()) {
        vkdr\waaaait();
    }
    $params['v'] = vkdr\api_version();
    $params['access_token'] = vkdr\token();
    $query = vkdr\api_url() . '/method/' . $method . '?' . http_build_query($params);
    $r = json_decode(file_get_contents($query), true);
    if (isset($r['error'])) {
示例#6
0
文件: yadr.php 项目: bubujka/yadr
<?php

def_accessor('yadr\\production', false);
def_accessor('yadr\\live_version', true);
def_accessor('yadr\\login', null);
def_accessor('yadr\\token', null);
def_accessor('yadr\\app_id', null);
def('yadr\\utf8', function ($struct) {
    foreach ($struct as $key => $value) {
        if (is_array($value)) {
            $struct[$key] = yadr\utf8($value);
        } elseif (is_string($value)) {
            $struct[$key] = utf8_encode($value);
        }
    }
    return $struct;
});
def('yadr\\method', function ($method, $params = array()) {
    $login = yadr\login();
    $token = yadr\token();
    $app_id = yadr\app_id();
    if (yadr\production()) {
        if (yadr\live_version()) {
            $backend = 'https://api.direct.yandex.ru/live/v4/json/';
        } else {
            $backend = 'https://api.direct.yandex.ru/json-api/v4/';
        }
    } else {
        $backend = 'https://api-sandbox.direct.yandex.ru/json-api/v4/';
    }
    $request = array('token' => $token, 'application_id' => $app_id, 'login' => $login, 'method' => $method, 'param' => yadr\utf8($params), 'locale' => 'ru');
示例#7
0
文件: cltr.php 项目: bubujka/cltr
<?php

require "vendor/autoload.php";
def_accessor('cltr\\pdo_host');
def_accessor('cltr\\pdo_dbname');
def_accessor('cltr\\pdo_user');
def_accessor('cltr\\pdo_password');
def_accessor('cltr\\pdo_table');
def_memo('cltr\\pdo', function () {
    $db = new PDO('mysql:host=' . cltr\pdo_host() . ';dbname=' . cltr\pdo_dbname(), cltr\pdo_user(), cltr\pdo_password());
    $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT);
    $db->query('set names utf8');
    return $db;
});
def_accessor('cltr\\time_start');
def('cltr\\start', function () {
    cltr\time_start(microtime(true));
});
def('cltr\\uri', function () {
    if (isset($_SERVER['REQUEST_URI'])) {
        return $_SERVER['REQUEST_URI'];
    }
});
def('cltr\\host', function () {
    if (isset($_SERVER['HTTP_HOST'])) {
        return $_SERVER['HTTP_HOST'];
    }
});
def('cltr\\time', function () {
    return microtime(true) - cltr\time_start();
});