* @author bergstein@trickyplan.com * @description Exec Parslet * @package Codeine * @version 8.x */ setFn('Parse', function ($Call) { foreach ($Call['Parsed'][2] as $IX => $Match) { $Root = simplexml_load_string('<root ' . $Call['Parsed'][1][$IX] . '></root>'); if ($Root->attributes()->type !== null) { $Type = (string) $Root->attributes()->type; } else { $Type = $Call['Parslet']['Exec']['Type']; } $Match = F::Run('Formats.' . $Type, 'Read', ['Value' => trim($Call['Parsed'][2][$IX])]); if ($Match) { F::Log($Match, LOG_INFO); foreach ($Call['Parslet']['Exec']['Inherited'] as $Key) { if (isset($Call[$Key])) { $Match[$Key] = $Call[$Key]; } else { $Match[$Key] = null; } } if (isset($Match['Exec TTL'])) { $RTTL = $Match['Exec TTL']; } else { $RTTL = 0; } $Application = F::Run('Code.Flow.Application', 'Run', ['RTTL' => $RTTL, 'Run' => $Match]); /*if (F::Environment() == 'Development') $Application['Output'] = '<div class="exec-cached">'.$Application['Output'].'</div>';
$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']; });
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('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('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; });
<?php /* Codeine * @author bergstein@trickyplan.com * @description * @package Codeine * @version 8.x */ setFn('Length', function ($Call) { if (isset($Call['View']['HTML']['Keywords']) && is_string($Call['View']['HTML']['Keywords'])) { $Length = mb_strlen($Call['View']['HTML']['Keywords']); if ($Length > $Call['SEO']['Audit']['Keywords']['Length']['Maximum']) { $Call = F::Hook('SEO.Audit.Keywords.TooLong', $Call); F::Log('SEO Keywords is too long *' . $Length . ' chars* over *' . $Call['SEO']['Audit']['Keywords']['Length']['Maximum'] . '*', LOG_WARNING, 'Marketing'); } elseif ($Length < $Call['SEO']['Audit']['Keywords']['Length']['Minimum']) { $Call = F::Hook('SEO.Audit.Keywords.TooShort', $Call); F::Log('SEO Keywords is too short *' . $Length . ' chars* over *' . $Call['SEO']['Audit']['Keywords']['Length']['Minimum'] . '*', LOG_WARNING, 'Marketing'); } else { F::Log('SEO Keywords length is optimal ', LOG_NOTICE, 'Marketing'); } } return $Call; });
<?php /* Codeine * @author bergstein@trickyplan.com * @description * @package Codeine * @version 7.x */ setFn('Do', function ($Call) { $Command = 'jpegoptim ' . $Call['Image']['Cached Filename'] . ' --strip-all'; F::Log($Command, LOG_INFO); F::Log(shell_exec($Command), LOG_INFO); return $Call; });
if ($Call['JS']['Compress']['JSMin']['Enabled']) { $Pipes = []; $JSMinCompressor = proc_open($Call['JS']['Compress']['JSMin']['Command'], $Call['JS']['Compress']['JSMin']['Descriptors'], $Pipes); if (is_resource($JSMinCompressor)) { if ($Call['JS']['Compress']['JSMin']['Expose']) { $Compressed = '// JSMin Compressed' . PHP_EOL; } else { $Compressed = ''; } fwrite($Pipes[0], $Call['JS']['Source']); fclose($Pipes[0]); $Compressed .= trim(stream_get_contents($Pipes[1])); fclose($Pipes[1]); if (($Code = proc_close($JSMinCompressor)) == 0) { $Call['JS']['Source'] = $Compressed; F::Log('[JSMin] ' . $Call['JS']['Fullpath'] . ' compressed', LOG_DEBUG); } else { F::Log('[JSMin] ' . $Call['JS']['Fullpath'] . ' not compressed', LOG_INFO); F::Log('Return code for ' . $Call['JS']['Compress']['JSMin']['Command'] . ': ' . $Code, LOG_DEBUG); if ($Call['JS']['Compress']['JSMin']['Disable On Error']) { $Call['JS']['Compress']['JSMin']['Enabled'] = false; // Codeine Magic: Dynamic Reconfiguration FGJ F::Log('[JSMin] Disabled by error', LOG_INFO); } } } else { F::Log('[JSMin] Not resource', LOG_WARNING); } } return $Call; });
<?php /* Codeine * @author bergstein@trickyplan.com * @description * @package Codeine * @version 8.x */ setFn('Run', function ($Call) { if (sys_getloadavg()[0] > $Call['Throttler']['CPU Limit']) { F::Run('System.Sleep', 'Do', ['Seconds' => $Call['Throttler']['Seconds']]); F::Log('Throttled on ' . $Call['Throttler']['Seconds'] . ' seconds', LOG_INFO); } return $Call; });
* @description * @package Codeine * @version 8.x */ setFn('Do', function ($Call) { $Call['User Agents'] = ["Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.93 Safari/537.36", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.93 Safari/537.36", "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.93 Safari/537.36", "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.93 Safari/537.36", "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:25.0) Gecko/20100101 Firefox/25.0", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:25.0) Gecko/20100101 Firefox/25.0", "Opera/9.80 (Windows NT 6.0) Presto/2.12.388 Version/12.14", "Mozilla/5.0 (Windows NT 6.0; rv:2.0) Gecko/20100101 Firefox/4.0 Opera 12.14", "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.0) Opera 12.14", "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)", "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)", "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/5.0)", "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/4.0; InfoPath.2; SV1; .NET CLR 2.0.50727; WOW64)", "Mozilla/5.0 (compatible; MSIE 10.0; Macintosh; Intel Mac OS X 10_7_3; Trident/6.0)", "Mozilla/5.0 (Windows; U; MSIE 9.0; WIndows NT 9.0; en-US))", "Mozilla/5.0 (Windows; U; MSIE 9.0; Windows NT 9.0; en-US)", "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 7.1; Trident/5.0)", "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0", "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0; chromeframe/13.0.782.215)", "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0; chromeframe/11.0.696.57)", "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0) chromeframe/10.0.648.205", "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/4.0; GTB7.4; InfoPath.1; SV1; .NET CLR 2.8.52393; WOW64; en-US)", "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.0; Trident/5.0; chromeframe/11.0.696.57)"]; if (file_exists(Root . '/proxy_http_ip.txt')) { F::Log(Root . '/proxy_http_ip.txt detected ', LOG_WARNING); $List = file(Root . '/proxy_http_ip.txt'); foreach ($List as $Line) { if (!empty($Line)) { $Call['Proxies'][] = trim($Line); } } F::Log(count($Call['Proxies']) . ' proxies loaded', LOG_WARNING); } foreach ($Call['Proxies'] as $Proxy) { F::Log($Proxy, LOG_WARNING); $Call['Proxy'] = []; list($Call['Proxy']['Host'], $Call['Proxy']['Port']) = explode(':', $Proxy); $Call['Agent'] = $Call['User Agents'][array_rand($Call['User Agents'])]; F::Log('UA: ' . $Call['Agent'] . ' selected', LOG_WARNING); F::Log($Call['URL'] . ' fetching', LOG_WARNING); $MT = microtime(true); $Result = F::Run('IO', 'Read', $Call, ['No Memo' => true, 'Storage' => 'Web', 'Where' => $Call['URL']]); $Call['Body'] = array_pop($Result); F::Log($Call['URL'] . ' fetched by ' . round((microtime(true) - $MT) * 1000) . ' ms', LOG_WARNING); sleep(rand(0, 6)); } return $Call; });
} else { $Result = null; } } return $Result; }); setFn('Access Token', function ($Call) { $Result = null; if (isset($Call['Data']['Facebook']['Auth'])) { F::Log('Using FB Token from Data', LOG_INFO); $Result['Auth'] = $Call['Data']['Facebook']['Auth']; } elseif (isset($Call['Session']['User']['Facebook']['Auth'])) { F::Log('Using FB Token from Session', LOG_INFO); $Result['Auth'] = $Call['Session']['User']['Facebook']['Auth']; } else { F::Log('Using FB Token from random users', LOG_INFO); $Donor = F::Run('Entity', 'Read', ['Entity' => 'User', 'Where' => ['Facebook.Active' => true], 'Limit' => ['From' => 0, 'To' => 1], 'Sort' => ['Modified' => false], 'One' => true]); $Result = $Donor['Facebook']; if (isset($Result['Expire']) && $Result['Expire'] > time()) { } elseif (isset($Result['Auth'])) { $URL = 'https://graph.facebook.com/oauth/access_token'; $ResultFB = F::Run('IO', 'Read', ['Storage' => 'Web', 'Where' => $URL, 'Data' => ['client_id' => $Call['Facebook']['AppID'], 'client_secret' => $Call['Facebook']['Secret'], 'grant_type' => 'fb_exchange_token', 'fb_exchange_token' => $Result['Auth']]]); if ((array) $ResultFB === $ResultFB) { $ResultFB = array_pop($ResultFB); parse_str($ResultFB, $ResultFB); } if (isset($ResultFB['access_token'])) { F::Run('Entity', 'Update', ['Entity' => 'User', 'Where' => ['Facebook.ID' => $Result['ID']], 'Data' => ['Facebook' => ['Auth' => $ResultFB['access_token'], 'Expire' => time() + $ResultFB['expires']]], 'No' => ['beforeEntityWrite' => true], 'One' => true]); F::Run('Code.Run.Delayed', 'Run', ['Delayed Mode' => 'Dirty', 'Run' => ['Service' => 'Entity', 'Method' => 'Update', 'Call' => ['Entity' => 'User', 'Where' => ['Facebook.ID' => $Result['ID']], 'Data' => ['Facebook' => ['Auth' => $ResultFB['access_token'], 'Expire' => time() + $ResultFB['expires']]], 'No' => ['beforeEntityWrite' => true]]]]); $Result['Auth'] = $ResultFB['access_token']; $Result['Expire'] = $ResultFB['expires'];
<?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; });
<?php /* Codeine * @author bergstein@trickyplan.com * @description * @package Codeine * @version 8.x */ setFn('Do', function ($Call) { if (isset($Call['Current Image']['Thumb']) && !empty($Call['Current Image']['Data'])) { try { $GImage = new Gmagick(); $GImage->readimageblob($Call['Current Image']['Data']); /* $GImage->setCompressionQuality($Call['Image']['Quality']);*/ if (!isset($Call['Current Image']['Height'])) { $Call['Current Image']['Height'] = ceil($Call['Current Image']['Width'] / $GImage->getimagewidth() * $GImage->getimageheight()); } if (!isset($Call['Current Image']['Width'])) { $Call['Current Image']['Width'] = ceil($Call['Current Image']['Height'] / $GImage->getimageheight() * $GImage->getimagewidth()); } $GImage->cropthumbnailimage($Call['Current Image']['Width'], $Call['Current Image']['Height']); $Call['Current Image']['Data'] = $GImage->getImageBlob(); } catch (Exception $e) { F::Log($e->getMessage(), LOG_ERR); F::Log($Call['Current Image'], LOG_ERR); } } return $Call; });
<?php /* Codeine * @author bergstein@trickyplan.com * @description * @package Codeine * @version 8.x */ setFn('Do', function ($Call) { if (isset($Call['Current Image']['Resample']) && !empty($Call['Current Image']['Data'])) { try { $GImage = new Gmagick(); $GImage->readimageblob($Call['Current Image']['Data']); if (isset($Call['Current Image']['Height'])) { } else { $Call['Current Image']['Height'] = ceil($Call['Current Image']['Width'] / $GImage->getimagewidth() * $GImage->getimageheight()); } if (isset($Call['Current Image']['Width'])) { } else { $Call['Current Image']['Width'] = ceil($Call['Current Image']['Height'] / $GImage->getimageheight() * $GImage->getimagewidth()); } $GImage->resizeImage($Call['Current Image']['Width'], $Call['Current Image']['Height'], Gmagick::FILTER_LANCZOS, 1); $Call['Current Image']['Data'] = $GImage->getImageBlob(); } catch (Exception $e) { F::Log($e->getMessage(), LOG_ERR); } } return $Call; });
* @package Codeine * @version 8.x */ setFn('Do', function ($Call) { if (isset($_SERVER['HTTPS']) && !empty($_SERVER['HTTPS']) or isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' or isset($_SERVER['HTTP_X_HTTPS']) && $_SERVER['HTTP_X_HTTPS']) { $Call['HTTP']['Proto'] = 'https://'; } else { $Call['HTTP']['Proto'] = 'http://'; } if (isset($Call['HTTP']['Force SSL']) && $Call['HTTP']['Force SSL']) { if ($Call['HTTP']['Proto'] !== 'https://') { $Call = F::Run('System.Interface.HTTP', 'Remote Redirect', $Call, ['Redirect' => 'https://' . $Call['HTTP']['Host'] . $Call['HTTP']['URI']]); } if (isset($Call['HTTP']['HSTS']['Enabled']) && $Call['HTTP']['HSTS']['Enabled']) { $Header = 'max-age=' . $Call['HTTP']['HSTS']['Expire']; if (isset($Call['HTTP']['HSTS']['Subdomains']) && $Call['HTTP']['HSTS']['Subdomains']) { $Header .= '; includeSubdomains'; } if (isset($Call['HTTP']['HSTS']['Preload']) && $Call['HTTP']['HSTS']['Preload']) { $Header .= '; preload'; } $Call['HTTP']['Headers']['Strict-Transport-Security:'] = $Header; } } if (empty($Call['HTTP']['Proto'])) { F::Log('Protocol is *empty*!', LOG_INFO); } else { F::Log('Protocol is *' . $Call['HTTP']['Proto'] . '*', LOG_INFO); } return $Call; });
<?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 * @date 31.08.11 * @time 6:17 */ setFn('Route', function ($Call) { if (isset($Call['Static'])) { } else { $Call['Static'] = $Call['Links']; // FIXME F::Log('«Links» now «Static», please replace', LOG_WARNING); } if (strpos($Call['Run'], '?')) { list($Call['Run']) = explode('?', $Call['Run']); } if (isset($Call['Static'])) { if (is_string($Call['Run']) && isset($Call['Static'][$Call['Run']])) { if (isset($Rule['Debug']) && $Rule['Debug'] === true) { d(__FILE__, __LINE__, $Rule); } $Call['Run'] = $Call['Static'][$Call['Run']]; } } unset($Call['Static']); return $Call; });
<?php /* Codeine * @author bergstein@trickyplan.com * @description * @package Codeine * @version 8.x */ setFn('Do', function ($Call) { if (isset($Call['Service']) && $Call['View']['Renderer'] == 'View.HTML') { if (in_array($Call['Service'], $Call['No SEO Audit'])) { F::Log('SEO Audit skipped', LOG_INFO, 'Marketing'); } else { if (isset($Call['View']['HTML']) && !isset($Call['Headers']['Location:'])) { foreach ($Call['Auditors'] as $Auditor) { $Call = F::Live($Auditor, $Call); } } } } return $Call; });
F::Log('Error accepting connection', LOG_ERR); } else { F::Log('Socket ready to connect', LOG_INFO); $Request = ''; $Output = 'HTTP/1.1 200 OK'; do { if (false === ($Buffer = socket_read($Message, 1024))) { F::Log('Error reading socket', LOG_ERR); } else { $Request .= $Buffer; if (empty(trim($Buffer))) { F::Log('Message received', LOG_INFO); $Headers = http_parse_headers($Request); print_r($Headers); print_r($Request); /* $Call['UA'] = $Headers['User-Agent']; $Call['HTTP']['URL'] = $Headers['Request Url'];*/ /* $Call = F::Run('Code.Flow.Front', 'Run', $Call);*/ socket_write($Socket, $Output . chr(0), 64); break; } } } while (true); } } while (true); if (isset($Scoket)) { socket_close($Socket); F::Log('Socket closed', LOG_INFO); } return $Call; });
} else { $Table[] = ['<l>' . $Call['Entity'] . '.Entity:' . $Name . '</l>', $OldValue, $NewValue]; } } $Call['Output']['Content'][] = ['Type' => 'Table', 'Value' => $Table]; } $Call['Output']['Content'][] = ['Type' => 'Block', 'Class' => 'alert alert-success', 'Value' => count($New) . ' object touched']; } $Call = F::Hook('afterTouch', $Call); return $Call; }); setFn('All', function ($Call) { $Call = F::Apply('Entity', 'Load', $Call); $Total = F::Run('Entity', 'Count', $Call); $Amount = ceil($Total / $Call['All']['Limit']); set_time_limit(10 * $Total); $Call = F::Apply('Code.Progress', 'Start', $Call); $Call['Progress']['Max'] = $Amount; for ($i = 0; $i < $Amount; $i++) { F::Run('Entity', 'Update', ['Entity' => $Call['Entity'], 'Where' => $Call['Where'], 'Data' => [], 'One' => false, 'Limit' => ['From' => $i * $Call['All']['Limit'], 'To' => ($i + 1) * $Call['All']['Limit']]]); $Call['Progress']['Now']++; $Call = F::Apply('Code.Progress', 'Log', $Call); F::Log('Touch Iteration № ' . ($i + 1) / $Amount, LOG_NOTICE); } $Call = F::Apply('Code.Progress', 'Finish', $Call); $Call['Output']['Content'][] = $Total . ' elements processed'; return $Call; }); setFn('Test', function ($Call) { F::Run(null, "All", $Call, ['Entity' => 'User', 'Where' => ['ID' => ['$gt' => 3]], 'Live Fields' => ['VKontakte.DOB']]); });
<?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; });
<?php /* Codeine * @author bergstein@trickyplan.com * @description * @package Codeine * @version 8.x */ setFn('Detect', function ($Call) { $GeoIP = F::Run('System.GeoIP', 'LatLon', ['Value' => F::Run('System.Interface.HTTP.IP', 'Get')]); if (isset($GeoIP['Lat'])) { $Call['Session']['Lat'] = $GeoIP['Lat']; $Call['Session']['Long'] = $GeoIP['Lon']; $Cities = F::Run('Entity', 'Read', ['Entity' => 'Location']); $Sorted = []; foreach ($Cities as $Location) { $Sorted[$Location['ID']] = F::Run('Science.Geography.Distance', 'Calc', ['From' => $Call['Session'], 'To' => $Location]); F::Log('Distance to ' . $Location['Title'] . ' is ' . $Sorted[$Location['ID']] . ' km', LOG_INFO); } asort($Sorted); list($DeterminedLocation) = each($Sorted); F::Log('Location determined', LOG_INFO); } else { $DeterminedLocation = 1; } return $DeterminedLocation; });
<?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; });
<?php /* Codeine * @author bergstein@trickyplan.com * @description * @package Codeine * @version 8.x */ setFn('Length', function ($Call) { if (isset($Call['View']['HTML']['Title']) && is_string($Call['View']['HTML']['Title'])) { $Length = mb_strlen($Call['View']['HTML']['Title']); if ($Length > $Call['SEO']['Audit']['Title']['Length']['Maximum']) { $Call = F::Hook('SEO.Audit.Title.TooLong', $Call); F::Log('SEO Title is too long *' . $Length . ' chars* over *' . $Call['SEO']['Audit']['Title']['Length']['Maximum'] . '*', LOG_WARNING, 'Marketing'); } elseif ($Length < $Call['SEO']['Audit']['Title']['Length']['Minimum']) { $Call = F::Hook('SEO.Audit.Title.TooShort', $Call); F::Log('SEO Title is too short *' . $Length . ' chars* over *' . $Call['SEO']['Audit']['Title']['Length']['Minimum'] . '*', LOG_WARNING, 'Marketing'); } else { F::Log('SEO Title length is optimal ', LOG_NOTICE, 'Marketing'); } } return $Call; });
setFn('Do', function ($Call) { return F::Run(null, $Call['HTTP']['Method'], $Call); }); setFn('GET', function ($Call) { $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 {
F::Log('Test: Developer Error', LOG_ERR, 'Developer'); F::Log('Test: Developer Critical', LOG_CRIT, 'Developer'); F::Log('Test: Developer Alert', LOG_ALERT, 'Developer'); F::Log('Test: Developer Emergency', LOG_EMERG, 'Developer'); F::Log('Test: Administrator Info', LOG_INFO, 'Administrator'); F::Log('Test: Administrator Warning', LOG_WARNING, 'Administrator'); F::Log('Test: Administrator Error', LOG_ERR, 'Administrator'); F::Log('Test: Administrator Critical', LOG_CRIT, 'Administrator'); F::Log('Test: Administrator Alert', LOG_ALERT, 'Administrator'); F::Log('Test: Administrator Emergency', LOG_EMERG, 'Administrator'); F::Log('Test: Security Info', LOG_INFO, 'Security'); F::Log('Test: Security Warning', LOG_WARNING, 'Security'); F::Log('Test: Security Error', LOG_ERR, 'Security'); F::Log('Test: Security Critical', LOG_CRIT, 'Security'); F::Log('Test: Security Alert', LOG_ALERT, 'Security'); F::Log('Test: Security Emergency', LOG_EMERG, 'Security'); F::Log('Test: Marketing Info', LOG_INFO, 'Marketing'); F::Log('Test: Marketing Warning', LOG_WARNING, 'Marketing'); F::Log('Test: Marketing Error', LOG_ERR, 'Marketing'); F::Log('Test: Marketing Critical', LOG_CRIT, 'Marketing'); F::Log('Test: Marketing Alert', LOG_ALERT, 'Marketing'); F::Log('Test: Marketing Emergency', LOG_EMERG, 'Marketing'); F::Log('Test: Performance Info', LOG_INFO, 'Performance'); F::Log('Test: Performance Warning', LOG_WARNING, 'Performance'); F::Log('Test: Performance Error', LOG_ERR, 'Performance'); F::Log('Test: Performance Critical', LOG_CRIT, 'Performance'); F::Log('Test: Performance Alert', LOG_ALERT, 'Performance'); F::Log('Test: Performance Emergency', LOG_EMERG, 'Performance'); $Call['Output']['Content'][] = 'Test executed'; 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('beforeLocaleDetect', function ($Call) { foreach ($Call['Locales']['Available'] as $Locale) { if (preg_match('@/' . $Locale . '/@', $Call['HTTP']['URL'])) { $Call['HTTP']['URL'] = str_replace('/' . $Locale, '', $Call['HTTP']['URL']); $Call['HTTP']['URI'] = str_replace('/' . $Locale, '', $Call['HTTP']['URI']); $Call['Run'] = str_replace('/' . $Locale, '', $Call['HTTP']['URI']); $Call['Locale'] = $Locale; F::Log('Locale detected by path: *' . $Locale . '*', LOG_INFO); } } return $Call; });
<?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 * @package Codeine * @version 8.x */ setFn('Do', function ($Call) { if (is_numeric($Call['Value'])) { return number_format($Call['Value'], $Call['Digits'], ',', ' '); } else { F::Log('Bad number format: *' . $Call['Value'] . '*', LOG_WARNING); return $Call['Value']; } });