/** * @ignore */ public function compile($uHeaders = true) { $tString = ""; $tBody = $this->compileBody(); if ($uHeaders) { $tHeaders =& $this->headers; if (!isset($tHeaders['Content-Id'])) { $tHeaders['Content-Id'] = '<' . String::generate(15) . '>'; } if (!isset($tHeaders['Content-Type'])) { $tHeaders['Content-Type'] = $this->type; } if (!isset($tHeaders['Content-Transfer-Encoding'])) { $tHeaders['Content-Transfer-Encoding'] = $this->transferEncoding; } if (!isset($tHeaders['Content-Disposition']) && strlen($this->filename) > 0) { $tHeaders['Content-Disposition'] = 'attachment; filename=' . $this->filename; } if (!isset($tHeaders['Content-Length'])) { $tHeaders['Content-Length'] = strlen($tBody); } foreach ($tHeaders as $tKey => $tValue) { $tString .= $tKey . ': ' . $tValue . "\n"; } for ($i = $this->linesAfterHeaders; $i > 0; $i--) { $tString .= "\n"; } } $tString .= $tBody; return $tString; }
/** * @ignore */ public static function output($uParms) { if (Request::$wrapperFunction === 'laroux.js') { if (Http::sentHeaderValue('Content-Type') === false) { header('Content-Type: application/json', true); } header('X-Response-Wrapper-Function: laroux.js', true); $uParms['content'] = '{ "isSuccess": ' . ($uParms['exitStatus'][0] > 0 ? 'false' : 'true') . ', "errorMessage": ' . ($uParms['exitStatus'] === null ? 'null' : String::dquote($uParms['exitStatus'][1], true)) . ', "format": ' . String::dquote($uParms['responseFormat'], true) . ', "object": ' . json_encode($uParms['content']) . ' }'; } }
/** * @ignore */ public function __construct($uField, $uDefaultValue = null) { if (String::endsWith($uField, '[]')) { $this->field = String::substr($uField, 0, -2); $this->isArray = true; } else { $this->field = $uField; $this->isArray = false; } $this->defaultValue = $uDefaultValue; }
/** * @ignore */ public function query($uQuery, array $uParameters = array(), $uCaching = null, $uModifies = false, $uSequence = null) { $this->connectionOpen(); $tPreDebugInfo = array('query' => $uQuery, 'parameters' => $uParameters); if (Framework::$development) { if ($uModifies) { $this->beginTransaction(); } if (!$uModifies || $this->explainOnModifies) { $tPreDebugInfo['explain'] = $this->queryArray(String::format($this->explainCommand, array('query' => $uQuery)), $uParameters); } if ($uModifies) { $this->rollBack(); } } $this->logger->profilerStart($this->id . ' query', 'query', $tPreDebugInfo); if (!Framework::$disableCaches && $uCaching !== null) { $tCaching = (array) $uCaching; if (!isset($tCaching[1])) { $tOld = array_merge((array) $uQuery, $uParameters); } else { $tOld = (array) $tCaching[1]; } if (!isset($tCaching[2])) { $tCaching[2] = 0; } $tCaching[1] = $this->id; $tCount = 0; foreach ($tOld as $tParameter) { $tCaching[1] .= ($tCount++ === 0 ? '/' : '_') . hash('adler32', $tParameter); } $tData = Datasources::get($tCaching[0])->cacheGet($tCaching[1]); if ($tData !== false) { $this->cache[$tCaching[1]] = $tData->resume($this); $tLoadedFromCache = true; } else { $tLoadedFromCache = false; } } else { $tCaching = null; $tData = false; $tLoadedFromCache = false; } if ($tData === false) { $tData = new DatabaseQueryResult($uQuery, $uParameters, $this, $tCaching, $uSequence); ++$this->stats['query']; } else { ++$this->stats['cache']; } //! affected rows $tPostDebugInfo = array('affectedRows' => $tData->count(), 'fromCache' => $tLoadedFromCache); $this->logger->profilerStop($tPostDebugInfo); return $tData; }
/** * @ignore */ public static function getType($uExtension, $uDefault = 'application/octet-stream') { $tExtension = String::toLower($uExtension); if ($tExtension === 'pdf') { return 'application/pdf'; } elseif ($tExtension === 'exe') { return 'application/octet-stream'; } elseif ($tExtension === 'dll') { return 'application/x-msdownload'; } elseif ($tExtension === 'zip') { return 'application/zip'; } elseif ($tExtension === 'rar') { return 'application/x-rar-compressed'; } elseif ($tExtension === 'gz' || $tExtension === 'gzip' || $tExtension === 'tgz') { return 'application/x-gzip'; } elseif ($tExtension === 'tar') { return 'application/x-tar'; } elseif ($tExtension === 'jar') { return 'application/java-archive'; } elseif ($tExtension === 'deb') { return 'application/x-deb'; } elseif ($tExtension === 'deb') { return 'application/x-apple-diskimage'; } elseif ($tExtension === 'deb') { return 'text/csv'; } elseif ($tExtension === 'txt' || $tExtension === 'text' || $tExtension === 'log' || $tExtension === 'ini') { return 'text/plain'; } elseif ($tExtension === 'rtf') { return 'text/rtf'; } elseif ($tExtension === 'odt') { return 'application/vnd.oasis.opendocument.text'; } elseif ($tExtension === 'smil') { return 'application/smil'; } elseif ($tExtension === 'eml') { return 'message/rfc822'; } elseif ($tExtension === 'xml' || $tExtension === 'xsl') { return 'text/xml'; } elseif ($tExtension === 'doc' || $tExtension === 'dot' || $tExtension === 'word') { return 'application/msword'; } elseif ($tExtension === 'docx' || $tExtension === 'dotx') { return 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'; } elseif ($tExtension === 'xls') { return 'application/vnd.ms-excel'; } elseif ($tExtension === 'xl') { return 'application/excel'; } elseif ($tExtension === 'xlsx') { return 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'; } elseif ($tExtension === 'ppt') { return 'application/vnd.ms-powerpoint'; } elseif ($tExtension === 'ics') { return 'text/calendar'; } elseif ($tExtension === 'bmp') { return 'image/x-ms-bmp'; } elseif ($tExtension === 'gif') { return 'image/gif'; } elseif ($tExtension === 'png') { return 'image/png'; } elseif ($tExtension === 'jpeg' || $tExtension === 'jpe' || $tExtension === 'jpg') { return 'image/jpeg'; } elseif ($tExtension === 'webp') { return 'image/webp'; } elseif ($tExtension === 'tif' || $tExtension === 'tiff') { return 'image/tiff'; } elseif ($tExtension === 'psd') { return 'image/vnd.adobe.photoshop'; } elseif ($tExtension === 'ai' || $tExtension === 'eps' || $tExtension === 'ps') { return 'application/postscript'; } elseif ($tExtension === 'cdr') { return 'application/cdr'; } elseif ($tExtension === 'mid' || $tExtension === 'midi') { return 'audio/midi'; } elseif ($tExtension === 'mpga' || $tExtension === 'mp2' || $tExtension === 'mp3') { return 'audio/mpeg'; } elseif ($tExtension === 'aif' || $tExtension === 'aiff' || $tExtension === 'aifc') { return 'audio/x-aiff'; } elseif ($tExtension === 'wav') { return 'audio/x-wav'; } elseif ($tExtension === 'aac') { return 'audio/aac'; } elseif ($tExtension === 'ogg') { return 'audio/ogg'; } elseif ($tExtension === 'wma') { return 'audio/x-ms-wma'; } elseif ($tExtension === 'm4a') { return 'audio/x-m4a'; } elseif ($tExtension === 'mpeg' || $tExtension === 'mpg' || $tExtension === 'mpe') { return 'video/mpeg'; } elseif ($tExtension === 'mp4' || $tExtension === 'f4v') { return 'application/mp4'; } elseif ($tExtension === 'qt' || $tExtension === 'mov') { return 'video/quicktime'; } elseif ($tExtension === 'avi') { return 'video/x-msvideo'; } elseif ($tExtension === 'wmv') { return 'video/x-ms-wmv'; } elseif ($tExtension === 'webm') { return 'video/webm'; } elseif ($tExtension === 'swf') { return 'application/x-shockwave-flash'; } elseif ($tExtension === 'flv') { return 'video/x-flv'; } elseif ($tExtension === 'htm' || $tExtension === 'html' || $tExtension === 'shtm' || $tExtension === 'shtml') { return 'text/html'; } elseif ($tExtension === 'php') { return 'application/x-httpd-php'; } elseif ($tExtension === 'phps') { return 'application/x-httpd-php-source'; } elseif ($tExtension === 'css') { return 'text/css'; } elseif ($tExtension === 'js') { return 'application/x-javascript'; } elseif ($tExtension === 'json') { return 'application/json'; } elseif ($tExtension === 'c' || $tExtension === 'h') { return 'text/x-c'; } elseif ($tExtension === 'py') { return 'application/x-python'; } elseif ($tExtension === 'sh') { return 'text/x-shellscript'; } elseif ($tExtension === 'pem') { return 'application/x-x509-user-cert'; } elseif ($tExtension === 'crt' || $tExtension === 'cer') { return 'application/x-x509-ca-cert'; } elseif ($tExtension === 'pgp') { return 'application/pgp'; } elseif ($tExtension === 'gpg') { return 'application/gpg-keys'; } return $uDefault; }
/** * @ignore */ public function orWhere($uCondition, $uList = null, $uKeyword = 'AND') { if (is_array($uCondition)) { if (count($uCondition) > 0) { if (strlen($this->where) > 0) { $this->where .= ' OR '; } $this->where .= '(' . implode(' ' . $uKeyword . ' ', $uCondition) . ')'; } } else { if (strlen($this->where) > 0) { $this->where .= ' OR '; } $this->where .= $uCondition; if ($uList !== null) { $this->where .= ' (' . implode(', ', String::squoteArray($uList, true)) . ')'; } } return $this; }
/** * Generates and outputs a captcha image * * @param string $uCookieName name of the cookie which will be stored on the client side * * @return string generated captcha code */ public static function generate($uCookieName = 'captcha') { $tFontFile = Io::translatePath(Config::get('captcha/fontFile', '{core}resources/fonts/KabobExtrabold.ttf')); $tFontSize = (int) Config::get('captcha/fontSize', 45); $tLength = (int) Config::get('captcha/length', 8); // pick a random word $tCode = String::generatePassword($tLength); // create a random gray shade $tColorScale = rand(40, 120); // allocate the image and colors $tImageCanvas = imagecreatetruecolor(300, 80); $tColorBackground = imagecolorallocate($tImageCanvas, 255, 255, 255); $tColorBackgroundChars = imagecolorallocatealpha($tImageCanvas, $tColorScale, $tColorScale, $tColorScale, 80); $tColorTextShadow = imagecolorallocatealpha($tImageCanvas, 255, 255, 255, 20); $tColorText = imagecolorallocatealpha($tImageCanvas, $tColorScale + 25, $tColorScale + 10, $tColorScale + 10, 30); // clear the background imagefilledrectangle($tImageCanvas, 0, 0, 300, 80, $tColorBackground); // create the background letters $tBackgroundChars = 'abcdefghijklmnopqrstuvwxyz'; for ($i = 0; $i < rand(60, 120); $i++) { // randomize the place and angle $x = rand(-50, 300); $y = rand(-50, 80); $tAngle = rand(-90, 90); imagettftext($tImageCanvas, $tFontSize, $tAngle, $x, $y, $tColorBackgroundChars, $tFontFile, $tBackgroundChars[rand(0, strlen($tBackgroundChars) - 1)]); } // randomize the start of the code $x = 50 + rand(-40, 30 - (strlen($tCode) - 6) * 24); $y = 56 + rand(-8, 8); // write the code letter-by-letter for ($i = 0; $i < strlen($tCode); $i++) { // angle is random $tAngle = rand(-10, 10); // create the shadow for the letter for ($ax = -1; $ax < 0; $ax++) { for ($ay = -1; $ay < 0; $ay++) { imagettftext($tImageCanvas, $tFontSize, $tAngle, $x + $ax, $y + $ay, $tColorTextShadow, $tFontFile, $tCode[$i]); } } // create the letter imagettftext($tImageCanvas, $tFontSize, $tAngle, $x, $y, $tColorText, $tFontFile, $tCode[$i]); // calculate the place of the next letter $y += rand(-2, 2); $tTemp = imagettfbbox($tFontSize, 0, $tFontFile, $tCode[$i]); $x += $tTemp[2] + rand(-4, 0); } // fancy border imagerectangle($tImageCanvas, 0, 0, 299, 79, $tColorText); imagerectangle($tImageCanvas, 1, 1, 298, 78, $tColorBackground); // store the code in session Session::set($uCookieName, $tCode); // try to avoid caching header('Expires: Thu, 01 Jan 1970 00:00:00 GMT', true); header('Pragma: public', true); header('Cache-Control: no-store, no-cache, must-revalidate', true); header('Cache-Control: pre-check=0, post-check=0, max-age=0'); header('Content-Type: image/png', true); header('Content-Disposition: inline;filename=' . $uCookieName . '.png', true); // clean up imagepng($tImageCanvas); imagedestroy($tImageCanvas); // return the code return $tCode; }
/** * @ignore */ public function export($tOutput = true) { return String::vardump($this->testReport, $tOutput); }
/** * @ignore */ public static function export($tOutput = true) { if (self::$data === null) { self::open(); } return String::vardump(self::$data, $tOutput); }
/** * @ignore */ public static function edit($uAction, $uSlug) { Auth::checkRedirect('editor'); $tModule = AutoModels::get(Panel::$module); $tViewbag = array('module' => $tModule, 'fields' => array()); if (Request::$method === 'post') { //! todo: validations Validation::addRule('name')->isRequired()->errorMessage('Name shouldn\'t be blank.'); // Validation::addRule('slug')->isRequired()->errorMessage('Slug shouldn\'t be blank.'); if (Validation::validate($_POST)) { $tSlug = Request::post('slug', ""); if (strlen(rtrim($tSlug)) === 0) { $tSlug = Request::post('name', ""); } $tInput = array('type' => Request::post('type'), 'name' => Request::post('name'), 'slug' => String::slug(String::removeAccent($tSlug))); $tAutoModel = new AutoModel('categories'); $tAutoModel->update($uSlug, $tInput); Session::set('notification', array('info', 'ok-sign', 'Record modified.')); Http::redirect('panel/categories'); return; } Session::set('notification', array('error', 'remove-sign', Validation::getErrorMessages(true))); foreach ($tModule['fieldList'] as $tField) { $tIsView = array_key_exists('view', $tField['methods']); $tIsEdit = array_key_exists('edit', $tField['methods']); if ($tIsView || $tIsEdit) { if ($tField['type'] === 'enum') { $tTypes = array(); foreach ($tField['valueList'] as $tValue) { $tTypes[$tValue['name']] = $tValue['title']; } $tAttributes = array('name' => $tField['name'], 'class' => 'input-block-level input_' . $tField['type']); if (!$tIsEdit) { $tAttributes['readonly'] = 'readonly'; } $tTag = '<p>' . I18n::_($tField['title']) . ': ' . Html::tag('select', $tAttributes, Html::selectOptions($tTypes, Request::post($tField['name'], null))) . '</p>'; } else { $tAttributes = array('type' => 'text', 'name' => $tField['name'], 'value' => Request::post($tField['name'], ""), 'class' => 'input-block-level input_' . $tField['type']); if (!$tIsEdit) { $tAttributes['readonly'] = 'readonly'; } $tTag = '<p>' . I18n::_($tField['title']) . ': ' . Html::tag('input', $tAttributes) . '</p>'; } } $tViewbag['fields'][] = array('data' => $tField, 'html' => $tTag); } Views::viewFile('{core}views/panel/models/form.php', $tViewbag); return; } $tAutoModel = new AutoModel('categories'); $tCategory = $tAutoModel->getBySlug($tModule['name'], $uSlug); foreach ($tModule['fieldList'] as $tField) { $tIsView = array_key_exists('view', $tField['methods']); $tIsEdit = array_key_exists('edit', $tField['methods']); if ($tIsView || $tIsEdit) { if ($tField['type'] === 'enum') { $tTypes = array(); foreach ($tField['valueList'] as $tValue) { $tTypes[$tValue['name']] = $tValue['title']; } $tAttributes = array('name' => $tField['name'], 'class' => 'input-block-level input_' . $tField['type']); if (!$tIsEdit) { $tAttributes['readonly'] = 'readonly'; } $tTag = '<p>' . I18n::_($tField['title']) . ': ' . Html::tag('select', $tAttributes, Html::selectOptions($tTypes, $tCategory[$tField['name']])) . '</p>'; } else { $tAttributes = array('type' => 'text', 'name' => $tField['name'], 'value' => $tCategory[$tField['name']], 'class' => 'input-block-level input_' . $tField['type']); if (!$tIsEdit) { $tAttributes['readonly'] = 'readonly'; } $tTag = '<p>' . I18n::_($tField['title']) . ': ' . Html::tag('input', $tAttributes) . '</p>'; } } $tViewbag['fields'][] = array('data' => $tField, 'html' => $tTag); } Views::viewFile('{core}views/panel/models/form.php', $tViewbag); }
/** * @ignore */ public function render($uAction, array $uParams, array $uInput) { $tActionName = $uAction; // strtr($uAction, '/', '_'); if ($tActionName === null || strlen($tActionName) <= 0) { $tActionName = $this->defaultAction; } $tFormat = substr($uInput['format'], 1); // @todo not sure on this // Framework::$responseFormat = $tFormat; if (isset($this->childControllers[$tActionName])) { if (count($uParams) > 0) { $tSubaction = array_shift($uParams); } else { $tSubaction = null; } $tInstance = new $this->childControllers[$tActionName](); return $tInstance->render($tSubaction, $uParams, $uInput); } $tMe = new \ReflectionClass($this); $tActionName2 = String::capitalizeEx($tActionName, '-', '', true); $tMethods = array($uInput['methodext'] . '_' . $tActionName2 . '_' . $tFormat, $uInput['methodext'] . '_' . $tActionName2, $uInput['methodext'] . '_otherwise' . '_' . $tFormat, $uInput['methodext'] . '_otherwise', $uInput['method'] . '_' . $tActionName2 . '_' . $tFormat, $uInput['method'] . '_' . $tActionName2, $uInput['method'] . '_otherwise' . '_' . $tFormat, $uInput['method'] . '_otherwise', $tActionName2 . '_' . $tFormat, 'otherwise' . '_' . $tFormat, $tActionName2, 'otherwise'); foreach ($tMethods as $tMethod) { if ($tMe->hasMethod($tMethod) && $tMe->getMethod($tMethod)->isPublic()) { Controllers::setController($this, $tActionName, $tFormat, $uParams, $uInput); $this->prerender->invoke(); $tReturn = call_user_func_array(array(&$this, $tMethod), $uParams); Framework::$responseFormat = $this->format; $this->postrender->invoke(); return $tReturn; } } return false; }
$class = 'alt'; } else { $class = ""; } if ($log['type'] === 'memory') { ?> <tr class="log-<?php echo $log['type']; ?> "> <td class="<?php echo $class; ?> "> <div><div class="measure"><?php echo String::sizeCalc($log['data']); ?> </div> <em><?php echo $log['datatype']; ?> </em>: <?php print_r($log['message']); ?> </div> <?php if (isset($log['object'])) { ?> <div><?php print_r($log['object']); ?> </div>
/** * @ignore */ public static function checkUserPermission($uPermissions = null) { $tPermissions = String::coalesce($uPermissions, self::$appPermissions); if ($tPermissions !== null) { $tUserPermissions = self::get('/me/permissions', true); if ($tUserPermissions === false || count($tUserPermissions->data) === 0) { return false; } foreach (explode(',', $uPermissions) as $tPermission) { if (!array_key_exists(trim($tPermission), $tUserPermissions->data[0])) { return false; } } } return true; }
/** * @ignore */ public static function export($tOutput = true) { return String::vardump(self::$summary, $tOutput); }
<div id="pageTopHead"> <div class="containerBox padding4px inner"> <a href="#" class="bgLink pull-left"><?php echo I18n::_('Notifications:'); ?> <span class="bgCount">0</span></a> <span class="bgSpacer pull-left"></span> <a href="#" class="bgLink pull-left"><?php echo I18n::_('User:'******'username']; ?> </span></a> <a href="#" class="bgLink pull-right bootstrap-popover" data-toggle="popover" data-placement="bottom" data-content="<?php echo String::encodeHtml(Html::tag('a', array('href' => 'https://github.com/eserozvataf/scabbia1'), 'https://github.com/eserozvataf/scabbia1')); ?> " title="" data-original-title="<?php echo I18n::_('Scabbia Framework'), ' ', Framework::VERSION; ?> "><?php echo I18n::_('Scabbia Framework'); ?> </a> <div class="clearfix"></div> </div> </div> <div id="pageTopLogo"> <div class="containerBox inner"> <a href="<?php echo Http::url('panel');
/** * @ignore */ public static function gatherTimeData() { self::$output['timeTotals'] = array('total' => String::timeCalc(microtime(true) - Framework::$timestamp), 'allowed' => ini_get('max_execution_time')); }
/** * Logs with an arbitrary level. * * @param string $uClass * @param mixed $uLevel * @param array $uContext * @return null */ public static function write($uClass, $uLevel, array $uContext = array()) { if (!isset($uContext['type'])) { $uContext['type'] = $uLevel === LogLevel::DEBUG || $uLevel === LogLevel::INFO ? 'log' : 'error'; } self::$typeCounts[$uContext['type']]++; $uContext['class'] = $uClass; $uContext['category'] = $uLevel; $uContext['ip'] = $_SERVER['REMOTE_ADDR']; if (isset($uContext['message'])) { $uContext['message'] = String::prefixLines($uContext['message'], '- ', PHP_EOL); } if (isset($uContext['file'])) { if (Framework::$development) { $uContext['location'] = Io::extractPath($uContext['file']); if (isset($uContext['line'])) { $uContext['location'] .= ' @' . $uContext['line']; } } else { $uContext['location'] = pathinfo($uContext['file'], PATHINFO_FILENAME); } } else { $uContext['location'] = '-'; } $uContext['stackTrace'] = array(); foreach (array_slice(debug_backtrace(), 2) as $tFrame) { $tArgs = array(); /* if (isset($tFrame['args'])) { foreach ($tFrame['args'] as $tArg) { $tArgs[] = var_export($tArg, true); } } */ if (isset($tFrame['class'])) { $tFunction = $tFrame['class'] . $tFrame['type'] . $tFrame['function']; } else { $tFunction = $tFrame['function']; } if (isset($tFrame['file'])) { if (Framework::$development) { $tLocation = Io::extractPath($tFrame['file']); if (isset($tFrame['line'])) { $tLocation .= ' @' . $tFrame['line']; } } else { $tLocation = pathinfo($tFrame['file'], PATHINFO_FILENAME); } } else { $tLocation = '-'; } $uContext['stackTrace'][] = $tFunction . '(' . implode(', ', $tArgs) . ') in ' . $tLocation; } $uContext['eventDepth'] = Events::$eventDepth; Events::$disabled = true; if (!Framework::$readonly) { $tContent = '+ ' . String::format(Logger::$line, $uContext); $tFilename = Io::translatePath('{writable}logs/' . String::format(Logger::$filename, $uContext), true); Io::write($tFilename, $tContent, LOCK_EX | FILE_APPEND); } self::$console[] = $uContext; Events::$disabled = false; if (isset($uContext['halt']) && $uContext['halt']) { Events::invoke('reportError', $uContext); Framework::end(-1); } }