I'm working on a plugin to work with a custom component I am developing for Joomla 3.3
However, with basic code firing in the event "onBeforeCompileHead", I am trying to update the canonical information that Joomla 3.3 produces, by taking all of the data from the array and resending it after modifying the data to add my own information.
However when adding custom code according to the Joomla programming guide (for starters) I do not see the code running nor does it add the head information needed for this test.
My code is as follows:
<?php
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
jimport('joomla.plugin.plugin');
class plgSystemCUSTOMPLUGIN extends JPlugin {
function onBeforeCompileHead() {
if ($this->params->get('site_url')) {
$document = JFactory::getDocument();
$headData = $document->getHeadData();
$headData['metaTags']['standard']['revised'] = $this->params->get('site_url');
$document->setHeadData($headData);
}
}
}
I've taken the if statement out, it was not even hitting this point. I've even added a basic PHP mailer call to send a test email if this function was hit at all.
The plugin was installed as a "System" plugin. It is loading however the class into the framework, as I am able to cause syntax errors. I've also checked and the dispatcher in Joomla's core is definitely loading the event.
Does anyone have insight as to what is going on here?
Thanks!
I've figured this out. My language file was not using the proper name for the plugin, and this will only work if the class name is like:
class plgSystem[plugin_name] {
}
I now have this working as expected.
Thanks!
Related
As stated in my question, how can i use the function which is inside joomla plugin folder from an external php file?
To be exact, it is under this patch "/plugins/system/rsfppayment/rsfppayment.php" and I want to use the function rsfp_afterConfirmPayment(). I pasted the code snippet below and this file is from rsForm Pro Paypal payment plugin.
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
/**
* RSForm! Pro Payment Plugin
*/
class plgSystemRSFPPayment extends JPlugin
{
function rsfp_afterConfirmPayment($SubmissionId) {
RSFormProHelper::sendSubmissionEmails($SubmissionId);
}
}
You can do the following:
require_once('/plugins/system/rsfppayment/rsfppayment.php');
$objplgSystemRSFPPayment = new plgSystemRSFPPayment();
$objplgSystemRSFPPayment->rsfp_afterConfirmPayment($submissionId);
Of course, you need to make sure that the path is correct and the value of $submissionId is valid.
Post the complete code then you use. The code of itoctopus is correct
What I want to accomplish
I am altering a PrestaShop module that currently uses a form submitted by a user to generate files to be a stand alone CRON job. The module works perfectly in the back office, and involves nothing more than a user clicking a button; a repetitive task that should instead be handled by a CRON job (the action, not the clicking of the button of course).
What I am trying
if (!defined('_PS_VERSION_')) {
// Initialize prestashop
require_once '../../config/config.inc.php';
require_once '../../init.php';
define('_PS_MODE_DEV_', true);
echo 'This gets echoed';
$exporter = new order_exporter;
echo 'This does not get echoed';
}
class order_exporter extends Module
{
// Rest of code here. Works when used with back office.
}
The behavior I am getting
The first echo works, but once I call $exporter = new order_exporter;, I get this error. PHP Fatal error: Class 'order_exporter' not found in C:\wamp\www\addressstamps\modules\order_exporter\order_exporter.php. This isn't on the screen and only in my error log. As I've understood in the past, this is the correct way to use OOP. I'm not sure if I'm misunderstanding something about Prestashop, OOP, or Scope, but after much research and tweaking, I have made no progress past this point.
This is not an OOP issue, but a PrestaShop design decision.
Try with:
$exporter = Module::getInstanceByName('order_exporter');
instead of:
$exporter = new order_exporter;
Here 'order_exporter' is your module name (i.e the name property from the class).
I had ReDJ plugin v 1.6 working on 2.5 Joomla site. But I'm moving on Joomla 3 and this module don't work now - exception errors appears. In change-logs I found this:
Changed class names for ALL models, controllers and views. So I simply add Legacy suffix to all classes that handles exceptions. And also change JRequest (it is deprecated in v3) on $input=JFactory::getApplication()->input;.
So for now, seems like all is working fine. Except.. component admin panel - i can see component menu, but there is no any content on page.
Here is screenshot: http://tinyurl.com/btfzxux
Main controller controller.php code:
http://pastebin.com/vQjYvYkK
Main component file redj.php code:
http://pastebin.com/gF6icdE3
I found that dont work line parent::display(); in controller.php file. And there is no error in logs and display.
And this line calls JControllerAdmin->display() which is:
/**
* Display is not supported by this controller.
*......................
*......................
*/
public function display($cachable = false, $urlparams = array())
{
return $this;
}
So nothing displayed. I tried to rename extends definition as JControllerLegasy (because it supports display() method), but still nothing in component output.
How can i output component content in admin panel in Joomla 3?
Any help appreciated.
S.G.
UPDATE 1:
I publish my code on GitHub. I'm tying to optimize this plugin for Joomla 3. Any help welcome!
https://github.com/staniaslavg/ReDJ
P.S. Now redirection list displays and adding a new one works fine. But.. there is no items in item list.
UPDATE 2:
Finally, everything works fine (tested jnly by me, but seems like everything is OK..)
P.S. If nothing displays in tabs - check for DataBase columns. I added a few more. Check whis by var_dump errors variable (like $this->get('Errors')) in files views/.../view.html.php
Code on GitHub: https://github.com/staniaslavg/ReDJ
I've posted some updates in the github repo, to show that it's possible to get it working. (for the redirects view sequence). Unforunately some code used in Joomla! 2.5 by the component was already deprecated and was removed in 3.0. Also the GUI looks bad in 3.0, it needs more work.
As much as I would like to help you to get it running, the time involved it huge. I would strongly suggest using Joomla! 2.5 which is still for a good period supported.
Also the developer announces that a Joomla! 3.0 version is underway.
Going over all the code and fixing it makes little sense for me, but here are some examples:
JDatabase::getEscaped() has been removed. Use JDatabase::escape() instead.
$db->getEscaped($orderCol.' '.$orderDirn)
=> $db->escape($orderCol.' '.$orderDirn)
JToolBar no longer supports the 'X' functions (eg, addNewX, editListX) that hide the main menu before doing the function.
and others.
I want my users to redirect to a custom URL after they successfully register in Joomla .
I can't find any option for that !
How can I achieve this ?
If you are using Joomla!'s built-in menu to load the registration page, or getting there from the Login module there isn't a way to redirect (which is odd because you can set a redirect after login in the login module).
The best place to start would be to look at existing solutions in the "Authentication" section of the Joomla! Extension Directory. It appears there are several listed that support both the old 1.5 style sites and the new 1.7/2.5 sites.
(By the way if you are still on 1.7 you should update to the latest 2.5 as there are serious security issues in the 1.7 line.)
In your code set do the following;
$app=JFactory::getapplication();
$app->redirect('index.php?option=com_users&view=login'));
You can achieve this with a plugin (at least in Joomla 3.x - not sure how far back this will work off-hand). Key here is the onUserAfterSave event, which tells you whether the user is new or existing.
I wrote the code below some time ago, so can't recall the exact reason the redirect could not be done from within the onUserAfterSave event handler, but I think the redirect is subsequently overridden elsewhere in the core Joomla user management code if you try to do it from there, hence saving a flag in the session and checking it in a later event handler.
class PlgUserSignupRedirect extends JPlugin
{
public function onUserAfterSave($user, $isnew, $success, $msg)
{
$app = JFactory::getApplication();
// If the user isn't new we don't act
if (!$isnew) {
return false;
}
$session = JFactory::getSession();
$session->set('signupRedirect', 1);
return true;
}
function onAfterRender() {
$session = JFactory::getSession();
if ($session->get('signupRedirect')) {
JFactory::getApplication()->redirect('/my-post-signup-url');
$session->clear('signupRedirect');
}
}
}
So I'm new at this whole CakePHP thing, but I'm looking to get the Uploader plugin installed. I'm stuck at the first installation step, after download/placing the files in the correct place: http://milesj.me/code/cakephp/uploader. I see this is the code I need to add somewhere:
// CakePHP 2
CakePlugin::load('Uploader');
App::import('Vendor', 'Uploader.Uploader');
$this->Uploader = new Uploader();
But I don't know where to put it! I'm using the basic "Blog tutorial", but I changed the name from "Posts" to "Media". Where would I put this code to get the plugin included? I'm not sure on the rest of the steps either, so if anyone could help me with that in terms of the default "Blog tutorial" setup, that'd be awesome. Thanks!
EDIT: I have the CakePlugin part working. I'm just unsure about the App:import line. I keep trying to add it inside my MediaController class, but it's just throwing errors. Where would this line go?
EDIT: App:import line is working, now I just need the new Uploader() part
I havn't used this specific plugin, but I have used one similar (MeioUpload).
The CakePlugin::load('Uploader') goes in your bootstrap configuration file (app/config/bootstrap.php)
App::import and the creation are likely to be handled within your "Media" controller.
For example. My Cake App uses App::uses('Sanitize', 'Utility'); in its PostController.
EDIT:
I assume it would be something like this.
<?php
App::import('Vendor', 'Uploader.Uploader');
class MediaController extends AppController {
$this->Uploader = new Uploader();
/* The rest of the controller */
}
But I could be wrong. The explanation for that plugin is weird.