I'm using WP-GeSHi in WordPress, and largely I'm very happy with it. There are, however, a few minor scenarios where the color highlighting is too aggressive when a keyword is:
a variable name (denoted by a leading #)
part of another word (e.g. IN in INSERTED)
the combination (part of a variable name, e.g. JOIN and IN in #JOINBING)
inside square brackets (e.g. [status])
Certain keywords are case sensitive, and others are not. The below screenshot sums up the various cases where this goes wrong:
Now, the code in GeSHi.php is pretty verbose, and I am by no means a PHP expert. I'm not afraid to get my hands a little dirty here, but I'm hoping someone else has made corrections to this code and can provide some pointers. I already implemented a workaround to prevent ##ROWCOUNT from being highlighted incorrectly, but this was easy, since ##ROWCOUNT is defined - I just shuffled the arrays around so that it was found before ROWCOUNT.
What I'd like is for GeSHi to completely ignore keywords that aren't whole words (whether they are prefixed by # or immediately surrounded by other letters/numbers). JOIN should be grey, but #JOIN and JOINS should not. I'd also like it to ignore keywords that are inside square brackets (after all, this is how we tell Management Studio to not color highlight it, and it's also how we tell the SQL engine to ignore reserved words, keywords, and invalid identifiers).
You can do this by adding a PARSER_CONTROL control to the end of the array:
'PARSER_CONTROL' => array(
'KEYWORDS' => array(
1 => array( // "1" maps to the main keywords near the start of the array
'DISALLOWED_BEFORE' => '(?![\(\w])',
'DISALLOWED_AFTER' => '(?![\(\w])'
),
5 => array( // "5" maps to the shorter keywords like "IN" that are further down
'DISALLOWED_BEFORE' => '(?![\(\w])',
'DISALLOWED_AFTER' => '(?![\(\w])'
),
)
)
Edit
I've modified your gist to move some of the keywords you added to SYMBOLS back to KEYWORDS (though in their own group and with your custom style), and I updated the PARSER_CONTROL array to match the new keyword array indexes and also to include the default regex that geshi generates. Here is the link:
https://gist.github.com/jamend/07e60bf0b9acdfdeee7a
According to me, what you are doing would take a lot of time. So, I suggest that you install a different plugin:
It has better features and supports more languages and in a better way. So, it would remove all these problems.
EDIT:
Hey, I tried out the same code with latest version and got following result-
EDIT:
So, if you don't want to use another plugin, then I'll tell you about the coding:
First open \wp-content\plugins\wp-geshi-highlight\geshi\geshi\tsql.php in your text editor.
Then, locate the array 'KEYWORDS' or search for it.
Add 6 to the last of it (after 5) and add your custom keywords in it. For example:
5 => array(
'ALL', 'AND', 'ANY', 'BETWEEN', 'CROSS', 'EXISTS', 'IN', 'JOIN', 'LIKE', 'NOT', 'NULL',
'OR', 'OUTER', 'SOME',
),
6 => array( //This line has been added by me
'status' //This line has been added by me
) //This line has been added by me
Note: I have just shown array element 5 (already present) and array element 6 (which I have made).
Then, to make it case-sensitive add below code to the last of 'CASE_SENSITIVE' array:
6 => true
The 'CASE_SENSITIVE' array should look like this:
'CASE_SENSITIVE' => array(
GESHI_COMMENTS => false,
1 => false,
2 => false,
3 => false,
4 => false,
5 => false,
6 => true //This line has been added by me
),
Now, you will have to add styling to the custom keywords. This can be achieved by adding below line to the 'KEYWORDS' element of 'STYLES' array. The starting of 'STYLES' array should look like this:
'STYLES' => array(
'KEYWORDS' => array(
1 => 'color: #0000FF;',
2 => 'color: #FF00FF;',
3 => 'color: #AF0000;',
4 => 'color: #AF0000;',
5 => 'color: #808080;',
6 => 'color: #0000FF;' //This line has been added by me
),
You can solve your problems by above guidelines, but for the part in which the plugin highlights incomplete words, I have found only one solution, that you update your plugin to latest version, because it solves this problem.
Related
My graph schema looks like this:
(Location)<-[:INVENTOR_LOCATED_IN]-(Inventor)-[:INVENTOR_OF]->(Patent)
I'm trying to return multiple values from each step in the query path. Here's the query I have so far that runs correctly:
g.V().and(has('Location', 'city', textContains('Bloomington')), has('Location','state',textContains('IN'))).as('a').
bothE().bothV().hasLabel('Inventor').as('b').
bothE().bothV().has('Patent', 'title', textContains('Lid')).as('c').
select('a,', 'b', 'c').
by('state').by('name_first').by('title').
fold();
What I would like to do is for each step return two node properties. I tried the following but it returns an error:
g.V().and(has('Location', 'city', textContains('Bloomington')), has('Location', 'state',textContains('IN'))).as('a').
bothE().bothV().hasLabel('Inventor').as('b').
bothE().bothV().has('Patent', 'title', textContains('Lid')).as('c').
select('a,', 'b', 'c').
by('city', 'state').by('name_first', 'name_last').by('title', 'abstract').
fold();
Can anyone suggest syntax that will allow me to return multiple properties from each node in the path?
The by(key) is meant to be a sort of shorthand for values(key) which means if you have more than one value you could do:
g.V().and(has('Location', 'city', textContains('Bloomington')), has('Location', 'state',textContains('IN'))).as('a').
bothE().bothV().hasLabel('Inventor').as('b').
bothE().bothV().has('Patent', 'title', textContains('Lid')).as('c').
select('a,', 'b', 'c').
by(values('city', 'state').fold()).
by(values('name_first', 'name_last').fold()).
by(values('title', 'abstract').fold()).
fold()
You might also consider forms of elementMap(), valueMap(), or project() as alternatives. Since by() takes a Traversal you have a lot of flexibility.
I have table with categories and instead of having name column for every language, I'm storing translations so it looks like this:
1 2 category.macbook_12.name img-12 category.macbook_12.title category.macbook_12.title macbook-12.jpg 0
2 category.macbook.name macbook category.macbook.title category.macbook.description macbook.jpg 0
3 2 category.macbook_air.name macbook-air category.macbook_air.title category.macbook_air.description macbook-air.jpg 0
4 3 category.macbook_air_11.name macbook-air-11 category.macbook_air_11.title category.macbook_air_11.description macbook-air-11.jpg 0
5 3 category.macbook_air_13.name macbook-air-13 category.macbook_air_13.title category.macbook_air_13.description macbook-air-13.jpg 0
6 2 category.macbook_pro.name macbook-pro category.macbook_pro.title category.macbook_pro.description macbook-pro.jpg 0
7 6 category.macbook_pro_13.name macbook-pro-13 category.macbook_pro_13.title category.macbook_pro_13.description macbook-pro-13.jpg 0
....
I'm trying to create form with entity field. Like this:
->add('categories', EntityType::class, [
'class' => Category::class,
'choice_label' => 'name',
'placeholder' => 'form.product.category.placeholder'
])
It's not translating name categories but without translating them.
I think, I should customise entity_widget and add |trans to it, but I can't find original one so I can edit it, because I'm not sure how to fetch data from entity.
Where can I find original entity_widget?
Or is there another way to force translating?
Thanks
If you want to translate choices in your form, you can set
choice_translation_domain => 'messages'.
Your translations MUST be in directory
the app/Resources/translations directory;
the app/Resources/<bundle_name>/translations directory;
the Resources/translations/ directory inside of any bundle.
via Docs
and stored in file messages.{NEEDED_LANGUAGE}.yml as #DOZ said.
NEEDED_LANGUAGE can be short (en, de, ru, pl) or long (en_US, en_AU, en_GB).
Also you can name your translations as you want, but with NEEDED_LANGUAGE notation. So your category.yml file must be named category.en.yml and must stored in translations directory.
For using translations from your custom file, u must set translation_domain and choice_translation_domain manually on each field or in twig file globaly.
# src/{BUNDLE_NAME}/Resources/translations/messages.en.yml (based on symfony version)
category:
macbook_12.name: "Macbook 12"
macbook_12.title: "Macbook 12` laptop"
macbook.name: "Macbook"
macbook.title: "Macbook laptop"
form.product.category.placeholder: "Awesome macbooks here!"
# ... and yet
I'm have a list with string types and i want to get each one that have maximum of occurence element grouped by another column. I'm trying to do this by linqu expression but it doesn't work. Is it possible to run my code that i show below ?
#test=(from a in #data
group a by new {a.PostCode}
into obj
select obj).ToDictionary(x => x.Key,x=>x.ToList()
.Select(y=>y.Statistic).GroupBy(s => s)
.OrderByDescending(s => s.Count())
.First().Key);
On pay-per-view content nodes (with Drupal MoneySuite module) when I click 'override settings' to input an amount/ type for then node it crashes with this error, though I have tried many versions for the price (eg 1, or 1.00) and dates (eg 2, or 2 days). I have tried using full html, filtered html and plain text in the settings for the field. One answer on Stackexhange hints that this is a ut8 issue but I don't know what that means about how to solve it? Any tips?
The error is:
PDOException: SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect integer value: 'full_html' for column 'protected_content_message_format' at row 1: INSERT INTO {ms_ppv_price} (vid, nid, price, expiration_string, allow_multiple, protected_content_message, protected_content_message_format, stock, out_of_stock_message) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6, :db_insert_placeholder_7, :db_insert_placeholder_8); Array ( [:db_insert_placeholder_0] => 96 [:db_insert_placeholder_1] => 96 [:db_insert_placeholder_2] => 3 [:db_insert_placeholder_3] => 3 days [:db_insert_placeholder_4] => 0 [:db_insert_placeholder_5] => This is a premium film- pay per view only. Get access [ms_ppv:price] to view for [ms_ppv:expirationLength] : [ms_ppv:addToCartLink] [ms_ppv:nodeTeaser] [:db_insert_placeholder_6] => full_html [:db_insert_placeholder_7] => 0 [:db_insert_placeholder_8] => ) in ms_ppv_insert_node_price() (line 774 of /home/cineafzh/public_html/sites/all/modules/moneysuite/ms_ppv/ms_ppv.module).
Looks like the MoneySuite module created the database table incorrectly.
Your error message explains exactly what's going wrong.
Column 'protected_content_message_format' is defined as a datetime column in your database. The value the module attempts to store in it is 'full_html', which is a string. It fails validation and throws an exception.
One workaround would be to edit your database and change the type of column for 'protected_content_message_format' to string, instead of datetime.
I can't guarantee that this won't introduce other undesirable behaviour without looking at the code, but it would definitely resolve this specific error.
I'm using formulas in phpexcel and I have a problem using the countif
Wrong number of arguments for COUNTIFS() function: 4 given, 2 expected
But in the documentation countif is:
COUNTIFS(criteria_range1, criteria1, [criteria_range2, criteria2]…)
I have for exemple:
COUNTIFS(C$17:D$46,$B55,C$16:D$45,$B55)
It works when I directly use it on excel, is there a way to catch the error and keep the formula ?
Change the definition of COUNTIFS in the /Classes/PHPExcel/Calculation.php file (around lines 499 to 502).
Currently it reads:
'COUNTIFS' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
'argumentCount' => '2'
),
add a comma after the argument count to make it
'COUNTIFS' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
'argumentCount' => '2,'
),
Note that the COUNTIFS() function isn't actually implemented, so you can't do a getCalculatedValue() on any cell using the function to get the correct result, but it will then save correctly using the Excel2007 Writer.
COUNTIFS in phpexcel is not yet implemented.