Help modifying this module code
Moderators: tjay, seadap, Rogue4ngel, matthewhayashida
Forum rules
Help modifying this module code
Okey I want to get this module to display the author name and link back to their profile. Its a front page module used to display the X number latest mamblog posts. Iv been playing with it but Im only learning php at the moment and cant get it to work. As far as I can tell its only a matter of changing the query to look for the correct field then outputting it and concatenating it correctly.
[code:1]defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
global $database, $mosConfig_offset;
$count = $params->get( 'count', 5 );
$section = $params->get( 'section', 'Mamblog' );
$now = date( "Y-m-d H:i:«»s", time()+$mosConfig_offset*60*60 );
$query = "SELECT id FROM #__sections WHERE title='$section'";
$database->setQuery($query);
$section_id = $database->LoadResult();
$query = "SELECT id FROM #__menu WHERE link='index.php?option=com_mamblog'";
$database->setQuery($query);
$Itemid = $database->LoadResult();
$query = "SELECT id, title"
. "\n FROM #__content"
. "\n WHERE sectionid='$section_id'"
. "\n AND state=1"
. "\n AND ( publish_up = '0000-00-00 00:00:00' OR publish_up <= '$now' )"
. "\n AND ( publish_down = '0000-00-00 00:00:00' OR publish_down >= '$now' )"
. "\n ORDER BY created DESC"
. "\n LIMIT $count"
;
$database->setQuery($query);
$rows = $database->loadObjectList();
echo $database->getErrorMsg();
foreach($rows as $row) {
echo ''.$row->title.'
';
}
?>[/code:1]
[code:1]defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
global $database, $mosConfig_offset;
$count = $params->get( 'count', 5 );
$section = $params->get( 'section', 'Mamblog' );
$now = date( "Y-m-d H:i:«»s", time()+$mosConfig_offset*60*60 );
$query = "SELECT id FROM #__sections WHERE title='$section'";
$database->setQuery($query);
$section_id = $database->LoadResult();
$query = "SELECT id FROM #__menu WHERE link='index.php?option=com_mamblog'";
$database->setQuery($query);
$Itemid = $database->LoadResult();
$query = "SELECT id, title"
. "\n FROM #__content"
. "\n WHERE sectionid='$section_id'"
. "\n AND state=1"
. "\n AND ( publish_up = '0000-00-00 00:00:00' OR publish_up <= '$now' )"
. "\n AND ( publish_down = '0000-00-00 00:00:00' OR publish_down >= '$now' )"
. "\n ORDER BY created DESC"
. "\n LIMIT $count"
;
$database->setQuery($query);
$rows = $database->loadObjectList();
echo $database->getErrorMsg();
foreach($rows as $row) {
echo ''.$row->title.'
';
}
?>[/code:1]
Re: Help modifying this module code
Are you getting any specific error messages?
Also, you use '$database->LoadResult'. It should be '$database->loadResult' (note the lowercase L). That might be the initial cause of some problems. Besides that, an error message of some kind would do wonders.
Regards,
Nick
Also, you use '$database->LoadResult'. It should be '$database->loadResult' (note the lowercase L). That might be the initial cause of some problems. Besides that, an error message of some kind would do wonders.
Regards,
Nick
Re: Help modifying this module code
Hi mate thanks for answering. The code I posted is the original unmodified code from the original module. Its not meant to display the author name just the content item. So there is no errors with that. I never posted the changes I attempted to make as I really dont know what im doing Im still learning the very basics of PHP and programming in general. But I can see that it would'nt take much to make it do what I would like it to do and I was hoping somebody would Just add the few lines of code needed for me.
cheers
cheers
Re: Help modifying this module code
Modify the query like this:
Then you can use $row->username for links and $row->created_by can be used on profile links as user id. (Note that if you change u.username to u.name and $row->username to $row->name it just displays the real name of the author.
Btw, for the Community Builder profile link you can use this, I think.
Please don't forget that I didn't try these codes. So I can't take any responsibility.
Code: Select all
"SELECT c.id, c.title, u.username"
. "\n FROM #__content AS c"
. "\n LEFT JOIN #__users AS u ON u.id = c.created_by"
Then you can use $row->username for links and $row->created_by can be used on profile links as user id. (Note that if you change u.username to u.name and $row->username to $row->name it just displays the real name of the author.
Btw, for the Community Builder profile link you can use this, I think.
Code: Select all
sefRelToAbs( 'index.php?option=com_comprofiler&task=userprofile&user=' . $row->created_by )
Please don't forget that I didn't try these codes. So I can't take any responsibility.
My Joomla! 1.5 extensions - http://joomla.ercan.us
Progress is made by lazy men looking for easier ways to do things.
Progress is made by lazy men looking for easier ways to do things.
Re: Help modifying this module code
Thanks man!
I changed the code to this and it almost works. The only thing thats wrong is its not actually linking to the cb profiles, Im just getting the message back saying This profile does not exist or is no longer available. But the profiles do exist.
$query = "SELECT c.id, c.title, u.username"
. "\n FROM #__content AS c"
. "\n LEFT JOIN #__users AS u ON u.id = c.created_by"
. "\n WHERE sectionid='$section_id'"
. "\n AND state=1"
. "\n AND ( publish_up = '0000-00-00 00:00:00' OR publish_up <= '$now' )"
. "\n AND ( publish_down = '0000-00-00 00:00:00' OR publish_down >= '$now' )"
. "\n ORDER BY created DESC"
. "\n LIMIT $count"
;
$database->setQuery($query);
$rows = $database->loadObjectList();
echo $database->getErrorMsg();
foreach($rows as $row) {
echo ''.$row->title.'
'.''.$row->username.'';
}
I changed the code to this and it almost works. The only thing thats wrong is its not actually linking to the cb profiles, Im just getting the message back saying This profile does not exist or is no longer available. But the profiles do exist.
$query = "SELECT c.id, c.title, u.username"
. "\n FROM #__content AS c"
. "\n LEFT JOIN #__users AS u ON u.id = c.created_by"
. "\n WHERE sectionid='$section_id'"
. "\n AND state=1"
. "\n AND ( publish_up = '0000-00-00 00:00:00' OR publish_up <= '$now' )"
. "\n AND ( publish_down = '0000-00-00 00:00:00' OR publish_down >= '$now' )"
. "\n ORDER BY created DESC"
. "\n LIMIT $count"
;
$database->setQuery($query);
$rows = $database->loadObjectList();
echo $database->getErrorMsg();
foreach($rows as $row) {
echo ''.$row->title.'
'.''.$row->username.'';
}
Last edited by Radio on Thu Oct 11, 2007 1:00 am, edited 1 time in total.
Re: Help modifying this module code
Hi, can you please add the html code generated by this module?
My Joomla! 1.5 extensions - http://joomla.ercan.us
Progress is made by lazy men looking for easier ways to do things.
Progress is made by lazy men looking for easier ways to do things.
Re: Help modifying this module code
My bad.
Forgot some field in query:
$query = "SELECT c.id, c.title, u.username, c.created_by"
It should solve the problem.
Forgot some field in query:
$query = "SELECT c.id, c.title, u.username, c.created_by"
It should solve the problem.
My Joomla! 1.5 extensions - http://joomla.ercan.us
Progress is made by lazy men looking for easier ways to do things.
Progress is made by lazy men looking for easier ways to do things.
Re: Help modifying this module code
Thanx alot man works perfectly
Re: Help modifying this module code
Hey man sorry to bother you again but I just thought id ask . You would'nt happen know how to call up the cb avator and display it as a little thumbnail next to posts?
Re: Help modifying this module code
There was a module for cb latest members. That was showing the avatars, you can take a look at its code. I don't know the exact database field the avatar urls are stored. But I'll try playing with this module a little later.
My Joomla! 1.5 extensions - http://joomla.ercan.us
Progress is made by lazy men looking for easier ways to do things.
Progress is made by lazy men looking for easier ways to do things.
Re: Help modifying this module code
Yeah I did look at the code in that module before asking, I looked at a couple of different modules doing similar things, Most of them were missing an important function. They were simply calling up the avator they were not taking into account if the avator had been approved or not. So even if the main profile showed the pending approval picture the random users module still showed the avator which make the whole module pretty useless. I emailed the author about this. The cb login module does take this into account and as far as I can make out from the code its just a matter checking if the avatorapproved field contains a 1 or 0 then displaying either the avator or the pending image.
Im not sure how to incorporate all this into the mamblog latest module however
Im not sure how to incorporate all this into the mamblog latest module however
Re: Help modifying this module code
ok I know i need to incorporate this into the query : SELECT avatar, avatarapproved FROM #__comprofiler WHERE id =
But i cant get the sql syntax to work. Ill obviously need some kind of IF statement in their to determine if the avator is approved or not.
But i cant get the sql syntax to work. Ill obviously need some kind of IF statement in their to determine if the avator is approved or not.
Re: Help modifying this module code
Code: Select all
$query = 'SELECT c.id, c.title, c.created_by, u.username, cb.avatar, cb.avatarapproved'
. 'FROM #__content AS c'
. 'LEFT JOIN #__users AS u ON u.id = c.created_by'
. 'INNER JOIN #__comprofiler AS cb ON u.id = cb.user_id'
. 'WHERE sectionid=' (int) $section_id
. 'AND state = 1'
. 'AND ( publish_up = \'0000-00-00 00:00:00\' OR publish_up <= ' . $now . ') '
. 'AND ( publish_down = \'0000-00-00 00:00:00\' OR publish_down >= ' . $now . ') '
. 'ORDER BY created DESC'
. 'LIMIT' . (int) $count;
I changed the query a bit. And added that two field you said. As I said before, I didn't have chance to try these with php. I only tried the query with CLI. It seemed like working.
In the foreach statement you need to do something like this.
Code: Select all
<?php
if ($row->avatarapproved) {
do something with $row->avatar;
}
?>
My Joomla! 1.5 extensions - http://joomla.ercan.us
Progress is made by lazy men looking for easier ways to do things.
Progress is made by lazy men looking for easier ways to do things.
Re: Help modifying this module code
getting the following error
Parse error: parse error, unexpected T_INT_CAST in
mod_mamblog_latest.php on line 30
Parse error: parse error, unexpected T_INT_CAST in
mod_mamblog_latest.php on line 30
Re: Help modifying this module code
My Joomla! 1.5 extensions - http://joomla.ercan.us
Progress is made by lazy men looking for easier ways to do things.
Progress is made by lazy men looking for easier ways to do things.
Re: Help modifying this module code
now getting this error
Parse error: parse error, unexpected '[' in W:\www\joomlaplazza\modules\mod_mamblog_latest.php on line 30
Parse error: parse error, unexpected '[' in W:\www\joomlaplazza\modules\mod_mamblog_latest.php on line 30
Re: Help modifying this module code
LOL sorry I get it The dot has worked Now I just need to figure out the foreach part.
getting this but im guessing thats because the foreach part of the code is nots setup yet.
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near \'AS cLEFT JOIN jos_users AS u ON u.id = c.created_byINNER JOIN jo SQL=SELECT c.id, c.title, c.created_by, u.username, cb.avatar, cb.avatarapprovedFROM jos_content AS cLEFT JOIN jos_users AS u ON u.id = c.created_byINNER JOIN jos_comprofiler AS cb ON u.id = cb.user_idWHERE sectionid=5AND state = 1AND ( publish_up = \'0000-00-00 00:00:00\' OR publish_up <= 2007-10-16 23:19:17) AND ( publish_down = \'0000-00-00 00:00:00\' OR publish_down >= 2007-10-16 23:19:17) ORDER BY created DESCLIMIT5
Warning: Invalid argument supplied for foreach() in W:\www\joomlaplazza\modules\mod_mamblog_latest.php on line 41
getting this but im guessing thats because the foreach part of the code is nots setup yet.
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near \'AS cLEFT JOIN jos_users AS u ON u.id = c.created_byINNER JOIN jo SQL=SELECT c.id, c.title, c.created_by, u.username, cb.avatar, cb.avatarapprovedFROM jos_content AS cLEFT JOIN jos_users AS u ON u.id = c.created_byINNER JOIN jos_comprofiler AS cb ON u.id = cb.user_idWHERE sectionid=5AND state = 1AND ( publish_up = \'0000-00-00 00:00:00\' OR publish_up <= 2007-10-16 23:19:17) AND ( publish_down = \'0000-00-00 00:00:00\' OR publish_down >= 2007-10-16 23:19:17) ORDER BY created DESCLIMIT5
Warning: Invalid argument supplied for foreach() in W:\www\joomlaplazza\modules\mod_mamblog_latest.php on line 41
Last edited by Radio on Tue Oct 16, 2007 11:23 pm, edited 1 time in total.
Re: Help modifying this module code
Okey this is how I think I could implement the code but im still getting the above sql syntax error.
$query = "SELECT id FROM #__menu WHERE link='index.php?option=com_mamblog'";
$database->setQuery($query);
$Itemid = $database->LoadResult();
$query = 'SELECT c.id, c.title, c.created_by, u.username, cb.avatar, cb.avatarapproved'
. 'FROM #__content AS c'
. 'LEFT JOIN #__users AS u ON u.id = c.created_by'
. 'INNER JOIN #__comprofiler AS cb ON u.id = cb.user_id'
. 'WHERE sectionid=' . (int) $section_id
. 'AND state = 1'
. 'AND ( publish_up = \'0000-00-00 00:00:00\' OR publish_up <= ' . $now . ') '
. 'AND ( publish_down = \'0000-00-00 00:00:00\' OR publish_down >= ' . $now . ') '
. 'ORDER BY created DESC'
. 'LIMIT' . (int) $count;
$database->setQuery($query);
$rows = $database->loadObjectList();
echo $database->getErrorMsg();
foreach($rows as $row) {
$avatar = $row->avatar;
$avatarapproved = $row->avatarapproved;
if($avatarapproved==0) $img = "";
elseif(($avatar=='' || $avatar==null) && $avatarapproved==1) $img = "";
else $img = "";
echo $img. ''.$row->title.'
'.''.$row->username.'';
}
?>
$query = "SELECT id FROM #__menu WHERE link='index.php?option=com_mamblog'";
$database->setQuery($query);
$Itemid = $database->LoadResult();
$query = 'SELECT c.id, c.title, c.created_by, u.username, cb.avatar, cb.avatarapproved'
. 'FROM #__content AS c'
. 'LEFT JOIN #__users AS u ON u.id = c.created_by'
. 'INNER JOIN #__comprofiler AS cb ON u.id = cb.user_id'
. 'WHERE sectionid=' . (int) $section_id
. 'AND state = 1'
. 'AND ( publish_up = \'0000-00-00 00:00:00\' OR publish_up <= ' . $now . ') '
. 'AND ( publish_down = \'0000-00-00 00:00:00\' OR publish_down >= ' . $now . ') '
. 'ORDER BY created DESC'
. 'LIMIT' . (int) $count;
$database->setQuery($query);
$rows = $database->loadObjectList();
echo $database->getErrorMsg();
foreach($rows as $row) {
$avatar = $row->avatar;
$avatarapproved = $row->avatarapproved;
if($avatarapproved==0) $img = "";
elseif(($avatar=='' || $avatar==null) && $avatarapproved==1) $img = "";
else $img = "";
echo $img. ''.$row->title.'
'.''.$row->username.'';
}
?>
Re: Help modifying this module code
Maybe it's a silly idea, but before each line on the query insert a space after '.
My Joomla! 1.5 extensions - http://joomla.ercan.us
Progress is made by lazy men looking for easier ways to do things.
Progress is made by lazy men looking for easier ways to do things.
Re: Help modifying this module code
Tried it, all it changed was the error message to this :
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near \'22:35:43) AND ( publish_down = \'0000-00-00 00:00:00\' OR publish SQL=SELECT c.id, c.title, c.created_by, u.username, cb.avatar, cb.avatarapproved FROM jos_content AS c LEFT JOIN jos_users AS u ON u.id = c.created_by INNER JOIN jos_comprofiler AS cb ON u.id = cb.user_id WHERE sectionid=5 AND state = 1 AND ( publish_up = \'0000-00-00 00:00:00\' OR publish_up <= 2007-10-18 22:35:43) AND ( publish_down = \'0000-00-00 00:00:00\' OR publish_down >= 2007-10-18 22:35:43) ORDER BY created DESC LIMIT5
Warning: Invalid argument supplied for foreach() in W:\www\joomlaplazza\modules\mod_mamblog_latest.php on line 43
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near \'22:35:43) AND ( publish_down = \'0000-00-00 00:00:00\' OR publish SQL=SELECT c.id, c.title, c.created_by, u.username, cb.avatar, cb.avatarapproved FROM jos_content AS c LEFT JOIN jos_users AS u ON u.id = c.created_by INNER JOIN jos_comprofiler AS cb ON u.id = cb.user_id WHERE sectionid=5 AND state = 1 AND ( publish_up = \'0000-00-00 00:00:00\' OR publish_up <= 2007-10-18 22:35:43) AND ( publish_down = \'0000-00-00 00:00:00\' OR publish_down >= 2007-10-18 22:35:43) ORDER BY created DESC LIMIT5
Warning: Invalid argument supplied for foreach() in W:\www\joomlaplazza\modules\mod_mamblog_latest.php on line 43
Re: Help modifying this module code
Iv taken a bit of time and have managed to get it working but im having a little trouble with the HTML inside the echo command. How would I change it so that it will be displayed with the avator on the right and title to the left and username under the avator image.
$query = "SELECT c.id, c.title, c.created_by, u.username, cb.avatar, cb.avatarapproved
FROM jos_content as c
LEFT JOIN jos_users AS u ON u.id = c.created_by
INNER JOIN jos_comprofiler AS cb ON u.id = cb.user_id
WHERE sectionid='$section_id'
AND c.state = 1
AND ( publish_up = '0000-00-00 00:00:00' OR publish_up <= '$now' )
AND ( publish_down = '0000-00-00 00:00:00' OR publish_down >= '$now' )
ORDER BY created DESC
LIMIT $count";
$database->setQuery($query);
$rows = $database->loadObjectList();
echo $database->getErrorMsg();
foreach($rows as $row) {
$link_cb = sefRelToAbs( 'index.php?option=com_comprofiler&task=userprofile&user=' . $row->created_by );
if ( $row->avatar == null || $row->avatar=='') {
$img = "username." \" border=\"0\"/>";
}
elseif ( $row->avatarapproved==0) {
$img = "username." \" border=\"0\"/>";
}
else {
$img = "avatar."\" alt=\" ".$row->username." \" border=\"0\"/>";
}
echo ''.$img.' '.$row->title.'
'.''.$row->username.'';
}
?>
$query = "SELECT c.id, c.title, c.created_by, u.username, cb.avatar, cb.avatarapproved
FROM jos_content as c
LEFT JOIN jos_users AS u ON u.id = c.created_by
INNER JOIN jos_comprofiler AS cb ON u.id = cb.user_id
WHERE sectionid='$section_id'
AND c.state = 1
AND ( publish_up = '0000-00-00 00:00:00' OR publish_up <= '$now' )
AND ( publish_down = '0000-00-00 00:00:00' OR publish_down >= '$now' )
ORDER BY created DESC
LIMIT $count";
$database->setQuery($query);
$rows = $database->loadObjectList();
echo $database->getErrorMsg();
foreach($rows as $row) {
$link_cb = sefRelToAbs( 'index.php?option=com_comprofiler&task=userprofile&user=' . $row->created_by );
if ( $row->avatar == null || $row->avatar=='') {
$img = "username." \" border=\"0\"/>";
}
elseif ( $row->avatarapproved==0) {
$img = "username." \" border=\"0\"/>";
}
else {
$img = "avatar."\" alt=\" ".$row->username." \" border=\"0\"/>";
}
echo ''.$img.' '.$row->title.'
'.''.$row->username.'';
}
?>