source: branches/1.2/content/plugins/users/libs/UserFunctions.php @ 1354

Revision 1354, 7.2 KB checked in by nick_ramsay, 3 years ago (diff)

[Branch 1.2] Custom iconv function, plus more SMTP email fixes

Line 
1<?php
2/**
3 * The UserFunctions class contains some more useful methods for working with users
4 *
5 * PHP version 5
6 *
7 * LICENSE: Hotaru CMS is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation, either version 3 of
10 * the License, or (at your option) any later version.
11 *
12 * Hotaru CMS is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with Hotaru CMS. If not, see http://www.gnu.org/licenses/.
18 *
19 * @category  Content Management System
20 * @package   HotaruCMS
21 * @author    Nick Ramsay <admin@hotarucms.org>
22 * @copyright Copyright (c) 2009, Hotaru CMS
23 * @license   http://www.gnu.org/copyleft/gpl.html GNU General Public License
24 * @link      http://www.hotarucms.org/
25 */
26   
27class UserFunctions
28{   
29    /**
30     * Send an email to admins/supermods chosen to receive emails about new user signups
31     *
32     * @param string $type - notification type, e.g. 'post', 'user', 'comment'
33     * @param string $status - role or status new user, post or comment
34     * @param string $id - post or user id
35     * @param string $commentid - comment id
36     */
37    public function notifyMods($h, $type, $status, $id = 0, $commentid = 0)
38    {
39        $h->includeLanguage('users'); // in some cases, we don't already have the language file so need to include it.
40
41        $line_break = "\r\n\r\n";
42        $next_line = "\r\n";
43       
44        $user = new UserBase();
45       
46        switch ($type) {
47            case 'user':
48                $user->getUserBasic($h, $id);
49                $user_signin_settings = $h->getSerializedSettings('user_signin');
50                $email_mods = $user_signin_settings['email_notify_mods'];
51                $subject = $h->lang['userfunctions_notifymods_subject_user'];
52                $about = $h->lang['userfunctions_notifymods_body_about_user'];
53                break;
54            case 'post':
55                $user->getUserBasic($h, $h->post->author);
56                $submit_settings = $h->getSerializedSettings('submit');
57                $email_mods = $submit_settings['email_notify_mods'];
58                $subject = $h->lang['userfunctions_notifymods_subject_post'];
59                $about = $h->lang['userfunctions_notifymods_body_about_post'];
60                $h->readPost($id); // If you're having problems, the caching used in an earlier readPost might be the cause
61                // emails were still saying new posts were "pending" and sending notification, so let's forcefully get the status:
62                $sql = "SELECT post_status FROM " . TABLE_POSTS . " WHERE post_id = %d";
63                $status = $h->db->get_var($h->db->prepare($sql, $id));
64                $h->post->status = $status;
65                break;
66            case 'comment':
67                $user->getUserBasic($h, $h->comment->author);
68                $comments_settings = $h->getSerializedSettings('comments');
69                $email_mods = $comments_settings['comment_email_notify_mods'];
70                $subject = $h->lang['userfunctions_notifymods_subject_comment'];
71                $about = $h->lang['userfunctions_notifymods_body_about_comment'];
72                $h->readPost($id); // If you're having problems, the caching used in an earlier readPost might be the cause
73                $comment_array = $h->getComment($commentid);
74                $comment = $h->readComment($comment_array);
75                break;
76            default:
77        }
78       
79        // send email
80
81        foreach ($email_mods as $mod)
82        {
83            if ($mod['type'] == 'none') { continue; } // skip rest of this iteration
84            if (($mod['type'] == 'pending') && ($status != 'pending')) { continue; } // skip rest of this iteration
85               
86            $body = $h->lang['userfunctions_notifymods_hello'] . $h->getUserNameFromId($mod['id']);
87            $body .= $line_break;
88            $body .= $about;
89           
90            if ($type == 'post') {
91                $body .= $line_break;
92                $body .= $h->lang['userfunctions_notifymods_body_post_status'] . $h->post->status . $next_line;
93                $body .= $h->lang['userfunctions_notifymods_body_post_title'] . stripslashes(html_entity_decode(urldecode($h->post->title), ENT_QUOTES,'UTF-8')) . $next_line;
94                $body .= $h->lang['userfunctions_notifymods_body_post_content'] . stripslashes(html_entity_decode(urldecode($h->post->content), ENT_QUOTES,'UTF-8')) . $next_line;
95                $body .= $h->lang['userfunctions_notifymods_body_post_page'] . $h->url(array('page'=>$h->post->id)) . $next_line; // edit post page
96                $body .= $h->lang['userfunctions_notifymods_body_post_orig'] . $h->post->origUrl . $next_line; // edit post page
97                $body .= $h->lang['userfunctions_notifymods_body_post_edit'] . BASEURL . "index.php?page=edit_post&post_id=" . $id . $next_line; // edit post page
98                $body .= $h->lang['userfunctions_notifymods_body_post_management'] . BASEURL . "admin_index.php?post_status_filter=" . $h->post->status . "&plugin=post_manager&page=plugin_settings&type=filter";
99           
100            }
101           
102            if ($type == 'comment') {
103                $body .= $line_break;
104                $body .= $h->lang['userfunctions_notifymods_body_post_title'] . stripslashes(html_entity_decode(urldecode($h->post->title), ENT_QUOTES,'UTF-8')) . $next_line;
105                $body .= $h->lang['userfunctions_notifymods_body_comment_status'] . $comment->status . $next_line;
106                $body .= $h->lang['userfunctions_notifymods_body_comment_content'] . stripslashes(html_entity_decode(urldecode($h->comment->content), ENT_QUOTES,'UTF-8')) . $next_line;
107                $body .= $h->lang['userfunctions_notifymods_body_post_page'] . $h->url(array('page'=>$h->post->id)) . $next_line; // edit post page
108                $body .= $h->lang['userfunctions_notifymods_body_comment_management'] . BASEURL . "admin_index.php?comment_status_filter=" . $comment->status . "&plugin=comment_manager&page=plugin_settings&type=filter";
109           
110            }
111           
112            $body .= $line_break;
113            $body .= $h->lang['userfunctions_notifymods_body_user_name'] . $user->name . $next_line;
114            $body .= $h->lang['userfunctions_notifymods_body_user_role'] . $user->role . $next_line;
115            $body .= $h->lang['userfunctions_notifymods_body_user_email'] . $user->email . $next_line;
116            $body .= $h->lang['userfunctions_notifymods_body_user_account'] . BASEURL . "index.php?page=account&user=" . $user->name . $next_line;
117            $body .= $h->lang['userfunctions_notifymods_body_user_management'] . BASEURL . "admin_index.php?search_value=" . $user->name . "&plugin=user_manager&page=plugin_settings&type=search";
118           
119            $body .= $line_break;
120            $body .= $h->lang['userfunctions_notifymods_body_regards'];
121            $body .= $next_line;
122            $body .= $h->lang['userfunctions_notifymods_body_sign'];
123            $to = $mod['email'];
124           
125            $h->email($to, $subject, $body);
126        }
127       
128        return true;
129    }
130   
131}
132
133?>
Note: See TracBrowser for help on using the repository browser.