Пример #1
0
 /**
  * Get one level of navigation
  *
  * @return Array containing navigation data
  */
 public static function get_product_group_navigation($id)
 {
     // Initialize the array
     $leaves = array();
     if (mgd_is_guid($id)) {
         try {
             $group = org_openpsa_products_product_group_dba::get_cached($id);
         } catch (midcom_error $e) {
             // Stop silently
             return $leaves;
         }
         $id = $group->id;
     }
     // Initialize the query builder
     $qb = org_openpsa_products_product_group_dba::new_query_builder();
     $qb->add_constraint('up', '=', $id);
     $qb->add_order('metadata.score', 'DESC');
     $qb->add_order('title');
     $qb->add_order('code');
     $groups = $qb->execute();
     // Get the properties of each group
     foreach ($groups as $group) {
         $leaves[$group->id] = array(MIDCOM_NAV_URL => $group->code ? "{$group->code}/" : "{$group->guid}/", MIDCOM_NAV_NAME => $group->title, MIDCOM_NAV_GUID => $group->guid, MIDCOM_NAV_OBJECT => $group, MIDCOM_NAV_NOENTRY => (bool) $group->metadata->navnoentry);
     }
     return $leaves;
 }
Пример #2
0
 /**
  * Simple lookup method which tries to map the guid to an article of out topic.
  */
 public function _on_resolve_permalink($topic, $config, $guid)
 {
     if (isset($config) && $config->get('disable_permalinks')) {
         return null;
     }
     $topic_guid = $config->get('symlink_topic');
     if (!empty($topic_guid) && mgd_is_guid($topic_guid)) {
         try {
             $new_topic = new midcom_db_topic($topic_guid);
             $topic = $new_topic;
         } catch (midcom_error $e) {
             $e->log();
         }
     }
     try {
         $article = new midcom_db_article($guid);
     } catch (midcom_error $e) {
         return null;
     }
     $arg = $article->name ? $article->name : $article->guid;
     if ($config->get('view_in_url')) {
         return "view/{$arg}/";
     } else {
         return "{$arg}/";
     }
 }
Пример #3
0
 /**
  * Photo inclusion support [photo: GUID]
  */
 private function _run_macro_photo($macro_content, $fulltag, $after)
 {
     $guid = trim($macro_content);
     if (!mgd_is_guid($guid)) {
         // value is not guid
         return $fulltag;
     }
     midcom::get('componentloader')->load_graceful('org.routamc.photostream');
     if (!class_exists('org_routamc_photostream_photo_dba')) {
         // TODO: do something to explain that we can't load o.r.photos...
         return $fulltag;
     }
     try {
         $photo = new org_routamc_photostream_photo_dba($guid);
         // Get the correct photo NAP object based on the GUID
         $nap = new midcom_helper_nav();
         $node = $nap->get_node($photo->node);
         if ($node[MIDCOM_NAV_COMPONENT] != 'org.routamc.photostream') {
             return "<span class=\"missing_photo\" title=\"{$guid}\">{$fulltag}</span>{$after}";
         }
     } catch (midcom_error $e) {
         $e->log();
         return "<span class=\"missing_photo\" title=\"{$guid}\">{$fulltag}</span>{$after}";
     }
     // Start buffering
     ob_start();
     // Load the photo
     midcom::get()->dynamic_load("{$node[MIDCOM_NAV_RELATIVEURL]}photo/raw/{$photo->guid}");
     // FIXME: The newlines are to avoid some CSS breakage. Problem is that Markdown adds block-level tags around this first
     $content = "\n\n" . str_replace('h1', 'h3', ob_get_contents()) . "\n\n";
     ob_end_clean();
     return "{$content}{$after}";
 }
Пример #4
0
 public function send_mail($message, $force_save = false)
 {
     if (!$this->recipient || empty($this->recipient->email)) {
         return false;
     }
     $mail = new net_nemein_notifications_api_mail();
     $mail->to = $this->recipient->email;
     $sender = null;
     $from = null;
     if (array_key_exists('from', $message) && !empty($message['from'])) {
         if (mgd_is_guid($message['from']) || is_int($message['from'])) {
             $sender = new midgard_person($message['from']);
         } else {
             $from = $message['from'];
         }
     } else {
         if ($_MIDGARD['user']) {
             //TODO: Get the user
         }
     }
     if (!is_null($sender) && is_null($from) && $sender->email) {
         $mail->from = '"' . $sender->firstname . " " . $sender->lastname . '" <' . $sender->email . '>';
     } else {
         if (!is_null($from)) {
             $mail->from = $from;
         } else {
             $mail->from = $this->configuration->get('fallback_mail_from');
         }
     }
     $mail->send();
     if ($this->configuration->get('auto_save') || $force_save) {
         $this->save_notification($message);
     }
 }
Пример #5
0
 /**
  * Helper to make an array usable with DM2 select datatype for selecting product groups
  *
  * @param mixed $up            Either the ID or GUID of the product group
  * @param string $prefix       Prefix for the code
  * @param string $keyproperty  Property to use as the key of the resulting array
  * @param array $label_fields  Object properties to show in the label (will be shown space separated)
  * @return array
  */
 public static function list_groups($up = 0, $prefix = '', $keyproperty = 'id', $order_by_score = false, $label_fields = array('code', 'title'))
 {
     static $result_cache = array();
     $cache_key = md5($up . $keyproperty . $prefix . $order_by_score . implode('', $label_fields));
     if (isset($result_cache[$cache_key])) {
         return $result_cache[$cache_key];
     }
     $result_cache[$cache_key] = array();
     $ret =& $result_cache[$cache_key];
     if (empty($up)) {
         // TODO: use reflection to see what kind of property this is ?
         if ($keyproperty == 'id') {
             $ret[0] = midcom::get('i18n')->get_string('toplevel', 'org.openpsa.products');
         } else {
             $ret[''] = midcom::get('i18n')->get_string('toplevel', 'org.openpsa.products');
         }
     }
     if (mgd_is_guid($up)) {
         $group = new org_openpsa_products_product_group_dba($up);
         $up = $group->id;
     }
     $mc = org_openpsa_products_product_group_dba::new_collector('up', (int) $up);
     $mc->add_value_property('title');
     $mc->add_value_property('code');
     $mc->add_value_property('id');
     if ($keyproperty !== 'id') {
         $mc->add_value_property($keyproperty);
     }
     foreach ($label_fields as $fieldname) {
         if ($fieldname == 'id' || $fieldname == $keyproperty) {
             continue;
         }
         $mc->add_value_property($fieldname);
     }
     unset($fieldname);
     // Order by score if required
     if ($order_by_score) {
         $mc->add_order('metadata.score', 'DESC');
     }
     $mc->add_order('code');
     $mc->add_order('title');
     $mc->execute();
     $mc_keys = $mc->list_keys();
     foreach ($mc_keys as $mc_key => $dummy) {
         $id = $mc->get_subkey($mc_key, 'id');
         $key = $mc->get_subkey($mc_key, $keyproperty);
         $ret[$key] = $prefix;
         foreach ($label_fields as $fieldname) {
             $field_val = $mc->get_subkey($mc_key, $fieldname);
             $ret[$key] .= "{$field_val} ";
         }
         unset($fieldname, $field_val);
         $ret = $ret + org_openpsa_products_product_group_dba::list_groups($id, "{$prefix} > ", $keyproperty, $label_fields);
         unset($id, $key);
     }
     unset($mc, $mc_keys, $dummy, $mc_key);
     return $ret;
 }
Пример #6
0
 public function load_object(array $args)
 {
     midgardmvc_core::get_instance()->authorization->require_user();
     if (!mgd_is_guid($args['group'])) {
         throw new midgardmvc_exception_notfound("Group {$args['group']} not found");
     }
     try {
         $this->object = new fi_openkeidas_groups_group($args['group']);
     } catch (midgard_error_exception $e) {
         throw new midgardmvc_exception_notfound($e->getMessage());
     }
 }
Пример #7
0
 private static function get_item_by_guid($guid)
 {
     if (!mgd_is_guid($guid)) {
         throw new InvalidArgumentException("Argument must be a valid GUID");
     }
     try {
         $item = new com_meego_planet_item($guid);
     } catch (midgard_error_exception $e) {
         throw new midgardmvc_exception_notfound($e->getMessage());
     }
     return $item;
 }
Пример #8
0
 /**
  * Retrieves the user specified by guid
  *
  * @param guid user's person guid
  * @return object midgard_user object
  */
 public static function get_user_by_person_guid($guid = '')
 {
     $user = null;
     if (mgd_is_guid($guid)) {
         $qb = new midgard_query_builder('midgard_person');
         $qb->add_constraint('guid', '=', $guid);
         $users = $qb->execute();
         if (count($users)) {
             $user = $users[0];
         }
         unset($qb);
     }
     return $user;
 }
Пример #9
0
 /**
  * Get schema name for person
  *
  * @return string Schema name
  */
 public function get_person_schema(org_openpsa_contacts_person_dba $contact)
 {
     $my_company_guid = $this->_config->get('owner_organization');
     if (empty($my_company_guid) || !mgd_is_guid($my_company_guid)) {
         if (midcom::get('auth')->admin) {
             midcom::get('uimessages')->add($this->_l10n->get($this->_component), $this->_l10n->get('owner organization couldnt be found'), 'error');
         }
     } else {
         // Figure out if user is from own organization or other org
         $person_user = new midcom_core_user($contact->id);
         if ($person_user->is_in_group("group:{$my_company_guid}")) {
             return 'employee';
         }
     }
     return null;
 }
Пример #10
0
 /**
  * Retrieves the user specified by guid
  *
  * @param guid user's guid
  * @return object midgard_user object
  */
 public static function get_user_by_guid($guid = '')
 {
     $user = null;
     if (mgd_is_guid($guid)) {
         $storage = new midgard_query_storage('midgard_user');
         $q = new midgard_query_select($storage);
         $q->set_constraint(new midgard_query_constraint(new midgard_query_property('guid'), '=', new midgard_query_value($guid)));
         $q->execute();
         $q->toggle_readonly(false);
         $users = $q->list_objects();
         if (count($users)) {
             $user = $users[0];
         }
         unset($storage);
         unset($q);
         unset($users);
     }
     return $user;
 }
Пример #11
0
 /**
  * Locates the root event
  */
 public static function find_root_event()
 {
     if (!midcom::get('componentloader')->is_loaded('org.openpsa.calendar')) {
         midcom::get('componentloader')->load_graceful('org.openpsa.calendar');
         //Doublecheck
         if (!midcom::get('componentloader')->is_loaded('org.openpsa.calendar')) {
             return false;
         }
     }
     $data = midcom_baseclasses_components_configuration::get('org.openpsa.calendar');
     //Check if we have already initialized
     if (isset($data['calendar_root_event']) && is_object($data['calendar_root_event'])) {
         return $data['calendar_root_event'];
     }
     $root_event = false;
     $root_guid = $data['config']->get('calendar_root_event');
     if (mgd_is_guid($root_guid)) {
         $root_event = org_openpsa_calendar_event_dba::get_cached($root_guid);
     } else {
         // Check for calendar event tree.
         $qb = org_openpsa_calendar_event_dba::new_query_builder();
         $qb->add_constraint('title', '=', '__org_openpsa_calendar');
         $qb->add_constraint('up', '=', '0');
         $ret = $qb->execute();
         if (is_array($ret) && count($ret) > 0) {
             $root_event = $ret[0];
             $siteconfig = org_openpsa_core_siteconfig::get_instance();
             $topic_guid = $siteconfig->get_node_guid('org.openpsa.calendar');
             if ($topic_guid) {
                 $topic = new midcom_db_topic($topic_guid);
                 $topic->set_parameter('org.openpsa.calendar', 'calendar_root_event', $root_event->guid);
             }
         } else {
             debug_add("OpenPSA Calendar root event could not be found", MIDCOM_LOG_ERROR);
             //Attempt to auto-initialize
             $root_event = self::create_root_event();
         }
     }
     $data['calendar_root_event'] = $root_event;
     return $root_event;
 }
Пример #12
0
 /**
  * Simple lookup method which tries to map the guid to an article of out topic.
  */
 public function _on_resolve_permalink($topic, $config, $guid)
 {
     $topic_guid = $config->get('symlink_topic');
     if (!empty($topic_guid) && mgd_is_guid($topic_guid)) {
         try {
             $new_topic = new midcom_db_topic($topic_guid);
             $topic = $new_topic;
         } catch (midcom_error $e) {
             $e->log();
         }
     }
     try {
         $article = new midcom_db_article($guid);
     } catch (midcom_error $e) {
         return null;
     }
     if ($article->name == 'index' && !$config->get('autoindex')) {
         return '';
     }
     return "{$article->name}/";
 }
Пример #13
0
 private function normalize_variables($variables, $values, $argv_str)
 {
     // Map variable arguments
     $matched = array();
     foreach ($variables as $index => $varname) {
         $variable_parts = explode(':', $varname);
         if (count($variable_parts) == 1) {
             $type_hint = '';
         } else {
             $type_hint = $variable_parts[0];
         }
         // Strip type hints from variable names
         $varname = mb_ereg_replace('^.+:', '', $varname);
         if ($type_hint == 'token') {
             // Tokenize the argument to handle resource typing
             $matched[$varname] = $this->tokenize_argument($values[$index]);
         } else {
             $value = $values[$index];
             switch ($type_hint) {
                 case 'string':
                 case '':
                     $matched[$varname] = $value;
                     break;
                 case 'guid':
                     if (!function_exists('mgd_is_guid') || !mgd_is_guid($value)) {
                         throw new InvalidArgumentException("Variable '{$varname}' is type hinted as '{$type_hint}' but parsed value '{$value}' is not guid");
                     }
                     $matched[$varname] = $value;
                     break;
                 case 'int':
                     if (!is_numeric($value)) {
                         throw new InvalidArgumentException("Variable '{$varname}' is type hinted as '{$type_hint}' but parsed value '{$value}' is not numeric");
                     }
                     $matched[$varname] = (int) $value;
                     break;
                 case 'float':
                 case 'double':
                     if (!is_numeric($value)) {
                         throw new InvalidArgumentException("Variable '{$varname}' is type hinted as '{$type_hint}' but parsed value '{$value}' is not numeric");
                     }
                     $matched[$varname] = (double) $value;
                     break;
                 default:
                     throw new InvalidArgumentException("Variable '{$varname}' is type hinted as '{$type_hint}', but he hint is not understood");
             }
         }
     }
     return $matched;
 }
Пример #14
0
 /**
  * Resolve MgdSchema object from guid or miscellaneous extended object
  *
  * @param mixed &$object    MgdSchema object, GUID or ID
  * @param string $class     MgdSchema class for resolving ID
  * @return mixed MgdSchema object or false on failure
  */
 public static function resolve_object(&$object, $class = null)
 {
     // Check the type of the requested parent
     switch (true) {
         case is_object($object):
             break;
         case mgd_is_guid($object):
             $object = midcom::get('dbfactory')->get_object_by_guid($object);
             break;
         case $class:
             $id = (int) $object;
             $object = new $class($id);
             // Bulletproof the attempt
             if (!$object->guid) {
                 return false;
             }
             break;
         default:
             return false;
     }
     $object_class = midcom_helper_reflector::resolve_baseclass(get_class($object));
     // This is an original MgdSchema class
     if ($object_class === get_class($object)) {
         return $object;
     }
     // Get the initial MgdSchema class
     $object = new $object_class($object->guid);
     return $object;
 }
Пример #15
0
 /**
  * Constructor. Creates an abstraction layer for an MgdSchema object.
  */
 public function __construct($id = null)
 {
     if (is_object($id)) {
         $this->__object = midcom::get('dbfactory')->convert_midcom_to_midgard($id);
     } else {
         if (is_string($id) && strlen($id) == 1) {
             debug_add('Constructing ' . $this->__mgdschema_class_name__ . ' object ' . $id . ' with ID typecast to string. Changing typecast.', MIDCOM_LOG_INFO);
             $id = (int) $id;
         }
         if (is_int($id) && $id < 1) {
             throw new midcom_error($id . ' is not a valid database ID');
         }
         try {
             $mgdschemaclass = $this->__mgdschema_class_name__;
             $this->__object = new $mgdschemaclass($id);
         } catch (midgard_error_exception $e) {
             debug_add('Constructing ' . $this->__mgdschema_class_name__ . ' object ' . $id . ' failed, reason: ' . $e->getMessage(), MIDCOM_LOG_WARN);
             throw new midcom_error_midgard($e, $id);
         }
         //Some useful information for performance tuning
         if ($GLOBALS['midcom_config']['log_level'] >= MIDCOM_LOG_DEBUG && $this->__object->guid) {
             static $guids = array();
             static $total = 0;
             $total++;
             //If the GUID was loaded already, write the appropriate log entry
             if (array_key_exists($this->__object->guid, $guids)) {
                 $guids[$this->__object->guid]++;
                 $message = $this->__mgdschema_class_name__ . ' ' . $this->__object->guid;
                 $message .= ' loaded from db ' . $guids[$this->__object->guid] . ' times.';
                 $stats = 'Objects loaded (Total/Unique): ' . $total . '/' . sizeof($guids);
                 debug_add($message);
                 debug_add($stats);
             } else {
                 $guids[$this->__object->guid] = 1;
             }
         }
     }
     if ($this->__object->guid && mgd_is_guid($this->__object->guid)) {
         midcom_baseclasses_core_dbobject::post_db_load_checks($this);
     }
 }
Пример #16
0
 /**
  * Sets the constraints for QB for articles, supports article links etc..
  *
  * @param midgard_query_builder $qb reference to the QB object
  * @param array $data reference to the request_data array
  */
 public static function article_qb_constraints(&$qb, &$data, $handler_id)
 {
     $config =& $data['config'];
     // GUIDs of topics to list articles from.
     $guids_array = array();
     $guids_array[] = $data['content_topic']->guid;
     // Resolve any other topics we may need
     $list_from_folders = $config->get('list_from_folders');
     if ($list_from_folders) {
         // We have specific folders to list from, therefore list from them and current node
         $guids = explode('|', $config->get('list_from_folders'));
         foreach ($guids as $guid) {
             if (!$guid || !mgd_is_guid($guid)) {
                 // Skip empty and broken guids
                 continue;
             }
             $guids_array[] = $guid;
         }
     }
     /**
      * Ref #1776, expands GUIDs before adding them as constraints, should save query time
      */
     $topic_ids = array();
     $topic_ids[] = $data['content_topic']->id;
     if (!empty($guids_array)) {
         $mc = midcom_db_topic::new_collector('metadata.deleted', false);
         $mc->add_constraint('guid', 'IN', $guids_array);
         $topic_ids = $mc->get_values('id');
         unset($mc);
     }
     // Include the article links to the indexes if enabled
     if ($config->get('enable_article_links')) {
         $mc = net_nehmer_blog_link_dba::new_collector('topic', $data['content_topic']->id);
         $mc->add_constraint('topic', '=', $data['content_topic']->id);
         $mc->add_order('metadata.published', 'DESC');
         $mc->set_limit((int) $config->get('index_entries'));
         // Get the results
         $mc->execute();
         $links = $mc->get_values('article');
         $qb->begin_group('OR');
         $qb->add_constraint('id', 'IN', $links);
         $qb->add_constraint('topic', 'IN', $topic_ids);
         $qb->end_group();
     } else {
         $qb->add_constraint('topic', 'IN', $topic_ids);
     }
     if (count($topic_ids) > 1 && ($list_from_folders_categories = $config->get('list_from_folders_categories'))) {
         // TODO: check schema storage to get fieldname
         $multiple_categories = true;
         if (isset($data['schemadb']['default']) && isset($data['schemadb']['default']->fields['list_from_folders_categories']) && array_key_exists('allow_multiple', $data['schemadb']['default']->fields['list_from_folders_categories']['type_config']) && !$data['schemadb']['default']->fields['list_from_folders_categories']['type_config']['allow_multiple']) {
             $multiple_categories = false;
         }
         debug_add("multiple_categories={$multiple_categories}");
         $qb->begin_group('OR');
         $list_from_folders_categories = explode(',', $list_from_folders_categories);
         $is_content_topic = true;
         foreach ($topic_ids as $topic_id) {
             if ($is_content_topic) {
                 $qb->add_constraint('topic', '=', $topic_id);
                 $is_content_topic = false;
                 continue;
             }
             $qb->begin_group('AND');
             $qb->add_constraint('topic', '=', $topic_id);
             $qb->begin_group('OR');
             foreach ($list_from_folders_categories as $category) {
                 if ($category = trim($category)) {
                     if ($multiple_categories) {
                         $qb->add_constraint('extra1', 'LIKE', "%|{$category}|%");
                     } else {
                         $qb->add_constraint('extra1', '=', $category);
                     }
                 }
             }
             $qb->end_group();
             $qb->end_group();
         }
         $qb->end_group();
     }
     // Hide the articles that have the publish time in the future and if
     // the user is not administrator
     if ($config->get('enable_scheduled_publishing') && !midcom::get('auth')->admin) {
         // Show the article only if the publishing time has passed or the viewer
         // is the author
         $qb->begin_group('OR');
         $qb->add_constraint('metadata.published', '<', gmdate('Y-m-d H:i:s'));
         if (midcom::get('auth')->user && isset(midcom::get('auth')->user->guid)) {
             $qb->add_constraint('metadata.authors', 'LIKE', '|' . midcom::get('auth')->user->guid . '|');
         }
         $qb->end_group();
     }
     $qb->add_constraint('up', '=', 0);
 }
Пример #17
0
 private function _process_results($result)
 {
     if ($result === false) {
         // Error while searching, we ignore this silently, as this is usually
         // a broken query. We don't have yet a way to pass error messages from
         // the indexer backend though (what would I give for a decent exception
         // handling here...)
         debug_add('Got boolean false as resultset (likely broken query), casting to empty array', MIDCOM_LOG_WARN);
         $result = array();
     }
     $count = count($result);
     $this->_request_data['document_count'] = $count;
     if ($count == 0) {
         midcom::get('cache')->content->uncached();
     }
     if ($count > 0) {
         $results_per_page = $this->_config->get('results_per_page');
         $max_pages = ceil($count / $results_per_page);
         $page = min($_REQUEST['page'], $max_pages);
         $first_document_id = ($page - 1) * $results_per_page;
         $last_document_id = min($count - 1, $page * $results_per_page - 1);
         $this->_request_data['page'] = $page;
         $this->_request_data['max_pages'] = $max_pages;
         $this->_request_data['first_document_number'] = $first_document_id + 1;
         $this->_request_data['last_document_number'] = $last_document_id + 1;
         $this->_request_data['shown_documents'] = $last_document_id - $first_document_id + 1;
         $this->_request_data['results_per_page'] = $results_per_page;
         $this->_request_data['all_results'] =& $result;
         $this->_request_data['result'] = array_slice($result, $first_document_id, $results_per_page);
         // Register GUIDs for cache engine
         foreach ($this->_request_data['result'] as $doc) {
             if (!isset($doc->source) || !mgd_is_guid($doc->source)) {
                 // Non-Midgard results don't need to go through cache registration
                 continue;
             }
             midcom::get('cache')->content->register($doc->source);
         }
         reset($this->_request_data['result']);
     }
 }
Пример #18
0
 /**
  * Look up a specific content privilege and cache the result. This implements the same semantics
  * as _collect_content_privileges, but only works for one privilege at a time, which allows us to cut
  * a few corners and therefore be faster
  *
  * @param string $privilegename The privilege to check for
  * @param string $guid A Midgard GUID pointing to an object
  * @param string $class DBA Class of the object in question
  * @param string $user_id The user against which to check the privilege, defaults to the currently authenticated user.
  * @return boolean True when privilege was found, otherwise false
  */
 private static function _load_content_privilege($privilegename, $guid, $class, $user_id)
 {
     $cache_id = $user_id . '::' . $guid;
     if (!array_key_exists($cache_id, self::$_content_privileges_cache)) {
         self::$_content_privileges_cache[$cache_id] = array();
     }
     if (array_key_exists($privilegename, self::$_content_privileges_cache[$cache_id])) {
         return self::$_content_privileges_cache[$cache_id][$privilegename];
     }
     $object_privileges = midcom_core_privilege::get_content_privileges($guid);
     $last_scope = -1;
     $content_privilege = null;
     foreach ($object_privileges as $privilege) {
         if ($privilege->privilegename != $privilegename || $privilege->scope <= $last_scope || !$privilege->does_privilege_apply($user_id)) {
             continue;
         }
         $last_scope = $privilege->scope;
         $content_privilege = $privilege;
     }
     //owner privileges override everything but person privileges, so we have to cross-check those here
     if ($privilegename != 'midgard:owner' && $last_scope < MIDCOM_PRIVILEGE_SCOPE_OWNER) {
         $owner_privileges = midcom::get('auth')->acl->get_owner_default_privileges();
         if (array_key_exists($privilegename, $owner_privileges)) {
             $found = self::_load_content_privilege('midgard:owner', $guid, $class, $user_id);
             if ($found && self::$_content_privileges_cache[$cache_id]['midgard:owner']) {
                 self::$_content_privileges_cache[$cache_id][$privilegename] = $owner_privileges[$privilegename];
                 return true;
             }
         }
     }
     if (!is_null($content_privilege)) {
         self::$_content_privileges_cache[$cache_id][$privilegename] = $content_privilege->value == MIDCOM_PRIVILEGE_ALLOW;
         return true;
     }
     //if nothing was found, we try to recurse to parent
     // ==> into SUDO
     $previous_sudo = midcom::get('auth')->acl->_internal_sudo;
     midcom::get('auth')->acl->_internal_sudo = true;
     $parent_guid = midcom::get('dbfactory')->get_parent_guid($guid, $class);
     midcom::get('auth')->acl->_internal_sudo = $previous_sudo;
     // <== out of SUDO
     if ($parent_guid == $guid || !mgd_is_guid($parent_guid)) {
         return false;
     } else {
         $parent_cache_id = $user_id . '::' . $parent_guid;
         if (!array_key_exists($parent_cache_id, self::$_privileges_cache)) {
             self::$_content_privileges_cache[$parent_cache_id] = array();
         }
         if (self::_load_content_privilege($privilegename, $parent_guid, null, $user_id)) {
             self::$_content_privileges_cache[$cache_id][$privilegename] = self::$_content_privileges_cache[$parent_cache_id][$privilegename];
             return true;
         }
         return false;
     }
 }
Пример #19
0
 /**
  * Loads the comments, does any processing according to the state of the GET list.
  * On successful processing we relocate once to ourself.
  *
  * @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.
  */
 function _handler_comments($handler_id, array $args, array &$data)
 {
     if (!mgd_is_guid($args[0])) {
         throw new midcom_error("The GUID '{$args[0]}' is invalid. Cannot continue.");
     }
     $this->_objectguid = $args[0];
     midcom::get('cache')->content->register($this->_objectguid);
     if ($handler_id == 'view-comments-nonempty') {
         $this->_comments = net_nehmer_comments_comment::list_by_objectguid_filter_anonymous($this->_objectguid, $this->_config->get('items_to_show'), $this->_config->get('item_ordering'), $this->_config->get('paging'));
     } else {
         $this->_comments = net_nehmer_comments_comment::list_by_objectguid($this->_objectguid, $this->_config->get('items_to_show'), $this->_config->get('item_ordering'), $this->_config->get('paging'));
     }
     if ($this->_config->get('paging') !== false) {
         $data['qb_pager'] = $this->_comments;
         $this->_comments = $this->_comments->execute();
     }
     if (midcom::get('auth')->user || $this->_config->get('allow_anonymous')) {
         $this->_init_post_controller();
         $this->_process_post();
         // This might exit.
     }
     if ($this->_comments) {
         $this->_init_display_datamanager();
     }
     $this->_process_admintoolbar();
     // This might exit.
     if ($handler_id = 'view-comments-custom' && count($args) > 1) {
         midcom::get()->skip_page_style = true;
         $this->custom_view = $args[1];
     }
     $this->_prepare_request_data();
     midcom::get('metadata')->set_request_metadata($this->_get_last_modified(), $this->_objectguid);
     if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') {
         midcom::get()->skip_page_style = true;
     }
 }
Пример #20
0
 /**
  * Retrieves devices created by user having the guid
  *
  * @param guid guid of the user
  * @return array an array of com_meego_devprogram_device objects
  */
 private static function get_devices_by_creator_guid($guid = '')
 {
     $devices = array();
     if (mgd_is_guid($guid)) {
         $devices = self::get_devices(array('creator' => $guid));
     }
     return $devices;
 }
Пример #21
0
 private function _load($src)
 {
     if (is_object($src) && is_a($src, 'midcom_core_privilege_db')) {
         // Got a privilege object as argument, use that
         $this->__guid = $src->guid;
         $this->__privilege_object = $src;
     } else {
         if (is_string($src) && mgd_is_guid($src)) {
             $this->__guid = $src;
             $this->__privilege_object = new midcom_core_privilege_db($src);
         } else {
             // Have a nonpersistent privilege
             $this->__privilege_object = new midcom_core_privilege_db();
         }
     }
 }
Пример #22
0
 /**
  * Retrieves membership using various filters
  *
  * @param array filters array
  *
  * @return array an array of com_meego_devprogram_provider_membership objects
  *               extended with some handy properties
  */
 private static function get_memberships(array $filters)
 {
     $memberships = array();
     $storage = new midgard_query_storage('com_meego_devprogram_provider_membership');
     $q = new midgard_query_select($storage);
     if (count($filters) > 1 || count($filters) == 1 && !array_key_exists('status', $filters)) {
         $qc = new midgard_query_constraint_group('AND');
     }
     foreach ($filters as $filter => $value) {
         switch ($filter) {
             case 'creator':
                 // check if creator guid is valid
                 if (mgd_is_guid($value)) {
                     $constraint = new midgard_query_constraint(new midgard_query_property('metadata.creator'), '=', new midgard_query_value($value));
                 }
                 break;
             case 'provider':
             case 'person':
                 if (isset($value)) {
                     $constraint = new midgard_query_constraint(new midgard_query_property($filter), '=', new midgard_query_value($value));
                 }
                 break;
             case 'status':
                 if (isset($value)) {
                     $constraint = new midgard_query_constraint(new midgard_query_property($filter), '=', new midgard_query_value($value));
                 }
                 break;
         }
         // set the constraint
         if (is_a($qc, 'midgard_query_constraint_group')) {
             $qc->add_constraint($constraint);
         } else {
             $qc = $constraint;
         }
     }
     if (!array_key_exists('status', $filters)) {
         // if status was not set explicitly then include all but cancelled memberships
         $constraint = new midgard_query_constraint(new midgard_query_property('status'), '<', new midgard_query_value(CMD_MEMBERSHIP_CANCELLED));
         // set the constraint
         if (count($filters) >= 1) {
             if (!is_a($qc, 'midgard_query_constraint_group')) {
                 $qc = new midgard_query_constraint_group('AND');
             }
             $qc->add_constraint($constraint);
         } else {
             $qc = $constraint;
         }
     }
     $q->set_constraint($qc);
     $q->execute();
     // does not seem to work
     // @bug: $q->toggle_read_only(false);
     $objects = $q->list_objects();
     foreach ($objects as $object) {
         $memberships[] = self::extend_membership($object);
     }
     return $memberships;
 }
Пример #23
0
 /**
  * This is a helper function which determines the parent GUID for an existing
  * GUID according to the MidCOM content tree rules.
  *
  * It tries to look up the GUID in the memory cache, only if this fails, the regular
  * content getters are invoked.
  *
  * @param mixed $object Either a MidCOM DBA object instance, or a GUID string.
  * @param string $class class name of object if known (so we can use get_parent_guid_uncached_static and avoid instantiating full object)
  * @return string The parent GUID, or null, if this is a top level object.
  */
 function get_parent_guid($object, $class = null)
 {
     if (is_object($object)) {
         if (!isset($object->guid)) {
             $object_guid = null;
         } else {
             if (isset($object->__guid) && !$object->guid) {
                 $object_guid = $object->__guid;
             } else {
                 $object_guid = $object->guid;
             }
         }
         $the_object = $object;
     } else {
         $object_guid = $object;
         $the_object = null;
     }
     static $cached_parent_guids = array();
     if (mgd_is_guid($object_guid)) {
         if (array_key_exists($object_guid, $cached_parent_guids)) {
             // We already got this either via query or memcache
             return $cached_parent_guids[$object_guid];
         }
         $parent_guid = midcom::get('cache')->memcache->lookup_parent_guid($object_guid);
     } else {
         if ($the_object === null) {
             throw new midcom_error('Tried to resolve an invalid GUID without an object being present. This cannot be done.');
         } else {
             $parent_guid = false;
         }
     }
     if (!$parent_guid) {
         // No cache hit, retrieve guid and update the cache
         if ($class) {
             // Class defined, we can use the static method for fetching parent and avoiding full object instantiate
             $parent_guid = call_user_func(array($class, 'get_parent_guid_uncached_static'), $object_guid, $class);
         } else {
             // class not defined, retrieve the full object by guid
             if ($the_object === null) {
                 try {
                     $the_object = $this->get_object_by_guid($object_guid);
                 } catch (midcom_error $e) {
                     return null;
                 }
             }
             $parent_guid = $the_object->get_parent_guid_uncached();
         }
         // Checking for old-behaviour
         if (is_object($parent_guid)) {
             debug_add('Warning, get_parent_guid_uncached should not return an object. This feature is deprecated.', MIDCOM_LOG_INFO);
             $parent_guid = $parent_guid->guid;
         }
         if (mgd_is_guid($object_guid)) {
             midcom::get('cache')->memcache->update_parent_guid($object_guid, $parent_guid);
         }
     }
     if (!mgd_is_guid($parent_guid)) {
         $parent_guid = null;
     }
     // Remember this so we don't need to get it again
     $cached_parent_guids[$object_guid] = $parent_guid;
     return $parent_guid;
 }
Пример #24
0
 /**
  * This function synchronizes the attachment listing parameter of this field with the
  * current attachment state.
  */
 private function _save_attachment_listing()
 {
     // Data that will be stored
     $data = array();
     // Count of attachments, used to calculate metadata->score
     $count = count($this->attachments);
     foreach ($this->attachments as $identifier => $attachment) {
         $attachment = $this->attachments[$identifier];
         if (!mgd_is_guid($attachment->guid)) {
             unset($attachment);
             continue;
         }
         // Store score if is sortable and we have value
         if ($this->sortable && isset($this->_sorted_list[$identifier])) {
             $score = $count - $this->_sorted_list[$identifier] + 1;
             // Store the attachment score
             $attachment->metadata->score = $score;
         }
         $data[] = "{$identifier}:{$attachment->guid}";
         unset($attachment);
     }
     // We need to be selective when saving, excluding one case: empty list
     // with empty storage object. In that case we store nothing. If we have
     // an object, we set the parameter unconditionally, to get all deletions.
     if ($this->storage->object) {
         $this->storage->object->set_parameter('midcom.helper.datamanager2.type.blobs', "guids_{$this->name}", implode(',', $data));
     } else {
         if ($data) {
             debug_add('We were told to store attachment GUIDs, but no storage object was present. This should not happen, ignoring silently.', MIDCOM_LOG_WARN);
             debug_print_r('This data should have been stored:', $data);
         }
     }
 }
Пример #25
0
 /**
  * Call a route of a component with given arguments and return the data it generated
  *
  * Dynamic calls may be called for either a specific page that has a component assigned to it
  * by specifying a page GUID or path as the first argument, or to a static instance of a component
  * by specifying component name as the first argument.
  *
  * @param string $component_name Component name, page GUID or page path
  * @param string $route_id     Route identifier
  * @param array $arguments  Arguments to give to the route
  * @param boolean $switch_context Whether to run the route in a new context
  * @return $array data
  */
 public function dynamic_call($component_name, $route_id, array $arguments, $switch_context = true)
 {
     if (is_null($this->dispatcher)) {
         $this->dispatcher = new midcom_core_services_dispatcher_manual();
     }
     if ($switch_context) {
         $_MIDCOM->context->create();
     }
     $page = null;
     if (mgd_is_guid($component_name)) {
         $page = new midgard_page($component_name);
     } elseif (strpos($component_name, '/') !== false) {
         $page = new midgard_page();
         $page->get_by_path($component_name);
     }
     if ($page) {
         $component_name = $page->component;
         if (!$component_name) {
             throw new Exception("Page {$page->guid} has no component defined");
         }
         $this->dispatcher->set_page($page);
     }
     $this->dispatcher->populate_environment_data();
     $this->dispatcher->initialize($component_name);
     if (!$_MIDCOM->context->component_instance->configuration->exists('routes')) {
         throw new Exception("Component {$component_name} has no routes defined");
     }
     $routes = $_MIDCOM->context->component_instance->configuration->get('routes');
     if (!isset($routes[$route_id])) {
         throw new Exception("Component {$component_name} has no route {$route_id}");
     }
     $this->dispatcher->set_route($route_id, $arguments);
     $this->dispatcher->dispatch();
     $data = $_MIDCOM->context->{$component_name};
     if ($switch_context) {
         $_MIDCOM->context->delete();
     }
     return $data;
 }
Пример #26
0
 /**
  * Loads the object identified by the ID from the database. After a successful
  * load by either get_by_id or get_by_guid methods or the copy constructor run,
  * the _on_loaded event handler is called. Thus, you have this calling sequence:
  *
  * 1. void $object->get_by_id($id) <i>or</i> $object->get_by_guid($guid) <i>or</i> copy constructor run.
  * 2. Validate privileges using can_do. The user needs midgard:read privilege on the content object.
  * 3. $object->_on_loaded() is executed to notify the class from a successful operation (and might abort by throwing an exception)
  *
  * This method is usually only called from the constructor of the class.
  *
  * @param midcom_core_dbaobject &$object The DBA object we're working on
  * @param mixed $id The object to load from the database. This can be either null (the default), indicating an empty object,
  *     a Midgard database row-ID or a Midgard GUID, the latter is detected using mgd_is_guid(). In addition, you can
  *     specify a parent object (usually a midgard_* base class) which will then use a copy constructor semantics instead.
  * @return bool Indicating success.
  * @see post_db_load_checks()
  * @see cast_object()
  */
 public static function load(midcom_core_dbaobject &$object, $id)
 {
     $object->id = 0;
     if (is_object($id)) {
         if (!self::cast_object($object, $id)) {
             return false;
         }
     } else {
         if (mgd_is_guid($id)) {
             if (!$object->__exec_get_by_guid($id)) {
                 debug_add("Failed to load the record identified by {$id}: " . midcom_connection::get_error_string(), MIDCOM_LOG_INFO);
                 self::_clear_object($object);
                 return false;
             }
         } else {
             if (is_numeric($id)) {
                 // Be sure we have an integer here, there are some problems when strings
                 // are passed.
                 if (!$object->__exec_get_by_id((int) $id)) {
                     debug_add("Failed to load the record identified by {$id}: " . midcom_connection::get_error_string(), MIDCOM_LOG_INFO);
                     self::_clear_object($object);
                     return false;
                 }
             } else {
                 debug_add("Failed to load object, argument {$id} is not valid..", MIDCOM_LOG_INFO);
                 self::_clear_object($object);
                 return false;
             }
         }
     }
     // This is a fallback implementation for earlier Versions of MidgardSchema, which
     // did not report loader errors during get_by_(gu)id appropriately.
     if ($object->id == 0 || $object->action == 'delete') {
         debug_add("Failed to load the record identified by {$id}: " . midcom_connection::get_error_string(), MIDCOM_LOG_INFO);
         debug_add('Midgard Version is too old, you should upgrade to latest 1.7 at least. get_by_id/guid is broken in this version.', MIDCOM_LOG_CRIT);
         self::_clear_object($object);
         return false;
     }
     return self::post_db_load_checks($object);
 }
Пример #27
0
 /**
  * Retrieves programs using various filters
  *
  * @param array filters, possible members: name, creator, status
  *              if multiple members used then we do a logical AND with them
  * @return object com_meego_devprogram_program object
  */
 public static function get_programs(array $filters)
 {
     $programs = array();
     $storage = new midgard_query_storage('com_meego_devprogram_program');
     $q = new midgard_query_select($storage);
     if (count($filters) > 1) {
         $qc = new midgard_query_constraint_group('AND');
     }
     foreach ($filters as $filter => $value) {
         switch ($filter) {
             case 'deleted':
                 if ($value) {
                     $q->include_deleted(true);
                 }
                 break;
             case 'creator':
                 // check if the value is a real guid
                 if (mgd_is_guid($value)) {
                     $constraint = new midgard_query_constraint(new midgard_query_property('metadata.creator'), '=', new midgard_query_value($value));
                 }
                 break;
             case 'id':
             case 'name':
             case 'device':
                 $constraint = new midgard_query_constraint(new midgard_query_property($filter), '=', new midgard_query_value($value));
                 break;
             case 'status':
                 // current date and time
                 $now = date("Y-m-d H:i:s");
                 switch ($value) {
                     case CMD_PROGRAM_CLOSED:
                         $type = '<';
                         break;
                     case CMD_PROGRAM_OPEN:
                     default:
                         $type = '>';
                 }
                 $constraint = new midgard_query_constraint(new midgard_query_property('duedate'), $type, new midgard_query_value($now));
                 break;
             case 'daysleft':
                 // duedate < now + value
                 $now = new DateTime();
                 $limit = $now->add(new DateInterval('P' . $value . 'D'));
                 $constraint = new midgard_query_constraint(new midgard_query_property('duedate'), '<', new midgard_query_value($limit->format('Y-m-d')));
                 break;
         }
         // set the constraint
         count($filters) > 1 ? $qc->add_constraint($constraint) : ($qc = $constraint);
     }
     $q->set_constraint($qc);
     $q->add_order(new midgard_query_property('metadata.created'), SORT_DESC);
     $q->execute();
     // does not seem to work
     // @bug: $q->toggle_read_only(false);
     $objects = $q->list_objects();
     if (count($objects)) {
         foreach ($objects as $object) {
             $programs[] = self::extend_program($object);
         }
     }
     return $programs;
 }
Пример #28
0
 /**
  * Call a route of a component with given arguments and return the data it generated
  *
  * Dynamic calls may be called for either a specific page that has a component assigned to it
  * by specifying a page GUID or path as the first argument, or to a static instance of a component
  * by specifying component name as the first argument.
  *
  * Here is an example of using dynamic calls inside a TAL template, in this case loading three latest news:
  * 
  * <code>
  * <tal:block tal:define="latest_news php:midgardmvc.templating.dynamic_call('net_nemein_news', 'latest', array('number' => 3))">
  *     <ul tal:condition="latest_news/news">
  *         <li tal:repeat="article latest_news/news">
  *             <a href="#" tal:attributes="href article/url" tal:content="article/title">Headline</a>
  *         </li>
  *     </ul>
  * </tal:block>
  * </code>
  *
  * @param string $component_name Component name, page GUID or page path
  * @param string $route_id     Route identifier
  * @param array $arguments  Arguments to give to the route
  * @param boolean $switch_context Whether to run the route in a new context
  * @return $array data
  */
 public function dynamic_call($component_name, $route_id, array $arguments, $switch_context = true)
 {
     if (is_null($this->dispatcher)) {
         $this->dispatcher = new midgardmvc_core_services_dispatcher_manual();
     }
     if ($switch_context) {
         $this->midgardmvc->context->create();
     }
     $request = new midgardmvc_core_helpers_request();
     if (is_object($component_name) && is_a($component_name, 'midgardmvc_core_node')) {
         $request->set_page($component_name);
     } elseif (mgd_is_guid($component_name)) {
         $request->set_page(new midgardmvc_core_node($component_name));
     } elseif (strpos($component_name, '/') !== false) {
         $request->resolve_page($component_name);
     } else {
         $request->set_component($component_name);
     }
     // Copy HTTP request method of main context to the request
     $request->set_method($this->midgardmvc->context->get_item('request_method', 0));
     $request->populate_context();
     // Run process injector for this context too
     $this->midgardmvc->componentloader->inject_process();
     // Then initialize the component, so it also goes to template stack
     $this->dispatcher->initialize($request);
     $this->dispatcher->set_route($route_id, $arguments);
     $this->dispatcher->dispatch();
     $component_name = $this->midgardmvc->context->component;
     $data = $this->midgardmvc->context->{$component_name};
     if ($switch_context) {
         $this->midgardmvc->context->delete();
     }
     return $data;
 }
Пример #29
0
 /**
  * Prepare event listing query builder that takes all configured filters into account
  *
  * @access static
  */
 static function prepare_event_qb(&$data, &$config)
 {
     // Load filters
     $filters = fi_kilonkipinat_events_viewer::prepare_filters($config);
     $qb = fi_kilonkipinat_events_event_dba::new_query_builder();
     if (!$_MIDGARD['user']) {
         $qb->add_constraint('visibility', '=', FI_KILONKIPINAT_EVENTS_EVENT_VISIBILITY_PUBLIC);
     }
     // Add node or root event constraints
     if ($config->get('list_from_master')) {
         // List under an event tree by up field
         $qb->add_constraint('up', 'INTREE', $data['master_event']);
     } else {
         $list_from_folders = $config->get('list_from_folders');
         if ($list_from_folders) {
             // We have specific folders to list from, therefore list from them and current node
             $guids = explode('|', $config->get('list_from_folders'));
             $guids_array = array();
             $guids_array[] = $data['content_topic']->guid;
             foreach ($guids as $guid) {
                 if (!$guid || !mgd_is_guid($guid)) {
                     // Skip empty and broken guids
                     continue;
                 }
                 $guids_array[] = $guid;
             }
             /**
              * Ref #1776, expands GUIDs before adding them as constraints, should save query time
              */
             $topic_ids = array();
             $topic_ids[] = $data['content_topic']->id;
             if (!empty($guids_array)) {
                 $mc = midcom_db_topic::new_collector('sitegroup', $_MIDGARD['sitegroup']);
                 $mc->add_constraint('guid', 'IN', $guids_array);
                 $mc->add_value_property('id');
                 $mc->execute();
                 $keys = $mc->list_keys();
                 foreach ($keys as $guid => $dummy) {
                     $topic_ids[] = $mc->get_subkey($guid, 'id');
                 }
                 unset($mc, $keys, $guid, $dummy);
             }
             $qb->add_constraint('topic', 'IN', $topic_ids);
         } else {
             // List from current node only
             $qb->add_constraint('topic', '=', $data['content_topic']->id);
         }
     }
     // Add filtering constraint
     if (isset($filters['type_filter'])) {
         $qb->add_constraint('type', '=', (int) $filters['type_filter']);
     }
     if (isset($filters['other'])) {
         // Handle other direct field mapping constraints
         foreach ($filters['other'] as $field => $filter) {
             $qb->add_constraint($field, '=', $filter);
         }
     }
     // Handle category filter
     if (isset($filters['category_filter'])) {
         $qb->add_constraint('category', 'LIKE', "%|{$filters['category_filter']}|%");
     }
     return $qb;
 }
Пример #30
0
 /**
  * Looks up a product to display.
  *
  * @param mixed $handler_id The ID of the handler.
  * @param Array $args The argument list.
  * @param Array &$data The local request data.
  */
 public function _handler_view($handler_id, array $args, array &$data)
 {
     if (preg_match('/_raw$/', $handler_id)) {
         midcom::get()->skip_page_style = true;
     }
     $qb = org_openpsa_products_product_dba::new_query_builder();
     if (preg_match('/^view_product_intree/', $handler_id)) {
         $group_qb = org_openpsa_products_product_group_dba::new_query_builder();
         if (mgd_is_guid($args[0])) {
             $group_qb->add_constraint('guid', '=', $args[0]);
         } else {
             $group_qb->add_constraint('code', '=', $args[0]);
         }
         $groups = $group_qb->execute();
         if (empty($groups)) {
             throw new midcom_error_notfound("Product group {$args[0]} not found");
         }
         $categories_mc = org_openpsa_products_product_group_dba::new_collector('up', $groups[0]->id);
         $categories_in = $categories_mc->get_values('id');
         if (count($categories_in) == 0) {
             /* No matching categories belonging to this group
              * So we can search for the application using only
              * this group id
              */
             $qb->add_constraint('productGroup', 'INTREE', $groups[0]->id);
         } else {
             $categories_in[] = $groups[0]->id;
             $qb->add_constraint('productGroup', 'IN', $categories_in);
         }
         if (mgd_is_guid($args[1])) {
             $qb->add_constraint('guid', '=', $args[1]);
         } else {
             $qb->add_constraint('code', '=', $args[1]);
         }
     } else {
         if (mgd_is_guid($args[0])) {
             $qb->add_constraint('guid', '=', $args[0]);
         } else {
             $qb->add_constraint('code', '=', $args[0]);
         }
     }
     if ($this->_config->get('enable_scheduling')) {
         $qb->add_constraint('start', '<=', time());
         $qb->begin_group('OR');
         /*
          * List products that either have no defined end-of-market dates
          * or are still in market
          */
         $qb->add_constraint('end', '=', 0);
         $qb->add_constraint('end', '>=', time());
         $qb->end_group();
     }
     $results = $qb->execute();
     $this->_request_data['is_linked_from'] = '';
     if (!empty($results)) {
         $this->_product = $results[0];
         if ($this->_config->get('enable_productlinks') && $this->_product->productGroup != 0) {
             $root_group_guid = $this->_config->get('root_group');
             if ($root_group_guid != '') {
                 $root_group = org_openpsa_products_product_group_dba::get_cached($root_group_guid);
             }
             if ($root_group->id != $this->_product->productGroup) {
                 $product_group = new org_openpsa_products_product_group_dba($this->_product->productGroup);
                 $mc_intree = org_openpsa_products_product_group_dba::new_collector('id', $product_group->id);
                 $mc_intree->add_constraint('up', 'INTREE', $root_group->id);
                 $count = $mc_intree->count();
                 if ($count == 0) {
                     $mc_intree = org_openpsa_products_product_link_dba::new_collector('product', $this->_product->id);
                     $mc_intree->add_constraint('productGroup', 'INTREE', $root_group->id);
                     $mc_intree->execute();
                     $results = $mc_intree->list_keys();
                     if (count($results) > 0) {
                         foreach ($results as $guid => $array) {
                             $this->_request_data['is_linked_from'] = $guid;
                         }
                     }
                 }
             }
         }
     } else {
         if (preg_match('/^view_product_intree/', $handler_id)) {
             $this->_product = new org_openpsa_products_product_dba($args[1]);
         } else {
             $this->_product = new org_openpsa_products_product_dba($args[0]);
         }
     }
     if ($GLOBALS['midcom_config']['enable_ajax_editing']) {
         $data['controller'] = midcom_helper_datamanager2_controller::create('ajax');
         $data['controller']->schemadb =& $data['schemadb_product'];
         $data['controller']->set_storage($this->_product);
         $data['controller']->process_ajax();
         $data['datamanager'] =& $data['controller']->datamanager;
     } else {
         $data['controller'] = null;
         $data['datamanager'] = new midcom_helper_datamanager2_datamanager($data['schemadb_product']);
         if (!$data['datamanager']->autoset_storage($this->_product)) {
             throw new midcom_error("Failed to create a DM2 instance for product {$this->_product->guid}.");
         }
     }
     $this->_prepare_request_data();
     $this->bind_view_to_object($this->_product, $data['datamanager']->schema->name);
     if (isset($product_group)) {
         unset($product_group);
     }
     $product_group = null;
     if ($this->_request_data['is_linked_from'] != '') {
         $linked_product = new org_openpsa_products_product_link_dba($data['is_linked_from']);
         if ($linked_product->productGroup != 0) {
             $product_group = new org_openpsa_products_product_group_dba($linked_product->productGroup);
         }
     }
     $breadcrumb = org_openpsa_products_viewer::update_breadcrumb_line($this->_product, $product_group);
     midcom_core_context::get()->set_custom_key('midcom.helper.nav.breadcrumb', $breadcrumb);
     midcom::get('metadata')->set_request_metadata($this->_product->metadata->revised, $this->_product->guid);
     $title = $this->_config->get('product_page_title');
     if (strstr($title, '<PRODUCTGROUP')) {
         try {
             $productgroup = new org_openpsa_products_product_group_dba($this->_product->productGroup);
             $title = str_replace('<PRODUCTGROUP_TITLE>', $productgroup->title, $title);
             $title = str_replace('<PRODUCTGROUP_CODE>', $productgroup->code, $title);
         } catch (midcom_error $e) {
             $title = str_replace('<PRODUCTGROUP_TITLE>', '', $title);
             $title = str_replace('<PRODUCTGROUP_CODE>', '', $title);
         }
     }
     $title = str_replace('<PRODUCT_CODE>', $this->_product->code, $title);
     $title = str_replace('<PRODUCT_TITLE>', $this->_product->title, $title);
     $title = str_replace('<TOPIC_TITLE>', $this->_topic->extra, $title);
     midcom::get('head')->set_pagetitle($title);
 }