Custom script in footer of every page - joomla

Im writing a Joomla extension that allows a custom script to run on every "site" page.
I've already done the backend part including database access, but, now I'm completely stuck as to how to add custom javascript to every page of the "site", no matter what theme is installed. Also, I do NOT want to disturb any other stuff on the page.
I have been searching the net for almost 4hours, plus have tried modifying index.php file of templates in various ways, but all in-vain.
Any help?
Thanx in advance...
EDIT
I need to distribute this as an extension...

You need to create a content plugin. For example
class plgContentMyplugin extends JPlugin
{
public function onContentPrepare($context, &$article, &$params, $page = 0)
{
$document = JFactory::getDocument();
$document->addScript(JURI::base().'plugins/content/myplugin/js/myscript.js' );
}
}
This will add myscript.js in the <head>. Just check in docs how to package the plugin

Related

OctoberCMS and BotMan

I want to integrate a chatbot (BotMan version 2.0) into an existing OctoberCMS project , here is what I did till now :
1- I added BotMan to the projct using the following command :
composer require botman/botman
2- I created a routes.php file in the same directory as the plugin.php file
<?php
use BotMan\BotMan\BotMan;
use BotMan\BotMan\BotManFactory;
use BotMan\BotMan\Drivers\DriverManager;
//Route::match(['get', 'post'], '/botman', 'BotManController#handle');
//Route::get('/botman/tinker', 'October\Demo\BotManController#tinker');
// Create an instance
$botman = BotManFactory::create($config);
// Give the bot something to listen for.
$botman->hears('hello', function (BotMan $bot) {
$bot->reply('Hello yourself.');
});
// Start listening
$botman->listen();
My questions are :
1- Where I have to add the BotManController.php file
2- I tried to add BotManController.php in the same directory as the routes.php file but I get the following error :
Class 'App\Http\Controllers\Controller' not found
( and thats because its an OctoberCMS project not Laravel project ... I dont have the App directory )
Can anyone please provide me a solution to that or another way to integrate Botman into OctoberCMS !
First off, read https://luketowers.ca/blog/how-to-use-laravel-packages-in-october-cms-plugins/ as well as https://octobercms.com/docs/plugin/composer.
Secondly, you can put the BotManController file anywhere in your plugin you want as long as you understand PHP namespaces and how to properly reference it where you want to. I would probably recommend putting it in a /classes/ directory under your plugin folder, and then changing the App\Http\Controllers\Controller reference to instead reference the base Illuminate\Routing\Controller class. You could also put it in a /controllers/ directory, but in OctoberCMS that is typically reserved for your backend controllers so I wouldn't recommend mixing the two.

Any wordpress plugin image captcha with shortcode

I am trying to use a Image Captcha plugin on my website.
Currently I am using google reCaptcha plugin with V2.
But I need a captcha with Image (like Flexible Captcha), I tried using it, but Image dosen't load for this plugin.
I searched for many, but I want it with short code, so that I can place it on my custom forms.
Or If anyone knows how to remove image issue with "Flexible Captcha" plugin, please post your solution.
Edit:
I also tried to use the Securimage-WP plugin as suggested by drew010. Following is the output of plugin:
On Admin settings for plugin:
On Login page:
Note:
My website URL is like http:abc.com/myWebFolder/
Is this thing breaks the plugin to work or it could be the theme issue.
Thanks
My plugin Securimage-WP offers a shortcode for putting a captcha on a custom form.
The plugin also defines a function which you can then call to validate the submitted CAPTCHA.
I have posted a gist here which shows a WordPress page that uses the shortcode on a form and then validates the form and CAPTCHA. Note: Since this page uses PHP, you will need a plugin (I use Exec-PHP) that allows you to run PHP code in posts and pages.
If you need to validate the CAPTCHA in a form processor that is independent of WordPress, you can hook into WP and the plugin by including wp-load.php from the root of your WordPress install.
Comment if you have any questions. Hope this helps!
thank you drew010 for your help, I made complete new installation of wordpress & used your plugin & it worked, then I also used Flexible Captcha plugin & that also worked. Then in order to debug the real problem I add my custom plugin code in new Wordpress. Then it braked. Therefore, to debug more I added each method in my plugin & tested it worked with method. The culprit was following code:
/**/
?>
<?php
function displayLoginForm() {
/*
ob_start();
get_template_part( 'signin-form' );
$ret = ob_get_contents();
ob_end_clean();
return $ret; */
ob_start();
include(ABSPATH . "wp-content/plugins/tus-forms/Views/sign-in.php");
$output = signin_get_clean();
return $output;
}
?>
Changing above into following solved my problem:
function displayLoginForm() {
/*
ob_start();
get_template_part( 'signin-form' );
$ret = ob_get_contents();
ob_end_clean();
return $ret; */
ob_start();
include(ABSPATH . "wp-content/plugins/tus-forms/Views/sign-in.php");
$output = signin_get_clean();
return $output;
}
?>
But I still don't know the real reason behind this issue?
but finally it worked.
Thanks
Captcha On Login This plugin is more flexible with image and its having another feature include of blocking ip and removing ip from blocked. I am using this plugin it is really good.
enter image description here

smarty not working in codeigniter

I installed Smarty in Codeigniter and it's not really working. Here is what I did:
I followed this instructions:
http://sunwebexpert.com/books/detail/PHP/integrating-smarty-and-codeigniter.html
But I also put another file in the library: parser.php which is a library to do parsing (I've used it before with smarty and worked well)
the on Codeigniter's autoload.php wrote this:
$autoload['libraries'] = array('parser','smarty');
On main controller I wrote this function to test:
public function index()
{
$this->data['d'] = 2;
$this->parser->parse('base/test.tpl', $this->data);
}
but the result is no error display and I see the variable 'd' as it is wrote in the template:
{$d}
So I have two questions:
Why can't I see the variable value if I installed smarty as I did before in other projects?
How can I enable to see errors if there are?
The problem is that in codeigniter, there is a built-in library called Parser. That's why this may cause conflict with your library name. Try to rename your library name or use built-in library.
Here is how to display error on codeigniter.
Hope it will be useful for you.

Use sh404SEF router from a plugin

I'm developing a Joomla 2.5 content plugin that need to programatically create a SEF url when an article is saved.
I've managed to make this work when the regular Joomla SEF is activated. My plugin is using the regular Joomla JRoute::_(); to build a SEF URL. This works great with native Joomla.
For example the url
http://localhost/index.php?option=com_content&view=article&id=123
is translated to
http://localhost/index.php/mycategory/article-title-123.html
My code looks like this:
private function joomlaSefUrl($article){
require_once(JPATH_SITE.DS.'components'.DS.'com_content'.DS.'helpers'.DS.'route.php');
$siteURL = substr(JURI::root(), 0, -1);
if(JPATH_BASE == JPATH_ADMINISTRATOR) {
// In the back end we need to set the application to the site app instead
JFactory::$application = JApplication::getInstance('site');
}
$articleRoute = JRoute::_( ContentHelperRoute::getArticleRoute($article->id, $article->catid) );
$sefURI = str_replace(JURI::base(true), '', $articleRoute);
if(JPATH_BASE == JPATH_ADMINISTRATOR) {
$siteURL = str_replace($siteURL.DS.'administrator', '', $siteURL);
JFactory::$application = JApplication::getInstance('administrator');
}
$sefURL = $siteURL.$sefURI;
return $sefURL;
}
The problem is that when third party extensions like sh404SEF is installed the SEF URL that I get from using the JRoute::_() method is still the the regular Joomla route url:
http://localhost/index.php/mycategory/article-123.html
instead of the expected sh404SEF's url
http://localhost/Mycategory/article-title.html
Joomla doesn't see that the sh404SEF is installed, so by using the JRoute::(), I allways get the regular SEF Joomla url. So I need to find a way to use the sh404SEF JRoute::() class directly from within my plugin, instead of the regular Joomla router class.
Does anyone know how the sh404SEF classes work?
With Joomla! to get rid of the index.php section of the URL you need to turn on mod_rewrite in you global preferences and enable the .htaccess file that comes with the basic install. (When you first install Joomla! it's called htaccess.txt duplicate and rename the copy to .htaccess
For more complete information read this on Joomla Docs about SEF URLs.
You could try looking at the source of the sh404SEF plugins on JED
Use function getSefFromNonSef in file
administrator\components\com_sh404sef\helpers\general.php
Example:
$url = 'index.php?option=com_content&view=article&id=1:aaaaaaaaa&catid=2&Itemid=101'
$sef_url = Sh404sefHelperGeneral::getSefFromNonSef($url, true, false, null);
Remember, non-sef url, starting with index.php?...

Setting up Codeigniter HMVC with tank auth

I am having trouble getting a working Codeigniter version 2.0.3 with hmvc and tank auth(set up as a module) setup properly. I have installed CI properlly and then install HMVC with these directions https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc/wiki/Home
I get to my welcome controller/view as example just fine which means the HMVC is working. Next I try to add tank auth to the project by adding it to a folder in the modules folder. It has the proper controller/view/model etc.. setup within the tank auth. I even added in routes something like
$route["auth"]="auth/login";
I also extended the controller within the auth module to MX_Controller like as directed. Also in the constructor I have :
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
$this->load->library('security'); <--failing to load this
$this->load->library('tank_auth');
$this->lang->load('tank_auth');
$this->form_validation->CI =& $this;
It seems to be redirecting fine to the module however it comes up with an error saying ::
An Error Was Encountered
Unable to load the requested class: security
What am I doing wrong? Does any one have a working CI installation with HMVC and tank auth as a module so I can see how its done? I'm new to HMVC, thanks
I found the same problem, but i solved by simple adding a comment to the
$this->load->library('security');
so it will look like this:
//$this->load->library('security');
since security its now part of the codeigniter core, i guess its already loaded by default, and everything seems to be working pretty good
it is in Helper now according to CodeIgniter 3.0 user guide
try:
$this->load->helper('security');
I fix this, by creating Security.php file in application/libraries directory with the following code:
require_once(BASEPATH.'core/Security.php');
class Security extends CI_Security { }
I found a solution, I simply took the security.php file from codeigniters system/core folder and dropped it into system/libraries.
move the file security.php from system/core to system/libraries
then edit core/codeigniter.php line number 204 from $SEC =& load_class('Security', 'core'); to $SEC =& load_class('Security', 'libraries');
Security.php is present in "codeigniter/system/core/Security.php"
so provide this path your problem gets solved easily
load->library('../core/security');
I Read CodeIgniter 3.X User Guide and I was found that "Security" is available as a 'helper' Now.
So you need to change this;
$this->load->library('security');
into
$this->load->helper('security');
XSS Filtering
The Input class has the ability to filter input automatically to prevent cross-site scripting attacks. If you want the filter to run automatically every time it encounters POST or COOKIE data you can enable it by opening your application/config/config.php file and setting this:
$config['global_xss_filtering'] = TRUE;
You need to read a CodeIgniter 3.0 User Guide there are so many changes and implementation or please Refer change log.

Resources