Esempio n. 1
0
 public function testHandler_tagged()
 {
     $article_properties = array('topic' => self::$_topic->id, 'title' => __CLASS__ . ' ' . __FUNCTION__ . ' ' . time());
     $page2 = $this->create_object('net_nemein_wiki_wikipage', $article_properties);
     midcom::get('auth')->request_sudo('net.nemein.wiki');
     net_nemein_tag_handler::tag_object($page2, array(self::$_page->name => ''), 'net.nemein.wiki');
     midcom::get('auth')->drop_sudo();
     $data = $this->run_handler(self::$_topic, array('tags', self::$_page->name));
     $this->assertEquals('tags', $data['handler_id']);
     $this->show_handler($data);
 }
Esempio n. 2
0
 public function convert_to_storage()
 {
     $tag_array = net_nemein_tag_handler::string2tag_array($this->value);
     $this->auto_context = trim($this->auto_context);
     if (!empty($this->auto_context)) {
         $new_tag_array = array();
         foreach ($tag_array as $tagname => $url) {
             $context = net_nemein_tag_handler::resolve_context($tagname);
             if (empty($context)) {
                 $tagname = "{$this->auto_context}:{$tagname}";
             }
             $new_tag_array[$tagname] = $url;
         }
         unset($tagname, $url);
         $tag_array = $new_tag_array;
         unset($new_tag_array);
     }
     $status = net_nemein_tag_handler::tag_object($this->storage->object, $tag_array);
     if (!$status) {
         debug_add("Tried to save the tags \"{$this->value}\" for field {$this->name}, but failed. Ignoring silently.", MIDCOM_LOG_WARN);
     }
     return null;
 }
Esempio n. 3
0
 /**
  * @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();
 }
Esempio n. 4
0
 /**
  * Parses rel-tag links in article content and tags the object based on them
  *
  * @param midgard_article $article Imported article
  * @param Array $item Feed item as provided by MagpieRSS
  * @return boolean
  */
 function parse_tags($article, $item, $field = 'content')
 {
     $html_tags = org_openpsa_httplib_helpers::get_anchor_values($article->{$field}, 'tag');
     $tags = array();
     if (count($html_tags) > 0) {
         foreach ($html_tags as $html_tag) {
             if (!$html_tag['value']) {
                 // No actual tag specified, skip
                 continue;
             }
             $tag = strtolower(strip_tags($html_tag['value']));
             $tags[$tag] = $html_tag['href'];
         }
         midcom::get('componentloader')->load_library('net.nemein.tag');
         return net_nemein_tag_handler::tag_object($article, $tags);
     }
     return true;
 }
Esempio n. 5
0
 private function _save_to_taglib()
 {
     if ($this->allow_other && !empty($this->others)) {
         $merged = array_merge($this->selection, $this->others);
         foreach ($merged as $k => $tag) {
             $tags[$tag] = '';
         }
     } else {
         if (count($this->selection) == 0) {
             return;
         } else {
             foreach ($this->selection as $k => $tag) {
                 $tags[$tag] = '';
             }
         }
     }
     debug_print_r('new tags to be saved to n.n.tag', $tags);
     $status = net_nemein_tag_handler::tag_object($this->storage->object, $tags);
     if (!$status) {
         debug_print_r('Tried to save the tags', $tags);
         debug_add("for field {$this->name}, but failed. Ignoring silently.", MIDCOM_LOG_WARN);
     }
     $tmp_tags = net_nemein_tag_handler::get_object_tags($this->storage->object);
     $tags = array();
     foreach ($tmp_tags as $name => $url) {
         $tags[$name] = $name;
     }
     debug_print_r("new tags:", $tags);
 }