/** * Find hanging duplicate marks (that no longer point anywhere) and clear them */ public function _on_execute() { debug_add('_on_execute called'); if (!$this->_config->get('enable_duplicate_search')) { debug_add('Duplicate operations disabled, aborting', MIDCOM_LOG_INFO); return; } // Untill the FIXME below is handled we abort debug_add('Duplicate cleanup disabled since it needs code cleanup for 1.8 Midgfard, aborting', MIDCOM_LOG_ERROR); return; ignore_user_abort(); $qb = new midgard_query_builder('midgard_parameter'); $qb->add_constraint('domain', '=', 'org.openpsa.contacts.duplicates:possible_duplicate'); $qb->add_order('name', 'ASC'); $results = @$qb->execute(); foreach ($results as $param) { try { $obj = midcom::get('dbfactory')->get_object_by_guid($param->name); } catch (midcom_error $e) { debug_add("GUID {$param->name} points to nonexistent person, removing possible duplicate mark", MIDCOM_LOG_INFO); if (!$param->delete()) { debug_add("Failed to delete parameter {$param->guid}, errstr: " . midcom_connection::get_error_string(), MIDCOM_LOG_ERROR); } } } debug_add('Done'); return; }
public function get_top(array $args) { $qb = new midgard_query_builder('fi_openkeidas_diary_activity'); $qb->set_limit(5); $qb->add_order('metadata.score', 'DESC'); $this->data['sports'] = $qb->execute(); }
public function get_read(array $args) { parent::get_read($args); $this->data['groups'] = array(); $this->data['is_challenger'] = $this->is_challenger(); if ($this->data['is_challenger']) { $this->data['groups_url'] = midgardmvc_core::get_instance()->dispatcher->generate_url('index', array(), 'fi_openkeidas_groups'); $this->data['update_url'] = $this->get_url_update(); $this->data['delete_url'] = midgardmvc_core::get_instance()->dispatcher->generate_url('challenge_delete', array('challenge' => $this->object->guid), $this->request); } $activityobject = null; if ($this->object->activity) { $activityobject = fi_openkeidas_diary_activities::get($this->object->activity); } $this->object->activityobject = $activityobject; $this->data['challenger'] = new fi_openkeidas_groups_group($this->object->challenger); $mc = new midgard_collector('fi_openkeidas_diary_challenge_participant', 'challenge', $this->object->id); //$mc->add_constraint('metadata.isapproved', '=', true); $mc->set_key_property('grp'); $mc->execute(); $grp_ids = array_keys($mc->list_keys()); if (count($grp_ids) == 0) { return; } $qb = new midgard_query_builder('fi_openkeidas_groups_group'); $qb->add_constraint('id', 'IN', $grp_ids); $qb->add_order('metadata.score', 'DESC'); $this->data['groups'] = array_map(function ($group) use($activityobject) { $group->url = midgardmvc_core::get_instance()->dispatcher->generate_url('group_read', array('group' => $group->guid), 'fi_openkeidas_groups'); $group->activity = fi_openkeidas_diary_logs::group_duration_this_week($group, $activityobject); return $group; }, $qb->execute()); }
function get_image_str_by_counter($max_count, $photostream_prefix) { $img_str = ''; $image_counter = rand(0, $max_count); $image_qb = org_routamc_photostream_photo_dba::new_query_builder(); $image_qb->set_limit(1); $image_qb->set_offset($image_counter - 1); $images = $image_qb->execute(); if (count($images) > 0) { $image = $images[0]; $qb_thumb = new midgard_query_builder('midgard_attachment'); $qb_thumb->add_constraint('parentguid', '=', $image->guid); $qb_thumb->add_constraint('parameter.domain', '=', 'midcom.helper.datamanager2.type.blobs'); $qb_thumb->add_constraint('parameter.name', '=', 'identifier'); $qb_thumb->add_constraint('parameter.value', '=', 'thumbnail'); $thumbs = $qb_thumb->execute(); if (count($thumbs) > 0) { $thumb = $thumbs[0]; $img_str = ''; if ($photostream_prefix != '') { $img_str = '<a title="' . $image->title . '" href="' . $photostream_prefix . 'photo/' . $image->guid . '/">'; } $img_str .= '<img src="/midcom-serveattachmentguid-' . $thumb->guid . '/' . $thumb->guid . '" border="0" alt="' . $image->title . '" />'; if ($photostream_prefix != '') { $img_str .= '</a>'; } $img_str .= "<br />\n<br />\n"; } } return $img_str; }
/** * Simple default topic hierarchy setup for OpenPSA * * @package midcom */ function openpsa_prepare_topics() { $openpsa_topics = array('Calendar' => 'org.openpsa.calendar', 'Contacts' => 'org.openpsa.contacts', 'Documents' => 'org.openpsa.documents', 'Expenses' => 'org.openpsa.expenses', 'Invoices' => 'org.openpsa.invoices', 'Products' => 'org.openpsa.products', 'Projects' => 'org.openpsa.projects', 'Reports' => 'org.openpsa.reports', 'Sales' => 'org.openpsa.sales', 'User Management' => 'org.openpsa.user', 'Wiki' => 'net.nemein.wiki'); $qb = new midgard_query_builder('midgard_topic'); $qb->add_constraint('name', '=', 'openpsa'); $qb->add_constraint('up', '=', 0); $topics = $qb->execute(); if ($topics) { return $topics[0]->guid; } // Create a new root topic for OpenPSA $root_topic = new midgard_topic(); $root_topic->name = 'openpsa'; $root_topic->component = 'org.openpsa.mypage'; $root_topic->extra = 'OpenPSA'; if (!$root_topic->create()) { throw new Exception('Failed to create root topic for OpenPSA: ' . midgard_connection::get_instance()->get_error_string()); } foreach ($openpsa_topics as $title => $component) { $topic = new midgard_topic(); $topic->name = strtolower(preg_replace('/\\W/', '-', $title)); $topic->component = $component; $topic->extra = $title; $topic->up = $root_topic->id; $topic->create(); } return $root_topic->guid; }
private function get_snippetdir_children($snippetdir_id) { // Load children for PROPFIND purposes $children = array(array('uri' => "{midgardmvc_core::get_instance()->context->prefix}mgd:snippets{$this->object_path}/", 'title' => $this->object_path, 'mimetype' => 'httpd/unix-directory', 'resource' => 'collection')); // Snippetdirs $mc = midgard_snippetdir::new_collector('up', $snippetdir_id); $mc->set_key_property('name'); $mc->add_value_property('description'); $mc->execute(); $snippetdirs = $mc->list_keys(); if (is_array($snippetdirs)) { foreach ($snippetdirs as $name => $array) { if (empty($name)) { continue; } $children[] = array('uri' => "{midgardmvc_core::get_instance()->context->prefix}mgd:snippets{$this->object_path}/{$name}/", 'title' => $name, 'mimetype' => 'httpd/unix-directory', 'resource' => 'collection'); } } // Snippets $qb = new midgard_query_builder('midgard_snippet'); $qb->add_constraint('up', '=', $snippetdir_id); $qb->add_constraint('name', '<>', ''); $snippets = $qb->execute(); if (is_array($snippets)) { foreach ($snippets as $snippet) { $children[] = array('uri' => "{midgardmvc_core::get_instance()->context->prefix}mgd:snippets{$this->object_path}/{$snippet->name}.php", 'title' => $snippet->name, 'mimetype' => 'text/plain', 'size' => $snippet->metadata->size, 'revised' => $snippet->metadata->revised); } } return $children; }
public function get_graph(array $args) { midgardmvc_core::get_instance()->authorization->require_user(); $stat_types = array('bmi', 'weight', 'vo2max'); $qb = new midgard_query_builder('fi_openkeidas_diary_stat'); $qb->add_constraint('person', '=', midgardmvc_core::get_instance()->authentication->get_person()->id); $qb->add_constraint('stat', 'IN', $stat_types); $qb->add_order('date', 'ASC'); $since = new midgard_datetime('6 months ago'); $qb->add_constraint('date', '>', $since); $stats = $qb->execute(); if (empty($stats)) { throw new midgardmvc_exception_notfound("No stats found"); } $dates = array(); foreach ($stats as $stat) { $date = $stat->date->format('d.m.Y'); if (!isset($dates[$date])) { $dates[$date] = array(); } $dates[$date][] = $stat; } $previous_value = array(); $this->data['stats'] = array(); foreach ($dates as $date => $stats) { foreach ($stats as $stat) { if (!isset($this->data['stats'][$stat->stat])) { $this->data['stats'][$stat->stat] = array(); } $value = round($stat->value, 1); $this->data['stats'][$stat->stat][$date] = $value; $previous_value[$stat->stat] = $value; } foreach ($stat_types as $stat_type) { if (!isset($this->data['stats'][$stat_type])) { continue; } if (!isset($this->data['stats'][$stat_type][$date]) && isset($previous_value[$stat_type])) { $this->data['stats'][$stat_type][$date] = $previous_value[$stat_type]; } } } midgardmvc_core::get_instance()->component->load_library('Graph'); $graph = new ezcGraphLineChart(); foreach ($this->data['stats'] as $name => $stats) { $graph->data[$this->get_label($name)] = new ezcGraphArrayDataSet($stats); $graph->data[$this->get_label($name)]->symbol = ezcGraph::BULLET; } $graph->driver = new fi_openkeidas_diary_graph_gd(); $graph->driver->options->imageFormat = IMG_PNG; $graph->options->font = midgardmvc_core::get_instance()->configuration->graph_font; $graph->legend->position = ezcGraph::BOTTOM; $graph->palette = new ezcGraphPaletteEz(); // render image directly to screen $graph->renderToOutput(575, 200); // wrap up the request midgardmvc_core::get_instance()->dispatcher->end_request(); }
/** * Check whether given token has already been used in the database * * @param string $token * @return boolean indicating whether token is free or not (true for free == not present) */ function token_is_free($token, $type = self::SENT) { $qb = new midgard_query_builder('org_openpsa_campaign_message_receipt'); $qb->add_constraint('token', '=', $token); if ($type) { $qb->add_constraint('orgOpenpsaObtype', '=', $type); } $ret = @$qb->execute(); if (empty($ret)) { return true; } return false; }
public static function within(DateTime $from, DateTime $to, array $users, fi_openkeidas_diary_activity $activity = null) { if (empty($users)) { return array(); } $qb = new midgard_query_builder('fi_openkeidas_diary_log'); $qb->add_constraint('date', '>', $from); $qb->add_constraint('date', '<', $to); $qb->add_constraint('person', 'IN', $users); if (!is_null($activity)) { $qb->add_constraint('activity', '=', $activity->id); } return $qb->execute(); }
/** * Seek users with Plazes account settings set * * @return Array */ function seek_fireeagle_users() { // TODO: With 1.8 we can query parameters more efficiently $qb = new midgard_query_builder('midgard_parameter'); $qb->add_constraint('domain', '=', 'net.yahoo.fireeagle'); $qb->add_constraint('name', '=', 'access_key'); $accounts = $qb->execute(); if (count($accounts) > 0) { foreach ($accounts as $account_param) { $user = new midcom_db_person($account_param->parentguid); $this->get_fireeagle_location($user, true); } } }
/** * Seek users with Qaiku API key set * * @return Array */ function seek_qaiku_users() { // TODO: With 1.8 we can query parameters more efficiently $qb = new midgard_query_builder('midgard_parameter'); $qb->add_constraint('domain', '=', 'org.routamc.statusmessage:qaiku'); $qb->add_constraint('name', '=', 'apikey'); $accounts = $qb->execute(); if (count($accounts) > 0) { foreach ($accounts as $account_param) { $user = new midcom_db_person($account_param->parentguid); $this->get_qaiku_location($user, true); } } }
/** * Seek users with Plazes account settings set * * @return Array */ function seek_georss_users() { // TODO: With 1.8 we can query parameters more efficiently $qb = new midgard_query_builder('midgard_parameter'); $qb->add_constraint('domain', '=', 'org.routamc.positioning:georss'); $qb->add_constraint('name', '=', 'georss_url'); $accounts = $qb->execute(); if (count($accounts) > 0) { foreach ($accounts as $account_param) { $user = new midcom_db_person($account_param->parentguid); $this->get_georss_location($user, true); } } }
/** * Seek users with instamapper API key set * * @return Array */ function seek_instamapper_users() { // TODO: With 1.8 we can query parameters more efficiently $qb = new midgard_query_builder('midgard_parameter'); $qb->add_constraint('domain', '=', 'org.routamc.positioning:instamapper'); $qb->add_constraint('name', '=', 'api_key'); $accounts = $qb->execute(); if (count($accounts) > 0) { foreach ($accounts as $account_param) { try { $user = new midcom_db_person($account_param->parentguid); $this->get_instamapper_location($user, true); } catch (midcom_error $e) { continue; } } } }
private function create_account(array $ldapuser, array $tokens) { midgardmvc_core::get_instance()->authorization->enter_sudo('midgardmvc_core'); $transaction = new midgard_transaction(); $transaction->begin(); $qb = new midgard_query_builder('midgard_person'); $qb->add_constraint('firstname', '=', $ldapuser['firstname']); $qb->add_constraint('lastname', '=', $ldapuser['lastname']); $persons = $qb->execute(); if (count($persons) == 0) { $person = new midgard_person(); $person->firstname = $ldapuser['firstname']; $person->lastname = $ldapuser['lastname']; if (!$person->create()) { midgardmvc_core::get_instance()->log(__CLASS__, "Creating midgard_person for LDAP user failed: " . midgard_connection::get_instance()->get_error_string(), 'warning'); $transaction->rollback(); midgardmvc_core::get_instance()->authorization->leave_sudo(); return false; } } else { $person = $persons[0]; } $person->set_parameter('midgardmvc_core_services_authentication_ldap', 'employeenumber', $ldapuser['employeenumber']); $user = new midgard_user(); $user->login = $tokens['login']; $user->password = ''; $user->usertype = 1; $user->authtype = 'LDAP'; $user->active = true; $user->set_person($person); if (!$user->create()) { midgardmvc_core::get_instance()->log(__CLASS__, "Creating midgard_user for LDAP user failed: " . midgard_connection::get_instance()->get_error_string(), 'warning'); $transaction->rollback(); midgardmvc_core::get_instance()->authorization->leave_sudo(); return false; } if (!$transaction->commit()) { midgardmvc_core::get_instance()->authorization->leave_sudo(); return false; } midgardmvc_core::get_instance()->authorization->leave_sudo(); return true; }
/** * Check whether given wikiword is free in given node * * Returns true if word is free, false if reserved */ public static function node_wikiword_is_free(&$node, $wikiword) { if (empty($node)) { //Invalid node debug_add('given node is not valid', MIDCOM_LOG_ERROR); return false; } $wikiword_name = midcom_helper_misc::generate_urlname_from_string($wikiword); $qb = new midgard_query_builder('midgard_article'); $qb->add_constraint('topic', '=', $node[MIDCOM_NAV_OBJECT]->id); $qb->add_constraint('name', '=', $wikiword_name); $ret = @$qb->execute(); if (is_array($ret) && count($ret) > 0) { //Match found, word is reserved debug_add("QB found matches for name '{$wikiword_name}' in topic #{$node[MIDCOM_NAV_OBJECT]->id}, given word '{$wikiword}' is reserved", MIDCOM_LOG_INFO); debug_print_r('QB results:', $ret); return false; } return true; }
private function get_person_by_name($name) { // We know the real name, try to match to a Midgard Person $name_parts = explode(' ', $_ENV['MIDGARD_ENV_REAL_NAME']); if (count($name_parts) < 2) { return null; } $qb = new midgard_query_builder('midgard_person'); $qb->add_constraint('firstname', '=', $name_parts[0]); $qb->add_constraint('lastname', '=', $name_parts[1]); $persons = $qb->execute(); if (count($persons) > 0) { return $persons[0]; } $person = new midgard_person(); $person->firstname = $name_parts[0]; $person->lastname = $name_parts[1]; $person->create(); return $person; }
/** * Checks for duplicate memberships returns true for NO duplicate memberships */ private function _check_duplicate_membership() { $qb = new midgard_query_builder('org_openpsa_campaign_member'); $qb->add_constraint('person', '=', $this->person); $qb->add_constraint('campaign', '=', $this->campaign); //For tester membership check only other tester memberships for duplicates, for other memberships check all BUT testers if ($this->orgOpenpsaObtype == self::TESTER) { $qb->add_constraint('orgOpenpsaObtype', '=', self::TESTER); } else { $qb->add_constraint('orgOpenpsaObtype', '<>', self::TESTER); } if ($this->id) { $qb->add_constraint('id', '<>', $this->id); } $ret = $qb->execute(); if (count($ret) > 0) { //We already have a membership with the same campaign and person return false; } return true; }
public static function update_sport_and_group(fi_openkeidas_diary_log $log, $params) { if (!$log->activity) { return; } midgardmvc_core::get_instance()->authorization->enter_sudo('fi_openkeidas_diary'); $activity = new fi_openkeidas_diary_activity(); $activity->get_by_id($log->activity); $activity->metadata->score++; $activity->update(); $qb = new midgard_query_builder('fi_openkeidas_groups_group_member'); $qb->add_constraint('person', '=', midgardmvc_core::get_instance()->authentication->get_person()->id); $qb->add_constraint('metadata.isapproved', '=', true); $memberships = $qb->execute(); foreach ($memberships as $membership) { $group = new fi_openkeidas_groups_group($membership->grp); $group->metadata->score++; $group->update(); } midgardmvc_core::get_instance()->authorization->leave_sudo(); }
public function _on_execute() { debug_add('called!'); midcom::get('dbclassloader')->load_classes('midcom', 'core_classes.inc', null, true); $qb = new midgard_query_builder('midcom_core_login_session_db'); $qb->add_constraint('timestamp', '<', time() - $GLOBALS['midcom_config']['auth_login_session_timeout']); $qb->set_limit(500); $result = $qb->execute(); foreach ($result as $tmp) { if (!$tmp->delete()) { // Print and log error $msg = "Failed to delete login session {$tmp->id}, last Midgard error was: " . midcom_connection::get_error_string(); $this->print_error($msg); debug_add($msg, MIDCOM_LOG_ERROR); debug_print_r('Tried to delete this object:', $tmp); } else { $tmp->purge(); debug_add("Deleted login session {$tmp->id}."); } } }
/** * Match an URL path to a page. Remaining path arguments are stored to argv * * @param $path URL path */ public function resolve_page($path) { if (!is_string($path) || substr($path, 0, 1) != '/') { throw new InvalidArgumentException('Invalid path provided'); } $temp = trim($path); $page = $this->root_page; $parent_id = $this->root_page->id; // Clean up path $path = substr(trim($path), 1); if (substr($path, strlen($path) - 1) == '/') { $path = substr($path, 0, -1); } if ($path == '') { $this->argv = array(); $this->set_page($page); return; } $path = explode('/', $path); $this->argv = $path; foreach ($path as $i => $p) { $qb = new midgard_query_builder('midgardmvc_core_node'); $qb->add_constraint('up', '=', $parent_id); $qb->add_constraint('name', '=', $p); $res = $qb->execute(); if (count($res) != 1) { break; } if ($res[0]->templatedir) { $this->templatedir_id = $res[0]->templatedir; } $parent_id = $res[0]->id; $temp = substr($temp, 1 + strlen($p)); $page = $res[0]; $this->path .= $page->name . '/'; $this->path_for_page[$page->id] = $this->path; array_shift($this->argv); } $this->set_page($page); }
public function action_edit($route_id, &$data, $args) { midgardmvc_core::get_instance()->authorization->require_user(); $person = midgardmvc_core::get_instance()->authentication->get_person(); $contact = new net_nemein_avaudu_contact($person->guid); // Read current settings from host $data['qaiku_apikey'] = $person->get_parameter('net_nemein_avaudu', 'qaiku_apikey'); // Update things as we go if (isset($_POST['qaiku_apikey'])) { // Test the API key $qaiku_json = @file_get_contents('http://www.qaiku.com/api/statuses/user_timeline.json?apikey=' . $_POST['qaiku_apikey']); if (!$qaiku_json) { // Qaiku didn't accept the API key // TODO: UImessage throw new Exception("Invalid Qaiku API key"); } $data['qaiku_apikey'] = $_POST['qaiku_apikey']; // Get user info from Qaiku $qaikus = json_decode($qaiku_json); if (isset($qaikus[0])) { $qaiku_user = $qaikus[0]->user; $qb = new midgard_query_builder('net_nemein_avaudu_contact'); $qb->add_constraint('qaikunick', '=', $qaiku_user->screen_name); $contacts = $qb->execute(); if (count($contacts) > 0) { $person->set_parameter('net_nemein_avaudu', 'user', $contacts[0]->guid); } else { // Populate "Me" into database $contact->qaikunick = $qaiku_user->screen_name; $contact->name = $qaiku_user->name; $contact->avatar = $qaiku_user->profile_image_url; $contact->qaikuid = $qaiku_user->id; $contact->update(); } } // Save the settings $person->set_parameter('net_nemein_avaudu', 'qaiku_apikey', $data['qaiku_apikey']); } }
/** * Get document list for requested sequences */ public function get_docs_by_seq(array $args) { //$this->authenticate(); // List the requested sequence data $qb = new midgard_query_builder('midgard_sequence'); if (isset($_MIDCOM->dispatcher->get['startkey'])) { $qb->add_constraint('id', '>', (int) $_MIDCOM->dispatcher->get['startkey']); } if (isset($_MIDCOM->dispatcher->get['limit'])) { $qb->set_limit((int) $_MIDCOM->dispatcher->get['limit']); } $qb->add_order('id', 'ASC'); $transactions = $qb->execute(); // Prepare the data list $this->data['total_rows'] = count($transactions); $this->data['offset'] = 0; $this->data['rows'] = array(); // Map the transaction data to what CouchDb protocol wants foreach ($transactions as $transaction) { $this->data['rows'][] = array('id' => $transaction->objectguid, 'key' => $transaction->id, 'value' => array('rev' => $transaction->revision . '-' . $transaction->metadata->revised->format('U'))); } }
public static function add_challenges_for_group(fi_openkeidas_groups_group $group) { $mc = new midgard_collector('fi_openkeidas_diary_challenge_participant', 'grp', $group->id); //$mc->add_constraint('metadata.isapproved', '=', true); $mc->add_constraint('challenge.start', '<=', new DateTime()); $mc->add_constraint('challenge.enddate', '>', new DateTime()); $mc->set_key_property('challenge'); $mc->execute(); $challenge_ids = array_keys($mc->list_keys()); if (count($challenge_ids) == 0) { return $group; } $qb = new midgard_query_builder('fi_openkeidas_diary_challenge'); $qb->add_constraint('id', 'IN', $challenge_ids); $group->challenges = array(); $challenges = $qb->execute(); foreach ($challenges as $challenge) { $challenge->url = midgardmvc_core::get_instance()->dispatcher->generate_url('challenge_read', array('challenge' => $challenge->guid), 'fi_openkeidas_diary'); $group->challenges[] = $challenge; } return $group; }
public function _on_execute() { debug_add('called!'); $cut_off = mktime(23, 59, 59, date('n'), date('j') - $GLOBALS['midcom_config']['cron_purge_deleted_after'], date('Y')); foreach (midcom_connection::get_schema_types() as $mgdschema) { if (substr($mgdschema, 0, 2) == '__') { continue; } debug_add("Processing class {$mgdschema}"); $qb = new midgard_query_builder($mgdschema); $qb->add_constraint('metadata.deleted', '<>', 0); $qb->add_constraint('metadata.revised', '<', gmdate('Y-m-d H:i:s', $cut_off)); $qb->include_deleted(); $qb->set_limit(500); $objects = $qb->execute(); unset($qb); if (!is_array($objects)) { debug_add("QB failed fatally on class {$mgdschema}, errstr: " . midcom_connection::get_error_string(), MIDCOM_LOG_ERROR); continue; } $found = count($objects); $purged = 0; foreach ($objects as $obj) { if (!$obj->purge()) { debug_add("Failed to purge {$mgdschema} {$obj->guid}, deleted: {$obj->metadata->deleted}, revised: {$obj->metadata->revised}. errstr: " . midcom_connection::get_error_string(), MIDCOM_LOG_ERROR); debug_print_r('Failed object', $obj); continue; } $purged++; } if ($found > 0) { debug_add("Found {$found} {$mgdschema} objects deleted before " . date('Y-m-d H:i:s', $cut_off) . ", purged {$purged}", MIDCOM_LOG_INFO); } else { debug_add("No {$mgdschema} objects deleted before " . date('Y-m-d H:i:s', $cut_off) . " found"); } } }
/** * Handler method for listing style elements for the currently used component topic * * @param string $handler_id Name of the used handler * @param mixed $args Array containing the variable arguments passed to the handler * @param mixed &$data Data passed to the show method */ public function _handler_folders($handler_id, array $args, array &$data) { $this->_group = new midcom_db_group($args[0]); midgard_admin_asgard_plugin::bind_to_object($this->_group, $handler_id, $data); $qb = new midgard_query_builder('midcom_core_privilege_db'); $qb->add_constraint('assignee', '=', "group:{$this->_group->guid}"); $privileges = $qb->execute(); $data['objects'] = array(); $data['privileges'] = array(); foreach ($privileges as $privilege) { if (!$privilege->objectguid) { // We're only interested in privs applying to objects now, skip continue; } $data['privileges'][] = $privilege->privilegename; if (!isset($data['objects'][$privilege->objectguid])) { $data['objects'][$privilege->objectguid] = array(); } $data['objects'][$privilege->objectguid][$privilege->privilegename] = $privilege->value; } $data['view_title'] = sprintf(midcom::get('i18n')->get_string('folders of %s', 'midcom.admin.user'), $this->_group->official); midcom::get('head')->set_pagetitle($data['view_title']); $this->_update_breadcrumb(); }
public function get_object_actions($object) { $actions = array(); if (!is_object($object)) { return $actions; } $type = get_class($object); $components_to_check = array(); $libraries_to_check = array(); if (isset($this->type_action_providers[$type])) { // Type-specific actions foreach ($this->type_action_providers[$type] as $component) { if (isset($this->manifests[$component]['library']) && $this->manifests[$component]['library']) { $libraries_to_check[] = $component; continue; } $components_to_check[] = $component; } } if (isset($this->type_action_providers['*'])) { // Generic actions for any type foreach ($this->type_action_providers['*'] as $component) { if (isset($this->manifests[$component]['library']) && $this->manifests[$component]['library']) { $libraries_to_check[] = $component; continue; } $components_to_check[] = $component; } } foreach ($libraries_to_check as $component) { $interface = $this->_core->componentloader->load($component); $component_actions = $interface->get_object_actions($object); $actions = array_merge($actions, $component_actions); } if (!empty($components_to_check)) { $qb = new midgard_query_builder('midgardmvc_core_node'); $qb->add_constraint('component', 'IN', $components_to_check); $folders = $qb->execute(); foreach ($folders as $folder) { $interface = $this->_core->componentloader->load($folder->component, $folder); $component_actions = $interface->get_object_actions($object); $actions = array_merge($actions, $component_actions); } } return $actions; }
/** * Function deletes login session row from database and * cleans away the cookie */ public function logout() { if ($this->user) { $this->user->logout(); } // Remove session cookie from browser $this->session_cookie->delete_login_session_cookie(); // Delete login session from DB midgardmvc_core::get_instance()->authorization->enter_sudo('midgardmvc_core'); $qb = new midgard_query_builder('midgardmvc_core_login_session'); $qb->add_constraint('guid', '=', $this->session_cookie->get_session_id()); $res = $qb->execute(); if (!$res) { return false; } $res[0]->delete(); $res[0]->purge(); midgardmvc_core::get_instance()->authorization->leave_sudo(); // Initialize a fresh session cookie handler $this->session_cookie = new midgardmvc_core_services_authentication_cookie(); return true; }
/** * This is a wrapper for get_group, which allows Midgard Group retrieval by its name. * If the group name is unknown, false is returned. * * In the case that more then one * group matches the given name, the first one is returned. Note, that this should not * happen as midgard group names should be unique according to the specs. * * @param string $name The name of the group to look up. * @return midcom_core_group A reference to the group object matching the group name, * or false if the group name is unknown. */ function &get_midgard_group_by_name($name) { $qb = new midgard_query_builder('midgard_group'); $qb->add_constraint('name', '=', $name); $result = @$qb->execute(); if (!$result || count($result) == 0) { $result = false; return $result; } $grp = $this->get_group($result[0]); return $grp; }
/** * This is a static helper function which retrieves a single given privilege * at a content object, identified by the combination of assignee and privilege * name. * * This call will return an object even if the privilege is set to INHERITED at * the given object (i.e. does not exist) for consistency reasons. Errors are * thrown for example on database inconsistencies. * * This function is for use in the authentication framework only and may only * be called statically. * * @param object $object The object to query. * @param string $name The name of the privilege to query * @param string $assignee The identifier of the assignee to query. * @param string $classname The optional classname required only for class-limited SELF privileges. * @return midcom_core_privilege The privilege matching the constraints. */ public static function get_privilege($object, $name, $assignee, $classname = '') { $qb = new midgard_query_builder('midcom_core_privilege_db'); $qb->add_constraint('objectguid', '=', $object->guid); $qb->add_constraint('privilegename', '=', $name); $qb->add_constraint('assignee', '=', $assignee); $qb->add_constraint('classname', '=', $classname); $result = @$qb->execute(); if (!$result) { $result = array(); } if (count($result) > 1) { midcom::get('auth')->request_sudo('midcom.core'); debug_add('A DB inconsistency has been detected. There is more then one record for privilege specified. Deleting all excess records after the first one!', MIDCOM_LOG_ERROR); debug_print_r('Content Object:', $object); debug_add("Privilege {$name} for assignee {$assignee} with classname {$classname} was queried.", MIDCOM_LOG_INFO); debug_print_r('Resultset was:', $result); while (count($result) > 1) { $privilege = array_pop($result); $privilege->delete(); } midcom::get('auth')->drop_sudo(); } else { if (count($result) == 0) { // No such privilege stored, return non-persistent one $privilege = new midcom_core_privilege(); $privilege->set_object($object); $privilege->set_assignee($assignee); $privilege->privilegename = $name; if (!is_null($classname)) { $privilege->classname = $classname; } $privilege->value = MIDCOM_PRIVILEGE_INHERIT; return $privilege; } } return new midcom_core_privilege($result[0]); }
public function get_child_nodes() { if (!empty($this->children)) { return $this->children; } $qb = new midgard_query_builder('midgardmvc_core_node'); $qb->add_constraint('up', '=', $this->node->id); $nodes = $qb->execute(); foreach ($nodes as $node) { $this->children[] = self::get_instance($node); } return $this->children; }