/** * Run the database seeds. * * @return void */ public function run() { Eloquent::unguard(); DB::table('tags')->truncate(); //DB::table('pastes')->truncate(); $faker = Faker\Factory::create(); $paste_count = 10; $tags = array('php', 'javascript', 'ruby', 'js', 'cpp', 'c++', 'c#', 'go', 'html', 'css'); for ($i = 0; $i < $paste_count; $i++) { $tags_per_paste = rand(1, 3); // Generate the paste $examplePaste = new Paste(); $examplePaste->paste = $faker->paragraph; $examplePaste->title = $faker->realText(46); $examplePaste->expire = $faker->dateTime($max = 'now'); $examplePaste->token = Str::random(40); $examplePaste->private = rand(0, 1); $examplePaste->delete_token = Str::random(40); $examplePaste->save(); // Attach some tags to the new paste for ($i = 0; $i < $tags_per_paste; ++$i) { $exampleTag = new Tag(); $exampleTag->tag = $tags[rand(0, sizeof($tags) - 1)]; $exampleTag->paste_id = $examplePaste->id; $examplePaste->tags()->save($exampleTag); } print "Seeded paste with ID of " . $examplePaste->id . "\n"; } }
public function indexAction() { // No view needed since this is all backend stuff. $this->view->disable(); // Generate random ids until we find one not in use. // This will cause one additional SQL query at minimum when creating a paste. do { $id = Text::random(Text::RANDOM_ALNUM, rand(5, 13)); } while (Paste::findFirstByid($id)); $paste = new Paste(); $paste->id = $id; $paste->content = rtrim($this->request->getPost("content")); $paste->lang = $this->request->getPost("lang") == null ? "auto" : $this->request->getPost("lang"); // No sanitisation needed if we accept anything at all to mean true and nothing to mean false. // Also addresses http://stackoverflow.com/a/14067312 $paste->private = $this->request->getPost("private") == null ? 0 : 1; $paste->owner_addr = $this->request->getClientAddress(); $paste->size_bytes = strlen($paste->content); if (!$paste->save()) { foreach ($paste->getMessages() as $message) { $this->flash->error($message->getMessage()); } return $this->response->redirect(); } return $this->response->redirect($this->url->get("v/{$id}")); }
/** * Display the specified resource. * * @param str $token * @return Response */ public function show($token, $raw = false) { // Get the requested paste $pasteModel = new Paste(); $results = $pasteModel->getPasteByToken($token); //$latestPastes = $pasteModel->getLatestPastes(); // Render the view return View::make('paste.show', array('page_title' => $results->title, 'paste' => $results)); }
/** * Tests the getShorten method of the controller */ public function testGetShorten() { $this->initTestStep(); $paste = Paste::createNew('web', array('title' => 'UnitTest::Title', 'data' => 'UnitTest::Data', 'language' => 'text')); $this->call('GET', "ajax/shorten/{$paste->urlkey}/{$paste->hash}"); $this->assertResponseOk(); }
/** * Tests the getFeed method of the controller */ public function testGetFeed() { $this->initTestStep(); Paste::createNew('web', array('title' => 'UnitTest::Title', 'data' => 'UnitTest::Data', 'language' => 'text')); $response = $this->call('GET', 'feed/rss'); $this->assertResponseOk(); $this->assertTrue(str_contains($response->headers->get('Content-Type'), 'application/rss+xml')); }
function initialize() { parent::initialize(); $id = $this->dispatcher->getParam("id"); $this->paste = Paste::findFirstById($id, array('cache' => array('lifetime' => 3600, 'key' => $id))); if (!$this->paste) { return $this->dispatcher->forward(array('controller' => 'error', 'action' => 'e404')); } }
public function store() { $validator = Validator::make(Input::all(), ['paste' => 'required']); if ($validator->fails()) { return Redirect::route('create')->withErrors($validator); } try { $paste = Paste::create(['paste' => Input::get('paste'), 'fork_of' => Input::get('fork', null)]); } catch (Exception $e) { return Redirect::route('create')->withErrors($e->getMessage()); } return Redirect::route('show', Math::to_base($paste->id)); }
/** * Generates a short URL for a paste * * @param string $urlkey * @param string $hash * @return \Illuminate\Support\Facades\View|string */ public function getShorten($urlkey, $hash = '') { // We need to validate the paste first $paste = Paste::where('urlkey', $urlkey)->first(); // Paste was not found if (is_null($paste)) { return Lang::get('ajax.error'); } // If it is a private paste, we need the hash if ($paste->private and $paste->hash != $hash) { return Lang::get('ajax.error'); } // Shorten and return the paste URL $longUrl = url("{$urlkey}/{$hash}"); return Service::urlShortener($longUrl); }
/** * Gets the news feed for the site * * @param string $type * @return void */ public function getFeed($type = 'rss') { // Create feeder instance $feed = Feed::make($type); // Only the public pastes are accessible in the feed $query = Paste::where('private', '<>', 1); // We fetch 100 pastes only $pastes = $query->take(100)->orderBy('id', 'desc')->get(); // We populate the data manually here as there is some // per item processing to be done $list = array(); // Get the key for each paste item foreach ($pastes as $paste) { $list[] = $paste->toArray(); } // Serve the feed output return $feed->out(array('pastes' => $list)); }
<?php /* This file is part of the Pastebin package. Copyright (c) 2003-2008, Stephen Olesen All rights reserved. More information is available at http://pastebin.ca/ */ require_once "include/global.inc.php"; $tpl = new Template(); $tpl->assign('typeOptions', TypeUtil::getOptionList()); if (isset($_GET["id"])) { $p = new Paste(); if ($p->load($_GET["id"])) { $tpl->assign('paste', $p); $tpl->headers(); if ($p->id_mask != null) { $tpl->assign('urlid', $p->id_mask); } else { $tpl->assign('urlid', $p->id); } $tpl->assign('title', _("General Pastebin") . " - " . htmlentities($p->poster, ENT_COMPAT, "UTF-8") . " - " . _("Paste number") . " " . $p->id); $tpl->display('paste-main.tpl', $p->id); exit; } } $tpl->headers(); $tpl->display('main.tpl');
/** * Creates a new paste revision * * @return \Illuminate\Support\Facades\Redirect */ public function postRevision() { $oldId = Input::get('id'); // First and foremost, validate the ID of the revision if (Session::get('paste.revision') != $oldId) { App::abort(401); // Unauthorized } // Define validation rules. We don't validate the title and language // here as we don't allow to change that for a revision. Instead, we // will use the data from the old paste $validator = Validator::make(Input::all(), array('data' => 'required|auth', 'expire' => 'in:' . Paste::getExpiration('create', TRUE))); // Generate anti-spam modules $antispam = Antispam::make('paste', 'data'); // Run validations $resultValidation = $validator->passes(); // Execute antispam services $resultAntispam = $antispam->passes(); if ($resultValidation and $resultAntispam) { // Get the paste being revised $oldPaste = Paste::findOrFail($oldId); // If the old paste's content is same as the revision, // we simply redirect to the old paste itself if (crc32($oldPaste->data) == crc32(Input::get('data'))) { return Redirect::to($oldPaste->urlkey); } // We use some data from the old paste $data = array('project' => $oldPaste->project, 'title' => $oldPaste->title, 'language' => $oldPaste->language, 'private' => NULL, 'password' => NULL, 'attachment' => NULL); // Merge it with the input to override the values the user submitted Input::merge($data); // All set, create the new revision $newPaste = Paste::createNew('web', Input::all()); // We now need to update the revisions table. One entry will be // created for this revision. We will also create entries for // any past revisions and link it to this new paste $revData = array(array('paste_id' => $newPaste->id, 'urlkey' => $oldPaste->urlkey, 'author' => $oldPaste->author, 'timestamp' => $oldPaste->timestamp)); foreach ($oldPaste->revisions as $revision) { $revData[] = array('paste_id' => $newPaste->id, 'urlkey' => $revision->urlkey, 'author' => $revision->author, 'timestamp' => $revision->timestamp); } // Now insert this batch data to the revisions table Revision::insert($revData); // Whoa, finally we are done, take the user to the shiny new // paste. Since this is a public paste, we don't need the url // hash or password shebang return Redirect::to($newPaste->urlkey); } else { // Set the error message as flashdata if (!$resultValidation) { Session::flash('messages.error', $validator->messages()->all('<p>:message</p>')); } else { if (!$resultAntispam) { Session::flash('messages.error', $antispam->message()); } } } return Redirect::to(URL::previous())->withInput(); }
/** * Tests the postRevision method of the controller without * guest posts enabled */ public function testPostRevisionNoGuest() { $this->initTestStep(FALSE); $paste = Paste::createNew('web', array('title' => 'UnitTest::Title', 'data' => 'UnitTest::Data', 'language' => 'text')); $this->session(array('paste.revision' => $paste->id)); $response = $this->call('POST', 'revise', array('id' => $paste->id, 'title' => 'UnitTest::Title', 'data' => 'UnitTest::Revision', 'language' => 'text')); $this->assertSessionHas('messages.error'); $this->assertEquals(Revision::where('urlkey', $paste->urlkey)->count(), 0); }
/** * Handles the paste password submission * * @param string $urlkey * @param string $hash * @return \Illuminate\Support\Facades\Redirect|null */ public function postComment() { if (Site::config('general')->comments) { // Define validation rules $validator = Validator::make(Input::all(), array('comment' => 'required|auth|min:5|max:1024')); // Generate anti-spam modules $antispam = Antispam::make('comment', 'comment'); // Run validations $resultValidation = $validator->passes(); // Execute antispam services $resultAntispam = $antispam->passes(); if ($resultValidation and $resultAntispam) { // Get the associated paste $paste = Paste::findOrFail(Input::get('id')); // Insert the new comment if (!is_null($paste)) { $comment = new Comment(); $comment->paste_id = $paste->id; $comment->data = nl2br(strip_tags(Input::get('comment'))); $comment->author = Auth::check() ? Auth::user()->username : Lang::get('global.anonymous'); $comment->timestamp = time(); $comment->save(); } return Redirect::to(URL::previous()); } else { // Set the error message as flashdata if (!$resultValidation) { Session::flash('messages.error', $validator->messages()->all('<p>:message</p>')); } else { if (!$resultAntispam) { Session::flash('messages.error', $antispam->message()); } } return Redirect::to(URL::previous())->withInput(); } } else { App::abort(401); // Unauthorized } }
$boundary = $out[1]; } else { if (empty($ffrom) && preg_match("#^From: (.+)#", $line, $out)) { $ffrom = $out[1]; } else { if (empty($subject) && preg_match("#^Subject: (.+)#", $line, $out)) { $subject = $out[1]; } } } } } } // Extract username instead of email adress if it exists if (preg_match("#([^<]+) <#ui", $ffrom, $out)) { $from = $out[1]; } else { $from = $ffrom; } // Create the paste $paste = new Paste(); $paste->title = $subject; $paste->author = $from; $paste->date = time(); $paste->content = utf8_encode(trim($cnt[max(0, $i - 1)])); // Save the paste and give read right to all users (if mail user is different from php one) $link = $paste->save(); chmod(Paste::get_path($paste->filename), 0644); // Send confirmation email $headers = 'From: paste@p0m.fr' . "\r\n" . 'Content-Type: text/plain; charset="utf-8"' . "\r\n" . 'X-Mailer: ' . ucfirst(HTTP_URL); mail($ffrom, "Re: " . $subject, "Bonjour,\n\nVotre paste a bien été publié à l'adresse suivante :\nhttp://" . HTTP_URL . "/?" . $link . "\n\n-- \n" . HTTP_URL, $headers);
/** * Creates a new paste via the API * * @param string $mode * @return \Illuminate\Support\Facades\View */ public function postCreate($mode) { $api = API::make($mode); // Set custom messages for validation module $custom = array('title.max' => 'title_max_30', 'data.required' => 'data_required', 'data.auth' => 'cannot_post', 'data.mbmax' => 'data_too_big', 'language.required' => 'lang_required', 'language.in' => 'lang_invalid', 'expire.integer' => 'expire_integer', 'expire.in' => 'expire_invalid'); // Define validation rules $validator = Validator::make(Input::all(), array('title' => 'max:30', 'data' => 'required|auth|mbmax:' . Site::config('general')->maxPasteSize, 'language' => 'required|in:' . Highlighter::make()->languages(TRUE), 'expire' => 'integer|in:' . Paste::getExpiration('create', TRUE)), $custom); // Run validations if ($validator->fails()) { return $api->error($validator->messages()->first()); } // Set custom messages for the antispam module $custom = array('ipban' => 'antispam_ipban', 'stealth' => 'antispam_stealth', 'censor' => 'antispam_censor', 'noflood' => 'antispam_noflood', 'php' => 'antispam_php'); // Instantiate the antispam module $antispam = Antispam::make('api_call', 'data', $custom); // Run the anti-spam modules if ($antispam->fails()) { return $api->error($antispam->message()); } // Create the paste like a boss! $paste = Paste::createNew('api', Input::all()); // All done! Now we need to output the urlkey and hash $data = array('urlkey' => $paste->urlkey, 'hash' => $paste->hash); // Return the output return $api->out('create', $data); }
<?php require_once "../common.php"; function generate_latex($filein) { print system("pdflatex -halt-on-error -output-directory ../gen " . $filein, $ret); if ($ret == 0) { return "../gen/" . basename(str_replace(".tex", ".pdf", $filein)); } else { return NULL; } } foreach ($_GET as $k => $t) { if (preg_match("#^([a-zA-Z0-9]{" . RGXP_NB . "})(:([a-zA-Z0-9]{" . RGXP_NB . "}))?\$#", $k, $kout) && is_file(Paste::get_path($kout[1]))) { $paste = new Paste($kout[1]); if (!empty($paste->crypt) && empty($_POST["passwd"]) && empty($t)) { ?> <!doctype html> <html> <head> <meta charset="UTF-8"> <title>.: Pommultimédia - Paste :.</title> <link href="style.css" rel="stylesheet" type="text/css"> <link href="favicon.ico" type="image/x-icon" rel="shortcut icon"/> </head> <body> <div id="corps" style="text-align: center;"> <h1> <?php echo htmlentities($paste->title); ?>
function post($data, $syntax, $ttl, $password, $cipher) { $template = $this->template; // This may be required if a user is dealing with a file that is so large that it takes more than 30 seconds set_time_limit(0); require_once __DIR__ . '/paste.class.php'; $pastes = new Paste(); // new post submission $paste = $pastes->add($data, $syntax, $ttl, $password, $cipher); // return our new ID to the user $output = array('id' => alphaID($paste, false)); $template->render(200, null, $output); }
$pastes = Paste::where('urlkey', '')->take(1000)->get(array('id', 'urlkey')); if ($pastes->count() > 0) { foreach ($pastes as $paste) { $paste->urlkey = Paste::makeUrlKey(); $paste->save(); } } else { break; } } // Get the FQDN for the server $fqdn = getenv('SERVER_NAME'); // Insert fqdn, app version and migration ID to site config // The migration ID is nothing but the max paste ID while updating // This will be used to allow/deny access to old pastes by their IDs Site::config('general', array('fqdn' => $fqdn, 'preMigrate' => Paste::max('id'))); // This is the v0.4 config file $configFile = app_path() . '/config/config.php'; // Now we migrate the old config data if (File::exists($configFile)) { include $configFile; // Import site settings Site::config('general', array_map('html_entity_decode', array('title' => $site_name, 'copyright' => $site_copyright, 'googleApi' => $google_api_key))); // Import antispam settings Site::config('antispam', array_map('html_entity_decode', array('services' => $sg_services, 'phpKey' => $sg_php_key, 'phpDays' => $sg_php_days, 'phpScore' => $sg_php_score, 'phpType' => $sg_php_type, 'censor' => $sg_censor))); // Import authentication settings Site::config('auth', array_map('html_entity_decode', array('method' => $auth_method, 'ldapServer' => $ldap_server, 'ldapPort' => $ldap_port, 'ldapBaseDn' => $ldap_base_dn, 'ldapUid' => $ldap_uid, 'ldapFilter' => $ldap_filter, 'ldapUserDn' => $ldap_user_dn, 'ldapPassword' => $ldap_password))); // Import SMTP settings Site::config('mail', array_map('html_entity_decode', array('host' => $smtp_host, 'port' => $smtp_port, 'encryption' => $smtp_crypt, 'username' => $smtp_username, 'password' => $smtp_password, 'address' => $smtp_from))); // If auth method is LDAP, notify the user to set // an admin filter.
/** * Save the current paste */ function save($filename = NULL) { $this->hash = base64_encode(sha1($this->content, true)); if (empty($filename)) { $i = 0; do { $filename = substr(str_replace("+", "", str_replace("/", "", $this->hash)), $i++, NB_CHAR); } while (is_file(Paste::get_path($filename)) && Paste::speed_cmp(Paste::get_path($filename), $this->hash)); } $this->filename = $filename; $xml = new DOMDocument('1.0', 'UTF-8'); $xml->formatOutput = true; $xml_paste = $xml->createElement("paste"); $xml_paste->appendChild($xml->createElement("title", $this->title)); $xml_paste->appendChild($xml->createElement("author", $this->author)); $xml_paste->appendChild($xml->createElement("language", $this->language)); $xml_paste->appendChild($xml->createElement("date", $this->date)); $xml_paste->appendChild($xml->createElement("ip", $this->ip)); $cnt = $xml->createElement("content"); $cnt->appendChild($xml->createCDATASection($this->content)); $xml_paste->appendChild($cnt); if (!empty($this->crypt)) { $xml_paste->appendChild($xml->createElement("crypt", base64_encode($this->crypt))); } if (!empty($this->ref)) { //Also indicate in the parent file $parent = new Paste($this->ref); //Does the parent exist? if ($parent->load()) { $xml_paste->appendChild($xml->createElement("ref", $this->ref)); if ($parent->add_answer($this->filename)) { $parent->save(); } } } foreach ($this->answers as $a) { $xml_paste->appendChild($xml->createElement("answer", $a)); } $xml_paste->appendChild($xml->createElement("hash", $this->hash)); if ($this->is_private()) { $xml_paste->appendChild($xml->createElement("private")); } $xml->appendChild($xml_paste); if ($xml->save(Paste::get_path($this->filename))) { return $this->filename; } else { die("Sorry, an error occured while saving the file. Please try again later."); return FALSE; } }
/** * Return count of active pastes * * @return int */ public function countActive() { $model = new Paste(); return $model->fetchActiveCount(); }
<?php return array('1800' => array('expire_30mins', TRUE), '21600' => array('expire_6hrs', TRUE), '86400' => array('expire_1day', TRUE), '604800' => array('expire_1week', TRUE), '2592000' => array('expire_1month', TRUE), '31536000' => array('expire_1year', TRUE), '0' => array('expire_forever', Paste::noExpire()));
/** * Tests the getFlagged method of the controller */ public function testGetFlagged() { $this->initTestStep(); $paste = Paste::createNew('web', array('title' => 'UnitTest::Title', 'data' => 'UnitTest::Data', 'language' => 'text')); $paste->flagged = 1; $paste->save(); $this->call('GET', 'flagged'); $this->assertResponseOk(); }
/** * Tests the postRevision method of the controller */ public function testPostRevision() { $this->initTestStep(); $paste = Paste::createNew('web', array('title' => 'UnitTest::Title', 'data' => 'UnitTest::Data', 'language' => 'text')); $this->session(array('paste.revision' => $paste->id)); $response = $this->call('POST', 'revise', array('id' => $paste->id, 'title' => 'UnitTest::Title', 'data' => 'UnitTest::Revision', 'language' => 'text')); $this->assertRedirectedTo($response->getTargetUrl()); $this->assertEquals(Revision::where('urlkey', $paste->urlkey)->count(), 1); }
}); /* |-------------------------------------------------------------------------- | Numeric paste ID filter |-------------------------------------------------------------------------- | | This filter gets a paste by its numeric ID. This is here purely for | backward compatibility as 0.4 and older versions had an optional / did | not have a alphanumeric URLkey. | */ Route::filter('numeric', function () { $key = Request::segment(1); $hash = Request::segment(2); if (is_numeric($key) and $key <= Site::config('general')->preMigrate) { $paste = Paste::findOrFail($key); return Redirect::to("{$paste->urlkey}/{$hash}"); } }); /* |-------------------------------------------------------------------------- | Setup validation filter |-------------------------------------------------------------------------- | | This filter checks if Sticky Notes is marked as installed. | | The following checks are done: | - If the main table does not exist, it is a fresh install | - If the main table is there, but versions mismatch, it is an update | - If main table is there and versions match, we should get out of setup |
/** * Tests the postPaste method of the controller */ public function testPostPaste() { $this->initTestStep(); $paste = Paste::createNew('web', array('title' => 'UnitTest::Title', 'data' => 'UnitTest::Data', 'language' => 'text')); $this->call('POST', 'admin/paste', array('search' => $paste->urlkey)); $this->assertRedirectedTo("admin/paste/{$paste->urlkey}"); }
return $fileout; } if (!preg_match("#begin{document}#ui", $content)) { $content = "\\documentclass[10pt]{report}\n\n\\usepackage[utf8x]{inputenc}\n\\usepackage[frenchb]{babel}\n\\usepackage{ucs}\n\\usepackage{amsmath}\n\\usepackage{amsfonts}\n\\usepackage{amssymb}\n\\usepackage{eurosym}\n\\usepackage{enumerate}\n\\usepackage{hyperref}\n\\usepackage{listings}\n\\usepackage{color}\n\\usepackage{array}\n\\usepackage{tikz}\n\n\\definecolor{dkgreen}{rgb}{0,0.6,0}\n\\definecolor{gray}{rgb}{0.5,0.5,0.5}\n\\definecolor{mauve}{rgb}{0.58,0,0.82}\n\n\\lstset{language=C++,keywordstyle=\\color{blue},stringstyle=\\color{mauve}}\n\\usetikzlibrary{arrows}\n\n\\begin{document}" . $content . "nd{document}"; } file_put_contents($filein, $content); print system("pdflatex -halt-on-error -output-directory ../gen " . $filein, $ret); if ($ret == 0) { return "../gen/" . basename(str_replace(".tex", "", $filein)) . ".pdf"; } else { return NULL; } } foreach ($_GET as $k => $t) { if (preg_match("#^([a-zA-Z0-9]{" . RGXP_NB . "})(:([a-zA-Z0-9]{" . RGXP_NB . "}))?\$#", $k, $kout) && is_file(Paste::get_path($kout[1]))) { $paste = new Paste($kout[1]); if (!empty($paste->crypt) && empty($_POST["passwd"]) && empty($t)) { ?> <!doctype html> <html> <head> <meta charset="UTF-8"> <title>.: Pommultimédia - Paste :.</title> <link href="style.css" rel="stylesheet" type="text/css"> <link href="favicon.ico" type="image/x-icon" rel="shortcut icon"> </head> <body> <div id="corps" style="text-align: center;"> <h1> <?php echo htmlentities($paste->title);
public function testActiveDataCountActionShouldReturnSimplyACount() { $data = $this->getData(); $model = new Paste(); $ids = array(); for ($i = 0; $i < 5; ++$i) { $ids[] = $model->add($data); } $this->dispatch('/paste/active-data-count/format/ajax'); $content = $this->response->getBody(); $this->assertEquals(5, $content); }
/** * Displays a list of flagged pastes * * @access public * @return \Illuminate\Support\Facades\View */ public function getFlagged() { $perPage = Site::config('general')->perPage; // Get all flagged pastes $query = Paste::where('flagged', 1); // Filter by project if (!empty($this->project)) { $query = $query->where('project', $this->project); } $pastes = $query->orderBy('id', 'desc')->paginate($perPage); return $this->getList($pastes, TRUE); }
/** * Creates a new paste with the data supplied * * @static * @param string $source * @param array $data * @return Illuminate\Database\Eloquent\Model */ public static function createNew($source, $data) { // Get the site's configuration $site = Site::config('general'); // Set the paste protected flag $protected = !empty($data['password']); // Set the private paste flag $private = !empty($data['private']); // We use an alphanumeric URL key to identify pastes // This is done so that users do not have access to the // actual primary key in the database and therefore, cannot // mass download all data $urlkey = static::makeUrlKey(); // This hash is used for identifying private pastes // Unless being opened by the paste author, sticky notes // makes passing this hass as a part of the URL mandatory // for private pastes $hash = static::getHash(); // Encrypt the password with a salt $password = ''; $salt = str_random(5); if (!empty($data['password'])) { $password = PHPass::make()->create($data['password'], $salt); } // Set the paste visibility based on the site's config switch ($site->pasteVisibility) { case 'public': $protected = $private = FALSE; $password = ''; break; case 'private': $private = TRUE; break; } // Set the paste author if (Auth::check()) { $user = Auth::user(); $authorId = $user->id; $author = $user->username; } else { $authorId = 0; $author = NULL; } // Set the paste expiration time default if (!isset($data['expire']) or $data['expire'] < 0) { $data['expire'] = $site->pasteAge; } // Check if we have an attachment if ($site->allowAttachment and isset($data['attachment']) and is_array($data['attachment'])) { $attachment = empty($data['attachment'][0]) ? 0 : 1; } else { $attachment = 0; } // Set up the new paste $paste = new Paste(); $paste->project = empty($data['project']) ? NULL : $data['project']; $paste->title = empty($data['title']) ? NULL : $data['title']; $paste->data = $data['data']; $paste->language = $data['language']; $paste->private = ($protected or $private) ? 1 : 0; $paste->password = $password; $paste->salt = $salt; $paste->hash = $hash; $paste->urlkey = $urlkey; $paste->author = $author; $paste->author_id = $authorId; $paste->timestamp = time(); $paste->expire = $data['expire'] > 0 ? time() + $data['expire'] : 0; $paste->ip = Request::getClientIp(); $paste->attachment = $attachment; $paste->hits = 0; $paste->flagged = 0; $paste->save(); // Insert paste count to the statistics table $stat = Statistics::firstOrNew(array('date' => date('Y-m-d'))); $stat->{$source}++; $stat->save(); // Return the created paste return $paste; }
/** * Handles POST actions for the user module * * @return \Illuminate\Support\Facades\Redirect */ public function postUser() { if (Input::has('_save')) { $id = Input::get('id'); // Define validation rules $validator = Validator::make(Input::all(), array('username' => 'required|max:50|alpha_dash|unique:users,username,' . $id . ',id,type,db', 'email' => 'required|max:100|email|unique:users,email,' . $id . ',id,type,db', 'dispname' => 'max:100', 'password' => empty($id) ? 'required|min:5' : 'min:5')); // Run the validator if ($validator->passes()) { // If ID is there, it is an update operation if (!empty($id)) { $user = User::findOrFail($id); $origUsername = $user->username; } else { $user = new User(); $origUsername = NULL; } $user->username = Input::get('username'); $user->email = Input::get('email'); $user->dispname = Input::get('dispname'); $user->salt = $user->salt ?: str_random(5); // The first user is always immutable $isFounder = $user->id == User::min('id'); $user->admin = $isFounder ?: Input::has('admin'); $user->active = $isFounder ?: Input::has('active'); if (Input::has('password')) { $user->password = PHPass::make()->create(Input::get('password'), $user->salt); } $user->save(); // Username is cached in the main, comment and revision tables, update them too if (!empty($id)) { Paste::where('author_id', $id)->update(array('author' => $user->username)); Revision::where('author', $origUsername)->update(array('author' => $user->username)); Comment::where('author', $origUsername)->update(array('author' => $user->username)); } Cache::flush(); Session::flash('messages.success', Lang::get('admin.user_saved')); return Redirect::to('admin/user'); } else { Session::flash('messages.error', $validator->messages()->all('<p>:message</p>')); return Redirect::to(URL::previous())->withInput(); } } else { if (Input::has('search')) { $username = Input::get('search'); return Redirect::to('admin/user/edit/' . urlencode($username)); } else { return Redirect::to('admin/user'); } } }