How do I stop Joomla from including jQuery? - joomla

I've recently upgraded from Joomla 3.2.1 to Joomla 3.2.2.
In Joomla 3.2.1, I manually unset jQuery from being included:
$doc = JFactory::getDocument();
$dontInclude = array(
'/media/jui/js/jquery.js',
'/media/jui/js/jquery.min.js',
'/media/jui/js/jquery-noconflict.js',
'/media/jui/js/jquery-migrate.js',
'/media/jui/js/jquery-migrate.min.js',
'/media/jui/js/bootstrap.js',
'/media/system/js/core-uncompressed.js',
'/media/system/js/tabs-state.js',
'/media/system/js/core.js',
'/media/system/js/mootools-core.js',
'/media/system/js/mootools-core-uncompressed.js',
);
foreach($doc->_scripts as $key => $script){
if(in_array($key, $dontInclude)){
unset($doc->_scripts[$key]);
}
}
But this isn't working in Joomla 3.2.2. Is there a way to not include Joomla's jQuery in 3.2.2?

Another variation which works well for me with Joomla 3.4 is to edit the template > index.php file with something like:
$doc = JFactory::getDocument();
$headData = $doc->getHeadData();
$scripts = $headData['scripts'];
//scripts to remove, customise as required
unset($scripts[JUri::root(true) . '/media/system/js/mootools-core.js']);
unset($scripts[JUri::root(true) . '/media/system/js/mootools-more.js']);
unset($scripts[JUri::root(true) . '/media/system/js/core.js']);
unset($scripts[JUri::root(true) . '/media/system/js/modal.js']);
unset($scripts[JUri::root(true) . '/media/system/js/caption.js']);
unset($scripts[JUri::root(true) . '/media/jui/js/jquery.min.js']);
unset($scripts[JUri::root(true) . '/media/jui/js/jquery-noconflict.js']);
unset($scripts[JUri::root(true) . '/media/jui/js/bootstrap.min.js']);
unset($scripts[JUri::root(true) . '/media/jui/js/jquery-migrate.min.js']);
$headData['scripts'] = $scripts;
$doc->setHeadData($headData);

You need to add a prefix of JUri::root(true) before each of those file names - relative paths will not work

I've added:
$doNotInclude = array(
'jquery',
'bootstrap',
'behavior',
);
if(in_array($file, $doNotInclude)){
return;
}
immediately after:
list($key, $prefix, $file, $func) = static::extract($key);
in libraries/cms/html/html.php, in the "_" function.
I don't like it since its a modification to the Joomla core but it works. I'm still looking for a better solution.

You can also try something like this:
$removeScripts = [
'/media/jui/js/jquery.min.js',
'/media/jui/js/jquery-noconflict.js',
'/media/jui/js/jquery-migrate.min.js',
'/media/system/js/caption.js',
];
foreach ($removeScripts as $removeScript) {
unset($this->_scripts[JURI::root(true).$removeScript]);
}

The problem is with your in_array.
If you remove it by changing this:
foreach($doc->_scripts as $key => $script){
if(in_array($key, $dontInclude)){
unset($doc->_scripts[$key]);
}
}
to this:
foreach($doc->_scripts as $key => $script){
unset($doc->_scripts[$key]);
}
Then it works fine. It's pretty pointless checking if the array key exists as I gathered you haven't manually deleted any of these files yourself.
Hope this helps

Joomla 3.3.6 loads scripts in different way so $doc->_scripts will return nothing... so there is nothing to unset.
I recommend to use this plugin: https://github.com/Poznakomlus/joomla_options
It allows you to remove bootstrap, jQuery and mootools (you can choose what to disable).
Disclaimer: I'm not affiliated any way with plugin developer or plugin itself in any way.

If you are writing a custom template or a component, where you need to remove all the scripts loaded by default inside Joomla you can create a simple plugin and bind the execution to the onBeforeCompileHead event.
My implementation was as below. Its very simple. You can further play around with the search list, by being specific to file names or just plain blacklisting the parent folder.
protected $app;
public function onBeforeCompileHead() {
// Front end
if ($this->app instanceof JApplicationSite) {
$doc = JFactory::getDocument();
$search = array(
'jui/js/',
'system/js/'
);
foreach ($doc->_scripts as $key => $script) {
foreach ($search as $findme) {
if (stristr($key, $findme) !== false) {
unset($doc->_scripts[$key]);
}
}
}
}
}

This worked for me in joomla 3.9
<?php
defined('_JEXEC') or die('Restricted access');
$unset_scripts = [
'/media/jui/js/jquery.min.js',
'/media/jui/js/jquery-noconflict.js',
'/media/jui/js/jquery-migrate.min.js',
'/media/system/js/caption.js',
];
foreach ($unset_scripts as $script) {
unset($this->_scripts[JURI::root(true) . $script]);
}
if (isset($this->_script['text/javascript'])) {
$captionJsStr = '%jQuery\(window\)\.on\(\'load\',\s*function\(\)\s*{\s*new\s*JCaption\(\'img.caption\'\);\s*}\);\s*%';
$this->_script['text/javascript'] = preg_replace($captionJsStr, '', $this->_script['text/javascript']);
if (empty($this->_script['text/javascript'])) {
unset($this->_script['text/javascript']);
}
}
$this->_scripts = array();
?>
<!DOCTYPE html>

Related

I want to Download multiple images as a zip file using laravel 7

I am a beginner at laravel and I want to downloads multiple images as a zip file using laravel but I do not have an idea how can I do that please help me thanks.
InboxController
public function dowloads($id)
{
$clientfiles = Inbox::where('id', $id)->first();
dd($clientfiles->file);
// "["phpIgRq3Q.jpg","phpe6b34M.jpg","phpnPGN2M.png","php8CQh5P.jpg"]"
$files =config('yourstitchart.file_url');
// $files = "http://localhost/yourstitchart.com/web/public/uploads/images/"
}
HTML view
<a href="{{ route('download.inbox',$digitizingInbox->id) }}" class="download
btn btn-warning">Download
</a>
Route
Route::get('downloads/{id}/files','DigitizingInboxController#dowloads')->name('download.inbox');
You can also use Chumper/Zipper package to make zip files. It is used by many developers. check here
You can try it like:
$zipper = Zipper::make(public_path('/documents/deals.zip'));
$clientfiles = Inbox::where('id', $id)->first();
foreach ($clientfiles->file as $file) {
$zipper->add(public_path($file)); // update it by your path
}
$zipper->close();
return response()
->download(
public_path('/temporary_files/' . "deals.zip"),
"deals.zip",
["Content-Type" => "application/zip"]
);

Stop Loading Automatic Scripts in Joomla 2.5

In Joomla 2.5, the scripts below are loaded automatically.
<script src="/media/system/js/mootools-core.js" type="text/javascript"></script>
<script src="/media/system/js/core.js" type="text/javascript"></script>
<script src="/media/system/js/caption.js" type="text/javascript"></script>
<script src="/media/system/js/mootools-more.js" type="text/javascript"></script>
<script src="/templates/pswedge/js/jquery.min.js" type="text/javascript" defer="defer"></script>
I don't want to load these files. How can I remove these links?
I would not recommend you to change the core files of Joomla.But if you really need to that then you can try this:
Step to disable the preloaded script file in joomla template.
Step one: Using your favorite file editor, open for edit:
/libraries/joomla/document/html/renderer/head.php
Step one: Find this code at line 151 and update it to include the code with this :
// Generate script file links
foreach ($document->_scripts as $strSrc => $strAttr)
{
// Code to disable mootools for your site (still loads it for your admin)
$ex_src = explode("/",$strSrc);
$js_file_name = $ex_src[count($ex_src)-1];
$js_to_ignore = array("mootools-core.js","mootools-more.js","core.js","caption.js");
if( in_array($js_file_name,$js_to_ignore) AND substr_count($document->baseurl,"/administrator") < 1 AND $_GET['view'] != 'form')
continue;
$buffer .= $tab . '<script src="' . $strSrc . '"';
if (!is_null($strAttr['mime']))
{
$buffer .= ' type="' . $strAttr['mime'] . '"';
}
if ($strAttr['defer'])
{
$buffer .= ' defer="defer"';
}
if ($strAttr['async'])
{
$buffer .= ' async="async"';
}
$buffer .= '</script>' . $lnEnd;
}
After saving the changes above, clear the cache that you have set and test your Joomla website and your Joomla Admin Dashboard. If you view the source code,all the predefind files are not there.
Or
You can try like this to hide it from index.php in template. Just put this line before the <jdoc:include type="head" /> and make necessary changes as needed to the scripts.
<?php
$search = array('mootools-more.js', 'caption.js');
// remove the js files
foreach($this->_scripts as $key => $script) {
foreach($search as $findme) {
if(stristr($key, $findme) !== false) {
unset($this->_scripts[$key]);
}
}
}
?>
May one of these method work-
Method 1:
Put Before <jdoc:include type="head" />
$search = array('mootools', 'caption.js');
// remove the js files
foreach($this->_scripts as $key => $script) {
foreach($search as $findme) {
if(stristr($key, $findme) !== false) {
unset($this->_scripts[$key]);
}
}
}
//Method 2
in index.php of template
$parameter_script = 'scripts';
$headerstuff=$document->getHeadData();
reset($headerstuff[$parameter_script]);
foreach($headerstuff[$parameter_script] as $key=>$value){
unset($headerstuff[$parameter_script][$key]);
}
$document->setHeadData($headerstuff);
//Method 3
In the file directory /plugins/system create a new file called “removemootools.php” and insert the following code (you will need to register the plugin in the database, too).
class plgSystemRemoveMooTools extends JPlugin
{
public function onAfterDispatch()
{
$app = JFactory::getApplication();
if($app->isSite()) //Only ever remove MooTools from the client-side, never the admin side
{
//Repeat these three line for all js you want to exclude
$mootools = JURI::root(true).DS.'media'.DS.'system'.DS.'js'.DS.'mootools.js';
$document = JFactory::getDocument();
unset($document->_scripts[$mootools]);
}
}
}
I used this code to remove jquery files from the head ( Joomla! 3.3.1 )
<?php
//Remove jquery
$search = array('jquery', 'jquery.min.js');
// remove the js files
foreach($this->_scripts as $key => $script) {
foreach($search as $findme) {
if(stristr($key, $findme) !== false) {
unset($this->_scripts[$key]);
}
}
}
?>
<jdoc:include type="head" />

Joomla - renderModule function strips javascript

please help, I've a problem with Joomla's function renderModule.. I am trying to render module with this function, but it unfortunately strips javascript from the the rendered module.
I use the function in my own module which includes other modules according to current article..
The code is as following:
<?php
$moduleType = "j15html";
$moduleName = "test";
$option = JRequest::getVar( 'option', '' );
$view = JRequest::getVar( 'view', '' );
$id = JRequest::getInt( 'id', 0 );
$moduleName .= $id;
//echo $view;
if ( $option == "com_content" && $view == "article" ) {
//echo $moduleName;
$module = JModuleHelper::getModule($moduleType, $moduleName);
//print_r($module);
if ( ! empty( $module ) ) {
$attribs = array();
echo JModuleHelper::renderModule( $module, $attribs );
}
}
When I set the position of the included module to any position used in my template and set it to displat in particular menu section, it renders properly even with javascript and so on..
Any advices how to make this thing working?
You didn't mention which version of Joomla you're using - but you may want to check out SOURCERER it keeps coding how you put it and does not strip out extra coding.
Make sure you read the how-to so you know how to use it because it can seem a little confusing at first, but it has a button to 'change the tags' from < to << or [ which do not get stripped out by the WYSIWYG editor in Joomla!.
Of course, that could be your issue also, if your WYSIWYG editor is on (by default it is) and you're inputting code - it strips it. An easy way is to just turn it off under global options, then when you save the code doesn't get stripped. Just turning off the WYSIWYG editor is the quick/easy/simple solution - but if you turn it back on and open that module again, the code will be gone. So it can be a tricky solution if others may like using the editor or if you're using lots of custom code around your side. In that case the plugin I mentioned above is a great solution.

can I use joomla's onAfterRender for a module rather than a plugin?

I want to insert some code to Joomla when any page is loaded.
For this I created a module that inserts code.
I am trying to use
<?php
// $Id: helper.php
defined('_JEXEC') or die;
jimport( 'joomla.plugin.plugin' );
jimport( 'joomla.environment.response' );
class modInsertCode
{
function onAfterRender($params)
{
$code = 'some code';
$documentbody = JResponse::getBody();
$documentbody = str_replace ("</body>", $code." </body>", $documentbody);
JResponse::setBody($documentbody);
return true;
}
}
?>
but JResponse::getBody(); returns an empty string. Any ideas, solutions of fixes to this code?
Thank you,
You have to do it using a plugin, you won't be able to do it using a module because the HTML response has not been generated by the time the code of the module gets executed.
I hope it helped!
I know this is a bit old but for future reference this can be done with jQuery:
$doc = JFactory::getDocument();
$js = 'jQuery(document).ready( function() {
jQuery("#module'.$module->id.'").appendTo(document.body);
})';
$doc->addScriptDeclaration($js);
This is assuming that you have wrapped the content in you module in something like the following, including the module id to support multiple instances of the module.
<div id="module<?php echo $module->id; ?>"> Your content </div>

WordPress plugin: finding the <!--more--> in the_content

I'm writing a WordPress plugin that filters the_content, and I'd like to make use of the <!--more--> tag, but it appears that it has been stripped out by the time it reaches me. This appears to be not a filter, but a function of the way WordPress works.
I could of course resort to reloading the already-loaded content from the database, but that sounds like it might cause other troubles. Is there any good way for me to get the raw content without the <!--more--> removed?
Chances are, by the time your plugin runs, <!--more--> has been converted to <span id="more-1"></span>
This is what I use in my plugin, which injects some markup immediately after the <!--more--> tag:
add_filter('the_content', 'inject_content_filter', 999);
function inject_content_filter($content) {
$myMarkup = "my markup here<br>";
$content = preg_replace('/<span id\=\"(more\-\d+)"><\/span>/', '<span id="\1"></span>'."\n\n". $myMarkup ."\n\n", $content);
return $content;
}
You can use the follow code:
The !is_single() will avoid display the more link in the View Post page.
add_filter('the_content', 'filter_post_content');
function filter_post_content($content,$post_id='') {
if ($post_id=='') {
global $post;
$post_id = $post->ID;
}
// Check for the "more" tags
$more_pos = strpos($filtered_content, '<!--more-->');
if ($more_pos && !is_single()) {
$filtered_content = substr($filtered_content, 0, $more_pos);
$replace_by = '<a href="' . get_permalink($post_id) . '#more-' . $post_id
. '" class="more-link">Read More <span class="meta-nav">→</span></a>';
$filtered_content = $filtered_content . $replace_by;
}
return $filtered_content;
}
Based on Frank Farmer's answer I solved to add thumbnail photo after the generated more tag (<span id="more-...) in single.php file with this:
// change more tag to post's thumbnail in single.php
add_filter('the_content', function($content)
{
if(has_post_thumbnail())
{
$post_thumbnail = get_the_post_thumbnail(get_the_ID(), 'thumbnail', array('class'=>'img img-responsive img-thumbnail', 'style'=>'margin-top:5px;'));
$content = preg_replace('/<span id\=\"(more\-\d+)"><\/span>/', '<span id="\1"></span>'.$post_thumbnail, $content);
}
return $content;
}, 999);

Resources