| 1: | <?php |
| 2: | |
| 3: | class Hm_Output_filter_tag_data extends Hm_Output_Module { |
| 4: | |
| 5: | |
| 6: | |
| 7: | protected function output() { |
| 8: | if ($this->get('imap_tag_data')) { |
| 9: | prepare_imap_message_list($this->get('imap_tag_data'), $this, 'tag'); |
| 10: | } |
| 11: | elseif (!$this->get('formatted_message_list')) { |
| 12: | $this->out('formatted_message_list', array()); |
| 13: | } |
| 14: | } |
| 15: | } |
| 16: | |
| 17: | |
| 18: | |
| 19: | |
| 20: | |
| 21: | class Hm_Output_tag_per_source_setting extends Hm_Output_Module { |
| 22: | |
| 23: | |
| 24: | |
| 25: | protected function output() { |
| 26: | $sources = DEFAULT_TAGS_PER_SOURCE; |
| 27: | $settings = $this->get('user_settings', array()); |
| 28: | $reset = ''; |
| 29: | if (array_key_exists('tag_per_source', $settings)) { |
| 30: | $sources = $settings['tag_per_source']; |
| 31: | } |
| 32: | if ($sources != DEFAULT_TAGS_PER_SOURCE) { |
| 33: | $reset = '<span class="tooltip_restore" restore_aria_label="Restore default value"><i class="bi bi-arrow-counterclockwise refresh_list reset_default_value_input"></i></span>'; |
| 34: | } |
| 35: | return '<tr class="tag_setting"><td><label for="tag_per_source">'. |
| 36: | $this->trans('Max messages per source').'</label></td>'. |
| 37: | '<td class="d-flex"><input type="text" size="2" class="form-control form-control-sm w-auto" id="tag_per_source" name="tag_per_source" value="'.$this->html_safe($sources).'" data-default-value="'.DEFAULT_TAGS_PER_SOURCE.'"/>'.$reset.'</td></tr>'; |
| 38: | } |
| 39: | } |
| 40: | |
| 41: | |
| 42: | |
| 43: | |
| 44: | |
| 45: | class Hm_Output_start_tag_settings extends Hm_Output_Module { |
| 46: | |
| 47: | |
| 48: | |
| 49: | protected function output() { |
| 50: | $res = '<tr><td data-target=".tag_setting" colspan="2" class="settings_subtitle cursor-pointer border-bottom p-2">'. |
| 51: | '<i class="bi bi-tags fs-5 me-2"></i>'. |
| 52: | $this->trans('Tags').'</td></tr>'; |
| 53: | print_r($res); |
| 54: | return $res; |
| 55: | } |
| 56: | } |
| 57: | |
| 58: | |
| 59: | |
| 60: | |
| 61: | |
| 62: | class Hm_Handler_process_tag_since_setting extends Hm_Handler_Module { |
| 63: | |
| 64: | |
| 65: | |
| 66: | public function process() { |
| 67: | process_site_setting('tag_since', $this, 'since_setting_callback'); |
| 68: | } |
| 69: | } |
| 70: | |
| 71: | |
| 72: | |
| 73: | |
| 74: | |
| 75: | class Hm_Output_tag_since_setting extends Hm_Output_Module { |
| 76: | |
| 77: | |
| 78: | |
| 79: | protected function output() { |
| 80: | $since = DEFAULT_TAGS_SINCE; |
| 81: | $settings = $this->get('user_settings', array()); |
| 82: | if (array_key_exists('tag_since', $settings) && $settings['tag_since']) { |
| 83: | $since = $settings['tag_since']; |
| 84: | } |
| 85: | return '<tr class="tag_setting"><td><label for="tag_since">'. |
| 86: | $this->trans('Show tagged messages since').'</label></td>'. |
| 87: | '<td>'.message_since_dropdown($since, 'tag_since', $this, DEFAULT_TAGS_SINCE).'</td></tr>'; |
| 88: | } |
| 89: | } |
| 90: | |
| 91: | class Hm_Output_tags_heading extends Hm_Output_Module { |
| 92: | |
| 93: | |
| 94: | protected function output() { |
| 95: | return '<div class="content_title">'.$this->trans('Tags').'</div>'; |
| 96: | } |
| 97: | } |
| 98: | class Hm_Output_tags_tree extends Hm_Output_Module { |
| 99: | |
| 100: | |
| 101: | protected function output() { |
| 102: | if ($this->format == 'HTML5') { |
| 103: | $folders = $this->get('tags', array()); |
| 104: | $tag = $this->get('edit_tag'); |
| 105: | $id = $this->get('edit_tag_id'); |
| 106: | |
| 107: | |
| 108: | $folderTree = []; |
| 109: | foreach ($folders as $folderId => $folder) { |
| 110: | if (isset($folder['parent']) && $folder['parent']) { |
| 111: | $folders[$folder['parent']]['children'][$folderId] = &$folders[$folderId]; |
| 112: | } else { |
| 113: | $folderTree[$folderId] = &$folders[$folderId]; |
| 114: | } |
| 115: | } |
| 116: | |
| 117: | |
| 118: | $treeViewHtml = generate_tree_view($folderTree, $this->html_safe(Hm_Request_Key::generate())); |
| 119: | $treeContent = count($folderTree) > 0 ? $treeViewHtml : '<p>'. $this->trans('No tags available yet.') .'</p>'; |
| 120: | return '<div class="tags_tree mt-3 col-lg-8 col-md-8 col-sm-12"> |
| 121: | <div class="card m-3 mr-0"> |
| 122: | <div class="card-body"> |
| 123: | <div class="tree-view"> |
| 124: | ' . $treeContent . ' |
| 125: | </div> |
| 126: | </div> |
| 127: | </div> |
| 128: | </div>'; |
| 129: | |
| 130: | } |
| 131: | } |
| 132: | } |
| 133: | |
| 134: | class Hm_Output_tags_form extends Hm_Output_Module { |
| 135: | |
| 136: | |
| 137: | protected function output() { |
| 138: | if ($this->format == 'HTML5') { |
| 139: | $count = count($this->get('tags', array())); |
| 140: | $count = sprintf($this->trans('%d configured'), $count); |
| 141: | $tag = $this->get('edit_tag', null); |
| 142: | $id = $this->get('edit_tag_id', null); |
| 143: | $parent_tag = !empty($tag) ? $tag['parent'] : null; |
| 144: | $options = ''; |
| 145: | |
| 146: | foreach ($this->get('tags', array()) as $index => $folder) { |
| 147: | $option_selected = !is_null($id) && $folder['id'] === $parent_tag ? 'selected' : ''; |
| 148: | $options .= '<option '. $option_selected.' value="'.$this->html_safe($folder['id']).'">'.$this->html_safe($folder['name']).'</option>'; |
| 149: | } |
| 150: | $form_title = !is_null($id) ? $this->trans('Edit tag/label').': '.$tag['name'] : $this->trans('Add an tag/label'); |
| 151: | return '<div class="tags_tree mt-3 col-lg-4 col-md-4 col-sm-12"> |
| 152: | <div class="card m-4"> |
| 153: | <div class="card-body"> |
| 154: | <form class="add_tag me-0" method="POST" action="?page=tags"> |
| 155: | <input type="hidden" name="hm_page_key" id="hm_page_key" value="'.$this->html_safe(Hm_Request_Key::generate()).'" /> |
| 156: | |
| 157: | <div class="subtitle mt-4">'.$form_title.'</div> |
| 158: | |
| 159: | <div class="form-floating mb-3"> |
| 160: | <input type="hidden" id="hm_ajax_hook" name="hm_ajax_hook" class="txt_fld form-control" value="ajax_process_tag_update"> |
| 161: | <input type="hidden" id="tag_id" name="tag_id" class="txt_fld form-control" value="'.$this->html_safe($id).'" placeholder="'.$this->trans('Tag id').'"> |
| 162: | <input required type="text" id="tag_name" name="tag_name" class="txt_fld form-control" value="'.$this->html_safe($tag['name']).'" placeholder="'.$this->trans('Tag name').'"> |
| 163: | <label class="" for="tag_name">'.$this->trans('Tag name').'</label> |
| 164: | </div> |
| 165: | <div class="form-floating mb-3"> |
| 166: | <select id="parent_tag" name="parent_tag" class="form-select form-select-lg mb-3" aria-label=""> |
| 167: | <option value="" selected>None</option> |
| 168: | '.$options.' |
| 169: | </select> |
| 170: | <label class="" for="parent_tag">'.$this->trans('Parent Tag name').'</label> |
| 171: | </div> |
| 172: | |
| 173: | <input type="submit" class="btn btn-primary px-5" value="'.$this->trans('Add').'" name="submit_tag" /> |
| 174: | </form> |
| 175: | </div> |
| 176: | </div> |
| 177: | </div>'; |
| 178: | } |
| 179: | } |
| 180: | } |
| 181: | |
| 182: | |
| 183: | |
| 184: | |
| 185: | class Hm_Output_tags extends hm_output_module { |
| 186: | protected function output() { |
| 187: | $res = ''; |
| 188: | $folders = $this->get('tags', array()); |
| 189: | if (is_array($folders) && !empty($folders)) { |
| 190: | if(count($this->get('tags', array())) > 1) { |
| 191: | $res .= '<li class="menu_tags"><a class="all_tags" href="?page=tags">'; |
| 192: | if (!$this->get('hide_folder_icons')) { |
| 193: | $res .= '<i class="bi bi-tags fs-5 me-2"></i>'; |
| 194: | } |
| 195: | $res .= $this->trans('All'); |
| 196: | $res .= '<span class="tags_count">('.count($folders).')</span></a></li>'; |
| 197: | } |
| 198: | $folderTree = []; |
| 199: | foreach ($folders as $folderId => $folder) { |
| 200: | if (isset($folder['parent']) && $folder['parent']) { |
| 201: | $folders[$folder['parent']]['children'][$folderId] = &$folders[$folderId]; |
| 202: | } else { |
| 203: | $folderTree[$folderId] = &$folders[$folderId]; |
| 204: | } |
| 205: | } |
| 206: | foreach ($folderTree as $id => $folder) { |
| 207: | $hasChild = isset($folder['children']) && !empty($folder['children']); |
| 208: | $res .= '<li class="tags_'.$this->html_safe($id).'">'; |
| 209: | if (!$this->get('hide_folder_icons')) { |
| 210: | $res .= $hasChild ? '<i class="bi bi-caret-down"></i>' : '<i class="bi bi-tags fs-5 me-2"></i>'; |
| 211: | } |
| 212: | $res .= '<a data-id="tag_'.$this->html_safe($id).'" href="?page=message_list&list_path=tag&tag_id='.$this->html_safe($id).'">'; |
| 213: | $res .= $this->html_safe($folder['name']).'</a>'; |
| 214: | if($hasChild) { |
| 215: | $res .= '<ul>'; |
| 216: | foreach ($folder['children'] as $key => $child) { |
| 217: | $res .= '<li class="tag_'.$this->html_safe($child['id']).'">'; |
| 218: | $res .= '<a data-id="tag_'.$this->html_safe($child['id']).'" href="?page=message_list&list_path=tag&tag_id='.$this->html_safe($child['id']).'">'; |
| 219: | $res .= $this->html_safe($folder['name']).'</a>'; |
| 220: | $res .= '</li>'; |
| 221: | } |
| 222: | $res .= '</ul>'; |
| 223: | } |
| 224: | $res .= '</li>'; |
| 225: | } |
| 226: | } |
| 227: | $res .= '<li class="tags_add_new"><a href="?page=tags">'; |
| 228: | if (!$this->get('hide_folder_icons')) { |
| 229: | $res .= '<i class="bi bi-plus-square menu-icon"></i>'; |
| 230: | } |
| 231: | $res .= $this->trans('Add label').'</a></li>'; |
| 232: | $this->append('folder_sources', array('tags_folders', $res)); |
| 233: | } |
| 234: | } |
| 235: | |
| 236: | |
| 237: | |
| 238: | |
| 239: | class Hm_Output_tag_bar extends hm_output_module { |
| 240: | protected function output() { |
| 241: | $headers = $this->get('msg_headers'); |
| 242: | if (is_string($headers)) { |
| 243: | $this->out('msg_headers', $headers.'<i class="bi bi-tags-fill fs-4 tag_icon refresh_list"></i>'); |
| 244: | } |
| 245: | } |
| 246: | } |
| 247: | |
| 248: | class Hm_Output_display_configured_tags extends Hm_Output_Module { |
| 249: | protected function output() { |
| 250: | $res = ''; |
| 251: | if ($this->format == 'HTML5') { |
| 252: | foreach ($this->get('feeds', array()) as $index => $vals) { |
| 253: | $res .= '<div class="configured_server col-12 col-lg-4 mb-2"><div class="card card-body">'; |
| 254: | $res .= sprintf('<div class="server_title"><b>%s</b></div><div title="%s" class="server_subtitle">%s</div>', |
| 255: | $this->html_safe($vals['name']), $this->html_safe($vals['server']), $this->html_safe($vals['server'])); |
| 256: | $res .= '<form class="feed_connect d-flex gap-2" method="POST">'; |
| 257: | $res .= '<input type="hidden" name="feed_id" value="'.$this->html_safe($index).'" />'; |
| 258: | $res .= '<input type="submit" value="'.$this->trans('Test').'" class="test_feed_connect btn btn-primary btn-sm" />'; |
| 259: | $res .= '<input type="submit" value="'.$this->trans('Delete').'" class="feed_delete btn btn-outline-danger btn-sm" />'; |
| 260: | $res .= '<input type="hidden" value="ajax_feed_debug" name="hm_ajax_hook" />'; |
| 261: | $res .= '</form></div></div>'; |
| 262: | } |
| 263: | $res .= '<br class="clear_float" /></div></div>'; |
| 264: | } |
| 265: | return $res; |
| 266: | } |
| 267: | } |
| 268: | |