SimplePortal

Customization => Blocks and Modifications => Topic started by: Kryzen on August 09, 2011, 10:05:01 AM

Title: Quick PM v1.0.4.1
Post by: Kryzen on August 09, 2011, 10:05:01 AM
Quick PM
v1.0.4.1

Quick PM was originally created for Dream Portal, but I decided to port it to SP. This module allows users to send quick PM's. I would like to say thanks to SoLoGHoST, SlammedDime, Labradoodle-360, Ccbtimewiz, Phantomm, Miss all Sunday and DoctorMalboro. The current version is 1.0.4.1 and I hope to release v1.1 soon.

Installing is very simple. Just create a new PHP code block and use this code:
Code: [Select]
/**
Quick PM modification by Dr. Deejay
Module originally created for Dream Portal
Ported to SimplePortal by Dr. Deejay
Version 1.0.4.1
Thanks to: SoLoGHoST, SlammedDime, Labradoodle-360, Ccbtimewiz, Phantomm, Miss all Sunday and DoctorMalboro     
*/
global $txt, $buttons, $scripturl, $smcFunc, $context;


/*Config*/
$txt['quick_pm_block_not_allowed'] = 'You are not allowed to access this block';
$txt['quick_pm_block_default_user'] = 'Select user';
$txt['quick_pm_block_send'] = 'Send';

$query = $smcFunc['db_query']('', '
SELECT real_name, id_member
FROM {db_prefix}members
WHERE is_activated={int:activated}
ORDER BY real_name ASC',
array(
'activated' => 1,
)
);

$context['fastpm']['members'] = array();

while ($row = $smcFunc['db_fetch_assoc']($query))
{
$context['fastpm']['members'][$row['id_member']] = $row['real_name'];
}

$smcFunc['db_free_result']($query);

// Wait.. We DO have permissions for it, or don't we?
if (!allowedTo('pm_send'))
{
echo '',$txt['quick_pm_block_not_allowed'],'';
return;
}

// Are we allowed to view the memberlist? If yes, begin with the select box
echo '
<form action="#" method="post">
<select name="u" onchange="if (this.value) window.location.href=this.value">
<option value="0" selected="selected" disabled="disabled">',$txt['quick_pm_block_default_user'],'</option>';

foreach ($context['fastpm']['members'] as $key => $value)
echo '
<option value="', $scripturl, '?action=pm;sa=send;u=', $key, '">', $value, '</option>';

echo ' </select>
<input type="submit" value="',$txt['quick_pm_block_send'],'">
</form>';

// If we submitted the form, redirect to the messages section
if(isset($_POST['u']))
redirectexit('action=pm;sa=send;u=' . $_POST['u']);

Enjoy!
Dr. Deejay
Title: Re: Quick PM v1.0.1
Post by: 130860 on August 09, 2011, 10:16:38 AM
Looks cool :) 

the only thing is that if you have thousands of members, the select list will be huge :P

Title: Re: Quick PM v1.0.1
Post by: Kryzen on August 09, 2011, 10:26:53 AM
Thanks 130850! :D
Yes, that's true lol :P Dunno how to solve that without letting it lose it's functionality, but I'll try and thanks for the comments :)
Title: Re: Quick PM v1.0.1
Post by: 130860 on August 10, 2011, 09:10:51 PM
Well you could limit the list to show only the users buddies  or  use the 2.0 user auto-suggest ajax thing, the user then will just need to type the other user's name.
Title: Re: Quick PM v1.0.1
Post by: Kryzen on August 17, 2011, 09:13:35 AM
Hmm great idea :) I'll change it in 1.1 ;)
Title: Re: Quick PM v1.0.1
Post by: Shadow Queen on September 14, 2011, 02:11:59 PM
Very nice.

Title: Re: Quick PM v1.0.1
Post by: Kryzen on September 14, 2011, 02:13:10 PM
Thanks Shadow Queen :)
Title: Re: Quick PM v1.0.1
Post by: Shadow Queen on September 14, 2011, 02:14:18 PM
Your welcome :)
Title: Re: Quick PM v1.0.1
Post by: ccbtimewiz on September 14, 2011, 03:17:51 PM
Code: [Select]
if(isset($_POST['u']))
header("Location: ".$scripturl."?action=pm;sa=send;u=".$_POST['u']);

Can replace with:
Code: [Select]
if(isset($_POST['u']))
redirectexit('?action=pm;sa=send;u=' . $_POST['u']);
Title: Re: Quick PM v1.0.1
Post by: Kryzen on September 14, 2011, 03:22:52 PM
Thanks for the tip ccbtimewiz, I'll change it in 1.0.2 (which will be released asap) :)
Title: Re: Quick PM v1.0.1
Post by: ccbtimewiz on September 14, 2011, 04:19:27 PM
Bug here:

Code: [Select]
if ($context['user']['is_guest'])
{
echo '</div>You are not allowed to access this module';
return;
}

Don't need a closing div if there was never an open div in the first place. Also, SimplePortal uses the term "Block", not "Module". In addition, you aren't checking if the user can even send a PM, just that if they're not a guest. Could make use of the allowedTo() function and use the appropriate permission.

Such as;

Code: [Select]
if (!allowedTo('send_pm'))
{
echo 'You are not allowed to access this block';
return;
}
Title: Re: Quick PM v1.0.1
Post by: Kryzen on September 15, 2011, 01:52:04 AM
Thanks ccbtimewiz, I've fixed both issues :)
Title: Re: Quick PM v1.0.2
Post by: phantomm on September 19, 2012, 11:47:43 AM
one more fix, change:
Code: [Select]
if (!allowedTo('send_pm')) to
Code: [Select]
if (!allowedTo('pm_send'))
http://simpleportal.net/index.php?topic=11817.0
Title: Re: Quick PM v1.0.2
Post by: boo2 on September 19, 2012, 01:37:16 PM
I thought no one would reply to a thread that was a year old, but I guess I was wrong. Anyway Phantomm said I should make my suggestion here. Not expecting anything really, just a suggestion because I find this particular code very useful but might not if I had a huge number of members, so I wonder if there might not be another way to do this at that point that would work as well.

My suggestion was..

It would be great if someone could change this a bit and have it only show contacts of that persons buddy list, so that at some point the drop down doesn't become so long it's difficult to use. Hope that made sense. Or maybe there is another way to do it so that the drop down list of members would not become so long it would not longer be convenient.

It would also be nice if when you clicked on the members name in the drop down it immediately took you to the reply box before you even had to hit send.
Title: Re: Quick PM v1.0.2
Post by: FrizzleFried on September 20, 2012, 01:16:07 PM
This code is nice... I used it at the bottom of my custom menu... however... the poor guy who is at #1 spot has his name showing at all time by default... that guy is geting a ton of PM's from the "idiot crowd"... any way to make a BLANK DEFAULT requiring someone click on the drop down menu to select a user?
Title: Re: Quick PM v1.0.2
Post by: phantomm on September 21, 2012, 03:34:49 AM
I replaced:
Code: [Select]
<form action="" method="post">
<select name="u">
to
Code: [Select]
<form action="" method="post">
<select name="u">
<option value="0" selected="selected">Select user</option>';

:)
Title: Re: Quick PM v1.0.2
Post by: FrizzleFried on September 21, 2012, 10:56:25 AM
Works perfect.  Thank you!
Title: Re: Quick PM v1.0.2
Post by: boo2 on September 30, 2012, 02:16:18 PM
I removed this for a while because i got tired of the error log filling up over it. Then yesterday I thought I would try it again, but removed the only other custom block for latest posts which doesn't throw any errors. Then I put this back as the only custom block and used it to pm just one person, then I checked the error logs and sure enough there they were. I can't believe a small bit of code like this could be so problematic. lol

Anyway doesn't look like anyone really cares about this mod but me at this point..

Heres the errors in case someone takes an interest one day. I sure would like it to work with out errors, works with them but I'm always nervousness when I have errors in admin.

Code: [Select]
/index.php?action=admin;area=portalblocks;sa=edit
2: fclose() expects parameter 1 to be resource, boolean given
File: Sources/Subs-PortalAdmin.php Line: 401

 
/index.php?action=admin;area=portalblocks;sa=edit
2: fwrite() expects parameter 1 to be resource, boolean given
File: Sources/Subs-PortalAdmin.php Line: 400
 

/index.php?action=admin;area=portalblocks;sa=edit
2: fopen(/public_html/sp_tmp_1349028364.php) [<a href='function.fopen'>function.fopen</a>]: failed to open stream: Permission denied
File: Sources/Subs-PortalAdmin.php Line: 399

And here is the code being used:

Code: [Select]
/**
Quick PM modification by Dr. Deejay
Module originally created for Dream Portal
Ported to SimplePortal by Dr. Deejay
Version 1.0.2
Thanks to: SoLoGHoST, SlammedDime, Labradoodle-360, Ccbtimewiz, Miss all Sunday and DoctorMalboro     
*/
global $txt, $buttons, $scripturl, $smcFunc, $context;

$query = $smcFunc['db_query']('', '
SELECT real_name, id_member
FROM {db_prefix}members
WHERE is_activated={int:activated}
ORDER BY real_name ASC',
array(
'activated' => 1,
)
);

$context['fastpm']['members'] = array();

while ($row = $smcFunc['db_fetch_assoc']($query))
{
$context['fastpm']['members'][$row['id_member']] = $row['real_name'];
}

$smcFunc['db_free_result']($query);

// Wait.. We DO have permissions for it, or don't we?
if (!allowedTo('pm_send'))
{
echo 'You are not allowed to access this block';
return;
}

// Are we allowed to view the memberlist? If yes, begin with the select box
echo '<form action="" method="post">
<select name="u">
<option value="0" selected="selected">Select user ....</option>';
foreach ($context['fastpm']['members'] as $key => $value)
echo ' <option value="', $key, '">', $value, '</option>';

echo ' </select>
<input type="submit" value="Send">
</form>';

// If we submitted the form, redirect to the messages section
if(isset($_POST['u']))
redirectexit('action=pm;sa=send;u=' . $_POST['u']);

Title: Re: Quick PM v1.0.2
Post by: Kryzen on October 01, 2012, 09:27:24 AM
one more fix, change:
Code: [Select]
if (!allowedTo('send_pm')) to
Code: [Select]
if (!allowedTo('pm_send'))
http://simpleportal.net/index.php?topic=11817.0
Thank you for the fix, I'll release a 1.0.3 this afternoon. :)

Quote
It would be great if someone could change this a bit and have it only show contacts of that persons buddy list, so that at some point the drop down doesn't become so long it's difficult to use. Hope that made sense. Or maybe there is another way to do it so that the drop down list of members would not become so long it would not longer be convenient.

It would also be nice if when you clicked on the members name in the drop down it immediately took you to the reply box before you even had to hit send.
Thank you for the suggestions, I totally agree. I think only showing the buddies would be great, I'll take a look at that. Second idea would just take a few seconds to implement, so I'll add that too. Thanks again for the suggestions. :)

any way to make a BLANK DEFAULT requiring someone click on the drop down menu to select a user?
Sure, thanks for the suggestion, will do that too. ;D

Works perfect.  Thank you!
You're welcome. :)

Heres the errors in case someone takes an interest one day. I sure would like it to work with out errors, works with them but I'm always nervousness when I have errors in admin.

/index.php?action=admin;area=portalblocks;sa=edit
2: fclose() expects parameter 1 to be resource, boolean given
File: Sources/Subs-PortalAdmin.php Line: 401

 
/index.php?action=admin;area=portalblocks;sa=edit
2: fwrite() expects parameter 1 to be resource, boolean given
File: Sources/Subs-PortalAdmin.php Line: 400
 

/index.php?action=admin;area=portalblocks;sa=edit
2: fopen(/home/cafeweco/public_html/sp_tmp_1349028364.php) [<a href='function.fopen'>function.fopen</a>]: failed to open stream: Permission denied
File: Sources/Subs-PortalAdmin.php Line: 399
Weird, the code is not using fwrite, fopen or fclose, so I'll point the team to this topic. Thanks for the report, though. :)
Title: Re: Quick PM v1.0.3
Post by: Kryzen on October 01, 2012, 09:53:34 AM
Version 1.0.3 released!
! Fixing wrong permission name (Thanks, Phantom!)
! Add default option (Thanks, Phantom!)
- Go to the send pm page automatically when you select a user

I couldn't find a way to show buddies only and I wanted to provide a patch as soon as possible, so I didn't include it in the 1.0.3 release. I'm still trying to find a way to show buddies only, though, but I'm afraid it could take some time.
Title: Re: Quick PM v1.0.3
Post by: phantomm on October 01, 2012, 12:06:38 PM
small suggestion, maybe you can use $txt instead of 'hardcoded' text?

I'm using this code:
Code: [Select]
/**
Quick PM modification by Dr. Deejay
Module originally created for Dream Portal
Ported to SimplePortal by Dr. Deejay
Version 1.0.3
Thanks to: SoLoGHoST, SlammedDime, Labradoodle-360, Ccbtimewiz, Phantomm, Miss all Sunday and DoctorMalboro     
*/
global $txt, $buttons, $scripturl, $smcFunc, $context;


/*Config*/
$txt['quick_pm_block_not_allowed'] = 'You are not allowed to access this block';
$txt['quick_pm_block_default_user'] = 'Select user';
$txt['quick_pm_block_send'] = 'Send';



$query = $smcFunc['db_query']('', '
SELECT real_name, id_member
FROM {db_prefix}members
WHERE is_activated={int:activated}
ORDER BY real_name ASC',
array(
'activated' => 1,
)
);

$context['fastpm']['members'] = array();

while ($row = $smcFunc['db_fetch_assoc']($query))
{
$context['fastpm']['members'][$row['id_member']] = $row['real_name'];
}

$smcFunc['db_free_result']($query);

// Wait.. We DO have permissions for it, or don't we?
if (!allowedTo('pm_send'))
{
echo '',$txt['quick_pm_block_not_allowed'],'';
return;
}

// Are we allowed to view the memberlist? If yes, begin with the select box
echo '
<form action="#" method="post">
<select name="u" onchange="if (this.value) window.location.href=this.value">
<option value="0" selected="selected" disabled="disabled">',$txt['quick_pm_block_default_user'],'</option>';

foreach ($context['fastpm']['members'] as $key => $value)
echo '
<option value="', $scripturl, '?action=profile;u=', $key, '">', $value, '</option>';

echo ' </select>
<input type="submit" value="',$txt['quick_pm_block_send'],'">
</form>';

// If we submitted the form, redirect to the messages section
if(isset($_POST['u']))
redirectexit('action=pm;sa=send;u=' . $_POST['u']);
Would be better for new users, if they can translate strings in one place than searching it inside PHP code :)
Title: Re: Quick PM v1.0.3
Post by: Kryzen on October 01, 2012, 12:10:51 PM
Thanks for the suggestion. :) Would you mind me using your code for a 1.0.4 release?
Title: Re: Quick PM v1.0.3
Post by: phantomm on October 01, 2012, 12:12:36 PM
yeah, you can use it :)
Title: Re: Quick PM v1.0.3
Post by: Kryzen on October 01, 2012, 12:13:36 PM
Thank you, I'll release a 1.0.4 release within a few minutes. ;D
Title: Re: Quick PM v1.0.4
Post by: Kryzen on October 01, 2012, 12:16:05 PM
1.0.4 released!
! Use $txt strings rather than hardcoded text (Thanks, Phantomm :))
Title: Re: Quick PM v1.0.4
Post by: FrizzleFried on October 02, 2012, 02:12:19 AM
Strange behavior from 1.0.4...

When I select a persons name,  it automatically takes me to their profile... not allowing me to hit send to take me to a PM?

Title: Re: Quick PM v1.0.4
Post by: phantomm on October 02, 2012, 02:57:38 AM
In block code:
Code: (Find) [Select]
<option value="', $scripturl, '?action=profile;u=', $key, '">', $value, '</option>';
Code: (Replace with) [Select]
<option value="', $scripturl, '?action=pm;sa=send;u=', $key, '">', $value, '</option>';
 :)

But then you don't need 'Send' button :)
Title: Re: Quick PM v1.0.2
Post by: boo2 on October 02, 2012, 02:07:42 PM
Heres the errors in case someone takes an interest one day. I sure would like it to work with out errors, works with them but I'm always nervousness when I have errors in admin.

/index.php?action=admin;area=portalblocks;sa=edit
2: fclose() expects parameter 1 to be resource, boolean given
File: Sources/Subs-PortalAdmin.php Line: 401

 
/index.php?action=admin;area=portalblocks;sa=edit
2: fwrite() expects parameter 1 to be resource, boolean given
File: Sources/Subs-PortalAdmin.php Line: 400
 

/index.php?action=admin;area=portalblocks;sa=edit
2: fopen(public_html/sp_tmp_1349028364.php) [<a href='function.fopen'>function.fopen</a>]: failed to open stream: Permission denied
File: Sources/Subs-PortalAdmin.php Line: 399
Weird, the code is not using fwrite, fopen or fclose, so I'll point the team to this topic. Thanks for the report, though. :)


I have no idea how to track a error like this. The only other block might be recent posts with preview. Thanks, hope the team can give me some clue as to where to look and what to look for.

Thanks for fixing the pm mod, I love this mod. Now it works perfect, goes right to the reply box with out the go button. Yippee! I'm keeping this for admin and mods, hopefully you'll create one for buddies one day..
Title: Re: Quick PM v1.0.4
Post by: FrizzleFried on October 02, 2012, 05:57:25 PM
In block code:
Code: (Find) [Select]
<option value="', $scripturl, '?action=profile;u=', $key, '">', $value, '</option>';
Code: (Replace with) [Select]
<option value="', $scripturl, '?action=pm;sa=send;u=', $key, '">', $value, '</option>';
 :)

But then you don't need 'Send' button :)

Works awesome... and send button removed.
Title: Re: Quick PM v1.0.4
Post by: AngelinaBelle on October 02, 2012, 06:16:41 PM
boo2 -- In Subs-PortalAdmin.php, function sp_validate_php does open a file, write the code to be validated to the file, and then checks for the file. Those 3 error lines indicate that the function was unable to write to or close a file because the file was never opened. The third one says it was unable to open the file for writing.  This may be because of a permission problem, or for some other reason.
Title: Re: Quick PM v1.0.4.1
Post by: Kryzen on October 03, 2012, 05:46:25 AM
I'm sorry, I must have been asleep when adding the url. :( It has been fixed now, thanks for the patch Phantomm. :).

In Subs-PortalAdmin.php, function sp_validate_php does open a file, write the code to be validated to the file, and then checks for the file.
Ah good to know, thanks for jumping in. :)
Title: Re: Quick PM v1.0.4
Post by: boo2 on October 03, 2012, 01:19:05 PM
boo2 -- In Subs-PortalAdmin.php, function sp_validate_php does open a file, write the code to be validated to the file, and then checks for the file. Those 3 error lines indicate that the function was unable to write to or close a file because the file was never opened. The third one says it was unable to open the file for writing.  This may be because of a permission problem, or for some other reason.

That went right over my head. lol Anyway which permissions, the one in the forums or the permissions on the server that I have to set and reset ever time I install with package manager?
Title: Re: Quick PM v1.0.4.1
Post by: Mu-So on September 16, 2013, 12:52:31 PM
nice, thx
Title: Re: Quick PM v1.0.4.1
Post by: AngelinaBelle on October 14, 2013, 04:39:37 PM
boo2 -- the permissions on the server.  Just like you need permission set permissively enough to create files during mod installation, you need them set permissively enough to permit creating files when you use this feature.