/** * Generate a prefix for the History system for the given Kolab data. * * @param Horde_Kolab_Storage_Data $data The data object. * * @return string The History prefix. */ public static function getPrefix(Horde_Kolab_Storage_Data $data) { $app = self::_type2app($data->getType()); if (empty($app)) { Horde::log(sprintf('Unsupported app type: %s', $data->getType()), 'WARN'); return false; } // Determine share id $user = $data->getAuth(); $folder = $data->getPath(); $share_id = ''; $all_shares = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Share')->create($app)->listAllShares(); foreach ($all_shares as $id => $share) { if ($folder == $share->get('folder')) { $share_id = $id; break; } } // Bail out if we are unable to determine the share id. if (empty($share_id)) { Horde::log(sprintf('HISTORY: share_id not found. Can\'t compute history prefix for user: %s, folder: %s', $user, $folder), 'WARN'); return false; } return $app . ':' . $share_id . ':'; }
/** * Build the HTML for the other galleries widget content. * * @param Horde_View $view The view object. */ protected function _getOtherGalleries(&$view) { $owner = $this->_view->gallery->get('owner'); // Set up the tree $tree = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Tree')->create('otherAnselGalleries_' . md5($owner), 'Javascript', array('class' => 'anselWidgets')); try { $galleries = $GLOBALS['injector']->getInstance('Ansel_Storage')->listGalleries(array('attributes' => $owner)); } catch (Ansel_Exception $e) { Horde::log($e, 'ERR'); return; } foreach ($galleries as $gallery) { $parents = $gallery->get('parents'); if (empty($parents)) { $parent = null; } else { $parents = explode(':', $parents); $parent = array_pop($parents); } $img = (string) Ansel::getImageUrl($gallery->getKeyImage(Ansel::getStyleDefinition('ansel_default')), 'mini', true); $link = Ansel::getUrlFor('view', array('gallery' => $gallery->id, 'slug' => $gallery->get('slug'), 'view' => 'Gallery'), true); $tree->addNode(array('id' => $gallery->id, 'parent' => $parent, 'label' => $gallery->get('name'), 'expanded' => $gallery->id == $this->_view->gallery->id, 'params' => array('icon' => $img, 'url' => $link))); } Horde::startBuffer(); $tree->sort('label'); $tree->renderTree(); $view->tree = Horde::endBuffer(); $GLOBALS['injector']->getInstance('Horde_Core_Factory_Imple')->create('Ansel_Ajax_Imple_ToggleOtherGalleries', array('id' => 'othergalleries-toggle')); }
/** * Return the HTML representing this widget. * * @return string The HTML for this widget. */ public function html() { if (!$GLOBALS['conf']['faces']['driver']) { return ''; } $this->_faces = $GLOBALS['injector']->getInstance('Ansel_Faces'); $this->_owner = $this->_view->gallery->get('owner'); try { $this->_count = $this->_faces->countOwnerFaces($this->_owner); } catch (Ansel_Exception $e) { Horde::log($e->getMessage(), 'ERR'); $this->_count = 0; } if (empty($this->_count)) { return null; } $this->_title = Horde::url('faces/search/owner.php')->add('owner', $this->_owner)->link() . sprintf(_("People in galleries owned by %s (%d of %d)"), $this->_owner, min(12, $this->_count), number_format($this->_count)) . '</a>'; $html = $this->_htmlBegin(); $results = $this->_faces->ownerFaces($this->_owner, 0, 12, true); $html .= '<div style="display: block' . ';background:' . $this->_style->background . ';width:100%;max-height:300px;overflow:auto;" id="faces_widget_content" >'; foreach ($results as $face) { $facename = htmlspecialchars($face['face_name']); $html .= '<a href="' . Ansel_Faces::getLink($face) . '" title="' . $facename . '">' . '<img src="' . $this->_faces->getFaceUrl($face['image_id'], $face['face_id'], 'mini') . '" style="padding-bottom: 5px; padding-left: 5px" alt="' . $facename . '" /></a>'; } return $html . '</div>' . $this->_htmlEnd(); }
/** */ protected function _initOb($params) { global $injector; $this->_params = $params; switch ($this->_params['driver']) { case 'cache': $ob = new Horde_Imap_Client_Cache_Backend_Cache(array_filter(array('cacheob' => $injector->getInstance('Horde_Cache'), 'lifetime' => isset($this->_params['lifetime']) ? $this->_params['lifetime'] : null))); break; case 'hashtable': $ob = new Horde_Imap_Client_Cache_Backend_Hashtable(array_filter(array('hashtable' => $injector->getInstance('Horde_HashTable'), 'lifetime' => isset($this->_params['lifetime']) ? $this->_params['lifetime'] : null))); break; case 'none': $ob = new Horde_Imap_Client_Cache_Backend_Null(); break; case 'nosql': $ob = new Horde_Imap_Client_Cache_Backend_Mongo(array('mongo_db' => $injector->getInstance('Horde_Nosql_Adapter'))); break; case 'sql': $ob = new Horde_Imap_Client_Cache_Backend_Db(array('db' => $injector->getInstance('Horde_Db_Adapter'))); break; default: $this->_params['driver'] = 'none'; Horde::log('IMAP caching has been disabled for this session due to an error', 'WARN'); $ob = new Horde_Imap_Client_Cache_Backend_Null(); break; } $this->backend = $ob; }
/** * Load FB content */ private function _loadFB() { if ($this->_fb) { return true; } if (!$conf['facebook']['enabled']) { $this->_fb = PEAR::raiseError(_("No Facebook integration exists.")); return false; } // Check FB user config $fbp = unserialize($prefs->getValue('facebook')); if (!$fbp || empty($fbp['uid'])) { $this->_fb = PEAR::raiseError(_("User has no link.")); return false; } try { $facebook = $GLOBALS['injector']->getInstance('Horde_Service_Facebook'); } catch (Horde_Exception $e) { $error = PEAR::raiseError($e->getMessage(), $e->getCode()); Horde::log($error, 'ERR'); return $error; } $this->_fb->auth->setUser($fbp['uid'], $fbp['sid'], 0); return true; }
public function logout() { $entry = sprintf('User %s [%s] logged out of Horde', $GLOBALS['registry']->getAuth(), $_SERVER['REMOTE_ADDR']); Horde::log($entry, 'NOTICE'); $GLOBALS['registry']->clearAuth(); $this->urlFor(array('controller' => 'index', 'action' => 'login'))->redirect(); }
/** */ public function uploadNotification() { global $conf, $injector, $prefs, $registry; $gallery = $injector->getInstance('Ansel_Storage')->getGallery($this->vars->g); switch ($this->vars->s) { case 'twitter': $url = Ansel::getUrlFor('view', array('view' => 'Gallery', 'gallery' => $gallery->id), true); if (!empty($conf['urlshortener'])) { try { $url = $injector->getInstance('Horde_Service_UrlShortener')->shorten($url->setRaw(true)); } catch (Horde_Service_UrlShortener_Exception $e) { Horde::log($e, 'ERR'); header('HTTP/1.1 500'); } } $text = sprintf(_("New images uploaded to %s. %s"), $gallery->get('name'), $url); $token = unserialize($prefs->getValue('twitter')); if (empty($token['key']) && empty($token['secret'])) { $pref_link = $registry->getServiceLink('prefs', 'horde')->add('group', 'twitter')->link(); throw new Ansel_Exception(sprintf(_("You have not properly connected your Twitter account with Horde. You should check your Twitter settings in your %s."), $pref_link . _("preferences") . '</a>')); } $twitter = $injector->getInstance('Horde_Service_Twitter'); $auth_token = new Horde_Oauth_Token($token['key'], $token['secret']); $twitter->auth->setToken($auth_token); try { return $twitter->statuses->update($text); } catch (Horde_Service_Twitter_Exception $e) { Horde::log($e, 'ERR'); header('HTTP/1.1 500'); } } }
/** */ public function gc() { global $registry; if (empty($this->_params['lifetime'])) { return; } /* Keep a file in the static directory that prevents us from doing * garbage collection more than once a day. */ $curr_time = time(); $static_dir = $registry->get('fileroot', 'horde') . '/static'; $static_stat = $static_dir . '/gc_cachecss'; $next_run = !is_readable($static_stat) ?: @file_get_contents($static_stat); if (!$next_run || $curr_time > $next_run) { file_put_contents($static_stat, $curr_time + 86400); } if (!$next_run || $curr_time < $next_run) { return; } $curr_time -= $this->_params['lifetime']; $removed = 0; foreach (glob($static_dir . '/*.css') as $file) { if ($curr_time > filemtime($file)) { @unlink($file); ++$removed; } } Horde::log(sprintf('Cleaned out static CSS files (removed %d file(s)).', $removed), 'DEBUG'); }
/** * @throws Turba_Exception */ public function execute() { // If cancel was clicked, return false. if ($this->_vars->get('submitbutton') == _("Cancel")) { Horde::url('', true)->redirect(); } if (!$GLOBALS['registry']->getAuth() || $this->_addressbook->get('owner') != $GLOBALS['registry']->getAuth()) { throw new Turba_Exception(_("You do not have permissions to delete this address book.")); } $driver = $GLOBALS['injector']->getInstance('Turba_Factory_Driver')->create($this->_addressbook->getName()); if ($driver->hasCapability('delete_all')) { try { $driver->deleteAll(); } catch (Turba_Exception $e) { Horde::log($e->getMessage(), 'ERR'); throw $e; } } // Address book successfully deleted from backend, remove the share. try { $GLOBALS['injector']->getInstance('Turba_Shares')->removeShare($this->_addressbook); } catch (Horde_Share_Exception $e) { Horde::log($e->getMessage(), 'ERR'); throw new Turba_Exception($e); } if ($GLOBALS['session']->get('turba', 'source') == Horde_Util::getFormData('deleteshare')) { $GLOBALS['session']->remove('turba', 'source'); } }
/** * Purge completed tasks that were completed before the configured date. * * @return boolean Whether any messages were purged from the mailbox. */ public function execute() { global $injector, $prefs; /* Get the current UNIX timestamp minus the number of days specified * in 'purge_completed_keep'. If a task has a timestamp prior to * this value, it will be deleted. */ $del_time = new Horde_Date($_SERVER['REQUEST_TIME'] - $prefs->getValue('purge_completed_keep') * 86400); $del_time = $del_time->timestamp(); $tasklists = Nag::listTasklists(true, Horde_Perms::DELETE, false); $tasks = Nag::listTasks(array('completed' => Nag::VIEW_COMPLETE, 'tasklists' => array_keys($tasklists))); $factory = $GLOBALS['injector']->getInstance('Nag_Factory_Driver'); $count = 0; $tasks->reset(); while ($task = $tasks->each()) { if ($task->completed_date && $task->completed_date < $del_time || !$task->completed_date && $task->modified && $task->modified->timestamp() < $del_time) { try { $factory->create($task->tasklist)->delete($task->id); ++$count; } catch (Nag_Exception $e) { Horde::log($e->getMessage(), 'ERR'); } } } $GLOBALS['notification']->push(sprintf(ngettext("Purging %d completed task.", "Purging %d completed tasks.", $count), $count), 'horde.message'); return true; }
/** * Log error message. * * @param string $level Level to log at. * * @return boolean True if message was logged. */ public function log($level = 'ERR') { if ($this->logged) { return false; } Horde::log($this, $level); $this->logged = true; return true; }
/** * Returns data needed to output quota. * * @param string $mailbox Mailbox to query. * @param boolean $force If true, ignore 'interval' config option and * force quota display. * * @return array|boolean Array with these keys: class, message, percent. * Returns false if no updated quota information. */ public function quota($mailbox = null, $force = true) { global $injector, $session; $qconfig = $injector->getInstance('IMP_Factory_Imap')->create()->config->quota; if (!$qconfig) { return false; } $qlist = array(); if (!is_null($mailbox)) { $mailbox = IMP_Mailbox::get($mailbox); if ($mailbox->nonimap) { return false; } if (!$force) { $qlist = $session->get('imp', self::SESSION_INTERVAL_KEY, $session::TYPE_ARRAY); if (isset($qlist[strval($mailbox)]) && time() < $qlist[strval($mailbox)]) { return false; } } } try { $quotaDriver = $injector->getInstance('IMP_Quota'); $quota = $quotaDriver->getQuota($mailbox); } catch (IMP_Exception $e) { Horde::log($e, 'ERR'); return false; } $qlist[strval($mailbox)] = $qconfig['params']['interval'] + time(); $session->set('imp', self::SESSION_INTERVAL_KEY, $qlist); if (empty($quota)) { return false; } $strings = $quotaDriver->getMessages(); list($calc, $unit) = $quotaDriver->getUnit(); $ret = array('class' => '', 'percent' => 0); if ($quota['limit'] != 0) { $quota['usage'] = $quota['usage'] / $calc; $quota['limit'] = $quota['limit'] / $calc; $ret['percent'] = $quota['usage'] * 100 / $quota['limit']; if ($ret['percent'] >= 90) { $ret['class'] = 'quotaalert'; } elseif ($ret['percent'] >= 75) { $ret['class'] = 'quotawarn'; } $ret['message'] = sprintf($strings['short'], $ret['percent'], $quota['limit'], $unit); $ret['percent'] = sprintf("%.2f", $ret['percent']); } elseif ($quotaDriver->isHiddenWhenUnlimited()) { return false; } elseif ($quota['usage'] != 0) { $quota['usage'] = $quota['usage'] / $calc; $ret['message'] = sprintf($strings['nolimit_short'], $quota['usage'], $unit); } else { $ret['message'] = _("No limit"); } return $ret; }
/** */ protected function _handleAutoCompleter($input) { $locs = array(); try { $locs = $GLOBALS['injector']->getInstance('Ansel_Storage')->searchLocations($input); } catch (Ansel_Exception $e) { Horde::log($e, 'ERR'); } return $locs; }
/** * Checks for triggers that may invalidate the current auth. * These triggers are independent of the credentials. * * @return boolean True if the results of authenticate() are still valid. */ public function validateAuth() { if (!empty($_SERVER[$this->getParam('username_header')]) && $this->_removeScope($_SERVER[$this->getParam('username_header')]) == $GLOBALS['registry']->getAuth('original')) { return true; } // Consider this a session expiration. $this->setError(Horde_Auth::REASON_SESSION); Horde::log('Shibboleth authentication expired for user ' . $GLOBALS['registry']->getAuth(), 'INFO'); return false; }
/** * Constructor. */ public function __construct() { global $conf; $this->active = false; if (!empty($conf['tos']['file'])) { if (file_exists($conf['tos']['file'])) { $this->active = true; } else { Horde::log('Terms of Service Agreement file was not found: ' . $conf['tos']['file'], 'ERR'); } } }
/** * Log error message. * * @param string $level Level to log at. * * @return boolean True if message was logged. */ public function log($level = 'ERR') { if ($this->logged) { return false; } Horde::log($this, $level); if (($previous = $this->getPrevious()) && isset($previous->details)) { Horde::log($previous->details, $level); } $this->logged = true; return true; }
/** * Convert a date to an epoch. * * @param array $values The array to convert. * * @return int Time. */ private function convert2epoch($values) { Horde::log(sprintf('Converting to epoch %s', print_r($values, true)), 'DEBUG'); if (is_array($values)) { $temp = $this->cleanArray($values); $epoch = gmmktime($temp['hour'], $temp['minute'], $temp['second'], $temp['month'], $temp['mday'], $temp['year']); } else { $epoch = $values; } Horde::log(sprintf('Converted <%s>', $epoch), 'DEBUG'); return $epoch; }
/** * Return the IMP_Search instance. * * @return IMP_Search The singleton instance. */ public function create(Horde_Injector $injector) { try { $this->_instance = $GLOBALS['session']->get('imp', 'search'); } catch (Exception $e) { Horde::log('Could not unserialize stored IMP_Search object.', 'DEBUG'); } if (!$this->_instance) { $this->_instance = new IMP_Search(); } Horde_Shutdown::add($this); return $this->_instance; }
/** * Return the IMP_Contacts instance. * * @return IMP_Contacts The singleton instance. */ public function create(Horde_Injector $injector) { try { $this->_instance = $GLOBALS['session']->get('imp', self::SESS_KEY); } catch (Exception $e) { Horde::log('Could not unserialize stored IMP_Contacts object.', 'DEBUG'); } if (is_null($this->_instance)) { $this->_instance = new IMP_Contacts(); } Horde_Shutdown::add($this); return $this->_instance; }
/** * Call a Horde hook. * * WARNING: Throwing exceptions is expensive, so use callHook() with care * and cache the results if you going to use the results more than once. * * @param string $hook The hook function to call. * @param string $app The hook application. * @param array $args An array of any arguments to pass to the hook * function. * * @return mixed The results of the hook. * @throws Horde_Exception Thrown on error from hook code. * @throws Horde_Exception_HookNotSet Thrown if hook is not active. */ public function callHook($hook, $app = 'horde', array $args = array()) { if (!$this->hookExists($hook, $app)) { throw new Horde_Exception_HookNotSet(); } try { Horde::log(sprintf('Hook %s in application %s called.', $hook, $app), 'DEBUG'); return call_user_func_array(array($this->_apps[$app], $hook), $args); } catch (Horde_Exception $e) { Horde::log($e, 'ERR'); throw $e; } }
/** */ public function getQuota($mailbox = null) { try { $quota = $GLOBALS['injector']->getInstance('Horde_Core_Hooks')->callHook('quota', 'imp', array($this->_params)); } catch (Horde_Exception_HookNotSet $e) { throw new IMP_Exception($e->getMessage()); } if (count($quota) != 2) { Horde::log('Incorrect number of return values from quota hook.', 'ERR'); throw new IMP_Exception(_("Unable to retrieve quota")); } return array('limit' => $quota[1], 'usage' => $quota[0]); }
/** * Expects: * $vars * $registry * $notification */ public function run() { extract($this->_params, EXTR_REFS); /* Set up the form variables and the form. */ $form_submit = $vars->get('submitbutton'); $channel_id = $vars->get('channel_id'); try { $channel = $GLOBALS['injector']->getInstance('Jonah_Driver')->getChannel($channel_id); } catch (Exception $e) { Horde::log($e, 'ERR'); $notification->push(_("Invalid channel specified for deletion."), 'horde.message'); Horde::url('channels')->redirect(); exit; } /* If not yet submitted set up the form vars from the fetched channel. */ if (empty($form_submit)) { $vars = new Horde_Variables($channel); } /* Check permissions and deny if not allowed. */ if (!Jonah::checkPermissions(Jonah::typeToPermName($channel['channel_type']), Horde_Perms::DELETE, $channel_id)) { $notification->push(_("You are not authorised for this action."), 'horde.warning'); throw new Horde_Exception_AuthenticationFailure(); } $title = sprintf(_("Delete News Channel \"%s\"?"), $vars->get('channel_name')); $form = new Horde_Form($vars, $title); $form->setButtons(array(_("Delete"), _("Do not delete"))); $form->addHidden('', 'channel_id', 'int', true, true); $msg = _("Really delete this News Channel? All stories created in this channel will be lost!"); $form->addVariable($msg, 'confirm', 'description', false); if ($form_submit == _("Delete")) { if ($form->validate($vars)) { $form->getInfo($vars, $info); try { $delete = $GLOBALS['injector']->getInstance('Jonah_Driver')->deleteChannel($info); $notification->push(_("The channel has been deleted."), 'horde.success'); Horde::url('channels')->redirect(); exit; } catch (Exception $e) { $notification->push(sprintf(_("There was an error deleting the channel: %s"), $e->getMessage()), 'horde.error'); } } } elseif (!empty($form_submit)) { $notification->push(_("Channel has not been deleted."), 'horde.message'); Horde::url('channels')->redirect(); exit; } $GLOBALS['page_output']->header(array('title' => $title)); $notification->notify(array('listeners' => 'status')); $form->renderActive(null, $vars, Horde::selfUrl(), 'post'); $GLOBALS['page_output']->footer(); }
/** * Run the task. Currently generates: * - screen image * - mini image (using the square pref. if set) * - thumb (currently, only the image's gallery's configured style) * */ public function run() { global $prefs; foreach ($this->_images as $id) { try { $image = $GLOBALS['injector']->getInstance('Ansel_Storage')->getImage($id); $image->createView('screen', null, $prefs->getValue('watermark_auto') ? $prefs->getValue('watermark_text', '') : ''); $image->createView('thumb'); $image->createView('mini'); } catch (Ansel_Exception $e) { Horde::log($e->getMessage, 'ERR'); } } }
/** * Returns a hash of group IDs and group names that the user has access * to. * * @return object Object with the following properties: * - groups: (array) Groups hash. */ public function listGroups() { $result = new stdClass(); try { $groups = $GLOBALS['injector']->getInstance('Horde_Group')->listAll(empty($GLOBALS['conf']['share']['any_group']) && !$GLOBALS['registry']->isAdmin() ? $GLOBALS['registry']->getAuth() : null); if ($groups) { asort($groups); $result->groups = $groups; } } catch (Horde_Group_Exception $e) { Horde::log($e); } return $result; }
/** * Takes a SOAP request and returns the result. * * @param string The raw request string. * * @return string The XML encoded response from the server. */ function getResponse($request) { if ($request == 'disco' || $request == 'wsdl') { /*@TODO Replace with subcalls for disco and wsdl generation from the old SOAP driver. */ //$handler = new Horde_Rpc_Soap($this->_params); //return $handler->getResponse($request); } /* We can't use Horde_Util::bufferOutput() here for some reason. */ $beginTime = time(); ob_start(); $this->_server->handle($request); Horde::log(sprintf('SOAP call: %s(%s) by %s serviced in %d seconds, sent %d bytes in response', $GLOBALS['__horde_rpc_PhpSoap']['lastMethodCalled'], implode(', ', array_map(create_function('$a', 'return is_array($a) ? "Array" : $a;'), $GLOBALS['__horde_rpc_PhpSoap']['lastMethodParams'])), $GLOBALS['registry']->getAuth(), time() - $beginTime, ob_get_length()), 'INFO'); return ob_get_clean(); }
/** * Form variables used: * - input */ protected function _handle(Horde_Variables $vars) { global $injector; $args = array('html' => !empty($vars->html)); if (isset($vars->locale)) { $args['locale'] = $vars->locale; } $input = $vars->get($vars->input); try { return new Horde_Core_Ajax_Response_Prototypejs($injector->getInstance('Horde_Core_Factory_SpellChecker')->create($args, $input)->spellCheck($input)); } catch (Horde_Exception $e) { Horde::log($e, 'ERR'); return array('bad' => array(), 'suggestions' => array()); } }
public function checkAccess($id = null, $permission = Koward::PERM_SHOW) { if ($id === null) { $id = $this->getPermissionId(); } if (!$this->koward->hasAccess($id, $permission)) { $this->koward->notification->push(_("Access denied."), 'horde.error'); Horde::log(sprintf('User %s does not have access to action %s!', $GLOBALS['registry']->getAuth(), $id), 'NOTICE'); if ($GLOBALS['registry']->getAuth()) { $url = $this->urlFor(array('controller' => 'index', 'action' => 'index')); } else { $url = $this->urlFor(array('controller' => 'index', 'action' => 'login')); } $url->redirect(); } }
public function html($active = true) { global $browser, $conf, $registry; if (!$this->contact || !$this->contact->hasPermission(Horde_Perms::READ)) { echo '<h3>' . _("The requested contact was not found.") . '</h3>'; return; } $vars = new Horde_Variables(); $form = new Turba_Form_Contact($vars, $this->contact); $form->setOpenSection(Horde_Util::getFormData('section', 0)); /* Get the contact's history. */ $history = $this->contact->getHistory(); foreach ($history as $what => $when) { $v = $form->addVariable($what == 'created' ? _("Created") : _("Last Modified"), 'object[__' . $what . ']', 'text', false, false); $v->disable(); $vars->set('object[__' . $what . ']', $when); } echo '<div id="Contact"' . ($active ? '' : ' style="display:none"') . '>'; $form->renderInactive($form->getRenderer(), $vars); /* Comments. */ if (!empty($conf['comments']['allow']) && $registry->hasMethod('forums/doComments')) { try { $comments = $registry->call('forums/doComments', array('turba', $this->contact->driver->getName() . '.' . $this->contact->getValue('__key'), 'commentCallback')); } catch (Horde_Exception $e) { Horde::log($e, 'DEBUG'); $comments = array(); } } if (!empty($comments['threads'])) { echo '<br />' . $comments['threads']; } if (!empty($comments['comments'])) { echo '<br />' . $comments['comments']; } echo '</div>'; if ($active && $browser->hasFeature('dom')) { if ($this->contact->hasPermission(Horde_Perms::EDIT)) { $edit = new Turba_View_EditContact($this->contact); $edit->html(false); } if ($this->contact->hasPermission(Horde_Perms::DELETE)) { $delete = new Turba_View_DeleteContact($this->contact); $delete->html(false); } } }
/** * Constructor. * * Searches all installed applications and libraries for migration * directories and builds lists of migrateable modules and directories. * * @param string $basedir Base directory of a Git checkout. If provided * a framework/ sub directory is searched for * migration scripts too. * @param string $pearconf Path to a PEAR configuration file. */ public function __construct($basedir = null, $pearconf = null) { // Loop through all applications. foreach ($GLOBALS['registry']->listAllApps() as $app) { $dir = $GLOBALS['registry']->get('fileroot', $app) . '/migration'; if (is_dir($dir)) { $this->apps[] = $app; $this->_lower[] = Horde_String::lower($app); $this->dirs[] = realpath($dir); } } // Silence PEAR errors. $old_error_reporting = error_reporting(); error_reporting($old_error_reporting & ~E_DEPRECATED); $pear = new PEAR_Config($pearconf); // Loop through local framework checkout. if ($basedir) { $packageFile = new PEAR_PackageFile($pear); foreach (glob($basedir . '/framework/*/migration') as $dir) { $package = $packageFile->fromPackageFile(dirname($dir) . '/package.xml', PEAR_VALIDATE_NORMAL); if ($package instanceof PEAR_Error) { Horde::log(sprintf('%s: %s', $package->getMessage(), print_r($package->getUserInfo(), true)), Horde_Log::ERR); continue; } $this->apps[] = $package->getName(); $this->_lower[] = Horde_String::lower($package->getName()); $this->dirs[] = realpath($dir); } } // Loop through installed PEAR packages. $registry = $pear->getRegistry(); foreach (glob($pear->get('data_dir') . '/*/migration') as $dir) { $package = $registry->getPackage(basename(dirname($dir)), 'pear.horde.org'); if ($package == false) { Horde::log("Ignoring package in directory {$dir}", Horde_Log::WARN); continue; } $app = $package->getName(); if (!in_array($app, $this->apps)) { $this->apps[] = $app; $this->_lower[] = Horde_String::lower($app); $this->dirs[] = realpath($dir); } } error_reporting($old_error_reporting); }
public function execute() { // @TODO $driver should be injected, or at the very least, obtained // via the injector global $driver, $notification; /* Form valid, save data. */ $this->getInfo($this->_vars, $info); foreach ($info['object'] as $info_key => $info_val) { if ($GLOBALS['attributes'][$info_key]['type'] == 'image') { if (!empty($info_val['file'])) { $this->_contact->setValue($info_key, file_get_contents($info_val['file'])); $this->_contact->setValue($info_key . 'type', $info_val['type']); } if (!empty($info_val['orig_file'])) { $this->_contact->setValue($info_key . '_orig', file_get_contents($info_val['orig_file'])); } } else { $this->_contact->setValue($info_key, $info_val); } } $contact = $this->_contact->attributes; unset($contact['__owner']); /* Create Contact. */ try { $key = $driver->add($contact); } catch (Turba_Exception $e) { Horde::log($e, 'ERR'); $key = null; } if ($key) { // Try 3 times to get the new entry. We retry to allow setups like // LDAP replication to work. for ($i = 0; $i < 3; ++$i) { try { $ob = $driver->getObject($key); $notification->push(sprintf(_("%s added."), $ob->getValue('name')), 'horde.success'); $url = empty($info['url']) ? $ob->url('Contact', true) : new Horde_Url($info['url']); $url->redirect(); } catch (Horde_Exception_NotFound $e) { } sleep(1); } } $notification->push(_("There was an error adding the new contact. Contact your system administrator for further help."), 'horde.error'); }