How is this done on AA? First few words of post showing in....

Discussion in 'vBulletin Discussions' started by ArnyVee, Sep 18, 2009.

  1. ArnyVee

    ArnyVee Regular Member

    Joined:
    May 25, 2009
    Messages:
    1,264
    Likes Received:
    39
  2. Ak Worm

    Ak Worm Grand Master

    Joined:
    May 22, 2009
    Messages:
    979
    Likes Received:
    20
    First Name:
    Corey
    vBSEO, Buy it!
     
  3. ArnyVee

    ArnyVee Regular Member

    Joined:
    May 25, 2009
    Messages:
    1,264
    Likes Received:
    39
    I already have one license, but I wanted to do it on another site without spending the extra money :)

    Anyone know of a way to do it without vBSEO?
     
  4. Nick

    Nick Regular Member

    Joined:
    Jul 27, 2008
    Messages:
    7,441
    Likes Received:
    218
    I'm pretty sure it can't be done without vBSEO. If it can, I'm not sure how.

    Sorry. :o
     
  5. Chani

    Chani Grand Master

    Joined:
    Sep 1, 2009
    Messages:
    884
    Likes Received:
    54
    First Name:
    Chani
    Actually, I'm sure it could be done fairly easily as long as the variables are available (which I don't see why they wouldn't be as it's just repeating a portion of the page they're already on).

    Lynne? Wayne Luke?
     
  6. David

    David Regular Member

    Joined:
    May 30, 2003
    Messages:
    1,088
    Likes Received:
    133
    Location:
    Australia
    Yeah, all you'll need to do is create a plugin that grabs the first post information and then cut it off after so many letters/words.
     
  7. Wayne Luke

    Wayne Luke Regular Member

    Joined:
    Apr 2, 2009
    Messages:
    991
    Likes Received:
    276
    To do this would need a plugin on the fetch_threadinfo_query hook. The reason is that the post snippet is not stored as a variable but is created by joining in the post table on forumdisplay.

    Something like the following might work but I haven't tested it.

    PHP:
    if ($vbulletin->options['threadpreview'] > 0)
    {
    $hook_query_fields .= " LEFT(post.pagetext," $vbulletin->options['threadpreview'] . ") AS preview,";
    $hook_query_joins .= "LEFT JOIN " TABLE_PREFIX "post AS post ON(post.postid = thread.firstpostid)";
    }
     
  8. ArnyVee

    ArnyVee Regular Member

    Joined:
    May 25, 2009
    Messages:
    1,264
    Likes Received:
    39
    Wayne Luke, I'm going to do some reading (How to Write Plug-ins) and hopefully get it working! :)

    By the way, any tips for a complete beginner in writing plugins?
     
  9. Wayne Luke

    Wayne Luke Regular Member

    Joined:
    Apr 2, 2009
    Messages:
    991
    Likes Received:
    276
    How well do you know PHP?

    Plugins can be simple like the one above or complex. It all depends on what you are trying to accomplish. The key thing is to remember your variable scope and to choose the right hook to take advantage of that scope. vBulletin 3.8.X has over 980 hooks (compared to 700 or so in 3.6.X) so you get a wide variety of places to tie into.

    You'll need to be able to read vBulletin's PHP code to do this so that you know where a specific hook is called and the code surrounding it.
     
  10. ArnyVee

    ArnyVee Regular Member

    Joined:
    May 25, 2009
    Messages:
    1,264
    Likes Received:
    39
  11. Wayne Luke

    Wayne Luke Regular Member

    Joined:
    Apr 2, 2009
    Messages:
    991
    Likes Received:
    276
    Looks correct. You would put the variable $threadinfo[preview] where you want it to show in the template.
     
  12. ArnyVee

    ArnyVee Regular Member

    Joined:
    May 25, 2009
    Messages:
    1,264
    Likes Received:
    39
    Got a database error when opening a thread after activating the plugin ....

    Code:
    Database error in vBulletin 3.8.4:
    
    Invalid SQL:
    
    SELECT IF(thread.visible = 2, 1, 0) AS isdeleted,
    
    
    NOT ISNULL(subscribethread.subscribethreadid) AS issubscribed, emailupdate, folderid,
    post.pagetext AS preview, 
    thread.*
    
    LEFT(post.pagetext,150) AS preview,
    FROM thread AS thread
    
    LEFT JOIN subscribethread AS subscribethread ON (subscribethread.threadid = thread.threadid AND subscribethread.userid = 1  AND subscribethread.canview = 1)
    
    
    LEFT JOIN post AS post ON(post.postid = thread.firstpostid)
    
    LEFT JOIN post AS post ON(post.postid = thread.firstpostid)
    WHERE thread.threadid = 19;
    
    MySQL Error   : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LEFT(post.pagetext,150) AS preview,
    FROM thread AS thread
    
    LEFT JOIN su' at line 8
    Error Number  : 1064
    Request Date  : Saturday, September 19th 2009 @ 08:09:26 AM
    Error Date    : Saturday, September 19th 2009 @ 08:09:26 AM
    Script        : http://www.magicthemeparks.com/mk/forum/showthread.php?t=19
    Referrer      : http://www.magicthemeparks.com/mk/forum/index.php
    IP Address    : 
    Username      : 
    Classname     : vB_Database
    MySQL Version : 5.0.67-userstats-log
    ....what should I do? I've disabled the plugin for now.
     
  13. Wayne Luke

    Wayne Luke Regular Member

    Joined:
    Apr 2, 2009
    Messages:
    991
    Likes Received:
    276
    Do you have any other plugins on that hook? The preview is being pulled twice it seems but my code would only add it once.

    Anyway to fix the syntax error in my code, put a comma in front of left so the code looks like:
    PHP:
    if ($vbulletin->options['threadpreview'] > 0)
    {
    $hook_query_fields .= ", LEFT(post.pagetext," $vbulletin->options['threadpreview'] . ") AS preview";
    $hook_query_joins .= "LEFT JOIN " TABLE_PREFIX "post AS post ON(post.postid = thread.firstpostid)";
    }
    </span></span>
     
  14. Wayne Luke

    Wayne Luke Regular Member

    Joined:
    Apr 2, 2009
    Messages:
    991
    Likes Received:
    276
    Hmm.. I got it working on vBCodex though the preview is in a HTML comment.

    Here is the final plugin:
    PHP:
    if ($vbulletin->options['threadpreview'] > 0)
    {
    $hook_query_fields .= ", LEFT(post.pagetext," $vbulletin->options['threadpreview'] . ") AS preview";
    $hook_query_joins .= "LEFT JOIN " TABLE_PREFIX "post AS post ON(post.postid = thread.firstpostid)";
    }
    Also requires a single file edit at this time. You need to find this line in functions.php:
    PHP:
    SELECT IF(visible 210) AS isdeleted,
    Change it to:
    PHP:
    SELECT IF(thread.visible 210) AS isdeleted,
    Can probably get rid of the file edit if I have more time. Unfortunately, I am pressed for that at the moment.
     
    2 people like this.
  15. Lynne

    Lynne Regular Member

    Joined:
    May 26, 2009
    Messages:
    333
    Likes Received:
    32
    Location:
    Home Sweet Home!
    2 people like this.
  16. Wayne Luke

    Wayne Luke Regular Member

    Joined:
    Apr 2, 2009
    Messages:
    991
    Likes Received:
    276
    I didn't think he was talking about meta information but the description box at the top of the thread here.
     
  17. Mikey

    Mikey Mikeylicio.us

    Joined:
    Sep 12, 2009
    Messages:
    484
    Likes Received:
    92
    Location:
    United Kingdom
    I've made this into a little product, with a few options, one to insert a table, one to insert a fieldset etc, (using waynes plugin, thx wayne), just need to get the str_replace working on SHOWTHREAD..

    I have this code:

    PHP:
         {
    $vbulletin->templatecache['SHOWTHREAD'] = str_replace('$navbar''$navbar <if condition="$vboptions[threadpreview_onoff] == 1">    
    Enabled Test
    </if>'
    $vbulletin->templatecache['SHOWTHREAD']);
    and it didn't work, note, that isn't the exact code, but html in there wouldn't hurt would it?

    it's on the parse_templates hook.

    I will release the product (with waynes permission, should he grant it) if I can get the str_replace working, so that it will work on customised styles, and not just the default one.

    Help?

    EDIT NVM, FIXED IT!
     
  18. ArnyVee

    ArnyVee Regular Member

    Joined:
    May 25, 2009
    Messages:
    1,264
    Likes Received:
    39
    Wayne, got another database error when activating the 'new' plugin.

    Code:
    Database error in vBulletin 3.8.4:
    
    Invalid SQL:
    
    SELECT IF(thread.visible = 2, 1, 0) AS isdeleted,
    
    
    NOT ISNULL(subscribethread.subscribethreadid) AS issubscribed, emailupdate, folderid,
    post.pagetext AS preview, 
    thread.*
    
    , LEFT(post.pagetext,150) AS preview
    FROM thread AS thread
    
    LEFT JOIN subscribethread AS subscribethread ON (subscribethread.threadid = thread.threadid AND subscribethread.userid = 1  AND subscribethread.canview = 1)
    
    
    LEFT JOIN post AS post ON(post.postid = thread.firstpostid)
    
    LEFT JOIN post AS post ON(post.postid = thread.firstpostid)
    WHERE thread.threadid = 23;
    
    MySQL Error   : Not unique table/alias: 'post'
    Error Number  : 1066
    Request Date  : Saturday, September 19th 2009 @ 02:29:37 PM
    Error Date    : Saturday, September 19th 2009 @ 02:29:37 PM
    Script        : http://www.magicthemeparks.com/mk/forum/showthread.php?t=23
    Referrer      : http://www.magicthemeparks.com/mk/forum/index.php
    IP Address    : XX.XX.XX.XXX
    Username      : XXXXXXXXXX
    Classname     : vB_Database
    MySQL Version : 5.0.67-userstats-log
    I've deactivated for now until I can get it working. Thanks for your help so far Wayne!
     
  19. ArnyVee

    ArnyVee Regular Member

    Joined:
    May 25, 2009
    Messages:
    1,264
    Likes Received:
    39
    Mikey/Wayne,

    I'll keep an eye open to see when it's working. :D
     
  20. Chani

    Chani Grand Master

    Joined:
    Sep 1, 2009
    Messages:
    884
    Likes Received:
    54
    First Name:
    Chani
    Glad you got it working! :)

    But...don't you need a little dot in there when you're replacing $navbar with $navbar . {code} ?
     

Share This Page