/** * @param mixed $handler_id The ID of the handler. * @param Array $args The argument list. * @param Array &$data The local request data. * @return boolean Indicating success. */ public function _handler_view($handler_id, array $args, array &$data) { $data['name'] = $args[0]; if (!midcom::get('componentloader')->is_installed($data['name'])) { throw new midcom_error_notfound("Component {$data['name']} is not installed."); } $componentpath = midcom::get('componentloader')->path_to_snippetpath($data['name']); // Load and parse the global config $cfg = midcom_baseclasses_components_configuration::read_array_from_file("{$componentpath}/config/config.inc"); if (!$cfg) { // hmmm... that should never happen $cfg = array(); } $config = new midcom_helper_configuration($cfg); // Go for the sitewide default $cfg = midcom_baseclasses_components_configuration::read_array_from_file("/etc/midgard/midcom/{$data['name']}/config.inc"); if ($cfg !== false) { $config->store($cfg, false); } // Finally, check the sitegroup config $cfg = midcom_baseclasses_components_configuration::read_array_from_snippet("{$GLOBALS['midcom_config']['midcom_sgconfig_basedir']}/{$data['name']}/config"); if ($cfg !== false) { $config->store($cfg, false); } $data['config'] =& $config; $this->_update_breadcrumb($data['name']); $this->_prepare_toolbar($data); midcom::get('head')->set_pagetitle($data['view_title']); }
private function _load_configs($component, $object = null) { $componentpath = midcom::get('componentloader')->path_to_snippetpath($component); // Load and parse the global config $cfg = midcom_baseclasses_components_configuration::read_array_from_file("{$componentpath}/config/config.inc"); if (!$cfg) { // Empty defaults $cfg = array(); } $config = new midcom_helper_configuration($cfg); if ($object) { $topic_config = new midcom_helper_configuration($object, $component); } // Go for the sitewide default $cfg = midcom_baseclasses_components_configuration::read_array_from_file("/etc/midgard/midcom/{$component}/config.inc"); if ($cfg !== false) { $config->store($cfg, false); } // Finally, check the sitegroup config $cfg = midcom_baseclasses_components_configuration::read_array_from_snippet("{$GLOBALS['midcom_config']['midcom_sgconfig_basedir']}/{$component}/config"); if ($cfg !== false) { $config->store($cfg, false); } if (isset($topic_config)) { $config->store($topic_config->_local); } return $config; }
function _on_execute() { debug_push_class(__CLASS__, __FUNCTION__); if (!$_MIDCOM->auth->request_sudo('fi.kilonkipinat.emailmappings')) { $msg = "Could not get sudo, aborting operation, see error log for details"; $this->print_error($msg); debug_add($msg, MIDCOM_LOG_ERROR); debug_pop(); return; } $email_group_guid = $this->_config->get('group_for_emails'); if ($email_group_guid == null) { // Email group not set in global config, we try to search for topic // $nap_topic = midcom_helper_find_node_by_component('fi.kilonkipinat.emailmappings'); // $topic = new midcom_db_topic($nap_topic[MIDCOM_NAV_GUID]); $qb = midcom_db_topic::new_query_builder(); $qb->add_constraint('component', '=', 'fi.kilonkipinat.emailmappings'); $qb->add_constraint('name', '<>', ''); $qb->set_limit(1); $topics = $qb->execute(); $topic = False; if (count($topics) > 0) { $topic = $topics[0]; } if ($topic && $topic->guid && $topic->guid != '') { $real_config = new midcom_helper_configuration($topic, 'fi.kilonkipinat.emailmappings'); $email_group_guid = $real_config->get('group_for_emails'); } else { $msg = "Could not find topic for config, aborting operation, see error log for details"; $this->print_error($msg); debug_add($msg, MIDCOM_LOG_ERROR); debug_pop(); return; } } $emails = array(); $usernames = array(); $file_content = ''; if ($email_group_guid != null) { $email_group = new midcom_db_group($email_group_guid); if ($email_group && $email_group->guid && $email_group->guid != '' && $email_group->guid == $email_group_guid) { $mc_members = midcom_db_member::new_collector('gid', $email_group->id); $mc_members->add_value_property('uid'); $mc_members->execute(); $member_keys = $mc_members->list_keys(); $person_ids = array(); foreach ($member_keys as $guid => $content) { $person_id = $mc_members->get_subkey($guid, 'uid'); $person_ids[] = $person_id; unset($person_id); } $mc_persons = fi_kilonkipinat_account_person_dba::new_collector('sitegroup', $_MIDGARD['sitegroup']); if (count($person_ids) > 0) { $mc_persons->add_constraint('id', 'IN', $person_ids); } $mc_persons->add_constraint('username', '<>', ''); $mc_persons->add_constraint('email', '<>', ''); $mc_persons->add_constraint('email', 'LIKE', '%@%'); $mc_persons->add_value_property('username'); $mc_persons->add_value_property('email'); $mc_persons->execute(); $person_keys = $mc_persons->list_keys(); foreach ($person_keys as $guid => $content) { $person_username = $mc_persons->get_subkey($guid, 'username'); $person_email = $mc_persons->get_subkey($guid, 'email'); if (strstr($person_email, '@kilonkipinat.fi') || strstr($person_email, '@lists.kilonkipinat.fi')) { debug_add('illegal content in email-address for person guid ' . $guid . ', continuing to next person', MIDCOM_LOG_ERROR); continue; } if (isset($emails[$person_email]) || isset($usernames[$person_username])) { continue; } $emails[$person_email] = $person_email; $usernames[$person_username] = $person_username; $file_content .= "\n" . $person_username . ': ' . $person_email; } } else { $msg = "Could not instantiate group for emailmapping, aborting operation, see error log for details"; $this->print_error($msg); debug_add($msg, MIDCOM_LOG_ERROR); debug_pop(); return; } } else { $msg = "Could not find group for emailmapping, aborting operation, see error log for details"; $this->print_error($msg); debug_add($msg, MIDCOM_LOG_ERROR); debug_pop(); return; } if ($file_content != '') { $file_content .= "\n\n"; $filename = '/root/mailaliases/aliases_automatic'; if (is_writable($filename)) { if (!file_put_contents($filename, $file_content)) { $msg = "Tried to write aliases file, aborting operation, see error log for details"; $this->print_error($msg); debug_add($msg, MIDCOM_LOG_ERROR); debug_pop(); return; } } else { $msg = "Couldn't write to aliases file, aborting operation, see error log for details"; $this->print_error($msg); debug_add($msg, MIDCOM_LOG_ERROR); debug_pop(); return; } } $file2_content = ''; $mc_mappings = fi_kilonkipinat_emailmappings_emailmapping_dba::new_collector('sitegroup', $_MIDGARD['sitegroup']); $mc_mappings->add_value_property('name'); $mc_mappings->add_value_property('persons'); if (count($usernames) != 0) { $mc_mappings->add_constraint('name', 'NOT IN', $usernames); } $mc_mappings->execute(); $mapping_keys = $mc_mappings->list_keys(); foreach ($mapping_keys as $guid => $content) { $key = $mc_mappings->get_subkey($guid, 'name'); $person_guids = $mc_mappings->get_subkey($guid, 'persons'); $tmp_guids = explode('|', $person_guids); $guids = array(); foreach ($tmp_guids as $guid2) { $guids[] = trim(str_replace('|', '', $guid2)); } $persons_mc = fi_kilonkipinat_account_person_dba::new_collector('sitegroup', $_MIDGARD['sitegroup']); $persons_mc->add_value_property('email'); if (count($guids) > 0) { $persons_mc->add_constraint('guid', 'IN', $guids); } $persons_mc->add_constraint('email', '<>', ''); $persons_mc->execute(); $persons_tmp = $persons_mc->list_keys(); $emails = ''; foreach ($persons_tmp as $guid3 => $content2) { $email = $persons_mc->get_subkey($guid3, 'email'); if ($emails != '') { $emails .= ', '; } $emails .= $email; } if (strlen($emails) > 3 && strstr($emails, "@")) { $file2_content .= "\n" . $key . ': ' . $emails; } } if ($file2_content != '') { $file2_content .= "\n\n"; $filename2 = '/root/mailaliases/aliases_mappings'; if (is_writable($filename2)) { if (!file_put_contents($filename2, $file2_content)) { $msg = "Tried to write aliases file 2, aborting operation, see error log for details"; $this->print_error($msg); debug_add($msg, MIDCOM_LOG_ERROR); debug_pop(); return; } } else { $msg = "Couldn't write to aliases file 2, aborting operation, see error log for details"; $this->print_error($msg); debug_add($msg, MIDCOM_LOG_ERROR); debug_pop(); return; } } $_MIDCOM->auth->drop_sudo(); debug_pop(); }
/** * Indexes an article. * * @param midcom_helper_datamanager2_datamanager &$dm The Datamanager encapsulating the event. * @param midcom_services_indexer &$indexer The indexer instance to use. * @param midcom_db_topic The topic which we are bound to. If this is not an object, the code * tries to load a new topic instance from the database identified by this parameter. */ public static function index(&$dm, &$indexer, $topic) { $config = new midcom_helper_configuration($topic, 'net.nehmer.blog'); if ($config->get('disable_indexing')) { return; } if (!is_object($topic)) { $topic = new midcom_db_topic($topic); } // Don't index directly, that would lose a reference due to limitations // of the index() method. Needs fixes there. $nav = new midcom_helper_nav(); $node = $nav->get_node($topic->id); $document = $indexer->new_document($dm); $document->topic_guid = $topic->guid; $document->component = $topic->component; $document->topic_url = $node[MIDCOM_NAV_FULLURL]; $document->read_metadata_from_object($dm->storage->object); $indexer->index($document); }
function sort_schema_fields($first, $second) { $preferred_fields = $this->_config->get('object_preferred_fields'); $timerange_fields = $this->_config->get('object_timerange_fields'); $address_fields = $this->_config->get('object_address_fields'); $phone_fields = $this->_config->get('object_phone_fields'); $location_fields = $this->_config->get('object_location_fields'); // We handle the cases, and then their subcases if (in_array($first, $preferred_fields) && $this->_reflector->get_midgard_type($first) != MGD_TYPE_LONGTEXT) { // This is one of the preferred fields, check subcases if (in_array($second, $preferred_fields)) { return strnatcmp($first, $second); } return -1; } if ($this->_reflector->get_midgard_type($first) == MGD_TYPE_LONGTEXT) { // This is a longtext field, they come next if (in_array($second, $preferred_fields) && $this->_reflector->get_midgard_type($second) != MGD_TYPE_LONGTEXT) { return 1; } if ($this->_reflector->get_midgard_type($second) == MGD_TYPE_LONGTEXT) { return strnatcmp($first, $second); } return -1; } if ($this->_reflector->is_link($first)) { // This is a linked property, they come next if (in_array($second, $preferred_fields) || $this->_reflector->get_midgard_type($second) == MGD_TYPE_LONGTEXT) { return 1; } if ($this->_reflector->is_link($second)) { return strnatcmp($first, $second); } return -1; } if (in_array($first, $timerange_fields)) { if (in_array($second, $preferred_fields) || $this->_reflector->get_midgard_type($second) == MGD_TYPE_LONGTEXT || $this->_reflector->is_link($second)) { return 1; } if (in_array($second, $timerange_fields)) { // Both are phone fields, arrange them in proper order return array_search($first, $timerange_fields) < array_search($second, $timerange_fields) ? -1 : 1; } return -1; } if (in_array($first, $phone_fields)) { if (in_array($second, $preferred_fields) || $this->_reflector->get_midgard_type($second) == MGD_TYPE_LONGTEXT || $this->_reflector->is_link($second) || in_array($second, $timerange_fields)) { return 1; } if (in_array($second, $phone_fields)) { // Both are phone fields, arrange them in proper order return array_search($first, $phone_fields) < array_search($second, $phone_fields) ? -1 : 1; } return -1; } if (in_array($first, $address_fields)) { if (in_array($second, $preferred_fields) || $this->_reflector->get_midgard_type($second) == MGD_TYPE_LONGTEXT || $this->_reflector->is_link($second) || in_array($second, $timerange_fields) || in_array($second, $phone_fields)) { return 1; } if (in_array($second, $address_fields)) { // Both are address fields, arrange them in proper order return array_search($first, $address_fields) < array_search($second, $address_fields) ? -1 : 1; } return -1; } if (in_array($first, $location_fields)) { if (in_array($second, $preferred_fields) || $this->_reflector->get_midgard_type($second) == MGD_TYPE_LONGTEXT || $this->_reflector->is_link($second) || in_array($second, $timerange_fields) || in_array($second, $phone_fields) || in_array($second, $address_fields)) { return 1; } if (in_array($second, $location_fields)) { // Both are address fields, arrange them in proper order return array_search($first, $location_fields) < array_search($second, $location_fields) ? -1 : 1; } return -1; } if (in_array($second, $preferred_fields) || $this->_reflector->get_midgard_type($second) == MGD_TYPE_LONGTEXT || $this->_reflector->is_link($second) || in_array($second, $timerange_fields) || in_array($second, $phone_fields) || in_array($second, $address_fields) || in_array($second, $location_fields)) { // First field was not a preferred field, but second is return 1; } // Others come as they do return strnatcmp($first, $second); }
/** * Imports an item as an event */ private function import_event($item) { // Check that we're trying to import item suitable to be an event if (!isset($item['xcal']) && !isset($item['gd']['when@'])) { // Not an event return false; } // Get start and end times $start = null; $end = null; if (isset($item['xcal']['dtstart'])) { // xCal RSS feed, for example Upcoming or Last.fm $start = strtotime($item['xcal']['dtstart']); } elseif (isset($item['gd']['when@starttime'])) { // gData Atom feed, for example Dopplr $start = strtotime($item['gd']['when@starttime']); } if (isset($item['xcal']['dtend'])) { $end = strtotime($item['xcal']['dtend']); } elseif (isset($item['gd']['when@starttime'])) { $end = strtotime($item['gd']['when@endtime']); } if (!$start || !$end) { return false; } if (!$this->_datamanager) { $schemadb = midcom_helper_datamanager2_schema::load_database($this->_node_config->get('schemadb')); $this->_datamanager = new midcom_helper_datamanager2_datamanager($schemadb); } // TODO: Move to real geocoded stuff $location_parts = array(); if (isset($item['xcal']['x-calconnect-venue_adr_x-calconnect-venue-name'])) { $location_parts[] = $item['xcal']['x-calconnect-venue_adr_x-calconnect-venue-name']; } if (isset($item['xcal']['x-calconnect-venue_adr_x-calconnect-street'])) { $location_parts[] = $item['xcal']['x-calconnect-venue_adr_x-calconnect-street']; } if (isset($item['xcal']['x-calconnect-venue_adr_x-calconnect-city'])) { $location_parts[] = $item['xcal']['x-calconnect-venue_adr_x-calconnect-city']; } if (isset($item['gd']['where@valuestring'])) { $wherevalues = explode(' ', $item['gd']['where@valuestring']); foreach ($wherevalues as $val) { $location_parts[] = $val; } } $qb = net_nemein_calendar_event_dba::new_query_builder(); $qb->add_constraint('node', '=', $this->_feed->node); $qb->add_constraint('extra', '=', md5($item['guid'])); $events = $qb->execute(); if (count($events) > 0) { // This item has been imported already earlier. Update $event = $events[0]; $event->_activitystream_verb = 'http://community-equity.org/schema/1.0/clone'; $event->_rcs_message = sprintf(midcom::get('i18n')->get_string('%s was imported from %s', 'net.nemein.rss'), $event->title, $this->_feed->title); $event->allow_name_catenate = true; if (empty($event->name)) { $resolver = new midcom_helper_reflector_nameresolver($event); // To prevent validation errors in case the auto-catenate is not allowed in the urlname datatype $event->name = $resolver->generate_unique_name(); } } else { $node = new midcom_db_topic($this->_feed->node); $node_lang_code = $node->get_parameter('net.nemein.calendar', 'language'); // This is a new item $event = new net_nemein_calendar_event_dba(); $event->start = $start; $event->end = $end; $event->extra = md5($item['guid']); $event->node = $this->_feed->node; if ($node->get_parameter('net.nemein.calendar', 'symlink_topic') != '') { try { $symlink_topic = new midcom_db_topic($node->get_parameter('net.nemein.calendar', 'symlink_topic')); $event->node = $symlink_topic->id; } catch (midcom_error $e) { $e->log(); } } if ($node_lang_code != '') { $lang_id = midcom::get('i18n')->code_to_id($node_lang_code); $event->lang = $lang_id; } $event->allow_name_catenate = true; $event->title = (string) $item['title']; $event->_activitystream_verb = 'http://community-equity.org/schema/1.0/clone'; $event->_rcs_message = sprintf(midcom::get('i18n')->get_string('%s was imported from %s', 'net.nemein.rss'), $event->title, $this->_feed->title); $resolver = new midcom_helper_reflector_nameresolver($event); $event->name = $resolver->generate_unique_name(); if (!$event->create()) { return false; } } $this->_datamanager->autoset_storage($event); $this->_datamanager->types['start']->value = new DateTime(strftime('%Y-%m-%d %H:%M:%S', $start)); $this->_datamanager->types['end']->value = new DateTime(strftime('%Y-%m-%d %H:%M:%S', $end)); if (is_a($this->_datamanager->types['location'], 'midcom_helper_datamanager2_type_position')) { // Position type, give all values we got, assume order "Street, City, Country" $location_parts = array_reverse($location_parts); if (count($location_parts) > 0) { $country = org_routamc_positioning_country_dba::get_by_name($location_parts[0]); if ($country && $country->code) { $this->_datamanager->types['location']->location->county = $country->code; } } if (count($location_parts) > 1) { $city = org_routamc_positioning_city_dba::get_by_name($location_parts[1]); if ($city && $city->id) { $this->_datamanager->types['location']->location->city = $city->id; } } if (count($location_parts) > 2) { $this->_datamanager->types['location']->location->street = $location_parts[2]; } if (isset($item['gml'])) { $gml_parts = explode(' ', $item['gml']['where_point_pos']); if (count($gml_parts) == 2) { $this->_datamanager->types['location']->location->latitude = (double) $gml_parts[0]; $this->_datamanager->types['location']->location->longitude = (double) $gml_parts[1]; } } } else { // Just give the location string we got $this->_datamanager->types['location']->value = implode(', ', $location_parts); } foreach ($item as $key => $value) { if (isset($this->_datamanager->types[$key])) { $this->_datamanager->types[$key]->value = $value; } } if (!$this->_datamanager->save()) { return false; } // This should be unnecessary but left in place just to be sure if (strlen($this->_datamanager->storage->object->name) == 0) { // Generate something to avoid empty "/" links in case of failures $this->_datamanager->storage->object->name = time(); $this->_datamanager->storage->object->update(); } $this->parse_tags($event, $item, 'description'); $this->parse_parameters($event, $item); return $event->guid; }
private function _resolve_productlink($productlink, $topic) { if (!$productlink->productGroup) { return null; } $intree = false; $real_config = new midcom_helper_configuration($topic, 'org.openpsa.products'); if ($real_config->get('root_group') != null && $real_config->get('root_group') != 0) { $root_group = new org_openpsa_products_product_group_dba($real_config->get('root_group')); if ($root_group->id == $productlink->productGroup) { $intree = true; } else { $qb_intree = org_openpsa_products_product_group_dba::new_query_builder(); $qb_intree->add_constraint('up', 'INTREE', $root_group->id); $qb_intree->add_constraint('id', '=', $productlink->productGroup); $results = $qb_intree->execute(); if ($qb_intree->count() > 0) { $intree = true; } } if ($intree) { $category_qb = org_openpsa_products_product_group_dba::new_query_builder(); $category_qb->add_constraint('id', '=', $productlink->productGroup); $category = $category_qb->execute_unchecked(); //Check if the product is in a nested category. if ($category && !empty($category[0]->up)) { $parent_category_qb = org_openpsa_products_product_group_dba::new_query_builder(); $parent_category_qb->add_constraint('id', '=', $category[0]->up); $parent_category = $parent_category_qb->execute_unchecked(); if ($parent_category && isset($parent_category[0]->code)) { return "productlink/{$productlink->guid}/"; } } else { return "productlink/{$productlink->guid}/"; } } else { return null; } } else { return "productlink/{$productlink->guid}/"; } }