1: | <?php
|
2: | |
3: | |
4: | |
5: | |
6: | |
7: | |
8: | |
9: | |
10: | |
11: | |
12: | |
13: | |
14: | |
15: | |
16: | |
17: | |
18: |
|
19: |
|
20: | |
21: | |
22: | |
23: | |
24: | |
25: | |
26: | |
27: |
|
28: | class PmMessage extends XoopsObject
|
29: | {
|
30: |
|
31: | public $msg_id;
|
32: | public $msg_image;
|
33: | public $subject;
|
34: | public $from_userid;
|
35: | public $to_userid;
|
36: | public $msg_time;
|
37: | public $msg_text;
|
38: | public $read_msg;
|
39: | public $from_delete;
|
40: | public $to_delete;
|
41: | public $from_save;
|
42: | public $to_save;
|
43: |
|
44: | |
45: | |
46: |
|
47: | public function __construct()
|
48: | {
|
49: | parent::__construct();
|
50: | $this->initVar('msg_id', XOBJ_DTYPE_INT, null, false);
|
51: | $this->initVar('msg_image', XOBJ_DTYPE_OTHER, 'icon1.gif', false, 100);
|
52: | $this->initVar('subject', XOBJ_DTYPE_TXTBOX, null, true, 255);
|
53: | $this->initVar('from_userid', XOBJ_DTYPE_INT, null, true);
|
54: | $this->initVar('to_userid', XOBJ_DTYPE_INT, null, true);
|
55: | $this->initVar('msg_time', XOBJ_DTYPE_INT, time(), false);
|
56: | $this->initVar('msg_text', XOBJ_DTYPE_TXTAREA, null, true);
|
57: | $this->initVar('read_msg', XOBJ_DTYPE_INT, 0, false);
|
58: | $this->initVar('from_delete', XOBJ_DTYPE_INT, 1, false);
|
59: | $this->initVar('to_delete', XOBJ_DTYPE_INT, 0, false);
|
60: | $this->initVar('from_save', XOBJ_DTYPE_INT, 0, false);
|
61: | $this->initVar('to_save', XOBJ_DTYPE_INT, 0, false);
|
62: | }
|
63: | }
|
64: |
|
65: | |
66: | |
67: |
|
68: | class PmMessageHandler extends XoopsPersistableObjectHandler
|
69: | {
|
70: | |
71: | |
72: |
|
73: | public function __construct(XoopsDatabase $db)
|
74: | {
|
75: | parent::__construct($db, 'priv_msgs', 'PmMessage', 'msg_id', 'subject');
|
76: | }
|
77: |
|
78: | |
79: | |
80: | |
81: | |
82: | |
83: | |
84: | |
85: |
|
86: | public function setRead(PmMessage $pm, $val = 1)
|
87: | {
|
88: | return $this->updateAll('read_msg', (int)$val, new Criteria('msg_id', $pm->getVar('msg_id')), true);
|
89: | }
|
90: |
|
91: | |
92: | |
93: | |
94: | |
95: | |
96: |
|
97: | public function setFromdelete(PmMessage $pm, $val = 1)
|
98: | {
|
99: | if ($pm->getVar('to_delete') == 0) {
|
100: | return $this->updateAll('from_delete', (int)$val, new Criteria('msg_id', $pm->getVar('msg_id')));
|
101: | } else {
|
102: | return parent::delete($pm);
|
103: | }
|
104: | }
|
105: |
|
106: | |
107: | |
108: | |
109: | |
110: | |
111: |
|
112: | public function setTodelete(PmMessage $pm, $val = 1)
|
113: | {
|
114: | $val = (int)$val;
|
115: | if ($pm->getVar('from_delete') == 0 || $pm->getVar('from_userid') == 0) {
|
116: | $pm->setVar('to_delete', $val);
|
117: | if ($val) {
|
118: | $pm->setVar('read_msg', 1);
|
119: | }
|
120: | return $this->insert($pm);
|
121: | } else {
|
122: | return parent::delete($pm);
|
123: | }
|
124: | }
|
125: |
|
126: | |
127: | |
128: | |
129: | |
130: | |
131: |
|
132: | public function setFromsave(PmMessage $pm, $val = 1)
|
133: | {
|
134: | return $this->updateAll('from_save', (int)$val, new Criteria('msg_id', $pm->getVar('msg_id')));
|
135: | }
|
136: |
|
137: | |
138: | |
139: | |
140: | |
141: | |
142: |
|
143: | public function setTosave(PmMessage $pm, $val = 1)
|
144: | {
|
145: | return $this->updateAll('to_save', (int)$val, new Criteria('msg_id', $pm->getVar('msg_id')));
|
146: | }
|
147: |
|
148: | |
149: | |
150: | |
151: | |
152: |
|
153: | public function getSavecount(XoopsUser $user = null)
|
154: | {
|
155: | if (!is_object($user)) {
|
156: | $user =& $GLOBALS['xoopsUser'];
|
157: | }
|
158: | $crit_to = new CriteriaCompo(new Criteria('to_delete', 0));
|
159: | $crit_to->add(new Criteria('to_save', 1));
|
160: | $crit_to->add(new Criteria('to_userid', $user->getVar('uid')));
|
161: | $crit_from = new CriteriaCompo(new Criteria('from_delete', 0));
|
162: | $crit_from->add(new Criteria('from_save', 1));
|
163: | $crit_from->add(new Criteria('from_userid', $user->getVar('uid')));
|
164: | $criteria = new CriteriaCompo($crit_to);
|
165: | $criteria->add($crit_from, 'OR');
|
166: |
|
167: | return $this->getCount($criteria);
|
168: | }
|
169: |
|
170: | |
171: | |
172: | |
173: | |
174: | |
175: |
|
176: | public function sendEmail(PmMessage $pm, XoopsUser $user)
|
177: | {
|
178: | global $xoopsConfig;
|
179: |
|
180: | if (!is_object($user)) {
|
181: | $user =& $GLOBALS['xoopsUser'];
|
182: | }
|
183: | $msg = sprintf(_PM_EMAIL_DESC, $user->getVar('uname'));
|
184: | $msg .= "\n\n";
|
185: | $msg .= formatTimestamp($pm->getVar('msg_time'));
|
186: | $msg .= "\n";
|
187: | $from = new XoopsUser($pm->getVar('from_userid'));
|
188: | $to = new XoopsUser($pm->getVar('to_userid'));
|
189: | $msg .= sprintf(_PM_EMAIL_FROM, $from->getVar('uname') . ' (' . XOOPS_URL . '/userinfo.php?uid=' . $pm->getVar('from_userid') . ')');
|
190: | $msg .= "\n";
|
191: | $msg .= sprintf(_PM_EMAIL_TO, $to->getVar('uname') . ' (' . XOOPS_URL . '/userinfo.php?uid=' . $pm->getVar('to_userid') . ')');
|
192: | $msg .= "\n";
|
193: | $msg .= _PM_EMAIL_MESSAGE . ":\n";
|
194: | $msg .= "\n" . $pm->getVar('subject') . "\n";
|
195: | $msg .= "\n" . strip_tags(str_replace(array('<p>', '</p>', '<br>', '<br>'), "\n", $pm->getVar('msg_text'))) . "\n\n";
|
196: | $msg .= "--------------\n";
|
197: | $msg .= $xoopsConfig['sitename'] . ': ' . XOOPS_URL . "\n";
|
198: |
|
199: | $xoopsMailer = xoops_getMailer();
|
200: | $xoopsMailer->useMail();
|
201: | $xoopsMailer->setToEmails($user->getVar('email'));
|
202: | $xoopsMailer->setFromEmail($xoopsConfig['adminmail']);
|
203: | $xoopsMailer->setFromName($xoopsConfig['sitename']);
|
204: | $xoopsMailer->setSubject(sprintf(_PM_EMAIL_SUBJECT, $pm->getVar('subject')));
|
205: | $xoopsMailer->setBody($msg);
|
206: |
|
207: | return $xoopsMailer->send();
|
208: | }
|
209: |
|
210: | |
211: | |
212: | |
213: | |
214: |
|
215: | public function getPruneForm()
|
216: | {
|
217: | include_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
|
218: | $form = new XoopsThemeForm(_PM_AM_PRUNE, 'form', 'prune.php', 'post', true);
|
219: |
|
220: | $form->addElement(new XoopsFormDateTime(_PM_AM_PRUNEAFTER, 'after'));
|
221: | $form->addElement(new XoopsFormDateTime(_PM_AM_PRUNEBEFORE, 'before'));
|
222: | $form->addElement(new XoopsFormRadioYN(_PM_AM_ONLYREADMESSAGES, 'onlyread', 1));
|
223: | $form->addElement(new XoopsFormRadioYN(_PM_AM_INCLUDESAVE, 'includesave', 0));
|
224: | $form->addElement(new XoopsFormRadioYN(_PM_AM_NOTIFYUSERS, 'notifyusers', 0));
|
225: |
|
226: | $form->addElement(new XoopsFormHidden('op', 'prune'));
|
227: | $form->addElement(new XoopsFormButton('', 'submit', _SUBMIT, 'submit'));
|
228: |
|
229: | return $form;
|
230: | }
|
231: | }
|
232: | |