HTMLPurifier converts £ back to £ - htmlpurifier

I'm having a problem with the HTMLPurifier, which seem to be converting the
£
back into
£
My current configuration is:
$config = \HTMLPurifier_Config::createDefault();
$config->set('HTML.Doctype', 'XHTML 1.0 Transitional');
$config->set('Core.Encoding', 'UTF-8');
$config->set('Attr.AllowedFrameTargets', array('_blank'));
$config->set('HTML.Trusted', true);
$config->set('CSS.Trusted', true);
$config->set('Attr.EnableID', true);
$def = $config->getHTMLDefinition(true);
$def->addAttribute('a', 'href*', 'URI');
$def->addAttribute('a', 'rel', 'CDATA');
$objPurifier = new HTMLPurifier($config);
$string = $objPurifier->purify($string);
First I was simply passing the £ symbol, which seem to be ignored and wasn't converted to £ so I've decided to run str_replace() before passing the $string to the purifier, but this was converting it back to £ symbol - so I'm really lost here and would appreciate some help if anyone knows what configuration setting might change that behaviour.
I'm now running the str_replace() after the purification, but there must be a better way.

This is by design; the canonicalization that occurs here helps HTML Purifier avoid certain types of XSS bugs. http://htmlpurifier.org/docs/enduser-utf8.html is a worthwhile read.

Related

one-hot encoding issue

I have the following code which i am trying to achieve one hot encoding.
k=tf.Variable(tf.zeros((10,1)))
hprev=tf.Variable(tf.zeros((10,1)))
x=tf.placeholder(tf.int32,shape=None,name="x")
y_op =tf.assign(k, k[x,0].assign(1))
M_c=tf.concat((hprev,y_op),axis=0)
init=tf.global_variables_initializer()
with tf.Session() as sess:
sess.run(init)
print(sess.run(y_op,feed_dict={x:1}))
print(M_c.eval())
I get the error:You must feed a value for placeholder tensor 'x_64' with dtype int32. Yet I have passed 1 as the value, which in my understanding is an integer. What I am doing wrong ?. I am still a beginner please.

How to make Text::slug() convert german umlauts properly?

I am using CakePHP 3.6, and when I am using words with german umlauts like:
Text::slug('Grundstücke')
I will get:
Grundstucke (where ü = u)
but that's not correct, I should get:
Grundstuecke (where ü = ue)
Is there an option to set so that umlauts are being converted the way I want them to?
Change your transliterator
The Text::slug() uses internally transliterator_transliterate (see php doc).
So you need to change the default transliterator that is being used.
After some research I found one that will work for you.
At the end of your bootstrap.php file add:
\Cake\Utility\Text::setTransliteratorId( 'de-ASCII; Any-Latin; Latin-ASCII; [\u0080-\u7fff] remove ');
Then your text will be converted as you expect.
Notes
Resources I've used to find this answer:
CakekPHP Text::transliterate()
Transliteration Identifiers Documentation
transliterator_list_ids - to get a list of valid identifiers - this is how I found the one that finally worked: de-ASCII
Text Utility API - to set the a new default transliterator id.

Overriding Ext.util.Format.thousandSeparator except when formatting money

I am trying to override Ext.util.Format.decimalSeparator and thousandSeparator. So, in my app, when I chnage the language to Spanish and I try using this function, Ext.util.Format.number(1234,'$0,000'), still it converts the number to 1.234 instead of 1,234.
I want that, irrespective of what language I choose, it should always format the money to $0,000 format and not using my selected locale, e.g., never $0.000. I observed if I change the thousandSeparator of Ext.util.Format object, it works fine. So, I added the following code in Ext.Loader.loadScript callback function in launch function in Application.js,
var utilFormatObj={};
utilFormatObj.thousandSeparator = ",";
utilFormatObj.decimalSeparator = ".";
Ext.override(Ext.util.Format, utilFormatObj);
BUt, it seems to work only in this place, once it loads the app on webpage, it again gets back to thousandSeparator=".". I can see that ext-lang-es.js file has the function which sets these properties. Can anyone suggest how can I catch whether the app is completely loaded on webapge and then use the above code there. Thank you.
When you call Ext.util.Format.number() you're not specifying what to use as decimal or thousand separator, you're only specifying precision, whether to show thousands separator, and whether to pad precision with zeroes.
The documentation for Ext.util.Format.number states:
The format string must specify separator characters according to US/UK conventions ("," as the thousand separator, and "." as the decimal separator)
Therefore if you want to display numbers in different locales, you have to run the code that changes the default separators before calling Ext.util.Format.number or Ext.util.Format.currency.
var value = 202020.20, format = "0,000.0000";
// Print in Spanish
Ext.util.Format.thousandSeparator = ".";
Ext.util.Format.decimalSeparator = ",";
alert(Ext.util.Format.number(value, format));
// Print in Swedish French
Ext.util.Format.thousandSeparator = "'";
Ext.util.Format.decimalSeparator = ",";
alert(Ext.util.Format.number(value, format));
// Print in English
Ext.util.Format.thousandSeparator = ",";
Ext.util.Format.decimalSeparator = ".";
alert(Ext.util.Format.number(value, format));
Here's a hack you can use if you really want to specify that currency should always use a period as the thousand separator but still have Ext.util.Format.number use the selected locale's separators.
function formatMoney(amount, sign, decimals, end) {
// Save the thousand separator
var thousandSep = Ext.util.Format.thousandSeparator;
Ext.util.Format.thousandSeparator = '.';
var formatted = Ext.util.Format.currency(amount, sign, decimals, end);
// restore the thousand separator
Ext.util.Format.thousandSeparator = thousandSep;
return formatted;
}
Example for the above code snippets: https://fiddle.sencha.com/#fiddle/9vm
I am guessing that you are not using the loader after you build your application for deployment. Typically the dynamic loader is only used for development (so you can see each script individually) and you use a faster method in prod.
You could load your Ext overrides on the callback for Ext.define:
Ext.define( className, data, [createdFn] )
where createdFn is a function that contains your Ext overrides. This approach may lend itself to race conditions if you invoke that Format object before the override is applied. To be confident, you could add another JS file with your overrides (after Ext is loaded, before your app code) and make sure that is included when you load your app.

Using PyMEL to set the "Alpha to Use" attribute in an object of class psdFileTex

I am using Maya to do some procedural work, and I have a lot of textures that I need to load into Maya, and they all have transparencies (alpha channels). I would very much like to be able to automate this process. Using PyMEL, I can create my textures and hook them up to a shader, but the alpha doesn't set properly by default. There is an attribute in the psdFileTex node called "Alpha to Use", and it must be set to "Transparency" in order for my alpha channel to work. My question is this - how do I use PyMEL scripting to set the "Alpha to Use" attribute properly?
Here is the code I am using to set up my textures:
import pymel.core as pm
pm.shadingNode('lambert', asShader=True, name='myShader1')
pm.sets(renderable=True, noSurfaceShader=True, empty=True, name='myShader1SG')
pm.connectAttr('myShader1.outColor', 'myShader1SG.surfaceShader', f=True)
pm.shadingNode('psdFileTex', asTexture=True, name='myShader1PSD')
pm.connectAttr('myShader1PSD.outColor', 'myShader1.color')
pm.connectAttr('myShader1PSD.outTransparency', 'myShader1.transparency')
pm.setAttr('myShader1ColorPSD.fileTextureName', '<pathway>/myShader1_texture.psd', type='string')
If anyone can help me, I would really appreciate it.
Thanks
With any node, you can use listAttr() to get the available editable attributes. Run listAttr('myShaderPSD'), note in it's output, there will be two attributes called 'alpha' and 'alphaList'. Alpha, will return you the current selected alpha channel. AlphaList will return you however many alpha channels you have in your psd.
Example
pm.PyNode('myShader1PSD').alphaList.get()
# Result: [u'Alpha 1', u'Alpha 2'] #
If you know you'll only ever be using just the one alpha, or the first alpha channel, you can simply do this.
psdShader = pm.PyNode('myShader1PSD')
alphaList = psdShader.alphaList.get()
if (len(alphaList) > 0):
psdShader.alpha.set(alphaList[0])
else:
// No alpha channel
pass
Remember that lists start iterating from 0, so our first alpha channel will be located at position 0.
Additionally and unrelated, while you're still using derivative commands of the maya.core converted for Pymel, there's still some commands you can use to help make your code read nicer.
pm.setAttr('myShader1ColorPSD.fileTextureName', '<pathway>/myShader1_texture.psd', type='string')
We can convert this to pymel like so:
pm.PyNode('myShader1ColorPSD').fileTextureName.set('<pathway>/myShader1_texture.psd')
And:
pm.connectAttr('myShader1PSD.outColor', 'myShader1.color')
Can be converted to:
pm.connect('myShader1PSD.outColor', 'myShader1.color')
While they may only be small changes, it reads just the little bit nicer, and it's native PyMel.
Anyway, I hope I have helped you!

CakePHP Inflector slug issue

When I use:
Inflector::slug("My Lovely & long slug");
On my local server I get:
My_Lovely_long_slug
When I use it on my server I get:
Lo_l_lo_lu
What gives? This issue is also affecting all my cache names which I assume are using the Inflector class. Any help appreciated.
looks like to different versions of cake? ive seen this reported before but dont have any references for you. Tested on my server for ~ 1.3.6/7 and it works as expected.
if the versions of cake are the same try and do a 'git bisect' which will give you an answer pretty quick
update:
seems to do with your PCRE libraries installed on the server that are older etc. give them an update and all should be fine
So I made my own slug for now.
function permalink ($string = '',$length = false)
{
$string = strtolower($string); // All lowercase
$string = preg_replace('/[^%a-z0-9]/',' ', $string); // Remove garbage
$string = preg_replace('/\s+/','_', $string);
$string = preg_replace('|-+|','_', $string);
if ($length) $string = substr($string,0,$length); // Limit string length?
$parsed = trim($string,'_'); // Trim pre and post trailing delims
return $parsed;
}

Resources