/** * indexAction * * generate image and stored keystring into storage * * @return null */ public function indexAction() { if ($this->_length === 'random') { $this->_length = mt_rand(5, 8); } $keyString = ''; $fontsPath = APPLICATION . 'resources/protection-image/*.png'; if (!($fonts = \FsUtils::glob($fontsPath))) { throw new \SystemErrorException(array('title' => 'Protection image error', 'description' => 'Fonts in resources not found')); } $alphabet = '0123456789abcdefghijklmnopqrstuvwxyz'; $alphabetLength = strlen($alphabet); $allowedSymbols = '23456789abcdeghkmnpqsuvxyz'; if ($this->_foregroundColor === 'random') { $this->_foregroundColor = array(mt_rand(0, 150), mt_rand(0, 150), mt_rand(0, 15)); } do { $asLen = strlen($allowedSymbols) - 1; for ($i = 0; $i < $this->_length; $i++) { $keyString .= $allowedSymbols[mt_rand(0, $asLen)]; } $font = imagecreatefrompng($fonts[mt_rand(0, sizeof($fonts) - 1)]); imagealphablending($font, true); $fFileWidth = imagesx($font); $fFileHeight = imagesy($font) - 1; $fontMetrics = array(); $symbol = 0; $readingSymbol = false; for ($i = 0; $i < $fFileWidth && $symbol < $alphabetLength; $i++) { $transparent = imagecolorat($font, $i, 0) >> 24 == 127; if (!$readingSymbol && !$transparent) { $fontMetrics[$alphabet[$symbol]] = array('start' => $i); $readingSymbol = true; continue; } if ($readingSymbol && $transparent) { $fontMetrics[$alphabet[$symbol]]['end'] = $i; $readingSymbol = false; $symbol++; continue; } } $img = imagecreatetruecolor($this->_width, $this->_height); imagealphablending($img, true); $white = imagecolorallocate($img, 255, 255, 255); $black = imagecolorallocate($img, 0, 0, 0); imagefilledrectangle($img, 0, 0, $this->_width - 1, $this->_height - 1, $white); $x = 1; for ($i = 0; $i < $this->_length; $i++) { $m = $fontMetrics[$keyString[$i]]; $y = mt_rand(-$this->_fluctuationAmplitude, $this->_fluctuationAmplitude) + ($this->_height - $fFileHeight) / 2 + 2; $shift = 0; if ($i > 0) { $shift = 10000; for ($sy = 7; $sy < $fFileHeight - 20; $sy += 1) { for ($sx = $m['start'] - 1; $sx < $m['end']; $sx += 1) { $rgb = imagecolorat($font, $sx, $sy); $opacity = $rgb >> 24; if ($opacity < 127) { $left = $sx - $m['start'] + $x; $py = $sy + $y; if ($py > $this->_height) { break; } for ($px = min($left, $this->_width - 1); $px > $left - 12 && $px >= 0; $px -= 1) { $color = imagecolorat($img, $px, $py) & 0xff; if ($color + $opacity < 190) { if ($shift > $left - $px) { $shift = $left - $px; } break; } } break; } } } if ($shift == 10000) { $shift = mt_rand(4, 6); } } imagecopy($img, $font, $x - $shift, $y, $m['start'], 1, $m['end'] - $m['start'], $fFileHeight); $x += $m['end'] - $m['start'] - $shift; } } while ($x >= $this->_width - 10); $center = $x / 2; $img2 = imagecreatetruecolor($this->_width, $this->_height); $foreground = imagecolorallocate($img2, $this->_foregroundColor[0], $this->_foregroundColor[1], $this->_foregroundColor[2]); $background = imagecolorallocate($img2, $this->_backgroundColor[0], $this->_backgroundColor[1], $this->_backgroundColor[2]); imagefilledrectangle($img2, 0, 0, $this->_width - 1, $this->_height - 1, $background); imagestring($img2, 2, $this->_width - 2, $this->_height - 2, 0, $background); // periods $rand1 = mt_rand(750000, 1200000) / 10000000; $rand2 = mt_rand(750000, 1200000) / 10000000; $rand3 = mt_rand(750000, 1200000) / 10000000; $rand4 = mt_rand(750000, 1200000) / 10000000; // phases $rand5 = mt_rand(0, 31415926) / 10000000; $rand6 = mt_rand(0, 31415926) / 10000000; $rand7 = mt_rand(0, 31415926) / 10000000; $rand8 = mt_rand(0, 31415926) / 10000000; // amplitudes $rand9 = mt_rand(330, 420) / 110; $rand10 = mt_rand(330, 450) / 110; // wave distortion for ($x = 0; $x < $this->_width; $x++) { for ($y = 0; $y < $this->_height; $y++) { $sx = $x + (sin($x * $rand1 + $rand5) + sin($y * $rand3 + $rand6)) * $rand9 - $this->_width / 2 + $center + 1; $sy = $y + (sin($x * $rand2 + $rand7) + sin($y * $rand4 + $rand8)) * $rand10; if ($sx < 0 || $sy < 0 || $sx >= $this->_width - 1 || $sy >= $this->_height - 1) { continue; } else { $color = imagecolorat($img, $sx, $sy) & 0xff; $color_x = imagecolorat($img, $sx + 1, $sy) & 0xff; $color_y = imagecolorat($img, $sx, $sy + 1) & 0xff; $color_xy = imagecolorat($img, $sx + 1, $sy + 1) & 0xff; } if ($color == 255 && $color_x == 255 && $color_y == 255 && $color_xy == 255) { continue; } else { if ($color == 0 && $color_x == 0 && $color_y == 0 && $color_xy == 0) { $newred = $this->_foregroundColor[0]; $newgreen = $this->_foregroundColor[1]; $newblue = $this->_foregroundColor[2]; } else { $frsx = $sx - floor($sx); $frsy = $sy - floor($sy); $frsx1 = 1 - $frsx; $frsy1 = 1 - $frsy; $newcolor = $color * $frsx1 * $frsy1 + $color_x * $frsx * $frsy1 + $color_y * $frsx1 * $frsy + $color_xy * $frsx * $frsy; if ($newcolor > 255) { $newcolor = 255; } $newcolor = $newcolor / 255; $newcolor0 = 1 - $newcolor; $newred = $newcolor0 * $this->_foregroundColor[0] + $newcolor * 255; $newgreen = $newcolor0 * $this->_foregroundColor[1] + $newcolor * 255; $newblue = $newcolor0 * $this->_foregroundColor[2] + $newcolor * 255; } } imagesetpixel($img2, $x, $y, imagecolorallocate($img2, $newred, $newgreen, $newblue)); } } imagedestroy($img); $action = preg_replace('/[^a-z-]+/', '', \Request::getParam('action')); $action = 'protection-code' . ($action ? '-' . $action : ''); \Storage::write($action, $keyString); \Request::addHeader('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); \Request::addHeader('Cache-Control: no-store, no-cache, must-revalidate'); \Request::addHeader('Cache-Control: post-check=0, pre-check=0'); \Request::addHeader('Pragma: no-cache'); \Request::addHeader('Content-Type: image/jpeg'); \Request::sendHeaders(); imagejpeg($img2, null, $this->_jpegQuality); exit; }
/** * processAction * * Member registration process * * @return null */ public function processAction() { // set json context \View::setOutputContext('json'); \View::lockOutputContext(); // validate form $registerForm = \App::getInstance('\\modules\\user\\RegisterForm'); $registerForm->validate(); // invalid form data if (!$registerForm->isValid()) { throw new \MemberErrorException(array('title' => \View::$language->register_error, 'description' => \View::$language->register_proc_err_descr, 'form_messages' => $registerForm->getMessages())); } // create a new user $userData = $registerForm->getData(); // set new user defaults $userData->group_id = 0; // TODO get default user group ID $userData->password = $userData->password; // TODO need hash password algorythm $userData->time_zone = '+00:00'; // TODO get default user time zone $userData->status = 0; // TODO get default new registered user status $userData->activation_hash = 'xxx'; // TODO need algorythm for generation of activation hash $userData->avatar = 'no-avatar.png'; // TODO get default user avatar $UserModel = \App::getInstance('common\\UserModel'); $UserModel->createUser($userData); // TODO send email notification of account activation \App::dump($userData); // redirect to complete page \Storage::write('__register_complete', true); throw new \MemberSuccessException(array('redirection' => '/user/register/complete')); }
/** * processAction * * Member registration process * * @return null */ public function processAction() { // set json context \View::setOutputContext('json'); \View::lockOutputContext(); // validate form $registerForm = new forms\RegisterForm(); $registerForm->validate(); if (!$registerForm->isValid()) { throw new \MemberErrorException(array('title' => \View::$language->register_error, 'description' => \View::$language->register_proc_err_descr, 'form_messages' => $registerForm->getMessages())); } $userData = $registerForm->getData(); // set new user defaults $hCnf = \App::getConfig('hosts'); $mCnf = \App::getConfig('member-defaults'); $pass = \common\CryptHelper::generateHash($userData->password); $userData->group_id = $mCnf->group_id; $userData->cookie = \common\HashHelper::getUniqueKey(); $userData->password = $pass; $userData->time_zone = $mCnf->time_zone; $userData->status = $mCnf->status; $userData->activation_hash = \common\HashHelper::getUniqueKey(); $userData->avatar = '//' . $hCnf->st . $mCnf->avatar; // create a new user $UserModel = \App::getInstance('common\\UserModel'); $UserModel->createUser($userData); // TODO send email notification of account activation \App::dump($userData); // redirect to complete page \Storage::write('__register_complete', true); throw new \MemberSuccessException(array('redirection' => '/user/register/complete')); }
public function write($data) { //write $data and timestamp $now = time(); //convert to json $foo = array('timestamp' => $now, 'data' => $data); Storage::write($this->options['cacheDir'] . md5($this->options['cacheId']), json_encode($foo)); }
public function testWhatYouWriteIsReadBack() { $data = array('this' => 'is', 'a' => 'sample'); Storage::write($data); $read = Storage::read(); $this->assertEquals($read, $data); // Actual, Expected <-- alphabetic order }
public static function write($data = array(), $type = 'access') { if (!isset($data['servername']) || !isset($data['remoteip']) || !isset($data['bundle'])) { $data['bundle'] = 'SYSEXC'; } if (isset($data['url']) && ($p = parse_url($data['url']))) { $data += $p; } $data += array('servername' => '', 'remoteip' => '', 'ssid' => '', 'uid' => 0, 'datetime' => time(), 'exectime' => 0, 'method' => 'GET', 'referer' => '', 'agent' => '', 'scheme' => 'http', 'query' => '', 'path' => '/', 'host' => '', 'port' => 80); $entry = array(':version' => static::$version, ':servername' => $data['servername'], ':remoteip' => $data['remoteip'], ':bundle' => strtoupper($data['bundle']), ':ssid' => $data['ssid'], ':uid' => (int) $data['uid'], ':datetime' => substr($data['datetime'], 0, 10), ':exectime' => (int) $data['exectime'], ':method' => strtoupper($data['method']), ':referer' => $data['referer'], ':agent' => $data['agent'], ':scheme' => strtolower($data['scheme']), ':query' => $data['query'], ':path' => strtolower($data['path']), ':host' => strtolower($data['host']), ':port' => (int) $data['port']); Storage::write($type, $entry); }
/** * __construct * * User sign in form class constructor. * Definition of validation rules * * @return null */ public function __construct() { parent::__construct(); \View::addLanguageItem('SignInForm'); $this->_rules = array('login' => array(array('negation', 'IsString', \View::$language->sign_in_form_data_invalid), array('filter', 'ToString'), array('filter', 'Trim'), array('assertion', 'IsEmpty', \View::$language->sign_in_form_login_is_empty)), 'password' => array(array('negation', 'IsString', \View::$language->sign_in_form_data_invalid), array('filter', 'ToString'), array('filter', 'Trim'), array('assertion', 'IsEmpty', \View::$language->sign_in_form_password_is_empty))); // increment sign in tries number if (\Storage::isExists('sign-in-tries')) { $signInTries = \Storage::read('sign-in-tries') + 1; } else { $signInTries = 1; } \Storage::write('sign-in-tries', $signInTries); // protection code appendix if ($signInTries >= 3) { // TODO maybe get number of tries from config? $this->_rules['protection_code'] = array(array('negation', 'IsString', \View::$language->sign_in_form_data_invalid), array('filter', 'ToString'), array('filter', 'Trim'), array('assertion', 'IsEmpty', \View::$language->sign_in_form_protection_code_is_empty)); } }
/** * setLanguage * * Loading language environment * * @param string $name Name of language * @return null */ public static function setLanguage($name) { if ($name != self::$_currentLang) { $langDir = APPLICATION . 'languages/' . $name; self::$language = array(); foreach (self::$_langItems as $langFile) { $langPath = $langDir . '/' . $langFile . '.php'; self::$language = array_merge(self::$language, require $langPath); } self::$_currentLang = $name; Storage::write(self::$_langStorageKey, $name); self::$language = (object) self::$language; } }
/** * Minify JS. * * @param string|array $source_filename * @param string $target_filename * @return bool */ public static function minifyJS($source_filename, $target_filename) { $minifier = new \MatthiasMullie\Minify\JS(); if (is_array($source_filename)) { foreach ($source_filename as $filename) { $minifier->add($filename); } } else { $minifier->add($source_filename); } $content = $minifier->execute($target_filename); Storage::write($target_filename, $content); return strlen($content) ? true : false; }
$mmcache = new MMCache(); //$mmcache->delete("key"); //$mmcache->set("key","问少尉",600); echo $mmcache->get("key"); return; $imgurl = 'http://localhost:86/temporary/test.jpg'; $request = new HttpRequest(false, false); $img_data = $request->get($imgurl); $img = new Image(); $img->setData($img_data); //$img->resize(300); // 等比缩放到200宽 $img->annotate("翁少尉1", 0.5, GRAVITY_SOUTHEAST, array("name" => FONT_MicroHei, "size" => 100, "color" => "red")); $new_data = $img->exec(); // 执行处理并返回处理后的二进制数据 $ftype = "jpg"; $stor = new Storage(); $picurlm = $stor->write(FILE_DIR_TEMP, "_400." . $ftype, $new_data); return; $stor = new Storage(); $picurl = $stor->upload(FILE_DIR_TEMP, $destination, $filename); return; $uptypes = array('image/jpg', 'image/jpeg', 'image/png', 'image/pjpeg', 'image/gif', 'image/bmp', 'image/x-png'); //上传文件大小限制, 单位BYTE //$destination_folder="../../../uploads/temporary/".date("Y-m-d")."/"; //上传文件路径 //sea存储方案 $destination_folder = '/' . date("Y-m") . "/a/"; //上传文件路径 $watermark = 0; //是否附加水印(1为加水印,其他为不加水印); $watertype = 0; //水印类型(1为文字,2为图片)
/** * 处理base64编码的图片上传 * @param $base64Data * @return mixed */ private function base64ToImage($base64Data) { $img = base64_decode($base64Data); $this->fileName = time() . rand(1, 10000) . ".png"; $this->fullName = $this->getFolder() . '/' . $this->fileName; if (!Storage::write($this->fullName, $img)) { $this->stateInfo = $this->getStateInfo("IO"); return; } else { $this->url = Storage::getUrl($this->fullName); } $this->oriName = ""; $this->fileSize = strlen($img); $this->fileType = ".png"; }
public function effect() { $res = array(); $project = new Project(); $project->setValue($this->ProjectId); if ($project->Url != $this->Url) { //生产二维码 $project->Url = $this->Url; $destination_folder = date("Y") . "/"; //上传文件路径 $filenamenew = uniqid(date("Ymd"), true) . '.png'; $destination = $destination_folder . $filenamenew; $stor = new Storage(); if (!empty($project->QrCode)) { $stor->delete(FILE_DOMAIN, $project->QrCode); } $project->QrCode = $destination; $url = urlencode($project->Url); $qrcode = URL_WEBSITE . '/basic/handles/qrcode.php?Url=' . $url; $f = new Fetchurl(); $imageData = $f->fetch($qrcode); $stor->write(FILE_DOMAIN, $project->QrCode, $imageData); } $project->Pv = $this->Pv; $project->Uv = $this->Uv; $project->Fans = $this->Fans; $project->Summary = $this->Summary; $project->Laud = $this->Laud; //print_r($project); $result = $project->update(); if ($result > 0) { $res['Success'] = true; $res['Message'] = "更新成功"; //发送部门老大emailt通知 } else { $res['Success'] = false; $res['Message'] = "没有更新任何数据"; } echo json_encode($res); exit; }
<?php require_once CONFIG::get('ABSPATH') . '/src/models/person.php'; require_once CONFIG::get('ABSPATH') . '/src/models/storage.php'; try { $people = $_POST['people']; foreach ($people as $key => $value) { $people[$key] = new Person($value); // this cleans up posted data } Storage::write($people); $_SESSION['info'] = 'People saved.'; redirect_to('/people/list'); } catch (Exception $e) { $_SESSION['page_error'] = $e->getMessage(); $_SESSION['page_post'] = $_POST; $_SESSION['errors'] = $errors; redirect_to('/people/list'); }