Ejemplo n.º 1
0
 public function getResource()
 {
     $resources = JRequest::getVar('resource');
     $component = JRequest::getCmd('kmtcomponent');
     Komento::setCurrentComponent($component);
     if (!is_array($resources)) {
         header('Content-type: text/x-json; UTF-8');
         echo '[]';
         exit;
     }
     foreach ($resources as &$resource) {
         $resource = (object) $resource;
         switch ($resource->type) {
             case 'language':
                 $resource->content = JText::_(strtoupper($resource->name));
                 break;
             case 'view':
                 $template = Komento::getTheme();
                 $out = $template->fetch($resource->name . '.ejs');
                 if ($out !== false) {
                     $resource->content = $out;
                 }
                 break;
         }
     }
     Komento::getClass('json', 'KomentoJson');
     header('Content-type: text/x-json; UTF-8');
     $json = new KomentoJson();
     echo $json->encode($resources);
     exit;
 }
Ejemplo n.º 2
0
 public function display($tpl = null)
 {
     $konfig = Komento::getKonfig();
     $id = JRequest::getInt('id', 0);
     // @task: If profiles are disabled, do not show the profile here.
     if (!$konfig->get('profile_enable')) {
         $app = JFactory::getApplication();
         $app->redirect('index.php', JText::_('COM_KOMENTO_PROFILE_SYSTEM_DISABLED'));
         $app->close();
     }
     $profileModel = Komento::getModel('Profile');
     $activityModel = Komento::getModel('Activity');
     $commentsModel = Komento::getModel('Comments');
     $actionsModel = Komento::getModel('Actions');
     $count = new stdClass();
     $user = JFactory::getUser();
     if ($id === 0 && $user->id > 0) {
         $id = $user->id;
     }
     // Block non-exists profile
     if (!$profileModel->exists($id)) {
         echo JText::_('COM_KOMENTO_PROFILE_NOT_FOUND');
         return;
     }
     // TODO: Block custom profile id
     // ..
     $profile = Komento::getProfile($id);
     // $activities		= $activityModel->getUserActivities( $profile->id );
     $count->totalComments = $commentsModel->getTotalComment($profile->id);
     $count->likesReceived = $actionsModel->getLikesReceived($profile->id);
     $count->likesGiven = $actionsModel->getLikesGiven($profile->id);
     // Set Pathway
     // Check if Komento profile menu item exist before setting profile pathway
     $app = JFactory::getApplication();
     $menu = $app->getMenu();
     $item = $menu->getActive();
     if (empty($item) || $item->query['view'] != 'profile') {
         $this->setPathway(JText::_('COM_KOMENTO_PROFILE'), '');
     }
     $this->setPathway($profile->getName(), '');
     // Set browser title
     $document = JFactory::getDocument();
     $document->setTitle(JText::_('COM_KOMENTO_USER_PROFILE') . ' - ' . $profile->getName());
     // set component to com_komento
     Komento::setCurrentComponent('com_komento');
     $theme = Komento::getTheme();
     $theme->set('profile', $profile);
     $theme->set('count', $count);
     // $theme->set( 'activities', $activities );
     echo $theme->fetch('profile/profile.php');
 }
Ejemplo n.º 3
0
 function __construct()
 {
     $component = JRequest::getCmd('component', '');
     $cid = JRequest::getInt('cid', 0);
     $id = JRequest::getInt('id', 0);
     if ($component == '' && $cid == 0 && $id != 0) {
         $tmp = Komento::getTable('comments');
         $tmp->load($id);
         $component = $tmp->component;
         $cid = $tmp->cid;
     }
     if ($component) {
         Komento::setCurrentComponent($component);
     }
 }
Ejemplo n.º 4
0
	public function upload()
	{
		$component	= JRequest::getString( 'component' );
		Komento::setCurrentComponent( $component );

		$profile	= Komento::getProfile();
		$config		= Komento::getConfig();

		// acl stuffs here
		if( !$config->get( 'upload_enable' ) || !$profile->allow( 'upload_attachment' ) )
		{
			echo json_encode( array( 'status' => 'notallowed' ) ); exit;
		}

		$file	= JRequest::getVar( 'file', '', 'FILES', 'array' );

		// check for file size if runtime HTML4 is used
		if( $file['size'] > ( $config->get( 'upload_max_size' ) * 1024 * 1024 ) )
		{
			echo json_encode( array( 'status' => 'exceedfilesize' ) ); exit;
		}

		// $file['name'] = filename
		// $file['type'] = mime
		// $file['tmp_name'] = temporary source
		// $file['size'] = size

		$id = Komento::getHelper( 'file' )->upload( $file );

		$result = array(
			'status'	=> 1,
			'id'		=> 0
		);

		if( $id === false )
		{
			$result['status'] = 0;
		}
		else
		{
			$result['id'] = $id;
		}

		// do not return
		// echo json string instead and exit

		echo json_encode( $result ); exit;
	}
Ejemplo n.º 5
0
 function process($row)
 {
     Komento::setCurrentComponent($row->component);
     // set extension object
     $row->extension = Komento::loadApplication($row->component)->load($row->cid);
     if ($row->extension === false) {
         $row->extension = Komento::getErrorApplication($row->component, $row->cid);
     }
     // get permalink
     $row->pagelink = $row->extension->getContentPermalink();
     // set content title
     $row->contenttitle = $row->extension->getContentTitle();
     // set component title
     $row->componenttitle = $row->extension->getComponentName();
     return $row;
 }
Ejemplo n.º 6
0
 /**
  * Process comments data
  **/
 public static function process($row, $admin = 0)
 {
     if (isset($row->processed) && $row->processed) {
         return $row;
     }
     Komento::setCurrentComponent($row->component);
     $config = Komento::getConfig();
     $konfig = Komento::getKonfig();
     $user = JFactory::getUser()->id;
     $commentsModel = Komento::getModel('comments');
     Komento::import('helper', 'date');
     // Duplicate created date first before lapsed time messing up the original date
     $row->unformattedDate = $row->created;
     // get number of child for each comment
     $row->childs = $commentsModel->getTotalChilds($row->id);
     // set url to proper url
     if (!empty($row->url)) {
         // Add 'http://' if not present
         $row->url = 0 === strpos($row->url, 'http') ? $row->url : 'http://' . $row->url;
     }
     // 1. Load article and article details
     $application = Komento::loadApplication($row->component)->load($row->cid);
     if ($application === false) {
         $application = Komento::getErrorApplication($row->component, $row->cid);
     }
     // set component title
     $row->componenttitle = $application->getComponentName();
     // set content title
     $row->contenttitle = $application->getContentTitle();
     // get permalink
     $row->pagelink = $application->getContentPermalink();
     $row->permalink = $row->pagelink . '#kmt-' . $row->id;
     // set parentlink
     if ($row->parent_id != 0) {
         $row->parentlink = $row->pagelink . '#kmt-' . $row->parent_id;
     }
     // to be reassign
     $row->shortlink = $row->permalink;
     // set extension object
     // use this to check if application is able to load article details
     // if row->extension is false, means error loading article details
     $row->extension = $application;
     if ($admin == 0) {
         // frontend
         $actionsModel = Komento::getModel('actions');
         $socialHelper = Komento::getHelper('social');
         // parse comments HTML
         $row->comment = self::parseComment($row->comment);
         // author's object
         $row->author = Komento::getProfile($row->created_by);
         // don't convert for guest
         if ($row->created_by != 0 && $row->created_by != $row->author->id) {
             if ($config->get('enable_orphanitem_convert')) {
                 KomentoCommentHelper::convertOrphanitem($row->id);
             }
         }
         if ($row->created_by != 0) {
             switch ($config->get('name_type')) {
                 case 'username':
                     // force username
                     $row->name = $row->author->getUsername();
                     break;
                 case 'name':
                     $row->name = $row->author->getName();
                     break;
                 case 'default':
                 default:
                     // default name to profile if name is null
                     if (empty($row->name)) {
                         $row->name = $row->author->getName();
                     }
                     break;
             }
         } else {
             if (empty($row->name)) {
                 $row->name = JText::_('COM_KOMENTO_GUEST');
             } else {
                 if ($config->get('guest_label')) {
                     $row->name = JText::_('COM_KOMENTO_GUEST') . ' - ' . $row->name;
                 }
             }
         }
         // set datetime
         if ($config->get('enable_lapsed_time')) {
             $row->created = KomentoDateHelper::getLapsedTime($row->unformattedDate);
         } else {
             $dateformat = $config->get('date_format');
             $row->created = KomentoDateHelper::toFormat(KomentoDateHelper::dateWithOffSet($row->created), $dateformat);
             // $row->created = Komento::getDate( $row->created )->toFormat( $dateformat );
         }
         // get actions likes
         $row->likes = $actionsModel->countAction('likes', $row->id);
         // get user liked
         $row->liked = $actionsModel->liked($row->id, $user);
         // get user reported
         $row->reported = $actionsModel->reported($row->id, $user);
     } else {
         // backend
         // format comments
         $row->comment = nl2br(Komento::getHelper('comment')->parseBBCode($row->comment));
         $row->created = KomentoDateHelper::dateWithOffSet($row->created);
     }
     $row->processed = true;
     return $row;
 }
Ejemplo n.º 7
0
	public static function allow( $type, $comment = '', $component = '', $cid = '' )
	{
		// for complicated acl situations
		// $type = ['edit', 'delete', 'publish', 'unpublish', 'stick', 'delete_attachment'];

		if( !empty( $comment ) && ( empty( $component ) || empty( $cid ) ) )
		{
			if( !is_object( $comment ) )
			{
				$comment = Komento::getComment( $comment );
			}

			$component = $comment->component;
			$cid = $comment->cid;
		}

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

		$profile		= Komento::getProfile();
		$application	= Komento::loadApplication( $component )->load( $cid );

		Komento::setCurrentComponent( $component );

		switch( $type )
		{
			case 'edit':
				if( $profile->id != 0 && ($profile->allow( 'edit_all_comment' ) || ( $profile->id == $application->getAuthorId() && $profile->allow( 'author_edit_comment' ) ) || ( $profile->id == $comment->created_by && $profile->allow( 'edit_own_comment' ))))
				{
					return true;
				}
				break;
			case 'delete':
				if( $profile->id != 0 && ($profile->allow( 'delete_all_comment' ) || ( $profile->id == $application->getAuthorId() && $profile->allow( 'author_delete_comment' ) ) || ( $profile->id == $comment->created_by && $profile->allow( 'delete_own_comment' ))))
				{
					return true;
				}
				break;
			case 'publish':
				if( $profile->allow( 'publish_all_comment' ) || ( $profile->id == $application->getAuthorId() && $profile->allow( 'author_publish_comment' ) ) )
				{
					return true;
				}
				break;
			case 'unpublish':
				if( $profile->allow( 'unpublish_all_comment' ) || ( $profile->id == $application->getAuthorId() && $profile->allow( 'author_unpublish_comment' ) ) )
				{
					return true;
				}
				break;
			case 'stick':
				if( $profile->allow( 'stick_all_comment' ) || ( $profile->id == $application->getAuthorId() && $profile->allow( 'author_stick_comment' ) ) )
				{
					return true;
				}
				break;
			case 'like':
				if( $profile->allow( 'like_comment' ) )
				{
					return true;
				}
				break;
			case 'report':
				if( $profile->allow( 'report_comment' ) )
				{
					return true;
				}
				break;
			case 'delete_attachment':
				if( $profile->allow( 'delete_all_attachment' ) || ( $profile->id == $application->getAuthorId() && $profile->allow( 'author_delete_attachment' ) ) || ( $profile->id == $comment->created_by && $profile->allow( 'delete_own_attachment' ) ) )
				{
					return true;
				}
				break;
		}

		return false;
	}
Ejemplo n.º 8
0
 public function approveComment()
 {
     $id = JRequest::getInt('commentId', '');
     $comment = Komento::getComment($id);
     Komento::setCurrentComponent($comment->component);
     $acl = Komento::getHelper('acl');
     $type = 'message';
     $message = '';
     if (!$acl->allow('publish', $comment)) {
         $type = 'error';
         $message = JText::_('COM_KOMENTO_NOT_ALLOWED');
         $this->setRedirect('index.php?option=com_komento', $message, $type);
         return false;
     }
     $model = Komento::getModel('comments');
     if ($model->publish($id)) {
         $message = JText::_('COM_KOMENTO_COMMENTS_COMMENT_PUBLISHED');
     } else {
         $message = JText::_('COM_KOMENTO_COMMENTS_COMMENT_PUBLISH_ERROR');
         $type = 'error';
     }
     $this->setRedirect('index.php?option=com_komento', $message, $type);
     return true;
 }
Ejemplo n.º 9
0
* 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-mod modKomentoComments kmt-mod-comments<?php 
echo $params->get('moduleclass_sfx');
?>
">
	<?php 
foreach ($comments as $row) {
    // initialise current row component
    Komento::setCurrentComponent($row->component);
    $config = Komento::getConfig();
    $row = Komento::getHelper('comment')->process($row);
    //convert <br /> to \n
    $row->comment = str_replace("<br />", "\n", $row->comment);
    $row->comment = strip_tags($row->comment);
    // trim comment length
    if (JString::strlen($row->comment) > $params->get('maxcommentlength')) {
        $row->comment = JString::substr($row->comment, 0, $params->get('maxcommentlength')) . '...';
    }
    // convert back \n to <br />
    $row->comment = str_replace("\n", "<br/>", $row->comment);
    $row->comment = str_replace("<br/><br/>", "<br/>", $row->comment);
    // trim title length
    if (JString::strlen($row->contenttitle) > $params->get('maxtitlelength')) {
        $row->contenttitle = JString::substr($row->contenttitle, 0, $params->get('maxtitlelength')) . '...';