Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
matrix_insert_quick_link.inc
1 <?php
18 global $ROOT_PATH;
19 include_once($ROOT_PATH.'wysiwyg_plugin.inc');
20 
32 class Matrix_Insert_Quick_Link extends WYSIWYG_Plugin
33 {
34 
35 
44  {
45  $this->_add_button('matrixinsertquicklink','matrixInsertQuickLink','Create a Quick Link','false','68');
46  }
47 
48 
57  function paint_generic()
58  {
59  ?>
60  <script type="text/javascript" src="<?php echo sq_web_path('lib').'/js/general.js' ?>"></script>
61  <script type="text/javascript" src="<?php echo sq_web_path('fudge').'/var_serialise/var_serialise.js' ?>"></script>
62 
63  <script type="text/javascript" language="Javascript">
64 
65  // Called when the user clicks on "InsertImage" button
66  HTMLArea.prototype._matrixInsertQuickLink = function() {
67  // declare some stuff
68  var editor = this;
69  var inside_html = '';
70  var current_a = this.getClosest("a");
71  if (current_a) {
72  if (HTMLArea.is_ie) {
73  inside_html = current_a.innerHTML;
74  } else {
75  this.selectNodeContents(current_a);
76  inside_html = editor.getSelectedHTML();
77  }
78  } else {
79  inside_html = editor.getSelectedHTML();
80  }
81  sel = this._getSelection();
82  range = this._createRange(sel);
83 
84  // convert all para tags to lowercase
85  var para_html = inside_html.replace(/(<\/?)P/gi, "$1p");
86 
87  // OK so we have some paragraph tags caught up in the mix, lets see what we can do with them
88  // because we dont want our hrefs going around paragraph tags
89  if (para_html.indexOf("<p") > -1) {
90 
91  // if the position of the first tag is the same as the last then we have only one paragraph
92  // we don't want more than one paragraph because these can start or end from half-way through
93  // a para, which would break the formatting when we go to re-insert the text with the href
94  if (para_html.indexOf("<p") != para_html.lastIndexOf("<p")) {
95  alert(js_translate('select_one_paragraph_at_a_time'));
96  return;
97  }
98 
99  }// end if paragraphs exist
100 
101  if (sel != "") {
102  var link_url = "";
103 
104  // Is an email? Keep it an email, keep it mail
105  var test = new String(sel);
106  var mailregexp = new RegExp("^(.+)(\@)(.+)$", "gi");
107  if (test.search(mailregexp) == -1) {
108  checkhttplink = new RegExp("^http\:\/\/", "gi");
109  if (test.search(checkhttplink) == -1) {
110  checkanchorlink = new RegExp("^\#", "gi");
111  if (test.search(checkanchorlink) == -1) {
112  link_url = "http://" + sel;
113  } else {
114  link_url = sel;
115  }
116  } else {
117  link_url = sel;
118  }
119  } else {
120  checkmaillink = new RegExp("^mailto\:", "gi");
121  if (test.search(checkmaillink) == -1) {
122  link_url = "mailto:" + sel;
123  } else {
124  link_url = sel;
125  }
126  }
127 
128  var html_code = '<a href="' + link_url + '">' + sel + '</a>';
129  html_code = editor.make_absolute_urls(html_code);
130 
131  // replace with new URL
132  editor.insertHTML(html_code, range);
133  }//end if
134 
135  };
136  </script>
137  <?php
138 
139  }//end paint_generic()
140 
141 
150  {
151  ?>
152  case "createlink":
153  this._matrixInsertQuickLink();
154  break;
155  <?php
156  }
157 
158 
166  {
167  ?>
168  case "matrixinsertquicklink":
169  this._matrixInsertQuickLink();
170  break;
171  <?php
172 
173  }//end print_plugin_button_click()
174 
175 
183  {
184 
185  }//end print_plugin_update_toolbar()
186 
187 
188 }//end class
189 
190 ?>