~ce-hyperscale/charms/precise/wordpress/arm64-trusty

« back to all changes in this revision

Viewing changes to files/wordpress/bash/parsers.js

  • Committer: Marco Ceppi
  • Date: 2012-07-11 20:45:43 UTC
  • mto: This revision was merged to the branch mainline in revision 55.
  • Revision ID: marco@ceppi.net-20120711204543-t44tb77atidxflll
Removed all OMG! Ubuntu specific stuff

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
function get_data(str, nm)
2
 
{
3
 
        if(typeof(str) == 'object')
4
 
        {
5
 
                if( typeof(str.cb) != "undefined") cb = str.cb
6
 
                str = $.param(str)
7
 
        }
8
 
 
9
 
        if(typeof(cache[str]) != "undefined")
10
 
                return cache[str]
11
 
        
12
 
        //$("#loading").fadeIn(500)
13
 
        input_blocked = true
14
 
 
15
 
        $.ajax.async = false
16
 
        xhr = new XMLHttpRequest()                              
17
 
        xhr.open("GET", url + "?" + str, false)
18
 
        xhr.send(null)
19
 
 
20
 
        response = JSON.parse(xhr.responseText)
21
 
 
22
 
 
23
 
        if(typeof(cb) != "undefined")
24
 
                response = eval(cb+"(response, nm)")
25
 
 
26
 
        cache[str] = response
27
 
        
28
 
        input_blocked = false
29
 
 
30
 
        return response
31
 
}
32
 
 
33
 
function parse_posts_pages(obj, jso, cb, nm)
34
 
{
35
 
        ret = {type: 'folder', dname: nm }
36
 
        i = 0
37
 
        $.each(obj, function()
38
 
        {
39
 
                cat = {type: 'folder', dname: this.title }
40
 
 
41
 
                if(this.post_count <= 20)
42
 
                {
43
 
                        cat.type = 'file'
44
 
                        cat.cb = cb
45
 
                        cat.json = jso
46
 
                        cat.include = 'slug,title,id,date'
47
 
                        cat.count = 20
48
 
                        cat.slug = this.slug
49
 
                }
50
 
                else
51
 
                {
52
 
                        for( var i = 0; i < Math.ceil(this.post_count / 20); i++ )
53
 
                        {
54
 
                                cat[i] = {type: 'folder', dname: 'Page '+(i+1), cb: cb, json: jso, include: 'slug,title,id,date', page: i, slug: this.slug, count: 20}
55
 
                        }
56
 
                }
57
 
 
58
 
                ret[this.id] = cat
59
 
        })
60
 
 
61
 
        return ret
62
 
}
63
 
 
64
 
function parse_categories(str,nm)
65
 
{
66
 
        return parse_posts_pages(str.categories, 'get_category_posts', 'parse_posts', nm)
67
 
}
68
 
 
69
 
function parse_tags(str,nm)
70
 
{
71
 
        ret = {type: 'folder', dname: nm}
72
 
 
73
 
        pres = []
74
 
        prel = {}
75
 
        slugs = {}
76
 
 
77
 
        $.each(str.tags, function()
78
 
        {
79
 
                s = this.slug.substr(0,1)
80
 
                if( typeof(ret[s]) == "undefined" )
81
 
                {
82
 
                        pres.push(s)
83
 
                        prel[s] = 0
84
 
                        slugs[s] = []
85
 
                        ret[s] = {type:'folder', dname: s}
86
 
                }
87
 
 
88
 
                prel[s] = prel[s] + 1
89
 
                slugs[s].push(this.slug)
90
 
                ret[s][this.slug] = {type: 'folder', dname: this.title, cb: "parse_posts", json: "get_tag_posts", include: "slug,title,id,date", slug: this.slug}
91
 
        })
92
 
        out = {type:'folder', dname: nm}
93
 
 
94
 
        $.each(pres, function(i)
95
 
        {
96
 
                s = pres[i]
97
 
                slug = slugs[s][0]
98
 
                if(prel[s] == 1)
99
 
                        out[slug] = ret[s][slug]
100
 
                else
101
 
                        out[s] = ret[s]
102
 
        })
103
 
 
104
 
        return out
105
 
}
106
 
 
107
 
function parse_authors(str,nm)
108
 
{
109
 
        ret = {type: 'folder', dname: nm }
110
 
        i = 0
111
 
        $.each(str.authors, function()
112
 
        {
113
 
                cat = {type: 'folder', dname: this.name }
114
 
 
115
 
                cat.cb = "parse_posts"
116
 
                cat.json = 'get_author_posts'
117
 
                cat.include = 'slug,title,id,date'
118
 
                cat.slug = this.slug
119
 
                cat.count = 100
120
 
 
121
 
                ret[this.slug] = cat
122
 
        })
123
 
        return ret
124
 
}
125
 
 
126
 
 
127
 
 
128
 
function parse_posts(data, nm)
129
 
{
130
 
 
131
 
        ret = {type: 'folder', dname: nm}
132
 
        i = 0
133
 
        $.each(data.posts, function()
134
 
        {
135
 
                ret[this.date.replace(/[ :-]+/g, "")] = {type: 'file', url: this.slug, dname: this.title, cb: 'parse_post', json:'get_post', id: this.id}
136
 
        })
137
 
        // console.log("parse posts", ret)
138
 
        return ret
139
 
}
140
 
 
141
 
function parse_post(data)
142
 
{
143
 
        data = data.post                        
144
 
        title = data.title
145
 
        content = $("<div>"+data.content+"</div>");
146
 
        content.find("style, img, .gallery, *:empty, a[href$=png], a[href$=jpg], a[href$=jpeg], embed, object, param").remove()
147
 
        content.find("a").each( function()
148
 
        {
149
 
                $(this).attr("href", "javascript: handle_click('"+$(this).attr("href")+"')")
150
 
        })
151
 
        content = content.html().replace(/[\s]+/g, " ")
152
 
 
153
 
        pad = title.replace(/./g, "-")+"--"
154
 
 
155
 
        return {type: 'file', dname: title, content: "\n"+pad+"\n> "+title+"\n"+pad+"\n\n"+content}
156
 
}
157
 
 
158
 
function parse_dates(data,nm)
159
 
{
160
 
        months = {"01":"January", "02":"February", "03":"March", "04":"April", "05":"May", "06":"June", "07":"July", "08":"August", "09":"September", "10":"October", "11":"November", "12":"December"}
161
 
        ret = {type: 'folder', dname: nm}
162
 
        $.each(data.tree, function(i,v)
163
 
        {
164
 
                year = {type: 'folder', dname: i}
165
 
                $.each(data.tree[i], function(j)
166
 
                {
167
 
                        year[j] = {type: 'folder', dname: months[j], cb:'parse_posts', json:'get_date_posts','date': i+"-"+j,'count':this.toString(), include:'slug,title,id,date'}
168
 
                })
169
 
                ret[i] = year
170
 
        })
171
 
        return ret
172
 
}
 
 
b'\\ No newline at end of file'