Jump to content

Recommended Posts

Hi,

 

I run a Joomla website, and I am trying to custom code a piece of code that performs the following function:

 

When a comment is posted with JomComment on either a SOBI2 item, content item or blog, it inserts a line into SQL with the relevant LINK, TITLE, URL and TIME, which is then displayed as you can imagine.

 

The link and title have to be taken from the specific components table in the database... I need more of a syntax and usage check of the PHP/SQL I use here, the method and insertion and etc is fine, the only problem is that is doesnt fetch the appropriate TITLE.

 

The output looks like so:

# Reviews : Chris Edington just wrote  a blog titled 0

 

The 0 should be the title, fetched from the specific components table, fetched by ID which it gets out of the $bigstring (which is a full url, http://etc) with the substr code.

 

Please if anyone can spot any errors or let me know how I could reapply this code properly, would be much appreciated, my first code i actually written myself so would love to succeed on this project!

 

Thanks alot,

Chris

 

Thanks alot,

 

<?
if ($data->option == "com_content") {			
    $strSQL1 = "SELECT `title` FROM #__content WHERE `id`='{$data->contentid}'";
    $this->cms->db->query($strSQL1);
    $shoutName = $this->cms->db->get_value(); 

global $database;
$link = $_SERVER['HTTP_REFERER'];
$cool = $newid;
$shout='[iurl='.sefRelToAbs('index.php?option=com_comprofiler&task=userProfile&user='.$this->cms->user->id.'&Itemid=140').']'.$this->cms->user->name.'[/iurl] just wrote '.$cool.' a blog titled [iurl='.$link.']'.stripslashes($shoutName).'[/iurl]';
$database->setQuery("INSERT INTO #__liveshoutbox (time,name,text,url) VALUES ('".time()."','Reviews','".mysql_real_escape_string($shout)."','".$link."')");
$res = $database->query();	

}	ELSEIF ($data->option == "com_res2") {	 

$bigstring = $_SERVER['HTTP_REFERER'];
$newid = substr($bigstring,75,2);

    $strSQL1 = "SELECT `title` FROM #___res2_item WHERE `id`='$newid'";	

    $this->cms->db->query($strSQL1);
    $shoutName = $this->cms->db->get_value();	

global $database;
$link = $_SERVER['HTTP_REFERER'];
$cool = $newid;
$shout='[iurl='.sefRelToAbs('index.php?option=com_comprofiler&task=userProfile&user='.$this->cms->user->id.'&Itemid=140').']'.$this->cms->user->name.'[/iurl] just wrote '.$cool.' a blog titled [iurl='.$link.']'.stripslashes($shoutName).'[/iurl]';
$database->setQuery("INSERT INTO #__liveshoutbox (time,name,text,url) VALUES ('".time()."','Reviews','".mysql_real_escape_string($shout)."','".$link."')");
$res = $database->query();

}	ELSEIF ($data->option == "com_night2") {	

$bigstring = $_SERVER['HTTP_REFERER'];
$newid = substr($bigstring,75,2);

    $strSQL1 = "SELECT `title` FROM #___night2_item WHERE `id`='$newid'";		

    $this->cms->db->query($strSQL1);
    $shoutName    = $this->cms->db->get_value();

global $database;
$link = $_SERVER['HTTP_REFERER'];
$cool = $newid;
$shout='[iurl='.sefRelToAbs('index.php?option=com_comprofiler&task=userProfile&user='.$this->cms->user->id.'&Itemid=140').']'.$this->cms->user->name.'[/iurl] just wrote '.$cool.' a blog titled [iurl='.$link.']'.stripslashes($shoutName).'[/iurl]';
$database->setQuery("INSERT INTO #__liveshoutbox (time,name,text,url) VALUES ('".time()."','Reviews','".mysql_real_escape_string($shout)."','".$link."')");
$res = $database->query();	

}	ELSEIF ($data->option == "com_myblog") {	

    $strSQL1 = "SELECT `title` FROM #___content WHERE `id`='{$data->contentid}'";
    $this->cms->db->query($strSQL1);
    $shoutName = $this->cms->db->get_value();



} ELSE {
$newid = "999";
$shout='[iurl='.sefRelToAbs('index.php?option=com_comprofiler&task=userProfile&user='.$this->cms->user->id.'&Itemid=140').']'.$this->cms->user->name.'[/iurl] just wrote '.$newid.' a blog titled [iurl='.$link.']'.stripslashes($shoutName).'[/iurl]';
$database->setQuery("INSERT INTO #__liveshoutbox (time,name,text,url) VALUES ('".time()."','Reviews','".mysql_real_escape_string($shout)."','".$link."')");
$res = $database->query();	

}
?>

Link to comment
https://forums.phpfreaks.com/topic/108832-joomla-piece-of-code/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.