예제 #1
0
 /**
  * Delete the outdated entries.
  */
 public function clear()
 {
     $db = Komento::getDBO();
     $date = Komento::getDate();
     $query = 'DELETE FROM ' . $db->nameQuote('#__komento_captcha') . ' WHERE ' . $db->nameQuote('created') . ' <= DATE_SUB( ' . $db->Quote($date->toMySQL()) . ', INTERVAL 12 HOUR )';
     $db->setQuery($query);
     $db->query();
     return true;
 }
예제 #2
0
	public function upload( $fileItem, $fileName = '', $storagePath = '', $published = 1 )
	{
		// $fileItem['name'] = filename
		// $fileItem['type'] = mime
		// $fileItem['tmp_name'] = temporary source
		// $fileItem['size'] = size

		if( empty( $fileItem ) )
		{
			return false;
		}

		// store record first
		$uploadtable = Komento::getTable( 'uploads' );

		$now = Komento::getDate()->toMySQL();
		$uploadtable->created = $now;

		$profile = Komento::getProfile();
		$uploadtable->created_by = $profile->id;

		$uploadtable->published = $published;

		$uploadtable->mime = $fileItem['type'];

		$uploadtable->size = $fileItem['size'];

		if( $fileName == '' )
		{
			$fileName = $fileItem['name'];
		}
		$uploadtable->filename = $fileName;

		if( $storagePath == '' )
		{
			$config = Komento::getConfig();
			$storagePath = $config->get( 'upload_path' );
		}
		$uploadtable->path = $storagePath;

		if( !$uploadtable->upload() )
		{
			return false;
		}

		$source = $fileItem['tmp_name'];
		$destination = $uploadtable->getFilePath();

		jimport( 'joomla.filesystem.file' );
		if( !JFile::copy( $source , $destination ) )
		{
			$uploadtable->rollback();
			return false;
		}

		return $uploadtable->id;
	}
예제 #3
0
	public function add( $type, $comment_id, $uid )
	{
		$table	= Komento::getTable( 'activities' );

		$table->type		= $type;
		$table->comment_id	= $comment_id;
		$table->uid			= $uid;
		$table->created		= Komento::getDate()->toMySQL();
		$table->published	= 1;

		return $table->store();
	}
예제 #4
0
	public function getReloadSyntax()
	{
		if ($currentId = JRequest::getInt( 'captcha-id' ))
		{
			$ref	= Komento::getTable( 'Captcha' , 'KomentoTable' );
			$ref->load( $currentId );
			$ref->delete();
		}

		// Regenerate a new captcha object
		$captcha	= Komento::getTable( 'Captcha' , 'KomentoTable' );
		$captcha->created	= Komento::getDate()->toMySQL();
		$captcha->store();

		$url	= $this->getCaptchaUrl( $captcha->id );

		$reloadData = array(
			'image'	=> $url,
			'id'	=> $captcha->id
		);

		return $reloadData;
	}
예제 #5
0
	private function subscribe( $type = 'comment', $component, $cid, $commentId = 0, $userid = 0, $name, $email )
	{
		if( $commentId !== 0 && ( !$component || !$cid ) )
		{
			$comment = Komento::getComment( $commentId );
			$component = $comment->component;
			$cid = $comment->cid;
		}

		if( !$component || !$cid )
		{
			return false;
		}

		$subscriptionExist = Komento::getModel( 'subscription' )->checkSubscriptionExist( $component, $cid, $userid, $email, $type );

		if( !$subscriptionExist )
		{
			$data = array(
				'type'		=> $type,
				'component' => $component,
				'cid'		=> $cid,
				'userid'	=> $userid,
				'fullname'	=> $name,
				'email'		=> $email,
				'created'	=> Komento::getDate()->toMySQL(),
				'published'	=> 1
			);

			$config = Komento::getConfig();

			if( $config->get( 'subscription_confirmation' ) )
			{
				$data['published'] = 0;
			}

			$subscribeTable = Komento::getTable( 'subscription' );

			$subscribeTable->bind( $data );

			if( !$subscribeTable->store() )
			{
				return false;
			}

			if( $config->get( 'subscription_confirmation' ) )
			{
				Komento::getHelper( 'Notification' )->push( 'confirm', 'me', array( 'component' => $component, 'cid' => $cid, 'subscribeId' => $subscribeTable->id, 'commentId' => $commentId ) );
			}
		}

		return true;
	}
예제 #6
0
 public function populatedb()
 {
     $db = Komento::getDBO();
     $articles = array('8', '50', '35');
     $authors = array('0' => 'Alien', '42' => 'Super User', '62' => 'Jason');
     $comments = array('hahaha :) love you', 'me too!!!', 'this is a link http://test.com', '[b]bbcode in use[/b] :( f**k you');
     $parentmap = array();
     $counter = 0;
     $date = Komento::getDate();
     for ($i = 0; $i < 20000; $i++) {
         $date->sub(new DateInterval('PT' . (20001 - $i) . 'S'));
         $modulo = $i % 3;
         $set = (int) ($i / 3);
         $setmodulo = (int) ($set / 3);
         $factor = $setmodulo * 6;
         $level = $set % 3 + 1;
         $lft = $level + $factor;
         $rgt = 7 - $level + $factor;
         $author = array_rand($authors);
         $article = $articles[$modulo];
         $comment = array_rand($comments);
         $parentid = 0;
         if ($level > 1) {
             $parentid = $parentmap[$article][$setmodulo][$level - 1];
         }
         $table = Komento::getTable('comments');
         $table->component = 'com_content';
         $table->comment = $comments[$comment];
         $table->cid = $article;
         $table->lft = $lft;
         $table->rgt = $rgt;
         $table->published = 1;
         $table->name = $authors[$author];
         $table->created_by = $author;
         $table->created = $date->toMySQL();
         $table->parent_id = $parentid;
         $result = $table->store();
         if (!$result) {
             var_dump($table);
             exit;
         }
         $parentmap[$article][$setmodulo][$level] = $table->id;
     }
     echo 'done';
     exit;
 }
예제 #7
0
	/**
	 * Push the email notification to MailQ
	 * @param	string	$type			type of notification
	 * @param	string	$recipient		recipient (subscribers,admins,author,me)
	 * @param	array	$options		various options
	 *
	 * @return nothing
	 */
	public function push( $type, $recipients, $options = array() )
	{
		if( !empty( $options['commentId'] ) )
		{
			$comment = Komento::getComment( $options['commentId'] );
			$options['comment'] = $comment;
			$options['component'] = $comment->component;
			$options['cid'] = $comment->cid;

			$options['comment'] = Komento::getHelper( 'comment' )->process( $options['comment'] );


			unset( $options['commentId'] );
		}

		if( !isset( $options['component'] ) || !isset( $options['cid'] ) )
		{
			return;
		}

		if( $type == 'new' && $options['comment']->parent_id )
		{
			$type = 'reply';
		}

		$recipients		= explode(',', $recipients);
		$rows			= array();
		$skipMe			= true;

		// process requested recipients first
		foreach ($recipients as $recipient)
		{
			$recipient		= 'get' . ucfirst( strtolower( trim($recipient) ) );

			if( !method_exists($this, $recipient) )
			{
				continue;
			}

			if( $recipient == 'getMe' )
			{
				$skipMe = false;
			}

			$result = $this->$recipient( $type, $options );

			// stacking up all the emails and details
			$rows	= $rows + $result;
		}

		// process usergroups notification based on notification type
		$rows = $rows + $this->getUsergroups( $type );

		if( $type == 'report' )
		{
			$admins = $this->getAdmins();

			foreach( $admins as $admin )
			{
				if( isset($rows[$options['comment']->email]) && $options['comment']->email === $admin->email )
				{
					$skipMe = false;
				}
			}
		}

		if( empty($rows) )
		{
			return;
		}

		// Do not send to the commentor/actor
		if( $skipMe && isset($rows[$options['comment']->email]) )
		{
			unset( $rows[$options['comment']->email] );
		}

		$lang = JFactory::getLanguage();

		// Load English first as fallback
		$konfig = Komento::getKonfig();
		if( $konfig->get( 'enable_language_fallback' ) )
		{
			$lang->load( 'com_komento', JPATH_ROOT, 'en-GB', true );
		}

		// Load site's selected language
		$lang->load( 'com_komento', JPATH_ROOT, $lang->getDefault(), true );

		// Load user's preferred language file
		$lang->load( 'com_komento', JPATH_ROOT, null, true );

		$jconfig	= JFactory::getConfig();
		$data		= $this->prepareData( $type, $options );
		$template	= $this->prepareTemplate( $type, $options );
		$subject	= $this->prepareTitle( $type, $options );

		$mailfrom	= Komento::_( 'JFactory::getConfig', 'mailfrom' );
		$fromname	= Komento::_( 'JFactory::getConfig', 'fromname' );

		$config	= Komento::getConfig();
		$sendHTML = $config->get( 'notification_sendmailinhtml' ) ? 'html' : 'text';

		// Storing notifications into mailq
		foreach ($rows as $row)
		{
			if( Komento::trigger( 'onBeforeSendNotification', array( 'component' => $options['component'], 'cid' => $options['cid'], 'recipient' => &$row ) ) === false )
			{
				continue;
			}

			if( empty( $row->email ) )
			{
				continue;
			}

			$body	= $this->getTemplateBuffer( $template, $data, array( 'recipient' => $row ) );
			$mailQ	= Komento::getTable( 'mailq' );
			$mailQ->mailfrom	= $mailfrom;
			$mailQ->fromname	= $fromname;
			$mailQ->recipient	= $row->email;
			$mailQ->subject		= $subject;
			$mailQ->body		= $body;
			$mailQ->created		= Komento::getDate()->toMySQL();
			$mailQ->type		= $sendHTML;
			$mailQ->status		= 0;
			$result = $mailQ->store();
		}
	}
예제 #8
0
 function publish($comments = array(), $publish = 1)
 {
     if ($comments == null) {
         return false;
     }
     if (!is_array($comments)) {
         $comments = array($comments);
     }
     $affectChild = JRequest::getInt('affectchild', 0);
     if (count($comments) > 0) {
         $now = Komento::getDate()->toMySql();
         $publishDateColumn = '';
         if ($publish == 0) {
             $publishDateColumn = 'publish_down';
         } else {
             $publishDateColumn = 'publish_up';
         }
         $nodes = $comments;
         foreach ($nodes as $comment) {
             $related = array();
             if ($publish == 1) {
                 $related = array_merge($related, self::getParents($comment));
             }
             if ($publish == 0 || $publish == 1 && $affectChild) {
                 $related = array_merge($related, self::getChilds($comment));
             }
             if (count($related) > 0) {
                 $comments = array_merge($comments, $related);
             }
         }
         $comments = array_unique($comments);
         $allComments = implode(',', $comments);
         foreach ($comments as $comment) {
             if (!Komento::getComment($comment)->publish($publish)) {
                 return false;
             }
         }
         return true;
     }
     return false;
 }
예제 #9
0
	function setReplyTime()
	{
		return $this->session->set('komento_last_reply', serialize( Komento::getDate()->toUnix() ) );
	}
예제 #10
0
 function save($comment)
 {
     $new = Komento::getTable('comments');
     $new->component = $this->component;
     $new->cid = $this->cid;
     $new->comment = $comment->comment;
     $new->name = $comment->name;
     $new->email = $comment->email;
     $new->url = $comment->website;
     // careful because rscomments save their datetime in unix format
     $new->created = Komento::getDate($comment->date)->toMySql();
     $new->created_by = $comment->uid;
     $new->published = $comment->published;
     $new->ip = $comment->ip;
     $new->parent_id = $comment->parent_id;
     $new->lft = $comment->lft;
     $new->rgt = $comment->rgt;
     if ($this->publishingState !== 'inherit') {
         $new->published = $this->publishingState;
     }
     if (!$new->store()) {
         return false;
     }
     return $new;
 }
예제 #11
0
 public function getContentPermalink()
 {
     require_once JPATH_ROOT . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_jevents' . DIRECTORY_SEPARATOR . 'jevents.defines.php';
     require_once JPATH_ROOT . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_jevents' . DIRECTORY_SEPARATOR . 'libraries' . DIRECTORY_SEPARATOR . 'helper.php';
     $Itemid = JEVHelper::getItemid();
     $task = JRequest::getCmd('task');
     $title = JFilterOutput::stringURLSafe($this->_item->summary);
     $date = Komento::getDate($this->_item->dtstart);
     $year = $date->toFormat('%Y');
     $month = $date->toFormat('%m');
     $day = $date->toFormat('%d');
     //Get the rp_id from the #__jevents_repetition table and assign to the permalink url
     $newEventId = $this->getEventId($this->_item->ev_id);
     $link = 'index.php?option=com_jevents&task=icalrepeat.detail&evid=' . $newEventId . '&Itemid=' . $Itemid . '&year=' . $year . '&month=' . $month . '&day=' . $day . '&title=' . $title . '&uid=' . $this->_item->uid;
     $link = $this->prepareLink($link);
     return $link;
 }
예제 #12
0
	function addAction($type, $comment_id, $user_id)
	{
		$comment	= Komento::getComment( $comment_id );

		$now			= Komento::getDate()->toMySQL();

		$actionsTable	= Komento::getTable( 'actions' );

		$actionsTable->type			= $type;
		$actionsTable->comment_id	= $comment_id;
		$actionsTable->action_by	= $user_id;
		$actionsTable->actioned		= $now;

		if(!$actionsTable->store())
		{
			return false;
			// return JText::_( 'COM_KOMENTO_LIKES_ERROR_SAVING_LIKES' );
		}

		return $actionsTable->id;
	}
예제 #13
0
	public function addMailq($component, $cid)
	{
		$config = Komento::getConfig();

		$subscribers = Komento::getModel('subscription')->getSubscribers($component, $cid);

		$mainframe	= JFactory::getApplication();
		$mailfrom	= $mainframe->getCfg( 'mailfrom' );
		$fromname 	= $mainframe->getCfg( 'fromname' );

		if( $config->get( 'admin_email' ) )
		{
			// get from config if config exist
		}

		if( count( $subscribers ) > 0 )
		{
			foreach( $subscribers as $subscriber )
			{
				$data = array(
					'mailfrom'	=> $mailfrom,
					'fromname'	=> $fromname,
					'recipient'	=> $subscriber->email,
					'subject'	=> 'new email',
					'body'		=> 'body',
					'created'	=> Komento::getDate()->toMySQL(),
					'status'	=> 0
				);

				$mailqTable = Komento::getTable( 'mailq' );

				$mailqTable->bind( $data );
				$mailqTable->store();
			}

			return true;
		}

		return false;
	}
예제 #14
0
 public function generate()
 {
     return JString::substr(md5($this->uid . $this->type . Komento::getDate()->toMySQL()), 0, 12);
 }
예제 #15
0
	public function publish( $type = '1' )
	{
		// set new = false
		$new = false;

		// Create the comment table object
		$commentTable = Komento::getTable( 'Comments' );
		$commentTable->bind($this->getProperties());

		// get date
		$now = Komento::getDate()->toMySQL();

		// check original status == 2
		if( $commentTable->published == 2 )
		{
			$new = true;
		}

		$commentTable->published = $type;

		if( $type == '1' )
		{
			$commentTable->publish_up = $now;
		}
		else
		{
			$commentTable->publish_down = $now;
		}

		// Trigger onBeforePublishComment( $this->component, $this->cid, &$this )
		// Trigger onBeforeUnpublishComment( $this->component, $this->cid, &$this )
		$triggerResult = true;
		if( $type == '1' )
		{
			$triggerResult = Komento::trigger( 'onBeforePublishComment', array( 'component' => $this->component, 'cid' => $this->cid, 'comment' => &$this ) );
		}
		else
		{
			$triggerResult = Komento::trigger( 'onBeforeUnpublishComment', array( 'component' => $this->component, 'cid' => $this->cid, 'comment' => &$this ) );
		}

		if( $triggerResult === false )
		{
			$this->setError( 'Trigger onBeforePublishComment/onBeforeUnpublishComment false' );
			return false;
		}

		if( !$commentTable->store() )
		{
			$this->setError( 'Comment publish/unpublish failed' );
			return false;
		}

		// bind with comment table data after successfully saving comment table.
		$this->setProperties($commentTable->getProperties());

		// Trigger onAfterPublishComment( $this->component, $this->cid, &$this )
		// Trigger onAfterUnpublishComment( $this->component, $this->cid, &$this )
		if( $type == '1' )
		{
			Komento::trigger( 'onAfterPublishComment', array( 'component' => $this->component, 'cid' => $this->cid, 'comment' => &$this ) );
		}
		else
		{
			Komento::trigger( 'onAfterUnpublishComment', array( 'component' => $this->component, 'cid' => $this->cid, 'comment' => &$this ) );
		}

		if( $new )
		{
			$config = Komento::getConfig( $commentTable->component );

			$action = $commentTable->parent_id ? 'reply' : 'comment';

			// send email
			if( $config->get( 'notification_enable' ) )
			{
				if( ( $action == 'comment' && $config->get( 'notification_event_new_comment' ) ) || ( $action == 'reply' && $config->get( 'notification_event_new_reply' ) ) )
				{
					Komento::getHelper( 'Notification' )->push( $action, 'subscribers,author,usergroups', array( 'commentId' => $commentTable->id ) );
				}
			}

			// process activities
			$activity = Komento::getHelper( 'activity' )->process( $action, $commentTable->id );

			// Manually get the attachment of this comment and process the "upload" activity
			$attachments = $commentTable->getAttachments();
			$totalAttachments = count( $attachments );
			for( $i = 0; $i < $totalAttachments; $i++ )
			{
				Komento::getHelper( 'activity' )->process( 'upload', $commentTable->id );
			}
		}

		return true;
	}
예제 #16
0
<?php
/**
 * @package		Komento
 * @copyright	Copyright (C) 2012 Stack Ideas Private Limited. All rights reserved.
 * @license		GNU/GPL, see LICENSE.php
 *
 * Komento is free software. This version may have been modified pursuant
 * to the GNU General Public License, and as distributed it includes or
 * is derivative of works licensed under the GNU General Public License or
 * other free or open source software licenses.
 * See COPYRIGHT.php for copyright notices and details.
 */
defined( '_JEXEC' ) or die( 'Restricted access' );
?>
<div class="kmt-author-detail">
	<h3 class="kmt-author">
		<a href="<?php echo Komento::getProfile()->getProfileLink(); ?>">
		<?php echo $system->my->getName(); ?>
		</a>
	</h3>
	<br />
	<span class="kmt-author-time"><?php echo Komento::getDate()->toFormat('%A, %B %d, %Y') ?></span>
</div>
예제 #17
0
	public static function getDifference( $end, $format = '' )
	{
		if( $end == '' )
		{
			return 0;
		}

		$now	= Komento::getDate();
		$time	= $now->toUnix() - $end;

		if( $format )
		{
			$time = self::toFormat( $end, $format );
		}

		return $time;
	}
예제 #18
0
 public static function getUniqueFileName($originalFilename, $path)
 {
     $ext = JFile::getExt($originalFilename);
     $ext = $ext ? '.' . $ext : '';
     $uniqueFilename = JFile::stripExt($originalFilename);
     $i = 1;
     while (JFile::exists($path . DIRECTORY_SEPARATOR . $uniqueFilename . $ext)) {
         // $uniqueFilename	= JFile::stripExt($originalFilename) . '-' . $i;
         $uniqueFilename = JFile::stripExt($originalFilename) . '_' . $i . '_' . Komento::getDate()->toFormat("%Y%m%d-%H%M%S");
         $i++;
     }
     //remove the space into '-'
     $uniqueFilename = str_ireplace(' ', '-', $uniqueFilename);
     return $uniqueFilename . $ext;
 }
예제 #19
0
 private function doSave()
 {
     $post = JRequest::get('post');
     $now = Komento::getDate()->toMySQL();
     $user = JFactory::getUser();
     $commentId = JRequest::getVar('commentid', '');
     // gettable instead of getobj to avoid sending mails
     $comment = Komento::getTable('comments');
     $comment->load($commentId);
     /*
     			check if postcomment = comment->comment (to update modified_by and modified)
     			check if postflag = comment->flag (to update flag_by and flag)
     			check if postflag = 0
     			check if published different
     */
     // check if modified
     if ($post['comment'] != $comment->comment) {
         $comment->modified = $now;
         $comment->modified_by = $user->id;
     }
     $comment->bind($post);
     // check publish change
     // publish_up
     // publish_down
     if ($post['published'] != $comment->published) {
         if ($post['published'] == 0) {
             $comment->publish_down = $now;
         } else {
             $comment->publish_up = $now;
         }
         $comment->published = $post['published'];
     }
     if (!$comment->store()) {
         JError::raiseError(500, $comment->getError());
         return $comment->getError();
     } else {
         return true;
     }
 }