Posted by pletcher on February 13, 2009 at 6:39am
Jump to:
| Project: | OpenSocial Shindig-Integrator |
| Version: | 6.x-1.x-dev |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed (fixed) |
Issue Summary
Adds the save pref rpc call to allow gadgets to store data inside the application_settings table. Also modifies the application display url to get the data and display it when the gadget is loaded.
Index: shindig_integrator.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/ShindigIntegrator/shindig_integrator/shindig_integrator.module
retrieving revision 1.1
diff -b -r1.1 shindig_integrator.module
89a90
> 'save application prefs',
145a147,153
> $items['pref/set'] = array(
> 'title' => t('Save Prefs'),
> 'description' => t('A place where prefs are saved'),
> 'page callback' => 'pref_set',
> 'access arguments' =>array('save application prefs'),
> 'type' => MENU_CALLBACK);
>
684,686c690,700
< .'&parent='. urlencode('http://'. $_SERVER['HTTP_HOST'])
< . $prefs
< . (isset($_REQUEST['appParams']) ? '&view-params='. urlencode($_REQUEST['appParams']):'')
---
> .'&parent='. urlencode('http://'. $_SERVER['HTTP_HOST']);
>
> $res = db_query("SELECT name, value FROM {application_settings}
> WHERE module_id = %d AND user_id = %d AND application_id = %d", $mod_id, $viewer_id, $gadget->id);
>
> while ($setting = db_fetch_array($res)) {
> $iframe_url .= '&up_' . urlencode($setting['name']) . '=' . urlencode($setting['value']);
> }
>
> $iframe_url .=
> (isset($_REQUEST['appParams']) ? '&view-params='. urlencode($_REQUEST['appParams']):'')
737a757,793
>
> function pref_set() {
> if (empty($_GET['st']) || empty($_GET['name']) || ! isset($_GET['value'])) {
> header("HTTP/1.0 400 Bad Request", true);
> echo "<html><body><h1>400 - Bad Request</h1></body></html>";
> }
> else {
> module_load_include('php', 'shindig_integrator', '/shindig/php/src/common/Config');
> module_load_include('php', 'shindig_integrator', '/shindig/php/src/common/SecurityToken');
> module_load_include('php', 'shindig_integrator', '/shindig/php/src/common/BlobCrypter');
> module_load_include('php', 'shindig_integrator', '/shindig/php/src/common/sample/BasicSecurityToken');
> module_load_include('php', 'shindig_integrator', '/shindig/php/src/common/sample/BasicBlobCrypter');
> module_load_include('php', 'shindig_integrator', '/shindig/php/src/common/sample/Crypto');
> module_load_include('php', 'shindig_integrator', '/shindig/php/config/local');
>
> $st = urldecode(base64_decode($_GET['st']));
> $key = urldecode($_GET['name']);
> $value = urldecode($_GET['value']);
> $token = BasicSecurityToken::createFromToken($st, Config::get('token_max_age'));
> $app_id = $token->getAppId();
> $viewer = $token->getViewerId();
>
> $result_get_mod_id = db_query("SELECT id FROM {user_applications} WHERE user_id = %d AND application_id = %d",
> $viewer, $app_id);
> if(!$result_get_mod_id) {
> return FALSE;
> }
> $record_get_mod_id = db_fetch_object($result_get_mod_id);
> $mod_id = $record_get_mod_id->id;
>
> db_query("INSERT INTO {application_settings} (application_id, user_id, module_id, name, value)
> VALUES (%d, %d, %d, '%s', '%s')
> ON DUPLICATE key UPDATE value = '%s'",
> $app_id, $viewer, $mod_id, $key, $value, $value
> );
> }
> }Index: container.js
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/ShindigIntegrator/shindig_integrator/container.js,v
retrieving revision 1.1
diff -b -r1.1 container.js
21a22
> gadgets.rpc.register('set_pref', this.setUserPref);
65a67,76
>
> gadgets.IfrContainer.prototype.setUserPref = function(editToken, name, value) {
> var elm = $(this.f);
> // we use the security token to tell our backend who this is (app/mod/viewer)
> // since it's the only fail safe way of doing so
> if (elm != undefined) {
> var params = gadgets.container.parseIframeUrl(elm.src);
> jQuery.get('/pref/set', { name : name, value : value, st : params.st });
> }
> };Its not the nicest way in the world, but it works.
| Attachment | Size |
|---|---|
| container-add-savepref.patch | 761 bytes |
| shindig_integrator-add-savepref.patch | 3.09 KB |
Comments
#1
Hi pletcher,
Thanks for patches.
It is really very nice to add this feature to ShindigIntegrator. But there is no UI to save user preferences. Can you please create patch for that also, so that it will be more convenient to test it.
Thanks again.
#2
I'm not entirely sure what you mean here. The gadgets call SavePref however they see fit, so it should be transparent from the Drupal side. Do you want a UI inside Drupal to see the prefs the gadgets have saved?
#3
I want to save user prefs corresponding to any gadget. How can I save them?
For eg. I want to save user to set background color for some gadget. How will I save this?
From where the url you have specified as "pref/set" called. You can take reference from partuza also.
Thanks
#4
/pref/set is at defined on the top of the first patch, its just a wrapper for a db query.
Module preferences will always be saved by the gadget. If the Shindig implementation can handle save prefs, your gadget can implement a save prefs call. All pref saving will be handled by the gadget, so in your example with the background color: you select the background color, and the gadget calls the save prefs to store the value without any user interaction. Alternately, you could implement a 'Save' button inside your gadget which would call the save prefs method.
Does this explain it?
#5
Resolved