コード例 #1
0
ファイル: lib.php プロジェクト: Br3nda/mahara
 /**
  * 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 (isset($entry->content['src']) && isset($entry->content['type'])) {
         $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 = count($entry->xpath('a:category[(' . $importer->curie_xpath('@scheme', PluginImportLeap::NS_CATEGORIES, 'readiness#') . ') and @term="Unready"]')) == 1;
     $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;
 }
コード例 #2
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;
 }