Prestashop 1.6.1.4 - Add CSS to CMS Page of Module - css

I am making a module that adds new tab in product edit page. The installation is Prestashop 1.6.1.4. The module adds a tab with some input fields that send data to mysql tables, but what I want to do is to style the fields a little bit, so that they look good. I am adding this in my module.php file:
public function install() {
if ($this->psversion() == 5 || $this->psversion() == 6)
{
if (parent::install() == false or !$this->registerHook('displayHeader') or !$this->registerHook('productFooter') or !$this->registerHook('displayAdminProductsExtra') or !$this->registerHook('actionProductUpdate') or !$this->registerHook('displayBackOfficeHeader'))
{
return false;
}
}
return true;
}
Then below this I put this code:
public function hookDisplayBackOfficeHeader($params) {
$this->context->controller->addCSS($this->_path.'views/css/adminsportsnutritionfadd.css');
}
But can't make the .css file appear. The file is in the right location, it has proper permissions and the owner of the file is www-data:www-data so this shouldn't be a permission issue. I have disable css combining in Prestashop as well as caching. Before reloading the page I am also deleting Prestashop's cache just in case, as well as I am deleting my brower's cache. Can somebody give me a hand in this?

Do like this:
public function hookBackOfficeHeader()
{
$this->context->controller->addCSS($this->_path.'views/css/adminsportsnutritionfadd.css');
}
For me it works like this:
$this->context->controller->addCSS($this->_path . 'views/css/back.css');
So the only difference is the css file name.

Not sure if you got this sorted or not, but...
I use this function within most of my modules to add
jQuery, Font-awesome, CSS & JS, then have it show ONLY on that module page...
public function hookDisplayBackOfficeHeader($params)
{
if(!(Tools::getValue('controller') == 'AdminModules'
&& Tools::getValue('configure') == 'MyModuleName')
){
return;
}
else
{
if ( method_exists($this->context->controller, 'addJquery') )
{
$this->context->controller->addJquery();
$this->context->controller->addCss('//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css');
$this->context->controller->addCss($this->_path.'views/css/back.css');
$this->context->controller->addJs($this->_path.'views/js/back.js');
}
}
}

Related

admin_enqueue_scripts not loading any file when not logged in

I'm using admin_enqueue_scripts to load my own CSS and JS in the WP-Admin, and I know the JS file is working when logged in, but the CSS file isn't being loaded from what I can see.
I'm checking if logged out, is there any condition that makes this only apply to logged in users? There's nothign to suggest this is the case, and I'm certain my code is right.
Have I missed something here? To me, this should be working, but the style-admin file isn't being loaded on the login page, and there's nothing in the console either.
function sg_assets_admin() {
if(WP_DEBUG === false) {
wp_enqueue_style('sg-style-admin', get_template_directory_uri().'/css/style-admin.min.css');
} else {
wp_enqueue_style('sg-style-admin', get_template_directory_uri().'/css/style-admin.css');
}
wp_enqueue_media();
if(WP_DEBUG === false) {
wp_enqueue_script('sg-script-admin', get_template_directory_uri().'/js/script-admin.min.js');
} else {
wp_enqueue_script('sg-script-admin', get_template_directory_uri().'/js/script-admin.js');
}
}
add_action('admin_enqueue_scripts', 'sg_assets_admin');
It turns out the login page as I am trying to reference doesn't use admin_enqueue_scripts, but login_enqueue_scripts
https://developer.wordpress.org/reference/hooks/login_enqueue_scripts/
function sg_assets_admin() {
if(WP_DEBUG === false) {
wp_enqueue_style('sg-style-admin', get_template_directory_uri().'/css/style-admin.min.css');
} else {
wp_enqueue_style('sg-style-admin', get_template_directory_uri().'/css/style-admin.css');
}
wp_enqueue_media();
if(WP_DEBUG === false) {
wp_enqueue_script('sg-script-admin', get_template_directory_uri().'/js/script-admin.min.js',array('jquery'));
} else {
wp_enqueue_script('sg-script-admin', get_template_directory_uri().'/js/script-admin.js',array('jquery'));
}
}
add_action('admin_enqueue_scripts', 'sg_assets_admin');
Try above modified code

How to detect the Javascript injected suspicious file in my wordpress post?

Detected potentially suspicious content from the website malware scanner. It showing some code from the scan results:https://scanner.pcrisk.com/detailed_report/pragmaticwebmedia.com#details
But unable to find the script on my site. How to delete the dump code in the above results?
I just tried website scanner and cpanel scan but none helps.
[[ window._wpemojiSettings = { "baseUrl":"https://s.w.org/images/core/emoji/11.2.0/72x72/","ext":".png","svgUrl":"https://s.w.org/images/core/emoji/11.2.0/svg/","svgExt":".svg","source": { "concatemoji":"https://pragmaticwebmedia.com/wp-includes/js/wp-emoji-release.min.js?ver=5.1.1" } }; !function(a,b,c) { function d(a,b) { var c=String.fromCharCode; l.clearRect(0,0,k.width,k.height),l.fillText(c.apply(this,a),0,0); var d=k.toDataURL(); l.clearRect(0,0,k.width,k.height),l.fillText(c.apply(this,b),0,0); var e=k.toDataURL(); return d===e } function e(a) { var b; if(!l||!l.fillText)return!1; switch(l.textBaseline="top",l.font="600 32px Arial",a) { case"flag":return!(b=d([55356,56826,55356,56819],[55356,56826,8203,55356,56819]))%26%26(b=d([55356,57332,56128,56423,56128,56418,56128,56421,56128,56430,56128,56423,56128,56447],[55356,57332,8203,56128,56423,8203,56128,56418,8203,56128,56421,8203,56128,56430,8203,56128,56423,8203,56128,56447]),!b); case"emoji":return b=d([55358,56760,9792,65039],[55358,56760,8203,9792,65039]),!b } return!1 } function f(a) { var c=b.createElement("script"); c.src=a,c.defer=c.type="text/javascript",b.getElementsByTagName("head")[0].appendChild(c) } var g,h,i,j,k=b.createElement("canvas"),l=k.getContext%26%26k.getContext("2d"); for(j=Array("flag","emoji"),c.supports= { everything:!0,everythingExceptFlag:!0 } ,i=0; i]]
Need to find the script location to remove it.
Just... leave it.
It's default WordPress Javascript that make your emoji beautier. The script can be found at WordPress official website: https://twentyfourteendemo.wordpress.com
In case you want to remove it, install a plugin called Disable WP Emoji Icons.

Excluding bootstrap from specific routes in Meteor

I was hoping anyone could give some input on this,
I'm creating a meteor app in which I would like to use bootstrap to creating the admin environment, but have the visitor facing side using custom css. When I add the bootstrap package to my app using meteor it's available on every page, is there a way to restrict the loading of bootstrap to routes that are in '/admin' ?
When you add bootstrap package it's not possible. You can, however, add bootstrap csses to public directory and then load them in a header subtemplate that will only be rendered when you're in the dashboard.
EDIT
But then how would you go about creating seperate head templates?
Easy:
<head>
...
{{> adminHeader}}
...
</head>
<template name="adminHeader">
{{#if adminPage}}
... // Put links to bootstrap here
{{/if}}
</template>
Template.adminHeader.adminPage = function() {
return Session.get('adminPage');
}
Meteor.router.add({
'/admin': function() {
Session.set('adminPage', true);
...
}
});
DISCLAIMER: I am unsure of a 'meteor way' to do this, so here is how I would do it with plain JS.
jQuery
$("link[href='bootstrap.css']").remove();
JS - Credit to javascriptkit
function removejscssfile(filename, filetype){
var targetelement=(filetype=="js")? "script" : (filetype=="css")? "link" : "none" //determine element type to create nodelist from
var targetattr=(filetype=="js")? "src" : (filetype=="css")? "href" : "none" //determine corresponding attribute to test for
var allsuspects=document.getElementsByTagName(targetelement)
for (var i=allsuspects.length; i>=0; i--){ //search backwards within nodelist for matching elements to remove
if (allsuspects[i] && allsuspects[i].getAttribute(targetattr)!=null && allsuspects[i].getAttribute(targetattr).indexOf(filename)!=-1)
allsuspects[i].parentNode.removeChild(allsuspects[i]) //remove element by calling parentNode.removeChild()
}
}
removejscssfile("bootstrap.css", "css")
However, doing that would complete remove it from the page. I am not sure whether meteor would then try to readd it when a user goes to another page. If that does not automatically get readded, then you have an issue of bootstrap not being included when someone goes from the admin section to the main site, which would break the look of the site.
The way I would get around that would be to disable and enable the stylesheets:
Meteor.autorun(function(){
if(Session.get('nobootstrap')){
$("link[href='bootstrap.css']").disabled = true;
}else{
$("link[href='bootstrap.css']").disabled = false;
}
});
There my be other bootstrap resources which may need to be removed, take a look at what your page is loading.
To use jQuery in the same way but for the javascript files, remember to change link to script and href to src
From my tests, Meteor does not automatically re-add the files once they have been removed so you would need to find some way of re-adding them dynamically if you want the same user to be able to go back and forth between the main site and the admin site. Or simply if the http referrer to the main site is from the admin, force reload the page and then the bootstrap resources will load and everything will look pretty.
P.s. make sure you get the href correct for the jQuery version
If somebody is interested in including any js/css files, I've written a helper for it:
if (Meteor.isClient) {
// dynamic js / css include helper from public folder
Handlebars.registerHelper("INCLUDE_FILES", function(files) {
if (files != undefined) {
var array = files.split(',');
array.forEach(function(entity){
var regex = /(?:\.([^.]+))?$/;
var extension = regex.exec(entity)[1];
if(extension == "js"){
$('head').append('<script src="' + entity + '" data-dynamicJsCss type="text/javascript" ></script>');
} else if (extension == "css"){
$('head').append('<link href="' + entity + '" data-dynamicJsCss type="text/css" rel="stylesheet" />');
};
});
}
});
Router.onStop(function(){
$("[data-dynamicJsCss]").remove();
});
}
Then simply use:
{{INCLUDE_FILES '/css/html5reset.css, /js/test.js'}}
in any of your loaded templates :)

Fishpig Magento/Wordpress Integration - Appending a WordPress custom menu doesn't set active states

I'm using Fishpigs Wordpress integration module in a Magento store. When I set it to use a custom Wordpress menu, which I've set up in Wordpress with some category hierarchies, it doesn't add any active states if you've clicked a link and are on an "active" page. After digging about, /app/code/community/Fishpig/Wordpress/Model/Menu/Item.php has the following:
public function isItemActive()
{
return false;
}
So it seems like they've just skipped this bit? Anyone any idea how to set active states here?
OK, this seems to do the job, bit of a workaround but hey!
public function isItemActive()
{
$currurl = Mage::helper('core/url')->getCurrentUrl();
$linkurl = $this->getUrl();
if(strstr($linkurl, $currurl)){
return true;
}
else {
return false;
}
}
Get the current url, get the blog url, if they match set active state to true. I then used a bit of jQuery to set states of parents to active as the above only sets the current link:
$('#nav li.nav-3 ul li.level1.active').parent().parent().addClass("active");
...where li.nav-3 is the parent blog link
Replace the isItemActive function with following code in /app/code/community/Fishpig/Wordpress/Model/Menu/Item.php. This is working for me.
public function isItemActive() {
$myblogUrl = Mage::helper('wordpress/abstract')->getBlogRoute();
$mycurrentUrl = preg_replace('/\?.*/', '', Mage::helper('core/url')->getCurrentUrl());
if (in_array($myblogUrl, explode("/", $mycurrentUrl))) {
return true;
} else {
return false;
}
}
The problem is just a simple miss.. Magento uses a "/" in all urls,$currentUrl never matches $currentUrl because of this. The correction is just to trim the "/" I know a late response, but thought it may help someone.
public function isItemActive()
{
$currentUrl = Mage::getUrl('*/*/*', array('_current' => true, '_use_rewrite' => true));
if (strpos($currentUrl, '?') !== false) {
$currentUrl = substr($currentUrl, 0, strpos($currentUrl, '?'));
}
return $currentUrl === rtrim($this->getUrl(), '/');
}

Is it possible to load JavaScript based on theme?

I'm developing a site for a client that has 3 themes available. I'm using the app_themes system to enable the user to change the style. Each theme uses a few different JavaScript files to load custom fonts. What would be the best approach to load these JavaScript files based on the chosen themes?
As far as I can tell, Kentico uses the same app themes system as default ASP.net webforms.
Ideally I would like to be able to add the appropriate JavaScript files to the corresponding App_Theme folder and let ASP add the tags to the document head. If this isn't an option I've considered writing a ScriptLoader JavaScript that will inspect the style sheet tags to determine which theme is being used. It would be better if I could just add the theme name as a class attribute on the body element and just look at that and pull in appropriate scripts.
I think I found a solution that involves making a webPart or control if you aren't using Kentico.
public static void AddScriptToHead(HtmlHead h, string script, bool AddScriptTags)
{
Literal l = new Literal();
if (AddScriptTags)
l.Text = "<script type=\"text/javascript\" src=\""
+ script +
"\"></script>";
else
l.Text = script;
h.Controls.Add(l);
}
protected void SetupControl()
{
if (this.StopProcessing)
{
// Do nothing
}
else
{
string theme = Page.Theme;
if (theme != null)
{
if (theme.Equals("Card"))
{
AddScriptToHead(Page.Header, "~/App_Themes/Cardamon/js/cufon-colors-classic.js", true);
AddScriptToHead(Page.Header, "~/App_Themes/Cardamon/js/Charis_SIL_700.font.js", true);
}
else if (theme.Equals("CardamonWave"))
{
AddScriptToHead(Page.Header, "~/App_Themes/Cardamon/js/cufon-colors-wave.js" ,true);
AddScriptToHead(Page.Header, "~/App_Themes/Cardamon/js/Lobster_14_400.font.js",true);
}
else if (theme.Equals("CardamonAncient"))
{
AddScriptToHead(Page.Header, "~/App_Themes/Cardamon/js/cufon-colors-ancient.js", true);
AddScriptToHead(Page.Header, "~/App_Themes/Cardamon/js/Charis_SIL_700.font.js", true);
}
else
{
//Y U no theme?
}
}
}
}
I'd like to extend this to accept Scripts and themes as properties in the future but this will work for now.

Resources