How do I include outside scripts? Topic is solved

General project discussion. NOT for help questions.
Post Reply
sds

How do I include outside scripts?

Post by sds »

I run a news aggregator by hand and the add article section is way to slow to add 20-30 links a day.  So, I would rather keep using my current setup, but include the output on a CMSMS page.  How is this done?  How can I run my php scripts from inside CMSMS and to a lesser extent, just insert a flat file when necessary?
tsw
Power Poster
Power Poster
Posts: 1408
Joined: Tue Dec 13, 2005 10:50 pm

Re: How do I include outside scripts?

Post by tsw »

Create new user defined tag copy paste your script into it and remove , then you can call it on your page with {yourtagname}
sds

Re: How do I include outside scripts?

Post by sds »

thanks.  I kind of did that, but it broke some things.

http://www.sabresreport.com/cms/index.p ... t_newswire

the footer broke.

What I did was call the function in my tag.  Then, in the file content.functions.php, I inserted my "require file" line.  The file has the function listed in my tag.  This is less than ideal, since this file will always be called regardless of page being vieng viewed and it also broke the smarty footer.

I guess I can include the entire function, calls to a database, etc... all in one function w/o problems?
tsw
Power Poster
Power Poster
Posts: 1408
Joined: Tue Dec 13, 2005 10:50 pm

Re: How do I include outside scripts?

Post by tsw »

You shouldnt have to edit any files when creating user defined tags, have you read these wiki pages about udt's

http://wiki.cmsmadesimple.org/index.php ... fined_Tags

and

http://wiki.cmsmadesimple.org/index.php ... _tags_here
sds

Re: How do I include outside scripts?

Post by sds »

so, I'm trying to include my functions in (mytag} and it is getting hung up on the db query.  Here is the top snippet where it stops....

$name = "xxxx";
$server = "localhost";
$user = "xxxx";
$pass = "xxxx";

function MySQLConnect($errmsg, $msg="") {
$success = mysql_connect($GLOBALS["server"], $GLOBALS["user"],
$GLOBALS["pass"]);
if (!$success) {
mail($GLOBALS["Err_Mail"], "[Connect Failure] $errmsg", mysql_errno(). ":  ".mysql_error(), "From: AutoError");
die();
}
}

function MySQLQuery($query, $errmsg, $msg="") {
$success = mysql_db_query($GLOBALS["name"], $query);
if (!$success) {
mail($GLOBALS["Err_Mail"], "[Query failure] $errmsg", mysql_errno(). ":  ".mysql_error(), "From: AutoError");
echo $msg;
die();
}
return $success;
}

global $show, $view;

MySQLConnect ("An error occured!",  "Sorry, this service is temporarily unavailable.");

$result = MySQLQuery ("select count(*) from mytable",  "There was an error!", "Sorry, this service is temporarily unavailable..");


the last line returns the "Sorry, this service is temporarily unavailable.." error....  what could be wrong here?  the script works fine outside of CMSMS.
tsw
Power Poster
Power Poster
Posts: 1408
Joined: Tue Dec 13, 2005 10:50 pm

Re: How do I include outside scripts?

Post by tsw »

Is there some reason not to use cmsms db connection?

example follows

Code: Select all

//get db connection
global $gCms;
$db = &$gCms->db;

//some output
$output = "Your query has returned: ";

//mysql query
$q = "SELECT count(*) FROM ".cms_db_prefix()."content";

//execute it!
$dbresult = $db->Execute( $q );

//oh noes, something went wrong
if( !$dbresult )
{
    echo 'DB error: '. $db->ErrorMsg()."<br/>";
}

//lets go through the results
while ($dbresult && $result_row = $dbresult->FetchRow())
{
//add to output
   $output .= $result_row['count(*)'];
}

//lets say it out loud
echo $output;
sds

Re: How do I include outside scripts?

Post by sds »

I didn't know how... ;)

it looks like if I cut and paste this I should have working output.  What if I use a different dBase?  Any issues there?
sds

Re: How do I include outside scripts?

Post by sds »

So, that worked, but I need to connect to a different dBase and I don't have a clue how to change that setting.  Even the table being queried looks odd to me in your example.
sds

Re: How do I include outside scripts?

Post by sds »

Ok, I have the proper table and db selected, but I am having a hell of a time getting the rest of the queries and code to run.

Now I get:

Fatal error: Call to a member function on a non-object in /home/xxx/xxx.com/xxx/xxx/lib/content.functions.php(653) : eval()'d code on line 95

What does that mean?

Line 95 in my tag is:

while ($result && $result_row = $row->FetchRow()) {
User avatar
Elijah Lofgren
Power Poster
Power Poster
Posts: 811
Joined: Mon Apr 24, 2006 1:01 am

Re: How do I include outside scripts?

Post by Elijah Lofgren »

sds wrote: Ok, I have the proper table and db selected, but I am having a hell of a time getting the rest of the queries and code to run.

Now I get:

Fatal error: Call to a member function on a non-object in /home/xxx/xxx.com/xxx/xxx/lib/content.functions.php(653) : eval()'d code on line 95

What does that mean?

Line 95 in my tag is:

while ($result && $result_row = $row->FetchRow()) {
Maybe try this line instead:

Code: Select all

while ($dbresult && $result_row = $dbresult->FetchRow()) {
If that does not work, please paste the entire UDT (without passwords of course) and I will take a look at it.  ;)
Note: I don't have time to take on any more projects. I'm quite busy. I may be too busy to reply to emails or messages. Thanks for your understanding. :)
Post Reply

Return to “General Discussion”