I have put a "Global:link" in the header of a view in Drupal 7. I suppose I could put the link as html in a Global:text area as well.
If the user is not admin I don't want them to see this link. So I have tried to put this code in my themes template.php:
// hide global text area in view header if user is not admin
function mytheme_views_pre_render(&$view) {
if ($view->name == 'taxonomy_term') {
dpm($view->name);
global $user;
// Check to see if $user has the administrator role or not.
if (!in_array('administrator', array_values($user->roles))) {
$header_item = $view->display_handler->get_option('header');
dpm($header_item['link']);
unset($header_item['link']);
}
}
}
}
.. but how do I unset a global field in the header of this specific view?
My code above does not do the trick.
Any help would be much appreciated!
SOLVED. I finally solved it. Here's the snippet. Hope it helps somebody having the same issue. Change "link" to whatever item you use in the header:
function mytheme_views_pre_view(&$view, &$display_id, &$args) {
if ($view->name == 'taxonomy_term') {
global $user;
$new_item = $view->get_item('page', 'header', 'link');
$new_item['text'] = "";
// Check to see if $user has the administrator role or not.
if (!in_array('administrator', array_values($user->roles))) {
$view->set_item('page', 'header', 'link', $new_item);
}
}
Related
Could you please tell me how to publish pages after clicking edit button (left top menu) mode in cocrete5 cms version 5.8.1.0 not using compose button?
I can't publish any page clicking edit button in top left corner, editing it and clicking edit button again.
Publish Changes Button is disabled and there is message:
"The field Page Thumbnail is required."
But I can publish using compose menu (next to edit in left top corner).
What's the cause of this problem? Is it concrete5 bug?
It looks like it allows to publish if I comment out lines in check for publishinh method. But I can't still understand the cause of issue and how to fix it.
class CheckIn extends BackendInterfacePageController
{
protected $viewPath = '/panels/page/check_in';
// we need this extra because this controller gets called by another page
// and that page needs to know how to submit it.
protected $controllerActionPath = '/ccm/system/panels/page/check_in';
public function canAccess()
{
return $this->permissions->canApprovePageVersions() || $this->permissions->canEditPageContents();
}
public function on_start()
{
parent::on_start();
if ($this->page) {
$v = CollectionVersion::get($this->page, "RECENT");
$this->set('publishDate', $v->getPublishDate());
$this->set('publishErrors', $this->checkForPublishing());
}
}
protected function checkForPublishing()
{
$c = $this->page;
// verify this page type has all the items necessary to be approved.
$e = Loader::helper('validation/error');
if ($c->isPageDraft()) {
if (!$c->getPageDraftTargetParentPageID()) {
$e->add(t('You haven\'t chosen where to publish this page.'));
}
}
$pagetype = $c->getPageTypeObject();
// if (is_object($pagetype)) {
// $validator = $pagetype->getPageTypeValidatorObject();
// $e->add($validator->validatePublishDraftRequest($c));
// }
if ($c->isPageDraft() && !$e->has()) {
$targetParentID = $c->getPageDraftTargetParentPageID();
if ($targetParentID) {
$tp = Page::getByID($targetParentID, 'ACTIVE');
$pp = new Permissions($tp);
if (!is_object($tp) || $tp->isError()) {
$e->add(t('Invalid target page.'));
} else {
if (!$pp->canAddSubCollection($pagetype)) {
$e->add(
t(
'You do not have permissions to add a page of this type in the selected location.'
)
);
}
}
}
}
return $e;
}
The error says it all? 'The field Page Thumbnail is required.' Did you actually add a thumbnail?
Basically you can't submit a form without filling in all the required fields.
Or did you and still got the error?
I could solve the issue overriding file:
<?php
namespace Application\Attribute\ImageFile;
use Loader;
use Core;
class Controller extends \Concrete\Attribute\ImageFile\Controller
{
public function validateValue()
{
$f = $this->getAttributeValue()->getValue();
if (is_object($f)) {
return true;
}
$e = Core::make('helper/validation/error');
$e->add(t('You must specify a valid file for %s', $this->attributeKey->getAttributeKeyDisplayName()));
return $e;
}
}
I'm trying to develop a plugin in Moodle. One of the requirements is to add an element to the Settings Menu, in which I was able to achieve with the help of this guide
https://docs.moodle.org/dev/Local_plugins#Adding_an_element_to_the_settings_menu
And this is my code in local/myplugin/lib.php
<?php
function local_myplugin_extends_settings_navigation($settingsnav, $context) {
// question_extend_settings_navigation
global $CFG, $PAGE;
// Only add this settings item on non-site course pages.
if (!$PAGE->course or $PAGE->course->id == 1) {
return;
}
// Only let users with the appropriate capability see this settings item.
/*if (!has_capability('moodle/backup:backupcourse', context_course::instance($PAGE->course->id))) {
return;
}*/
if ($settingnode = $settingsnav->find('courseadmin', navigation_node::TYPE_COURSE)) {
$strfoo = get_string('classrecord', 'local_myplugin');
$url = new moodle_url('/course/classrecord.php', array('id' => $PAGE->course->id));
$foonode = navigation_node::create(
$strfoo,
$url,
navigation_node::NODETYPE_LEAF,
'myplugin',
'myplugin',
new pix_icon('i/grades', $strfoo)
);
if ($PAGE->url->compare($url, URL_MATCH_BASE)) {
$foonode->make_active();
}
$settingnode->add_node($foonode);
}
}
?>
I allowed the students to see the element "Class Record" in the settings menu
My concern is that how can I hide/show Class Record I added?
Any ideas would be great!
If you want only certain users to see the link, then create an appropriate capability in local/myplugin/db/access.php, e.g. 'local/myplugin:viewclassrecord', defaulting to being assigned to the 'student' role. Then check for it in the function you have defined.
e.g.
if (!has_capability('local/myplugin:viewclassrecord', $context)) {
return;
}
I have set category page my default home page.But now i want to show CMS(Home page) for not logged in user while for logged-in i want to show category page.Means how i can set logic that can load both cms pages. How can i do that ? Thanks for any help in advance
<?php if(!Mage::getSingleton('customer/session')->isLoggedIn()): ?>
load->category page
<?php else: ?>//If user is NOT logged in
Load home page default one
<?php endif; ?>
IF you want only to check condition on home page .You can do like this .Change little bit code for CMS controller like this :
class Mage_Cms_IndexController extends Mage_Core_Controller_Front_Action
{
public function indexAction($coreRoute = null)
{
if(Mage::getSingleton('customer/session')->isLoggedIn())
{
Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getUrl('catalog/category/view/id/3'));
}else{
$pageId = Mage::getStoreConfig(Mage_Cms_Helper_Page::XML_PATH_HOME_PAGE);
if (!Mage::helper('cms/page')->renderPage($this, $pageId)) {
$this->_forward('defaultIndex');
}
}
}
Try and inform me about results.Hope this will solve your issue
This might work in your case :
// condition depending on login status of user
if(!$this->helper('customer')->isLoggedIn())
{
Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getBaseUrl());
die();
}
else
{
Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getUrl('YOUR_CATEGORY_URL'));
die();
}
IF above doesn't work, try this :
$sessionCustomer = Mage::getSingleton("customer/session");
if($sessionCustomer->isLoggedIn()) {
Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getUrl('YOUR_CATEGORY_URL'));
} else {
Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getBaseUrl());
}
i am using opencart in one project,
every thing is working fine but i am unable to find an option to stop view of home page until LOGIN.
actually this is project requirement, no one can see home until LOGIN.
is there way to do this with OPEN CART ?
Thanks
this is untested, but should point you in the right direction:
(OpenCart 1.4.9.x)
Save this to:
catalog/controller/common/check_login.php
<?php
class ControllerCommonCheckLogin extends Controller {
public function index() {
if (!$this->customer->isLogged()) {
// Require to be logged in
$ignore = array(
'account', 'payment'
);
$match = false;
if (isset($this->request->get['route'])) {
foreach ($ignore as $i) {
if (strpos($this->request->get['route'], $i) !== false) {
$match = true;
break;
}
}
}
// Show site if logged in as admin
$this->load->library('user');
$this->registry->set('user', new User($this->registry));
if (!$this->user->isLogged() && !$match) {
return $this->forward('account/login');
}
}
}
}
?>
Edit /index.php
Find:
// Maintenance Mode
$controller->addPreAction(new Action('common/maintenance/check'));
Add After:
// Login Check
$controller->addPreAction(new Action('common/check_login'));
Essentially use the same logic as the maintenence check... The big difference is it looks for the word 'account' in the string... If it finds it it allows the page to be displayed, if not it redirects to the login page...
Use the word "account" instead of "login" in case they need to register... All of the account pages already check for loggin so there is no worry there...
Again, untested so you may need to tweak one or two things - but it should/may work by dropping in the code
check_login.php for opencart 1.5.3
<?php
class ControllerCommonCheckLogin extends Controller {
public function index() {
// Require to be logged in
if (!$this->customer->isLogged()) {
// Require to be logged in
$ignore = array(
'account','payment'
);
$match = false;
if (isset($this->request->get['route'])) {
foreach ($ignore as $i) {
if (strpos($this->request->get['route'], $i) !== false) {
$match = true;
break;
}
}
}
// Show site if logged in as admin
$this->load->library('user');
$this->user = new User($this->registry);
if (!$this->user->isLogged() && !$match) {
$this->redirect($this->url->link('account/login'));
}
}
}
}
?>
There is nothing built-in that I know of, but you can do it yourself. Based on your answers to #CarpeNoctumDC's questions you may have to do some digging, but this should get you started:
system/library/customer.php
public function isLogged() { ... }
catalog/controller/common/home.php
if (!$this->customer->isLogged()) {
// login page
exit;
}
The right way to go about this is to open
/catalog/controller/common/home.php
find public function index() { at the top of the code, and after it put
if(!$this->customer->isLogged()) {
$this->session->data['redirect'] = $this->url->link('common/home');
$this->url->redirect('account/login', '', 'SSL');
}
In case you're unsure how to do this properly, just take a look at the first few lines after public function index() { in
/catalog/controller/account/account.php
setting your code in the home controller to common/home in place of account/account
I'm using a very simple plugin called Semi Private Comments which does almost everything I need, it hides comments from other users and allows only the author of the comment and the admin to view the comment. My problem is the plugin allows any admin comment to be viewed by anyone. I would like it to keep the comment between the admin and any user a one on one conversation.
I really don't know PHP well enough to modify the plugins logic and was hopping for some help.
Here's the code.
if (current_user_can('edit_users') || // user is admin, or
$user_matched==1 || // user is original author, or
$comment->user_id == 1) // comment author is admin
{
return $content;
}
else
{
$hidden_comment_text = get_option('spc_hidden_comment_text');
return $hidden_comment_text;
}
}
else
{
return $content;
}
I think just removing the $comment->user_id == 1 should do the trick
if (current_user_can('edit_users') || // user is admin, or
$user_matched==1) // user is original author
{
return $content; // Only admins and authors of the comment can read
}
else
{
$hidden_comment_text = get_option('spc_hidden_comment_text');
return $hidden_comment_text;
}
Btw, the code snipped you posted is incomplete the if statement of the following part is missing
}
else
{
return $content;
}