<commit_before><?php
	/**
	 * Class: Main Controller
	 * The logic behind the Chyrp install.
	 */
	class MainController {
		/**
		 * Function: index
		 * Grabs the posts for the main page.
		 */
		public function index() {
			global $posts;
			$posts = new Paginator(Post::find(array("placeholders" => true)), Config::current()->posts_per_page);
		}

		/**
		 * Function: archive
		 * Grabs the posts for the Archive page when viewing a year or a month.
		 */
		public function archive() {
			global $posts;
			if (!isset($_GET['month'])) return;

			if (isset($_GET['day']))
				$posts = new Paginator(Post::find(array("placeholders" => true,
				                                        "where" => "`__posts`.`created_at` like :date",
				                                        "params" => array(":date" => $_GET['year']."-".$_GET['month']."-".$_GET['day']."%"))),
				                       Config::current()->posts_per_page);
			else
				$posts = new Paginator(Post::find(array("placeholders" => true,
				                                        "where" => "`__posts`.`created_at` like :date",
				                                        "params" => array(":date" => $_GET['year']."-".$_GET['month']."%"))),
				                       Config::current()->posts_per_page);
		}

		/**
		 * Function: search
		 * Grabs the posts for a search query.
		 */
		public function search() {
			global $posts;
			fallback($_GET['query'], "");
			$posts = new Paginator(Post::find(array("placeholders" => true,
			                                        "where" => "`xml` LIKE :query",
			                                        "params" => array(":query" => '%'.htmlspecialchars(urldecode($_GET['query'])).'%'))),
				                   Config::current()->posts_per_page);
		}

		/**
		 * Function: drafts
		 * Grabs the posts for viewing the Drafts lists. Shows an error if the user lacks permissions.
		 */
		public function drafts() {
			$visitor = Visitor::current();
			if (!$visitor->group()->can("view_own_draft", "view_draft"))
				error(__("Access Denied"), __("You do not have sufficient privileges to view drafts."));

			global $posts;
			$posts = new Paginator(Post::find(array("placeholders" => true,
			                                        "where" => array("`__posts`.`status` = 'draft'", "`__posts`.`user_id` = :current_user"),
			                                        "params" => array(":current_user" => $visitor->id))),
				                   Config::current()->posts_per_page);
		}

		/**
		 * Function: feather
		 * Views posts of a specific feather.
		 */
		public function feather() {
			global $posts;
			$posts = new Paginator(Post::find(array("placeholders" => true,
			                                        "where" => "`feather` = :feather",
			                                        "params" => array(":feather" => depluralize($_GET['action'])))),
				                   Config::current()->posts_per_page);
		}

		/**
		 * Function: feed
		 * Grabs posts for the feed.
		 */
		public function feed() {
			global $posts;
			$posts = new Paginator(Post::find(array("placeholders" => true)), Config::current()->posts_per_page);
		}

		/**
		 * Function: view
		 * Views a post.
		 */<commit_msg>Added a backwards-compatibility thing for /rss.<commit_after><?php
	/**
	 * Class: Main Controller
	 * The logic behind the Chyrp install.
	 */
	class MainController {
		/**
		 * Function: index
		 * Grabs the posts for the main page.
		 */
		public function index() {
			global $posts;
			$posts = new Paginator(Post::find(array("placeholders" => true)), Config::current()->posts_per_page);
		}

		/**
		 * Function: archive
		 * Grabs the posts for the Archive page when viewing a year or a month.
		 */
		public function archive() {
			global $posts;
			if (!isset($_GET['month'])) return;

			if (isset($_GET['day']))
				$posts = new Paginator(Post::find(array("placeholders" => true,
				                                        "where" => "`__posts`.`created_at` like :date",
				                                        "params" => array(":date" => $_GET['year']."-".$_GET['month']."-".$_GET['day']."%"))),
				                       Config::current()->posts_per_page);
			else
				$posts = new Paginator(Post::find(array("placeholders" => true,
				                                        "where" => "`__posts`.`created_at` like :date",
				                                        "params" => array(":date" => $_GET['year']."-".$_GET['month']."%"))),
				                       Config::current()->posts_per_page);
		}

		/**
		 * Function: search
		 * Grabs the posts for a search query.
		 */
		public function search() {
			global $posts;
			fallback($_GET['query'], "");
			$posts = new Paginator(Post::find(array("placeholders" => true,
			                                        "where" => "`xml` LIKE :query",
			                                        "params" => array(":query" => '%'.htmlspecialchars(urldecode($_GET['query'])).'%'))),
				                   Config::current()->posts_per_page);
		}

		/**
		 * Function: drafts
		 * Grabs the posts for viewing the Drafts lists. Shows an error if the user lacks permissions.
		 */
		public function drafts() {
			$visitor = Visitor::current();
			if (!$visitor->group()->can("view_own_draft", "view_draft"))
				error(__("Access Denied"), __("You do not have sufficient privileges to view drafts."));

			global $posts;
			$posts = new Paginator(Post::find(array("placeholders" => true,
			                                        "where" => array("`__posts`.`status` = 'draft'", "`__posts`.`user_id` = :current_user"),
			                                        "params" => array(":current_user" => $visitor->id))),
				                   Config::current()->posts_per_page);
		}

		/**
		 * Function: feather
		 * Views posts of a specific feather.
		 */
		public function feather() {
			global $posts;
			$posts = new Paginator(Post::find(array("placeholders" => true,
			                                        "where" => "`feather` = :feather",
			                                        "params" => array(":feather" => depluralize($_GET['action'])))),
				                   Config::current()->posts_per_page);
		}

		/**
		 * Function: feed
		 * Grabs posts for the feed.
		 */
		public function feed() {
			global $posts;
			$posts = new Paginator(Post::find(array("placeholders" => true)), Config::current()->posts_per_page);
		}

		/**
		 * Function: rss
		 * Redirects to /feed (backwards compatibility).
		 */
		public function rss() {
			redirect(Route::current()->url("feed/"));
		}

		/**
		 * Function: view
		 * Views a post.
		 */
{'fraction_non_alphanumeric': 0.16963208685162848, 'fraction_numerical': 0.0, 'mean_word_length': 2.0136301681054065, 'pattern_counts': {'":': 10, '<': 5, '<?xml version=': 0, '>': 68, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5741429', 'n_tokens_mistral': 2148, 'n_tokens_neox': 1741, 'n_words': 430}