| 1: | <?php |
| 2: | |
| 3: | |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 9: | |
| 10: | |
| 11: | |
| 12: | class Hm_Handler_history_record_feed_message extends Hm_Handler_Module { |
| 13: | public function process() { |
| 14: | $headers = $this->get('feed_message_headers', array()); |
| 15: | if (count($headers) == 0) { |
| 16: | return; |
| 17: | } |
| 18: | $history = $this->session->get('msg_history', array()); |
| 19: | $url = sprintf('?page=message&uid=%s&list_path=%s', $this->request->post['feed_uid'], |
| 20: | $this->request->post['feed_list_path']); |
| 21: | if (array_key_exists($url, $history)) { |
| 22: | return; |
| 23: | } |
| 24: | $path = explode('_', $this->request->post['feed_list_path']); |
| 25: | $feed_data = Hm_Feed_List::dump($path[1]); |
| 26: | $id = sprintf('feeds_%s_%s', $path[1], $this->request->post['feed_uid']); |
| 27: | $from = ''; |
| 28: | foreach (array('author', 'cd:creator', 'name') as $v) { |
| 29: | if (array_key_exists($v, $headers)) { |
| 30: | $from = $headers[$v]; |
| 31: | break; |
| 32: | } |
| 33: | } |
| 34: | $date = ''; |
| 35: | foreach (array('pubdate', 'dc:date') as $v) { |
| 36: | if (array_key_exists($v, $headers)) { |
| 37: | $date = $headers[$v]; |
| 38: | break; |
| 39: | } |
| 40: | } |
| 41: | $history[$url] = array( |
| 42: | 'source' => $feed_data['name'], |
| 43: | 'subject' => $headers['title'], |
| 44: | 'id' => $id, |
| 45: | 'from' => $from, |
| 46: | 'date' => $date, |
| 47: | 'type' => 'feed' |
| 48: | ); |
| 49: | $this->session->set('msg_history', $history); |
| 50: | } |
| 51: | } |
| 52: | |
| 53: | |
| 54: | |
| 55: | |
| 56: | class Hm_Github_Output_Module extends Hm_Output_Module { protected function output() { return ''; } } |
| 57: | |
| 58: | |
| 59: | |
| 60: | |
| 61: | class Hm_Handler_history_record_github_message extends Hm_Handler_Module { |
| 62: | public function process() { |
| 63: | $data = $this->get('github_event_detail', array()); |
| 64: | if (count($data) == 0) { |
| 65: | return; |
| 66: | } |
| 67: | $url = sprintf('?page=message&uid=%s&list_path=%s', $this->request->post['github_uid'], |
| 68: | $this->request->post['list_path']); |
| 69: | $history = $this->session->get('msg_history', array()); |
| 70: | if (array_key_exists($url, $history)) { |
| 71: | return; |
| 72: | } |
| 73: | $stub = new Hm_Github_Output_Module(array(), array()); |
| 74: | $subject = build_github_subject($data, $stub); |
| 75: | $date = ''; |
| 76: | $id = sprintf('github_%s', $this->request->post['github_uid']); |
| 77: | if (array_key_exists('created_at', $data)) { |
| 78: | $date = date('r', strtotime($data['created_at'])); |
| 79: | } |
| 80: | $from = ''; |
| 81: | if (array_key_exists('actor', $data) && array_key_exists('login', $data['actor'])) { |
| 82: | $from = $data['actor']['login']; |
| 83: | } |
| 84: | $history[$url] = array( |
| 85: | 'source' => mb_substr($this->request->post['list_path'], 7), |
| 86: | 'subject' => $subject, |
| 87: | 'date' => $date, |
| 88: | 'id' => $id, |
| 89: | 'from' => $from, |
| 90: | 'type' => 'github' |
| 91: | ); |
| 92: | $this->session->set('msg_history', $history); |
| 93: | } |
| 94: | } |
| 95: | |
| 96: | |
| 97: | |
| 98: | |
| 99: | class Hm_Handler_history_record_wp_message extends Hm_Handler_Module { |
| 100: | public function process() { |
| 101: | $data = $this->get('wp_notice_details'); |
| 102: | if (count($data) == 0) { |
| 103: | return; |
| 104: | } |
| 105: | $url = sprintf('?page=message&list_path=wp_notifications&uid=%s', $this->request->post['wp_uid']); |
| 106: | $history = $this->session->get('msg_history', array()); |
| 107: | $id = sprintf('wp_%s', $this->request->post['wp_uid']); |
| 108: | if (array_key_exists($url, $history)) { |
| 109: | return; |
| 110: | } |
| 111: | $history[$url] = array( |
| 112: | 'source' => 'WordPress.com', |
| 113: | 'date' => date('r', $data['notes'][0]['timestamp']), |
| 114: | 'subject' => $data['notes'][0]['subject']['text'], |
| 115: | 'id' => $id, |
| 116: | 'from' => '', |
| 117: | 'type' => 'wordpress', |
| 118: | ); |
| 119: | $this->session->set('msg_history', $history); |
| 120: | } |
| 121: | } |
| 122: | |
| 123: | |
| 124: | |
| 125: | |
| 126: | class Hm_Handler_history_record_imap_message extends Hm_Handler_Module { |
| 127: | public function process() { |
| 128: | $headers = lc_headers($this->get('msg_headers', array())); |
| 129: | if (count($headers) == 0) { |
| 130: | return; |
| 131: | } |
| 132: | if (array_key_exists('imap_prefetch', $this->request->post) && $this->request->post['imap_prefetch']) { |
| 133: | return; |
| 134: | } |
| 135: | $history = $this->session->get('msg_history', array()); |
| 136: | $list_path = sprintf('imap_%s_%s', $this->request->post['imap_server_id'], $this->request->post['folder']); |
| 137: | $url = sprintf('?page=message&uid=%s&list_path=%s', $this->request->post['imap_msg_uid'], $list_path); |
| 138: | $id = sprintf('imap_%s_%s_%s', $this->request->post['imap_server_id'], |
| 139: | $this->request->post['imap_msg_uid'], $this->request->post['folder']); |
| 140: | if (array_key_exists($url, $history)) { |
| 141: | return; |
| 142: | } |
| 143: | $date = ''; |
| 144: | if (array_key_exists('date', $headers) && $headers['date']) { |
| 145: | $date = $headers['date']; |
| 146: | } |
| 147: | $subject = ''; |
| 148: | if (array_key_exists('subject', $headers) && $headers['subject']) { |
| 149: | $subject = $headers['subject']; |
| 150: | } |
| 151: | $from = ''; |
| 152: | if (array_key_exists('from', $headers) && $headers['from']) { |
| 153: | $from = format_imap_from_fld($headers['from']); |
| 154: | } |
| 155: | |
| 156: | $history[$url] = array( |
| 157: | 'source' => Hm_IMAP_List::dump($this->request->post['imap_server_id'])['name'], |
| 158: | 'subject' => $subject, |
| 159: | 'id' => $id, |
| 160: | 'from' => $from, |
| 161: | 'date' => $date, |
| 162: | 'type' => 'imap' |
| 163: | ); |
| 164: | $this->session->set('msg_history', $history); |
| 165: | } |
| 166: | } |
| 167: | |
| 168: | |
| 169: | |
| 170: | |
| 171: | class Hm_Handler_load_message_history extends Hm_Handler_Module { |
| 172: | public function process() { |
| 173: | $this->out('msg_history', $this->session->get('msg_history', array())); |
| 174: | } |
| 175: | } |
| 176: | |
| 177: | |
| 178: | |
| 179: | |
| 180: | class Hm_Output_history_page_link extends Hm_Output_Module { |
| 181: | protected function output() { |
| 182: | $res = '<li class="menu_history"><a class="unread_link" href="?page=history">'; |
| 183: | if (!$this->get('hide_folder_icons')) { |
| 184: | $res .= '<i class="bi bi-clock-history menu-icon"></i>'; |
| 185: | } |
| 186: | $res .= '<span class="nav-label">'.$this->trans('History').'</span></a></li>'; |
| 187: | if ($this->format == 'HTML5') { |
| 188: | return $res; |
| 189: | } |
| 190: | $this->concat('formatted_folder_list', $res); |
| 191: | } |
| 192: | } |
| 193: | |
| 194: | |
| 195: | |
| 196: | |
| 197: | class Hm_Output_history_heading extends Hm_Output_Module { |
| 198: | protected function output() { |
| 199: | $res = '<div class="content_title">'.$this->trans('Message history').'</div>'. |
| 200: | '<div class="history_content"><table class="message_table">'; |
| 201: | if (!$this->get('is_mobile')) { |
| 202: | $res .= '<colgroup><col class="source_col"><col class="from_col"><col '. |
| 203: | 'class="subject_col"><col class="date_col"></colgroup><thead></thead>'; |
| 204: | } |
| 205: | $res .= '<tbody>'; |
| 206: | return $res; |
| 207: | } |
| 208: | } |
| 209: | |
| 210: | |
| 211: | |
| 212: | |
| 213: | class Hm_Output_history_content extends Hm_Output_Module { |
| 214: | protected function output() { |
| 215: | $style = $this->get('news_list_style') ? 'news' : 'email'; |
| 216: | if ($this->get('is_mobile')) { |
| 217: | $style = 'news'; |
| 218: | } |
| 219: | $res = ''; |
| 220: | $data = $this->get('msg_history', array()); |
| 221: | $data = array_reverse($data); |
| 222: | foreach ($data as $url => $row) { |
| 223: | $from_class = 'from'; |
| 224: | if (!$row['from']) { |
| 225: | $row['from'] = $this->trans('[No From]'); |
| 226: | $from_class = 'nofrom'; |
| 227: | } |
| 228: | if (!$row['subject']) { |
| 229: | $row['subject'] = sprintf('[%s]', $this->trans('No subject')); |
| 230: | } |
| 231: | if (!$row['date']) { |
| 232: | $row['date'] = sprintf('[%s]', $this->trans('No date')); |
| 233: | $ts = 0; |
| 234: | } |
| 235: | else { |
| 236: | $ts = strtotime($row['date']); |
| 237: | } |
| 238: | switch ($row['type']) { |
| 239: | case 'github': |
| 240: | $icon = 'code'; |
| 241: | break; |
| 242: | case 'wordpress': |
| 243: | $icon = 'w'; |
| 244: | break; |
| 245: | case 'feed': |
| 246: | $icon = 'rss'; |
| 247: | break; |
| 248: | default: |
| 249: | $icon = 'env_closed'; |
| 250: | break; |
| 251: | } |
| 252: | if ($style == 'news') { |
| 253: | $data = message_list_row(array( |
| 254: | array('subject_callback', $row['subject'], $url, array(), ''), |
| 255: | array('safe_output_callback', 'source', $row['type'].' - '), |
| 256: | array('safe_output_callback', 'source', $row['source']), |
| 257: | array('safe_output_callback', $from_class, $row['from']), |
| 258: | array('date_callback', translate_time_str(human_readable_interval($row['date']), $this), $ts), |
| 259: | ), |
| 260: | $row['id'], |
| 261: | $style, |
| 262: | $this |
| 263: | ); |
| 264: | } |
| 265: | else { |
| 266: | $data = message_list_row(array( |
| 267: | array('safe_output_callback', 'source', $row['type'].'-'.$row['source'], $icon), |
| 268: | array('safe_output_callback', $from_class, $row['from']), |
| 269: | array('subject_callback', $row['subject'], $url, array(), ''), |
| 270: | array('date_callback', translate_time_str(human_readable_interval($row['date']), $this), $ts), |
| 271: | ), |
| 272: | $row['id'], |
| 273: | $style, |
| 274: | $this |
| 275: | ); |
| 276: | } |
| 277: | $res .= $data[0]; |
| 278: | } |
| 279: | return $res; |
| 280: | } |
| 281: | } |
| 282: | |
| 283: | |
| 284: | |
| 285: | |
| 286: | class Hm_Output_history_footer extends Hm_Output_Module { |
| 287: | protected function output() { |
| 288: | $res = '</tbody></table></div>'; |
| 289: | if (count($this->get('msg_history', array())) == 0) { |
| 290: | $res .= '<div class="empty_list">'.$this->trans('So alone').'</div>'; |
| 291: | } |
| 292: | return $res; |
| 293: | } |
| 294: | } |
| 295: | |