示例#1
0
文件: midcom.php 项目: nemein/openpsa
 /**
  * Processes the information contained in the metadata instance.
  */
 private function _process_metadata()
 {
     $this->read_metadata_from_object($this->_metadata->__object);
     $datamanager = $this->_metadata->get_datamanager();
     foreach ($datamanager->types as $key => $instance) {
         switch ($key) {
             /**
              * @see parent::read_metadata_from_object()
              */
             case 'revised':
             case 'revisor':
             case 'created':
             case 'creator':
                 break;
             case 'keywords':
             case 'tags':
                 $this->content .= $datamanager->types[$key]->convert_to_html() . "\n";
                 // Fall-through intentional
             // Fall-through intentional
             default:
                 $this->add_text("META_{$key}", $datamanager->types[$key]->convert_to_html());
                 break;
         }
     }
     $this->_metadata->release_datamanager();
 }
示例#2
0
 /**
  * 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_edit($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');
     midcom::get('auth')->require_user_do('midgard.admin.asgard:manage_objects', null, 'midgard_admin_asgard_plugin');
     if (is_a($this->_object, 'midcom_db_topic')) {
         // This is a topic
         $this->_topic->require_do('midgard.admin.asgard:topic_management');
     }
     $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->_controller = $this->get_controller('simple', $this->_object);
     switch ($this->_controller->process_form()) {
         case 'save':
             // Reindex the object
             //$indexer = midcom::get('indexer');
             //net_nemein_wiki_viewer::index($this->_request_data['controller']->datamanager, $indexer, $this->_topic);
             // *** FALL-THROUGH ***
             midcom::get('cache')->invalidate($this->_object->guid);
             return new midcom_response_relocate("__mfa/asgard/object/metadata/{$this->_object->guid}");
         case 'cancel':
             return new midcom_response_relocate("__mfa/asgard/object/view/{$this->_object->guid}");
     }
     $this->_prepare_request_data();
     midgard_admin_asgard_plugin::bind_to_object($this->_object, $handler_id, $data);
 }
示例#3
0
 /**
  * Checks the integrity of the content topic and gets the stored approvals of
  * the content folder.
  *
  * @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_approval($handler_id, array $args, array &$data)
 {
     if (!array_key_exists('guid', $_REQUEST) || !array_key_exists('return_to', $_REQUEST)) {
         throw new midcom_error('Cannot process approval request, request is incomplete.');
     }
     $object = midcom::get('dbfactory')->get_object_by_guid($_REQUEST['guid']);
     $object->require_do('midcom:approve');
     $metadata = midcom_helper_metadata::retrieve($object);
     if (!$metadata) {
         throw new midcom_error("Failed to retrieve Metadata for " . get_class($object) . " {$object->guid}.");
     }
     /**
      * This flag is used to make it possible to explicitly recognize user intent
      * to for example do special operations in midcom.helper.replicator
      */
     if (!isset($GLOBALS['midcom_admin_folder_handler_approvals']) || !is_array($GLOBALS['midcom_admin_folder_handler_approvals'])) {
         $GLOBALS['midcom_admin_folder_handler_approvals'] = array();
     }
     if ($handler_id == '____ais-folder-approve') {
         $GLOBALS['midcom_admin_folder_handler_approvals'][$object->guid] = 'approve';
         $metadata->approve();
     } else {
         $GLOBALS['midcom_admin_folder_handler_approvals'][$object->guid] = 'unapprove';
         $metadata->unapprove();
     }
     return new midcom_response_relocate($_REQUEST['return_to']);
 }
示例#4
0
 /**
  * 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');
 }
示例#5
0
文件: order.php 项目: nemein/openpsa
 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;
 }
示例#6
0
文件: email.php 项目: nemein/openpsa
 /**
  * @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_import($handler_id, array $args, array &$data)
 {
     if (!$this->_config->get('api_email_enable')) {
         throw new midcom_error('Email API is disabled');
     }
     if ($handler_id === 'api-email-basicauth') {
         midcom::get('auth')->require_valid_user('basic');
     }
     //Content-Type
     midcom::get()->skip_page_style = true;
     midcom::get('cache')->content->content_type('text/plain');
     if (!isset($this->_request_data['schemadb'][$this->_config->get('api_email_schema')])) {
         throw new midcom_error('Schema "' . $this->_config->get('api_email_schema') . '" not found in schemadb "' . $this->_config->get('schemadb') . '"');
     }
     $schema_instance =& $this->_request_data['schemadb'][$this->_config->get('api_email_schema')];
     // Parse email
     $this->_decode_email();
     $this->_parse_email_persons();
     midcom::get('auth')->request_sudo('net.nehmer.blog');
     // Create article
     $this->_create_article($this->_decoder->subject);
     // Load the article to DM2
     $this->_load_datamanager();
     // Find image and tag fields in schema
     foreach ($schema_instance->fields as $name => $field) {
         if (is_a($this->_datamanager->types[$name], 'midcom_helper_datamanager2_type_image')) {
             $this->_request_data['image_field'] = $name;
             continue;
         }
         if (is_a($this->_datamanager->types[$name], 'midcom_helper_datamanager2_type_tags')) {
             $data['tags_field'] = $name;
             continue;
         }
     }
     // Try to find tags in email content
     $content = $this->_decoder->body;
     $content_tags = '';
     midcom::get('componentloader')->load_graceful('net.nemein.tag');
     if (class_exists('net_nemein_tag_handler')) {
         // unconditionally tag
         debug_add("content before machine tag separation\n===\n{$content}\n===\n");
         $content_tags = net_nemein_tag_handler::separate_machine_tags_in_content($content);
         if (!empty($content_tags)) {
             debug_add("found machine tags string: {$content_tags}");
             net_nemein_tag_handler::tag_object($this->_article, net_nemein_tag_handler::string2tag_array($content_tags));
         }
         debug_add("content AFTER machine tag separation\n===\n{$content}\n===\n");
     }
     // Populate rest of the data
     $this->_datamanager->types['content']->value = $content;
     if (!empty($data['tags_field'])) {
         // if we have tags field put content_tags value there as well or they will get deleted!
         $this->_datamanager->types[$data['tags_field']]->value = $content_tags;
     }
     $body_switched = false;
     foreach ($this->_decoder->attachments as $att) {
         debug_add("processing attachment {$att['name']}");
         switch (true) {
             case strpos($att['mimetype'], 'image/') !== false:
                 $this->_add_image($att);
                 break;
             case strtolower($att['mimetype']) == 'text/plain':
                 if (!$body_switched) {
                     // Use first text/plain part as the content
                     $this->_datamanager->types['content']->value = $att['content'];
                     $body_switched = true;
                     break;
                 }
                 // Fall-through if not switching
             // Fall-through if not switching
             default:
                 $this->_add_attachment($att);
         }
     }
     if (!$this->_datamanager->save()) {
         // Remove the article, but get errstr first
         $errstr = midcom_connection::get_error_string();
         $this->_article->delete();
         throw new midcom_error('DM2 failed to save the article. Last Midgard error was: ' . $errstr);
     }
     // Index the article
     $indexer = midcom::get('indexer');
     net_nehmer_blog_viewer::index($this->_datamanager, $indexer, $this->_content_topic);
     if ($this->_config->get('api_email_autoapprove')) {
         $metadata = midcom_helper_metadata::retrieve($this->_article);
         if (!$metadata->force_approve()) {
             // Remove the article, but get errstr first
             $errstr = midcom_connection::get_error_string();
             $this->_article->delete();
             throw new midcom_error('Failed to force approval on article. Last Midgard error was: ' . $errstr);
         }
     }
     midcom::get('auth')->drop_sudo();
 }
示例#7
0
 /**
  * This function resolves any GUID into a fully qualified URL which can be relocated
  * to. It operates in multiple phases:
  *
  * 1. Check, whether the GUID is already known by NAP. In case we have the corresponding
  *    node/leaf loaded, use its linking information directly.
  * 2. Look if we have a topic, in that case, we get the corresponding NAP node and use
  *    it to resolve the permalink. If that object is not retrievable, the lookup
  *    fails.
  * 3. We check whether the object in question has a topic as one of its ancestors. If yes,
  *    that topic and its corresponding component is used to lookup the GUID, which might
  *    fail.
  * 4. As a last resort we have to iterate over all NAP topics to do the resolving.
  *
  * @param string $guid The GUID to resolve.
  * @return string The full HTTP relocation'able URL to the GUID.
  */
 function resolve_permalink($guid)
 {
     // resolves a guid into a fully qualified url, uses some heuristics for that, mainly replaces
     // the nap permalink resolver, with the difference that it will be based on the
     // components permalink interface code.
     $nav = new midcom_helper_nav();
     // Step 1: Maybe NAP already knows the topic.
     $napobj = $nav->resolve_guid($guid);
     if ($napobj) {
         return $napobj[MIDCOM_NAV_FULLURL];
     }
     try {
         $object = midcom::get('dbfactory')->get_object_by_guid($guid);
     } catch (midcom_error $e) {
         debug_add("Failed to resolve the GUID {$guid}, this is most probably an access denied error.", MIDCOM_LOG_ERROR);
         debug_add('Last MidCOM error string: ' . $e->getMessage());
         return null;
     }
     $metadata = midcom_helper_metadata::retrieve($object);
     if (!$metadata->is_object_visible_onsite()) {
         return null;
     }
     if (is_a($object, 'midcom_db_topic')) {
         $napobj = $nav->get_node($object->id);
         if (!$napobj) {
             debug_add("Failed to retrieve the NAP object for topic {$object->id}.", MIDCOM_LOG_INFO);
             return null;
         }
         return $napobj[MIDCOM_NAV_FULLURL];
     }
     if (is_a($object, 'midcom_db_attachment')) {
         // Faster linking to attachments
         $parent = $object->get_parent();
         if (is_a($parent, 'midcom_db_topic') && $nav->is_node_in_tree($parent->id, $nav->get_root_node())) {
             $napobj = $nav->get_node($parent->id);
             return $napobj[MIDCOM_NAV_FULLURL] . $object->name;
         } else {
             return "{$GLOBALS['midcom_config']['midcom_site_url']}midcom-serveattachmentguid-{$object->guid}/{$object->name}";
         }
     }
     // Ok, unfortunately, this is not an immediate topic. We try to traverse
     // upwards in the object chain to find a topic.
     $topic = null;
     $parent = $object->get_parent();
     while ($parent) {
         if (is_a($parent, 'midcom_db_topic')) {
             // Verify that this topic is within the current sites tree, if it is not,
             // we ignore it. This might happen on symlink topics with static & co
             // which point to the outside f.x.
             if ($nav->is_node_in_tree($parent->id, $nav->get_root_node())) {
                 $topic = $parent;
                 break;
             }
         }
         $parent = $parent->get_parent();
     }
     if ($topic !== null) {
         $return_value = $this->_resolve_permalink_in_topic($topic, $guid);
         if ($return_value != null) {
             return $return_value;
         }
     }
     // Bad, this means a full scan,
     // We need to try every topic for the GUID.
     $topic_qb = midcom_db_topic::new_query_builder();
     $topic_qb->add_constraint('name', '<>', '');
     $topic_qb->add_constraint('up', 'INTREE', midcom_core_context::get()->get_key(MIDCOM_CONTEXT_ROOTTOPIC)->id);
     $topics = $topic_qb->execute();
     foreach ($topics as $topic) {
         $result = $this->_resolve_permalink_in_topic($topic, $guid);
         if ($result !== null) {
             return $result;
         }
     }
     // We were unable to find the GUID
     return null;
 }
示例#8
0
 /**
  * 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'));
     }
 }
示例#9
0
文件: fetch.php 项目: nemein/openpsa
 /**
  * Imports an item as a news article
  */
 private function import_article($item)
 {
     if ((empty($item['title']) || trim($item['title']) == '...') && empty($item['guid'])) {
         // Something wrong with this entry, skip it
         return false;
     }
     $guid_property = $this->_guid_property;
     $qb = midcom_db_article::new_query_builder();
     $qb->add_constraint('topic', '=', $this->_feed->node);
     // TODO: Move this to a parameter in Midgard 1.8
     $qb->add_constraint($guid_property, '=', substr($item['guid'], 0, 255));
     $articles = $qb->execute();
     if (count($articles) > 0) {
         // This item has been imported already earlier. Update
         $article = $articles[0];
     } else {
         // Check against duplicate hits that may come from different feeds
         if ($item['link']) {
             $qb = midcom_db_article::new_query_builder();
             $qb->add_constraint('topic', '=', $this->_feed->node);
             $qb->add_constraint('url', '=', $item['link']);
             $hits = $qb->count();
             if ($hits > 0) {
                 // Dupe, skip
                 return false;
             }
         }
         // This is a new item
         $article = new midcom_db_article();
     }
     // Sanity check
     if (!is_a($article, 'midcom_db_article')) {
         debug_add('$article is not an instance of midgard_article (or subclass), see debug level logs for object dump', MIDCOM_LOG_ERROR);
         debug_print_r('$article: ', $article);
         return false;
     }
     $article->allow_name_catenate = true;
     $updated = false;
     // Copy properties
     if ($article->title != $item['title']) {
         $article->title = $item['title'];
         $updated = true;
     }
     // FIXME: This breaks with URLs longer than 255 chars
     if ($article->{$guid_property} != $item['guid']) {
         $article->{$guid_property} = $item['guid'];
         $updated = true;
     }
     if ($article->content != $item['description']) {
         $article->content = $item['description'];
         $updated = true;
     }
     $article->topic = $this->_feed->node;
     if ($article->url != $item['link']) {
         $article->url = $item['link'];
         $updated = true;
     }
     $feed_category = 'feed:' . md5($this->_feed->url);
     $orig_extra1 = $article->extra1;
     $article->extra1 = "|{$feed_category}|";
     $article->_activitystream_verb = 'http://community-equity.org/schema/1.0/clone';
     $article->_rcs_message = sprintf(midcom::get('i18n')->get_string('%s was imported from %s', 'net.nemein.rss'), $article->title, $this->_feed->title);
     // Handle categories provided in the feed
     if (isset($item['category'])) {
         // Check if we have multiple categories
         if (is_array($item['category'])) {
             // Some systems provide multiple categories as per in spec
             $categories = $item['category'];
         } elseif (strstr($item['category'], ',')) {
             // Some systems expose multiple categories in single category element
             $categories = explode(',', $item['category']);
         } else {
             $categories = array();
             $categories[] = $item['category'];
         }
         foreach ($categories as $category) {
             // Clean up the categories and save
             $category = str_replace('|', '_', trim($category));
             $article->extra1 .= "{$category}|";
         }
     }
     if ($orig_extra1 != $article->extra1) {
         $updated = true;
     }
     // Try to figure out item author
     if ($this->_feed->forceauthor && $this->_feed->defaultauthor) {
         // Feed has a "default author" set, use it
         $article_author = new midcom_db_person($this->_feed->defaultauthor);
     } else {
         $article_author = $this->match_item_author($item);
         $fallback_person_id = 1;
         if (!$article_author || $article_author->id == $fallback_person_id) {
             if ($this->_feed->defaultauthor) {
                 // Feed has a "default author" set, use it
                 $article_author = new midcom_db_person($this->_feed->defaultauthor);
             } else {
                 // Fall back to "Midgard Admin" just in case
                 $fallback_author = new midcom_db_person($fallback_person_id);
                 $article_author = $fallback_author;
             }
         }
     }
     if (is_object($article_author) && $article_author->guid) {
         if ($article->metadata->authors != "|{$article_author->guid}|") {
             $article->metadata->set('authors', "|{$article_author->guid}|");
             $updated = true;
         }
     }
     // Try to figure out item publication date
     $article_date = null;
     if (isset($item['date_timestamp'])) {
         $article_date = $item['date_timestamp'];
     }
     $article_data_tweaked = false;
     if (!$article_date) {
         $article_date = time();
         $article_data_tweaked = true;
     }
     if ($article_date > $this->_feed->latestupdate) {
         // Cache "latest updated" time to feed
         $this->_feed->latestupdate = $article_date;
         $this->_feed->_use_activitystream = false;
         $this->_feed->_use_rcs = false;
         $this->_feed->update();
     }
     if ($article->id) {
         // store <link rel="replies"> url in parameter
         if (isset($item['link_replies'])) {
             $article->set_parameter('net.nemein.rss', 'replies_url', $item['link_replies']);
         }
         if ($article->metadata->published != $article_date && !$article_data_tweaked) {
             $article->metadata->published = $article_date;
             $updated = true;
         }
         // Safety, make sure we have sane name (the allow_catenate was set earlier, so this will not clash
         if (empty($article->name)) {
             $article->name = midcom_helper_misc::generate_urlname_from_string($article->title);
             $updated = true;
         }
         if (!$updated) {
             // No data changed, avoid unnecessary I/O
             return $article->guid;
         }
         $article->allow_name_catenate = true;
         if ($article->update()) {
             if ($this->_feed->autoapprove) {
                 $metadata = midcom_helper_metadata::retrieve($article);
                 $metadata->approve();
             }
             $this->parse_tags($article, $item);
             $this->parse_parameters($article, $item);
             return $article->guid;
         }
         return false;
     } else {
         // Safety, make sure we have sane name (the allow_catenate was set earlier, so this will not clash
         if (empty($article->name)) {
             $article->name = midcom_helper_misc::generate_urlname_from_string($article->title);
         }
         // This is a new item
         $node = new midcom_db_topic($this->_feed->node);
         $node_lang_code = $node->get_parameter('net.nehmer.blog', 'language');
         if ($node->get_parameter('net.nehmer.blog', 'symlink_topic') != '') {
             try {
                 $symlink_topic = new midcom_db_topic($node->get_parameter('net.nehmer.blog', 'symlink_topic'));
                 $article->topic = $symlink_topic->id;
             } catch (midcom_error $e) {
                 $e->log();
             }
         }
         if ($node_lang_code != '') {
             $lang_id = midcom::get('i18n')->code_to_id($node_lang_code);
             $article->lang = $lang_id;
         }
         $article->allow_name_catenate = true;
         if ($article->create()) {
             // store <link rel="replies"> url in parameter
             if (isset($item['link_replies'])) {
                 $article->set_parameter('net.nemein.rss', 'replies_url', $item['link_replies']);
             }
             // This should be unnecessary but leave it in place just  in case
             if (strlen($article->name) == 0) {
                 // Generate something to avoid empty "/" links in case of failures
                 $article->name = time();
             }
             $article->metadata->published = $article_date;
             $article->allow_name_catenate = true;
             $article->update();
             if ($this->_feed->autoapprove) {
                 $metadata = midcom_helper_metadata::retrieve($article);
                 $metadata->approve();
             }
             $this->parse_tags($article, $item);
             $this->parse_parameters($article, $item);
             return $article->guid;
         }
         return false;
     }
 }
示例#10
0
 /**
  * Binds object to given metadata type.
  */
 function bind_metadata_to_object($metadata_type, &$object, $context_id = null)
 {
     $context = midcom_core_context::get($context_id);
     $this->_metadata[$context->id][$metadata_type] = midcom_helper_metadata::retrieve($object);
     if (!$this->_metadata[$context->id][$metadata_type]) {
         return;
     }
     // Update request metadata if appropriate
     $request_metadata = $this->get_request_metadata($context->id);
     $edited = $this->_metadata[$context->id][$metadata_type]->get('revised');
     if ($edited > $request_metadata['lastmodified']) {
         $this->set_request_metadata($edited, $request_metadata['permalinkguid']);
     }
 }
示例#11
0
 public function get_metadata()
 {
     return midcom_helper_metadata::retrieve($this);
 }
示例#12
0
 /**
  * Update possible ratings cache as requested in configuration
  */
 private function _cache_ratings()
 {
     $config = midcom_baseclasses_components_configuration::get('net.nehmer.comments', 'config');
     if ($config->get('ratings_enable') && ($config->get('ratings_cache_to_object') || $config->get('comment_count_cache_to_object'))) {
         // Handle ratings
         $comments = net_nehmer_comments_comment::list_by_objectguid($this->objectguid);
         $ratings_total = 0;
         $rating_comments = 0;
         $value = 0;
         foreach ($comments as $comment) {
             if (!empty($comment->rating)) {
                 $rating_comments++;
                 $ratings_total += $comment->rating;
             }
         }
         // Get parent object
         $parent_property = $config->get('ratings_cache_to_object_property');
         midcom::get('auth')->request_sudo('net.nehmer.comments');
         if ($config->get('ratings_cache_total')) {
             $value = $ratings_total;
         } else {
             if ($rating_comments != 0) {
                 $value = $ratings_total / $rating_comments;
             }
         }
         if ($config->get('ratings_cache_to_object_property_metadata')) {
             $metadata = midcom_helper_metadata::retrieve($this->objectguid);
             $metadata->set($parent_property, round($value));
         } else {
             $parent_object = midcom::get('dbfactory')->get_object_by_guid($this->objectguid);
             // TODO: Figure out whether to round
             if (!$config->get('ratings_cache_to_object_use_rcs')) {
                 $parent_object->_use_rcs = false;
             }
             $parent_object->{$parent_property} = $value;
             $parent_object->update();
             if (!$config->get('ratings_cache_to_object_use_rcs')) {
                 $parent_object->_use_rcs = true;
             }
         }
         // Get parent object
         $parent_property = $config->get('comment_count_cache_to_object_property');
         if ($config->get('comment_count_cache_to_object_property_metadata')) {
             $metadata = midcom_helper_metadata::retrieve($this->objectguid);
             $metadata->set($parent_property, count($comments));
         } else {
             $parent_object = midcom::get('dbfactory')->get_object_by_guid($this->objectguid);
             if (!$config->get('comment_count_cache_to_object_use_rcs')) {
                 $parent_object->_use_rcs = false;
             }
             $parent_object->{$parent_property} = count($comments);
             $parent_object->update();
             if (!$config->get('comment_count_cache_to_object_use_rcs')) {
                 $parent_object->_use_rcs = true;
             }
         }
         midcom::get('auth')->drop_sudo();
     }
 }
示例#13
0
文件: main.php 项目: nemein/openpsa
 /**
  * This function tries to instantiate the most specific document class
  * for the object given in the parameter.
  *
  * This class will not return empty document base class instances if nothing
  * specific can be found. If you are in this situation, you need to instantiate
  * an appropriate document manually and populate it.
  *
  * The checking sequence is like this right now:
  *
  * 1. If a datamanager instance is passed, it is transformed into a midcom_services_indexer_document_datamanager2.
  * 2. If a Metadata object is passed, it is transformed into a midcom_services_indexer_document_midcom.
  * 3. Next, the method tries to retrieve a MidCOM Metadata object using the parameter directly. If successful,
  *    again, a midcom_services_indexer_document_midcom is returned.
  *
  * This factory method will work even if the indexer is disabled. You can check this
  * with the enabled() method of this class.
  *
  * @todo Move to a full factory pattern here to save document php file parsings where possible.
  *     This means that all document creations will in the future be handled by this method.
  *
  * @param object &$object The object for which a document instance is required, passed by reference.
  * @return midcom_services_indexer_document A valid document class as specific as possible. Returns
  *     false on error or if no specific class match could be found.
  */
 function new_document(&$object)
 {
     // Scan for datamanager instances.
     if (is_a($object, 'midcom_helper_datamanager2_datamanager')) {
         debug_add('This is a document_datamanager2');
         return new midcom_services_indexer_document_datamanager2($object);
     }
     // Maybe we have a metadata object...
     if (is_a($object, 'midcom_helper_metadata')) {
         debug_add('This is a metadata document, built from a metadata object.');
         return new midcom_services_indexer_document_midcom($object);
     }
     // Try to get a metadata object for the argument passed
     // This should catch all DBA objects as well.
     $metadata = midcom_helper_metadata::retrieve($object);
     if ($metadata) {
         debug_add('Successfully fetched a Metadata object for the argument.');
         return new midcom_services_indexer_document_midcom($metadata);
     }
     // No specific match found.
     debug_print_r('No match found for this type:', $object);
     return false;
 }
示例#14
0
 private function _add_toolbar_update_items($object)
 {
     if (is_a($object, 'midcom_db_topic') && $object->component && $object->can_do('midcom:component_config')) {
         $this->add_item(array(MIDCOM_TOOLBAR_URL => "__mfa/asgard/components/configuration/edit/{$object->component}/{$object->guid}/", MIDCOM_TOOLBAR_LABEL => midcom::get('i18n')->get_string('component configuration', 'midcom'), MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/stock_folder-properties.png'));
     }
     $this->add_item(array(MIDCOM_TOOLBAR_URL => $this->_generate_url('metadata', $object), MIDCOM_TOOLBAR_LABEL => midcom::get('i18n')->get_string('metadata', 'midcom'), MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/metadata.png', MIDCOM_TOOLBAR_ACCESSKEY => 'm'));
     /** COPIED from midcom_services_toolbars */
     if ($GLOBALS['midcom_config']['metadata_approval']) {
         $metadata = midcom_helper_metadata::retrieve($object);
         if ($metadata && $metadata->is_approved()) {
             $icon = 'stock-icons/16x16/page-approved.png';
             if (!$GLOBALS['midcom_config']['show_hidden_objects'] && !$metadata->is_visible()) {
                 // Take scheduling into account
                 $icon = 'stock-icons/16x16/page-approved-notpublished.png';
             }
             $this->add_item(array(MIDCOM_TOOLBAR_URL => "__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 => $icon, MIDCOM_TOOLBAR_POST => true, MIDCOM_TOOLBAR_POST_HIDDENARGS => array('guid' => $object->guid, 'return_to' => $_SERVER['REQUEST_URI']), MIDCOM_TOOLBAR_ACCESSKEY => 'u', MIDCOM_TOOLBAR_ENABLED => $object->can_do('midcom:approve')));
         } else {
             $icon = 'stock-icons/16x16/page-notapproved.png';
             if (!$GLOBALS['midcom_config']['show_hidden_objects'] && !$metadata->is_visible()) {
                 // Take scheduling into account
                 $icon = 'stock-icons/16x16/page-notapproved-notpublished.png';
             }
             $this->add_item(array(MIDCOM_TOOLBAR_URL => "__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 => $icon, MIDCOM_TOOLBAR_POST => true, MIDCOM_TOOLBAR_POST_HIDDENARGS => array('guid' => $object->guid, 'return_to' => $_SERVER['REQUEST_URI']), MIDCOM_TOOLBAR_ACCESSKEY => 'a', MIDCOM_TOOLBAR_ENABLED => $object->can_do('midcom:approve')));
         }
     }
     /** /COPIED from midcom_services_toolbars */
     $this->add_item(array(MIDCOM_TOOLBAR_URL => $this->_generate_url('attachments', $object), MIDCOM_TOOLBAR_LABEL => midcom::get('i18n')->get_string('attachments', 'midgard.admin.asgard'), MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/attach.png'));
     $this->add_item(array(MIDCOM_TOOLBAR_URL => $this->_generate_url('parameters', $object), MIDCOM_TOOLBAR_LABEL => midcom::get('i18n')->get_string('parameters', 'midcom'), MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/properties.png', MIDCOM_TOOLBAR_ENABLED => $object->can_do('midgard:parameters')));
     $this->add_item(array(MIDCOM_TOOLBAR_URL => $this->_generate_url('permissions', $object), MIDCOM_TOOLBAR_LABEL => midcom::get('i18n')->get_string('privileges', 'midcom'), MIDCOM_TOOLBAR_ICON => 'midgard.admin.asgard/permissions-16.png', MIDCOM_TOOLBAR_ENABLED => $object->can_do('midgard:privileges')));
     if (midcom::get('componentloader')->is_installed('midcom.helper.replicator') && midcom::get('auth')->admin) {
         $this->add_item(array(MIDCOM_TOOLBAR_URL => "__mfa/asgard_midcom.helper.replicator/object/{$object->guid}/", MIDCOM_TOOLBAR_LABEL => midcom::get('i18n')->get_string('replication information', 'midcom.helper.replicator'), MIDCOM_TOOLBAR_ICON => 'midcom.helper.replicator/replicate-server-16.png', MIDCOM_TOOLBAR_ACCESSKEY => 'r'));
     }
 }