Advanced search  

News:

cpg1.5.48 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.5.46 or older update to this latest version as soon as possible.
[more]

Pages: [1]   Go Down

Author Topic: PMS Plugin: Static link with unread total  (Read 4811 times)

0 Members and 1 Guest are viewing this topic.

KyleClarkeNZ

  • Coppermine newbie
  • Country: nz
  • Offline Offline
  • Gender: Male
  • Posts: 17
    • NZ Game Collectors
PMS Plugin: Static link with unread total
« on: May 23, 2012, 08:42:11 am »

Hi,

I was wondering if someone could please help me with a little mod for the Private Message Plugin. I'd like to be able to display a stand alone link instead of the full on "Welcome back KyleClarkeNZ" section that get's tacked on to the {SUB_MENU}

Specifically I'd like to add another menu item to the {SYS_MENU} next to "My Profile" where it just says "Private Messages [2]" (where [2] is the number of unread messages)

Thanks in advance,

Kyle
Logged

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15760
Re: PMS Plugin: Static link with unread total
« Reply #1 on: May 23, 2012, 02:37:38 pm »

It should be quite easy to adapt the already existing menu item to your needs (just have a look at the code). As I don't know that plugin don't expect a working mod from me.
Logged

KyleClarkeNZ

  • Coppermine newbie
  • Country: nz
  • Offline Offline
  • Gender: Male
  • Posts: 17
    • NZ Game Collectors
Re: PMS Plugin: Static link with unread total
« Reply #2 on: May 24, 2012, 07:19:51 am »

Ok, well thanks for your help anyway. I really appreciate you answering my other question (and the one a few weeks ago)

to help with anyone else who can help. The code for plugins/cpg_pms/include/init.inc.php

Code: [Select]
<?php
#**************************************************
#  CPG PMS Plugin for Coppermine Photo Gallery
#  *************************************************
#  Copyright (c) 2006 Thomas Lange <stramm@gmx.net>
#  *************************************************
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#  *************************************************
#  Coppermine version: 1.4.13
#  CPG PMS version: 1.1
#  $Revision: 1.0 $
#  $Author: stramm $
#***************************************************

if (!defined('IN_COPPERMINE')) die('Not in Coppermine...');

//language detection
$lang = isset($USER['lang']) ? $USER['lang'] : $CONFIG['lang'];
if (!
file_exists("plugins/cpg_pms/lang/{$lang}.php"))
  
$lang 'english';
require 
"plugins/cpg_pms/lang/{$lang}.php";

//pms table prefix
$CONFIG['TABLE_PMS'] = $CONFIG['TABLE_PREFIX'] . "pms";

//bridge compatibility
$udb_var get_object_vars($cpg_udb);
class 
cpg_pms_udb extends core_udb {

function cpg_pms_fetch_pms($db_user_id$uid$db_table){
global $CONFIG$BRIDGE$udb_var$db_prefix;
$pms_table $db_prefix.$db_table;
$sql "SELECT 1 FROM {$pms_table} WHERE $db_user_id=".$uid."";

$result cpg_db_query($sql$this->link_id);
$total mysql_num_rows($result);
                         
mysql_free_result($result);
return $total;
}
function cpg_pms_fetch_pms_read($db_user_id$uid$db_table$db_read1$db_read2){
global $CONFIG$BRIDGE$udb_var$db_prefix;
$pms_table $db_prefix.$db_table;
$sql "SELECT 1 FROM {$pms_table} WHERE $db_user_id=".$uid." AND $db_read1=".$db_read2."";

$result cpg_db_query($sql$this->link_id);
$total mysql_num_rows($result);
                         
mysql_free_result($result);
return $total;
}
}

$cpg_udb = new cpg_pms_udb;

//bridge support incl. loginbox
switch($BRIDGE['short_name']){
case 'smf10':
//vars for grabbing pms stats from db
$db_user_id 'ID_MEMBER';
$db_table 'pm_recipients';
$db_read1 'is_read';
$db_read2 '0';
//pms send link
define('PM_LINK'$BRIDGE['relative_path_to_config_file'].'gallery.php?action=pm;sa=send;u=');
define('PM_LINK_INBOX'$BRIDGE['relative_path_to_config_file'].'gallery.php?action=pm');
//loginform data
if (!USER_ID && $CONFIG['enable_loginform']) {
$loginFormHtml = <<<EOT
<div align="right" class="smallfont">
<ins>

<form action="
{$BRIDGE['relative_path_to_config_file']}gallery.php?action=login2&referer={$REFERER}" method="post" accept-charset="UTF-8" class="middletext" style="margin: 3px 1ex 1px 0pt;">
        <table cellpadding="0" cellspacing="3" border="0">
        <tr>
            <td><input type="text" class="textinput" name="user" size="10" /></td>
            <td><input type="password" class="textinput" name="passwrd" size="10" /></td>
            <td><input name="submitted" type="submit" value="Login" />
             <input type="hidden" name="cookielength" value="-1">
             <input name="hash_passwrd" value="" type="hidden">
</td>
        </tr>
        <tr>
        <td class="smallfont">
$lang_pms_sys[user]</td>
        <td class="smallfont">
$lang_pms_sys[pass]</td>
        <td></td>
</tr>
        </table>
</form>
</ins>
</div>
EOT;
}
break;
default: // unbridged coppermine
//vars for grabbing pms stats from db
$db_user_id 'owner';
$db_table $CONFIG['TABLE_PMS'];
$db_read1 'showed';
$db_read2 '0';
//pms send link
define('PM_LINK''gallery.php?file=cpg_pms/pms_send&id=');
define('PM_LINK_INBOX'$BRIDGE['relative_path_to_config_file'].'gallery.php?file=cpg_pms/pms');
//loginform data
if (!USER_ID && $CONFIG['enable_loginform']) {
$loginFormHtml = <<<EOT
<div align="right" class="smallfont">
<ins>
     <form action="login.php?referer=
$REFERER" method="post" name="loginbox" style="margin:0; padding:0;">
        <table cellpadding="0" cellspacing="3" border="0">
        <tr>
           
           <td><input type="text" class="textinput" name="username" size="10" value="
$lang_pms_sys[user]" onfocus="if (this.value == '$lang_pms_sys[user]') {this.value = '';}" onblur="if (this.value == '') {this.value = '$lang_pms_sys[user]';}"></td>
           <td><input type="password" class="textinput" name="password" size="10" /></td>
            
            <td><input name="submitted" class="button" style="text-decoration: none;" type="submit" value="Login" />
            <input name="remember_me" type="hidden" class="checkbox" value="1" checked="checked" /></td>
            

        </tr>
        </table>
        </form>
</ins>
</div>
EOT;
}
// switch


//loginForm data ... the statistics, pms status
if (USER_ID && $CONFIG['display_pms_status']) {
$loginFormHtml "<div align=\"right\" class=\"smallfont\">".$lang_pms_sys['welcome']." <strong>".(USER_NAME)."</strong><br />";

if ($CONFIG['display_pms_status']){
$tot_all_messages $cpg_udb->cpg_pms_fetch_pms($db_user_idUSER_ID$db_table);
$tot_new_messages $cpg_udb->cpg_pms_fetch_pms_read($db_user_idUSER_ID$db_table$db_read1$db_read2);
if ($CONFIG['pms_enabled']) {
$loginFormHtml .= "<a href='{$BRIDGE['relative_path_to_config_file']}"PM_LINK_INBOX ."'>".$lang_pms_sys['pms']."</a> ".$tot_new_messages.$lang_pms_sys['unread_total'].$tot_all_messages."</div>";
}
}

}


?>

the part that seems to be pointing use in the right direction is this:

Code: [Select]
if (USER_ID && $CONFIG['display_pms_status']) {
$loginFormHtml = "<div align=\"right\" class=\"smallfont\">".$lang_pms_sys['welcome']." <strong>".(USER_NAME)."</strong><br />";

if ($CONFIG['display_pms_status']){
$tot_all_messages = $cpg_udb->cpg_pms_fetch_pms($db_user_id, USER_ID, $db_table);
$tot_new_messages = $cpg_udb->cpg_pms_fetch_pms_read($db_user_id, USER_ID, $db_table, $db_read1, $db_read2);
if ($CONFIG['pms_enabled']) {
$loginFormHtml .= "<a href='{$BRIDGE['relative_path_to_config_file']}". PM_LINK_INBOX ."'>".$lang_pms_sys['pms']."</a> ".$tot_new_messages.$lang_pms_sys['unread_total'].$tot_all_messages."</div>";
}
}

}

Thanks,

Kyle
Logged

KyleClarkeNZ

  • Coppermine newbie
  • Country: nz
  • Offline Offline
  • Gender: Male
  • Posts: 17
    • NZ Game Collectors
[SOLVED] PMS Plugin: Static link with unread total
« Reply #3 on: May 29, 2012, 12:56:33 pm »

I figured it out. To make it easier to read I'm using the format Andre used in a reply to another query of mine.

Copy the function theme_main_menu from themes/sample/theme.php to your theme's theme.php file if it doesn't exist. Then, find
Code: [Select]
$param = array(and above, add
Code: [Select]
       // display number of unread PMs

function cpg_pms_fetch_pms_read($db_user_id, $uid, $db_table, $db_read1, $db_read2){
global $CONFIG, $BRIDGE, $udb_var, $db_prefix;
$pms_table = $db_prefix.$db_table;
$sql = "SELECT 1 FROM {$pms_table} WHERE $db_user_id=".$uid." AND $db_read1=".$db_read2."";

$result = cpg_db_query($sql, $this->link_id);
$total = mysql_num_rows($result);
                         mysql_free_result($result);
return $total;
}

$cpg_udb = new cpg_pms_udb;

$db_user_id = 'owner';
$db_table = $CONFIG['TABLE_PMS'];
$db_read1 = 'showed';
$db_read2 = '0';

$tot_new_messages = $cpg_udb->cpg_pms_fetch_pms_read($db_user_id, USER_ID, $db_table, $db_read1, $db_read2);

Place this amongst the other tokens below the change you just made.
Code: [Select]
'{NOTIFY_PMS_UNREAD}' =>  $tot_new_messages,
then place {NOTIFY_PMS_UNREAD} in the sys_menu part of your theme (where you want the number of unread messages to go)

http://nzgc.co.nz to see it in action, though you would have to register an account. (theme is work in progress)

Thanks,

Kyle
Logged
Pages: [1]   Go Up
 

Page created in 0.045 seconds with 20 queries.