Mysidia Adoptables Support Forum

Mysidia Adoptables Support Forum (http://www.mysidiaadoptables.com/forum/index.php)
-   Questions and Supports (http://www.mysidiaadoptables.com/forum/forumdisplay.php?f=18)
-   -   Is this possible? (http://www.mysidiaadoptables.com/forum/showthread.php?t=4949)

Kyttias 12-22-2015 03:37 AM

Is this possible?
 
When replying to a user's PM, I'd like to place a copy of the title and text from the original message into the new PM.

In view/messagesview.php it already detects if you're replying to a user (rather than making a new PM) by use of this:
PHP Code:

if($mysidia->input->get("id")) $user $mysidia->input->get("id"); 

I was able to take that a step further, made it this:
PHP Code:

if($mysidia->input->get("id")) {
    
$user $mysidia->input->get("id");
    
$re "RE: ";


And a few lines down, I modified the where the title appears to include "RE: " before the title if new the recipient as such.
PHP Code:

$pmForm->add(new TextField("mtitle"$re."(no subject)"50)); 

Okay, cool. That works - "RE: " only appears while I'm replying, because it knows the recipient when the page loads.

But that's also not a copy of the title I'm replying to, either, it's just a placeholder title (I added it in so people wouldn't get errors while attempting to send messages with no subject lines).

So... if $user equals a 'get' value of id, is that because that's how the url is being rewritten? Where's that the rewrite happening (because its not part of the htaccess)? If values containing the original message (and title) are already being sent, what're they called? Do I need to explicitly send these values, if they're not already being sent? (Because I don't mind jabbing at the message on the page with some javascript and attaching it to the url the reply button goes to if I have to. But do I have to?)



EDIT - Discussed this on aim with HoF. The solution was to send the message's actual id (not the username) and use the PrivateMessage object to pull data from the id that had the user name, title, and message contents.

In view/messagesview.php, inside the newpm() function, I changed the contents of the if statement mentioned above to now contain the data I asked for (EDIT 2 - this has been updated to reflect issues discussed later in the thread):
PHP Code:

$message = new PrivateMessage
// CHANGES START HERE

$title "(no subject)"// this way it'll never be blank
if($mysidia->input->get("id")){ // if there's an get value
    
$where trim($mysidia->input->get("id")); // trim the value
     
if (!ctype_digit($where)) { // if its not numeric only
        
$user $where// create a message to this user
    
} else if (ctype_digit($where)){ // if it IS numeric only then it's a reply, so pull data        
        
$oldMessage = new PrivateMessage($where); 
        
$js "<script>$('.content h2').text('Reply To Message');</script>"// optional
        
$user $oldMessage->fromuser;            
        
$title "RE: ".$oldMessage->messagetitle;    
        
$msg "› {$user} wrote: ".$oldMessage->messagetext;
    }
}

// CHANGES END HERE
$editor $message->getEditor(); 

Try styling $msg up a bit, if you like, but test that it sends properly. It took me some effort to get this to look nice. I don't actually use the CKEditor so I don't know if adding in raw html will help you. (It helped me.)

Change appropriate $pmForm lines as needed. Mine's different, but this is the jist of the two lines changed:
PHP Code:

/* title line: */
$pmForm->add(new TextField("mtitle"$title50)); 
/* editor line: */
$pmForm->add(new Comment($editor->editor("mtext"$msg))); 

But I need to send that data, so in classes/class_privatemessage.php, in the getMessage() function, change
PHP Code:

<a href='../../messages/newpm/{$this->fromuser}'

to
PHP Code:

<a href='../../messages/newpm/{$this->mid}'

And that'll pretty much do it. I did some other things, of course, but in case anyone's wondering for future reference.

Hall of Famer 12-22-2015 05:42 AM

Well it is possible, I had the idea before that there would be a quoted text, but couldnt get the formatting done properly. Since Mysidia uses CKEditor now, there may be a solution to this, and I will see what I can do about it.

Kyttias 12-22-2015 07:21 AM

Thanks for helping me on aim. :meow: I editted the first post to try and explain the solution.

Hall of Famer 12-22-2015 05:04 PM

I see, glad you figured it out. Maybe you can post this as a mod or tutoriual, so it will be easier for other users to find. Best of luck. ^^

tahbikat 12-22-2015 05:18 PM

Oohh I was actually wondering about this. Awesome, thanks for sharing Kyttias!

Abronsyth 12-22-2015 10:24 PM

I did encounter an error with this when trying to send a user a PM through their profile (going to user profile and clicking "send user a PM" link), as it tries to create a PM by inserting their username into it, which I believe no longer works since this makes it so PMs are not ID'd but the username?

Not sure, super tired so I'll look into it more tomorrow but I wanted to give y'all a heads-up in case you've not tested it (though I'm aware that link may no longer exist on your site).

Kyttias 12-22-2015 11:35 PM

Oh, good point Abronsyth. Links will have to be changed there, too! (Though, yeah, I've removed the link from my user's profiles, I should really add it back in...)

I think that's in classes/class_userprofile.php currently, inside the contactinfo() function. The line begins with this:
PHP Code:

 $document->add(new Link("messages/newpm/{$mysidia->input->get("user")}"

........HMMMMmmmm. Well removing the username entirely will at least remove the error, but then the newpm page won't know/remember who it should be sending something to - the entire point of having a link on the page.

Maybe... if the value is not numerical, set the recipient to whatever the value is? (edit: I've tried a lot of things, included is_numeric(), is_int(), and even going so far as !ctype_alpha() but... I seem to maybe be doing something extremely basic wrong??? I can't get this to work.)

Thoughts, HoF?

Distortion 12-23-2015 01:33 AM

replace line 178 with:
PHP Code:

 $document->add(new Link("messages/newpm/{$member->uid}""Send {$mysidia->input->get("user")} a Private Message"TRUE)); 

Basically just changing {$mysidia->input->get("user")} to {$member->uid}

Kyttias 12-23-2015 01:43 AM

Well, no... the id the file is looking for is the message id of an message being sent as a reply, not a user id.

By default the url is:
.../messages/newpm
And originally the reply button linked to a page with a url like this:
.../messages/newpm/Kyttias
(A new message is created going to Kyttias, but no information about the old message itself is being sent.)

Now, we have it sending the message id number instead so we can extract the message title and text:
.../messages/newpm/25
(A reply is sent to the sender of message id #25. The message and title of message id #25 are being used to pre-fill reply information.)

The profile link still wants to create a new pm to a particular user, so it still tries to sends you here:
.../messages/newpm/Kyttias
(But this won't work with the modifications we've made, even though it's how it worked previously. If there's a 'get' value (the last end of the url) at all, it's now automatically assuming it's the message id #. The file is trying to figure out what to do with a message id #Kyttias. It's looking for a message id #, not a username, and definitely not a user id. It screams and cries and throws and error.)

I'm hoping for a way to detect whether the value is numerical only (it's definitely receiving a message id #, so go through with the new modifications) or not (it's receiving a username instead, so set the message up how it was before the mod). But everything I've tried so far has come up not working.
.
.
.

Or, and this could get messy fast, with the reply button url we could add the substring "reply_" before the message id, and on the user profile we could add the substring "user_". We could preg_match to check which substring is prefixed to the get value, and decide what to do based on if that substring exists... but then we also have to then remove that substring we attached before we can continue on. So... messy, but doable. There's got to be a better way, right?

Kyttias 12-23-2015 10:50 AM

Got it: It wasn't checking if it was a numeric value or not until I applied trim() to it to remove whitespace/linebreaks. I had no idea there were even there until I decided to echo the value to see what was going on.

Inside view/messagesview.php, my newpm() function now looks like this:
PHP Code:

$message = new PrivateMessage
// CHANGES START HERE

$title "(no subject)"// this way it'll never be blank
if($mysidia->input->get("id")){ // if there's an get value
    
$where trim($mysidia->input->get("id")); // trim the value
     
if (!ctype_digit($where)) { // if its not numeric only
        
$user $where// create a message to this user
    
} else if (ctype_digit($where)){ // if it IS numeric only then it's a reply, so pull data        
        
$oldMessage = new PrivateMessage($where); 
        
$js "<script>$('.content h2').text('Reply To Message');</script>"// optional
        
$user $oldMessage->fromuser;            
        
$title "RE: ".$oldMessage->messagetitle;    
        
$msg "› {$user} wrote: ".$oldMessage->messagetext;
    }
}

// CHANGES END HERE
$editor $message->getEditor(); 

Added in some optional javascript in the $js variable that should work if you have jQuery included. It'll change the title of the page to indicate it's a reply page, rather than continue to say its a new message page (assuming you're still using the h2 size for page titles, else change it).

Let me clarify that you should leave the url that sends a PM to a user alone in classes/class_userprofile.php. Keep it as it was - sending a username. Do NOT change it to send a user id.


All times are GMT -5. The time now is 09:59 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.