Utolsó hozzászólások megjelenítés probléma

Szerző
Üzenet
-pity-
Kezdő phpBB-s
Kezdő phpBB-s


Csatlakozott: 2014.02.09. Vasárnap 7:22
Hozzászólások: 27
Hozzászólás Elküldve: 2014.12.09. 22:07    Hozzászólás témája: Utolsó hozzászólások megjelenítés probléma
Hozzászólás az előzmény idézésével
Igazából nem találtam releváns témát (tényleg kerestem) ezért is nyitottam újat.

A fórumomon egy sidebar-ba íratom ki az utolsó öt hozzászólást. Ez tökéletesen működik, azonban az Emotikonok helyett a sidebar-ban default image kép jelenik meg, ami elég rondán néz ki. 2 napja azzal játszom, hogy ezt valahogy eltüntessem vagy kicseréljem szövegre. Sajnos nem sikerül.

Ez az url gnerálódik le, s a hozzászólás megjelenítő program nem tud vele mit kezdeni, ezért default image képet tesz ki:

oldalam.hu/forum/%7BSMILIES_PATH%7D/icon_e_smile.gif

Van ötletetek? Minden segítségért végtelenül hálás lennék. Itt a php, ami megjeleníti az utolsó 5 hozzászólást:

Kód:

<?php

// recent-widget.php
// Displays recent posts from a phpBB forum
// More info: http://www.lkozma.net/blog/phpbb-recent-posts-widget
//
$db_host = 'localhost';  // TODO: put here your database host name
$db_user = 'user';  // TODO: put here your database user name
$db_pwd = 'pwd';   // TODO: put here your database password
$database = 'database';  // TODO: change here if your forum database name is something else than phpbb_forum

if (!mysql_connect($db_host, $db_user, $db_pwd))
    die("DB connection error");

if (!mysql_select_db($database))
    die("DB selection error");

// sending query
mysql_query("SET NAMES 'utf8'");

// The following queries the most recent comments from the database
// It fetches the post time, post text, topic title and username
// The query is limited to approved posts and the 5 most recent posts are returned.
// Feel free to play around with the query and fetch different fields. Some information about the phpBB database structure is here:
// http://www.phpbbdoctor.com/doc_tables.php . Be aware that these things could change between versions. I tested it with phpBB 3.0
//
// [EDIT OCT 2011] Note that there are two versions of the query, the first will return the 5 most recent posts, the second will return the 5 most recent posts _from separate topics_,
//   i.e. it will not show posts from the same topic. This was suggested in the comments of the blog post.
// Uncomment only one of the two queries, depending on which you prefer.

$result = mysql_query("select phpbb_posts.post_time as post_time, phpbb_posts.post_text as post_text, phpbb_posts.topic_id as tid, phpbb_posts.forum_id as fid, phpbb_posts.post_id as pid, phpbb_topics.topic_title as topic_title, phpbb_users.username as username, phpbb_posts.post_username as anon from phpbb_posts, phpbb_topics, phpbb_users where post_approved=1 and phpbb_posts.topic_id=phpbb_topics.topic_id and phpbb_posts.poster_id=phpbb_users.user_id order by post_time desc limit 5;");

//$result = mysql_query("select phpbb_posts.post_time as post_time, phpbb_posts.post_text as post_text, phpbb_posts.topic_id as tid, phpbb_posts.forum_id as fid, phpbb_topics.topic_title as topic_title, phpbb_users.username as username, phpbb_posts.post_username as anon from phpbb_posts, phpbb_topics, phpbb_users where post_id IN (select * from (select max(post_id) as mpt from phpbb_posts group by topic_id order by mpt desc limit 5) alias ) AND post_approved=1 and phpbb_posts.topic_id=phpbb_topics.topic_id and phpbb_posts.poster_id=phpbb_users.user_id order by post_time desc;");


if (!$result) {
    die("DB query error");
}


echo "<table border='0' style='background-color:#ffffff'>";
$i = 0;
while($row = mysql_fetch_assoc($result))
{
    $i = $i+1; // This is to have different color for odd/even rows
    echo "<tr><td style='background-color:".(($i%2==1)?"faf0dc":"#faf0dc")."'><small>";
    // Time of post
    $ptime = strftime('%Y. %b. %d., %H:%S', $row['post_time']);
    // Username
    $puser = ($row['username']=="Anonymous")?$row['anon']:$row['username'];
    // Post text
    // Removing BBCode
    $ppost = preg_replace('/\[[^\]]*\]/', '', $row['post_text']);
    // Summarizing post
    $ppost = summary($ppost);
    // Removing some leftover formatting
   $ppost = str_replace("<!--", "", $ppost);
        $ppost = str_replace("-->", "", $ppost);
   
    // TODO: Replace nebulo.ro in the following line to the URL of your forum
    echo "<font color=gray>".$ptime."</font><br><b>".$puser."</b><br>".$ppost."<br><a href='http://oldalam.hu/forum/viewtopic.php?f=".$row['fid']."&t=".$row['tid']."&p=".$row['pid']."&#p".$row['pid']."'><b>".$row['topic_title']."</b></a>"."<br>";
   echo "</small></td></tr>";
}
mysql_free_result($result);

// This function summarizes posts to max. 200 characters
function summary($str, $limit = 90, $strip = false) {
    $str = ($strip == true)?strip_tags($str):$str;
    if (strlen ($str) > $limit) {
        $str = substr ($str, 0, $limit - 3);
        return trim(substr ($str, 0, strrpos ($str, ' ')).'...');
    }
    return trim($str);
}

// TODO: put your own forum link in the last line
?>
</table>

Felhasználó profiljának megtekintése Privát üzenet küldése
-pity-
Kezdő phpBB-s
Kezdő phpBB-s


Csatlakozott: 2014.02.09. Vasárnap 7:22
Hozzászólások: 27
Hozzászólás Elküldve: 2014.12.11. 12:03    Hozzászólás témája:
Hozzászólás az előzmény idézésével
Gondoltam, hogy nem egyszerű a kérdésem :(

Felhasználó profiljának megtekintése Privát üzenet küldése
Marcee
Adminisztrátor
Adminisztrátor
Avatar

Csatlakozott: 2006.01.17. Kedd 1:00
Hozzászólások: 2921
Hozzászólás Elküldve: 2014.12.13. 21:02    Hozzászólás témája:
Hozzászólás az előzmény idézésével
Szerintem egyszerűbb megoldás lenne, ha a hozzászólások formázását a phpBB funkcióira hagynád. A phpBB.com leírása alapján ez kb. így nézne ki:

Kód:

<?php
// Hány hozzászólás jelenjen meg
$search_limit = 5;
// Hozzászólásonként hány karaktert jelenítsen meg
$char_limit = 50;

// https://blog.phpbb.com/2009/11/09/how-to-display-posts-and-topics-on-external-pages/
/*
* home.php
* Description: example file for displaying latest posts and topics
* by battye (for phpBB.com MOD Team)
* September 29, 2009
*/

define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'includes/bbcode.' . $phpEx);
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup('viewforum');

/* create_where_clauses( int[] gen_id, String type )
* This function outputs an SQL WHERE statement for use when grabbing
* posts and topics */

function create_where_clauses($gen_id, $type)
{
   global $db, $auth;

    $size_gen_id = sizeof($gen_id);

        switch($type)
        {
            case 'forum':
                $type = 'forum_id';
                break;
            case 'topic':
                $type = 'topic_id';
                break;
            default:
                trigger_error('No type defined');
        }

    // Set $out_where to nothing, this will be used of the gen_id
    // size is empty, in other words "grab from anywhere" with
    // no restrictions
    $out_where = '';

    if( $size_gen_id > 0 )
    {
      // Get a list of all forums the user has permissions to read
      $auth_f_read = array_keys($auth->acl_getf('f_read', true));

      if( $type == 'topic_id' )
      {
         $sql     = 'SELECT topic_id FROM ' . TOPICS_TABLE . '
                  WHERE ' .  $db->sql_in_set('topic_id', $gen_id) . '
                  AND ' .  $db->sql_in_set('forum_id', $auth_f_read);

         $result     = $db->sql_query($sql);

         while( $row = $db->sql_fetchrow($result) )
         {
               // Create an array with all acceptable topic ids
               $topic_id_list[] = $row['topic_id'];
         }

         unset($gen_id);

         $gen_id = $topic_id_list;
         $size_gen_id = sizeof($gen_id);
      }

      $j = 0;

        for( $i = 0; $i < $size_gen_id; $i++ )
        {
         $id_check = (int) $gen_id[$i];

            // If the type is topic, all checks have been made and the query can start to be built
            if( $type == 'topic_id' )
            {
                $out_where .= ($j == 0) ? 'WHERE ' . $type . ' = ' . $id_check . ' ' : 'OR ' . $type . ' = ' . $id_check . ' ';
            }

            // If the type is forum, do the check to make sure the user has read permissions
            else if( $type == 'forum_id' && $auth->acl_get('f_read', $id_check) )
            {
                $out_where .= ($j == 0) ? 'WHERE ' . $type . ' = ' . $id_check . ' ' : 'OR ' . $type . ' = ' . $id_check . ' ';
            }

         $j++;
        }
    }

    if( $out_where == '' && $size_gen_id > 0 )
    {
        trigger_error('A list of topics/forums has not been created');
    }

    return $out_where;
}

// http://book.cakephp.org/2.0/en/core-libraries/helpers/text.html#TextHelper::truncate
// Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
// http://opensource.org/licenses/mit-license.php
function truncate($text, $length = 100, $options = array()) {
   $defaults = array(
      'ellipsis' => '...', 'exact' => true, 'html' => true
   );
   if (isset($options['ending'])) {
      $defaults['ellipsis'] = $options['ending'];
   } elseif (!empty($options['html'])) {
      $defaults['ellipsis'] = "\xe2\x80\xa6";
   }
   $options += $defaults;
   extract($options);
   if (!function_exists('mb_strlen')) {
      class_exists('Multibyte');
   }
   if ($html) {
      if (mb_strlen(preg_replace('/<.*?>/', '', $text)) <= $length) {
         return $text;
      }
      $totalLength = mb_strlen(strip_tags($ellipsis));
      $openTags = array();
      $truncate = '';
      preg_match_all('/(<\/?([\w+]+)[^>]*>)?([^<>]*)/', $text, $tags, PREG_SET_ORDER);
      foreach ($tags as $tag) {
         if (!preg_match('/img|br|input|hr|area|base|basefont|col|frame|isindex|link|meta|param/s', $tag[2])) {
            if (preg_match('/<[\w]+[^>]*>/s', $tag[0])) {
               array_unshift($openTags, $tag[2]);
            } elseif (preg_match('/<\/([\w]+)[^>]*>/s', $tag[0], $closeTag)) {
               $pos = array_search($closeTag[1], $openTags);
               if ($pos !== false) {
                  array_splice($openTags, $pos, 1);
               }
            }
         }
         $truncate .= $tag[1];
         $contentLength = mb_strlen(preg_replace('/&[0-9a-z]{2,8};|&#[0-9]{1,7};|&#x[0-9a-f]{1,6};/i', ' ', $tag[3]));
         if ($contentLength + $totalLength > $length) {
            $left = $length - $totalLength;
            $entitiesLength = 0;
            if (preg_match_all('/&[0-9a-z]{2,8};|&#[0-9]{1,7};|&#x[0-9a-f]{1,6};/i', $tag[3], $entities, PREG_OFFSET_CAPTURE)) {
               foreach ($entities[0] as $entity) {
                  if ($entity[1] + 1 - $entitiesLength <= $left) {
                     $left--;
                     $entitiesLength += mb_strlen($entity[0]);
                  } else {
                     break;
                  }
               }
            }
            $truncate .= mb_substr($tag[3], 0, $left + $entitiesLength);
            break;
         } else {
            $truncate .= $tag[3];
            $totalLength += $contentLength;
         }
         if ($totalLength >= $length) {
            break;
         }
      }
   } else {
      if (mb_strlen($text) <= $length) {
         return $text;
      }
      $truncate = mb_substr($text, 0, $length - mb_strlen($ellipsis));
   }
   if (!$exact) {
      $spacepos = mb_strrpos($truncate, ' ');
      if ($html) {
         $truncateCheck = mb_substr($truncate, 0, $spacepos);
         $lastOpenTag = mb_strrpos($truncateCheck, '<');
         $lastCloseTag = mb_strrpos($truncateCheck, '>');
         if ($lastOpenTag > $lastCloseTag) {
            preg_match_all('/<[\w]+[^>]*>/s', $truncate, $lastTagMatches);
            $lastTag = array_pop($lastTagMatches[0]);
            $spacepos = mb_strrpos($truncate, $lastTag) + mb_strlen($lastTag);
         }
         $bits = mb_substr($truncate, $spacepos);
         preg_match_all('/<\/([a-z]+)>/', $bits, $droppedTags, PREG_SET_ORDER);
         if (!empty($droppedTags)) {
            if (!empty($openTags)) {
               foreach ($droppedTags as $closingTag) {
                  if (!in_array($closingTag[1], $openTags)) {
                     array_unshift($openTags, $closingTag[1]);
                  }
               }
            } else {
               foreach ($droppedTags as $closingTag) {
                  $openTags[] = $closingTag[1];
               }
            }
         }
      }
      $truncate = mb_substr($truncate, 0, $spacepos);
   }
   $truncate .= $ellipsis;
   if ($html) {
      foreach ($openTags as $tag) {
         $truncate .= '</' . $tag . '>';
      }
   }
   return $truncate;
}

$posts_ary = array(
   'SELECT'    => 'p.*, t.*, u.username, u.user_colour',

   'FROM'      => array(
      POSTS_TABLE     => 'p',
   ),

   'LEFT_JOIN' => array(
      array(
         'FROM'  => array(USERS_TABLE => 'u'),
         'ON'    => 'u.user_id = p.poster_id'
      ),
      array(
         'FROM'  => array(TOPICS_TABLE => 't'),
         'ON'    => 'p.topic_id = t.topic_id'
      ),
   ),

   'WHERE'     => $db->sql_in_set('t.forum_id', array_keys($auth->acl_getf('f_read', true))) . '
               AND t.topic_status <> ' . ITEM_MOVED . '
                AND t.topic_approved = 1',

   'ORDER_BY'  => 'p.post_id DESC',
);

$posts = $db->sql_build_query('SELECT', $posts_ary);

$posts_result = $db->sql_query_limit($posts, $search_limit);

$latest_posts = array();

$bbcode_bitfield = null;

while( $posts_row = $db->sql_fetchrow($posts_result) )
{
   $topic_title       = $posts_row['topic_title'];
   $post_author       = get_username_string('full', $posts_row['poster_id'], $posts_row['username'], $posts_row['user_colour']);
   $post_date          = $user->format_date($posts_row['post_time']);
   $post_link       = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $posts_row['forum_id'] . '&amp;t=' . $posts_row['topic_id'] . '&amp;p=' . $posts_row['post_id']) . '#p' . $posts_row['post_id'];

   $post_text = nl2br($posts_row['post_text']);

   $bbcode = new bbcode(base64_encode($bbcode_bitfield));
   $bbcode->bbcode_second_pass($post_text, $posts_row['bbcode_uid'], $posts_row['bbcode_bitfield']);

   $post_text = smiley_text($post_text);

   $latest_posts[] = array(
      'TOPIC_TITLE'       => censor_text($topic_title),
      'POST_AUTHOR'       => $post_author,
      'POST_DATE'       => $post_date,
      'POST_LINK'       => $post_link,
      'POST_TEXT'         => censor_text($post_text),
   );
}

// -pity- eredeti kódja
echo "<table border='0' style='background-color:#ffffff'>";

$i = 0;
foreach($latest_posts as $post)
{
   $i++;

   echo "<tr><td style='background-color:".(($i%2==1)?"#faf0dc":"#faf0dc")."'><small>";
   echo "<font color='gray'>".$post['POST_DATE']."</font><br><b>".$post['POST_AUTHOR']."</b><br>".truncate($post['POST_TEXT'], $char_limit)."<br><a href='".$post['POST_LINK']."'><b>".$post['TOPIC_TITLE']."</b></a><br>";
   echo "</small></td></tr>";
}

echo "</table>";
// -pity- eredeti kódja


Ha a fájl nem a phpBB gyökérkönyvtárában van, akkor a

Kód:

$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
sorban módosítsd a './' elérési utat a fórumodéra.

Felhasználó profiljának megtekintése Privát üzenet küldése
-pity-
Kezdő phpBB-s
Kezdő phpBB-s


Csatlakozott: 2014.02.09. Vasárnap 7:22
Hozzászólások: 27
Hozzászólás Elküldve: 2014.12.14. 08:12    Hozzászólás témája:
Hozzászólás az előzmény idézésével
Éééés működik! Köszönöm, köszönöm, köszönöm! :D

Felhasználó profiljának megtekintése Privát üzenet küldése
Hozzászólások megtekintése:  

Nem készíthetsz új témákat ebben a fórumban.
Nem válaszolhatsz egy témára ebben a fórumban.
Nem módosíthatod a hozzászólásaidat a fórumban.
Nem törölheted a hozzászólásaidat a fórumban.
Nem szavazhatsz ebben fórumban.

Hirdetés
Hirdetés