to previous topic Print topic to next topic

 Root :: Developments :: Modules :: advProfile plugin help - pnWebLogs
 Moderated by:
 
  Bottom  advProfile plugin help - pnWebLogs
mookiestix Posted: 21.12.2006, 06:23
Noob
Noob


registered: Dec 20, 2006
Posts: 4

Status:  offline
last visit: 22.12.06
Without sounding too much like a kiss-up, let me start off by saying that after innumerable Google searches on various Postnuke issues, the name usually attached to the solution I was looking for was Chestnut. That being said, I figured I'd come straight to the source instead of waiting for Google to point me here again.

I've been using advProfile for a couple of days now and need a little help with a plugin. At first, I tried using a plugin script posted here by MACScr for v4bjournal but couldn't get it to work (he never posted the final code for it). I have since switched to pnWebLogs and am trying to get a "Last 5 Blogs" to list to my site's advProfile pages.

Here is what I tried to do (note, all I did was follow the example from your core plugins and try to make it work...I'm actually quite clueless):

function.last5blog.php
Code
  1. function smarty_function_last5blog($params, &$smarty)
  2. {
  3.  
  4.     if (!pnSecAuthAction(0, 'advProfile::', 'Plugin::last5blog.php', ACCESS_READ)) {
  5.         return false;
  6.     }
  7.  
  8.     extract($params);
  9.     unset($params);
  10.  
  11.     if (!isset($uid) || empty($uid)) {
  12.         echo "uid";
  13.         return false;
  14.     }
  15.  
  16.     if (!isset($template) || empty($template)) {
  17.         $template = pnModGetVar('advProfile', 'template');
  18.     }
  19.  
  20.     //if (!pnModAvailable('pnWebLogs')) return false;*/
  21.  
  22.     pnModDBInfoLoad('pnWebLog');
  23.     $dbconn  =& pnDBGetConn(true);
  24.     $pntable =& pnDBGetTables();
  25.  
  26.     $tbl = &$pntable['pnWebLog_posts'];
  27.     $col = &$pntable['pnWebLog_posts_column'];
  28.  
  29.     $sql = "SELECT   $col[post_id],
  30.                      $col[title]
  31.             FROM     $tbl
  32.             WHERE    $col[uid] = '".pnVarPrepForStore($uid)."'
  33.             ORDER BY $col[post_id] DESC";
  34.  
  35.     $result = $dbconn->SelectLimit($sql, 5, 0);
  36.  
  37.     if ($dbconn->ErrorNo() != 0) {
  38.         echo $dbconn->ErrorMsg();
  39.         return false;
  40.     }
  41.  
  42.     $last5blog = array();
  43.  
  44.     for(; !$result->EOF; $result->MoveNext()) {
  45.         list($post_id, $title) = $result->fields;
  46.  
  47.         $last5blog[] = array('post_id'   => $post_id,
  48.                               'title' => $title);
  49.  
  50.     }
  51.  
  52.     $result->Close();
  53.  
  54.     $pnRender =& new pnRender('advProfile');
  55.  
  56.     $pnRender->Assign('last5blog', $last5blog);
  57.  
  58.     $template = $template."/advProfile_plugin_last5blog.tpl";
  59.  
  60.     if (!$pnRender->template_exists(pnVarPrepForOS($template))) {
  61.         echo "notexists";
  62.         return false;
  63.     }
  64.  
  65.     @include_once('modules/advProfile/pnlang/'.pnVarPrepForOS(pnUserGetLang()).'/last5blog.php');
  66.     /*@include_once('modules/advProfile/pnstyle/last5blog.css');*/
  67.  
  68.     $tpl = $pnRender->Fetch($template, $uid);
  69.  
  70.     if (isset($assign)) {
  71.         $smarty->assign($assign, $tpl);
  72.     } else {
  73.         return $tpl;
  74.     }
  75.  
  76. }


advProfile_plugin_last5blog.tpl:
Code
  1. <!--[* $Id: advProfile_plugin_last5blog.tpl,v 1.1 2005/09/03 21:29:21 chestnut exp $ *]-->
  2. <table >
  3.   <thead>
  4.     <tr>
  5.       <th > <!--[pnml name="_LAST5BLOG"]--> </th>
  6.     </tr>
  7.   </thead>
  8.   <tbody>
  9.     <tr>
  10.       <td >
  11.         <!--[if $last5blog]-->
  12.           <ul class="linklist">
  13.             <!--[section name="last5blog" loop=$last5blog]-->
  14.               <li><a href="index.php?module=pnWebLog&func=viewpost&post_id=<!--[$last5blog[last5blog].post_id]-->" title="<!--[$last5blog[last5blog].title]-->"><!--[$last5blog[last5blog].title]--></a></li>
  15.             <!--[/section]-->
  16.           </ul>
  17.         <!--[else]-->
  18.            
  19.         <!--[/if]-->
  20.       </td>
  21.     </tr>
  22.   </tbody>
  23. </table>


advProfile function call in templates:

Code
  1. <!--[last5blog uname=$USERNAME_VALUE uid=$uid assign="last5blog"]-->
  2.           <td><!--[$last5blog|pnvarprephtmldisplay]--></td>


When I try using this, it says I have a 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 ' FROM WHERE = '5' ORDE' at line 1".

Any help would be appreciated.








edited by: mookiestix, Dec 22, 2006 - 11:17 AM
Top  mookiestix send PM Homepage
 
Chestnut Posted: 21.12.2006, 16:21
Site Admin
avatar

registered: Jun 02, 2002
Posts: 1320

Status:  offline
last visit: 07.02.08
ok... Before:
Code
  1. $dbconn  =& pnDBGetConn(true);


I would put:
Code
  1. pnModDBInfoLoad('pnWebLog');


And this
Code
  1. if (!isset($uname) || empty($uname)) {

to this
Code
  1. if (!isset($uid) || empty($uid)) {

... as in this particular case, you use the uid and not the username.

As for the rest, it looks completly fine. :)

Chestnut ! Cool
Site Admin
Top  Chestnut send PM Homepage
 
mookiestix Posted: 21.12.2006, 19:37
Noob
Noob


registered: Dec 20, 2006
Posts: 4

Status:  offline
last visit: 22.12.06
Excellent, I knew I came to the right place. Thanks for the assist!

It seems to work now...except for one thing.

Is there something wrong with this piece of code in my .tpl?

Code
  1. <!--[section name="last5blog" loop=$last5blog]-->
  2.               <li><a href="index.php?module=pnWebLog&func=viewpost&post_id=<!--[$last5blog[last5blog].post_id]-->" title="<!--[$last5blog[last5blog].title]-->"><!--[$last5blog[last5blog].title]--></a></li>
  3.             <!--[/section]-->


The plugin now shows the last entries to the blog, but when the link is clicked to take you to that entry, it doesn't display. It's not adding the "post_id" to the end of the link.

Also, I made the recommended changes to code in the first post of this topic if anyone else wants to use the plugin. Just need to figure out how to fix this last issue before it can be used correctly.



edited by: mookiestix, Dec 21, 2006 - 10:24 PM
Top  mookiestix send PM Homepage
 
Chestnut Posted: 22.12.2006, 17:38
Site Admin
avatar

registered: Jun 02, 2002
Posts: 1320

Status:  offline
last visit: 07.02.08
Yup... error is in the plugin itself :

Code
  1. list($sid, $title) = $result->fields;


should be

Code
  1. list($post_id, $title) = $result->fields;


And you should have a go. icon_wink

Chestnut ! Cool
Site Admin
Top  Chestnut send PM Homepage
 
mookiestix Posted: 22.12.2006, 19:19
Noob
Noob


registered: Dec 20, 2006
Posts: 4

Status:  offline
last visit: 22.12.06
Awesome! Works like a charm now. I updated the code in the first post in case anyone else would like to use it.

I'll zip it up and submit a link for the downloads section as well. Thanks for the help!
Top  mookiestix send PM Homepage
 



Powered by pnForum Version 2.0.1
DarkMindZ