<?php /* Codeine * @author bergstein@trickyplan.com * @description: * @package Codeine * @version 8.x */ setFn('Read', function ($Call) { $Result = jd($Call['Value'], true); if (json_last_error() > 0) { F::Log('JSON: ' . json_last_error_msg(), LOG_ERR); F::Log($Call['Value'], LOG_ERR); } return $Result; }); setFn('Write', function ($Call) { return j($Call['Value'], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT); }); setFn('Write.Call', function ($Call) { $Call['Value'] = j($Call['Value']); return $Call; });
public static function loadOptions($Service = null, $Method = null, $Call = [], $Path = 'Options') { $Service = $Service == null ? self::$_Service : $Service; /* $Method = ($Method == null)? self::$_Method: $Method;*/ // Если контракт уже не загружен if (isset(self::$_Options[$Service])) { } else { $Options = []; $ServicePath = strtr($Service, '.', '/'); $Filenames = []; if (self::$_Environment != 'Production') { $Filenames[] = $Path . DS . $ServicePath . '.' . self::$_Environment . '.json'; } $Filenames[] = $Path . DS . $ServicePath . '.json'; if (($Filenames = self::findFiles($Filenames)) !== null) { foreach ($Filenames as $Filename) { $Current = jd(file_get_contents($Filename), true); if ($Current) { self::Log('Options: *' . $Filename . '* loaded', LOG_DEBUG); } else { switch (json_last_error()) { case JSON_ERROR_NONE: $JSONError = ' - No errors'; break; case JSON_ERROR_DEPTH: $JSONError = ' - Maximum stack depth exceeded'; break; case JSON_ERROR_STATE_MISMATCH: $JSONError = ' - Underflow or the modes mismatch'; break; case JSON_ERROR_CTRL_CHAR: $JSONError = ' - Unexpected control character found'; break; case JSON_ERROR_SYNTAX: $JSONError = ' - Syntax error, malformed JSON'; break; case JSON_ERROR_UTF8: $JSONError = ' - Malformed UTF-8 characters, possibly incorrectly encoded'; break; default: $JSONError = ' - Unknown error'; break; } self::Log('JSON Error: ' . $Filename . ':' . $JSONError, LOG_CRIT); //FIXME $Current = []; } if (isset($Current['Mixins']) && is_array($Current['Mixins'])) { foreach ($Current['Mixins'] as $Mixin) { self::Log('Options *' . $Filename . '* mixed with *' . $Mixin . '*', LOG_DEBUG); $Current = self::Merge(self::loadOptions($Mixin), $Current); } } $Options = self::Merge($Options, $Current); } } else { self::Log('No options for *' . $Service . '*', LOG_DEBUG); $Options = []; } self::$_Options[$Service] = $Options; } return self::Merge(self::$_Options[$Service], $Call); }
<?php /* Codeine * @author bergstein@trickyplan.com * @description: * @package Codeine * @version 8.x * @date 13.08.11 * @time 22:37 */ setFn('Open', function ($Call) { return jd(file_get_contents(F::findFile($Call['Filename'])), true); }); setFn('Read', function ($Call) { if (isset($Call['Where']['ID'])) { return $Call['Link'][$Call['Where']['ID']]; } else { return $Call['Link']; } }); setFn('Write', function ($Call) { }); setFn('Close', function ($Call) { return true; });
<?php /* Codeine * @author bergstein@trickyplan.com * @description * @package Codeine * @version 8.x */ setFn('Write', function ($Call) { return jd($Call['Value']); }); setFn('Read', function ($Call) { return j($Call['Value']); });
// Обходим рой F::Log('Traversing swarm', LOG_INFO); F::Log($Call['Honey'], LOG_INFO); foreach ($Call['Honey'] as $Honey) { // В рое есть и мы if ($Honey == $Call['HTTP']['Host']) { continue; } // Если мы стучим в того, кто стучал к нам, будет плохо if (isset($Call['Request']['Honey']) && $Call['Request']['Honey'] == $Honey) { continue; } F::Log('Traversing ' . $Honey, LOG_INFO); $Response = F::Run('IO', 'Read', ['Storage' => 'Web', 'Where' => ['ID' => $Call['HTTP']['Proto'] . $Honey . '/swarm']]); F::Log($Response, LOG_INFO); if (empty($Response)) { } else { foreach ($Response as $cResponse) { $Call['Honey'] = F::Merge($Call['Honey'], jd($cResponse, true)['Honey']); } } } // Если нам принесли медок if (isset($Call['Request']['Honey']) && !isset($Call['Honey'][sha1($Call['Request']['Honey'])])) { $Call['Honey'][sha1($Call['Request']['Honey'])] = $Call['Request']['Honey']; // Медок в горшок! F::Run('IO', 'Write', ['Storage' => 'Swarm', 'Scope' => $Call['HTTP']['Host'], 'Where' => ['ID' => $Call['Swarm']['ID']], 'Data' => $Call['Honey']]); } $Call['Output']['Content']['Honey'] = $Call['Honey']; return $Call; });
<?php /* Codeine * @author bergstein@trickyplan.com * @description * @package Codeine * @version 8.x */ setFn('Read', function ($Call) { if (preg_match('/<\\?xml/', $Call['Value'])) { return jd(j(simplexml_load_string($Call['Value'], null, LIBXML_NOCDATA), JSON_NUMERIC_CHECK), true); } else { return jd(j(simplexml_load_string('<root>' . $Call['Value'] . '</root>'), JSON_NUMERIC_CHECK), true); } });
<?php /* Codeine * @author bergstein@trickyplan.com * @description: * @package Codeine * @version 8.x * @date 13.08.11 * @time 22:37 */ setFn('Open', function ($Call) { if (F::file_exists($Call['Directory'] . '/' . $Call['Filename'])) { $Call['Link'] = (array) jd(file_get_contents($Call['Directory'] . '/' . $Call['Filename']), true); } else { $Call['Link'] = []; } return $Call['Link']; }); setFn('Read', function ($Call) { $Result = array_shift($Call['Link']); file_put_contents($Call['Directory'] . '/' . $Call['Filename'], j($Call['Link'], JSON_NUMERIC_CHECK | JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT)); return $Result; }); setFn('Write', function ($Call) { array_push($Call['Link'], $Call['Data']); return file_put_contents($Call['Directory'] . '/' . $Call['Filename'], j($Call['Link'], JSON_NUMERIC_CHECK | JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT)); }); setFn('Count', function ($Call) { return count($Call['Link']); }); setFn('Close', function ($Call) {
/* Codeine * @author bergstein@trickyplan.com * @description * @package Codeine * @version 8.x */ setFn('Run', function ($Call) { $Hash = sha1(j($Call['Call'])); $Scope = $Call['Service'] . '/' . $Call['Method']; $Cached = F::Run('IO', 'Execute', ['Storage' => 'SOAP Cache', 'Scope' => $Scope, 'Execute' => 'Version', 'Where' => ['ID' => $Hash]]); if (isset($Call['Cache'])) { if ($Cached > time() - $Call['Cache']) { $Result = F::Run('IO', 'Read', ['Storage' => 'SOAP Cache', 'Scope' => $Scope, 'Where' => ['ID' => $Hash]])[0]; F::Log('Cached: ' . $Call['Service'] . '->' . $Call['Method'], LOG_INFO, 'Administrator'); } } if (!isset($Result)) { try { $SOAP = new SoapClient($Call['Service']); F::Log($Call['Service'] . '->' . $Call['Method'], LOG_INFO, 'Administrator'); $Result = $SOAP->__soapCall($Call['Method'], [$Call['Call']]); } catch (SoapFault $e) { F::Log($Call['Service'] . '->' . $Call['Method'], LOG_ERR, 'Administrator'); F::Log($e->getMessage(), LOG_ERR, 'Administrator'); return $Cached; } $Result = jd(j($Result), true); F::Run('IO', 'Write', ['Storage' => 'SOAP Cache', 'Scope' => $Scope, 'Where' => ['ID' => $Hash], 'Data' => $Result]); } return $Result; });
/** * @author bergstein@trickyplan.com * @time 5:17 */ include 'Core.php'; $Opts = []; foreach ($argv as $arg) { if (preg_match('/^--([^=]+)\\=(.+)$/Ssu', $arg, $Pockets)) { $Opts = F::Dot($Opts, strtr($Pockets[1], '_', ' '), $Pockets[2]); F::Log($Pockets[1] . ' = ' . $Pockets[2], LOG_INFO); } else { $Opts[] = $arg; } } if (isset($Opts[1]) && file_exists($Opts[1])) { if ($Opts = F::Merge(jd(file_get_contents($Opts[1]), true), $Opts)) { F::Log('JSON CLI parameters loaded from ' . $Opts[1], LOG_INFO); } } if (file_exists('/etc/default/codeine')) { define('Root', file_get_contents('/etc/default/codeine')); } !defined('Root') ? define('Root', getcwd()) : false; F::Log('Root folder: ' . Root, LOG_INFO); if (empty($Opts)) { F::Log('Empty CLI parameters', LOG_INFO); } else { if (isset($Opts['Service'])) { if (isset($Opts['Method'])) { } else { $Opts['Method'] = 'Do';
public function editItem() { /** @var ActiveRecord $owner */ $owner = $this->owner; if ($this->multiLanguage) { $map = SiteMap::findOne(['model_name' => $owner, 'model_id' => $owner->getPrimaryKey(), 'lang_id' => 0]); if (!$map) { $map = new SiteMap(); $map->model_name = $owner::className(); $map->model_id = $owner->getPrimaryKey(); $map->lang_id = 0; } if ($owner->hasAttribute($this->attribute)) { $map->label = $owner->getAttribute($this->attribute); } $map->route = $this->route; $map->params = jd($this->params); $map->changefreq = $this->freq; $map->priority = $this->priority; $map->updated = time(); $map->save(); } else { foreach ($this->languages as $language) { $map = SiteMap::findOne(['model_name' => $owner, 'model_id' => $owner->getPrimaryKey(), 'lang_id' => $language]); if (!$map) { $map = new SiteMap(); $map->model_name = $owner::className(); $map->model_id = $owner->getPrimaryKey(); $map->lang_id = $language; } if ($owner->hasAttribute($this->attribute . '_' . $language)) { $map->label = $owner->getAttribute($this->attribute . '_' . $language); } $map->route = $this->route; if ($language == $this->defaultLanguage) { $map->params = jd($this->params); } else { $map->params = jd([$this->languageVar => $language], $this->params); } $map->changefreq = $this->freq; $map->priority = $this->priority; $map->updated = time(); $map->save(); } } }
$XML->startElement('params'); F::Map($Call['Call'], function ($Key, $Value) use($XML, &$Root) { if (substr($Key, 0, 1) == '@') { $XML->startAttribute(substr($Key, 1)); $XML->text($Value); $XML->endAttribute(); } else { if (is_numeric($Key)) { if ($Key > 0) { // FIXME Костыль! $XML->endElement(); } } else { $XML->startElement($Key); $Root = $Key; } if (is_array($Value)) { } else { $XML->text($Value); $XML->endElement(); } } }); $XML->endElement(); $XML->endDocument(); $Query = $XML->outputMemory(true); $Result = F::Run('IO', 'Write', ['Storage' => 'Web', 'Where' => ['ID' => $Call['Service']], 'Data' => $Query]); $Result = array_pop($Result); $Result = jd(j(simplexml_load_string($Result)), true); return $Result['params']; });
* @version 8.x */ setFn('Identificate', function ($Call) { /*if ($Call['Loginza']['ID'] == 0) $Call = F::Hook('Loginza.NotConfigured', $Call);*/ $Call['LoginzaURL'] = urlencode($Call['HTTP']['Proto'] . $Call['HTTP']['Host'] . '/auth/social'); // FIXME return $Call; }); setFn('Authenticate', function ($Call) { if ($Call['Loginza']['ID'] != 0) { $Auth = '&id=' . $Call['Loginza']['ID'] . '&sig=' . md5($Call['Request']['token'] . $Call['Loginza']['Key']); } else { $Auth = ''; } $Response = jd(F::Run('IO', 'Read', ['Storage' => 'Web', 'Where' => 'http://loginza.ru/api/authinfo?token=' . $Call['Request']['token'] . $Auth])[0], true); F::Log($Response, LOG_INFO, 'Security'); if (isset($Response['identity'])) { $Provider = parse_url($Response['provider'], PHP_URL_HOST); if (isset($Response['name']['full_name'])) { $Title = $Response['name']['full_name']; } elseif (isset($Response['name']['first_name']) && isset($Response['name']['last_name'])) { $Title = $Response['name']['first_name'] . ' ' . $Response['name']['last_name']; } else { $Title = $Response['identity']; } $UserData = ['External' => $Provider, 'EMail' => $Response['identity'], 'Status' => 1, 'Password' => sha1(rand()), 'Title' => $Title]; // FIXME foreach ($Call['Loginza']['Map'] as $Own => $Their) { $UserData[$Own] = F::Dot($Response, $Their); }
<?php /* Codeine * @author bergstein@trickyplan.com * @description * @package Codeine * @version 8.x */ setFn('Do', function ($Call) { $CanIUse = jd(F::Live($Call['Caniuse']['Source'], $Call)[0], true); foreach ($CanIUse['data'] as $Feature => $Data) { if (isset($Data['stats'][$Call['Browser']][$Call['Version']])) { $Output[$Feature] = $Data['stats'][$Call['Browser']][$Call['Version']]; } } return $Output; });
<?php /* Codeine * @author bergstein@trickyplan.com * @description * @package Codeine * @version 8.x */ setFn('Do', function ($Call) { $Call = F::Hook('beforeCreateDo', $Call); $Call = F::Apply(null, $Call['HTTP']['Method'], $Call); return $Call; }); setFn('GET', function ($Call) { return $Call; }); setFn('POST', function ($Call) { F::Run('Entity', 'Create', $Call, ['Data' => jd($Call['Request']['Data'], true)]); return $Call; }); setFn('Input', function ($Call) { $Call['Data'] = jd(file_get_contents('php://stdin'), true); F::Log($Call['Entity'] . ' ' . count($Call['Data']) . ' objects loaded from stdin', LOG_WARNING, 'Developer'); foreach ($Call['Data'] as $Data) { F::Run('Entity', 'Create', $Call, ['Skip Live' => true, 'Data!' => $Data]); } return []; });
<?php /* Codeine * @author bergstein@trickyplan.com * @description * @package Codeine * @version 8.x */ setFn('Open', function ($Call) { return F::Run('IO.Storage.Redis', 'Open', $Call); }); setFn('Read', function ($Call) { F::Log('Pull: ' . $Call['Scope'] . $Call['Queue'], LOG_INFO, 'Administrator'); if (($Result = $Call['Link']->lPop($Call['Scope'] . $Call['Queue'])) !== false) { return [jd($Result, true)]; } else { return null; } }); setFn('Write', function ($Call) { F::Log('Push: ' . $Call['Scope'] . $Call['Queue'], LOG_INFO, 'Administrator'); return $Call['Link']->rPush($Call['Scope'] . $Call['Queue'], j($Call['Data'])); }); setFn('Count', function ($Call) { F::Log('Count: ' . $Call['Scope'] . $Call['Queue'], LOG_INFO, 'Administrator'); return $Call['Link']->lLen($Call['Scope'] . $Call['Queue']); });
<?php /* Codeine * @author bergstein@trickyplan.com * @description * @package Codeine * @version 8.x */ setFn('Run', function ($Call) { $Test = jd(file_get_contents(F::findFile('Tests/' . $Call['Test']['Name'] . '.json'))); $Call['Test']['Report'] = []; $Call['Test']['Name'] = str_replace('.json', '', $Call['Test']['Name']); $Call['Test']['Name'] = strtr($Call['Test']['Name'], '/', '.'); if (isset($Test) && isset($Test['Suites'])) { F::Log('Test *' . $Call['Test']['Name'] . '* loaded', LOG_INFO); foreach ($Test['Suites'] as $SuiteName => $Suite) { foreach ($Suite as $CaseName => $Call['Case']) { $Call['Case']['Result']['Actual'] = F::Live($Call['Case']['Run'], $Call); if (isset($Call['Case']['Output']['Content'])) { $Call['Case']['Result']['Actual'] = print_r($Call['Return']['Output']['Content'], true); } foreach ($Call['Case']['Assert'] as $Assert => $Call['Checker']) { $TestTime = microtime(true); // FIXME $Call['Decision'] = F::Run('Test.Assert.' . $Assert, 'Do', $Call); $TestTime = microtime(true) - $TestTime; } if (isset($Call['Case']['Result Key'])) { $Call['Case']['Result']['Actual'] = F::Dot($Call['Case']['Result']['Actual'], $Call['Case']['Result Key']); } $Call['Test']['Report'][$Call['Test']['Name'] . $SuiteName . $CaseName] = [$Call['Test']['Name'], $SuiteName, $CaseName, '<pre>' . j($Call['Case']['Result']['Actual']) . '</pre>', round($TestTime, 5) * 1000, '_Class' => $Call['Decision'] ? 'success' : 'danger'];
function cbSecured($in) { return str_replace(jd(CB_SIGN_B), jd(CB_SIGN_A), $in); }
<?php /* Codeine * @author bergstein@trickyplan.com * @description: JSON Router * @package Codeine * @version 8.x * @date 31.08.11 * @time 6:17 */ setFn('Route', function ($Call) { if (is_string($Call['Run'])) { $Call['Run'] = jd($Call['Run'], true); } return $Call; });
<?php /* Codeine * @author bergstein@trickyplan.com * @description * @package Codeine * @version 8.x */ setFn('Check', function ($Call) { $Call['Scan'] = jd(F::Run('IO', 'Write', ['Storage' => 'Web', 'Where' => 'https://www.virustotal.com/vtapi/v2/url/scan', 'Data' => ['apikey' => '058a90c9a1ecb024cdc3f11dde2e90c469deb1760abe38994e20db0e4e15093f', 'url' => 'http://trickyplan.ru/img/logo.png']]), true); return $Call['Scan']['scan_id']; }); setFn('Report', function ($Call) { $Report = jd(F::Run('IO', 'Write', ['Storage' => 'Web', 'Where' => 'http://www.virustotal.com/vtapi/v2/url/report', 'Data' => ['apikey' => '058a90c9a1ecb024cdc3f11dde2e90c469deb1760abe38994e20db0e4e15093f', 'resource' => $Call['Value']]]), true); if ($Report['response_code'] == 1) { if ($Report['positives'] == 0) { return 'Clean'; } else { return 'Danger'; } } else { return 'Scanning'; } });
} return $Result; }); setFn('Access Token', function ($Call) { $Result = null; if (isset($Call['Session']['User']['Odnoklassniki']['Auth'])) { $Result = $Call['Session']['User']['Odnoklassniki']; } else { $Result = $Call['Data']['Odnoklassniki'] = F::Run('Entity', 'Read', ['Entity' => 'User', 'Where' => ['Odnoklassniki.Active' => true], 'Sort' => ['Modified' => false], 'One' => true])['Odnoklassniki']; if (isset($Result['Expire']) > time()) { } else { $oldAuth = $Result['Auth']; $URL = 'http://api.odnoklassniki.ru/oauth/token.do'; $Result = F::Run('IO', 'Write', ['Storage' => 'Web', 'Where' => $URL, 'Output Format' => 'Formats.JSON', 'Data' => ['client_id' => $Call['Odnoklassniki']['AppID'], 'client_secret' => $Call['Odnoklassniki']['Secret'], 'grant_type' => 'refresh_token', 'refresh_token' => $Result['Refresh']]]); $Result = array_pop($Result); $Result = jd($Result, true); if (empty($Result['access_token'])) { $Result = null; } else { F::Run('Entity', 'Update', ['Entity' => 'User', 'Where' => ['Odnoklassniki.Auth' => $oldAuth], 'Data' => ['Odnoklassniki.Auth' => $Result['Auth']], 'One' => true]); } } } return $Result; }); setFn('Calc Signature', function ($Call) { if (!ksort($Call['Call'])) { F::Log('Sort error', LOG_ERR); return null; } else { $requestStr = "";