- Estás aquí:
- Inicio › Foro › Application Support › cBB Blockgets
Blockgets with other extensions
36 mensajes
• Página 4 de 4 • 1, 2, 3, 4
- IvanPF
- Administrador
- Mensajes: 2010
- Registrado: Vie Jun 17, 2011 12:15 am
- Ubicación: España (Spain)
Vie Mar 25, 2022 10:34 pm • a través de Web
Leinad4Mind escribió: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:
- Código: Seleccionar todo
$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:
- Código: Seleccionar todo
// 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:
- Código: Seleccionar todo
{% for prefix in image.prefix %}{{ prefix.NAME }}{% endfor %}
- Leinad4Mind
- Mensajes: 213
- Registrado: Jue Oct 15, 2015 10:10 pm
Sab Mar 26, 2022 4:23 am • a través de 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
- Código: Seleccionar todo
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
- Mensajes: 213
- Registrado: Jue Oct 15, 2015 10:10 pm
- IvanPF
- Administrador
- Mensajes: 2010
- Registrado: Vie Jun 17, 2011 12:15 am
- Ubicación: España (Spain)
Lun May 16, 2022 8:25 pm • a través de Web
Please, send me the BBPoints extension to test
- IvanPF
- Administrador
- Mensajes: 2010
- Registrado: Vie Jun 17, 2011 12:15 am
- Ubicación: España (Spain)
Mar May 17, 2022 1:12 pm • a través de Web
I am not able to reproduce the problem with bbpoints. In my test forums it looks good
- Leinad4Mind
- Mensajes: 213
- Registrado: Jue Oct 15, 2015 10:10 pm
Mar May 17, 2022 9:46 pm • a través de 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 mensajes
• Página 4 de 4 • 1, 2, 3, 4
¿Quién está conectado?
Usuarios navegando por este Foro: No hay usuarios registrados visitando el Foro y 0 invitados
- Contenido
- Descargas
- En desarrollo
- Comunidad y Soporte
- Rss
- Enlaces de Interés
- phpBB Oficial
- phpBB Oficial (Español)
- Raul Arroyo Monzo
- PasionReef
- Sobre CaniDev
- Condiciones de uso
- Política de Privacidad
- Sobre nosotros
- Contacto
- © 2011-2024 CaniDev