Exemplo n.º 1
0
	function add() {
		log_message('debug', 'add');
		if ($post_id = $this->input->post('post_id', TRUE)) {
			log_message('debug', 'add favorites');
			$user = models\Current_User::user();
			if ($user) {
				$post = $this->em->find('models\Post', $post_id);
				log_message('debug', 'add favorites - we got the user');
				if ($post) {
					log_message('debug', 'add favorites - we got the post');
					$favorite = new models\Favorite;
					$favorite->setUser($user);
					$favorite->setPost($post);
					
					$this->em->persist($favorite);
					$this->em->flush();
					
					$result = array('result' => 1);
					echo json_encode($result);
					die();
				}
			}
		} else {
			echo 'no post';
		}
	}
Exemplo n.º 2
0
function __construct()  {
		parent::__construct();
		
		//$config = array('userID' => 12);
		$this->load->library('acl');
		$controller = $this->router->class;
		$method = $this->router->fetch_method();
		$con_met = $controller.'_'.$method;
		
		$allPerms = $this->acl->getAllPerms('full');
		
		if (array_key_exists($con_met, $allPerms)) {
			$user = models\Current_User::user();
			if (!$user) {
				$next = '/'.$controller.'/'.$method.'/'.$this->uri->segment(3);
				if ($this->input->post()) {
					log_message('debug', 'there is post to post: '.print_r($this->input->post(), true));
					$next_post = $this->input->post();
					$this->session->set_userdata('next_post', $next_post);
				}
				$this->session->set_userdata('next', $next);
				redirect('/login/');
				return;
			}
			$config['userID'] = $user->getId();
			$this->acl->init($config);
			if ( !$this->acl->hasPermission($con_met) ) {
				//if ($controller != 'login') redirect('/login/');
				redirect('/error/');
				return;
			}
		}

		
		/* Instantiate Doctrine's Entity manage so we don't have
		   to everytime we want to use Doctrine */
		$this->em = $this->doctrine->em;
		
	}
Exemplo n.º 3
0
<div class="navbar navbar-fixed-top">
  <div class="navbar-inner">
	<div class="container">
	  <a class="brand" href="<?php echo base_url(); ?>home">PPION</a>
	  <ul class="nav">
		<li <?php if ($template['title'] == 'Articles') echo 'class="active"'; ?>><a href="<?php echo base_url(); ?>posts">Artikel</a></li>
		<!--<li <?php if ($template['title'] == 'Events') echo 'class="active"'; ?>><a href="<?php echo base_url(); ?>events">Event</a></li>-->
		<li <?php if ($template['title'] == 'Members') echo 'class="active"'; ?>><a href="<?php echo base_url(); ?>members">Anggota</a></li>
		<li><a href="http://www.flickr.com/photos/ppi-on/"  target="_blank">Gallery</a></li>
	  </ul>
	<?php  
		$user = models\Current_User::user();
		if (!$user) { ?>
		<button onClick="window.location='<?php echo base_url(); ?>signup'" type="signup" class="btn btn-success pull-right" style="margin-top: 6px">Belum punya akun?</button>
			<?php echo form_open('login/submit', array('class' => 'navbar-search pull-right')); ?>
				<input class="search-query span2" type="text" placeholder="E-mail" name="email">
				<input class="search-query span2" type="password" placeholder="Password" name="password">
				<button class="btn" type="submit" style="margin-top: -1px; height: 27px;">Log in</button>
				
			  </form>
			  
		<? } else { ?>
		<ul class="nav pull-right">
			<li class="dropdown">
				<a href="#" class="dropdown-toggle" data-toggle="dropdown"><?php echo $user->getName(); ?><b class="caret"></b></a>
					<ul class="dropdown-menu">
					  <li><a href="<?php echo base_url(); ?>dashboard/">Dashboard</a></li>
					  <li><a href="<?php echo base_url(); ?>posts/add">Bikin Artikel Baru</a></li>
					  <!--<li><a href="<?php echo base_url(); ?>events/add">Bikin Event Baru</a></li>-->
					  <li class="divider"></li>
					  <li><a href="<?php echo base_url(); ?>logout">Log out</a></li>
Exemplo n.º 4
0
	private function _fetchMyFavorites() {
		$this->load->helper('date');
		$user = models\Current_User::user();
		if ($user) {
			$q = $this->em->createQuery('select f.created_at, p.id as post_id, p.title from models\Favorite f LEFT JOIN f.post p WHERE f.user = ?1 ORDER BY f.created_at DESC');
			$q->setParameter(1, $user->getId());
			$favorites = $q->getResult(Query::HYDRATE_ARRAY);
			foreach ($favorites as $key => $value) {
				$favorites[$key]['_created_at'] = time_diff(now() - strtotime($value['created_at']));
			}
		}
		return $favorites;
	}
Exemplo n.º 5
0
	public function comment($id) {
		if ($this->_submit_comment_validate() === FALSE) {
			$this->show($id);
			return;
		}
		$post = $this->em->find('models\Post', $id);
		$user = models\Current_User::user();
		$content = $this->input->post('comment');
		if ($post && $user && $post->getFlag()!='deleted') {
			$comment = new models\Comment;
			$comment->setUser($user);
			$comment->setPost($post);
			$comment->setContent($content);
			$this->em->persist($comment);
			$this->em->flush();
			
			$this->show($id);
		}
	}
Exemplo n.º 6
0
				?>
				</div>
			</div>
			<?php } ?>
			
		<?php } else {
			?>
			<div class="alert-message warning">
			  Belum ada komen.
			</div>
			<?php
		}
	?>
	<div class="row commentBox commentInputBox">
			<div class="span8 columns">
				<?php if (models\Current_User::user()) { ?>
				<?php echo form_open('posts/comment/'.$post->getId());  ?>
				<?php 
					$data = array(
								'name' => 'comment',
								'value' => ($comment_content != NULL)?$comment_content:set_value('comment'),
								'class' => 'large'
							);?>
				<textarea class="span8 commentInput" name="comment" type="textarea" placeholder="Tulis komen disini" rows="1"><?php 
					if ($comment_content != NULL) {
						echo $comment_content;
					} else echo '';
				?></textarea></div>
			<div class="span1 columns commentButton">
				<input type="submit" class="btn primary">
			</div>
Exemplo n.º 7
0
	public function authenticate() {
		return models\Current_User::login(trim($this->input->post('email')), $this->input->post('password'));

	}