View Full Version : creating plugin issue
Honourable
06-22-2013, 06:29 PM
Hi,
I would like
to run this plugin
$this->registry->db->query_read_slave(("SET CHARACTER SET utf8");
$stream = $this->registry->db->query_read_slave(("
SELECT stream.*, users.* FROM " . TABLE_PREFIX . "dmods_stream AS stream
INNER JOIN " . TABLE_PREFIX . "user AS users USING (userid)
WHERE stream.touserid = 0 || stream.touserid = " . $this->registry->userinfo['userid'] . "
ORDER BY stream.dateline DESC
");
$streamHTML = "";
while($item = $this->registry->db->fetch_array($stream)) {
if ($item['type'] == 'status') {
// Unserialize params
$streamdata = unserialize($item['parameters']);
$templater = vB_Template::create('lywomen_allstatuses');
$templater->register('stream', $streamdata);
$templater->register('streaminfo', $item);
$streamHTML .= $templater->render();
}
}
vB_Template::preRegister('ad_global_below_navbar', array('streamHTML' => $streamHTML));
in this template ad_global_below_navbar
using this
<ul id="webticker">
{vb:raw streamHTML}
</ul>
and in this template lywomen_allstatuses which contains the bits
<li><span class="usersign"><a href="member.php?u={vb:raw streaminfo.userid}">{vb:raw streaminfo.username}</a></span> {vb:raw stream.status}</li>
I'm having a problem with the plugin as internal error for whole website once I make it activated I tried to hook the plugin in parse_templates as well as process_templates_complete also loads of hooks but non of them works
some hook places such as procces_templates_complete it does get rid of internal error yet is not doing what it suppose such as displaying data out in ad_global_below_navbar template
any suggestions as I'm makin connection to the database retrieve elements contained within a table then construct out in template
I will be more than happy if I can see any help or hint at least
Many thanks in advance :D
Try changing all occurences of $this->registry->db-> to $vbulletin->db-> , and use hook parse_templates.
Honourable
06-22-2013, 07:07 PM
Hi,
I changed variables names maybe conflict with something else
but it still not working
$streamxha = $this->registry->db->query_read_slave(("
SELECT stream.*, users.* FROM " . TABLE_PREFIX . "dmods_stream AS stream
INNER JOIN " . TABLE_PREFIX . "user AS users USING (userid)
WHERE stream.touserid = 0 || stream.touserid = " . $this->registry->userinfo['userid'] . "
ORDER BY stream.dateline DESC
");
$streamhtmlxha = "";
while($itemxha = $this->registry->db->fetch_array($streamxha)) {
// Unserialize params
$streamdataxha = unserialize($itemxha['parameters']);
$templater = vB_Template::create('lywomen_allstatuses');
$templater->register('streamxha', $streamdataxha);
$templater->register('streaminfoxha', $itemxha);
$streamhtmlxha .= $templater->render();
}
vB_Template::preRegister('ad_global_below_navbar', array('streamhtmlxha' => $streamhtmlxha));
looking forward to your help
--------------- Added 1371931663 at 1371931663 ---------------
seconds I will try ur suggestion please dont leave
i will update u in seconds
--------------- Added 1371931850 at 1371931850 ---------------
I changed any occurance of $this->registry->db-> to $vbulletin->db->
adn the hook place to parse_templates
is not working unfurunately
please what do you think?
--------------- Added 1371931939 at 1371931939 ---------------
Also this making a huge conflict as when I browse any registered user with us it tells me
this user is not register once I disable the plugin I can browse users profile with no problem
what do you think?
note the internal error is gone now yet is not display the content that should be retrieved from db
Can you post again the exact code you're using?
Honourable
06-22-2013, 07:19 PM
Here u go
$vbulletin->db->query_read_slave(("SET CHARACTER SET utf8");
$stream = $vbulletin->db->query_read_slave(("
SELECT stream.*, users.* FROM " . TABLE_PREFIX . "dmods_stream AS stream
INNER JOIN " . TABLE_PREFIX . "user AS users USING (userid)
WHERE stream.touserid = 0 || stream.touserid = " . $this->registry->userinfo['userid'] . "
ORDER BY stream.dateline DESC
");
$streamHTML = "";
while($item = $vbulletin->db->fetch_array($stream)) {
if ($item['type'] == 'status') {
// Unserialize params
$streamdata = unserialize($item['parameters']);
$templater = vB_Template::create('lywomen_allstatuses');
$templater->register('stream', $streamdata);
$templater->register('streaminfo', $item);
$streamHTML .= $templater->render();
}
}
vB_Template::preRegister('ad_global_below_navbar', array('streamHTML' => $streamHTML));
Try this:
$vbulletin->db->query_read_slave("SET CHARACTER SET utf8");
$stream = $vbulletin->db->query_read_slave("
SELECT stream.*, users.* FROM " . TABLE_PREFIX . "dmods_stream AS stream
INNER JOIN " . TABLE_PREFIX . "user AS users USING (userid)
WHERE stream.touserid = 0 || stream.touserid = " . $vbulletin->userinfo['userid'] . "
ORDER BY stream.dateline DESC
");
$streamHTML = "";
while($item = $vbulletin->db->fetch_array($stream)) {
if ($item['type'] == 'status') {
// Unserialize params
$streamdata = unserialize($item['parameters']);
$templater = vB_Template::create('lywomen_allstatuses');
$templater->register('stream', $streamdata);
$templater->register('streaminfo', $item);
$streamHTML .= $templater->render();
}
}
vB_Template::preRegister('ad_global_below_navbar', array('streamHTML' => $streamHTML));
Honourable
06-22-2013, 07:23 PM
still not working???
--------------- Added 1371932856 at 1371932856 ---------------
just to let you know when I delete this bit
$vbulletin->db->query_read_slave(("SET CHARACTER SET utf8");
$stream = $vbulletin->db->query_read_slave(("
SELECT stream.*, users.* FROM " . TABLE_PREFIX . "dmods_stream AS stream
INNER JOIN " . TABLE_PREFIX . "user AS users USING (userid)
WHERE stream.touserid = 0 || stream.touserid = " . $vbulletin->userinfo['userid'] . "
ORDER BY stream.dateline DESC
");
I can browse users profile but still not working the sql query seems to me is the issue
as it makes problem in the whole forum if it existed??
Try the above code again (I just fixed a couple things instead of posting it all again).
Honourable
06-22-2013, 07:29 PM
ur last edit works great
please explain to me what was the problem I really want to learn
many thanks in advance
Well, first I should have told you to replace $this->registry with $vbulletin, because there was one that didn't have a ->db on it. $this is used when inside an object method. I guess you copied the code from a class definition, so those had to be changed.
Also, these two lines had extra '(' characters (in red):
$vbulletin->db->query_read_slave(("SET CHARACTER SET utf8");
$stream = $vbulletin->db->query_read_slave(("
Honourable
06-22-2013, 07:34 PM
the extra one which has db I figured but it didnt work yet
well the extre ( it was behind this so funny
yes that is right I copied the code from object
Big thanks u really saved me
Big respect
--------------- Added 1371989416 at 1371989416 ---------------
u said $this used in object
then how come I used this plugin and it works?
global $show;
if (is_array($options))
{
$options = array_merge($this->option_defaults, $options);
}
else
{
$options = $this->option_defaults;
}
require_once(DIR . '/includes/functions_album.php');
$state = array('public');
if (can_view_private_albums($this->profile->userinfo['userid']))
{
$state[] = 'private';
}
if (can_view_profile_albums($this->profile->userinfo['userid']))
{
$state[] = 'profile';
}
if (!$this->profile->prepared['myprofile'])
{
if (!can_moderate(0, 'canmoderatepictures'))
{
$sql = "AND album.visible > 0";
}
else
{
$sql = "AND (album.visible > 0 OR album.moderation > 0)";
}
}
else
{
$sql = "";
}
$albums = $this->registry->db->query_read_slave("
SELECT album.*,
a.attachmentid, album.moderation,
fd.thumbnail_dateline, fd.thumbnail_width, fd.thumbnail_height, IF(fd.thumbnail_filesize > 0, 1, 0) AS hasthumbnail
FROM " . TABLE_PREFIX . "album AS album
LEFT JOIN " . TABLE_PREFIX . "attachment AS a ON (album.coverattachmentid = a.attachmentid)
LEFT JOIN " . TABLE_PREFIX . "filedata AS fd ON (fd.filedataid = a.filedataid)
WHERE
album.userid = ". $this->profile->userinfo['userid'] . "
AND
album.state IN ('" . implode("', '", $state) . "')
$sql
ORDER BY album.lastpicturedate DESC
");
$albumbits2 = '';
while ($album = $this->registry->db->fetch_array($albums))
{
$album['picturedate'] = vbdate($this->registry->options['dateformat'], $album['lastpicturedate'], true);
$album['picturetime'] = vbdate($this->registry->options['timeformat'], $album['lastpicturedate']);
$album['title_html'] = fetch_word_wrapped_string(fetch_censored_text($alb um['title']));
$album['coverdimensions'] = ($album['thumbnail_width'] ? "width=\"$album[thumbnail_width]\" height=\"$album[thumbnail_height]\"" : '');
if ($album['moderation'])
{
$album['moderatedcount'] = vb_number_format($album['moderation']);
$show['moderated'] = true;
}
else
{
$show['moderated'] = false;
}
$templater = vB_Template::create('memberinfo_block_photosbit');
$templater->register('album', $album);
$albumbits2 .= $templater->render();
}
$this->block_data['albumbits2'] = $albumbits2;
vB_Template::preRegister('memberinfo_block_photos' , array('userinfo' => $userinfo));
vB_Template::preRegister('memberinfo_block_photos' , array('albumbits2' => $albumbits2));
and I'm using $this????
--------------- Added 1372002280 at 1372002280 ---------------
??????????????????????
Scanu
06-23-2013, 07:14 PM
It depends on where the plugin is running, if the hook is called on a object method than you have to use $this on that plugin (if don't understand you might search for php oop and understand how does work the vb hook system)
vBulletin® v3.8.12 by vBS, Copyright ©2000-2024, vBulletin Solutions Inc.