Blockgets with other extensions


User avatar
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 %}
User avatar
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

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);
               }
            }
         }
User avatar
Leinad4Mind
 
Posts: 213
Joined: Thu Oct 15, 2015 10:10 pm
 Sun Apr 03, 2022 5:01 pm • via Web
Found a little bug on portal when using a feature from BBPoints:

We've a button to send points to another user:
Image

This modal opens up and when we search for an user it appears the username list, button on the portal it appears behind:
Image

Should be like this:
Image
User avatar
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
User avatar
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
User avatar
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.
Previous

Who is online

Users browsing this forum: No registered users and 0 guests