Adding CPMFetch to PhpBB Profile... How to pass "profile username" to PHP? Adding CPMFetch to PhpBB Profile... How to pass "profile username" to PHP?
 

News:

CPG Release 1.6.26
Correct PHP8.2 issues with user and language managers.
Additional fixes for PHP 8.2
Correct PHP8 error with SMF 2.0 bridge.
Correct IPTC supplimental category parsing.
Download and info HERE

Main Menu

Adding CPMFetch to PhpBB Profile... How to pass "profile username" to PHP?

Started by NicMason.com, December 12, 2008, 03:33:10 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

NicMason.com

Hi Vuud,

Thanks for a great piece of code in CPMFetch!

I'm hoping you might know the answer to this problem if you have some experience with phpBB.  I have asked at the phpbb forums also,  but I thought it would be appropriate to also post it on this sub-board,  as CPMFetch is designed for external use.

I've been searching and reading high and low on this forum, PhpBB, and in many other sources,  but I can't seem to work out the answer...


I'm adding CPMFetch to the User Profile page in phpBB3 (in memberlist_view.html) so that it will display the latest images they've uploaded to the Coppermine gallery.

I've gotten as far as showing the last uploaded images for the currently logged-in user,  but NOT for the user who's profile it is we're viewing (which is what I want...)

This is the code that will show the currently logged-in user's images (ie: the user who's looking at the profile):

<!-- Nic - ADDED BELOW - Show Gallery in Profile  -  11-12-2008 -->
<div class="panel bg2">
<div class="inner"><span class="corners-top"><span></span></span>
<div class="column1">
<h3>GALLERY OF {USERNAME}</h3>
<dl class="details">
<dt>Latest Images</dt>
<dd>
<!-- PHP -->
$profile_name = $user->data['username'];
$options = array(
"imageStyle" => "style2" );
$objCpm = new cpm("../gallery/cpmfetch/cpmfetch_config.php");
$objCpm->cpm_viewLastAddedMediaFrom("owner=$profile_name",1,4,$options);
$objCpm->cpm_close();
<!-- ENDPHP -->
</dd>
</dl>
</div>
<span class="corners-bottom"><span></span></span></div>
</div>


What do I need to change here to get the username of the currently viewed profile?

$profile_name = $user->data['username'];


This line (below) gives the correct profile name,  but I don't know how to pass it to the PHP...

<h3>GALLERY OF {USERNAME}</h3>

Thanks in advance for any help anyone can give!

Cheers!

Nic

NicMason.com

Never mind.  I worked it out myself using a database query.  Cheers!  :D

If anyone's interested,  just email me,  and I can post it here...

Joachim Müller


NicMason.com


NicMason.com

PLEASE NOTE: I haven't yet determined if this is secure or not,  as I'm accessing the database directly,  rather than through the phpbb3 system.


// Display CPG Images in PhpBB Profile - Written by Nic Mason - NicMason.com

// I have my Coppermine Gallery integrated with Joomla,
// so in this code I'm accessing the Joomla database to get the user IDs,
// as they are the same as the CPG user IDs and CPG usernames due to the integration.

// If you don't have CPG integrated with Joomla you'll have to check and
// likely change the database names and table names to successfully retrieve
// the user IDs from the CPG database instead.

// Remember to check ALL your database and table names
// as you may need to change the defaults I've used here.

// Santé! - NicMason.com



Enter your host and database info in this code and save it as cpgimages.php in the root of your phpBB forum installation, ie: in the same folder as the phpBB config.php file.


<?php

// Display CPG Images in PhpBB Profile - Written by Nic Mason - NicMason.com

// Please leave these comments in place when reusing or distributing this code.

// I have my Coppermine Gallery integrated with Joomla,
// so in this code I'm accessing the Joomla database to get the user IDs,
// as they are the same as the CPG user IDs and CPG usernames due to the integration.

// If you don't have CPG integrated with Joomla you'll have to check and
// likely change the database names and table names to successfully retrieve
// the user IDs from the CPG database instead.

// Remember to check ALL your database and table names
// as you may need to change the defaults I've used here.

// Sant&#233;! - NicMason.com

function curPageURL() {
 
$pageURL 'http';
 if (
$_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
 
$pageURL .= "://";
 if (
$_SERVER["SERVER_PORT"] != "80") {
&
#160; $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
 
} else {
&
#160; $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
 
}
 return 
$pageURL;
}

$url curPageURL();

$mystring $url;
$findme&#160; &#160;= '&u=';
$pos strpos($mystring$findme);
$uidpos $pos+3;
$uid_inter substr($mystring$uidpos);

for(
$i=0$i<strlen($uid_inter); $i++){
if(!is_numeric(substr($uid_inter$i1))){
$uid substr($uid_inter0$i);
break;
}
else{
$uid $uid_inter;
}
}

$profile_name '';
$gallery_id 0;
$owner_id 0;

$username "---------------------"; // Enter your host username,&#160; in place of ---------------------.
$password "---------------------"; // Enter your host password.
$hostname "localhost"; // Enter your hostname,&#160; usually "localhost".

$dbh mysql_connect($hostname$username$password
or die("Unable to connect to MySQL");

$selected mysql_select_db("---------------------",$dbh // Enter your phpBB database name.
or die("Could not select the database.");


$result mysql_query("select username from phpbb_users WHERE user_id=$uid");  // Check YOUR phpBB database table names against these.


while ($row mysql_fetch_row($result)) {
for ($i=0$i<mysql_num_fields($result); $i++) {
$profile_name "$row[$i]";
}
}
mysql_close($dbh);


$dbh mysql_connect($hostname$username$password
or die("Unable to connect to MySQL");

$selected mysql_select_db("---------------------",$dbh)&#160;  // Enter your Joomla database name.
or die("Could not select the database.");

$result mysql_query("select id from jos_users WHERE username='$profile_name'");  // Check YOUR Joomla database table names.

while ($row mysql_fetch_row($result)) {
for ($i=0$i<mysql_num_fields($result); $i++) {
$gallery_id "$row[$i]";
}
}


/*
To help find MySQL error - Use code below...
*/

&#160; &#160; &#160; &#160; if ($row = mysql_fetch_row($result)) {
&#160; &#160; &#160; &#160; &#160; &#160;return $row;
&#160; &#160; &#160; &#160; } else {
&#160; &#160; &#160; &#160; &#160; &#160;print (mysql_error());
&#160; &#160; &#160; &#160; }



mysql_close($dbh);

$dbh mysql_connect($hostname$username$password
or die("Unable to connect to MySQL");

$selected mysql_select_db("---------------------",$dbh)&#160;  // Enter your CPG database name.
or die("Could not select the database.");


$result mysql_query("select owner_id from cpg14x_pictures WHERE owner_id=$gallery_id");  // Check YOUR CPG database table names.

while ($row mysql_fetch_row($result)) {
for ($i=0$i<mysql_num_fields($result); $i++) {
$owner_id "$row[$i]";
}
}
mysql_close($dbh);

$objCpm = new cpm("../gallery/cpmfetch/cpmfetch_config.php");&#160;  // Check YOUR cpmfetch path.
$objCpm->cpm_viewRandomMediaFrom("owner=$profile_name",1,9);
$objCpm->cpm_close();

// Display CPG Images in PhpBB Profile - Written by Nic Mason - NicMason.com
// Please leave these comments in place when reusing or distributing this code.&#160; Sant&#233;!
// NicMason.com

?>



Replace the path in the following code with YOUR path to your cpmfetch.php file (from the phpBB forum root.)
Then add this code to the phpBB file memberlist.php at around line 20 (after the second "include" line.)
include "../gallery/cpmfetch/cpmfetch.php";

In your phpBB style template folder open memberlist_view.php
and find <!-- IF SIGNATURE -->
Just BEFORE this line, insert the following code:
<!-- INCLUDEPHP cpgimages.php -->


EDIT: Add the following to /forum/.htaccess which will hopefully do the trick of keeping the vital data hidden...  I recommend anyone who uses this to rename "cpgimages.php" to something else,  wherever it appears in the code submitted here (above and below.)


<Files "cpgimages.php">
Order Allow,Deny
Deny from All
</Files>



Enable PHP in your PhpBB Admin,  and you're done!

NicMason.com


(Edit: Fixed non-essential grammatical error. - 19-02-2009)

NicMason.com

PLEASE NOTE: I haven't yet determined if this is secure or not,  as I'm accessing the database directly,  rather than through the phpbb3 system.

EDIT: Add the following to /forum/.htaccess which will hopefully do the trick of keeping the vital data hidden...  I recommend anyone who uses this to rename "cpgimages.php" to something else,  wherever it appears in the code submitted here.


<Files "cpgimages.php">
Order Allow,Deny
Deny from All
</Files>