to previous topic Print topic to next topic

 Root :: Developments :: Tutorials and programming :: HELP: advprofile + photoshare mainpic as user pic
 Moderated by:
 
  Bottom  HELP: advprofile + photoshare mainpic as user pic
whiskey Posted: 14.07.2005, 06:07
Noob
Noob


registered: Jul 13, 2005
Posts: 5

Status:  offline
last visit: 18.07.05
I have tried a lot of things but none of them seem to work (maybe because i don't know much about php and pnrender)... anyways... here is a thing i tried...
i hacked the ns_newuser module to create a new photoshare gallery for each new user... the main pic should be used as advprofile pic...

in user menu (so the image remains there) i added after line 7 in advprofile_user_menu.tpl:

Code
  1. <?php
  2. $dbhost = pnConfigGetVar&#40;'dbhost');
  3. $dbuname = pnConfigGetVar&#40;'dbuname');
  4. $dbpass = pnConfigGetVar&#40;'dbpass');
  5. $dbname = pnConfigGetVar&#40;'dbname');
  6. $nukeurl = pnGetBaseURL&#40;);
  7. $count = &#40; isset($HTTP_GET_VARS['c']) ) ? intval($HTTP_GET_VARS['c']) : 15;
  8. $count = &#40; $count == 0 ) ? 15 : $count;
  9. //Main pic from user gallery
  10. $mainpic = mysql_query&#40;"select nuke_photoshare_folders.ps_mainimage as mainimage from nuke_photoshare_folders");
  11. $mainpic = mysql_result&#40;$mainpic,0,"mainimage");
  12. echo "mainpic=$mainpic"
  13. echo "\<img src=\"index.php?module=photoshare&type=show&func=viewimage&iid=$mainpic&thumbnail=1\"&gt"; ?>


now ... what am i doing wrong? has anybody tried something like this? what is wrong with my syntax?

How would you get the data needed? it's just one tiny little number sitting there and i cannot get it to work jajaja

help or comments appreciated
Top  whiskey send PM
 
Chestnut Posted: 14.07.2005, 15:09
Site Admin
avatar

registered: Jun 02, 2002
Posts: 1320

Status:  offline
last visit: 07.02.08
Eww........

My first suggestion would be to drop that code......

Then, look at the advProfile/pntemplates/plugins...

Use the available code (take a plugin, rename it and adapt it) to get the your main image name (shouldn't there be a WHERE ??)...
(Do not use mysql_query, use the available $dbconn-> ....)

If you study the plugins right, at the end, all you'll have to put in the template is something like this :

Code
  1. <!--&#91;psmainimage]-->
  2.  


And your image will show if you did your plugin right. :wink:

Chestnut ! Cool
Site Admin
Top  Chestnut send PM Homepage
 
whiskey Posted: 16.07.2005, 00:11
Noob
Noob


registered: Jul 13, 2005
Posts: 5

Status:  offline
last visit: 18.07.05
dont know where is the WHERE (lol)... maybe got lost somewhere...

thanks.. i will do and when its done i will post it somewhere here (for others to help me get it working right lol)

see ya... gotta lot to do with this
Top  whiskey send PM
 
whiskey Posted: 17.07.2005, 10:15
Noob
Noob


registered: Jul 13, 2005
Posts: 5

Status:  offline
last visit: 18.07.05
Ok, here is what i tried

Code
  1. function.mainpic.php&#58;
  2.  
  3. <?php
  4. function smarty_function_mainpic&#40;$params, &$smarty)
  5. &#123;
  6.  
  7.     if &#40;!pnSecAuthAction(0, 'advProfile::', 'Plugin::mainpic.php', ACCESS_READ)) {
  8.         return false;
  9.     &#125;
  10.  
  11.     extract&#40;$params);
  12.     unset&#40;$params);
  13.  
  14.     if &#40;!isset($uid) || empty($uid)) {
  15.         return false;
  16.     &#125;
  17.  
  18.     if &#40;!isset($template) || empty($template)) {
  19.         $template = pnModGetVar&#40;'advProfile', 'template');
  20.     &#125;
  21.  
  22.     $dbconn  =& pnDBGetConn&#40;true);
  23.     $pntable =& pnDBGetTables&#40;);
  24.  
  25.     $tbl = &$pntable&#91;'photoshare_folders'];
  26.     $col = &$pntable&#91;'photoshare_folders_column'];
  27.  
  28.     $sql = "SELECT   $col&#91;ps_mainimage],
  29.             FROM     $tbl
  30.             WHERE    $col&#91;ps_owner] = '" . pnUserGetVar($uid);
  31.  
  32.     $result = $dbconn->Execute&#40;$sql);
  33.    
  34.     if &#40;$dbconn->ErrorNo() != 0) {
  35.         echo $dbconn->ErrorMsg&#40;);
  36.         return false;
  37.     &#125;
  38.  
  39.     if &#40;$result->EOF) {
  40.  
  41.         $mainpic = 0;
  42.  
  43.     &#125; else {
  44.  
  45.         list&#40;$mainpic) = $result->fields;
  46.  
  47.     &#125;
  48.  
  49.     $result->Close&#40;);
  50.  
  51.     @include_once&#40;'modules/advProfile/pnlang/'.pnVarPrepForOS(pnUserGetLang()).'/mainpic.php');
  52.  
  53.     if &#40;isset($assign)) {
  54.         $smarty->assign&#40;$assign, $mainpic);
  55.     &#125; else {
  56.         return $mainpic;
  57.     &#125;
  58.  
  59. &#125;
  60.  
  61. ?>


But i get no output using
Code
  1. <!--&#91;mainpic]-->
  2.  

or
Code
  1. <!--&#91;$mainpic]-->
  2.  

in the advprofile_user_menu.tpl

:cry: What am i doing wrong? I used pncuserpoints.php function as a base for the function.

Thanks in advance!

edited but still not working
Top  whiskey send PM
 
Chestnut Posted: 17.07.2005, 15:37
Site Admin
avatar

registered: Jun 02, 2002
Posts: 1320

Status:  offline
last visit: 07.02.08
Use the code tag please.

And you had no sql Error ? There is one :

Code
  1. $sql = "SELECT   $col&#91;ps_mainimage],
  2.             FROM     $tbl
  3.             WHERE    $col&#91;ps_owner] = '" . pnVarPrepForStore($uid)."'"; // <------ Fix
  4.  


Code
  1. <!--&#91;mainpic uid=$uid]-->
  2.  


That should help getting nearer...

This part is useless :
Code
  1. if &#40;!isset($template) || empty($template)) {
  2.         $template = pnModGetVar&#40;'advProfile', 'template');
  3.     &#125;
  4.  

Unless you use a template...

Be careful also if there is more than one file for this owner... If more than one file, then $mainpic will be an array and will output "Array" or nothing.

Chestnut ! Cool
Site Admin
Top  Chestnut send PM Homepage
 
whiskey Posted: 18.07.2005, 06:09
Noob
Noob


registered: Jul 13, 2005
Posts: 5

Status:  offline
last visit: 18.07.05
At last it worked thanks... here its the code:

Code
  1. <?php
  2. // File : $Id: function.mainpic.php,v 1.3 2005/05/16 16:29:19 Chestnut Exp $
  3. // ----------------------------------------------------------------------
  4. // PostNuke Content Management System
  5. // Copyright (C) 2001 by the PostNuke Development Team.
  6. // http://www.postnuke.com/
  7. // ----------------------------------------------------------------------
  8. // Based on:
  9. // PHP-NUKE Web Portal System - http://phpnuke.org/
  10. // Thatware - http://thatware.org/
  11. // ----------------------------------------------------------------------
  12. // LICENSE
  13. //
  14. // This program is free software; you can redistribute it and/or
  15. // modify it under the terms of the GNU General Public License (GPL)
  16. // as published by the Free Software Foundation; either version 2
  17. // of the License, or (at your option) any later version.
  18. //
  19. // This program is distributed in the hope that it will be useful,
  20. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  22. // GNU General Public License for more details.
  23. //
  24. // To read the license please visit http://www.gnu.org/copyleft/gpl.html
  25. // ----------------------------------------------------------------------
  26. // Original Author of file: Chestnut :: http://www.pnconcept.com
  27. // Purpose of file: Last 10 Comments for the advProfile
  28. // ----------------------------------------------------------------------
  29.  
  30. /**
  31. * Smarty function to displays the main user pic for the ns_newuser hack + photoshare
  32. *
  33. * Example
  34. * <!--[mainpic uid=$uid]-->
  35. *
  36. * @author       F. Chestnut (yup, i just modded this file -whiskey- )
  37. * @since        25/01/05
  38. * @see          function.mainpic.php::smarty_function_mainpic()
  39. * @param        array       $params      All attributes passed to this function from the template
  40. * @param        object      &$smarty     Reference to the Smarty object
  41. * @param        string      $uid         userid
  42. * @return       string      the results of the module function
  43. */
  44. function smarty_function_mainpic&#40;$params, &$smarty)
  45. &#123;
  46.  
  47.     if &#40;!pnSecAuthAction(0, 'advProfile::', 'Plugin::mainpic.php', ACCESS_READ)) {
  48.         return false;
  49.     &#125;
  50.  
  51.     extract&#40;$params);
  52.     unset&#40;$params);
  53.  
  54.     if &#40;!isset($uid) || empty($uid)) {
  55.         return false;
  56.     &#125;
  57.  
  58.     if &#40;!isset($template) || empty($template)) {
  59.         $template = pnModGetVar&#40;'advProfile', 'template');
  60.     &#125;
  61.     pnModDBInfoLoad&#40;'photoshare');
  62.     $dbconn  =& pnDBGetConn&#40;true);
  63.     $pntable =& pnDBGetTables&#40;);
  64.  
  65.     $tbl = $pntable&#91;'photoshare_folders'];
  66.     $col = &$pntable&#91;'photoshare_folders_column'];
  67.  
  68.     $sql = "SELECT  ps_mainimage
  69.             FROM    $tbl
  70.             WHERE   ps_owner = '" . pnVarPrepForStore($uid) . "'"; //
  71.  
  72.     $result = $dbconn->Execute&#40;$sql);
  73.    
  74.     if &#40;$dbconn->ErrorNo() != 0) {
  75.         echo $dbconn->ErrorMsg&#40;);
  76.         return false;
  77.     &#125;
  78.  
  79.     if &#40;$result->EOF) {
  80.  
  81.         $mainpic = 0;
  82.  
  83.     &#125; else {
  84.  
  85.         list&#40;$mainpic) = $result->fields;
  86.  
  87.     &#125;
  88.  
  89.     $result->Close&#40;);
  90.  
  91.  
  92.         return $mainpic;
  93.  
  94. &#125;
  95.  
  96. ?>

Now, you can see that i had to call the tables by their names... well i didn't found a way for them to work properly calling them:
Code
  1. $sql = "SELECT  $col&#91;ps_mainimage]
  2.             FROM    $tbl
  3.             WHERE  $col&#91;ps_owner] = '" . pnVarPrepForStore($uid) . "'"; //
  4.  


and i do not why but this works.

Now for the other part of the hack... i will post later because we have to make sure every new user has a unique album.

see ya
Top  whiskey send PM
 
whiskey Posted: 18.07.2005, 06:54
Noob
Noob


registered: Jul 13, 2005
Posts: 5

Status:  offline
last visit: 18.07.05
Note that the previous plugin will work when you create a photoshare album for each new user (yes, previous users will require you to create them an album)

go to user.php from ns_newuser and somewhere insert this:
Code
  1. // Add photoshare entry to postnuke for this user
  2.                 $psdate= UNIX_TIMESTAMP&#40;pnVarPrepForStore($user_regdate))
  3.                 $result = &$dbconn->Execute&#40;"INSERT INTO nuke_photoshare_folders (ps_id, ps_owner, ps_createddate, ps_modifieddate, ps_title, ps_description, ps_topic, ps_template, ps_blockfromlist, ps_hidepnframe, ps_parentfolder, ps_accesslevel, ps_viewkey, ps_mainimage)
  4.                                              VALUES &#40;". pnVarPrepForStore($uid) . ", " . pnVarPrepForStore($uid) . ", " . $psdate . ", " . $psdate . ", " . pnVarPrepForStore($uid) . ", " . pnVarPrepForStore($uid) . ", -1, 'book', 0, 0, -1, 0, NULL, NULL)");
  5.                 // Resume your work now
  6.  


below this:

Code
  1. // Let any hooks know that we have created a new item
  2.             pnModCallHooks&#40;'item', 'create', $uid, 'uid');
  3.  

which is somewhere around line 440 - 442

This code creates a new sql entry for your user into photoshare folders after they create their entry, it uses the book template as default, you can change to any other template you want. Also uses the nuke preffix and the photoshare standard name so keep that in mind.

Now this takes care for new users, but not for existing ones... i will see how to fix this (maybe a php script to read your existing users and create them new albums? i dont know), and if you create the user manually via admin, such user will not have (yet) a new album. Easy, just go and create one yourself for him/her. (yes as soon as i find how i will post the hack for this).

Next we should take care about a couple of things... for example, as chestnut points out, if multiple albums are generated (sub albums), multiple main pictures will be defined for each user and multiple outputs will generate an array... Maybe we can make it select just main folders ( adding to the WHERE in the query something like AND ps_parentfolder = -1. Also we will want to make sure that photoshare will not create a new folder with the same number as a new user... (this hack is also in the TODO bin), maybe creating manually a folder with a really really large number (so new users get the lower numbers and sub folders will autoincrement from lets say 123456789 and forth XD ), but until i try it i will not recommend it.

Now for my website i do not need multiple albums per user (yet), so there will be no "create new album" function (nor delete function)... any new hack needed i will post here.

Thanks for the help!
Top  whiskey send PM
 
MACscr Posted: 03.10.2005, 00:12
Plumber
Plumber


registered: Jan 11, 2005
Posts: 147

Status:  offline
last visit: 19.04.06
Any update on this hack? I would also love to see a working version of it.
Top  MACscr send PM Homepage
 



Powered by pnForum Version 2.0.1
DarkMindZ