- Posts: 30
COMMUNITY FORUM
Frontend Preview Button
- Omar Ramos
- Topic Author
- Offline
- Junior Member
Less
More
14 years 9 months ago #78582
by Omar Ramos
Frontend Preview Button was created by Omar Ramos
Requires modifications to 3 files:components/com_k2/views/item/view.html.phpcomponents/com_k2/views/item/tmpl/form.phpmodules/mod_k2_tools/helper.phpcomponents/com_k2/views/item/view.html.phpFirst we'll add the previewLink for the edit view around line 380 by checking to see if the article is not new (it has an article_id and a category_id): if ($item->id && $item->catid) { $this->assign('previewLink', JRoute::_(K2HelperRoute::getItemRoute($item->id, $item->catid) . '&preview=1')); } else { $this->assign('previewLink', ''); }components/com_k2/views/item/view.html.phpThen we'll add in the check to not show a 404 page if the article is not new (it has an article_id and a category_id) and the user is not a guest and the checked_out user id matches the current user id. This is around line 61://Published check if (!$item->published && !$user->guest && ($item->checked_out == $user->id)) { // Do nothing} else { // Do the normal published checks if (!$item->published || $item->trash) { JError::raiseError(404, JText::_("Item not found")); } if ($item->publish_up != $nullDate && $item->publish_up > $now) { JError::raiseError(404, JText::_("Item not found")); } if ($item->publish_down != $nullDate && $item->publish_down < $now) { JError::raiseError(404, JText::_("Item not found")); } if (!$item->category->published || $item->category->trash) { JError::raiseError(404, JText::_("Item not found")); }}components/com_k2/views/item/tmpl/form.phpIn this file we just need to add in the login to display the preview link and toolbar button when it should (should be around line 250 or so): <?php if ($this->previewLink) : ?> <td id="toolbar-preview" class="button"> <a class="toolbar" href="<?php echo $this->previewLink; ?>" target="_blank"> <span title="<?php echo JText::_('Preview');?>" class="icon-32-preview"></span> <?php echo JText::_('Preview');?> </a> </td> <?php endif; ?>modules/mod_k2_tools/helper.phpThen so that the K2 Breadcrumbs don't explode we need to add in a check to look for the "preview" value within the URL (around line 420: if (JRequest::getInt('preview') == 1) { $published = ''; // Ignore Publishing Options } else { $published = ' AND published=1 '; } $query = "SELECT * FROM #__k2_items WHERE id={$id} " . $published . "AND trash=0 AND access<={$aid} AND EXISTS (SELECT * FROM #__k2_categories WHERE #__k2_categories.id= #__k2_items.catid AND published=1 AND access<={$aid})"; $db->setQuery($query);
Please Log in or Create an account to join the conversation.