Modding the {URL} tag, WIP, need help!

Post custom hacks and enhancements for phpwcms here only. Maybe some of these things will be included in official release later.
Post Reply
vrain
Posts: 52
Joined: Mon 20. Sep 2004, 04:43

Modding the {URL} tag, WIP, need help!

Post by vrain » Sat 23. Apr 2005, 12:33

Hi, my host does not allow the include function to be used, so I am trying to make the {URL} tag functional through modding it to use the CURL function.

So, in the beginning, this is how to link to a site with CURL instead of using {URL:mysite.com} tag.

Code: Select all

[PHP]

$curl_handle=curl_init();
curl_setopt($curl_handle,CURLOPT_URL,'http://mysite.com');
curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,1);
curl_exec($curl_handle);
curl_close($curl_handle);

[/PHP]
Now lets look at phpwcms default code for handling {URL}

/include/inc_front/content.func.inc.php

Code: Select all

// -------------------------------------------------------------

// include external HTML page but only part between <body></body>
$content["all"] = preg_replace('/\{URL:(.*?)\}/ie', 'include_url("$1");', $content["all"]);

// -------------------------------------------------------------
Alright, now I need to mod this code into default {URL} tag handling in phpwcms!

NEW EDITED /include/inc_front/content.func.inc.php

Code: Select all

// -------------------------------------------------------------

// include external HTML page but only part between <body></body>
$curl_handle=curl_init();
curl_setopt($curl_handle,CURLOPT_URL,'("$1")');
curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,2);

$content["all"] = preg_replace('/\{URL:(.*?)\}/ie', 'curl_exec($curl_handle);', $content["all"]);

curl_close($curl_handle);

// -------------------------------------------------------------
Okay, so now I go into plain text content part and type {URL:mysite.com}.

RESULT : Blank!

:?

Any idea what I am doing wrong?

I suspect the problem might be this ( see blue text ).

// -------------------------------------------------------------

// include external HTML page but only part between <body></body>
$curl_handle=curl_init();
curl_setopt($curl_handle,CURLOPT_URL,'("$1")');
curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,2);

$content["all"] = preg_replace('/\{URL:(.*?)\}/ie', 'curl_exec($curl_handle);', $content["all"]);

curl_close($curl_handle);

// -------------------------------------------------------------

Somehow it does not replace the

Code: Select all

'include_url("$1");',
with

Code: Select all

'curl_exec($curl_handle);'
Is it the syntax?

your help would be greatly appreciated!

V

User avatar
marcus@localhorst
Posts: 815
Joined: Fri 28. May 2004, 11:31
Location: localhorst
Contact:

Post by marcus@localhorst » Mon 25. Apr 2005, 15:01

hello,

i don't know anything about the curl function and i don't test the function below, but try this:

you don't need to change the orginal function of {URL} just create a new ReplacementTag.

go to the fontend_render folder. create a php file and put this code inside.

Code: Select all

<?php 

function grab($the_site='')
{
$curl_handle=curl_init(); 
curl_setopt($curl_handle,CURLOPT_URL,$the_site); 
curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,2); 

$pagebody = curl_exec($curl_handle);

curl_close($curl_handle); 

return $pagebody;

}

if( ! ( strpos($content["all"],'{GRAB:')===false ) ) { 
$content["all"] = preg_replace('/\{GRAB:(.*?)\}/ie', 'grab("$1");', $content["all"]); 

}
 ?>
i try to describe:
the function grab() needs the parameter "which URL".

the last line find the RT {GRAB and take the content of the RegExpr. (.*?) into the function ($1 is the Backreference - it means it hold the URL)

greetings marcus

Post Reply