Add CSS to whitelist - border-radius, opacity, text-shadow - htmlpurifier

Starting off, I have very little understanding of the PHP or how HTMLPurifier itself works and am completely learning on the go. I've got a fair understanding of HTML and CSS from teaching myself, but I wouldn't call myself anything more than a novice at this point.
I run a myBB forum via hostgator wherein my users want HTML allowed to make fancy tables for their posts. Since we only opened shop a month ago and have a very small userbase so far of people I know and trust, I enabled HTML. About a week ago I used a plugin plus the current library to install HTMLPurifier into my forum. It works great. Thing is, it eats up a majority of the code my users are using to make their posts look good.
I tried to plug this code which I found here into my CSSDefinition.php file between the border-color and border-width codes to try to fix the border-radius issue.
// border-radius
$border_radius =
$this->info['border-top-left-radius'] =
$this->info['border-top-right-radius'] =
$this->info['border-bottom-left-radius'] =
$this->info['border-bottom-right-radius'] = new HTMLPurifier_AttrDef_CSS_Composite(array
(
new HTMLPurifier_AttrDef_CSS_Length('0'),
new HTMLPurifier_AttrDef_CSS_Percentage(true)
)
);
$this->info['border-radius'] = new HTMLPurifier_AttrDef_CSS_Multiple($border_radius);
That did absolutely nothing, I assume because his is out of date. I haven't been able to find any information on adding text-shadow to my whitelist, nor how to allow opacity, either through opacity:#; or rbga(#,#,#,0.5), though I did find a hack for the latter that I couldn't make heads or tails of for what to actually do with the file.
I don't know how to run my Config.php file because looking at the code I can see there is information there, but trying to visit the page through various means gets me nowhere.

Related

In CakePHP, can someone explain how __d() works, particularly in relation to how it is used in default.ctp?

Sorry this will be a super newbie question.
In the default.ctp layout file, towards the beginning there are two lines.
$cakeDescription = __d('cake_dev', 'CakePHP: the rapid development php framework');
$cakeVersion = __d('cake_dev', 'CakePHP %s', Configure::version())
I've found the function for __d here which says it "Allows you to override the current domain for a single message lookup." I don't really understand what it means at all.
Additionally, I was able to do the same thing without throwing any errors by simply replacing the lines with
$cakeDescription = 'CakePHP: the rapid development php framework';
$cakeVersion = 'CakePHP ' . Configure::version();
Its used for making your application multilingual.
You can use the command Console/cake i18n extract to extract all the text strings(which is the second parameter in __d()) into a pot file, which you can then translate.
See this for more information about __d() https://book.cakephp.org/2.0/en/core-libraries/internationalization-and-localization.html#internationalizing-cakephp-plugins
And see this for more information about extracting the strings into pot files
https://book.cakephp.org/2.0/en/console-and-shells/i18n-shell.html

Composite C1: how to make the page editor to display the source code by default

When you start editing a page, the editor is initially in the Visual mode, so every time you have to switch it to the Source mode if you prefer html-level editing as usually programmers do.
It is annoying when you have a lot of things to do during the day, especially when there is a bunch of languages every page is translated to.
I haven't found any option in the CMS and no solution in Google.
Actually I found myself the way to change this, so I post this question in order to instantly answer it. Maybe this will help somebody.
Edit file VisualEditorPageBinding.js, which is located in /Composite/content/misc/editors/visualeditor/bindings.
There is function VisualEditorPageBinding.prototype.initializeComponent.
Simply add this line at the very end of the function:
this.switchEditingMode();

How to add a custom field into template.php using Zen sub theme

First time poster here, I'm a designer not skilled at all with php and I have a small issue I don't seem to be able to solve. I'm making a site in drupal 7 using a sub theme on zen.
Btw this is a great CMS, even though people say it's really more a developers CMS. I have no trouble to do what I need using views, rules, display suite etc. So a big thank you for all the developers out there making this such a good CMS. But for this apparently simple problem... no module will help me (I think) and I'm kinda stuck.
So here it is: I'd like to add a subtitle next to the title in all my pages.
So what I did was to add a custom field into the content type basic page (machine name: field_sub_title) which is a simple text field.
I uncommented the following line in my template.php
function mytheme_preprocess_page(&$variables, $hook) {
$variables['sub_title'] = t('field_sub_title');
}
Now my question is how do I load the content of my custom field into that variable?
I know i need to change the second part, but I don't have a clue as into what I need to change this.
Displaying the variable into the the page.tpl.php is something I know about so I only need help with the first part.
{EDIT}
Ok I found how to do this :)
I was looking for a solution in the wrong place. I don't need to change any thing in the template.php file.
Just needed to add this bit of code into my page.tpl.php:
<?php
print $node->field_sub_title['und'][0]['value'];
?>
So I'm posting this here for other Drupal newbies struggling with this....
Your solution may work for now, but there may be a more Drupal-y way to handle a problem like this. If you haven't noticed any problems yet, you may find one or more of the following issues down the road:
Someone who doesn't know php or Drupal theming may need to change the way this works.
If you're like me, you may forget where exactly in code this was implemented.
You may see superfluous markup and/or errors on nodes (content) that do not have this sub-title field (ie. event content not having a sub-title field while basic pages and news articles do).
When you add a field to a content type, it will automatically appear anytime content in that content type is displayed. You should be able to add the sub-title field for your page, event or whatever else you need and have it automatically appear in the markup.
You can 'manage display' of a content type to drag and drop the order for fields to appear. You could take it a step further by using a module like Display Suite to add formatting or layout per-content type.
If you feel like this isn't good enough and the markup for the subtitle must be at the same level as the page title (which is rare), at least add an if statement to make your code check to see if the variable is present before trying to print it. I'd also add a new variable and comments for code readability.
<?php
$subtitle = $node->field_sub_title['und'][0]['value'];
if($subtitle){
print $subtitle;
}
?>
Consider using field_get_items or field_view_value, or at least use the LANGUAGE_NONE constant instead of 'und'
See https://api.drupal.org/api/drupal/modules%21field%21field.module/function/field_get_items/7 and https://api.drupal.org/api/drupal/modules!field!field.module/function/field_view_value/7
This has the added benefit of reducing the number of potential security holes you create.

Difficulty with filename and filemime when using Migrate module

I am using the Drupal 7 Migrate module to create a series of nodes from JPG and EPS files. I can get them to import just fine. But I notice that when I am done importing them if I look at the nodes it creates, none of the attached filefield and thumbnail files contain filename information.
Upon inspecting the file_managed table I see that both the filename and filemime fields are empty for ONLY the files that I attached via the migrate module. This also creates an issue with downloading the files.
Now I think the problem has to do with the fact that I am using "file_link" instead of "file_copy" as the file operation I specify. The problem is I am importing around 2TB (thats Terabytes) of image files. We had to put in a special request with Rackspace just to get access to that much disk space on our server. So I can't go around copying from one directory to the next because of space issues. So "file_link" seems like the obvious choice.
Now you probably want to see how I am doing this exactly, so here is the code snippet:
$jpg_arguments = MigrateFileFieldHandler::arguments(NULL,
'file_link', FILE_EXISTS_RENAME, 'en', array('source_field' => 'jpg_name'),
array('source_field' => 'jpg_filename'), array('source_field' => 'jpg_filename'));
$this->addFieldMapping('field_image', 'jpg_uri')
->arguments($jpg_arguments);
As you can see I am specifying no base path (just like the beer.inc example file does). I have set file_link, the language, and the source fields for the description, title, and alt.
It is able to generate thumbnails from the JPGs. But still missing those columns of data in the db table. I traced through the functions the best I could but I don't see what is causing this. I tried running the uri in the table through the functions that generate the filename and the filemime and they output just fine. It is like something is removing just those segments of data.
Does anyone have any idea what this could be? I am using the Drupal 7 Migrate module version 2.2. It is running on Drupal 7.8.
Thanks,
Patrick
Ok, so I have found the answer to yet another question of mine. This is actually an issue with the migrate module itself. The issue is documented here. I will be repealing this bounty (as soon as I figure out how).

Reverse Routing Slug-Based URL in CakePHP

(I know there's a couple of other reverse-routing-slugs questions on this site, but I'm not having much luck relating the answers to my particular issue, so I'll ask my more specific question...)
I am building a site whose URLs now need to be slug-based, i.e. what was initially news/item/1 now has to have the URL news/firstnewsitem. And so on for a number of other controllers. I can easily get these addresses to work, and maybe even not stomp on my existing utility actions, with something like:
Router::connect('/:controller/:slug',
array('action'=>'item'),
array('pass'=>array('slug'), 'slug'=>'[^(index|add|edit|view|delete)]')
);
However, the reverse routing of these new links seems to be a non-starter: Cake is still generating such links as news/item/3. It seems optimistic to hope that a slug-based URL would automagically happen, but is there any array that I can pass in my Html->link parameters that will create the :controller/:slug format I'm looking for? Or do I have to cut my losses and back away from reverse routing at this point?
There's a pretty decent plugin for handling slug-based routing here:
https://github.com/jeremyharris/slugger
If you used this, you would be able to create links something like this
$html->link("some item", array(
'controller'=>'items',
'action'=>'view',
'Item'=>$item['id']
));
and that would output a link to /items/view/slug-for-your-item

Resources