- You are here:
- Main › Forum › Application Support › cBB Blockgets
Blockgets with other extensions
36 posts
• Page 4 of 4 • 1, 2, 3, 4
- IvanPF
- Administrator
- Posts: 2010
- Joined: Fri Jun 17, 2011 12:15 am
- Location: España (Spain)
Fri Mar 25, 2022 10:34 pm • via Web
Leinad4Mind wrote:I was trying to get extra information from bbprefix on the gallery block. Can't figure out how to write the sql part
I haven't tested this 100% but I think it should work. Let's start from what you had done without the prefixes:
- Code: Select all
$sql = 'SELECT DISTINCT p.post_id, p.forum_id, p.topic_id, p.post_text, p.post_subject
FROM ' . POSTS_TABLE . ' p
WHERE (' . implode(' OR ', $sql_where) . ")
AND p.bbcode_uid <> ''
AND p.post_text " . $this->db->sql_like_expression($this->db->get_any_char() . '[album]' . $this->db->get_any_char()) . '
ORDER BY p.post_time DESC';
$result = $this->db->sql_query_limit($sql, $data['max_number']);
while($row = $this->db->sql_fetchrow($result))
{
preg_match_all('#<ALBUM content="(.*?)">#i', $row['post_text'], $matches, PREG_SET_ORDER);
foreach($matches as $match)
{
$images[] = array(
'ACTION' => '/forum/viewtopic.php?f='.$row['forum_id'].'&t='. $row['topic_id'],
'SRC' => '/forum/gallery/image/'.$match[1].'/source',
'TITLE' => $row['post_subject'],
);
}
}
$this->db->sql_freeresult($result);
Since there is the possibility of more than one prefix in each topic, you cannot do everything with the same query, you have to do it in two, one to get the posts and another for the prefixes.
The following code should work for you to replace yours:
- Code: Select all
// Declare two new variables
$post_ary = $prefix_ary = array();
// First, obtain the posts
$sql = 'SELECT DISTINCT p.post_id, p.forum_id, p.topic_id, p.post_text, p.post_subject
FROM ' . POSTS_TABLE . ' p
WHERE (' . implode(' OR ', $sql_where) . ")
AND p.bbcode_uid <> ''
AND p.post_text " . $this->db->sql_like_expression($this->db->get_any_char() . '[album]' . $this->db->get_any_char()) . '
ORDER BY p.post_time DESC';
$result = $this->db->sql_query_limit($sql, $data['max_number']);
while($row = $this->db->sql_fetchrow($result))
{
$post_ary[] = $row;
// Prepare array for prefixes
if(!isset($prefix_ary[$row['topic_id']]))
{
$prefix_ary[$row['topic_id']] = array();
}
}
$this->db->sql_freeresult($result);
// Obtain prefixes
$sql = 'SELECT i.*, p.*
FROM ' . BBPREFIX_INSTANCES_TABLE . ' i
LEFT JOIN ' . BBPREFIX_TABLE . ' p ON(p.id = i.prefix)
WHERE ' . $this->db->sql_in_set('topic', array_keys($prefix_ary)) . '
ORDER BY i.ordered';
$result = $this->db->sql_query($sql);
while($row = $this->db->sql_fetchrow($result))
{
$prefix_ary[$row['topic']][] = $row;
}
$this->db->sql_freeresult($result);
// Parse data
foreach($post_ary as $row)
{
$row_prefixes = array();
preg_match_all('#<ALBUM content="(.*?)">#i', $row['post_text'], $matches, PREG_SET_ORDER);
if(!empty($prefix_ary[$row['topic_id']]))
{
foreach($prefix_ary[$row['topic_id']] as $prefix)
{
$row_prefixes[] = array(
'NAME' => $prefix['name']
);
}
}
foreach($matches as $match)
{
$row_images[] = array(
'ACTION' => '/forum/viewtopic.php?f=' . $row['forum_id'] . '&t=' . $row['topic_id'],
'SRC' => '/forum/gallery/image/' . $match[1] . '/source',
'TITLE' => $row['post_subject'],
'PREFIX_STR' => implode('-', array_map(
function($prefix) {
return $prefix['NAME'];
},
$row_prefixes
)),
'prefix' => $row_prefixes,
);
}
}
In the style, you can use {{ image.PREFIX_STR }} to obtain all prefixes as string, joined by "-" or use as array:
- Code: Select all
{% for prefix in image.prefix %}{{ prefix.NAME }}{% endfor %}
- Leinad4Mind
- Posts: 213
- Joined: Thu Oct 15, 2015 10:10 pm
Sat Mar 26, 2022 4:23 am • via Web
Thank you
Here is the final code in case someone wants too. I've edited the gallery_block.php
Here is the final code in case someone wants too. I've edited the gallery_block.php
- Code: Select all
if(sizeof($sql_where))
{
// Declare two new variables
$post_ary = $prefix_ary = array();
$sql_ary = array(
'SELECT' => 'p.post_id, p.forum_id, p.topic_id, p.post_text, p.post_subject',
'FROM' => array(POSTS_TABLE => 'p'),
'WHERE' => '(' . implode(' OR ', $sql_where) . ")
AND p.bbcode_uid <> ''
AND p.post_text " . $this->db->sql_like_expression($this->db->get_any_char() . '[album]' . $this->db->get_any_char()),
'ORDER_BY' => ($data['image_order'] == 'last') ? 'p.post_time DESC' : 'RAND()',
);
/*
* @event block.gallery_posts_query
* @var array sql_ary The SQL data
* @var array data Block Configuration
* @since 2.0.3
*/
$vars = array('sql_ary', 'data');
extract($this->dispatcher->trigger_event('block.gallery_posts_query', compact($vars)));
$sql = $this->db->sql_build_query('SELECT', $sql_ary);
$result = $this->db->sql_query_limit($sql, $data['max_number']);
while($row = $this->db->sql_fetchrow($result))
{
$post_ary[] = $row;
// Prepare array for prefixes
if(!isset($prefix_ary[$row['topic_id']]))
{
$prefix_ary[$row['topic_id']] = array();
}
}
$this->db->sql_freeresult($result);
// Obtain prefixes
$sql = 'SELECT i.*, p.*
FROM ' . BBPREFIX_INSTANCES_TABLE . ' i
LEFT JOIN ' . BBPREFIX_TABLE . ' p ON(p.id = i.prefix)
WHERE ' . $this->db->sql_in_set('topic', array_keys($prefix_ary)) . '
ORDER BY i.ordered';
$result = $this->db->sql_query($sql);
while($row = $this->db->sql_fetchrow($result))
{
$prefix_ary[$row['topic']][] = $row;
}
$this->db->sql_freeresult($result);
// Parse data
foreach($post_ary as $row)
{
$row_prefixes = array();
preg_match_all('#<ALBUM content="(.*?)">#i', $row['post_text'], $matches, PREG_SET_ORDER);
if(!empty($prefix_ary[$row['topic_id']]))
{
foreach($prefix_ary[$row['topic_id']] as $prefix)
{
$row_prefixes[] = array(
'NAME' => $prefix['name']
);
}
}
foreach($matches as $match)
{
$row_images[] = array(
'ACTION' => '/forum/viewtopic.php?f=' . $row['forum_id'] . '&t=' . $row['topic_id'],
'SRC' => '/forum/gallery/image/' . $match[1] . '/source',
'TITLE' => $row['post_subject'],
'PREFIX_STR' => implode('-', array_map(
function($prefix) {
return $prefix['NAME'];
},
$row_prefixes
)),
'prefix' => $row_prefixes,
);
/*
* @event block.gallery_posts_row
* @var array $row_images The rows array
* @var array $data Block Configuration
* @var array $row Row data
* @since 2.0.3
*/
$vars = array('row_images', 'data', 'row');
extract($this->dispatcher->trigger_event('block.gallery_posts_row', compact($vars)));
$images = array_merge($row_images);
}
}
}
- Leinad4Mind
- Posts: 213
- Joined: Thu Oct 15, 2015 10:10 pm
- IvanPF
- Administrator
- Posts: 2010
- Joined: Fri Jun 17, 2011 12:15 am
- Location: España (Spain)
Mon May 16, 2022 8:25 pm • via Web
Please, send me the BBPoints extension to test
- IvanPF
- Administrator
- Posts: 2010
- Joined: Fri Jun 17, 2011 12:15 am
- Location: España (Spain)
Tue May 17, 2022 1:12 pm • via Web
I am not able to reproduce the problem with bbpoints. In my test forums it looks good
- Leinad4Mind
- Posts: 213
- Joined: Thu Oct 15, 2015 10:10 pm
Tue May 17, 2022 9:46 pm • via Web
I took a better look today and found out the culprit. Its BBTags that overwrites the zindex of a BBPoints class. Sorry, and thanks for taking a look.
36 posts
• Page 4 of 4 • 1, 2, 3, 4
Who is online
Users browsing this forum: No registered users and 0 guests
- External Links
- phpBB Official
- phpBB Official (Spanish)
- Raul Arroyo Monzo
- PasionReef
- About CaniDev
- Terms of use
- Privacy Policy
- About Us
- Contact
- © 2011-2024 CaniDev