Commit 8a803caf3e1cff330c8342fb95a5cbc7a741ce31
- Diff rendering mode:
- inline
- side by side
server/alipi.py
(80 / 27)
  | |||
11 | 11 | def start_page() : | |
12 | 12 | d = {} | |
13 | 13 | d['foruri'] = request.args['foruri'] | |
14 | myhandler = urllib2.ProxyHandler({'http':'http://proxy.iiit.ac.in:8080/'}) | ||
15 | opener = urllib2.build_opener(myhandler) | ||
16 | urllib2.install_opener(opener) | ||
17 | a = urllib2.urlopen(d['foruri']) | ||
14 | myhandler1 = urllib2.Request(d['foruri'],headers={'User-Agent':"Mozilla/5.0 (X11; U; Linux i686) Gecko/20071127 Firefox/2.0.0.11"}) #A fix to send user-agents, so that sites render properly. | ||
15 | a = urllib2.urlopen(myhandler1) | ||
18 | 16 | page = a.read() | |
19 | 17 | a.close() | |
20 | 18 | root = lxml.html.parse(StringIO.StringIO(page)).getroot() | |
21 | if request.args.has_key('lang') == False: | ||
19 | if request.args.has_key('lang') == False and request.args.has_key('blog') == False: | ||
22 | 20 | root.make_links_absolute(d['foruri'], resolve_base_href = True) | |
23 | 21 | script_test = root.makeelement('script') | |
24 | 22 | root[0].append(script_test) | |
25 | script_test.set("src", "http://x.a11y.in/alipi/ajay/alipi/test.js") | ||
23 | script_test.set("src", "http://dev.a11y.in/alipi/ui.js") | ||
26 | 24 | script_test.set("type", "text/javascript") | |
27 | 25 | ||
28 | 26 | script_jq_mini = root.makeelement('script') | |
… | … | ||
32 | 32 | root[0].append(style) | |
33 | 33 | style.set("rel","stylesheet") | |
34 | 34 | style.set("type", "text/css") | |
35 | style.set("href", "http://x.a11y.in/alipi/ajay/alipi/stylesheet.css") | ||
35 | style.set("href", "http://dev.a11y.in/alipi/stylesheet.css") | ||
36 | 36 | ||
37 | 37 | connection = pymongo.Connection('localhost',27017) | |
38 | 38 | db = connection['alipi'] | |
… | … | ||
75 | 75 | btn.set("value", "EDIT") | |
76 | 76 | return lxml.html.tostring(root) | |
77 | 77 | ||
78 | else: | ||
78 | elif request.args.has_key('lang') == True and request.args.has_key('blog') == False: | ||
79 | 79 | d['lang'] = request.args['lang'] | |
80 | 80 | script_test = root.makeelement('script') | |
81 | 81 | root[0].append(script_test) | |
82 | script_test.set("src", "http://x.a11y.in/alipi/ajay/alipi/test.js") | ||
82 | script_test.set("src", "http://dev.a11y.in/alipi/ui.js") | ||
83 | 83 | script_test.set("type", "text/javascript") | |
84 | 84 | root.body.set("onload","a11ypi.ren()"); | |
85 | # connection = pymongo.Connection('localhost',27017) | ||
86 | # db = connection['alipi'] | ||
87 | # collection = db['post'] | ||
88 | # query = collection.group( | ||
89 | # key = Code('function(doc){return {"xpath" : doc.xpath, "url": doc.url}}'), | ||
90 | # condition={"url" : request.args['foruri'], "lang" : request.args['lang']}, | ||
91 | # initial={'narration': []}, | ||
92 | # reduce=Code('function(doc,out){out.narration.push(doc);}') | ||
93 | # ) | ||
94 | # if len(query)==0: | ||
95 | # return 'empty' | ||
96 | # else: | ||
97 | # for key in query: | ||
98 | # post = key['narration'][len(key['narration'])-1] #for now, we only take the first re-narations, after we'll pick regarding filters. | ||
99 | |||
100 | # el = root.xpath('.//*[' + post['xpath'].split('/',2)[2].split('[',1)[1].lower()) | ||
101 | # el[0].text = post['data'] | ||
85 | root.make_links_absolute(d['foruri'], resolve_base_href = True) | ||
86 | return lxml.html.tostring(root) | ||
102 | 87 | ||
88 | elif request.args.has_key('interactive') == True and request.args.has_key('blog') == True: | ||
89 | script_test = root.makeelement('script') | ||
90 | root[0].append(script_test) | ||
91 | script_test.set("src", "http://dev.a11y.in/alipi/ui.js") | ||
92 | script_test.set("type", "text/javascript") | ||
93 | root.body.set("onload","a11ypi.filter()"); | ||
103 | 94 | root.make_links_absolute(d['foruri'], resolve_base_href = True) | |
104 | 95 | return lxml.html.tostring(root) | |
105 | 96 | ||
97 | elif request.args.has_key('interactive') == False and request.args.has_key('blog') == True: | ||
98 | script_test = root.makeelement('script') | ||
99 | root[0].append(script_test) | ||
100 | script_test.set("src", "http://dev.a11y.in/alipi/ui.js") | ||
101 | script_test.set("type", "text/javascript") | ||
102 | |||
103 | script_jq_mini = root.makeelement('script') | ||
104 | root[0].append(script_jq_mini) | ||
105 | script_jq_mini.set("src", "http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js") | ||
106 | script_jq_mini.set("type", "text/javascript") | ||
107 | |||
108 | style = root.makeelement('link') | ||
109 | root[0].append(style) | ||
110 | style.set("rel","stylesheet") | ||
111 | style.set("type", "text/css") | ||
112 | style.set("href", "http://dev.a11y.in/alipi/stylesheet.css") | ||
113 | |||
114 | connection = pymongo.Connection('localhost',27017) | ||
115 | db = connection['alipi'] | ||
116 | collection = db['post'] | ||
117 | if collection.find_one({"url" : request.args['foruri']}) is not None: | ||
118 | ren_overlay = root.makeelement('div') | ||
119 | root[0].append(ren_overlay) | ||
120 | ren_overlay.set("id", "ren_overlay") | ||
121 | ren_overlay.text = "Narration(s) available" | ||
122 | |||
123 | close = root.makeelement('input') | ||
124 | ren_overlay.append(close) | ||
125 | close.set("id", "close-button") | ||
126 | close.set("type", "submit") | ||
127 | close.set("onClick", "a11ypi.close();") | ||
128 | close.set("value", "Close") | ||
129 | |||
130 | overlay1 = root.makeelement('div') | ||
131 | root[0].append(overlay1) | ||
132 | overlay1.set("id", "overlay1") | ||
133 | |||
134 | opt = root.makeelement('option') | ||
135 | opt.text = "Choose a narration" | ||
136 | |||
137 | rpl = root.makeelement('select') | ||
138 | overlay1.append(rpl) | ||
139 | rpl.append(opt) | ||
140 | rpl.set("id", "menu-button") | ||
141 | rpl.set("onclick", "a11ypi.ajax1();") | ||
142 | |||
143 | overlay2 = root.makeelement('div') | ||
144 | root[0].append(overlay2) | ||
145 | overlay2.set("id", "overlay2") | ||
146 | |||
147 | btn = root.makeelement('input') | ||
148 | overlay2.append(btn) | ||
149 | btn.set("id", "edit-button") | ||
150 | btn.set("type", "submit") | ||
151 | btn.set("onClick", "a11ypi.testContext();") | ||
152 | btn.set("value", "EDIT") | ||
153 | # script_test1 = root.makeelement('script') | ||
154 | # root[0].append(script_test1) | ||
155 | # script_test1.set("src", "http://192.168.100.56:82/server/ui.js") | ||
156 | # script_test1.set("type", "text/javascript") | ||
157 | # root.body.set("onload","a11ypi.filter()"); | ||
158 | root.make_links_absolute(d['foruri'], resolve_base_href = True) | ||
159 | return lxml.html.tostring(root) | ||
160 | |||
106 | 161 | import logging | |
107 | 162 | from logging import FileHandler | |
108 | 163 | ||
109 | fil = FileHandler('/var/www/ajay/alipi/logme',mode='a') | ||
164 | fil = FileHandler('/var/www/dev/alipi/logme',mode='a') | ||
110 | 165 | fil.setLevel(logging.ERROR) | |
111 | 166 | app.logger.addHandler(fil) | |
112 | 167 |
server/ui.js
(122 / 21)
  | |||
16 | 16 | var a = content.document.createElement("script"); | |
17 | 17 | for (j=0; j<v.length; j++) { | |
18 | 18 | c = v[0].appendChild(a); | |
19 | c.setAttribute("src","http://x.a11y.in/alipi/ajay/alipi/wsgi/page_edit.js"); | ||
19 | c.setAttribute("src","http://dev.a11y.in/alipi/wsgi/page_edit.js"); | ||
20 | 20 | ||
21 | 21 | c.setAttribute("type","text/javascript"); | |
22 | 22 | } | |
… | … | ||
58 | 58 | } | |
59 | 59 | } | |
60 | 60 | } | |
61 | xhr.open("POST","http://x.a11y.in/alipi/menu",true); | ||
61 | xhr.open("POST","http://dev.a11y.in/menu",true); | ||
62 | 62 | xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded"); | |
63 | xhr.send(String(window.location.search.split('=')[1])); | ||
63 | d = window.location.search.split('?')[1]; | ||
64 | var a =[]; | ||
65 | for (var i = 0;i<d.split('&').length;i++){ | ||
66 | a[d.split('&')[i].split('=')[0]] = d.split('&')[i].split('=')[1]; | ||
67 | } | ||
68 | var url = a['foruri']; | ||
69 | xhr.send('url='+url); | ||
64 | 70 | } | |
65 | 71 | }, | |
72 | ajax1: function() { | ||
73 | if(a11ypi.flag == '0') | ||
74 | { | ||
75 | a11ypi.flag = 1; | ||
76 | var xhr = new XMLHttpRequest(); | ||
77 | xhr.onreadystatechange = function() | ||
78 | { | ||
79 | if(xhr.readyState == 4) | ||
80 | { | ||
81 | if(xhr.responseText == "empty") | ||
82 | { | ||
83 | a11ypi.clearMenu(); | ||
84 | } | ||
85 | else | ||
86 | { | ||
87 | a11ypi.createMenuFilter(JSON.parse(xhr.responseText)); | ||
88 | } | ||
89 | } | ||
90 | } | ||
91 | xhr.open("POST","http://dev.a11y.in/menu",true); | ||
92 | xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded"); | ||
93 | d = window.location.search.split('?')[1]; | ||
94 | var a =[]; | ||
95 | for (var i = 0;i<d.split('&').length;i++){ | ||
96 | a[d.split('&')[i].split('=')[0]] = d.split('&')[i].split('=')[1]; | ||
97 | } | ||
98 | var url = a['foruri']; | ||
99 | var option = a['blog']; | ||
100 | data = 'url='+url+'&option='+option; | ||
101 | xhr.send(data) ; | ||
102 | } | ||
103 | }, | ||
104 | |||
66 | 105 | getURL: function(e) { | |
67 | 106 | window.location = window.location.href + "&lang=" + e.value; | |
68 | 107 | window.reload(); | |
… | … | ||
139 | 139 | } | |
140 | 140 | } | |
141 | 141 | } | |
142 | var url = window.location.search.split('?')[1].split('=')[1].split('&')[0]; | ||
143 | var lang= window.location.search.split('&')[1].split('=')[1]; | ||
142 | d = window.location.search.split('?')[1]; | ||
143 | var a =[]; | ||
144 | for (var i = 0;i<d.split('&').length;i++){ | ||
145 | a[d.split('&')[i].split('=')[0]] = d.split('&')[i].split('=')[1]; | ||
146 | } | ||
147 | var url = a['foruri']; | ||
148 | var lang= a['lang']; | ||
144 | 149 | var data="url="+encodeURIComponent(url)+"&lang="+encodeURIComponent(lang); | |
145 | 150 | ||
146 | xhr.open("POST","http://x.a11y.in/alipi/replace",true); | ||
151 | xhr.open("POST","http://dev.a11y.in/replace",true); | ||
147 | 152 | xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded"); | |
148 | 153 | xhr.send(data);// | |
149 | 154 | }, | |
150 | 155 | evaluate: function() | |
151 | 156 | { | |
152 | var nodes = content.document.evaluate(path, content.document, null, XPathResult.ANY_TYPE,null); | ||
153 | |||
157 | path = path.slice(0, path.lastIndexOf('SPAN')-1); //A hack to fix xpath after adding span. This must be corrected from the server side. #TODO | ||
158 | var nodes = document.evaluate(path, document, null, XPathResult.ANY_TYPE,null); | ||
154 | 159 | try{ | |
155 | 160 | ||
156 | 161 | var result = nodes.iterateNext(); | |
157 | |||
158 | 162 | while (result) | |
159 | 163 | ||
160 | 164 | { | |
… | … | ||
196 | 196 | close: function() { | |
197 | 197 | document.getElementById('ren_overlay').style.display = 'none'; | |
198 | 198 | }, | |
199 | |||
200 | }; | ||
201 | |||
202 | $(document).ready(function ($) { | ||
203 | $("a").click(function () { | ||
204 | var a = $(this), | ||
205 | href = a.attr('href'), | ||
206 | content = a.parent().next(); | ||
207 | // content.load(href + " #content"); | ||
208 | return false; | ||
209 | }); | ||
210 | }); | ||
199 | filter: function() | ||
200 | { | ||
201 | var xhr = new XMLHttpRequest(); | ||
202 | xhr.onreadystatechange = function() | ||
203 | { | ||
204 | if(xhr.readyState == 4) | ||
205 | { | ||
206 | if(xhr.responseText =='empty') | ||
207 | { | ||
208 | a11ypi.clearMenu(); | ||
209 | alert("An internal server error occured, please try later."); | ||
210 | } | ||
211 | else | ||
212 | { | ||
213 | |||
214 | d ={}; | ||
215 | var response=xhr.responseText.substring(3).split('###'); | ||
216 | for (var j= 0; j< response.length ; j++){ | ||
217 | chunk = response[j].substring(1).split('&'); | ||
218 | |||
219 | for (var i= 0; i< chunk.length ; i++){ | ||
220 | pair =chunk[i].split("::"); | ||
221 | key = pair[0]; | ||
222 | value = pair[1]; | ||
223 | d[key] = value; | ||
224 | } | ||
225 | path = d['xpath']; | ||
226 | newContent = d['data']; | ||
227 | a11ypi.evaluate(path,newContent); | ||
228 | } | ||
229 | } | ||
230 | } | ||
231 | } | ||
232 | d = window.location.search.split('?')[1]; | ||
233 | var a =[]; | ||
234 | for (var i = 0;i<d.split('&').length;i++){ | ||
235 | a[d.split('&')[i].split('=')[0]] = d.split('&')[i].split('=')[1]; | ||
236 | } | ||
237 | var url = a['foruri']; | ||
238 | var lang= a['lang']; | ||
239 | var blog= a['blog']; | ||
240 | var data="url="+encodeURIComponent(url)+"&lang="+encodeURIComponent(lang)+"&blog="+encodeURIComponent(blog); | ||
241 | |||
242 | xhr.open("POST","http://dev.a11y.in/filter",true); | ||
243 | xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded"); | ||
244 | xhr.send(data);// | ||
245 | }, | ||
246 | createMenuFilter: function(menu_list) { | ||
247 | var xyz = document.getElementById("menu-button"); | ||
248 | for(var i in menu_list) | ||
249 | { | ||
250 | var newel = document.createElement("option"); | ||
251 | newel.textContent = menu_list[i]; | ||
252 | newel.setAttribute("value",menu_list[i]); | ||
253 | newel.setAttribute("onclick","a11ypi.getURLFilter(event.target);"); | ||
254 | xyz.appendChild(newel); | ||
255 | } | ||
256 | }, | ||
257 | clearMenuFilter: function() { | ||
258 | var xyz = document.getElementById("menu-button"); | ||
259 | while(null!= xyz.firstChild) | ||
260 | { | ||
261 | xyz.removeChild(xyz.firstChild); | ||
262 | } | ||
263 | }, | ||
264 | getURLFilter: function(e) { | ||
265 | window.location = window.location.href + "&lang=" + e.value+"&interactive=1"; | ||
266 | window.reload(); | ||
267 | }, | ||
268 | }; |