OSDN Git Service

git-svn-id: https://svn.sourceforge.jp/svnroot/nucleus-jp/plugin@1020 1ca29b6e-896d...
[nucleus-jp/nucleus-plugins.git] / NP_TrackBack / branches / DOM-branch / trackback / autodetect.php
1 <?php
2         $strRel = '../../../'; 
3         include($strRel . 'config.php');
4         
5         global $manager, $CONF;
6         $action = $manager->addTicketToUrl($CONF['ActionURL'] . '?action=plugin&name=TrackBack&type=detect')    
7 ?>
8         var xmlhttp = false;
9         var inProgress = false;
10         
11         var TrackbackAction = "<?php echo $action; ?>";
12         var TrackbackSource = new Array;
13         var TrackbackName   = new Array;
14         var TrackbackURL    = new Array;
15         
16         var LookupTable     = new Array;
17         var Lookup                      = '';
18         var countTotal                  = 0;
19         
20         var regexp = /href\s*=\s*([\"\'])(http:[^\"\'>]+)([\"\'])/ig;
21                 
22                 
23         function tbParseLinks ()
24         {
25                 oinputbody = document.getElementById('inputbody');
26                 oinputmore = document.getElementById('inputmore');
27                 full = oinputbody.value + ' ' + oinputmore.value;
28
29                 while (vArray = regexp.exec(full)) 
30                 {
31                         unused = true;
32                         
33                         if (Lookup == vArray[2])
34                                 unused = false;
35
36                         for (var i = 0; i < LookupTable.length; i++)
37                                 if (LookupTable[i] == vArray[2])
38                                         unused = false;
39
40                         for (var i = 0; i < TrackbackSource.length; i++) 
41                                 if (TrackbackSource[i] == vArray[2])
42                                         unused = false;
43                         
44                         if (unused == true)
45                                 LookupTable.push(vArray[2]);
46                 }
47         }
48         
49         function tbAutoDetect()
50         {
51                 if (LookupTable.length > 0)
52                 {
53                         tbBusy(true);
54
55                         if (!inProgress)
56                         {
57                                 // We have something to do and the connection is free
58                                 Lookup = LookupTable.shift();
59                                 inProgress = true;
60         
61                                 // The reason we use GET instead of POST is because
62                                 // Opera does not properly support setting headers yet,
63                                 // which is a requirement for using POST.
64                                 xmlhttp.open("GET", TrackbackAction + "&tb_link=" + escape(Lookup), true);
65                                 xmlhttp.onreadystatechange = tbStateChange;
66                                 xmlhttp.send('');
67                         }
68                         else
69                         {
70                                 // Still busy... simply wait until next turn
71                         }
72                 }
73                 else
74                 {
75                         // Nothing to do, check back later...
76                         if (Lookup == '')
77                         {
78                                 tbBusy(false);
79                         }
80                 }
81         }
82
83         function tbStateChange ()
84         {
85                 if (inProgress == true && xmlhttp.readyState == 4 && xmlhttp.status == 200) 
86                 {
87                         eval (xmlhttp.responseText);
88                         inProgress = false;
89                         Lookup = '';
90                 }
91         }
92
93         function tbBusy(toggle)
94         {
95
96                 if (toggle)
97                 {
98                                 document.forms[0].discoverit.style.color = "#888888";
99                                 document.forms[0].discoverit.style.fontWeight="bold";
100                                 document.forms[0].discoverit.value = "  Loading ....";
101                 }
102                 else
103                 {
104                                 document.forms[0].discoverit.style.color = "#888888";
105                                 document.forms[0].discoverit.style.fontWeight="bold";
106                                 document.forms[0].discoverit.value = "  D o n e !  ";
107                 }
108
109                 o = document.getElementById('tb_busy');
110                 
111                 if (o)
112                 {
113                         if (toggle)
114                                 o.style.display = '';
115                         else
116                                 o.style.display = 'none'
117                 }
118         }
119
120         function tbDone(source, url, name)
121         {
122                 TrackbackSource.push(source);
123                 TrackbackURL.push(url);
124                 TrackbackName.push(name);
125                         
126 //              var parent = document.getElementById('tb_auto');
127                 var amount = document.getElementById('tb_url_amount');
128                 var subtitle = document.getElementById('tb_auto_title');
129                 var listtable = document.getElementById('tb_ping_list');
130
131                 if (url != '')
132                 {
133 //                      count = parseInt(amount.value);
134                         count = countTotal;
135
136                         mycurrent_row=document.createElement("TR");
137
138                         checkbox = document.createElement("input");
139                         checkbox.type = 'checkbox';
140                         checkbox.name = "tb_url_" + count;
141                         checkbox.id = "tb_url_" + count;
142                         checkbox.value = url;
143                         checkbox.defaultChecked = true;
144
145                         label = document.createElement("label"); 
146                         label.htmlFor = "tb_url_" + count;
147                         label.title = source;
148                         
149                         text = document.createTextNode(name);
150                         label.appendChild(text);
151                         
152                         
153 //                      br = document.createElement("br"); 
154
155 //                      subtitle.innerHTML = "Auto Discovered Ping URL's:";
156 //                      parent.appendChild(checkbox);
157 //                      parent.appendChild(label);
158
159                         mycurrent_cell=document.createElement("TD");
160                         mycurrent_cell.appendChild(checkbox);
161                         mycurrent_row.appendChild(mycurrent_cell);
162                         mycurrent_cell=document.createElement("TD");
163                         mycurrent_cell.appendChild(label);
164                         mycurrent_row.appendChild(mycurrent_cell);
165                         
166                         mycurrent_row.appendChild(mycurrent_cell);
167
168
169                         if(url.indexOf("<?php echo $CONF['IndexURL'];?>",0) != -1)
170                         {
171                                 //local?
172                                 checkboxL = document.createElement("input");
173                                 checkboxL.type = 'checkbox';
174                                 checkboxL.name = "tb_url_" + count + "_local";
175                                 checkboxL.id = "tb_url_" + count + "_local";
176                                 checkboxL.defaultChecked = true;
177
178                                 labelL =        document.createElement("label"); 
179                                 labelL.htmlFor = "tb_url_" + count + "_local";
180                                 labelL.title = "local?";
181
182                                 text = document.createTextNode("local?");
183                                 labelL.appendChild(text);
184 //                              parent.appendChild(checkboxL);
185 //                              parent.appendChild(labelL);
186                                 mycurrent_cell=document.createElement("TD");
187                                 mycurrent_cell.appendChild(checkboxL);
188                                 mycurrent_cell.appendChild(labelL);
189                                 mycurrent_row.appendChild(mycurrent_cell);
190
191                         }
192                         else
193                         {
194                                 mycurrent_cell=document.createElement("TD");
195                                 mycurrent_row.appendChild(mycurrent_cell);
196                         }
197 //                      parent.appendChild(br);
198                         listtable.appendChild(mycurrent_row);
199
200 //                      amount.value = count + 1;
201                         countTotal++;
202                         amount.value = countTotal;
203                 }
204                 else
205                 {
206                         subtitle.innerHTML = "No Trackbak URLs.";
207                 }
208         }
209
210         function tbSetup() 
211         {
212                 try 
213                 {
214                         xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
215                 } 
216                 catch (e) 
217                 {
218                         try 
219                         {
220                                 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
221                         } 
222                         catch (e) 
223                         {
224                                 xmlhttp = false;
225                         }
226                 }
227
228                 if (!xmlhttp && typeof XMLHttpRequest!='undefined') 
229                 {
230                         xmlhttp = new XMLHttpRequest();
231                 }
232                 
233                 setInterval ('tbParseLinks();', 500);
234                 setInterval ('tbAutoDetect();', 500);
235                 
236                 if (window.onloadtrackback)
237                         window.onloadtrackback();                               
238         }
239
240         function AddStart()
241         {
242                 var strString = "";
243                 strString = document.forms[0].trackback_ping_url.value;
244                 strArray = strString.split("\n");
245                                 for (var i = 0; i < strArray.length; i++)
246                                 {
247                                         strTemp = trim(strArray[i]);
248                                         if (strTemp != "" && strTemp.match(/^http/))
249                                         {
250                                                 tbDone(strTemp,strTemp,strTemp);
251                                         }
252                                 }
253                 document.forms[0].trackback_ping_url.value = '';
254         }
255
256         function trim(string) 
257         { 
258                 return string.replace(/(^\s*)|(\s*$)/g,''); 
259         }