public function _on_watched_dba_create($object) { $ret = array(); //Check if we have data in session, if so use that. $session = new midcom_services_session('org.openpsa.relatedto'); if ($session->exists('relatedto2get_array')) { $relatedto_arr = $session->get('relatedto2get_array'); $session->remove('relatedto2get_array'); } else { $relatedto_arr = org_openpsa_relatedto_plugin::get2relatedto(); } foreach ($relatedto_arr as $k => $rel) { $ret[$k] = array('stat' => false, 'method' => false, 'obj' => false); $rel->fromClass = get_class($object); $rel->fromGuid = $object->guid; if (!$rel->id) { $ret[$k]['method'] = 'create'; $ret[$k]['stat'] = $rel->create(); } else { //In theory we should not ever hit this, but better to be sure. $ret[$k]['method'] = 'update'; $ret[$k]['stat'] = $rel->update(); } $ret[$k]['obj'] = $rel; } }
public static function get_location($when = null) { if (midcom::get('auth')->user) { // Get from user's location log return org_routamc_positioning_user::get_location_for_person(midcom::get('auth')->user->get_storage(), $when); } // Get from session $session = new midcom_services_session(); if (!$session->exists('org_routamc_positioning_user_location')) { return null; } return $session->get('org_routamc_positioning_user_location'); }
// Save request token to session and redirect user $session->set('auth_state', 'start'); $session->set('request_token', $request_token['oauth_token']); $session->set('request_secret', $request_token['oauth_token_secret']); ?> <p><a href="<?php echo $fireeagle->getAuthorizeURL($request_token['oauth_token']); ?> " target="_blank">Authorize this application</a></p> <p><a href="?f=callback">And then click here</a></p> <?php midcom::get()->finish(); _midcom_stop_request(); } elseif (isset($_GET['f']) && $_GET['f'] == 'callback') { // the user has authorized us at FE, so now we can pick up our access token + secret if (!$session->exists('auth_state') || $session->get('auth_state') != 'start') { throw new midcom_error("Out of sequence."); } $fireeagle = new FireEagle($fireeagle_consumer_key, $fireeagle_consumer_secret, $session->get('request_token'), $session->get('request_secret')); $access_token = $fireeagle->getAccessToken(); if (!isset($access_token['oauth_token']) || !is_string($access_token['oauth_token']) || !isset($access_token['oauth_token_secret']) || !is_string($access_token['oauth_token_secret'])) { throw new midcom_error("Failed to get FireEagle access token\n"); } $user->set_parameter('net.yahoo.fireeagle', 'access_key', $access_token['oauth_token']); $user->set_parameter('net.yahoo.fireeagle', 'access_secret', $access_token['oauth_token_secret']); midcom::get()->relocate($_SERVER['SCRIPT_NAME']); // This will exit } ?> <p><a href="?f=start">Start Fire Eagle authentication</a></p> <?php
/** * The initialization event handler creates the captcha passphrase (if necessary). * * @return boolean Indicating Success */ public function _on_initialize() { $request_fieldname = "{$this->name}_session_key"; if (array_key_exists($request_fieldname, $_REQUEST)) { $this->_session_key = $_REQUEST[$request_fieldname]; } else { $hash = $_SERVER['REQUEST_URI']; $this->_session_key = md5($hash); } $session = new midcom_services_session($this->_session_domain); if (!$session->exists($this->_session_key)) { $phrase = midcom_admin_user_plugin::generate_password($this->length); $this->_passphrase = $phrase; $session->set($this->_session_key, $phrase); } else { $this->_passphrase = $session->get($this->_session_key); } return true; }
/** * Store unshown UI messages from the stack to user session. */ function store() { if (count($this->_message_stack) == 0) { // No unshown messages return true; } // We have to be careful what messages to store to session to prevent them // from accumulating $messages_to_store = array(); foreach ($this->_message_stack as $id => $message) { // Check that the messages were not coming from earlier session if (!in_array($id, $this->_messages_from_session)) { $messages_to_store[$id] = $message; } } if (count($messages_to_store) == 0) { // We have only messages coming from earlier sessions, and we ditch those return true; } $session = new midcom_services_session('midcom_services_uimessages'); // Check if some other request has added stuff to session as well if ($session->exists('midcom_services_uimessages_stack')) { $old_stack = $session->get('midcom_services_uimessages_stack'); $messages_to_store = array_merge($old_stack, $messages_to_store); } $session->set('midcom_services_uimessages_stack', $messages_to_store); $this->_message_stack = array(); }
* * No caching is done so far. * * If the session is not valid, a 500 will be triggered. * * @package midcom.helper.datamanager2 * @author The Midgard Project, http://www.midgard-project.org * @copyright The Midgard Project, http://www.midgard-project.org * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License */ global $argc, $argv; $session = new midcom_services_session('midcom_helper_datamanager2_widget_captcha'); if (!isset($argv[0])) { throw new midcom_error_notfound("Missing CAPTCHA session key."); } if ($argc == 0 || !$session->exists($argv[0])) { throw new midcom_error('Failed to generate CAPTCHA, the session key passed is invalid.'); } $passphrase = $session->get($argv[0]); if (empty($passphrase)) { throw new midcom_error('Failed to generate CAPTCHA, no passphrase in session.'); } // Set Captcha options (font must exist!) $options = array('width' => 200, 'height' => 80, 'phrase' => $passphrase, 'imageOptions' => array('font_path' => MIDCOM_ROOT . '/midcom/helper/datamanager2/widget/', 'font_file' => 'captcha-font.ttf', 'background_color' => '#000000', 'text_color' => '#FFFFFF')); /* Generate a new Text_CAPTCHA object, Image driver * This is working at least with Text_CAPTCHAS latest alpha version. Older versions * give missing font error */ $captcha = Text_CAPTCHA::factory('Image'); $result = $captcha->init($options); if (PEAR::isError($result)) {
/** * Clean up after get2session() (in case we cancel or something) * * To be used in case we do not get to call on_created_handle_relatedto() * or some other method that reads and saves the data (and while at it cleans * up after itself) */ function get2session_cleanup() { $session = new midcom_services_session('org.openpsa.relatedto'); if ($session->exists('relatedto2get_array')) { $session->remove('relatedto2get_array'); } }