private static function get_blogpost_entry_data(SimpleXMLElement $entry, PluginImportLeap $importer, $blogentryid) { // 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)) { $isfile = true; } else { $isfile = false; $description = PluginImportLeap::get_entry_content($entry, $importer); $type = isset($entry->content['type']) ? (string) $entry->content['type'] : 'text'; if ($type == 'text') { $description = format_whitespace($description); } } return $config = array('isfile' => $isfile, 'owner' => $importer->get('usr'), 'type' => 'blogpost', 'parent' => $blogentryid, 'content' => array('title' => (string) $entry->title, 'description' => isset($description) ? $description : null, 'files' => self::add_files_to_import_entry_request_blogpost($entry, $importer, $blogentryid), 'ctime' => (string) $entry->published, 'mtime' => (string) $entry->updated, 'published' => PluginImportLeap::is_correct_category_scheme($entry, $importer, 'readiness', 'Unready') ? 0 : 1, 'tags' => PluginImportLeap::get_entry_tags($entry))); }
/** * 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') . '&maxwidth=500&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; }