Exemplo n.º 1
0
 public function action_delete()
 {
     if (!user::logged('admin')) {
         ajax::error(__('You must be logged in to delete content'));
     }
     if ($_POST) {
         $delete = arr::get($_POST, 'delete', false);
         if ($delete) {
             try {
                 if (is_array($delete)) {
                     foreach ($delete as $id) {
                         $content = ORM::factory('Content', $id);
                         if ($content->loaded()) {
                             $content->delete();
                         }
                     }
                 } else {
                     $content = ORM::factory('Content', $delete);
                     if ($content->loaded()) {
                         $content->delete();
                     }
                 }
                 ajax::success(__('The content has been deleted'));
             } catch (exception $e) {
                 ajax::error(__('An error occurred and the content couldn\'t be deleted: :errormessage', array(':errormessage' => $e->getMessage())));
             }
         }
         ajax::error(__('No data recieved'));
     }
 }
Exemplo n.º 2
0
 public function action_twittercallback()
 {
     if (arr::get($_GET, 'denied', false)) {
         notes::error('Seems like you didn\'t want to log in with Twitter anyway. Feel free to try again if it was a mistake!');
         site::redirect();
     }
     $token = arr::get($_GET, 'oauth_token', false);
     $verifier = arr::get($_GET, 'oauth_verifier', false);
     if (!$token || !$verifier) {
         notes::error('Something went wrong in the process, and we didn\'t get the expected data back from Twitter. Please try again');
         site::redirect();
     }
     $connection = new TwitterOAuth(arr::get($this->creds, 'key'), arr::get($this->creds, 'secret'), Session::instance()->get_once('twitter_oauth_token'), Session::instance()->get_once('twitter_oauth_token_secret'));
     $token = $connection->getAccessToken($verifier);
     $oauth_token = arr::get($token, 'oauth_token', '');
     $oauth_token_secret = arr::get($token, 'oauth_token_secret', '');
     $user_id = arr::get($token, 'user_id', '');
     $screen_name = arr::get($token, 'screen_name', '');
     $oauth = ORM::factory('Oauth')->where('type', '=', 'twitter')->where('token', '=', $oauth_token)->find();
     if ($oauth->loaded()) {
         try {
             $user = $oauth->user;
             user::force_login($user);
         } catch (exception $e) {
             if ($user->loaded()) {
                 if (user::logged()) {
                     // Random error, but user got logged in. We don't care, YOLO!
                 } else {
                     notes::error('Whoops! Something wen\'t wrong and we couldn\'t log you in. Please try again or send us a message if the problem persists.');
                     Kohana::$log->add(Log::ERROR, '1. Couldnt log user in: ' . $e->getMessage());
                 }
             }
         }
         site::redirect('write');
     } else {
         try {
             $user = ORM::factory('User');
             $user->username = $screen_name;
             $user->validation_required(false)->save();
             $user->add_role('login');
             $oauth = ORM::factory('Oauth');
             $oauth->user_id = $user->id;
             $oauth->type = 'twitter';
             $oauth->token = $oauth_token;
             $oauth->token_secret = $oauth_token_secret;
             $oauth->service_id = $user_id;
             $oauth->screen_name = $screen_name;
             $oauth->save();
             user::force_login($user);
         } catch (exception $e) {
             Kohana::$log->add(Log::ERROR, '2. Couldnt create user: '******'Whoops! Something wen\'t wrong and we couldn\'t log you in. Please try again or send us a message if the problem persists.');
         }
         site::redirect('/write');
     }
 }
Exemplo n.º 3
0
 public function action_write()
 {
     $errors = false;
     $page = false;
     if (user::logged()) {
         $page = $this->request->param('page');
         if ($_POST && strlen(arr::get($_POST, 'content', '')) > 0) {
             $content = arr::get($_POST, 'content', '');
             if ($page->type == 'page') {
                 $raw = $page->rawcontent();
                 if ($raw != "") {
                     $content = $raw . "\n" . $content;
                 }
             } else {
                 if ($page->type == 'autosave') {
                     $page->type = 'page';
                 }
             }
             try {
                 $page->wordcount = site::count_words($content);
                 $page->content = $content;
                 if ($page->wordcount >= 750 && !(bool) $page->counted) {
                     user::update_stats($page);
                     $page->counted = 1;
                 }
                 $page->duration = $page->duration + (time() - arr::get($_POST, 'start', 999));
                 $page->update();
                 $oldsaves = ORM::factory('Page')->where('type', '=', 'autosave')->where('user_id', '=', user::get()->id)->find_all();
                 if ((bool) $oldsaves->count()) {
                     foreach ($oldsaves as $old) {
                         $old->delete();
                     }
                 }
                 achievement::check_all(user::get());
                 notes::success('Your page has been saved!');
                 //site::redirect('write/'.$page->day);
             } catch (ORM_Validation_Exception $e) {
                 $errors = $e->errors('models');
             }
         }
     } else {
         if ($_POST) {
             notes::error('You must be logged in to save your page. Please log in and submit again.');
         }
     }
     $this->bind('errors', $errors);
     $this->bind('page', $page);
     $this->template->daystamp = $this->request->param('daystamp');
     $this->template->page = $page;
     seo::instance()->title("Write Your Morning Pages");
     seo::instance()->description("Morning Pages is about writing three pages of stream of consciousness thought every day. Become a better person by using MorninPages.net");
 }
Exemplo n.º 4
0
 public function action_getautosave()
 {
     if (!user::logged()) {
         ajax::error('You must be logged in');
     }
     $user = user::get();
     $autosave = ORM::factory('Page')->where('user_id', '=', $user->id)->where('type', '=', 'autosave')->find();
     $content = '';
     if ($autosave->loaded() && $autosave->content != '') {
         $content = $autosave->decode($autosave->content);
         $autosave->delete();
     }
     ajax::success('', array('content' => $content, 'md5' => md5($content)));
 }
Exemplo n.º 5
0
 public function require_login($msg = true, $redirect = false)
 {
     if ($msg === true) {
         $msg = 'You must be logged in to see this page';
     }
     if (!user::logged()) {
         if ($msg) {
             notes::error($msg);
         }
         if ($redirect) {
             site::redirect($redirect);
         } else {
             user::redirect('login');
         }
     }
 }
Exemplo n.º 6
0
 public static function update_stats($page)
 {
     if (!user::logged()) {
         return;
     }
     $user = self::get();
     $yesterdayslug = site::day_slug(strtotime('-1 day', $user->timestamp()));
     $yesterday = ORM::factory('Page')->where('user_id', '=', $user->id)->where('day', '=', $yesterdayslug)->where('type', '=', 'page')->find();
     if ($yesterday->loaded()) {
         $user->current_streak += 1;
         if ($user->doing_challenge()) {
             $challenge = $user->challenge;
             $challenge->progress += 1;
             if ($challenge->progress >= 30) {
                 if ($user->option('completedchallenge') == 0) {
                     notes::success('You have completed the 30 day challenge and have been added to our ' . HTML::anchor('challenge/wall-of-fame', 'wall of fame') . '! Congratulations!');
                     $options = $user->option;
                     $options->completedchallenge = $user->timestamp();
                     $options->save();
                 } else {
                     notes::success('You have completed the 30 day challenge! Congratulations!');
                 }
                 user::award_points(100, 'Completed the 30 day challenge! (+100 points)', $user);
                 $challenge->delete();
             } else {
                 $challenge->save();
             }
         }
         if ($user->current_streak > $user->longest_streak) {
             $user->longest_streak = $user->current_streak;
         }
     } else {
         $user->current_streak = 1;
         if ($user->doing_challenge()) {
             $challenge = $user->challenge;
             $challenge->progress = 1;
             $challenge->save();
         }
     }
     $user->all_time_words += $page->wordcount;
     if ($page->wordcount > $user->most_words) {
         notes::success('You have written more today than you ever have before! Good job!');
         $user->most_words = $page->wordcount;
     }
     $user->save();
 }
Exemplo n.º 7
0
 public function before()
 {
     if (!user::logged('admin') && $this->request->action() !== 'media') {
         site::redirect();
     }
     if ($this->request->action() === 'media' || $this->request->action() === 'uploads') {
         // Do not template media files
         $this->auto_render = FALSE;
     } else {
         parent::before();
         $this->template->controller = str_replace('cms_', '', $this->request->controller());
         $this->template->action = $this->request->action();
         $file = $this->template->controller . '/' . $this->template->action;
         $file = str_replace('_', '/', $file);
         if (file_exists(Kohana::find_file('views', $file))) {
             $this->template->view = View::factory($file);
         }
     }
 }
Exemplo n.º 8
0
 public static function save_update_current()
 {
     if (true || !user::logged('admin')) {
         $session = Session::instance();
         $visitor = ORM::factory('Visitor', $session->get('active_visitor'));
         $base = request::detect_uri();
         $queries = isset($_GET) && !empty($_GET) ? '?' . http_build_query($_GET) : '';
         $uri = request::detect_uri() . $queries;
         //substr($base, 1, strlen($base))
         if ($visitor->loaded() && $uri == $visitor->page) {
             // This is just a reload of the current page.
             return;
         }
         if (!$visitor->loaded()) {
             $numvisits = cookie::get('numvisits');
             if (!$numvisits) {
                 $numvisits = 0;
             }
             cookie::set('numvisits', $numvisits + 1);
             $visitor->numvisits = $numvisits + 1;
             $visitor->start = time();
             $visitor->referrer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';
             $visitor->ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '';
             $visitor->geolocation = 'todo';
         }
         if (empty($visitor->client)) {
             $visitor->client = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '';
         }
         $visitor->page = $uri;
         if (user::logged()) {
             $visitor->user_id = user::get()->id;
         }
         $history = json_decode($visitor->history);
         if (!is_array($history)) {
             $history = array();
         }
         $history[] = $uri;
         $visitor->history = json_encode($history);
         $visitor->time = time();
         $visitor->save();
         $session->set('active_visitor', $visitor->id);
     }
 }
Exemplo n.º 9
0
 public function action_info()
 {
     maintenance::delete_inactive_visitors();
     $messages = 0;
     if (user::logged()) {
         $user = user::get();
         $messages += $user->messages->where('read', '=', '0')->count_all();
         $roles = $user->roles->find_all();
         $roleids = array();
         if ((bool) $roles->count()) {
             foreach ($roles as $role) {
                 $roleids[] = $role->id;
             }
         }
         if ((bool) count($roleids)) {
             $messages += ORM::factory('Message')->where('role_id', 'in', $roleids)->where('read', '=', '0')->where('user_id', '!=', $user->id)->count_all();
         }
     }
     ajax::success('', array('current_visitors' => $visitors = ORM::factory('Visitor')->count_all(), 'unread_messages' => $messages));
 }
Exemplo n.º 10
0
 public function action_takechallenge()
 {
     if (!user::logged()) {
         ajax::error('You must be logged in to sign up for the challenge!');
     }
     $user = user::get();
     if ($user->doing_challenge()) {
         ajax::error('You are already doing the challenge! Complete it first, then sign up again.');
     }
     $challenge = ORM::factory('User_Challenge');
     $challenge->user_id = $user->id;
     $challenge->start = $user->timestamp();
     $challenge->progress = 0;
     if ($user->wrote_today()) {
         $challenge->progress = 1;
     }
     $challenge->save();
     $user->add_event('Signed up for the 30 day challenge!');
     ajax::success('Awesome! You have signed up for the challenge! Good luck!', array('progress' => $challenge->progress));
 }
Exemplo n.º 11
0
 public function action_xml()
 {
     if (!user::logged()) {
         ajax::error('You must be logged in to use this feature');
     }
     $user = user::get();
     $pages = $user->pages->where('type', '=', 'page')->find_all();
     $xml = '<?xml version="1.0" encoding="UTF-8"?>';
     $xml .= '<channel>';
     $namelen = strlen($user->username);
     $possessive = $user->username . "'s";
     if (substr($user->username, $namelen - 1, $namelen) == 's') {
         $possessive = $user->username . "'";
     }
     $xml .= '<title>' . $possessive . ' morning pages</title>';
     $xml .= '<language>en-US</language>';
     $xml .= '<author>' . $user->username . '</author>';
     $xml .= '<pages>';
     if ((bool) $pages->count()) {
         foreach ($pages as $page) {
             $xml .= '<page>';
             $xml .= '<published>';
             $xml .= '<date>' . $page->daystamp() . '</date>';
             $xml .= '<timestamp>' . $page->created . '</timestamp>';
             $xml .= '</published>';
             $xml .= '<content><![CDATA[' . $page->rawcontent() . ']]></content>';
             $xml .= '<wordcount>' . $page->wordcount . '</wordcount>';
             $xml .= '</page>';
         }
     }
     $xml .= '</pages>';
     $xml .= '</channel>';
     $this->response->headers('Content-Type', 'text/xml');
     $this->response->body($xml);
     $this->response->send_file(true, 'pages.xml');
 }
Exemplo n.º 12
0
 public function action_savesetting()
 {
     if (!user::logged()) {
         ajax::error('You must be logged in');
     }
     $user = user::get();
     $option = $user->option;
     $setting = arr::get($_POST, 'setting', false);
     $value = arr::get($_POST, 'value', false);
     if (!$setting || $value === false) {
         ajax::error('Something wen\'t wrong and your setting couldn\'t be saved. I received no data!');
     }
     $update_timestamp = false;
     switch ($setting) {
         case 'reminder':
             $option->reminder = $value;
             $update_timestamp = true;
             break;
         case 'reminder_hour':
             $option->reminder_hour = $value;
             $update_timestamp = true;
             break;
         case 'reminder_minute':
             $option->reminder_minute = $value;
             $update_timestamp = true;
             break;
         case 'reminder_meridiem':
             $option->reminder_meridiem = $value;
             $update_timestamp = true;
             break;
         case 'timezone_id':
             $option->timezone_id = $value;
             $update_timestamp = true;
             break;
         case 'privacymode':
             $option->privacymode = $value;
             break;
         case 'privacymode_minutes':
             $option->privacymode_minutes = $value;
             break;
         case 'hemingwaymode':
             $option->hemingwaymode = $value;
             break;
         case 'public':
             $option->public = $value;
             break;
         case 'rtl':
             $option->rtl = $value;
             break;
         case 'language':
             $option->language = (int) $value;
             break;
         default:
             ajax::error('Something wen\'t wrong and your setting couldn\'t be saved. I received no data!');
             break;
     }
     try {
         if ($update_timestamp) {
             $option->next_reminder = $user->get_next_reminder($user);
         }
         $option->save();
         ajax::success('Saved');
     } catch (ORM_Validation_Exception $e) {
         ajax::error('An error occurred and your setting couldn\'t be saved.', array('errors' => $e->errors()));
     }
 }
Exemplo n.º 13
0
 public function action_talk()
 {
     $tag = $this->request->param('tag');
     $talk = $this->request->param('talk');
     if (user::logged()) {
         // Iterate views
         if ($talk->user_id != user::get()->id) {
             $talk->views = $talk->views + 1;
             try {
                 $talk->save();
             } catch (ORM_Validation_Exception $e) {
                 //var_dump($e->errors());
             }
         }
         // Set when the user last saw the topic
         $user = user::get();
         $viewed = $user->talkviews->where('talk_id', '=', $talk->id)->find();
         if (!$viewed->loaded()) {
             $viewed->user_id = $user->id;
             $viewed->talk_id = $talk->id;
         }
         $viewed->last = time();
         $viewed->save();
     }
     $replies = $talk->replies->where('op', '!=', 1);
     $counter = $talk->replies->where('op', '!=', 1);
     $limit = Kohana::$config->load('talk')->get('pagination_limit');
     $numreplies = $counter->count_all();
     $numpages = ceil($numreplies / $limit);
     $page = (int) arr::get($_GET, 'page', 0);
     if ($_POST) {
         $this->require_login();
         $reply = ORM::factory('Talkreply');
         $reply->values($_POST);
         $reply->user_id = user::get()->id;
         $reply->talk_id = $talk->id;
         try {
             $reply->save();
             $page = $numpages;
             $talk->last_reply = time();
             $talk->save();
             $subscriptions = $talk->subscriptions->find_all();
             if ((bool) $subscriptions->count()) {
                 foreach ($subscriptions as $subscription) {
                     if ($subscription->user_id != $reply->user_id) {
                         mail::create('talkreplyposted')->to($subscription->user->email)->tokenize(array('username' => $subscription->user->username, 'sendername' => $reply->user->username, 'title' => $talk->title, 'reply' => $reply->content, 'link' => HTML::anchor(URL::site($talk->url() . '?page=' . $page . '#comment-' . $reply->id, 'http'), $talk->title)))->send();
                     }
                 }
             }
             $vote = ORM::factory('User_Talkvote');
             $vote->type = 'talkreply';
             $vote->user_id = user::get()->id;
             $vote->object_id = $reply->id;
             $vote->save();
             notes::success('Your reply has been posted.');
             site::redirect($talk->url() . '?page=' . $page . '#comment-' . $reply->id);
         } catch (ORM_Validation_Exception $e) {
             notes::error('Whoops! Your submission contained errors. Please review it and submit again');
             $errors = $e->errors();
         }
     }
     if ($page < 1) {
         $page = 1;
     }
     if ($page > $numpages) {
         $page = $numpages;
     }
     $replies = $replies->limit($limit);
     if ($page - 1 > 0) {
         $replies = $replies->offset($limit * ($page - 1));
     }
     $replies = $replies->find_all();
     $this->bind('tag', $tag);
     $this->bind('talk', $talk);
     $this->bind('replies', $replies);
     $this->bind('tags', ORM::factory('Talktag')->find_all());
     $this->bind('numpages', $numpages);
     $this->bind('currentpage', $page);
     seo::instance()->title($talk->title);
     seo::instance()->description("Talk About Morning Pages, or anything else you might find interesting. Use this area to ask questions, make friends, or find out information about Morning Pages.");
 }
Exemplo n.º 14
0
					</ul>
				</li>
			</ul>
		</nav>
	</div>
</header>

<?php 
if (false) {
    ?>
	
	<section id="user-options" class="hidden-menu">
		<div class="container">
			<ul>
				<?php 
    if (user::logged()) {
        ?>
					<li><a href="<?php 
        echo URL::site('user/options');
        ?>
">User options</a></li>
					<!-- <li>Current streak: echo user::get()->current_streak </li> -->
					<li>
				    	<select data-bind="goToPreviousPage:true" id="pastposts">
				        	<option value="0">Previous pages</option>
				        	<option value="/">Today</option>
<?php 
        $pages = user::get()->pages->where('type', '=', 'page')->order_by('created', 'DESC')->find_all();
        $years = array();
        if ((bool) $pages->count()) {
            foreach ($pages as $p) {
Exemplo n.º 15
0
" type="text/javascript"></script>
<script src="<?php 
echo URL::site('media/js/config.js');
?>
" type="text/javascript"></script>
<script>
<?php 
$filename = 'media/js/viewModels/' . $controller . '/' . $action . '.js';
$include_viewmodel = false;
if (file_exists($filename)) {
    $include_viewmodel = true;
}
?>
	require(['project'], function(project){
		project.init(<?php 
echo (user::logged() ? 'true' : 'false') . ', ' . site::notes();
?>
).then(function(){
			<?php 
if ($include_viewmodel) {
    ?>
				require(['viewModels/<?php 
    echo $controller . '/' . $action;
    ?>
']);
			<?php 
}
?>
		});
	});
</script>
Exemplo n.º 16
0
 public function upload($files, $limits = array())
 {
     $parts = explode('.', $files['name'][0]);
     $orgfilename = $files['name'][0];
     $size = $files['size'][0];
     $this->ext = strtolower(strtolower(end($parts)));
     if ($this->allowed_exts != false && !in_array($this->ext, $this->allowed_exts)) {
         // Illegal file extention
         throw new Exception_File('Filen "' . $orgfilename . '" kunne ikke uploades. <strong>Filtypen er ikke tilladt</strong>. Kun billeder af følgende filtyper er tilladt: ' . implode(', ', $this->allowed_exts));
     }
     if ($this->maxsize != false && (!$size || $size == 0 || $size > $this->maxsize)) {
         // Too big
         throw new Exception_File('Filen "' . $orgfilename . '" kunne ikke uploades da den er for stor! Filer må højest være ' . files::format_bytes($this->maxsize));
     }
     if ($this->require_login && !user::logged()) {
         // We only accept files from logged in users
         throw new Exception_User('Du skal være logget ind for at uploade filer. Tjek at du er logget ind og forsøg igen.');
     }
     $this->filename = files::randomname() . '.' . $this->ext;
     $i = 2;
     while (file_exists($this->path . $this->filename)) {
         $this->filename = files::randomname() . '.' . $this->ext;
     }
     try {
         move_uploaded_file($files['tmp_name'][0], $this->path . $this->filename);
         // Should throw an exception if it fails
         $finfo = new finfo(FILEINFO_MIME);
         $type = $finfo->file($this->path . $this->filename);
         $mime = substr($type, 0, strpos($type, ';'));
         if ($this->allowed_mimes != false && !in_array($mime, $this->allowed_mimes)) {
             // Illegal file mime
             throw new Exception_File('Filen "' . $orgfilename . '" kunne ikke uploades. <strong>Filtypen er ikke tilladt</strong>. Kun billeder af følgende filtyper er tilladt: ' . implode(', ', $this->allowed_exts));
         }
         if ($this->require_login) {
             $this->user_id = user::get()->id;
         }
         $this->type = $mime;
         $this->created = time();
         $this->save();
         return $this;
     } catch (exception $e) {
         // File move failed. Maybe log the error?
         if (file_exists($this->path . $this->filename)) {
             unlink($this->path . $this->filename);
         }
         throw $e;
     }
 }
Exemplo n.º 17
0
function set_keyword_search($llllllll)
{
    $llllllll = removeHTML($llllllll);
    $llllllll = replaceMQ($llllllll);
    $llllllll = htmlspecialchars($llllllll);
    $llllllll = mb_strtolower($llllllll);
    $rrrrrrrr = new user();
    if ($rrrrrrrr->logged()) {
        $ssssssss = $rrrrrrrr->id;
    } else {
        $ssssssss = 0;
    }
    $tttttttt = new db_execute('INSERT INTO keyword_temp(key_text,key_user_id) VALUES("' . $llllllll . '",' . $ssssssss . ')');
    unset($tttttttt);
}
Exemplo n.º 18
0
 public function action_deletepost()
 {
     if (!user::logged()) {
         ajax::error('You must be logged in to do that.');
     }
     $id = arr::get($_POST, 'id', false);
     $object = ORM::factory('Talkreply', $id);
     if (!$object->loaded()) {
         ajax::error('I couldn\'t find that post. Has it already been deleted? Please contact us if you think this is a mistake');
     }
     if (!user::can_edit($object)) {
         ajax::error('That doesn\'t seem to be your post to delete. Please contact us if you think this is a mistake');
     }
     $object->deleted = time();
     $object->deleted_by = user::get()->id;
     try {
         $object->talk->deleted = 0;
         $object->talk->save();
         $object->save();
         if ($object->op == 1) {
             $talk = $object->talk;
             $talk->deleted = 1;
             $talk->save();
         }
         ajax::info('Your post has been deleted.');
     } catch (exception $e) {
         Kohana::$log->add(Log::CRITICAL, 'Couldn\'t delete Model_Talkreply: :message. User_id: :userid, postreply_id: :replyid', array(':message' => $e->getMessage(), ':userid' => user::get()->id, ':replyid' => $object->id));
         ajax::error('Something went wrong and your post couln\'t be deleted. Please try again or contact us if you think this is a mistake.');
     }
 }
Exemplo n.º 19
0
     }
     return html_entity_decode($excerpt);
 }
 public function delete()
 {
     $kids = ORM::factory('block')->where('parent', '=', $this->id)->find_all();
     if ((bool) $kids->count()) {
         foreach ($kids as $kid) {
             $kid->delete();
         }
     }
     return parent::delete();
 }
 // This is dumb...
 public function __toString()
 {
     return $this->value;
     $class = '';
     $id = '';
     if (user::logged('admin')) {
         $class = 'contentblock';
         $id = 'contentblock-' . $this->id;
     }
     $block = '<div class="' . $class . '" id="' . $id . '">';
     switch ($this->blocktype->type) {
         case 'gallery':
             $files = $this->files->find_all();
Exemplo n.º 20
0
					<a href="#" id="header-filesbtn" class="btn btn-default" title="<?php 
echo __('Browse files');
?>
">
						<span class="glyphicon glyphicon-floppy-disk"></span>
					</a>
					<a href="#/messages" class="btn btn-default" data-bind="css:{'btn-default':unread_messages()==0,'btn-warning':unread_messages()>0}">
						<span class="glyphicon glyphicon-envelope"></span>
						<span data-bind="text:unread_messages(),visible:unread_messages()>0"></span>
					</a>
					<a href="#" class="btn btn-info" id="site-info">
						<span class="glyphicon glyphicon-user"></span>
						<span data-bind="text:current_visitors()">0</span>
					</a>
					<?php 
if (user::logged('developer')) {
    ?>
						<a href="#/super" class="btn btn-primary" title="Superadmin">
							<span class="glyphicon glyphicon-lock"></span>
						</a>
					<?php 
}
?>
					<a href="<?php 
echo URL::site(localization::get('users.urls.logout'));
?>
" data-bind="click:logout" class="btn btn-danger" title="<?php 
echo __('Log out');
?>
">
						<span class="glyphicon glyphicon-off"></span>
Exemplo n.º 21
0
    $errs = arr::get($errors, 'talktag_id');
    if (is_array($errs)) {
        echo '<ul>';
        foreach ($errs as $err) {
            echo '<li>' . $err . '</li>';
        }
        echo '</ul>';
    } else {
        echo $errs;
    }
    echo '</label>';
}
?>
			</p>
			<?php 
if (user::logged('admin')) {
    ?>
				<p>
					<label class="stay" for="new-talk-announcement"><input id="new-talk-announcement" placeholder="Announcement" type="checkbox" value="1" name="announcement" /> Announcement?</label>
				</p>
			<?php 
}
?>
			<p>
				<label for="new-talk-title">Title</label>
				<input class="<?php 
echo $errors && arr::get($errors, 'title', false) ? 'error' : '';
?>
" value="<?php 
echo arr::get($_POST, 'title', '');
?>
Exemplo n.º 22
0
function set_keyword_search($keyword)
{
    $keyword = removeHTML($keyword);
    $keyword = replaceMQ($keyword);
    $keyword = htmlspecialchars($keyword);
    $keyword = mb_strtolower($keyword);
    $myuser = new user();
    if ($myuser->logged()) {
        $user_id = $myuser->id;
    } else {
        $user_id = 0;
    }
    $db_insert = new db_execute('INSERT INTO keyword_temp(key_text,key_user_id) VALUES("' . $keyword . '",' . $user_id . ')');
    unset($db_insert);
}
Exemplo n.º 23
0
    ?>
			<div class="text-right" id="fullscreen-toolbar">
				<a href="#" data-bind="click:fullscreen">
					<span class="fa fa-arrows-alt"></span>
				</a>
			</div>
			<form role="form" action="<?php 
    echo URL::site('write/');
    ?>
" method="post" id="writeform" data-bind="submit:submitPage">
				<input type="hidden" name="start" value="<?php 
    echo time();
    ?>
" />
				<textarea class="<?php 
    echo user::logged() && (bool) user::get()->option('rtl') ? 'rtl' : '';
    ?>
" name="content" autofocus data-bind="value:writtenwords,valueUpdate:'keyup',autogrow:''" id="morningpage-content"><?php 
    echo arr::get($_POST, 'content', '');
    ?>
</textarea>
				<button  class="writing-submit">Submit</button>
				<p class="subtext">
				      <span data-bind="text:wordcount">0</span> / 750
                </p>
			</form>
		<?php 
}
?>
	</div>
</article>
Exemplo n.º 24
0
		<div class="me-icon">
			<img src="<?php 
echo $user->gravatar(150);
?>
" alt="Profile photo for <?php 
echo $user->username;
?>
">
		</div>
		<div class="me-username">
			<p>Member since <?php 
echo $user->created();
?>
</p>
			<?php 
if (user::logged() && user::get()->id == $user->id) {
    $pages = user::get()->pages->where('type', '=', 'page')->order_by('created', 'DESC')->find_all();
    ?>
				<select data-bind="goToPreviousPage:true" id="pastposts">
		        	<option value="0">Previous pages (<?php 
    echo $pages->count();
    ?>
)</option>
		        	<option value="/">Today</option>
<?php 
    $years = array();
    if ((bool) $pages->count()) {
        foreach ($pages as $p) {
            $stamp = $p->created;
            $year = date('Y', $stamp);
            if (!array_key_exists($year, $years)) {
Exemplo n.º 25
0
 {
     return url::site(self::slug($uri), $protocol);
 }
 public static function hascompany()
Exemplo n.º 26
0
 /**
  * Site routes
  */
 public static function find($route, $params, $request)
 {
     visitor::save_update_current();
     maintenance::delete_inactive_visitors();
     extract($params);
     if (!isset($controller)) {
         $controller = 'content';
     }
     $controller = strtolower($controller);
     $guid = $controller . '/' . $action;
     if ($action == 'index') {
         $guid = $controller;
     }
     $controllerfile = ucfirst($controller);
     $action = isset($params['action']) ? $params['action'] : 'index';
     //$action = ucfirst($action);
     $slug = isset($params['slug']) ? $params['slug'] : '';
     $slug2 = isset($params['slug2']) ? $params['slug2'] : '';
     $slug3 = isset($params['slug3']) ? $params['slug3'] : '';
     $slug4 = isset($params['slug4']) ? $params['slug4'] : '';
     $slug5 = isset($params['slug5']) ? $params['slug5'] : '';
     // Homepage
     if ($guid == 'content') {
         return array('controller' => 'Site', 'action' => 'index');
     }
     // Page alias
     if ($controller == 'test') {
         return array('controller' => 'Page', 'action' => 'test');
     }
     if ($controller == 'contact') {
         return array('controller' => 'Page', 'action' => 'contact');
     }
     if ($controller == 'challenge') {
         if ($action == 'wall-of-fame') {
             return array('controller' => 'Games', 'action' => 'walloffame');
         } elseif ($action == 'index') {
             return array('controller' => 'Games', 'action' => 'challenge');
         }
     }
     if ($controller == 'leaderboard') {
         return array('controller' => 'Games', 'action' => 'leaderboard');
     }
     if ($controller == 'write') {
         $todayslug = site::day_slug();
         if (user::logged()) {
             $todayslug = user::get()->today_slug();
         }
         if (empty($action) || $action == 'index') {
             $action = $todayslug;
         }
         $page = false;
         if (user::logged()) {
             $page = ORM::factory('Page')->where('user_id', '=', user::get()->id)->where('type', '=', 'page')->where('day', '=', $action)->find();
             if (!$page->loaded() && $action == $todayslug) {
                 $page = ORM::factory('Page')->where('user_id', '=', user::get()->id)->where('type', '=', 'autosave')->where('day', '=', $action)->find();
                 // It's today, but todays page doesn't exist yet. Create it
                 if (!$page->loaded()) {
                     $page->type = 'autosave';
                     $page->save();
                 }
             }
         }
         if (user::logged() && ($page && $page->loaded()) && $slug == 'stats') {
             return array('controller' => 'Write', 'action' => 'pagestats', 'page' => $page);
         }
         if (user::logged() && ($page && $page->loaded()) || !user::logged()) {
             return array('controller' => 'Write', 'action' => 'write', 'page' => $page, 'daystamp' => $action);
         } else {
             return array('controller' => 'Write', 'action' => 'daynotfound');
         }
     }
     if ($controller == 'read') {
         return array('controller' => 'Page', 'action' => 'read', 'id' => $action);
     }
     if ($controller == 'user') {
         if ($action != '') {
             if ($action == 'password') {
                 return array('controller' => 'User', 'action' => 'password', 'token' => $slug);
             }
             if (in_array($action, user::reservednames())) {
                 return array('controller' => 'User', 'action' => $action);
             }
             // We're either looking at a user's public profile or 404'd
             $user = ORM::factory('User')->where('slug', '=', $action)->find();
             if ($user->loaded()) {
                 if ((bool) $user->option('public') || user::logged('admin')) {
                     return array('controller' => 'Me', 'action' => 'profile', 'user' => $user);
                 } else {
                     return array('controller' => 'Me', 'action' => 'notpublic');
                 }
             } else {
                 return array('controller' => 'Errors', 'action' => '404', 'params' => $params);
             }
         } else {
             return array('controller' => 'User', 'action' => 'options');
         }
     }
     // Pages/Content
     $content = ORM::factory('Content');
     if (!user::logged('admin')) {
         $content = $content->where('status', '=', 'active');
     }
     $content = $content->where('guid', '=', $guid)->find();
     if ($content->loaded()) {
         // Specific content
         $class = 'Content';
         if (class_exists('Controller_' . ucfirst($content->contenttype->type))) {
             $class = ucfirst($content->contenttype->type);
         }
         $action = 'default';
         if ($content->contenttypetype_id != 0) {
             if (method_exists('Controller_' . $class, 'action_' . $content->contenttypetype->key)) {
                 $action = $content->contenttypetype->key;
             }
         }
         $content->hit();
         return array('controller' => $class, 'action' => $action, 'content' => $content);
     } else {
         // Index page for contenttype
         if ($action == 'index') {
             $contenttype = $controller;
             if (class_exists('Controller_' . ucfirst($contenttype))) {
                 $class = ucfirst($contenttype);
                 return array('controller' => $class, 'action' => 'index');
             }
         }
     }
     // "Static" controllers
     $file = 'application/classes/Controller/' . $controllerfile . '.php';
     if (file_exists($file) && method_exists('Controller_' . ucfirst($controllerfile), 'action_' . $action)) {
         $return = array();
         $return['controller'] = $controllerfile;
         $return['action'] = isset($action) ? $action : 'index';
         $return['id'] = isset($slug) ? $slug : '';
         $return['params'] = $params;
         return $return;
     }
     // No matches. 404
     return array('controller' => 'Errors', 'action' => '404', 'params' => $params);
 }
Exemplo n.º 27
0
 public function action_signup()
 {
     $errors = false;
     $password = false;
     if ($_POST) {
         $user = ORM::factory('User');
         try {
             user::create($_POST);
             notes::add('success', 'You are now signed up. Welcome!');
             if (user::logged()) {
                 site::redirect('write');
             } else {
                 // should log this error (user wasnt logged in with user::create())
                 user::redirect('login');
             }
         } catch (ORM_Validation_Exception $e) {
             $errors = $e->errors('models');
         }
     }
     $this->bind('errors', $errors);
 }