Пример #1
0
 /**
  * The profile importer tries to import raw profile fields using the
  * strategy mechanism, but most of the useful profile information is stored
  * in the person entry corresponding to the author.
  *
  * The persondata entry is not actually imported using a strategy, because
  * we need to be able to import basic data from the <author> element if
  * it's not present too. So all the person importing is handled in import_author_data()
  */
 public static function get_import_strategies_for_entry(SimpleXMLElement $entry, PluginImportLeap $importer)
 {
     if (self::$personcontentblank === null) {
         self::$personcontentblank = true;
         if ($persondataid = $importer->get('persondataid')) {
             self::$personcontentblank = !(string) $importer->get_entry_by_id($persondataid)->content;
         }
     }
     $isentry = PluginImportLeap::is_rdf_type($entry, $importer, 'entry');
     if ($isentry && self::$personcontentblank && PluginImportLeap::is_correct_category_scheme($entry, $importer, 'common_item', 'Personalstatement')) {
         return array(array('strategy' => self::STRATEGY_IMPORT_AS_INTRODUCTION, 'score' => 100, 'other_required_entries' => array()));
     }
     // If it's a raw entry with the right mahara:plugin and mahara:type
     // we should be able to import it
     $correctplugintype = count($entry->xpath('mahara:artefactplugin[@mahara:plugin="internal"]')) == 1;
     if ($isentry && $correctplugintype) {
         return array(array('strategy' => self::STRATEGY_IMPORT_AS_PROFILE_FIELD, 'score' => 100, 'other_required_entries' => array()));
     }
     return array();
 }
Пример #2
0
 /**
  * Creates a comment from the given entry
  *
  * @param SimpleXMLElement $entry    The entry to create the comment from
  * @param PluginImportLeap $importer The importer
  * @return array A list of artefact IDs created, to be used with the artefact mapping.
  */
 private static function create_comment(SimpleXMLElement $entry, PluginImportLeap $importer)
 {
     $createdartefacts = array();
     $comment = new ArtefactTypeComment();
     $comment->set('title', (string) $entry->title);
     $description = PluginImportLeap::get_entry_content($entry, $importer);
     $type = isset($entry->content['type']) ? (string) $entry->content['type'] : 'text';
     if ($type == 'text') {
         $description = format_whitespace($description);
     }
     $comment->set('description', $description);
     if ($published = strtotime((string) $entry->published)) {
         $comment->set('ctime', $published);
     }
     if ($updated = strtotime((string) $entry->updated)) {
         $comment->set('mtime', $updated);
     }
     $private = PluginImportLeap::is_correct_category_scheme($entry, $importer, 'audience', 'Private');
     $comment->set('private', (int) $private);
     $comment->set('owner', $importer->get('usr'));
     if (isset($entry->author->name) && strlen($entry->author->name)) {
         $comment->set('authorname', $entry->author->name);
     } else {
         $comment->set('author', $importer->get('usr'));
     }
     if (empty(self::$tempview)) {
         self::create_temporary_view($importer->get('usr'));
     }
     $comment->set('onview', self::$tempview);
     $comment->set('tags', PluginImportLeap::get_entry_tags($entry));
     $comment->commit();
     array_unshift($createdartefacts, $comment->get('id'));
     return $createdartefacts;
 }
Пример #3
0
 /**
  * Given an entry, see if it's attached to one of the special selections 
  * representing a Mahara resume group. If so, return the display order it 
  * should have in that group.
  *
  * We look for the special Mahara selections only, because entries could be 
  * in more than one selection, with different display orders in each.
  *
  * @param SimpleXMLElement $entry    The entry to check
  * @param PluginImportLeap $importer The importer
  * @param string $selectiontype      The type of selection we're checking to 
  *                                   see if the entry is part of - one of the 
  *                                   special Mahara resume selections
  * @return int The display order of the element in the selection, should it 
  *             be in one - else null
  */
 private static function get_display_order_for_entry(SimpleXMLElement $entry, PluginImportLeap $importer, $selectiontype)
 {
     static $cache = array();
     $found = false;
     foreach ($entry->link as $link) {
         if ($importer->curie_equals($link['rel'], $importer->get_leap2a_namespace(), 'is_part_of') && isset($link['href'])) {
             $href = (string) $link['href'];
             if (isset($cache[$href])) {
                 $found = true;
             } else {
                 if ($potentialselection = $importer->get_entry_by_id($href)) {
                     if (PluginImportLeap::is_rdf_type($potentialselection, $importer, 'selection')) {
                         if (PluginImportLeap::is_correct_category_scheme($potentialselection, $importer, 'selection_type', 'Grouping')) {
                             if (count($potentialselection->xpath('mahara:artefactplugin[@mahara:type="' . $selectiontype . '"]')) == 1) {
                                 $cache[$href] = true;
                                 $found = true;
                             }
                         }
                     }
                 }
             }
             if ($found) {
                 $leapattributes = $importer->get_attributes($link, $importer->get_leap2a_namespace());
                 $displayorder = isset($leapattributes['display_order']) && intval($leapattributes['display_order']) > 0 ? $leapattributes['display_order'] : '';
                 return $displayorder;
             }
         }
     }
 }
Пример #4
0
 /**
  * Logic to figure out how to process an entry into a comment
  * Used by import_using_strategy() and add_import_entry_request_using_strategy().
  *
  * @param SimpleXMLElement $entry
  * @param PluginImportLeap $importer
  * @param unknown_type $strategy
  * @param array $otherentries
  * @return array An array of config stuff to either create the comment, or store an import request.
  * @throws ImportException
  */
 private static function get_entry_data_using_strategy(SimpleXMLElement $entry, PluginImportLeap $importer, $strategy, array $otherentries)
 {
     if ($strategy != self::STRATEGY_IMPORT_AS_COMMENT) {
         throw new ImportException($importer, 'TODO: get_string: unknown strategy chosen for importing entry');
     }
     $description = PluginImportLeap::get_entry_content($entry, $importer);
     $type = isset($entry->content['type']) ? (string) $entry->content['type'] : 'text';
     if ($type == 'text') {
         $description = format_whitespace($description);
     }
     if (isset($entry->author->name) && strlen($entry->author->name)) {
         $authorname = (string) $entry->author->name;
     } else {
         $author = $importer->get('usr');
     }
     return array('owner' => $importer->get('usr'), 'type' => 'comment', 'content' => array('title' => (string) $entry->title, 'description' => $description, 'ctime' => (string) $entry->published, 'mtime' => (string) $entry->updated, 'private' => (int) PluginImportLeap::is_correct_category_scheme($entry, $importer, 'audience', 'Private'), 'authorname' => isset($authorname) ? $authorname : null, 'author' => isset($author) ? $author : null, 'tags' => PluginImportLeap::get_entry_tags($entry)));
 }
Пример #5
0
 /**
  * Returns whether the given entry is a folder
  *
  * @param SimpleXMLElement $entry    The entry to check
  * @param PluginImportLeap $importer The importer
  * @return boolean Whether the entry is a folder
  */
 private static function is_folder(SimpleXMLElement $entry, PluginImportLeap $importer)
 {
     static $cache = array();
     $id = (string) $entry->id;
     if (isset($cache[$id])) {
         return $cache[$id];
     }
     return $cache[$id] = PluginImportLeap::is_rdf_type($entry, $importer, 'selection') && PluginImportLeap::is_correct_category_scheme($entry, $importer, 'selection_type', 'Folder');
 }
Пример #6
0
 private static function get_annotationfeedback_entry_data(SimpleXMLElement $entry, PluginImportLeap $importer, $annotationentryid)
 {
     $description = PluginImportLeap::get_entry_content($entry, $importer);
     $type = isset($entry->content['type']) ? (string) $entry->content['type'] : 'text';
     if ($type == 'text') {
         $description = format_whitespace($description);
     }
     if (isset($entry->author->name) && strlen($entry->author->name)) {
         $authorname = (string) $entry->author->name;
     } else {
         $author = $importer->get('usr');
     }
     return array('owner' => $importer->get('usr'), 'type' => 'annotationfeedback', 'parent' => $annotationentryid, 'content' => array('title' => (string) $entry->title, 'description' => $description, 'ctime' => (string) $entry->published, 'mtime' => (string) $entry->updated, 'authorname' => isset($authorname) ? $authorname : null, 'author' => isset($author) ? $author : null, 'tags' => PluginImportLeap::get_entry_tags($entry), 'private' => (int) PluginImportLeap::is_correct_category_scheme($entry, $importer, 'audience', 'Private'), 'onannotation' => $annotationentryid));
 }
Пример #7
0
 /**
  * Creates a blogpost from the given entry
  *
  * @param SimpleXMLElement $entry    The entry to create the blogpost from
  * @param PluginImportLeap $importer The importer
  * @param int $blogid                The blog in which to put the post
  * @return array A list of artefact IDs created, to be used with the artefact mapping.
  *               There will either be one (the blogpost ID), or two. If there is two, the
  *               second one will be the ID of the file created to hold the out-of-line
  *               content associated with the blogpost
  */
 private static function create_blogpost(SimpleXMLElement $entry, PluginImportLeap $importer, $blogid)
 {
     $config = self::get_blogpost_entry_data($entry, $importer, $blogid);
     $createdartefacts = array();
     $blogpost = new ArtefactTypeBlogPost();
     $blogpost->set('title', $config['content']['title']);
     // If the entry has out of line content, we import that separately as a
     // file and set the content to refer to it
     if ($config['isfile']) {
         $file = LeapImportFile::create_file($entry, $importer);
         $createdartefacts[] = $file->get('id');
         $content = '<a href="' . get_config('wwwroot') . 'artefact/file/download.php?file=' . $file->get('id') . '"' . ' title="' . hsc($file->get('title')) . '">';
         if (is_image_mime_type($file->get('filetype'))) {
             $content .= '<img src="' . get_config('wwwroot') . 'artefact/file/download.php?file=' . $file->get('id') . '&amp;maxwidth=500&amp;maxheight=500"' . ' alt="' . hsc($file->get('title')) . '">';
         }
         $content .= '</a>';
         $blogpost->set('description', $content);
     } else {
         $blogpost->set('description', $config['content']['description']);
     }
     if ($config['content']['ctime']) {
         $blogpost->set('ctime', $config['content']['ctime']);
     }
     if ($config['content']['mtime']) {
         $blogpost->set('mtime', $config['content']['mtime']);
     }
     $draftpost = PluginImportLeap::is_correct_category_scheme($entry, $importer, 'readiness', 'Unready');
     $blogpost->set('published', $config['content']['published']);
     $blogpost->set('owner', $config['owner']);
     $blogpost->set('parent', $blogid);
     $blogpost->set('tags', $config['content']['tags']);
     $blogpost->commit();
     array_unshift($createdartefacts, $blogpost->get('id'));
     return $createdartefacts;
 }
Пример #8
0
 /**
  * Creates a blogpost from the given entry
  *
  * @param SimpleXMLElement $entry    The entry to create the blogpost from
  * @param PluginImportLeap $importer The importer
  * @param int $blogid                The blog in which to put the post
  * @return array A list of artefact IDs created, to be used with the artefact mapping. 
  *               There will either be one (the blogpost ID), or two. If there is two, the 
  *               second one will be the ID of the file created to hold the out-of-line 
  *               content associated with the blogpost
  */
 private static function create_blogpost(SimpleXMLElement $entry, PluginImportLeap $importer, $blogid)
 {
     $createdartefacts = array();
     $blogpost = new ArtefactTypeBlogPost();
     $blogpost->set('title', (string) $entry->title);
     // If the entry has out of line content, we import that separately as a
     // file and set the content to refer to it
     if (LeapImportFile::is_file($entry, $importer)) {
         $file = LeapImportFile::create_file($entry, $importer);
         $createdartefacts[] = $file->get('id');
         $content = '<a href="' . get_config('wwwroot') . 'artefact/file/download.php?file=' . $file->get('id') . '"' . ' title="' . hsc($file->get('title')) . '">';
         if (is_image_mime_type($file->get('filetype'))) {
             $content .= '<img src="' . get_config('wwwroot') . 'artefact/file/download.php?file=' . $file->get('id') . '&amp;maxwidth=500&amp;maxheight=500"' . ' alt="' . hsc($file->get('title')) . '">';
         }
         $content .= '</a>';
         $blogpost->set('description', $content);
     } else {
         $description = PluginImportLeap::get_entry_content($entry, $importer);
         $type = isset($entry->content['type']) ? (string) $entry->content['type'] : 'text';
         if ($type == 'text') {
             $description = format_whitespace($description);
         }
         $blogpost->set('description', $description);
     }
     if ($published = strtotime((string) $entry->published)) {
         $blogpost->set('ctime', $published);
     }
     if ($updated = strtotime((string) $entry->updated)) {
         $blogpost->set('mtime', $updated);
     }
     $draftpost = PluginImportLeap::is_correct_category_scheme($entry, $importer, 'readiness', 'Unready');
     $blogpost->set('published', $draftpost ? 0 : 1);
     $blogpost->set('owner', $importer->get('usr'));
     $blogpost->set('parent', $blogid);
     $blogpost->set('tags', PluginImportLeap::get_entry_tags($entry));
     $blogpost->commit();
     array_unshift($createdartefacts, $blogpost->get('id'));
     return $createdartefacts;
 }