Keyword

k2 items view title and itrotext but login to read

  • Vlachos Evaggelos
  • Vlachos Evaggelos's Avatar Topic Author
  • Offline
  • Junior Member
More
9 years 10 months ago #133880 by Vlachos Evaggelos
k2 items view title and itrotext but login to read was created by Vlachos Evaggelos
Is possible all visitors ( public access )in a site view k2 items ( in category view or in category listings ) title and intro text but if click to read items require them to do login? Now when give Access level in a k2 item, non login users dont view title and introtext... not see the item.

Thanks for your time again :)

Please Log in or Create an account to join the conversation.

  • Vlachos Evaggelos
  • Vlachos Evaggelos's Avatar Topic Author
  • Offline
  • Junior Member
More
9 years 10 months ago #133886 by Vlachos Evaggelos
Replied by Vlachos Evaggelos on topic k2 items view title and itrotext but login to read
Example

Create a k2 item and give public access, item view by anyone.

Copy url of the item.

Give access level registered to the item. Now item dont view in category listing.

If paste the item url in brower the site ask me for username and password.

Exacly this i want. View all items all visitors (registered or not) but whet click in item site ask username and password depending το item access level.

What php files need modification for this?

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
9 years 10 months ago #133918 by Krikor Boghossian
Replied by Krikor Boghossian on topic k2 items view title and itrotext but login to read
Please search the forum before posting.
There is a similar question just before yours.

www.joomlaworks.net/forum/k2-en/37670-premium-content-items-invisible-if-not-logged-in

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.

  • Vlachos Evaggelos
  • Vlachos Evaggelos's Avatar Topic Author
  • Offline
  • Junior Member
More
9 years 10 months ago #133930 by Vlachos Evaggelos
Replied by Vlachos Evaggelos on topic k2 items view title and itrotext but login to read
Sorry but dont understande what php files need modification with this code

$user = JFactory::getUser();

if ($user->guest) {
echo "<p>You must login to see the content. I want your email address.</p>";
} else {
// do sth

It is possible to help me to find what php files need modifications?

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
9 years 10 months ago #133998 by Krikor Boghossian
Replied by Krikor Boghossian on topic k2 items view title and itrotext but login to read

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.

  • Vlachos Evaggelos
  • Vlachos Evaggelos's Avatar Topic Author
  • Offline
  • Junior Member
More
9 years 10 months ago #134088 by Vlachos Evaggelos
Replied by Vlachos Evaggelos on topic k2 items view title and itrotext but login to read
i now the way to overrides k2 files but i dont now what files edit to put the code

$user = JFactory::getUser();

if ($user->guest) {
echo "<p>You must login to see the content. I want your email address.</p>";
} else {
// do sth

So if you want help me please tell me what php files to edit so everyone can see all the items but just clicked the link to read them seeking for login page if the item has access level not public.

Please Log in or Create an account to join the conversation.

  • Vlachos Evaggelos
  • Vlachos Evaggelos's Avatar Topic Author
  • Offline
  • Junior Member
More
9 years 10 months ago #134092 by Vlachos Evaggelos
Replied by Vlachos Evaggelos on topic k2 items view title and itrotext but login to read
******@****:~/domains/*******/public_html$ find . | xargs grep 'K2_YOU_NEED_TO_LOGIN_FIRST' -sl
./components/com_k2/helpers/permissions.php
./components/com_k2/controllers/comments.php
./components/com_k2/controllers/item.php
./components/com_k2/views/itemlist/view.raw.php
./components/com_k2/views/itemlist/view.html.php
./components/com_k2/views/itemlist/view.feed.php
./components/com_k2/views/item/view.raw.php
./components/com_k2/views/item/view.html.php
./language/en-GB/en-GB.com_k2.ini
./plugins/system/k2/k2.php


./components/com_k2/views/itemlist/view.html.php is the right file?

This code need edit?
// Access check
		if ($this->getLayout() == 'form')
		{
			JError::raiseError(403, JText::_('K2_ALERTNOTAUTH'));
		}
		if (K2_JVERSION != '15')
		{
			if (!in_array($item->access, $user->getAuthorisedViewLevels()) || !in_array($item->category->access, $user->getAuthorisedViewLevels()))
			{
				if ($user->guest)
				{
					$uri = JFactory::getURI();
					$url = 'index.php?option=com_users&view=login&return='.base64_encode($uri->toString());
					$mainframe->redirect(JRoute::_($url, false), JText::_('K2_YOU_NEED_TO_LOGIN_FIRST'));
				}
				else
				{
					JError::raiseError(403, JText::_('K2_ALERTNOTAUTH'));
					return;
				}
			}
		}
		else
		{
			if ($item->access > $user->get('aid', 0) || $item->category->access > $user->get('aid', 0))
			{

				if ($user->guest)
				{
					$uri = JFactory::getURI();
					$url = 'index.php?option=com_user&view=login&return='.base64_encode($uri->toString());
					$mainframe->redirect(JRoute::_($url, false), JText::_('K2_YOU_NEED_TO_LOGIN_FIRST'));
				}
				else
				{
					JError::raiseError(403, JText::_('K2_ALERTNOTAUTH'));
					return;
				}
			}
		}

Please Log in or Create an account to join the conversation.

  • Vlachos Evaggelos
  • Vlachos Evaggelos's Avatar Topic Author
  • Offline
  • Junior Member
More
9 years 10 months ago - 9 years 10 months ago #134094 by Vlachos Evaggelos
Replied by Vlachos Evaggelos on topic k2 items view title and itrotext but login to read
Where the user is no login mysql query for items is
SELECT i.*, 
  CASE WHEN i.modified = 0 THEN i.created ELSE i.modified END as lastChanged, c.name as categoryname,c.id as categoryid, c.alias as categoryalias, c.params as categoryparams 
  FROM r8zxh_k2_items as i RIGHT JOIN r8zxh_k2_categories AS c 
  ON c.id = i.catid 
  WHERE i.published = 1 
  AND i.access IN(1,1,5) 
  AND i.trash = 0 
  AND c.published = 1 
  AND c.access IN(1,1,5) 
  AND c.trash = 0 
  AND ( i.publish_up = '0000-00-00 00:00:00' OR i.publish_up <= '2014-11-18 13:36:24' ) 
  AND ( i.publish_down = '0000-00-00 00:00:00' OR i.publish_down >= '2014-11-18 13:36:24' ) 
  AND c.id IN (130) 
  ORDER BY i.id DESC 
  LIMIT 0, 14

when the user is login mysql auery for items is
SELECT i.*, 
  CASE WHEN i.modified = 0 THEN i.created ELSE i.modified END as lastChanged, c.name as categoryname,c.id as categoryid, c.alias as categoryalias, c.params as categoryparams 
  FROM r8zxh_k2_items as i RIGHT JOIN r8zxh_k2_categories AS c 
  ON c.id = i.catid 
  WHERE i.published = 1 
  AND i.access IN(1,1,2,6) 
  AND i.trash = 0 
  AND c.published = 1 
  AND c.access IN(1,1,2,6) 
  AND c.trash = 0 
  AND ( i.publish_up = '0000-00-00 00:00:00' OR i.publish_up <= '2014-11-18 13:37:05' ) 
  AND ( i.publish_down = '0000-00-00 00:00:00' OR i.publish_down >= '2014-11-18 13:37:05' ) 
  AND c.id IN (130) 
  ORDER BY i.id DESC 
  LIMIT 0, 14

ths different is AND i.access IN(1,1,5) AND c.access IN(1,1,2,6). I want no login users to view second query list.

For this edit components/com_k2/models/itemlist.php:65 ????
$query .= "i.access IN(".implode(',', $user->getAuthorisedViewLevels()).")"." AND i.trash = 0"." AND c.published = 1"." AND c.access IN(".implode(',', $user->getAuthorisedViewLevels()).")"." AND c.trash = 0";


The logic is right???
Last edit: 9 years 10 months ago by Vlachos Evaggelos.

Please Log in or Create an account to join the conversation.

  • Vlachos Evaggelos
  • Vlachos Evaggelos's Avatar Topic Author
  • Offline
  • Junior Member
More
9 years 10 months ago - 9 years 10 months ago #134098 by Vlachos Evaggelos
Replied by Vlachos Evaggelos on topic k2 items view title and itrotext but login to read
1.) if not use joomla 1.5 and
2.) need to view non login users all k2 items where have access level public and register (if need extra access levels just put level(s) id in "i.access IN(1,2, your_extra_level_id(s))" edit ./components/com_k2/models/itemlist.php


final code ./components/com_k2/models/itemlist.php:62-88

if ($user->guest)
        {

            $query .= "i.access IN(1,2)"." AND i.trash = 0"." AND c.published = 1"." AND c.access IN(".implode(',', $user->getAuthorisedViewLevels()).")"." AND c.trash = 0";

            $mainframe = JFactory::getApplication();
            $languageFilter = $mainframe->getLanguageFilter();
            if ($languageFilter)
            {
                $languageTag = JFactory::getLanguage()->getTag();
                $query .= " AND c.language IN (".$db->quote($languageTag).",".$db->quote('*').") 
						AND i.language IN (".$db->quote($languageTag).",".$db->quote('*').")";
            }
        }
        else
        {
            $query .= "i.access IN(".implode(',', $user->getAuthorisedViewLevels()).")"." AND i.trash = 0"." AND c.published = 1"." AND c.access IN(".implode(',', $user->getAuthorisedViewLevels()).")"." AND c.trash = 0";

            $mainframe = JFactory::getApplication();
            $languageFilter = $mainframe->getLanguageFilter();
            if ($languageFilter)
            {
                $languageTag = JFactory::getLanguage()->getTag();
                $query .= " AND c.language IN (".$db->quote($languageTag).",".$db->quote('*').") 
						AND i.language IN (".$db->quote($languageTag).",".$db->quote('*').")";
            }
        }

Please use k2 template for above changes... :)
Last edit: 9 years 10 months ago by Vlachos Evaggelos.

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
9 years 10 months ago #134105 by Krikor Boghossian
Replied by Krikor Boghossian on topic k2 items view title and itrotext but login to read
These are considered 'hacks' and you need to keep backups of your edits at all times.

This also changes the entire component's functionality. It would be better used in a plugin and have it run on specific categories only.

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.


Powered by Kunena Forum