Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
Do the impossible?
If anyone can help with this problem I’d be both amazed and delighted.
I’ve been embedding videos in the excerpt of some of my articles.
Unfortunately I wasn’t thinking of future possibilities … the video website changed their player and the older videos on my site no longer work.
I have in the excerpt …
<div><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" width="448" height="396"><param name="height" value="396" /><param name="width" value="448" /><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://eplayer.clipsyndicate.com/cs_api/get_swf/2/&csEnv=p&wpid=0&va_id=1037776" /><embed type="application/x-shockwave-flash" height="396" width="448" allowfullscreen="true" allowscriptaccess="always" src="http://eplayer.clipsyndicate.com/cs_api/get_swf/2/&csEnv=p&wpid=0&va_id=1037776"></embed></object></div>
What I need is the video number extracting from this code .. (in this case it is 1037776) and saving as a custom field which I’ve imaginatively called var1
The excerpt can then be deleted. It takes me a minute to do this manually but I have 1000’s to do … anyone good at pattern matching?
Alternatively a work around would be to change http://eplayer.clipsyndicate.com/cs_api/get_swf/2/
to http://eplayer.clipsyndicate.com/cs_api/get_swf/3/
this would get the videos playing again. Anyone know MySQL well enough to alter the excerpt?
Thanks
Geoff
Last edited by geoff777 (2010-03-25 08:15:20)
There are 10 types of people in the world: those who understand binary, and those who don’t.
Offline
Re: Do the impossible?
geoff777 wrote:
If anyone can help with this problem I’d be both amazed and delighted.
Try this for size in an article (Textile processing off!) or in a page/form. Backup first :-)
<txp:php>
$rs = safe_rows('ID, excerpt', 'textpattern', "1=1");
foreach ($rs as $row) {
if (!empty($row['excerpt'])) {
preg_match('/va_id=(\d+)\"/', $row['excerpt'], $matches);
if($matches) {
safe_update('textpattern', "custom_2='".$matches[1]."'", 'ID='.$row['ID']);
echo 'Done: '.$row['ID'].n;
}
}
}
</txp:php>
Change custom_2 to the custom_N field ID of the one that corresponds with your var1.
(EDIT: if you want to test what it’s going to do first, you can comment out the safe_update
for now and add dmp($row['ID'].' : '.$matches[1]);
after it to see the video id it has extracted for each article ID)
Once you’ve let it rip and sampled a few articles to check that it’s done everything correctly, just run this to clear out your excerpts:
<txp:php>
safe_update('textpattern', "Excerpt='', Excerpt_html=''", "1=1");
</txp:php>
But that’ll delete ALL your excerpts so be careful! If you want to only affect articles in a certain section, change the "1=1"
in both bits of code to "Section='your_section_name'"
.
Hope that helps.
Last edited by Bloke (2010-03-24 20:18:27)
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline
Re: Do the impossible?
Brilliant Stef I stand here both amazed and delighted at the same time, a strange but wonderous feeling :-),
I ran the test it works like a charm.
Before I run the PHP to update the table.
Could I do this to delete the correct excerpts at the same time?
<txp:php>
$rs = safe_rows('ID, excerpt', 'textpattern', "1=1");
foreach ($rs as $row) {
if (!empty($row['excerpt'])) {
preg_match('/va_id=(\d+)\"/', $row['excerpt'], $matches);
if($matches) {
safe_update('textpattern', "custom_2='".$matches[1]."'", 'ID='.$row['ID']);
safe_update('textpattern', "Excerpt='', Excerpt_html=''", 'ID='.$row['ID']);
echo 'Done: '.$row['ID'].n;
}
}
}
</txp:php>
Last edited by geoff777 (2010-03-25 08:14:25)
There are 10 types of people in the world: those who understand binary, and those who don’t.
Offline
Re: Do the impossible?
geoff777 wrote:
Could I do this to delete the correct excerpts at the same time?
Yep. I shied away from that course of action just in case my code blew up. Ever the cautious :-)
Last edited by Bloke (2010-03-25 08:34:31)
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline
Re: Do the impossible?
Thanks Stef worked perfectly :-)
There are 10 types of people in the world: those who understand binary, and those who don’t.
Offline
Re: Do the impossible?
I love the thread title – just had to read it – and trust Stef to pull off the trick!
TXP Builders – finely-crafted code, design and txp
Offline
Pages: 1