/** * saves user preferences * * @return Illuminate\View\View */ public function savePreferences() { $section_ids = function ($input) { $input_data = Input::get($input, ''); if (strlen($input_data) == 0) { return ""; } $arr = explode(',', $input_data); return implode(',', array_unique(F::map($this->section->getByTitle($arr), function ($m) { return $m->id; }))); }; $show_nsfw = Input::get('show_nsfw', 0); $show_nsfl = Input::get('show_nsfl', 0); $frontpage_show_sections = $section_ids('frontpage_show_sections'); $frontpage_ignore_sections = $section_ids('frontpage_ignore_sections'); if ($frontpage_show_sections == "0") { $frontpage_show_sections = ""; } if ($frontpage_ignore_sections == "0") { $frontpage_ignore_sections = ""; } $this->user->savePreferences(Auth::id(), ['show_nsfw' => $show_nsfw, 'show_nsfl' => $show_nsfl, 'frontpage_show_sections' => $frontpage_show_sections, 'frontpage_ignore_sections' => $frontpage_ignore_sections]); $sections = $this->section->get(); $section = $this->section->sectionFromEmptySection(); return View::make('page.user.prefs.savedpreferences', ['sections' => $sections, 'section' => $section]); }
/** * generate xss/atom from spreadit * * @param string $section_title * @return Roumen\Feed */ protected function generate($section_title) { $sections = $this->section->getByTitle(Utility::splitByTitle($section_title)); if (empty($sections)) { App::abort(404); } $section = $this->section->sectionFromSections($sections); $posts = $this->post->getHotList(F::map($sections, function ($m) { return $m->id; }), $this->vote); $feed = Feed::make(); $feed->title = $section_title; $feed->description = "read hot posts from {$section_title}"; $feed->link = URL::to("/s/{$section_title}"); $feed->lang = 'en'; $created_at_counter = 0; foreach ($posts as $post) { $feed->add($post->title, $post->username, URL::to($post->url), date(DATE_ATOM, $post->created_at), $post->markdown); if ($post->created_at > $created_at_counter) { $created_at_counter = $post->created_at; } } $feed->pubdate = date(DATE_ATOM, $created_at_counter); return $feed; }
public function render($branch = null, $first = false) { if ($branch == null) { $branch = $this; } $rval = $first ? View::make('comment.piece', ['comment' => $branch]) : ''; if (count($branch->children) > 0) { $result = F::reduce_left(F::map($branch->children, function ($v) { $tresult = $this->render($v, true); return "<div class='child'>{$tresult}<div class='clearleft'></div></div>"; }), function ($v, $i, $c, $r) { return $r . $v; }); $rval .= $result; } $rval .= "<div class='clearleft'></div>"; return $rval; }
public function getMatchingVotes($type, $items) { //requires to be logged in if (!Auth::check()) { return array(); } $items_to_check = F::map($items, function ($m) { return $m->id; }); if (count($items_to_check) == 0) { $items_to_check = array(0); } $votes = DB::table('votes')->select('item_id', 'updown')->where('user_id', '=', Auth::user()->id)->where('type', '=', $type)->whereIn('item_id', $items_to_check)->get(); $rval = array(); foreach ($votes as $i) { $rval[$i->item_id] = $i->updown; } return $rval; }
public function sectionFromSections(array $sections) { if (count($sections) == 0) { $section = new stdClass(); $section->id = -1; $section->multi_spreadit = false; $section->title = ""; } else { if (count($sections) == 1) { $section = $sections[0]; } else { if (count($sections) > 1) { $section = new stdClass(); $section->id = -1; $section->multi_spreadit = true; $section->title = implode('+', F::map($sections, function ($m) { return $m->title; })); } } } return $section; }
/** * renders a section page * * @param string $section_title * @param string $sort_mode * @param string $timeframe_mode * @param bool $no_view * @return mixed */ protected function get($section_title, $sort_mode, $timeframe_mode, $no_view) { $sections = $this->section->getByTitle(Utility::splitByTitle($section_title)); if (empty($sections)) { App::abort(404); } $sections = $this->vote->getSelectedList(Constant::SECTION_TYPE, $sections); $section = $this->section->sectionFromSections($sections); $section->selected = $this->vote->getSelected(Constant::SECTION_TYPE, $section); if (is_null($sort_mode)) { $sort_mode = Utility::getSortMode(); } if (is_null($timeframe_mode)) { $timeframe_mode = Utility::getSortTimeframe(); } $section_ids = F::map($sections, function ($m) { return $m->id; }); $posts = $this->getPosts($sort_mode, $section_ids, $this->getSecondsFromTimeframe($timeframe_mode)); if ($no_view) { return $posts; } return Response::make(View::make('page.section', ['sections' => $this->section->get(), 'posts' => $posts, 'section' => $section, 'sort_highlight' => $sort_mode, 'sort_timeframe_highlight' => $timeframe_mode]))->withCookie(Cookie::make('posts_sort_mode', $sort_mode))->withCookie(Cookie::make('posts_sort_timeframe', $timeframe_mode)); }