how to restrict access specific article in joomla by IP address? - joomla

i have one article under a menu in JOOMLA and want to restrict the contents of that article by range of allowed or deny IP addresses. please suggest.

The easiest way to do this one is customizing source code inside com_content component if you are a developer
<?php $deny = array("111.111.111", "222.222.222", "333.333.333");
if (in_array ($_SERVER['REMOTE_ADDR'], $deny)) {
header("location: https://example.com/");
exit();
} ?>

Related

Roles and permissions issues in laravel project

I am working on a laravel project. I have a side menu that is persistent across all pages. However the menu items to be shown is dependent on the role assigned to the user. I achieved that by doing this:
<?php
/**$links = Session::get('links'); **/
use Illuminate\Support\Facades\DB;
$id_hr_employee= Auth::user()->id_hr_employee;
$links = DB::select("select a.link as links from sys_menu_links as a a.id_hr_employee = $id_hr_employee)
");
?>
#if(isset($links))
#foreach($links as $link)
<li><hr class="light-grey-hr mb-10"/></li>
#include("$link->links")
#endforeach
#endif
This works quite alright. However, if someone enters a route to a menu (that he is not assigned to) on the address bar, he sees that page.
Please how do I prevent this?
i would highly recommend you using laratrust: https://laratrust.readthedocs.io/en/4.0/.
And to secure your sides: 1.option work with middelware to Block your admin views 2. Option Check for permission in the Controller files.
As a guidance you could look up this tutorial: http://itsolutionstuff.com/post/laravel-52-user-acl-roles-and-permissions-with-middleware-using-entrust-from-scratch-tutorialexample.html
greetings

Breadcrumb in magento

I am to magento. I got breadcrumb in my static blocks by default. But In my dashboard page, it is not displaying.I have searched in Google but nothing works. Can anyone tell me how to add breadcrumb in my dashboard page.I want to display breadcrumb without using page.xml
Thanks in Advance.
Go to app\design\frontend\your-package\ your -theme\template\your-modulename\phtml-file and add the following code snippet as per your requirement
// to get breadcrumbs block
<?php $breadcrumbs = $this->getLayout()->getBlock('breadcrumbs');
// add first item ‘'home'’ with link
$breadcrumbs->addCrumb(
'home',
array(
'label'=>$this->__('Home'),
'title'=>$this->__('Home'),
'link'=>Mage::getBaseUrl()
)
);
// add second item ‘'brands'’ without link
$breadcrumbs->addCrumb(
'brands',
array(
'label'=>$this->__('Brands'),
'title'=>$this->__('Brands')
)
);
echo $breadcrumbs->toHtml(); ?>
By default in magento breadcrumb not come for member account section. You can add breadcrumb using xml. Here is the blog post that explain complete steps:
http://www.douglasradburn.co.uk/adding-breadcrumbs-to-customer-account-pages-in-magento/
You can also use the below extension to add breadcrumb links:
http://www.magentocommerce.com/magento-connect/customer-account-breadcrumbs.html
You need to check its compatibility with latest version.

Magento disable cache only for cms pages

My requirement is to disable cache only for cms pages. So is there any way to achieve this functionality?
You need to rewrite / modify Mage_Cms_PageController models preDispatch method.
public function preDispatch() {
$cache = Mage::app()->getCacheInstance();
// Tell Magento to 'ban' the use of FPC, can also ban other types such as 'block_html'
$cache->banUse('full_page');
parent::preDispatch();
}
The better, cleaner and safer option than rewriting this controller is to use observers, these look at these events:
controller_action_predispatch
controller_action_predispatch_' . $this->getRequest()
controller_action_predispatch_' . $this->getFullActionName()
See Disable/Bypass Magento Full Page Cache on single page for more information.

Magento creating new customer page

Ok i cant figure this out at all. I have searched and i cant find anything either. Whats the best way to add a new page to the account section. I am trying to integrate a support ticket system into a magento account page i.e. so the user must be logged in and registered to use this feature. i can get this to work using a cms page and custom page layout. but then how do i set this custom cms page to only work for logged in users?
Also doing it this way this is showing the category menu and not the account menu. How can i get the my account menu to show instead? or is there a better way of doing this? Im new to magento and im really stuck and cant figure this out so any help would be appreciated.
Im running magento 1.7.0.2 community edition.
If I understand you correctly, just check to see if the customer is logged in, but in order to use PHP you're going to have to use the teplating system and create a module, or generate your own "stand alone page" If you go the module route:
if ($this->helper('customer')->isLoggedIn()){
//show page contents or do whatever ..
}
else{
header( 'Location: http://www.yoursite.com/customer/account/login/' ) ;
}
is all you'll need. IF you go the stand alone route:
//LOAD MAGENTO
require_once 'YOUR_PATH_TO_MAGENTO/app/Mage.php';
umask(0);
Mage::app('YOUR_WEBSITE_CODE', 'website');
//GET SESSION DATA
Mage::getSingleton('core/session', array('name'=>'frontend'));
$session = Mage::getSingleton('customer/session', array('name'=>'frontend'));
$customer_data = Mage::getModel('customer/customer')->$session->id);
//CHECK IF LOGGED IN
if($session->isLoggedIn()){
echo 'Welcome ' . $customer_data->firstname . " " . $customer_data->lastname;
} else {
echo "Access Denied: Sorry, but this page is for registered members only.";
exit;
}
Hope that helps
For any action there is a controller and action function.
So for your new feature you define an action.Make sure this action value is in URL.
Now within your controller add this action function
myAction()
{
if ($this->helper('customer')->isLoggedIn()){
//show page contents or do whatever ..
}
else{
header( 'Location: http://www.yoursite.com/customer/account/login/' ) ;
}
}
Although both of the answers above might have sufficed for the question posted, just for a note, it is surely not the correct way to work with Magento, a better understanding of how this can be achieved in the way according to magento practices, I think this tutorial from Alan Stormis a great place, however there is some problem with the preDispatch method in that blog, for which I think it might be better alternative:
public function preDispatch() {
parent::preDispatch();
if (!Mage::getSingleton('customer/session')->authenticate($this)) {
$this->setFlag('', 'no-dispatch', true);
}
}
Which I got from here.
In Alan's blog, If a customer is already logged in and try to go the custom account page, he is redirected to the homepage(It did in my case.)

Place certain article anywhere in joomla template

Is it possible in Joomla to place a certain article in a template, additionally to the normal content? I want the article to show up on every page.
You can simply take it from the databse and print its content. In the template, where you want to show the article, write this:
$id=/*Id of the article to show*/;
$db=&JFactory::getDBO();
$db->setQuery("SELECT * FROM #__content WHERE id=$id");
$item=$db->loadObject();
echo $item->introtext;
UPDATE: ENABLE PLUGINS
I can't find where i've used that code and i can't copy-paste it, so i try to write it again by looking at the view.html.php of the com_content:
JPluginHelper::importPlugin('content');
$dispatcher =& JDispatcher::getInstance();
$params = &$mainframe->getParams();
$dispatcher->trigger('onPrepareContent', array (&$item, &$params, 0));
//The last line triggers the onPrepareContent event, so if it does not work maybe you need other events, so try with onAfterDisplayTitle, onBeforeDisplayContent or onAfterDisplayContent
Have you seen this? http://extensions.joomla.org/extensions/news-display/content-embed/7528
It allows you to place any article as a module on your Joomla site. And with modules you can have them displayed site wide.

Resources