function createThumb() { $url = Config::get('static.url') . self::STATIC_DIR . $this->path; $ext = pathinfo($url, PATHINFO_EXTENSION); $localFile = "/tmp/a.{$ext}"; $localThumbFile = "/tmp/thumb.{$ext}"; $contents = file_get_contents($url); file_put_contents($localFile, $contents); $command = sprintf("convert -strip -geometry %sx%s -sharpen 1x1 '%s' '%s'", self::THUMB_SIZE, self::THUMB_SIZE, $localFile, $localThumbFile); OS::executeAndAssert($command); $f = new FtpUtil(); $f->staticServerPut($localThumbFile, self::STATIC_THUMB_DIR . $this->path); unlink($localFile); unlink($localThumbFile); }
foreach ($schemaOnly as $table) { $command .= " {$table}"; } $command .= " >> {$SQL_FILE}"; OS::executeAndAssert($command); if (!$doFullDump) { // Anonymize the User table. Handle the case for id = 0 separately, since // "insert into _User_Copy set id = 0" doesn't work (it inserts an id of 1). log_scriptLog('Anonymizing the User table'); db_execute("create table _User_Copy like User"); db_execute("insert into _User_Copy select * from User where id = 0"); db_execute("update _User_Copy set id = 0 where id = 1"); db_execute("insert into _User_Copy select * from User where id > 0"); db_execute("update _User_Copy set password = md5('1234'), email = concat(id, '@anonymous.com'), identity = null"); OS::executeAndAssert("{$COMMON_COMMAND} _User_Copy | sed 's/_User_Copy/User/g' >> {$SQL_FILE}"); db_execute("drop table _User_Copy"); log_scriptLog('Anonymizing the Source table'); db_execute("create table _Source_Copy like Source"); db_execute("insert into _Source_Copy select * from Source"); db_execute("update _Source_Copy set link = null"); OS::executeAndAssert("{$COMMON_COMMAND} _Source_Copy | sed 's/_Source_Copy/Source/g' >> {$SQL_FILE}"); db_execute("drop table _Source_Copy"); // Dump only the Definitions for which we have redistribution rights log_scriptLog('Filtering the Definition table'); OS::executeAndAssert("{$COMMON_COMMAND} Definition --lock-all-tables --where='Definition.sourceId in (select id from Source where canDistribute)' " . ">> {$SQL_FILE}"); } OS::executeAndAssert("gzip -f {$SQL_FILE}"); $f = new FtpUtil(); $f->staticServerPut($GZ_FILE, $remoteFile); unlink($GZ_FILE); log_scriptLog('dumpDatabase.php completed successfully (against all odds)');
FlashMessage::add('Imaginea a fost ștearsă.', 'info'); util_redirect('preferinte'); } $rawFileList = glob($AVATAR_RAW_GLOB); if (empty($rawFileList)) { FlashMessage::add('Imaginea dumneavoastră de profil nu mai există. Vă rugăm să o reîncărcați.'); util_redirect(util_getWwwRoot()); } $rawFileName = $rawFileList[0]; $canvas = imagecreatetruecolor(AVATAR_RESOLUTION, AVATAR_RESOLUTION); $image = loadImage($rawFileName); imagecopyresampled($canvas, $image, 0, 0, $x0, $y0, AVATAR_RESOLUTION, AVATAR_RESOLUTION, $side, $side); sharpenImage($canvas); $tmpFileName = tempnam(Config::get('global.tempDir'), 'dex_avatar_'); imagejpeg($canvas, $tmpFileName, AVATAR_QUALITY); $f = new FtpUtil(); $f->staticServerPut($tmpFileName, $AVATAR_REMOTE_FILE); unlink($rawFileName); unlink($tmpFileName); $user->hasAvatar = 1; $user->save(); FlashMessage::add('Imaginea a fost salvată.', 'info'); util_redirect('preferinte'); /****************************************************************************/ /* Load an image by its (supported) type */ function loadImage($file) { $size = getimagesize($file); switch ($size['mime']) { case 'image/jpeg': return imagecreatefromjpeg($file);
public function copyFile($srcFile, $desFile, $type) { $_G = Yii::app()->setting->toArray(); if (!is_file($srcFile)) { return false; } if ($type == "file") { $this->mkdirs(dirname($desFile)); copy($srcFile, $desFile); } else { if ($type == "ftp") { $siteFtp = $_GET["siteftp"]; $siteFtp["on"] = 1; $autoKey = md5($_G["config"]["security"]["authkey"]); $siteFtp["password"] = StringUtil::authCode($siteFtp["password"], "ENCODE", $autoKey); $ftp =& FtpUtil::instance($siteFtp); $ftp->connect(); $ftp->upload($srcFile, $desFile); if ($ftp->error()) { return false; } } } return true; }
<?php $f = new FtpUtil(); $ftp_user_imgs = $f->staticServerRelativeFileList('img/user'); $existing_user_imgs = array_map(function ($item) { $file = array_pop(explode('/', $item)); $id = reset(explode('.', $file)); return $id; }, $ftp_user_imgs); printf("Existing avatars: %s\n", count($existing_user_imgs)); printf("Setting hasAvatar for users with avatars.\n"); ORM::for_table('User')->where_id_in($existing_user_imgs)->find_result_set()->set('hasAvatar', 1)->save();
public static function copyFile($srcFile, $desFile, $type) { if (!is_file($srcFile)) { return false; } if ($type == "file") { FileUtil::makeDirs(dirname($desFile)); copy($srcFile, $desFile); } elseif ($type == "ftp") { $ftpConf = EnvUtil::getRequest("ftp"); $ftpConf["on"] = 1; $ftpConf["password"] = StringUtil::authcode($ftpConf["password"], "ENCODE", md5(Yii::app()->setting->get("config/security/authkey"))); $ftp = FtpUtil::getInstance($ftpConf); $ftp->connect(); $ftp->upload($srcFile, $desFile); if ($ftp->error()) { return false; } } return true; }
throw new Exception(sprintf("Cuvântul '%s' nu apare în intervalul %s - %s.", $word, $dateMin, $dateMax)); } else { if (count($wotds) > 1) { throw new Exception(sprintf("Cuvântul '%s' apare de %d ori în intervalul %s - %s.", $word, count($wotds), $dateMin, $dateMax)); } } $wotd = $wotds[0]; $today = date('Y-m-d'); if ($wotd->image && $wotd->displayDate < $today) { throw new Exception("Cuvântul zilei '{$word}' are deja o imagine ataşată. Nu puteți modifica imaginile cuvintelor din trecut."); } $wotdDisplayDate = new DateTime($wotd->displayDate); $wotd->image = sprintf("%s/%s.%s", $wotdDisplayDate->format('Y-m'), $word, $imageExtension); $wotd->save(); $wotdImagePath = '/img/wotd/' . $wotd->image; $f = new FtpUtil(); $f->staticServerPut($tmpFilePath, $wotdImagePath); unlink($tmpFilePath); ReplyToEmail($sender, $subject, "Am adăugat imaginea pentru '{$word}'."); } catch (Exception $e) { unlink($tmpFilePath); log_scriptLog($e->getMessage()); ReplyToEmail($sender, $subject, $e->getMessage()); } log_scriptLog("getWotdImageByEmail: done"); /***************************************************************************/ function ReplyToEmail($senderAddress, $subject, $message) { $sender = Config::get('WotD.sender'); $replyto = Config::get('WotD.reply-to'); $headers = array("From: {$sender}", "Reply-To: {$replyto}", 'Content-Type: text/plain; charset=UTF-8');
<?php require_once __DIR__ . '/../phplib/util.php'; log_scriptLog('Running rebuildFirefoxSpellChecker.php.'); $tmpDir = tempnam(Config::get('global.tempDir'), 'xpi_'); log_scriptLog('Setting up directories'); chdir(util_getRootPath()); OS::executeAndAssert("rm {$tmpDir}"); OS::executeAndAssert("mkdir {$tmpDir}"); OS::executeAndAssert("mkdir {$tmpDir}/chrome"); OS::executeAndAssert("mkdir {$tmpDir}/dictionaries"); OS::executeAndAssert("echo 'SET UTF-8' > {$tmpDir}/dictionaries/ro-dex.aff"); OS::executeAndAssert("cp docs/install.rdf {$tmpDir}/"); $mysqlFile = tempnam(Config::get('global.tempDir'), 'mysql_'); unlink($mysqlFile); $query = "select distinct formNoAccent from InflectedForm where formNoAccent rlike '^[a-zăâîșț]+\$' into outfile '{$mysqlFile}'"; log_scriptLog("Running mysql query: [{$query}]"); db_execute($query); log_scriptLog("Prepending line count"); OS::executeAndAssert("wc -l {$mysqlFile} | cut -d ' ' -f 1 > {$tmpDir}/dictionaries/ro-dex.dic"); OS::executeAndAssert("cat {$mysqlFile} >> {$tmpDir}/dictionaries/ro-dex.dic"); log_scriptLog("Zipping"); OS::executeAndAssert("cd {$tmpDir} && zip -r dex-ff.xpi *"); $f = new FtpUtil(); $f->staticServerPut("{$tmpDir}/dex-ff.xpi", '/download/dex-ff.xpi'); OS::executeAndAssert("rm -rf {$tmpDir}"); log_scriptLog('rebuildFirefoxSpellChecker.php completed successfully (against all odds)'); // Note -- this leaves behind the temporary MySQL file created by "... into outfile...". // The file is owned by mysql so we cannot delete it.