<?php /* Codeine * @author bergstein@trickyplan.com * @description * @package Codeine * @version 8.x */ setFn('beforeOperation', function ($Call) { if (isset($Call['EV'])) { $Call['Data']['EV'] = $Call['EV']; } else { $Call['Data']['EV'] = 0; } return $Call; });
<?php /* Codeine * @author bergstein@trickyplan.com * @description * @package Codeine * @version 8.x */ setFn('Calculate', function ($Call) { if (preg_match_all('/href=\\=/', $Call['Value'], $Pockets)) { return count($Pockets) * $Call['Antispam']['Link']['Weight']; } else { return 0; } });
<?php /* Codeine * @author bergstein@trickyplan.com * @description * @package Codeine * @version 8.x */ setFn('Do', function ($Call) { if (isset($Call['Request'])) { foreach ($Call['HTTP']['Filter']['Request']['Rules'] as $FilterName => $Filter) { foreach ($Filter['Match'] as $Match) { if (F::Diff($Match, $Call['Request']) === null) { if ($Filter['Decision']) { } else { F::Log('HTTP Request Filter *' . $FilterName . '* matched', LOG_WARNING, 'Security'); return false; } } } } } return true; });
<?php /* Codeine * @author bergstein@trickyplan.com * @description Exec Parslet * @package Codeine * @version 6.0 */ setFn('Parse', function ($Call) { foreach ($Call['Parsed'][2] as $IX => $Match) { $Root = simplexml_load_string('<root ' . $Call['Parsed'][1][$IX] . '></root>'); $Engine = isset($Root->attributes()->engine) ? (string) $Root->attributes()->engine : 'Date'; // TODO Due bug 13744 at w3c validator, time tag temporary diabled. // $Outer = '<time datetime="'.date(DATE_ISO8601, $Match).'">'.date($Format, $Inner).'</time>'; $Outer = ['Value' => $Match]; if (isset($Root->attributes()->format)) { $Outer['Format'] = (string) $Root->attributes()->format; } $Outer = F::Run('Formats.Date.' . $Engine, 'Format', $Outer); $Call['Output'] = str_replace($Call['Parsed'][0][$IX], $Outer, $Call['Output']); } return $Call; });
<?php /* Codeine * @author bergstein@trickyplan.com * @description * @package Codeine * @version 8.x */ setFn('Catch', function ($Call) { $Call['Run'] = ['Service' => 'Error.Page', 'Method' => 'Do', 'Call' => ['Code' => 403]]; return $Call; }); setFn('Do', function ($Call) { $Call['Page']['Title'] = $Call['Code']; $Call['Page']['Description'] = 'TODO'; $Call['Page']['Keywords'] = array('TODO'); $Call['Layouts'] = [['Scope' => 'Default', 'ID' => 'Main'], ['Scope' => 'Project', 'ID' => 'Zone']]; if (isset($Call['Reason'])) { $Call['Output']['Content'] = [['Type' => 'Template', 'Scope' => 'Error/' . $Call['Code'], 'ID' => $Call['Reason']]]; } else { $Call['Output']['Content'] = [['Type' => 'Template', 'Scope' => 'Error', 'ID' => $Call['Code']]]; } return $Call; });
<?php /* Codeine * @author bergstein@trickyplan.com * @description * @package Codeine * @version 8.x */ setFn('Do', function ($Call) { $Call = F::Apply(null, 'Input', $Call); $Call = F::Apply(null, 'Render', $Call); $Call = F::Apply(null, 'Output', $Call); return $Call; }); setFn('Input', function ($Call) { return $Call; }); setFn('Render', function ($Call) { return $Call; }); setFn('Output', function ($Call) { return $Call; });
<?php /* Codeine * @author bergstein@trickyplan.com * @description: Simple HTML Renderer * @package Codeine * @version 8.x */ setFn('Render', function ($Call) { $finfo = new finfo(FILEINFO_MIME); if (is_array($Call['Output']['Content'])) { $Call['Output']['Content'] = implode('', $Call['Output']['Content']); } $Call['Output'] = $Call['Output']['Content']; $Call['HTTP']['Headers']['Content-type:'] = $finfo->buffer($Call['Output']); return $Call; });
<?php /* Codeine * @author bergstein@trickyplan.com * @description * @package Codeine * @version 7.6,2 */ setFn('Widget', function ($Call) { return F::Apply($Call['Modes'][$Call['Mode']], 'Widget', $Call); }); setFn('Check', function ($Call) { if (!isset($Call['CAPTCHA']['Bypass'])) { if (!F::Run($Call['Modes'][$Call['Mode']], 'Check', $Call)) { F::Log('CAPTCHA Failed from IP ' . F::Live($Call['HTTP']['IP']), LOG_ERR, 'Security'); $Call['Failure'] = true; $Call = F::Hook('CAPTCHA.Failed', $Call); } } return $Call; });
foreach ($Locations as $Location) { if (!isset($Call['Location']['Slug']) or null === $Call['Location']['Slug']) { $Location['URL'] = '/' . $Location['Slug']; } else { if (preg_match('@^/' . $Call['Location']['Slug'] . '@Ssuu', $Call['HTTP']['URL'])) { $Location['URL'] = str_replace($Call['Location']['Slug'], $Location['Slug'], $Call['HTTP']['URL']); } else { $Location['URL'] = '/' . $Location['Slug']; } } $Location['URL'] = $Call['HTTP']['Proto'] . $Call['HTTP']['Host'] . $Location['URL']; if (isset($Call['Location']['ID']) && $Location['ID'] == $Call['Location']['ID']) { $Call['Output']['Content'][] = '<option selected value="' . $Location['Slug'] . '"><a href="' . $Location['Slug'] . '">' . $Location['Title'] . '</a></option>'; } else { $Call['Output']['Content'][] = '<option value="' . $Location['Slug'] . '"><a href="' . $Location['Slug'] . '">' . $Location['Title'] . '</a></option>'; } } } return $Call; }); setFn('Select', function ($Call) { if ($Call['Location'] != $Call['Session']['Location']) { F::Run('Session', 'Write', $Call, ['Session Data' => ['Location' => $Call['Location']]]); } if (isset($_SERVER['HTTP_REFERER'])) { $Call = F::Apply('System.Interface.HTTP', 'Redirect', $Call, ['Location' => $_SERVER['HTTP_REFERER']]); } else { $Call = F::Apply('System.Interface.HTTP', 'Redirect', $Call, ['Location' => '/']); } return $Call; });
<?php /* Codeine * @author bergstein@trickyplan.com * @description * @package Codeine * @version 8.x */ setFn('Do', function ($Call) { $Call['HTTP']['Agent'] = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : ''; F::Log($Call['HTTP']['Agent'], LOG_INFO); return $Call; });
<?php /* Codeine * @author bergstein@trickyplan.com * @description * @package Codeine * @version 8.x */ setFn('Write', function ($Call) { $Output = $Call['Data'][0]; $Output = preg_replace('/\\*(.*)\\*/SsUu', '$1', implode(PHP_EOL, (array) $Output)); return $Output; });
<?php /* Codeine * @author bergstein@trickyplan.com * @description * @package Codeine * @version 8.x */ setFn('Do', function ($Call) { time_nanosleep($Call['Seconds'], $Call['Seconds'] - round($Call['Seconds']) * 1000000000); return $Call; });
<?php /* Codeine * @author bergstein@trickyplan.com * @description * @package Codeine * @version 8.x */ setFn('Do', function ($Call) { if (is_string($Call['Value'])) { $Call['Value'] = strip_tags($Call['Value']); } return $Call; });
<?php /* Codeine * @author bergstein@trickyplan.com * @description * @package Codeine * @version 8.x */ setFn('Do', function ($Call) { $Call = F::Hook('beforeIncreaseDo', $Call); $Call = F::Run('Entity', 'Load', $Call); if (isset($Call['Nodes'][$Call['Key']]['Widgets']['Write']) or isset($Call['Nodes'][$Call['Key']]['Widgets']['Update'])) { $Data = F::Run('Entity', 'Read', $Call, ['One' => true]); $Data = F::Dot($Data, $Call['Key'], F::Dot($Data, $Call['Key']) + $Call['Value']); F::Run('Entity', 'Update', $Call, ['Data' => $Data]); $Call['Output']['Content'][] = 'OK'; } $Call = F::Hook('afterIncreaseDo', $Call); return $Call; });
<?php /* Codeine * @author bergstein@trickyplan.com * @description * @package Codeine * @version 7.0 */ setFn('Parse', function ($Call) { foreach ($Call['Parsed'][0] as $Ix => $Match) { $Round = simplexml_load_string($Match); // FIXME Абстрагировать этот пиздец $Call['Output'] = str_replace($Call['Parsed'][0][$Ix], round((double) $Round, (int) $Round->attributes()->precision), $Call['Output']); } return $Call; });
<?php /* Codeine * @author bergstein@trickyplan.com * @description * @package Codeine * @version 8.x */ setFn('Process', function ($Call) { $Call['Value'] = preg_replace('/\\(r\\)/', '®', $Call['Value']); return $Call; });
setFn('Write', function ($Call) { if (isset($Call['Link'])) { } else { $Call['Link'] = F::Run(null, 'Open', $Call); } self::$_Perfect = false; if (isset($Call['From'])) { $Screen = $Call['From']; } elseif (isset($Call['Project']['Title'])) { $Screen = $Call['Project']['Title'] . ' <' . $Call['Username'] . '>'; } else { $Screen = 'Codeine <' . $Call['Username'] . '>'; } $Call['Headers']['From'] = $Screen; $Call['Headers']['To'] = $Call['Scope']; $Call['Headers']['Subject'] = $Call['Where']['ID']; $mime = new Mail_mime(); // Setting the body of the email $mime->setParam('html_charset', 'utf-8'); $mime->setParam('text_charset', 'utf-8'); $mime->setParam('head_charset', 'utf-8'); if (is_array($Call['Data'])) { $Call['Data'] = implode(PHP_EOL, $Call['Data']); } if (isset($Call['HTML Mail']) && $Call['HTML Mail']) { $mime->setHTMLBody($Call['Data']); $Call['Headers']['Content-Type'] = 'text/html; charset=utf-8'; } else { $mime->setTXTBody(strip_tags($Call['Data'])); } $Call['Data'] = $mime->get(['text_charset' => 'utf-8']); $Call['Headers'] = $mime->headers($Call['Headers']); F::Log('Sending mail "' . $Call['Where']['ID'] . '" to ' . $Call['Scope'] . ' with ' . $Call['Server'], LOG_INFO, 'Administrator'); $Result = $Call['Link']->send($Call['Scope'], $Call['Headers'], $Call['Data']); if ($Result instanceof PEAR_Error) { F::Log($Result->getMessage(), LOG_ERR, 'Administrator'); } // Temp. return $Call['Data']; });
<?php /* Codeine * @author bergstein@trickyplan.com * @description * @package Codeine * @version 8.x */ setFn('beforeIOWrite', function ($Call) { if (F::Dot($Call, 'Storages.' . $Call['Storage'] . '.Journal') == true) { F::Log([F::Dot($Call, 'Storage'), F::Dot($Call, 'Where'), F::Dot($Call, 'Data'), F::Dot($Call, 'Reason')], LOG_WARNING, 'Administrator'); } return $Call; });
/* Codeine * @author bergstein@trickyplan.com * @description: Фронт контроллер * @package Codeine * @version 8.x * @date 31.08.11 * @time 1:12 */ setFn('Run', function ($Call) { // В этом месте, практически всегда, происходит роутинг. $Call = F::Hook('beforeFrontRun', $Call); // Если передан нормальный вызов, совершаем его F::Log('Front Controlled *' . $Call['Service'] . ':' . $Call['Method'] . '* started', LOG_NOTICE); if (F::Dot($Call, 'Skip Front')) { F::Log('Front Skip Enabled', LOG_NOTICE); } else { if (F::isCall($Call['Run'])) { if (!isset($Call['Run']['Method'])) { $Call['Run']['Method'] = 'Do'; } list($Call['Service'], $Call['Method']) = [$Call['Run']['Service'], $Call['Run']['Method']]; if (isset($Call['Run']['Call'])) { F::Log($Call['Run']['Call'], LOG_INFO); } $Call = F::Live($Call['Run'], $Call); } } // А здесь - рендеринг $Call = F::Hook('afterFrontRun', $Call); return $Call; });
<?php /* Codeine * @author bergstein@trickyplan.com * @description * @package Codeine * @version 8.x */ setFn('Process', function ($Call) { if (isset($Call['Map']) && is_array($Call['Map'])) { if (preg_match_all('@var\\("(.*)"\\)@SsUu', $Call['Value'], $Pockets)) { foreach ($Pockets[1] as $IX => $Match) { if (isset($Call['Map'][$Match])) { $Call['Value'] = str_replace($Pockets[0][$IX], $Call['Map'][$Match], $Call['Value']); } } } } return $Call['Value']; });
setFn('Do', function ($Call) { $IP = $_SERVER['REMOTE_ADDR']; foreach ($Call['IP']['Headers'] as $Header) { if (isset($_SERVER['HTTP_' . $Header])) { $IP = $_SERVER['HTTP_' . $Header]; break; } } if ($IP == '127.0.0.1' && isset($Call['IP']['Pingback'])) { if (($IP = F::Run('IO', 'Read', $Call, ['Storage' => 'Cookie', 'Where' => 'DeveloperIP'])) == null) { $Pingback = F::Run('IO', 'Read', ['Storage' => 'Web', 'Where' => $Call['IP']['Pingback'], 'IO One' => true]); if (preg_match($Call['IP']['Regex'], $Pingback, $Pockets)) { $IP = $Pockets[0]; } else { $IP = '127.0.0.1'; } F::Run('IO', 'Write', $Call, ['Storage' => 'Cookie', 'Where' => 'DeveloperIP', 'Data' => $IP]); F::Log('Pingback IP: *' . $IP . '* from *' . $Call['IP']['Pingback'] . '*', LOG_INFO); } else { F::Log('Pingback IP: *' . $IP . '* from *Cookie*', LOG_INFO); } } else { if (isset($Call['IP']['Substitute'][$IP])) { F::Log('IP substituted from *' . $IP . '* to ' . $Call['IP']['Substitute'][$IP], LOG_INFO); $IP = $Call['IP']['Substitute'][$IP]; } } $Call['HTTP']['IP'] = $IP; F::Log('User IP: ' . $IP, LOG_INFO); return $Call; });
<?php /* Codeine * @author bergstein@trickyplan.com * @description * @package Codeine * @version 8.x */ setFn('Make', function ($Call) { $Call['Value'] = F::Run('View', 'Load', $Call, ['Context' => 'txt']); return $Call; });
<?php /* Codeine * @author bergstein@trickyplan.com * @description * @package Codeine * @version 8.x */ setFn('Do', function ($Call) { foreach ($Call['Terms'] as $Term) { $Call['Output']['Content'][] = ['Type' => 'Heading', 'Level' => 3, 'Value' => '<l>Project.Terms:Rule.' . $Term . '</l>']; } return $Call; }); setFn('RAW', function ($Call) { return $Call['Terms']; });
$Call['Layouts'][] = ['Scope' => 'Parser', 'ID' => 'URL']; return $Call; }); setFn('POST', function ($Call) { $Call['URL'] = $Call['Request']['Data']['URL']; $Call['Data'] = F::Run('Parser.URL', 'Parse', $Call); $Call['Output']['Content'][] = ['Type' => 'Block', 'Value' => j($Call['Data'])]; return $Call; }); setFn('Parse', function ($Call) { if ($Call['Schema'] = F::Run('Parser', 'Discovery', $Call)) { F::Log('Schema is ' . $Call['Schema'], LOG_INFO); $Schema = F::loadOptions('Parser/' . $Call['Schema']); $Call = F::Merge($Call, $Schema); $Result = F::Live($Call['Parser']['URL']['Backend'], ['Where' => ['ID' => $Call['URL']]]); $Result = array_pop($Result); $Call = F::Run('Parser', 'Do', $Call, ['Markup' => $Result]); $Slices = explode('/', $Call['Schema']); $Call['Entity'] = array_pop($Slices); $Call['Data']['Source'] = $Call['URL']; if (isset($Call['Parser']['Create']['Auto']) && $Call['Parser']['Create']['Auto']) { $Call['Data'] = F::Run('Entity', 'Create', $Call, ['One' => true]); } if (isset($Call['Data']['ID'])) { $Call = F::Run('System.Interface.HTTP', 'Redirect', $Call, ['Redirect' => '/control/' . $Call['Entity'] . '/Show/' . $Call['Data']['ID']]); } } else { $Call['Data'] = null; } return $Call['Data']; });
<?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'; } });
<?php /* Codeine * @author bergstein@trickyplan.com * @description: * @package Codeine * @version 8.x */ setFn('Read', function ($Call) { return urldecode($Call['Value']); }); setFn('Write', function ($Call) { return urlencode($Call['Value']); }); setFn('Write.Call', function ($Call) { $Call['Value'] = urlencode($Call['Value']); return $Call; });
<?php /* Codeine * @author bergstein@trickyplan.com * @description HTML Textfield Driver * @package Codeine * @version 8.x */ setFn('Make', function ($Call) { $Call['Value'] = ''; $Call['HTML'] = F::Run('View.HTML.Widget.Base', 'Make', $Call, ['Tag' => 'input', 'Type' => 'password']); return $Call; });
<?php /* Codeine * @author bergstein@trickyplan.com * @description * @package Codeine * @version 8.x */ setFn('Get', function ($Call) { return (int) shell_exec('nproc'); });
<?php /* Codeine * @author bergstein@trickyplan.com * @description * @package Codeine * @version 8.x */ setFn('Write', function ($Call) { if (isset($Call['Value']) && !empty($Call['Value'])) { $Parts = parse_url($Call['Value']); if (!isset($Parts['host'])) { $Parts['host'] = $Parts['path']; unset($Parts['path']); } $Parts['scheme'] = isset($Parts['scheme']) ? $Parts['scheme'] : 'http'; $Parts['path'] = isset($Parts['path']) ? $Parts['path'] : ''; $Parts['query'] = isset($Parts['query']) ? $Parts['query'] : ''; $Parts['fragment'] = isset($Parts['fragment']) ? $Parts['fragment'] : ''; return $Parts['scheme'] . '://' . $Parts['host'] . $Parts['path'] . $Parts['query'] . $Parts['fragment']; } else { return null; } }); setFn(['Read', 'Where'], function ($Call) { return (string) $Call['Value']; });
<?php /* Codeine * @author bergstein@trickyplan.com * @description * @package Codeine * @version 8.x */ setFn('Log', function ($Call) { if (preg_match_all('@\\$([\\.\\w]+)@', $Call['Message'], $Vars)) { foreach ($Vars[0] as $IX => $Key) { $Call['Message'] = str_replace($Key, F::Dot($Call, $Vars[1][$IX]), $Call['Message']); } } F::Log($Call['Message'], $Call['Type']); return $Call; });