static function generate_summary($activity, $target = null) { if (!$target && $activity->target) { try { $target = midcom::get('dbfactory')->get_object_by_guid($activity->target); $reflector = new midcom_helper_reflector($target); $class_label = $reflector->get_class_label(); $target_label = "{$class_label} " . $reflector->get_object_label($target); } catch (midcom_error $e) { $target_label = $activity->target; } } switch ($activity->verb) { case 'http://activitystrea.ms/schema/1.0/post': $verb = 'saved'; break; case 'http://community-equity.org/schema/1.0/delete': $verb = 'deleted'; break; case 'http://community-equity.org/schema/1.0/clone': $verb = 'cloned'; break; default: // TODO: Check if the originating component can provide this return ''; } try { $actor = new midcom_core_user($activity->actor); return sprintf(midcom::get('i18n')->get_string('%s ' . $verb . ' %s', 'midcom.helper.activitystream'), $actor->name, $target_label); } catch (midcom_error $e) { return sprintf(midcom::get('i18n')->get_string('%s was ' . $verb, 'midcom.helper.activitystream'), $target_label); } }
/** * Handler for folder move. Checks for updating permissions, initializes * the move and the content topic itself. Handles also the sent form. * * @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_move($handler_id, array $args, array &$data) { $this->_object = midcom::get('dbfactory')->get_object_by_guid($args[0]); if (!is_a($this->_object, 'midcom_db_topic') && !is_a($this->_object, 'midcom_db_article')) { throw new midcom_error_notfound("Moving only topics and articles is supported."); } $this->_object->require_do('midgard:update'); if (isset($_POST['move_to'])) { $this->_move_object((int) $_POST['move_to']); return new midcom_response_relocate(midcom::get('permalinks')->create_permalink($this->_object->guid)); } $object_label = midcom_helper_reflector::get($this->_object)->get_object_label($this->_object); if (is_a($this->_object, 'midcom_db_topic')) { // This is a topic $this->_object->require_do('midcom.admin.folder:topic_management'); $this->_node_toolbar->hide_item("__ais/folder/move/{$this->_object->guid}/"); $data['current_folder'] = new midcom_db_topic($this->_object->up); } else { // This is a regular object, bind to view $this->bind_view_to_object($this->_object); $this->add_breadcrumb(midcom::get('permalinks')->create_permalink($this->_object->guid), $object_label); $this->_view_toolbar->hide_item("__ais/folder/move/{$this->_object->guid}/"); $data['current_folder'] = new midcom_db_topic($this->_object->topic); } $this->add_breadcrumb("__ais/folder/move/{$this->_object->guid}/", $this->_l10n->get('move')); $data['title'] = sprintf(midcom::get('i18n')->get_string('move %s', 'midcom.admin.folder'), $object_label); midcom::get('head')->set_pagetitle($data['title']); // Ensure we get the correct styles midcom::get('style')->prepend_component_styledir('midcom.admin.folder'); $this->add_stylesheet(MIDCOM_STATIC_URL . '/midcom.admin.folder/folder.css'); }
private function _list_revised($since, $review_by = null, $type = null, $only_mine = false) { $classes = array(); $revised = array(); // List installed MgdSchema types and convert to DBA classes foreach ($this->_request_data['schema_types'] as $schema_type) { if (!is_null($type) && $schema_type != $type) { // Skip continue; } $mgdschema_class = midcom_helper_reflector::class_rewrite($schema_type); $dummy_object = new $mgdschema_class(); $midcom_dba_classname = midcom::get('dbclassloader')->get_midcom_class_name_for_mgdschema_object($dummy_object); if (empty($midcom_dba_classname)) { continue; } $classes[] = $midcom_dba_classname; } // List all revised objects foreach ($classes as $class) { if (!midcom::get('dbclassloader')->load_mgdschema_class_handler($class)) { // Failed to load handling component, skip continue; } $qb_callback = array($class, 'new_query_builder'); if (!is_callable($qb_callback)) { continue; } $qb = call_user_func($qb_callback); if ($since != 'any') { $qb->add_constraint('metadata.revised', '>=', $since); } if ($only_mine && midcom::get('auth')->user) { $qb->add_constraint('metadata.authors', 'LIKE', '|' . midcom::get('auth')->user->guid . '|'); } $qb->add_order('metadata.revision', 'DESC'); $objects = $qb->execute(); if (count($objects) > 0) { if (!isset($this->_reflectors[$class])) { $this->_reflectors[$class] = new midcom_helper_reflector($objects[0]); } } foreach ($objects as $object) { if (!is_null($review_by)) { $object_review_by = (int) $object->get_parameter('midcom.helper.metadata', 'review_date'); if ($object_review_by > $review_by) { // Skip continue; } } $revised["{$object->metadata->revised}_{$object->guid}_{$object->metadata->revision}"] = $object; } } krsort($revised); return $revised; }
/** * 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_edit($handler_id, array $args, array &$data) { $this->_group = new midcom_db_group($args[0]); $this->_group->require_do('midgard:update'); $controller = $this->get_controller('simple', $this->_group); switch ($controller->process_form()) { case 'save': // Show confirmation for the group midcom::get('uimessages')->add($this->_l10n->get('midcom.admin.user'), sprintf($this->_l10n->get('group %s saved'), $this->_group->name)); return new midcom_response_relocate("__mfa/asgard_midcom.admin.user/group/edit/{$this->_group->guid}/"); case 'cancel': return new midcom_response_relocate('__mfa/asgard_midcom.admin.user/'); } $data['group'] =& $this->_group; $data['controller'] =& $controller; $ref = new midcom_helper_reflector($this->_group); $data['view_title'] = sprintf(midcom::get('i18n')->get_string('edit %s', 'midcom.admin.user'), $ref->get_object_title($this->_group)); midcom::get('head')->set_pagetitle($data['view_title']); $this->_update_breadcrumb(); $data['asgard_toolbar']->add_item(array(MIDCOM_TOOLBAR_URL => "__mfa/asgard_midcom.admin.user/group/move/{$this->_group->guid}/", MIDCOM_TOOLBAR_LABEL => midcom::get('i18n')->get_string('move group', 'midcom.admin.user'), MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/save-as.png')); $data['asgard_toolbar']->add_item(array(MIDCOM_TOOLBAR_URL => "__mfa/asgard_midcom.admin.user/group/folders/{$this->_group->guid}/", MIDCOM_TOOLBAR_LABEL => midcom::get('i18n')->get_string('folders', 'midcom.admin.user'), MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/folder.png')); midgard_admin_asgard_plugin::bind_to_object($this->_group, $handler_id, $data); }
/** * * @param mixed $object * @param CollectionInterface $config * @return array */ public function getChildren($object, CollectionInterface $collection) { $config = $collection->getConfig(); if (empty($config['parentfield'])) { throw new \midcom_error('parentfield was not defined in config'); } $parentfield = $config['parentfield']; // if storage is not defined, we assume it's the same as object if (empty($config['storage'])) { $storage = get_class($object); } else { $storage = $config['storage']; } $reflector = new \midgard_reflection_property(\midcom_helper_reflector::resolve_baseclass($storage)); if (!$reflector->is_link($parentfield)) { throw new \midcom_error('could not determine storage class'); } $qb = call_user_func(array($storage, 'new_query_builder')); $qb->add_constraint($parentfield, '=', $object->id); // order the children by their score values $qb->add_order('score', 'ASC'); return $qb->execute(); }
/** * Helper function to prepare the breadcrumb */ private function _prepare_breadcrumb() { $ref = midcom_helper_reflector::get($this->_current_object); $object_label = $ref->get_object_label($this->_current_object); $this->add_breadcrumb(midcom::get('permalinks')->create_permalink($this->_current_object->guid), $object_label); $this->add_breadcrumb(midcom_core_context::get()->get_key(MIDCOM_CONTEXT_ANCHORPREFIX) . '__mfa/org.openpsa.relatedto/render/' . $this->_current_object->guid . '/both/', $this->_l10n->get('view related information')); $this->add_breadcrumb("", $this->_l10n->get('journal entry') . " : " . $object_label); }
private function _list_leaf_children($object, $skip = array()) { if ($children = self::_get_child_objects($object)) { if ($skip) { foreach ($children as $class => $objects) { if (in_array($class, $skip)) { unset($children[$class]); } } } } if ($children) { echo " <ul>\n"; foreach ($children as $class => $objects) { foreach ($objects as $object) { $title = midcom_helper_reflector::get($class)->get_object_label($object); echo " <li class=\"leaf_child {$class}\" style=\"display: none;\">{$title}\n"; self::_list_leaf_children($object); echo " </li>\n"; } } echo " </ul>\n"; } }
<?php /** * @package midcom.helper.reflector * @author The Midgard Project, http://www.midgard-project.org * @copyright The Midgard Project, http://www.midgard-project.org * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License */ if (!isset($_GET['guid']) || empty($_GET['guid'])) { throw new midcom_error_notfound('Specify $guid via GET for info'); } $object = midcom::get('dbfactory')->get_object_by_guid($_GET['guid']); $reflector =& midcom_helper_reflector::get($object); echo "Got " . $reflector->get_class_label() . ' "' . $reflector->get_object_label($object) . "\", dump<pre>\n"; var_dump($object); echo "</pre>\n"; if (midcom_helper_reflector_tree::has_children($object)) { echo "Object has children<br/>\n"; echo "Child counts <pre>\n"; $counts = midcom_helper_reflector_tree::count_child_objects($object); print_r($counts); echo "</pre>\n"; echo "Child objects dump<pre>\n"; $children = midcom_helper_reflector_tree::get_child_objects($object); var_dump($children); echo "</pre>\n"; }
/** * Method for updating title for current object and handler, should be implemented in the * component handler for better performance. * * @param mixed $handler_id The ID of the handler. */ public function _update_title($handler_id) { $ref = midcom_helper_reflector::get($this->_dba_class); $view_title = $this->_topic->extra . ': '; switch ($this->_mode) { case 'create': $view_title = sprintf($this->_l10n_midcom->get('create %s'), $ref->get_class_label()); break; case 'read': $object_title = $ref->get_object_label($this->_object); $view_title .= $object_title; break; case 'update': $object_title = $ref->get_object_label($this->_object); $view_title .= sprintf($this->_l10n_midcom->get('edit %s'), $object_title); break; case 'delete': $object_title = $ref->get_object_label($this->_object); $view_title .= sprintf($this->_l10n_midcom->get('delete %s'), $object_title); break; } midcom::get('head')->set_pagetitle($view_title); }
/** * Helper to update the breadcrumb */ private function _update_breadcrumb() { $ref = midcom_helper_reflector::get($this->_linked_object); $object_label = $ref->get_object_label($this->_linked_object); $this->add_breadcrumb(midcom::get('permalinks')->create_permalink($this->_linked_object->guid), $object_label); $this->add_breadcrumb('', $this->_l10n->get('billing data') . " : " . $object_label); }
/** * Copy an object * * @param mixed &$source MgdSchema object for reading the parameters * @param mixed &$parent MgdSchema parent object * @param array $defaults * @return boolean Indicating success */ public function copy_object(&$source, &$parent = null, $defaults = array()) { // Resolve the source object self::resolve_object($source); // Duplicate the object $class_name = get_class($source); $target = new $class_name(); $properties = $this->get_object_properties($source); // Copy the object properties foreach ($properties as $property) { // Skip certain fields if (preg_match('/^(_|metadata|guid|id)/', $property)) { continue; } $target->{$property} = $source->{$property}; } // Override requested root object properties if (isset($this->target->guid) && $target->guid === $this->target->guid) { foreach ($this->root_object_values as $name => $value) { $target->{$name} = $value; } } // Override with defaults if ($defaults) { foreach ($defaults as $name => $value) { $target->{$name} = $value; } } $parent_property = $this->get_parent_property($source); // Copy the link to parent if ($parent) { self::resolve_object($parent); if (!$parent || !$parent->guid) { return false; } // @TODO: Is there a sure way to determine if the parent is // GUID or is it ID? If so, please change it here. if (is_string($source->{$parent_property})) { $parent_key = 'guid'; } else { $parent_key = 'id'; } $target->{$parent_property} = $parent->{$parent_key}; } else { if (is_string($source->{$parent_property})) { $target->{$parent_property} = ''; } else { $target->{$parent_property} = 0; } } $name_property = midcom_helper_reflector::get_name_property($target); $resolver = new midcom_helper_reflector_nameresolver($target); if (!empty($name_property) && !$resolver->name_is_safe_or_empty($name_property)) { debug_add('Source object ' . get_class($source) . " {$source->guid} has unsafe name, rewriting to safe form for the target", MIDCOM_LOG_WARN); $name_property = midcom_helper_reflector::get_name_property($target); if (empty($name_property)) { $this->errors[] = sprintf($this->_l10n->get('cannot fix unsafe name for source object %s, skipping'), get_class($source) . " {$source->guid}"); return false; } $name_parts = explode('.', $target->{$name_property}, 2); if (isset($name_parts[1])) { $target->{$name_property} = midcom_helper_misc::generate_urlname_from_string($name_parts[0]) . ".{$name_parts[1]}"; // Doublecheck safety and fall back if needed if (!$resolver->name_is_safe_or_empty()) { $target->{$name_property} = midcom_helper_misc::generate_urlname_from_string($target->{$name_property}); } } else { $target->{$name_property} = midcom_helper_misc::generate_urlname_from_string($target->{$name_property}); } unset($name_parts, $name_property); } if ($this->allow_name_catenate && $name_property) { $name = $resolver->generate_unique_name(); if ($name !== $target->{$name_property}) { $target->{$name_property} = $name; } } // This needs to be here, otherwise it will be overridden $target->allow_name_catenate = true; if (!$target->create()) { $this->errors[] = $this->_l10n->get('failed to create object: ' . mgd_errstr()); return false; } // Store for later use - if ever needed $this->new_objects[] = $target; unset($name_property); // Copy parameters if (!$this->copy_parameters($source, $target) && $this->halt_on_errors) { $this->errors[] = $this->_l10n->get('failed to copy parameters'); return false; } // Copy metadata if (!$this->copy_metadata($source, $target) && $this->halt_on_errors) { $this->errors[] = $this->_l10n->get('failed to copy metadata'); return false; } // Copy attachments if (!$this->copy_attachments($source, $target) && $this->halt_on_errors) { $this->errors[] = $this->_l10n->get('failed to copy attachments'); return false; } // Copy privileges if (!$this->copy_privileges($source, $target) && $this->halt_on_errors) { $this->errors[] = $this->_l10n->get('failed to copy privileges'); return false; } return $target; }
/** * Trash view * * @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_trash_type($handler_id, array $args, array &$data) { midcom::get('auth')->require_admin_user(); midcom::get('cache')->content->no_cache(); $this->type = $args[0]; $data['view_title'] = midgard_admin_asgard_plugin::get_type_label($this->type); midcom::get('head')->set_pagetitle($data['view_title']); $dummy = new $this->type(); $data['midcom_dba_classname'] = midcom::get('dbclassloader')->get_midcom_class_name_for_mgdschema_object($dummy); $data['type'] = $this->type; $data['reflector'] = midcom_helper_reflector::get($data['type']); $data['label_property'] = $data['reflector']->get_label_property(); if (isset($_POST['undelete']) && !isset($_POST['purge']) && is_array($_POST['undelete'])) { $this->_undelete(); return new midcom_response_relocate("__mfa/asgard/trash/{$this->type}/"); } if (isset($_POST['purge']) && is_array($_POST['undelete'])) { $this->_purge(); return new midcom_response_relocate("__mfa/asgard/trash/{$this->type}/"); } $qb = new org_openpsa_qbpager_direct($data['type'], "{$data['type']}_trash"); $qb->include_deleted(); $qb->add_constraint('metadata.deleted', '=', true); $qb->add_order('metadata.revised', 'DESC'); $data['qb'] =& $qb; $data['trash'] = $qb->execute_unchecked(); // Set the breadcrumb data $this->add_breadcrumb('__mfa/asgard/', $this->_l10n->get('midgard.admin.asgard')); $this->add_breadcrumb("__mfa/asgard/{$this->type}/", $data['view_title']); $this->add_breadcrumb("__mfa/asgard/trash/{$this->type}/", sprintf($this->_l10n->get('%s trash'), midgard_admin_asgard_plugin::get_type_label($data['type']))); }
private function _add_linked_field($key) { $linked_type = $this->_reflector->get_link_name($key); $linked_type_reflector = midcom_helper_reflector::get($linked_type); $field_type = $this->_reflector->get_midgard_type($key); if ($key == 'up') { $field_label = sprintf($this->_l10n->get('under %s'), midgard_admin_asgard_plugin::get_type_label($linked_type)); } else { $type_label = midgard_admin_asgard_plugin::get_type_label($linked_type); if (substr($type_label, 0, strlen($key)) == $key) { // Handle abbreviations like "lang" for "language" $field_label = $type_label; } else { if ($key == $type_label) { $field_label = $key; } else { $ref = midcom_helper_reflector::get($this->_object); $component_l10n = $ref->get_component_l10n(); $field_label = sprintf($this->_l10n->get('%s (%s)'), $component_l10n->get($key), $type_label); } } } // Get the chooser widgets switch ($field_type) { case MGD_TYPE_UINT: case MGD_TYPE_STRING: case MGD_TYPE_GUID: $class = midcom::get('dbclassloader')->get_midcom_class_name_for_mgdschema_object($linked_type); if (!$class) { break; } $component = midcom::get('dbclassloader')->get_component_for_class($linked_type); $this->_schemadb['object']->append_field($key, array('title' => $field_label, 'storage' => $key, 'type' => 'select', 'type_config' => array('require_corresponding_option' => false, 'options' => array(), 'allow_other' => true, 'allow_multiple' => false), 'widget' => 'chooser', 'widget_config' => array('class' => $class, 'component' => $component, 'titlefield' => $linked_type_reflector->get_label_property(), 'id_field' => $this->_reflector->get_link_target($key), 'searchfields' => $linked_type_reflector->get_search_properties(), 'result_headers' => $this->_get_result_headers($linked_type_reflector), 'orders' => array(), 'creation_mode_enabled' => true, 'creation_handler' => midcom_connection::get_url('self') . "__mfa/asgard/object/create/chooser/{$linked_type}/", 'creation_default_key' => $linked_type_reflector->get_label_property(), 'generate_path_for' => midcom_helper_reflector::get_name_property($this->_object)))); break; } }
<?php /** * @package midcom.helper.reflector * @author The Midgard Project, http://www.midgard-project.org * @copyright The Midgard Project, http://www.midgard-project.org * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License */ // FIXME: make generic $article = new midcom_db_article(); $article->topic = 5; $article->title = 'Duplicate name test with (with allow_catenate)'; $article->name = 'gathering-09'; $article->allow_name_catenate = true; $reflected_name_property = midcom_helper_reflector::get_name_property($article); $resolver = new midcom_helper_reflector_nameresolver($article); $reflected_name = $resolver->get_object_name(); echo "Reflector thinks name is '{$reflected_name}' (from property '{$reflected_name_property}')<br>\n"; if ($resolver->name_is_safe()) { echo "OK: '{$reflected_name}' is considered URL-safe<br>\n"; } else { echo "ERROR: '{$reflected_name}' is NOT considered URL-safe<br>\n"; } if ($resolver->name_is_clean()) { echo "OK: '{$reflected_name}' is considered 'clean'<br>\n"; } else { echo "WARN: '{$reflected_name}' is NOT considered 'clean'<br>\n"; } if ($resolver->name_is_unique()) { echo "OK: '{$reflected_name}' is unique (among siblings)<br>\n"; } else {
private function _prepare_qb() { $query = $this->_request["term"]; $wildcard_query = $this->_add_wildcards($query); $qb = @call_user_func(array($this->_request['class'], 'new_query_builder')); if (!$qb) { debug_add("use midgard_query_builder"); $qb = new midgard_query_builder($class); } if (!empty($this->_request['constraints']) && is_array($this->_request['constraints'])) { $constraints = $this->_request['constraints']; ksort($constraints); reset($constraints); foreach ($constraints as $key => $data) { if (!array_key_exists('value', $data) || empty($data['field']) || empty($data['op'])) { debug_add("Constraint #{$key} is not correctly defined, skipping", MIDCOM_LOG_WARN); continue; } $qb->add_constraint($data['field'], $data['op'], $data['value']); } } if (preg_match('/^%+$/', $query)) { debug_add('$query is all wildcards, don\'t waste time in adding LIKE constraints'); } else { $reflector = new midgard_reflection_property(midcom_helper_reflector::resolve_baseclass($this->_request['class'])); $qb->begin_group('OR'); foreach ($this->_request['searchfields'] as $field) { $field_type = $reflector->get_midgard_type($field); $operator = 'LIKE'; if (strpos($field, '.')) { //TODO: This should be resolved properly $field_type = MGD_TYPE_STRING; } switch ($field_type) { case MGD_TYPE_GUID: case MGD_TYPE_STRING: case MGD_TYPE_LONGTEXT: debug_add("adding search (ORed) constraint: {$field} LIKE '{$wildcard_query}'"); $qb->add_constraint($field, 'LIKE', $wildcard_query); break; case MGD_TYPE_INT: case MGD_TYPE_UINT: case MGD_TYPE_FLOAT: debug_add("adding search (ORed) constraint: {$field} = {$query}'"); $qb->add_constraint($field, '=', $query); break; default: debug_add("can't handle field type " . $field_type, MIDCOM_LOG_WARN); break; } } $qb->end_group(); } if (!empty($this->_request['orders']) && is_array($this->_request['orders'])) { ksort($this->_request['orders']); reset($this->_request['orders']); foreach ($this->_request['orders'] as $data) { foreach ($data as $field => $order) { $qb->add_order($field, $order); } } } return $qb; }
private function _draw_type_list(array $types) { echo "<ul class=\"midgard_admin_asgard_navigation\">\n"; foreach ($types as $type => $label) { $url = midcom_connection::get_url('self') . "__mfa/asgard/{$type}"; echo " <li class=\"mgdschema-type\">"; $dbaclass = midcom::get('dbclassloader')->get_midcom_class_name_for_mgdschema_object($type); if ($dbaclass) { $object = new $dbaclass(); } else { $object = new $type(); } $icon = midcom_helper_reflector::get_object_icon($object); echo "<a href=\"" . $url . "\" title=\"{$label}\">{$icon}{$label}</a>\n"; echo " </li>\n"; } echo "</ul>\n"; }
/** * Handler for folder metadata. Checks for updating permissions, initializes * the metadata and the content topic itself. Handles also the sent form. * * @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_metadata($handler_id, array $args, array &$data) { $this->_object = midcom::get('dbfactory')->get_object_by_guid($args[0]); // FIXME: We should modify the schema according to whether or not scheduling is used $this->_object->require_do('midgard:update'); if (is_a($this->_object, 'midcom_db_topic')) { // This is a topic $this->_object->require_do('midcom.admin.folder:topic_management'); } else { // This is a regular object, bind to view $this->bind_view_to_object($this->_object); } $this->_metadata = midcom_helper_metadata::retrieve($this->_object); if (!$this->_metadata) { throw new midcom_error("Failed to retrieve Metadata for " . get_class($this->_object) . " {$this->_object->guid}."); } // Load the DM2 controller instance $this->_load_datamanager(); switch ($this->_controller->process_form()) { case 'save': midcom::get('cache')->invalidate($this->_object->guid); case 'cancel': return new midcom_response_relocate(midcom::get('permalinks')->create_permalink($this->_object->guid)); } $object_label = midcom_helper_reflector::get($this->_object)->get_object_label($this->_object); if (is_a($this->_object, 'midcom_db_topic')) { $this->_node_toolbar->hide_item("__ais/folder/metadata/{$this->_object->guid}/"); } else { $this->add_breadcrumb(midcom::get('permalinks')->create_permalink($this->_object->guid), $object_label); $this->_view_toolbar->hide_item("__ais/folder/metadata/{$this->_object->guid}/"); } $this->add_breadcrumb("__ais/folder/metadata/{$this->_object->guid}/", $this->_l10n->get('edit metadata')); $data['title'] = sprintf(midcom::get('i18n')->get_string('edit metadata of %s', 'midcom.admin.folder'), $object_label); midcom::get('head')->set_pagetitle($data['title']); // Set the help object in the toolbar $help_toolbar = midcom::get('toolbars')->get_help_toolbar(); $help_toolbar->add_help_item('edit_metadata', 'midcom.admin.folder', null, null, 1); // Ensure we get the correct styles midcom::get('style')->prepend_component_styledir('midcom.admin.folder'); }
/** * Default line rendering, used if a specific renderer cannot be found * * Tries to find certain properties likely to hold semi-useful information about * the object, failing that outputs class and guid. * * @param array &$link The necessary link information * @param object &other_obj The link target */ private function _render_line_default(&$link, &$other_obj) { $class = get_class($other_obj); $object_url = midcom::get('permalinks')->create_permalink($other_obj->guid); $ref = midcom_helper_reflector::get($other_obj); $class_label = $ref->get_class_label(); $object_label = $ref->get_object_label($other_obj); if ($object_url) { $object_label = '<a href="' . $object_url . '" target="' . $class . $this->_object->guid . '">' . $object_label . '</a>'; } echo " <li class=\"unknown {$class}\" id=\"org_openpsa_relatedto_line_{$link['guid']}\">\n"; echo ' <span class="icon">' . $this->_request_data['icon'] . "</span>\n"; echo ' <span class="title">' . $object_label . "</span>\n"; echo ' <ul class="metadata">'; echo ' <li>' . $class_label . "</li>\n"; echo " </ul>\n"; self::render_line_controls($link, $other_obj); echo "</li>\n"; }
/** * Binds the a toolbar to a DBA object. This will append a number of globally available * toolbar options. For example, expect Metadata- and Version Control-related options * to be added. * * This call is available through convenience functions throughout the framework: The * toolbar main class has a mapping for it (midcom_helper_toolbar::bind_to($object)) * and object toolbars created by this service will automatically be bound to the * specified object. * * Repeated bind calls are intercepted, you can only bind a toolbar to a single object. * * @see midcom_helper_toolbar::bind_to() * @see create_object_toolbar() * @param &$toolbar */ function bind_toolbar_to_object(&$toolbar, &$object) { if (array_key_exists('midcom_services_toolbars_bound_to_object', $toolbar->customdata)) { // We already processed this toolbar, skipping further adds. return; } else { $toolbar->customdata['midcom_services_toolbars_bound_to_object'] = true; } $prefix = midcom_core_context::get()->get_key(MIDCOM_CONTEXT_ANCHORPREFIX); if (!$prefix) { debug_add("Toolbar for object {$object->guid} was called before topic prefix was available, skipping global items.", MIDCOM_LOG_WARN); return; } $reflector = new midcom_helper_reflector($object); $this->_view_toolbar_label = $reflector->get_class_label(); if ($GLOBALS['midcom_config']['metadata_approval'] && $object->can_do('midcom:approve')) { $metadata = midcom_helper_metadata::retrieve($object); if ($metadata && $metadata->is_approved()) { $toolbar->add_item(array(MIDCOM_TOOLBAR_URL => "{$prefix}__ais/folder/unapprove/", MIDCOM_TOOLBAR_LABEL => midcom::get('i18n')->get_string('unapprove', 'midcom'), MIDCOM_TOOLBAR_HELPTEXT => midcom::get('i18n')->get_string('approved', 'midcom'), MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/page-approved.png', MIDCOM_TOOLBAR_POST => true, MIDCOM_TOOLBAR_POST_HIDDENARGS => array('guid' => $object->guid, 'return_to' => $_SERVER['REQUEST_URI']), MIDCOM_TOOLBAR_ACCESSKEY => 'u')); } else { $toolbar->add_item(array(MIDCOM_TOOLBAR_URL => "{$prefix}__ais/folder/approve/", MIDCOM_TOOLBAR_LABEL => midcom::get('i18n')->get_string('approve', 'midcom'), MIDCOM_TOOLBAR_HELPTEXT => midcom::get('i18n')->get_string('unapproved', 'midcom'), MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/page-notapproved.png', MIDCOM_TOOLBAR_POST => true, MIDCOM_TOOLBAR_POST_HIDDENARGS => array('guid' => $object->guid, 'return_to' => $_SERVER['REQUEST_URI']), MIDCOM_TOOLBAR_ACCESSKEY => 'a')); } } if ($object->can_do('midgard:update')) { $toolbar->add_item(array(MIDCOM_TOOLBAR_URL => "{$prefix}__ais/folder/metadata/{$object->guid}/", MIDCOM_TOOLBAR_LABEL => midcom::get('i18n')->get_string('edit metadata', 'midcom.admin.folder'), MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/metadata.png', MIDCOM_TOOLBAR_ACCESSKEY => 'm')); $toolbar->add_item(array(MIDCOM_TOOLBAR_URL => "{$prefix}__ais/folder/move/{$object->guid}/", MIDCOM_TOOLBAR_LABEL => midcom::get('i18n')->get_string('move', 'midcom.admin.folder'), MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/save-as.png', MIDCOM_TOOLBAR_ENABLED => is_a($object, 'midcom_db_article'))); $toolbar->add_item(array(MIDCOM_TOOLBAR_URL => midcom_connection::get_url('self') . "__mfa/asgard/object/open/{$object->guid}/", MIDCOM_TOOLBAR_LABEL => midcom::get('i18n')->get_string('manage object', 'midgard.admin.asgard'), MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/properties.png', MIDCOM_TOOLBAR_ENABLED => midcom::get('auth')->can_user_do('midgard.admin.asgard:access', null, 'midgard_admin_asgard_plugin', 'midgard.admin.asgard') && midcom::get('auth')->can_user_do('midgard.admin.asgard:manage_objects', null, 'midgard_admin_asgard_plugin'))); } if ($GLOBALS['midcom_config']['midcom_services_rcs_enable'] && $object->can_do('midgard:update') && $object->_use_rcs) { $toolbar->add_item(array(MIDCOM_TOOLBAR_URL => "{$prefix}__ais/rcs/{$object->guid}/", MIDCOM_TOOLBAR_LABEL => midcom::get('i18n')->get_string('show history', 'no.bergfald.rcs'), MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/history.png', MIDCOM_TOOLBAR_ACCESSKEY => 'v')); } }
/** * Static helper */ public static function resolve_object_title($object) { $object_reflector = midcom_helper_reflector::get($object); return $object_reflector->get_object_label($object); }
public function render_content() { if (count($this->_type->selection) == 0) { return $this->_translate('type select: no selection'); } else { $selection = array(); foreach ($this->_type->selection as $key) { if ($this->id_field == 'id') { $key = (int) $key; } try { $object = new $this->class($key); } catch (midcom_error $e) { $e->log(); continue; } if (!class_exists('midcom_helper_reflector')) { $selection[] = get_class($object) . " #{$object->id}"; continue; } $ref = new midcom_helper_reflector($object); $selection[] = $ref->get_object_label($object); } return implode(', ', $selection); } }
/** * This function constructs the message */ private function _construct_message() { // Construct the message $message = array(); // Resolve parent title $parent_object = midcom::get('dbfactory')->get_object_by_guid($this->objectguid); $ref = midcom_helper_reflector::get($parent_object); $parent_title = $ref->get_object_label($parent_object); // Resolve commenting user $auth = midcom::get('auth'); if ($auth->user) { $user_string = "{$auth->user->name} ({$auth->user->username})"; } else { $user_string = "{$this->author} (" . midcom::get('i18n')->get_string('anonymous', 'midcom') . ")"; } $message['title'] = sprintf(midcom::get('i18n')->get_string('page %s has been commented by %s', 'net.nehmer.comments'), $parent_title, $user_string); $message['content'] = "{$this->title}\n"; $message['content'] .= "{$this->content}\n\n"; $message['content'] .= midcom::get('i18n')->get_string('link to page', 'net.nemein.wiki') . ":\n"; $message['content'] .= midcom::get('permalinks')->create_permalink($this->objectguid); $message['abstract'] = $message['title']; return $message; }
/** * Helper method for purging objects * * @param Array $guids * @param string $type * @return boolean Indicating success */ public static function purge($guids, $type) { $purged_size = 0; foreach ($guids as $guid) { $object = midcom_helper_reflector::get_object($guid, $type); if (is_null($object)) { debug_add("Failed to get object {$type} {$guid}", MIDCOM_LOG_ERROR); // Something wrong continue; } // first kill your children $children_types = midcom_helper_reflector_tree::get_child_objects($object, true); if (is_array($children_types)) { foreach ($children_types as $child_type => $children) { $child_guids = array(); foreach ($children as $child) { if (!$child->metadata->deleted) { $child->delete(); } $child_guids[] = $child->guid; } self::purge($child_guids, $child_type); } } // then shoot your dogs $purged_size += self::purge_parameters($guid); $purged_size += self::purge_attachments($guid); // now shoot yourself if (!$object->purge()) { debug_add("Failed to purge object " . get_class($object) . " {$object->guid}", MIDCOM_LOG_INFO); } else { $purged_size += $object->metadata->size; } } return $purged_size; }
private function _resolve_object_name($object) { if (!class_exists('midcom_helper_reflector')) { return get_class($object) . " #{$object->id}"; } $ref = new midcom_helper_reflector($object); return $ref->get_object_label($object); }
/** * @dataProvider providerGet_link_properties */ public function testGet_link_properties($classname, $properties) { $reflector = new midcom_helper_reflector($classname); $this->assertEquals($properties, $reflector->get_link_properties()); }
/** * Resolves the "root level" classes, used by get_root_classes() * * @return array of classnames (or false on critical failure) */ private static function _resolve_root_classes() { $root_exceptions_notroot = midcom_baseclasses_components_configuration::get('midcom.helper.reflector', 'config')->get('root_class_exceptions_notroot'); // Safety against misconfiguration if (!is_array($root_exceptions_notroot)) { debug_add("config->get('root_class_exceptions_notroot') did not return array, invalid configuration ??", MIDCOM_LOG_ERROR); $root_exceptions_notroot = array(); } $root_classes = array(); foreach (midcom_connection::get_schema_types() as $schema_type) { if (substr($schema_type, 0, 2) == '__') { continue; } if (in_array($schema_type, $root_exceptions_notroot)) { // Explicitly specified to not be root class, skip all heuristics continue; } // Class extensions mapping $schema_type = midcom_helper_reflector::class_rewrite($schema_type); // Make sure we only add classes once if (in_array($schema_type, $root_classes)) { // Already listed continue; } $parent = midgard_object_class::get_property_parent($schema_type); if (!empty($parent)) { // type has parent set, thus cannot be root type continue; } $dba_class = midcom::get('dbclassloader')->get_midcom_class_name_for_mgdschema_object($schema_type); if (!$dba_class) { // Not a MidCOM DBA object, skip continue; } $root_classes[] = $schema_type; } unset($root_exceptions_notroot); $root_exceptions_forceroot = midcom_baseclasses_components_configuration::get('midcom.helper.reflector', 'config')->get('root_class_exceptions_forceroot'); // Safety against misconfiguration if (!is_array($root_exceptions_forceroot)) { debug_add("config->get('root_class_exceptions_forceroot') did not return array, invalid configuration ??", MIDCOM_LOG_ERROR); $root_exceptions_forceroot = array(); } if (!empty($root_exceptions_forceroot)) { foreach ($root_exceptions_forceroot as $schema_type) { if (!class_exists($schema_type)) { // Not a valid class debug_add("Type {$schema_type} has been listed to always be root class, but the class does not exist", MIDCOM_LOG_WARN); continue; } if (in_array($schema_type, $root_classes)) { // Already listed continue; } $root_classes[] = $schema_type; } } usort($root_classes, 'strnatcmp'); return $root_classes; }
/** * Get the MgdSchema root classes * * @return array containing class name and translated name */ public static function get_root_classes() { static $root_classes = array(); // Return cached results if (!empty($root_classes)) { return $root_classes; } // Initialize the returnable array $root_classes = array(); // Get the classes $classes = midcom_helper_reflector_tree::get_root_classes(); // Get the translated name foreach ($classes as $class) { $ref = new midcom_helper_reflector($class); $root_classes[$class] = $ref->get_class_label(); } asort($root_classes); return $root_classes; }
foreach ($data['navigation_items'] as $i => $item) { if (isset($item[MIDCOM_NAV_SORTABLE]) && !$item[MIDCOM_NAV_SORTABLE]) { continue; } if ($item[MIDCOM_NAV_GUID]) { $identificator = $item[MIDCOM_NAV_GUID]; } else { $identificator = $item[MIDCOM_NAV_ID]; } $index = $count - $i; $style = ''; if (isset($_GET['ajax'])) { $style = ' style="display: none;"'; } // Get the icon from corresponding reflector class $icon = midcom_helper_reflector::get_object_icon($item[MIDCOM_NAV_OBJECT], true); // Actually we should skip all components that return the default icon as icon here! if (isset($item[MIDCOM_NAV_COMPONENT]) && $item[MIDCOM_NAV_COMPONENT] !== 'net.nehmer.static' && $item[MIDCOM_NAV_COMPONENT] !== 'net.nehmer.blog' && ($tmp = midcom::get('componentloader')->get_component_icon($item[MIDCOM_NAV_COMPONENT], false))) { $icon = MIDCOM_STATIC_URL . "/{$tmp}"; } if ($icon) { $icon = " style=\"background-image: url('{$icon}');\""; } else { $icon = ''; } if (!$item[MIDCOM_NAV_GUID]) { $icon = " style=\"background-image: url('" . MIDCOM_STATIC_URL . "/stock-icons/16x16/script.png');\""; } echo " <li class=\"sortable {$item[MIDCOM_NAV_TYPE]}\"{$icon}>\n"; echo " <input type=\"text\" name=\"sortable[{$item[MIDCOM_NAV_TYPE]}][{$identificator}]\" value=\"{$index}\"{$style} />\n"; echo " {$item[MIDCOM_NAV_NAME]}\n";
private function _update_score($identifier, $score) { // Use the DB Factory to resolve the class and to get the object try { $object = midcom::get('dbfactory')->get_object_by_guid($identifier); } catch (midcom_error $e) { // This is probably a pseudo leaf, store the score to the current node $this->_topic->set_parameter('midcom.helper.nav.score', $identifier, $score); return true; // This will skip the rest of the handling } // Get the original approval status and update metadata reference $metadata = midcom_helper_metadata::retrieve($object); if (!is_object($metadata)) { throw new midcom_error("Could not fetch metadata for object {$object->guid}"); } // Make sure this is reference to correct direction (from our point of view) $metadata->__object =& $object; // Get the approval status if metadata object is available $approval_status = false; if ($metadata->is_approved()) { $approval_status = true; } $object->metadata->score = $score; //$metadata->set() calls update *AND* updates the metadata cache correctly, thus we use that in stead of raw update if (!$metadata->set('score', $object->metadata->score)) { // Show an error message on an update failure $reflector =& midcom_helper_reflector::get($object); $title = $reflector->get_class_label() . ' ' . $reflector->get_object_label($object); midcom::get('uimessages')->add($this->_l10n->get('midcom.admin.folder'), sprintf($this->_l10n->get('failed to update %s due to: %s'), $title, midcom_connection::get_error_string()), 'error'); return false; } // Approve if possible if ($approval_status && $object->can_do('midcom:approve')) { if (!isset($metadata)) { $metadata = midcom_helper_metadata::retrieve($object); } $metadata->approve(); } return true; }
/** * Copy handler * * @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_copy($handler_id, array $args, array &$data) { // Get the object that will be copied $this->_load_object($args[0]); midcom::get('auth')->require_user_do('midgard.admin.asgard:manage_objects', null, 'midgard_admin_asgard_plugin'); static $targets = array(); $mgdschema_class = midcom_helper_reflector::resolve_baseclass(get_class($this->_object)); // Get the target details if (in_array($mgdschema_class, $targets)) { $target = $targets[$mgdschema_class]; } else { $target = midcom_helper_reflector_copy::get_target_properties($this->_object); } // Load the schemadb for searching the parent object $this->_load_schemadb($target['class'], $target['parent'], true); // Change the name for the parent field $this->_schemadb['object']->fields[$target['parent']]['title'] = $this->_l10n->get('choose the target'); // Load the nullstorage controller $this->_controller = midcom_helper_datamanager2_controller::create('nullstorage'); $this->_controller->schemadb =& $this->_schemadb; if (!$this->_controller->initialize()) { throw new midcom_error('Failed to initialize the controller'); } $this->_prepare_request_data(); // Process the form switch ($this->_controller->process_form()) { case 'save': $new_object = $this->_process_copy($target); // Relocate to the newly created object return new midcom_response_relocate("__mfa/asgard/object/{$this->_request_data['default_mode']}/{$new_object->guid}/"); case 'cancel': return new midcom_response_relocate("__mfa/asgard/object/{$this->_request_data['default_mode']}/{$args[0]}/"); } // Add Thickbox midcom::get('head')->add_jsfile(MIDCOM_STATIC_URL . '/midgard.admin.asgard/object_browser.js'); midcom::get('head')->add_jsfile(MIDCOM_STATIC_URL . '/jQuery/thickbox/jquery-thickbox-3.1.pack.js'); $this->add_stylesheet(MIDCOM_STATIC_URL . '/jQuery/thickbox/thickbox.css', 'screen'); midcom::get('head')->add_jscript('var tb_pathToImage = "' . MIDCOM_STATIC_URL . '/jQuery/thickbox/loadingAnimation.gif"'); // Add jQuery file for the checkbox operations midcom::get('head')->add_jsfile(MIDCOM_STATIC_URL . '/midgard.admin.asgard/jquery-copytree.js'); midcom::get('head')->add_jscript('jQuery(document).ready(function(){jQuery("#midgard_admin_asgard_copytree").tree_checker();})'); // Common hooks for Asgard midgard_admin_asgard_plugin::bind_to_object($this->_object, $handler_id, $data); // Set the page title switch ($handler_id) { case '____mfa-asgard-object_copy_tree': $data['page_title'] = sprintf($this->_l10n->get('copy %s and its descendants'), $this->_object->{$target}['label']); break; default: $data['page_title'] = sprintf($this->_l10n->get('copy %s'), $this->_object->{$target}['label']); } $data['target'] = $target; }