rxcms-podio_plugin 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,12 @@
1
+ class AbstractOrganization < Podio::Organization
2
+ # To change this template use File | Settings | File Templates.
3
+
4
+ def self.get_list_of_organizations
5
+ begin
6
+ self.find_all
7
+ rescue
8
+ []
9
+ end
10
+ end
11
+
12
+ end
@@ -0,0 +1,4 @@
1
+ class AbstractSpace < Podio::Space
2
+ # To change this template use File | Settings | File Templates.
3
+
4
+ end
@@ -0,0 +1,184 @@
1
+ <!-- app delete modal -->
2
+ <div id="appDelete" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
3
+ <div class="modal-header">
4
+ <button type="button" class="close" data-dismiss="modal" aria-hidden="true">x</button>
5
+ <h3 id="myModalLabel">Delete App</h3>
6
+ </div>
7
+ <div class="modal-body">
8
+ <p>Are you sure you want to do this?</p>
9
+ </div>
10
+ <div class="modal-footer">
11
+ <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
12
+ <button id="appDeleteBtn" class="btn btn-primary" data-dismiss="modal" onclick="void(0)">Delete</button>
13
+ </div>
14
+ </div>
15
+ <!-- -->
16
+
17
+ <!-- Modal -->
18
+ <div id="appAccesses" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
19
+ <div class="modal-header">
20
+ <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
21
+ <h3 id="myModalLabel">Currently have access(es) to:</h3>
22
+ </div>
23
+ <div class="modal-body">
24
+ <ul id="accessibleApps">
25
+ </ul>
26
+ </div>
27
+ <div class="modal-footer">
28
+ <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
29
+ </div>
30
+ </div>
31
+ <!-- -->
32
+
33
+ <div class="container" style="margin-bottom: 25px;">
34
+ <div class="">
35
+ <div class="row-fluid">
36
+ <div style="min-height:512px;">
37
+ <ul class="nav nav-tabs" id="systemTabs">
38
+ <li><a href="#podio" data-toggle="tab">Podio Integration</a></li>
39
+ <li><a href="#serviceAccountConfig" data-toggle="tab">Podio Service Account</a></li>
40
+ <li><a href="#uninstaller" data-toggle="tab">Uninstall</a></li>
41
+ </ul>
42
+
43
+ <div class="tab-content">
44
+
45
+ <!-- Podio Tab -->
46
+ <div class="tab-pane" id="podio">
47
+
48
+ <div>
49
+ <ul class="inline">
50
+ <!--<li><i class="icon-refresh"></i>&nbsp;<span><a href="javascript:void(0);">Reload</a></span></li>-->
51
+ <a id="aAppAccesses" href="#appAccesses" data-toggle="modal">show access</a>
52
+ <li><span id="podioTabLoadingText" style="padding:5px;display:none;">populating registered apps, please wait...</span></li>
53
+ </ul>
54
+ </div>
55
+
56
+ <div>
57
+ <table id="appTable" style="max-width:none;" class="table">
58
+ <thead>
59
+ <tr>
60
+ <th width="2%">#</th>
61
+ <th width="5%"></th>
62
+ <th width="2%">Status</th>
63
+ <th width="20%"><span style="padding: 0 5px 0 5px;">App Name</span></th>
64
+ <th width="70%"><span style="padding: 0 5px 0 5px;">App ID</span></th>
65
+ </tr>
66
+ </thead>
67
+ <tbody id="appTableBody">
68
+
69
+ <tr>
70
+ <td data-modify-flag="unchecked" data-id="">...</td>
71
+ <td data-modify-flag="unchecked" style="text-align:center;">
72
+ <a id="aNewApp" href="javascript:void(0);"><i class="icon-ok"></i></a>
73
+ </td>
74
+ <td data-modify-flag="unchecked" style="text-align:center;"></td>
75
+ <td data-modify-flag="checked">
76
+ <div style="max-height:175px;overflow-y:auto;cursor:pointer;">
77
+ <input type="text" class="input" id="newAppNameTxt" placeholder="new app name" maxlength="64" style="width:90%;display:block;border:0 !important;box-shadow:none !important;outline:0;font-family:'Courier New',sans-serif;" />
78
+ </div>
79
+ </td>
80
+ <td data-modify-flag="checked">
81
+ <div style="max-height:175px;overflow-y:auto;cursor:pointer;">
82
+ <!--<input type="text" class="input" id="newAppIdTxt" placeholder="new app id" maxlength="64" style="width:90%;display:block;border:0 !important;box-shadow:none !important;outline:0;font-family:'Courier New',sans-serif;" />-->
83
+ <select id="newAppIdSelect">
84
+ </select>
85
+ </div>
86
+ </td>
87
+ </tr>
88
+
89
+ <!-- DUMMY -->
90
+ <tr class="appItem" id="podioAppItemDummy" style="display:none;">
91
+ <td data-modify-flag="unchecked" data-id=""></td>
92
+ <td data-modify-flag="unchecked" style="text-align:center;">
93
+ <a href="#appDelete" data-toggle="modal"><i class="icon-remove"></i></a>
94
+ </td>
95
+ <td data-modify-flag="unchecked" style="text-align:center;">
96
+ <a title="online" href="javascript:void(0);"><i id="" class="icon-eye-open"></i></a>
97
+ </td>
98
+ <td data-modify-flag="checked">
99
+ <div style="max-height:175px;overflow-y:auto;cursor:pointer;">
100
+ <span style="padding:0 5px 0 5px;">
101
+
102
+ </span>
103
+ <input type="text" class="input" data-attr="editor" maxlength="64" style="width:90%;display:none;border:0 !important;box-shadow:none !important;outline:0;font-family:'Courier New',sans-serif;" />
104
+ </div>
105
+ </td>
106
+ <td data-modify-flag="checked">
107
+ <div style="max-height:175px;overflow-y:auto;cursor:pointer;">
108
+ <span style="padding:0 5px 0 5px;">
109
+
110
+ </span>
111
+ <input type="text" class="input" data-attr="editor" maxlength="64" style="width:90%;display:none;border:0 !important;box-shadow:none !important;outline:0;font-family:'Courier New',sans-serif;" />
112
+ </div>
113
+ </td>
114
+ </tr>
115
+ <!-- DUMMY -->
116
+ </tbody>
117
+ </table>
118
+
119
+ </div>
120
+ </div>
121
+ <!-- End -->
122
+
123
+ <!-- Service Account Tab -->
124
+ <div class="tab-pane" id="serviceAccountConfig">
125
+ <div style="padding: 15px;">
126
+ <div>
127
+ <strong>Service Status:&nbsp;</strong>
128
+ <% if (@serviceAccount.nil?) %>
129
+ <span id="serviceAccountStatus">No service account are currently active</span>
130
+ <% else %>
131
+ <span id="serviceAccountStatus">Podio service account <%= @serviceAccount.value.strip.html_safe %> is active</span>
132
+ <% end %>
133
+ </div>
134
+ <div style="padding: 25px 0 25px 0;">
135
+ <div class="control-group">
136
+ <div class="controls">
137
+ <div class="input-prepend">
138
+ <span class="add-on"><i class="icon-user"></i></span>
139
+ <input id="username" type="text">
140
+ </div>
141
+ </div>
142
+ </div>
143
+ <div class="control-group">
144
+ <div class="controls">
145
+ <div class="input-prepend">
146
+ <span class="add-on"><i class="icon-asterisk"></i></span>
147
+ <input id="password" type="password">
148
+ </div>
149
+ </div>
150
+ </div>
151
+ <div>
152
+ <button class="btn btn-danger" id="activateServiceAccountBtn">activate</button>
153
+ </div>
154
+ </div>
155
+ <div id="orgsIndicator" style="display:none;">Loading...</div>
156
+ <div id="chooseOrganization" class="chooseSomething" style="padding: 25px 0 25px 0;display:none;">
157
+ <label for="selectOrganization"><strong>Choose an organization</strong></label>
158
+ <select id="selectOrganization">
159
+ </select>
160
+ </div>
161
+ <div id="workspacesIndicator" style="display:none;">Loading...</div>
162
+ <div id="chooseWorkspace" class="chooseSomething" style="padding: 25px 0 25px 0;display:none;">
163
+ <label for="selectPodioWorksapce"><strong>Choose a workspace</strong></label>
164
+ <select id="selectPodioWorkspace">
165
+ </select>
166
+ </div>
167
+ </div>
168
+ </div>
169
+ <!-- End -->
170
+
171
+ <!-- Uninstaller -->
172
+ <div class="tab-pane" id="uninstaller">
173
+ <input type="button" id="uninstall" class="btn" value="uninstall">
174
+ </div>
175
+ <!-- End -->
176
+
177
+ </div>
178
+
179
+ </div>
180
+ </div>
181
+ </div>
182
+ </div>
183
+
184
+ <%= javascript_include_tag "alliance_podio_plugin/configure" %>
@@ -0,0 +1 @@
1
+ <h2>README</h2>
@@ -0,0 +1,33 @@
1
+ <div class="container" style="margin-bottom: 25px;">
2
+ <div class="">
3
+ <div class="row-fluid">
4
+ <h4>Please provide a valid podio account</h4>
5
+
6
+ <div class="input-prepend">
7
+ <span class="add-on">Username</span>
8
+ <input class="span12" id="username" type="text" placeholder="">
9
+ </div>
10
+ <br />
11
+ <div class="input-prepend">
12
+ <span class="add-on">Password</span>
13
+ <input class="span12" id="password" type="password" placeholder="">
14
+ </div>
15
+ <br />
16
+ <div class="input-prepend">
17
+ <span class="add-on">Podio API Key</span>
18
+ <input class="span12" id="podioApiKey" type="text" placeholder="">
19
+ </div>
20
+ <br />
21
+ <div class="input-prepend">
22
+ <span class="add-on">Podio Secret Key</span>
23
+ <input class="span12" id="podioSecretKey" type="text" placeholder="">
24
+ </div>
25
+ <br />
26
+ <div>
27
+ <input type="button" id="submit" class="btn" value="authenticate">
28
+ </div>
29
+ </div>
30
+ </div>
31
+ </div>
32
+
33
+ <%= javascript_include_tag "alliance_podio_plugin/installer" %>
@@ -0,0 +1 @@
1
+ <%= yield %>
@@ -0,0 +1,5 @@
1
+ SERVICE_ACCOUNT_NAME : serviceAccountName
2
+ SERVICE_ACCOUNT_PASS : serviceAccountPass
3
+ PODIO_API_KEY : podioApiKey
4
+ PODIO_SECRET_KEY : podioSecretKey
5
+ PODIO_WORKSPACE : currentWorkspace
data/config/routes.rb ADDED
@@ -0,0 +1,42 @@
1
+ Rails.application.routes.draw do
2
+
3
+ # Mandatory routes
4
+ get "/podio/engine/readme" => "engine#index"
5
+ get "/podio/engine/installer" => "engine#installer"
6
+ get "/podio/engine/configure" => "engine#configure"
7
+
8
+ # Mandatory installer routes
9
+ post "/podio/installer/before_process" => "installer#before_process"
10
+ post "/podio/installer/core_process" => "installer#core_process"
11
+ post "/podio/installer/post_process" => "installer#post_process"
12
+ post "/podio/installer/uninstall" => "installer#uninstall"
13
+
14
+ # Optional routes
15
+ get "engine/services"
16
+
17
+ # Authentication routes
18
+ # match '/podio/auth/podio' => 'sessions#create_session'
19
+ # match '/podio/auth/podio/callback' => 'sessions#success_callback'
20
+ match '/podio/auth/podio/delete' => 'sessions#delete_session'
21
+ match '/podio/auth/podio_as_user' => 'sessions#create_session_as_user'
22
+ match '/podio/auth/podio_change_user' => 'sessions#change_session_as_user'
23
+
24
+ # Utility routes
25
+ get '/ext/podio/data/:appid/:fields/:order/:limit/:offset' => 'podio#get_podio_items', :constraints => { :fields => /([a-zA-Z]+\-{0,1}[a-zA-Z]+(%7){0,1})+/ }
26
+ get '/ext/podio/data/:appid/:fields/:order' => 'podio#get_podio_items', :constraints => { :fields => /([a-zA-Z]+\-{0,1}[a-zA-Z]+(%7){0,1})+/ }
27
+ get '/ext/podio/data/:appid/:fields/:order/:limit' => 'podio#get_podio_items', :constraints => { :fields => /([a-zA-Z]+\-{0,1}[a-zA-Z]+(%7){0,1})+/ }
28
+ get '/ext/podio/data/:appid/:fields/:order/:offset' => 'podio#get_podio_items', :constraints => { :fields => /([a-zA-Z]+\-{0,1}[a-zA-Z]+(%7){0,1})+/ }
29
+ get '/ext/podio/data/:appid/:fields' => 'podio#get_podio_items', :constraints => { :fields => /([a-zA-Z]+\-{0,1}[a-zA-Z]+(%7){0,1})+/ }
30
+
31
+ # Servicing routes
32
+ get '/podio/app/active/:appid' => 'podio#get_podio_app_status'
33
+ post '/podio/user/login' => 'podio#check_user_login'
34
+ get '/podio/data/orgs' => 'podio#get_list_of_organizations_of_user'
35
+ get '/podio/orgs/space/:space' => 'podio#get_list_of_apps_from_workspace'
36
+ post '/podio/user/manipulate' => 'services#update_or_create_podio_service_account'
37
+ get '/podio/orgs/curspace' => 'services#get_current_podio_workspace'
38
+ post '/podio/orgs/space/manipulate/' => 'services#set_current_podio_workspace'
39
+ get '/podio/orgs/curspace/apps' => 'podio#get_list_of_apps_for_elements'
40
+ get '/podio/user/current' => 'services#get_current_podio_user'
41
+
42
+ end
@@ -0,0 +1,107 @@
1
+ #
2
+ # Symmetric Encryption for Ruby
3
+ #
4
+ ---
5
+ # For the development and test environments the test symmetric encryption keys
6
+ # can be placed directly in the source code.
7
+ # And therefore no RSA private key is required
8
+ development: &development_defaults
9
+ key: 1234567890ABCDEF1234567890ABCDEF
10
+ iv: 1234567890ABCDEF
11
+ cipher_name: aes-128-cbc
12
+ encoding: :base64strict
13
+
14
+ test:
15
+ <<: *development_defaults
16
+
17
+ release:
18
+ # Since the key to encrypt and decrypt with must NOT be stored along with the
19
+ # source code, we only hold a RSA key that is used to unlock the file
20
+ # containing the actual symmetric enc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FVDK6WpsiL
38
+ 6tGzE0KZ18AAUA1FwfODrp9Qa1+EtU5aErNsf1uLBRrZkYcCwewyI/c6jb0xN5oc
39
+ coW+ijz/Zh7Y13XGUl+Jq0pwQH2dIlr4mvQ6cnsCgYEAvAWSk5DdsRcL1yf8alIz
40
+ 2WZDUghdLlkjPurOnf50SjNMVs46qp5RQdNpNE1XLaSJVnH1LGYJOA5HmTFb5UN6
41
+ wkQ3RU+eQvXAgOPX3zjL4bJ3WO7kVlY+EI0QdRqBWHn/m7GmrLul6Bt0QFYO/Mby
42
+ OJc4EdQ9rECX2KhP6SA7GwECgYEAojQJNMqZMUHys6zKgkU5aFQJCbB/StF/PoBm
43
+ R1SKuaVgFqeSn+Uwv8b4pHsgXmEnDhD3p1cn8CRYK6Kgn0tOtnihZ5spzkHKNsNe
44
+ ySeXoQjxYjLKF1zmmGq4n4VnYnD5pp/x7RzV22B/sMiWKFeECTFDXRrfdTv7ud7P
45
+ +kpEFyECgYEAqsZBfG77Z2kCWNwq/AJqTZk2kZ7gO7TLRjTgwHEYUog9fT5v5KHm
46
+ KWCo0hchTvtYaJ+MM+f6I627O96LTGll3Iw35YdUjQp/Xzlke20wHoXODy8c+y6M
47
+ QSamgNAlTe9il4I07p8xd1O1j/fTJXOuUUxK7pfA0+FGNQtEEdMeDZQ=
48
+ -----END RSA PRIVATE KEY-----
49
+
50
+
51
+ # List Symmetric Key files in the order of current / latest first
52
+ ciphers:
53
+ -
54
+ # Filename containing Symmetric Encryption Key encrypted using the
55
+ # RSA public key derived from the private key above
56
+ key_filename: /etc/rails/keys/podioror_release.key
57
+ iv_filename: /etc/rails/keys/podioror_release.iv
58
+ cipher_name: aes-256-cbc
59
+ # Base64 encode encrypted data without newlines
60
+ encoding: :base64strict
61
+ version: 1
62
+
63
+ production:
64
+ # Since the key to encrypt and decrypt with must NOT be stored along with the
65
+ # source code, we only hold a RSA key that is used to unlock the file
66
+ # containing the actual symmetric encryption key
67
+ private_rsa_key: |
68
+ -----BEG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+xdR9kyWjQA/9tWsJHm29gFc3VcwOvcNz/ll5mgSOgX2sutj5AmML
85
+ Nb1Vtlkq/s2UABHEXQc+VJl4YKaMWF+fj0SYfMsCgYEAoth7OJzs+XM0XTf9etsa
86
+ RLqffFr2mtfQA5+QPuuCsGDt8XaGcsbApibbd97uWA68wxjFY0kQtslMO93+rQoh
87
+ fkyUp5vuxqvl8Stf82c4dmzzjYqiZ3WObZoA2fIokoY6vrQhYWilUiCrsJIXjORK
88
+ Kn92EQfuNo510uYW3zCdufkCgYEA1eQ2xsObOB21AMNL8i1vR0DnllloNNn+XQqv
89
+ CCg6UilYSLMTU5F9tGiksnnh4BQlX0zTcEEYK4Fl2wvbgmcQJOv7zl2jOYRUfTAx
90
+ JorOsw5XDECZn9kZ8sPkSZtB4rF95DFX9eamVL6mrZHOpBsSyyXzsWmqqcKkX2BH
91
+ uBJObu0CgYEA3Uu5hA65WCjP+hABYKNa+XCdd5ljysnPqp3y3BEfu/6QL9wQRLOy
92
+ slwapCPQoxxpsEoLLEXsO7Ydw9EJxrePGw6qPji7B+nGUhs6rUlZWVr6lhJV9p3v
93
+ X4YSzkMAbdsaYDh6oqSMN6F4vGnQ+W4uKIFsjGZccH2J6GcaCiW5imk=
94
+ -----END RSA PRIVATE KEY-----
95
+
96
+
97
+ # List Symmetric Key files in the order of current / latest first
98
+ ciphers:
99
+ -
100
+ # Filename containing Symmetric Encryption Key encrypted using the
101
+ # RSA public key derived from the private key above
102
+ key_filename: /etc/rails/keys/podioror_production.key
103
+ iv_filename: /etc/rails/keys/podioror_production.iv
104
+ cipher_name: aes-256-cbc
105
+ # Base64 encode encrypted data without newlines
106
+ encoding: :base64strict
107
+ version: 1
@@ -0,0 +1,5 @@
1
+ require "rxcms-podio_plugin/engine"
2
+
3
+ module RxcmsPodioPlugin
4
+ require "rxcms-podio_plugin/classes/executor"
5
+ end
@@ -0,0 +1,185 @@
1
+ module RxcmsPodioPlugin
2
+
3
+ class Executor
4
+ def self.execute(placeholder, attrs, exts)
5
+ # Check if placeholder/element template is bound with a podio item, if not, return static HTML content.
6
+ if (!placeholder.MetadataAssociation.nil?)
7
+ # Just get one app for one placeholder/element
8
+ if (placeholder.MetadataAssociation.length == 1)
9
+ # Check if the items of podio app are specified; if not, show error
10
+ if (!attrs['configs'].nil?)
11
+ if (attrs['configs']['items'].nil?)
12
+ return "{{[rxcms-podio-plugin]WARNING: The items parameter for a podio app for element was not found}}"
13
+ end
14
+ else
15
+ return "{{[rxcms-podio-plugin]WARNING: The configs parameter for element was not found}}"
16
+ end
17
+
18
+ placeholderTemplate = placeholder.value.strip
19
+ podio = (placeholder.MetadataAssociation.first).destId
20
+
21
+ if (!podio.nil?)
22
+ podioApp = Metadata.find(podio)
23
+
24
+ if (!podioApp.nil?)
25
+ appId = podioApp.value
26
+
27
+ contentResult = ''
28
+ listItems = attrs['configs']['items'].split('|')
29
+ listItems.each { |i| i.strip }
30
+
31
+ # logger.debug(listItems.inspect)
32
+ # Check if the podio app exists?, if not, raise an awesome error
33
+
34
+ # logger.debug(appId);
35
+ if (AbstractApplication.app_exists?(appId) == false)
36
+ return "{{[rxcms-podio-plugin]WARNING: The \"#{podioApp.key.strip}\" app doesn't exist or service account doesn't have access to it}}"
37
+ end
38
+
39
+ # Use internal method to get a list of items from that podio app
40
+ contentObjs = get_podio_items(appId, listItems)
41
+ # logger.debug(contentObjs.inspect)
42
+
43
+ if (attrs['mode'] == 'multiple')
44
+
45
+ return "{{[rxcms-podio-plugin]WARNING: The mode \"multiple\" is currently not supported}}"
46
+
47
+ elsif (attrs['mode'] == 'alternate')
48
+
49
+ if (attrs['configs']['tple'].nil? && attrs['configs']['tplo'].nil?)
50
+ return "[rxcms-podio-plugin]WARNING: Odd aka. \"&tple\" & even aka. \"&tplo\" template haven't been defined"
51
+ else
52
+ evenTpl = attrs['configs']['tple']
53
+ oddTpl = attrs['configs']['tplo']
54
+
55
+ # Load even and odd template from database
56
+ even = Metadata.first({ :conditions => ['key = ? and cat = ? and sites_id = ?',
57
+ evenTpl, 'placeholder', exts[:appid]
58
+ ]})
59
+
60
+ odd = Metadata.first({ :conditions => ['key = ? and cat = ? and sites_id = ?',
61
+ oddTpl, 'placeholder', exts[:appid]
62
+ ]})
63
+
64
+ if (!odd.nil? && !even.nil?)
65
+ oddContent = odd.value.strip
66
+ evenContent = even.value.strip
67
+ rCount = 0
68
+
69
+ contentObjs.each do |obj|
70
+ parsedObjs = Array.new
71
+ objectContent = ''
72
+
73
+ if (rCount % 2 == 0)
74
+ parsedObjs = evenContent.scan(/\[\[\$[a-zA-Z\-]+\]\]/)
75
+ objectContent = evenContent
76
+ else
77
+ parsedObjs = oddContent.scan(/\[\[\$[a-zA-Z\-]+\]\]/)
78
+ objectContent = oddContent
79
+ end
80
+
81
+ # logger.debug(parsedObjs.inspect)
82
+
83
+ parsedObjs.each do |pobj|
84
+ tpObj = pobj.gsub(/[^a-zA-Z\-]/, '')
85
+
86
+ # logger.debug(obj[tpObj].inspect)
87
+
88
+ if (!obj[tpObj].nil?)
89
+ objectContent = objectContent.gsub(pobj, obj[tpObj])
90
+ else
91
+ objectContent = objectContent.gsub(pobj, '')
92
+ end
93
+
94
+ end
95
+
96
+ contentResult << objectContent
97
+ rCount += 1
98
+ end
99
+
100
+ else
101
+ return "{{[rxcms-podio-plugin]WARNING: Either even, odd or both templates are missing}}"
102
+ end
103
+ end
104
+
105
+ elsif (attrs['mode'] == 'single')
106
+
107
+ contentObjs.each do |obj|
108
+ objectContent = placeholderTemplate.strip
109
+ parsedObjs = objectContent.scan(/\[\[\$[a-zA-Z\-]+\]\]/)
110
+
111
+ parsedObjs.each do |pobj|
112
+ tpObj = pobj.gsub(/[^a-zA-Z\-]/, '')
113
+
114
+ if (!obj[tpObj].nil?)
115
+ objectContent = objectContent.gsub(pobj, obj[tpObj])
116
+ else
117
+ objectContent = objectContent.gsub(pobj, '')
118
+ end
119
+ end
120
+
121
+ contentResult << objectContent
122
+ end
123
+
124
+ else
125
+
126
+ return "{{[rxcms-podio-plugin]WARNING: The mode \"#{attrs['mode']}\" is not supported}}"
127
+
128
+ end
129
+
130
+ contentResult.html_safe
131
+ else
132
+ placeholder.value.strip.html_safe
133
+ end
134
+ else
135
+ placeholder.value.strip.html_safe
136
+ end
137
+
138
+ else
139
+ placeholder.value.strip.html_safe
140
+ end
141
+ else
142
+ placeholder.value.strip.html_safe
143
+ end
144
+ end
145
+
146
+ # Input: podio app id, arrays of string and a set of attributes
147
+ # Output: an empty array or an array of data
148
+ def self.get_podio_items(podioAppId, fields = [], attrs = {
149
+ :order => "ASC",
150
+ :limit => 30,
151
+ :offset => 0
152
+ })
153
+ appid = podioAppId.to_i
154
+ order = attrs[:order].nil? ? "ASC" : attrs[:order].strip
155
+ limit = attrs[:limit].nil? ? 30 : attrs[:limit]
156
+ offset = attrs[:offset].nil? ? 0 : attrs[:offset]
157
+
158
+ if (fields.length > 0)
159
+ appFieldsArray = Array.new
160
+ fields.each do |t|
161
+ tHash = Hash.new
162
+
163
+ tHash[:external_id] = t
164
+ tHash[:simple] = true
165
+
166
+ appFieldsArray << tHash
167
+ end
168
+
169
+ data = nil
170
+ if (defined?(RxcmsPodioPlugin))
171
+ data = AbstractItem.range(appid, appFieldsArray, {:order => order, :offset => offset, :limit => limit})
172
+ end
173
+
174
+ if (!data.nil?)
175
+ return data
176
+ else
177
+ return []
178
+ end
179
+ else
180
+ return []
181
+ end
182
+ end
183
+ end
184
+
185
+ end