function rss_bootstrap($withDB = true, $etag_prefix = "", $cacheValidity = 0) { require_once GREGARIUS_HOME . 'constants.php'; if ($withDB) { require_once GREGARIUS_HOME . 'db.php'; } if (!defined('RSS_NO_CACHE')) { checkETag($withDB, $etag_prefix, $cacheValidity); } }
function view($name) { /* Redirect numeric id instead of showing pages (below) */ if (is_numeric($name)) { $this->load->database(); $query = $this->db->query('SELECT `name` FROM aboutpages WHERE `id` = ' . $this->db->escape($name) . ' LIMIT 1'); if ($query->num_rows() === 0) { show_404(); } header('Location: ' . site_url('about/' . $query->row()->name)); return; } $this->load->library('cache'); $this->load->helper('gfx'); if (checkETag($name, 'about')) { return; } $data = $this->cache->get($name, 'about'); if (!$data) { $this->load->database(); $about = $this->db->query('SELECT * FROM aboutpages WHERE `name` = ' . $this->db->escape($name) . ' LIMIT 1'); if ($about->num_rows() === 0) { show_404(); } $this->load->config('gfx'); $data = array('meta' => $this->load->view('about/meta.php', $about->row_array(), true), 'content' => $this->load->view('about/content.php', $about->row_array(), true), 'admin' => $this->load->view('about/admin.php', $about->row_array(), true)); $data['expiry'] = $this->cache->save($about->row()->name, $data, 'about', $this->config->item('gfx_cache_time')); $data['db'] = 'content '; } else { $data['expiry'] = $this->cache->get_expiry($name, 'about'); } if ($this->session->userdata('admin') !== 'Y') { unset($data['admin']); } $this->load->library('parser'); $this->parser->page($data, $this->session->userdata('id')); }
function view($id, $type = '') { /* Redirect numeric id */ if (is_numeric($id)) { $this->load->database(); $query = $this->db->query('SELECT `name` FROM features WHERE `id` = ' . $this->db->escape($id) . ' LIMIT 1'); if ($query->num_rows() === 0) { show_404(); } switch ($type) { case 'inframe': header('Location: ' . site_url('feature/' . $query->row()->name . '/inframe')); break; default: header('Location: ' . site_url('feature/' . $query->row()->name)); break; } return; } $this->load->library('cache'); switch ($type) { case 'inframe': if (isset($_SERVER['HTTP_IF_NONE_MATCH']) && trim($_SERVER['HTTP_IF_NONE_MATCH']) === md5($this->cache->get_expiry($id, 'feature-inframe'))) { header("HTTP/1.1 304 Not Modified"); return; } $data = $this->cache->get($id, 'feature-inframe'); if (!$data) { $this->load->database(); $feature = $this->db->query('SELECT * FROM features WHERE `name` = ' . $this->db->escape($id) . ' LIMIT 1'); if ($feature->num_rows() === 0) { show_404(); } $data = $this->load->view('feature/inframe.php', $feature->row_array(), true); $this->load->config('gfx'); $expiry = $this->cache->save($feature->row()->name, $data, 'feature-inframe', $this->config->item('gfx_cache_time')); } else { $expiry = $this->cache->get_expiry($id, 'feature-inframe'); } header('ETag: ' . md5($expiry)); //TBD: this will introduce GZip error print $data; break; default: $this->load->helper('gfx'); if (checkETag($id, 'feature')) { return; } $data = $this->cache->get($id, 'feature'); if (!$data) { $this->load->database(); $feature = $this->db->query('SELECT * FROM features WHERE `name` = ' . $this->db->escape($id) . ' LIMIT 1'); if ($feature->num_rows() === 0) { show_404(); } $this->load->config('gfx'); $data = array('meta' => $this->load->view('feature/meta.php', $feature->row_array(), true), 'content' => $body = $this->load->view('feature/content.php', $feature->row_array(), true), 'admin' => $this->load->view('feature/admin.php', $feature->row_array(), true)); $data['expiry'] = $this->cache->save($feature->row()->name, $data, 'feature', $this->config->item('gfx_cache_time')); $data['db'] = 'content '; } else { $data['expiry'] = $this->cache->get_expiry($id, 'feature'); } if ($this->session->userdata('admin') !== 'Y') { unset($data['admin']); } $this->load->library('parser'); $this->parser->page($data, $this->session->userdata('id')); break; } }
function view($name = '') { /* xrds doc request, usually done by OpenID 2.0 op who checks "Relay Party" */ if (isset($_SERVER['HTTP_ACCEPT']) && strpos($_SERVER['HTTP_ACCEPT'], 'application/xrds+xml') !== false) { header('X-XRDS-Location: ' . site_url('auth/xrds')); header('Content-Type: text/plain'); //print 'You should find the location of xrds doc in the header. I could place a <meta> tag here but I am lazy and you are dumb.'; //TBD: <meta http-equiv="X-XRDS-Location" content=""/> return; } $this->load->library('cache'); $this->load->helper('gfx'); if (checkETag($name, 'user')) { return; } $data = $this->cache->get(strtolower($name), 'user'); //$data = null; // no cache if (!$data) { $data = array(); $this->load->config('gfx'); if (!preg_match('/^[a-zA-Z0-9_\\-]+$/', $name) || strlen($name) < 3 || strlen($name) > 200 || substr($name, 0, 8) === '__temp__' || in_array($name, $this->config->item('gfx_badname'))) { show_404(); } $this->load->database(); $user = $this->db->query('SELECT * FROM users WHERE `ready` = \'Y\' AND `name` = ' . $this->db->escape($name) . ' LIMIT 1'); if ($user->num_rows() === 0) { //TBD: pretty error for userpages, indicate this name is available show_404(); } $U = $user->row_array(); /* Instead of evaluate space before/after case by case we add the space and rely on Browser's white-space processing */ mb_internal_encoding('UTF-8'); if (mb_strwidth(mb_substr($U['title'], 0, 1)) === 1) { $U['title'] = ' ' . $U['title']; } if (mb_strwidth(mb_substr($U['title'], -1, 1)) === 1) { $U['title'] .= ' '; } $user->free_result(); $F = array(); for ($i = 0; $i < 3; $i++) { $feature = $this->db->query('SELECT name, title, description FROM features ' . 'WHERE `id` = ' . $U['feature_' . $i] . ';'); $F[] = $feature->row_array(); $feature->free_result(); } unset($feature); // get groups to see if user has more than one group. $groups = $this->db->query('SELECT t1.id, t1.name, t1.title, t1.description FROM groups t1, u2g t2 ' . 'WHERE t2.group_id = t1.id AND t2.user_id = ' . $U['id'] . ' ORDER BY t2.order ASC;'); $G = array(); foreach ($groups->result_array() as $group) { if (!isset($A[$group['id']])) { $A[$group['id']] = array(); } $G[] = $group; } $groups->free_result(); unset($groups, $group); if (sizeof($G) > 1) { // more than one group -> old layout $addons = $this->db->query('SELECT t1.*, t2.group_id FROM addons t1, u2a t2 ' . 'WHERE t2.addon_id = t1.id AND t2.user_id = ' . $U['id'] . ' ORDER BY t2.order ASC;'); $A = array(); foreach ($addons->result_array() as $addon) { if (!isset($A[$addon['group_id']])) { $A[$addon['group_id']] = array(); } $A[$addon['group_id']][] = $addon; } $addons->free_result(); unset($addons, $addon); } else { // only one group -> new layout $groups = $this->db->query('SELECT t1.id, t1.name, t1.title, t1.description FROM groups t1 WHERE t1.id = 1;'); $G = array(); foreach ($groups->result_array() as $group) { if (!isset($A[$group['id']])) { $A[$group['id']] = array(); } $G[] = $group; } $groups->free_result(); unset($groups, $group); $addons = $this->db->query('SELECT t1.*, t2.group_id FROM addons t1, u2a t2 ' . 'WHERE t2.addon_id = t1.id AND t2.user_id = ' . $U['id'] . ' ORDER BY t2.order ASC;'); $A = array(); foreach ($addons->result_array() as $addon) { if (!isset($A[$addon['group_id']])) { $A[$addon['group_id']] = array(); } $A[1][] = $addon; } $addons->free_result(); unset($addons, $addon); } $this->load->_ci_cached_vars = array(); //Clean up cached vars $data['name'] = $U['name']; $data['meta'] = $this->load->view('user/meta.php', $U, true); $data['admin'] = $this->load->view('user/admin.php', $U, true); $data['content'] = $this->load->view('user/content.php', array_merge($U, array('features' => $F, 'groups' => $G, 'addons' => $A)), true); $this->load->config('gfx'); $data['expiry'] = $this->cache->save(strtolower($U['name']), $data, 'user', $this->config->item('gfx_cache_time')); $data['db'] = 'content '; } else { $data['expiry'] = $this->cache->get_expiry($name, 'user'); } //name caps check if (isset($data['name']) && $data['name'] !== $name) { header('Location: ' . site_url($data['name'])); return; } if ($this->session->userdata('admin') !== 'Y') { unset($data['admin']); } if ($this->session->userdata('name') && $name === $this->session->userdata('name')) { $data['messages'] = array(array('type' => 'highlight', 'icon' => 'info', 'message' => $this->lang->line('gfx_message_userpage_yourpage'))); } $this->load->library('parser'); if ($this->session->userdata('id') && isset($user) && $U['id'] == $this->session->userdata('id')) { $this->parser->page($data, $this->session->userdata('id'), $user->row_array()); } else { $this->parser->page($data, $this->session->userdata('id')); } }