This is my plugin:
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
// Import library dependencies
jimport('joomla.plugin.plugin');
class plgContentEya extends JPlugin
{
function plgContentEya( &$subject, $config )
{
parent::__construct( $subject, $config );
}
/**
* Plugin method with the same name as the event will be called automatically.
*/
function onAfterDisplayContent( &$article, &$params, $limitstart)
{//Echo script there
echo "script works";
// Plugin code goes here.
// You can access parameters via $this->params.
return "<script src='http://widget.eya.com/sprk.1.0.2.js' type='text/javascript'></script>";
}
}
http://docs.joomla.org/Plugin/Events/Content
According to their documenation
Return Value
String. Returned value from this event will be displayed in a placeholder. Most templates display this placeholder after the article separator.
The plugin gets displayed and doesnt throw an error when I install it.. But the event never gets triggered. I dont see it in the document
<install version="2.5" type="plugin" group="content">
<name>plg_content_eya</name>
<author>eya</author>
<creationDate>February 2013</creationDate>
<copyright>(C) 2013 Open Source Matters. All rights reserved.</copyright>
<license>GNU General Public License version 2 or later; see LICENSE.txt</license>
<authorEmail>anattaligg#graeit.com</authorEmail>
<authorUrl>www.eya.com</authorUrl>
<version>2.5.0</version>
<description>Adds eya plugin ot your site</description>
<files>
<filename plugin="eya">eya.php</filename>
</files>
</install>
Based on the version="2.5" in your XML, your plugin is not being called because you have the wrong event name.
The event names have changed since the Plugin/Events/Content for Joomla! 1.5 document was written. I've marked it as a 1.5 document to make that clear.
Events were renamed to be more consistent (domain/period/event e.g. Content/After/Display), so, the event you want is now called onContentAfterSave and you can find more information about renamed events in the article "Adapting a Joomla 1.5 extension to Joomla 1.6"
If you want to support Joomla! 1.5 in your plug-in as well you will also have to add a compatibility layer to catch the 2.5 call and redirect it to your method. e.g.
// Catch 2.5
public function onContentAfterDisplay($article, $params, $limitstart)
{
$result = $this->onAfterDisplayContent($article, $params, $limitstart);
return $result;
}
N.B. Not tested code just typed in...
Related
My code in user file-
I am trying to onUserBeforeSave, but in this event, Joomla code is executed, control does not come to my code:
class PlgUserotp extends JPlugin
{
public function onUserBeforeSave($oldUser,$isnew,$newuser)
{
$errors = NULL;
$phone_number = NULL;
foreach ($newuser as $key => $value)
{
if($key=="username")
$username = $value;
elseif ($key=="email1")
$email = $value;
elseif ($key=="password1")
$password = $value;
else
$extra_data[$key]=$value;
}
//echo $username . $email .$password;
$this->startVerificationProcess($username,$email,$errors,$phone_number,$password,$extra_data);
//MoCurlOTP::mo_send_otp_token('EMAIL',$newuser["email1"],'');
}
}
The first step in debugging this issue is to make sure that your plugin is really being loaded. First add a die('In my plugin'); at the very beginning and see if it's really dying. If that's the case, then this means that Joomla is really loading your plugin (if it's not, then check that your plugin is enabled, also check that the System - cache plugin is disabled, just in case).
The next step is to make sure that Joomla is instantiating your plugin object, and this is done by adding a construct method, and then adding a die('In constructor'); in that function. If it's not displaying this message, then this means that your class name is not in line with the class name defined in your XML manifest file.
The last step is to check whether the onUserBeforeSave is really being triggered, by adding a die('In onUserBeforeSave'); at the very beginning of the function. If it's not triggered, then try debugging the file libraries/src/User/User.php (I'm assuming you're using Joomla 3.8.x), as the this event is triggered from there. If is being triggered, then this means that your code is working, but has no effect.
I have created a system plugin in joomla and created a custom method that is mymethod(). Now i want to call this method via ajax. I have tried link but it will create new ajax plugin but i want to call system plugin custom method not create new plugin.
You can use the plugin system event onAfterInitialise().
Use this url for ajax: index.php?type=mymethod
This leads to:
function onAfterInitialise() {
$jinput = JFactory::getApplication()->input;
if($jinput->get('type')=='mymethod') {
// your code here
}
}
The link is ok. You just need to change the folder name from ajax to system. Prior to joomla 3.4 it was mandatory to place your plugin in ajax folder but now you can place in any folder. Your code will look like this
JPluginHelper::importPlugin('system');
$plugin = ucfirst($input->get('plugin'));
$dispatcher = JEventDispatcher::getInstance();
try
{
$results = $dispatcher->trigger('myMethod' . $plugin);
}
catch (Exception $e)
{
$results = $e;
}
Follow rest instruction as given there.
I'm trying to write a single-signon extension so that our MediaWiki users with the correct permissions don't need to log in to our Joomla 2.5. I can't get it to work, because the onAfterInitialise event won't trigger (neither does onAfterRoute or onAfterDispatch if I try to use those instead). I know the extension is actually running because the onUserAuthentication event is triggering and logging me in as my test user.
Below is my code with the two events, the first won't trigger and execute the die() statement, the second triggers after login and unconditionally authenticates me properly.
Is there something I'm missing here like that one extension can't use two different categories of events or something?
class plgAuthenticationMwSSO extends JPlugin {
function __construct( &$subject, $config ) {
parent::__construct( $subject, $config );
}
public function onAfterInitialise() {
die('testing');
}
public function onUserAuthenticate( $creds, $opt, &$response ) {
$response->username = 'Foo';
$response->fullname = 'Foo Bar';
$response->email = 'foo#bar.baz';
$response->status = JAuthentication::STATUS_SUCCESS;
$response->error_message = '';
}
}
You need to put the onAfterInitialise in a system plugin. As a parallel example, notice how the Remember plugin is a system plugin and then the Cookie plugin is an authentication one. System plugins are checked very early in the stack and are checked on every page load. Authentication plugins are checked when authentication starts and are specifically loaded as a group at certain times. Since you have an authentication plugin, it is not triggered at the right time to respond to the system events that you are looking for.
I created a custom plugin and installed in joomla 2.5. It must be called when user logins.
My plugin has following code..
class plgUserZencartlogin extends JPlugin
{
public function __construct(& $subject, $config){
parent::__construct($subject, $config);
$this->loadLanguage();
}
public function onUserLogin($user, $options = array())
{
//here is my custom code..
}
}
Everything was worked fine upto installation. But is not getting triggered. I've gone through "onUserLogin" event, where it is shown that, it must be triggered automatically when user logins. But nothing was paid off for my hardwork. Thanks in advance..
We have several magento websites and some of them we would like to turn on the website restriction so only logged in customers can view it. This seems to work great except we have custom pages that we want the user to be able to access without having to login. And currently if we turn on access restriction it redirects all pages, except the login page and the password reset page, to the login page.
Does anyone know how to exclude other pages from being redirected to the login page? I think it would be a layout xml setting but I can't seem to figure it out or find anything on it.
Magento Enterprise version 1.12.02
Wow, this question is pretty valid, rather old, ranked high on on Google results, yet without a good answer. So here goes one.
The right way to exclude pages from restriction is by adding them to generic list of pages under Enterprise_WebsiteRestriction module config.
See app/code/core/Enterprise/WebsiteRestriction/etx/config.xml and config/frontend/enterprise/websiterestriction section in particular. Pages under full_action_names/generic are always accessible no matter what restriction level is set. Those in full_action_names/register are still accessible when restriction mode is set to "Login and Register" - i.e. they are intended for new registration to be possible.
The values under those sections are full actions names (i.e. <module>_<controller>_<action>), so e.g. to enable contact form for everyone, you need to add contacts_index_index to the generic list.
Note that editing files in core codepool is strongly discouranged, so to achieve this it's best to create your own module and add the configuration section.
It should look somewhat like this (remember to enable this module in app/etc/modules):
<?xml version="1.0"?>
<config>
<modules>
<Emki_WebsiteUnrestrict>
<version>0.1.0</version>
</Emki_WebsiteUnrestrict>
</modules>
<frontend>
<enterprise>
<websiterestriction>
<full_action_names>
<generic>
<contacts_index_index />
</generic>
</full_action_names>
</websiterestriction>
</enterprise>
</frontend>
</config>
Nick,There are several process for this function...
Step1:you can it from Controllers from using dispatch event.
/**
* Retrieve customer session model object
*
* #return Mage_Customer_Model_Session
*/
protected function _getSession()
{
return Mage::getSingleton('customer/session');
}
public function preDispatch()
{
// a brute-force protection here would be nice
parent::preDispatch();
if (!$this->getRequest()->isDispatched()) {
return;
}
$action = $this->getRequest()->getActionName();
/* put all action of this controllers for check ,if any actions of list is exit then redirect to login page*/
$openActions = array(
'index',
'post',
'autoy',
'confirmation'
);
$pattern = '/^(' . implode('|', $openActions) . ')/i';
if (!preg_match($pattern, $action)) {
if (!$this->_getSession()->authenticate($this)) {
$this->setFlag('', 'no-dispatch', true);
}
} else {
$this->_getSession()->setNoReferer(true);
}
}
/**
* Action postdispatch
*
* Remove No-referer flag from customer session after each action
*/
public function postDispatch()
{
parent::postDispatch();
$this->_getSession()->unsNoReferer(false);
}
Other thing is Using observer