Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
mahara
mahara
Commits
5a83c883
Commit
5a83c883
authored
Apr 21, 2009
by
Richard Mansfield
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Import/export changes from Penny, Nigel collected from importexport branch
parent
5777b4aa
Changes
81
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
75 changed files
with
6627 additions
and
57 deletions
+6627
-57
htdocs/admin/extensions/pluginconfig.php
htdocs/admin/extensions/pluginconfig.php
+21
-0
htdocs/admin/extensions/plugins.php
htdocs/admin/extensions/plugins.php
+6
-2
htdocs/api/xmlrpc/lib.php
htdocs/api/xmlrpc/lib.php
+7
-15
htdocs/artefact/blog/export/html/lib.php
htdocs/artefact/blog/export/html/lib.php
+73
-0
htdocs/artefact/blog/export/html/theme/default/index.tpl
htdocs/artefact/blog/export/html/theme/default/index.tpl
+7
-0
htdocs/artefact/blog/export/leap/lib.php
htdocs/artefact/blog/export/leap/lib.php
+97
-0
htdocs/artefact/blog/import/leap/lib.php
htdocs/artefact/blog/import/leap/lib.php
+283
-0
htdocs/artefact/blog/lib.php
htdocs/artefact/blog/lib.php
+2
-2
htdocs/artefact/blog/theme/default/render/blogpost_renderfull.tpl
...rtefact/blog/theme/default/render/blogpost_renderfull.tpl
+1
-1
htdocs/artefact/file/export/html/lib.php
htdocs/artefact/file/export/html/lib.php
+165
-0
htdocs/artefact/file/export/html/theme/default/index.tpl
htdocs/artefact/file/export/html/theme/default/index.tpl
+19
-0
htdocs/artefact/file/export/leap/lib.php
htdocs/artefact/file/export/leap/lib.php
+97
-0
htdocs/artefact/file/import/leap/lib.php
htdocs/artefact/file/import/leap/lib.php
+359
-0
htdocs/artefact/file/lib.php
htdocs/artefact/file/lib.php
+4
-4
htdocs/artefact/internal/blocktype/profileinfo/theme/default/content.tpl
.../internal/blocktype/profileinfo/theme/default/content.tpl
+1
-1
htdocs/artefact/internal/export/html/lib.php
htdocs/artefact/internal/export/html/lib.php
+56
-0
htdocs/artefact/internal/export/html/theme/default/summary.tpl
...s/artefact/internal/export/html/theme/default/summary.tpl
+6
-0
htdocs/artefact/internal/export/leap/lib.php
htdocs/artefact/internal/export/leap/lib.php
+169
-0
htdocs/artefact/internal/export/leap/theme/default/entry.tpl
htdocs/artefact/internal/export/leap/theme/default/entry.tpl
+24
-0
htdocs/artefact/internal/import/leap/lib.php
htdocs/artefact/internal/import/leap/lib.php
+570
-0
htdocs/artefact/internal/lib.php
htdocs/artefact/internal/lib.php
+5
-1
htdocs/artefact/lib.php
htdocs/artefact/lib.php
+26
-4
htdocs/artefact/resume/export/leap/lib.php
htdocs/artefact/resume/export/leap/lib.php
+469
-0
htdocs/artefact/resume/export/leap/theme/default/composite.tpl
...s/artefact/resume/export/leap/theme/default/composite.tpl
+6
-0
htdocs/artefact/resume/lib.php
htdocs/artefact/resume/lib.php
+2
-2
htdocs/artefact/resume/resume.css
htdocs/artefact/resume/resume.css
+8
-0
htdocs/artefact/resume/resumeshowhide.js
htdocs/artefact/resume/resumeshowhide.js
+49
-0
htdocs/auth/internal/lib.php
htdocs/auth/internal/lib.php
+4
-0
htdocs/blocktype/lib.php
htdocs/blocktype/lib.php
+1
-1
htdocs/config-defaults.php
htdocs/config-defaults.php
+3
-0
htdocs/export/TODO
htdocs/export/TODO
+3
-0
htdocs/export/html/lib.php
htdocs/export/html/lib.php
+167
-0
htdocs/export/html/theme/default/footer.tpl
htdocs/export/html/theme/default/footer.tpl
+2
-0
htdocs/export/html/theme/default/header.tpl
htdocs/export/html/theme/default/header.tpl
+6
-0
htdocs/export/html/theme/default/index.tpl
htdocs/export/html/theme/default/index.tpl
+12
-0
htdocs/export/html/version.php
htdocs/export/html/version.php
+33
-0
htdocs/export/index.php
htdocs/export/index.php
+72
-0
htdocs/export/leap/lib.php
htdocs/export/leap/lib.php
+635
-0
htdocs/export/leap/theme/default/author.tpl
htdocs/export/leap/theme/default/author.tpl
+6
-0
htdocs/export/leap/theme/default/categories.tpl
htdocs/export/leap/theme/default/categories.tpl
+3
-0
htdocs/export/leap/theme/default/entry.tpl
htdocs/export/leap/theme/default/entry.tpl
+17
-0
htdocs/export/leap/theme/default/entryfooter.tpl
htdocs/export/leap/theme/default/entryfooter.tpl
+2
-0
htdocs/export/leap/theme/default/entryheader.tpl
htdocs/export/leap/theme/default/entryheader.tpl
+2
-0
htdocs/export/leap/theme/default/footer.tpl
htdocs/export/leap/theme/default/footer.tpl
+1
-0
htdocs/export/leap/theme/default/header.tpl
htdocs/export/leap/theme/default/header.tpl
+15
-0
htdocs/export/leap/theme/default/links.tpl
htdocs/export/leap/theme/default/links.tpl
+3
-0
htdocs/export/leap/version.php
htdocs/export/leap/version.php
+33
-0
htdocs/export/lib.php
htdocs/export/lib.php
+220
-0
htdocs/grouptype/standard/lib.php
htdocs/grouptype/standard/lib.php
+4
-0
htdocs/import/TODO
htdocs/import/TODO
+14
-0
htdocs/import/index.php
htdocs/import/index.php
+138
-0
htdocs/import/leap/lib.php
htdocs/import/leap/lib.php
+662
-0
htdocs/import/leap/version.php
htdocs/import/leap/version.php
+33
-0
htdocs/import/lib.php
htdocs/import/lib.php
+299
-0
htdocs/init.php
htdocs/init.php
+3
-1
htdocs/interaction/forum/lib.php
htdocs/interaction/forum/lib.php
+4
-0
htdocs/lang/en.utf8/export.php
htdocs/lang/en.utf8/export.php
+29
-0
htdocs/lang/en.utf8/import.php
htdocs/lang/en.utf8/import.php
+29
-0
htdocs/lang/en.utf8/langconfig.php
htdocs/lang/en.utf8/langconfig.php
+1
-0
htdocs/lang/en.utf8/mahara.php
htdocs/lang/en.utf8/mahara.php
+5
-0
htdocs/lib/country.php
htdocs/lib/country.php
+1278
-0
htdocs/lib/cron.php
htdocs/lib/cron.php
+1
-1
htdocs/lib/db/upgrade.php
htdocs/lib/db/upgrade.php
+94
-1
htdocs/lib/dml.php
htdocs/lib/dml.php
+42
-0
htdocs/lib/errors.php
htdocs/lib/errors.php
+39
-1
htdocs/lib/file.php
htdocs/lib/file.php
+1
-1
htdocs/lib/mahara.php
htdocs/lib/mahara.php
+40
-9
htdocs/lib/smarty/mahara/resource.export.php
htdocs/lib/smarty/mahara/resource.export.php
+78
-0
htdocs/lib/upgrade.php
htdocs/lib/upgrade.php
+1
-1
htdocs/lib/version.php
htdocs/lib/version.php
+1
-1
htdocs/lib/view.php
htdocs/lib/view.php
+11
-1
htdocs/lib/web.php
htdocs/lib/web.php
+19
-7
htdocs/notification/internal/lib.php
htdocs/notification/internal/lib.php
+3
-0
htdocs/search/internal/lib.php
htdocs/search/internal/lib.php
+4
-0
htdocs/test/export.php
htdocs/test/export.php
+22
-0
No files found.
htdocs/admin/extensions/pluginconfig.php
View file @
5a83c883
...
...
@@ -39,6 +39,27 @@ define('SECTION_PLUGINNAME', $pluginname);
define
(
'SECTION_PAGE'
,
'pluginconfig'
);
safe_require
(
$plugintype
,
$pluginname
);
if
(
$sesskey
=
param_alphanum
(
'sesskey'
,
''
))
{
if
(
$sesskey
!=
$USER
->
get
(
'sesskey'
))
{
throw
new
UserException
(
'Invalid sesskey'
);
}
}
$enable
=
param_integer
(
'enable'
,
0
);
$disable
=
param_integer
(
'disable'
,
0
);
if
(
$disable
&&
!
call_static_method
(
generate_class_name
(
$plugintype
,
$pluginname
),
'can_be_disabled'
))
{
throw
new
UserException
(
"Plugin
$plugintype
$pluginname
cannot be disabled"
);
}
if
(
$enable
||
$disable
)
{
if
(
$plugintype
==
'blocktype'
)
{
$pluginname
=
blocktype_namespaced_to_single
(
$pluginname
);
}
set_field
(
$plugintype
.
'_installed'
,
'active'
,
$enable
,
'name'
,
$pluginname
);
$SESSION
->
add_ok_msg
(
get_string
(
'plugin'
.
((
$enable
)
?
'enabled'
:
'disabled'
)));
redirect
(
'/admin/extensions/plugins.php'
);
}
if
(
$plugintype
==
'artefact'
)
{
$type
=
param_alpha
(
'type'
);
$classname
=
generate_artefact_class_name
(
$type
);
...
...
htdocs/admin/extensions/plugins.php
View file @
5a83c883
...
...
@@ -48,13 +48,17 @@ foreach (plugin_types() as $plugin) {
}
foreach
(
array_keys
(
$plugins
)
as
$plugin
)
{
if
(
table_exists
(
new
XMLDBTable
(
$plugin
.
'_installed'
)))
{
if
(
$installed
=
get_records_array
(
$
plugin
.
'
_installed
'
))
{
if
(
$installed
=
plugin
s
_installed
(
$plugin
,
true
))
{
foreach
(
$installed
as
$i
)
{
$key
=
$i
->
name
;
if
(
$plugin
==
'blocktype'
)
{
$key
=
blocktype_single_to_namespaced
(
$i
->
name
,
$i
->
artefactplugin
);
}
$plugins
[
$plugin
][
'installed'
][
$key
]
=
array
();
safe_require
(
$plugin
,
$key
);
$plugins
[
$plugin
][
'installed'
][
$key
]
=
array
(
'active'
=>
$i
->
active
,
'disableable'
=>
call_static_method
(
generate_class_name
(
$plugin
,
$key
),
'can_be_disabled'
),
);
if
(
$plugin
==
'artefact'
)
{
$plugins
[
$plugin
][
'installed'
][
$key
][
'types'
]
=
array
();
safe_require
(
'artefact'
,
$key
);
...
...
htdocs/api/xmlrpc/lib.php
View file @
5a83c883
...
...
@@ -272,7 +272,7 @@ function user_authorise($token, $useragent) {
function
send_content_intent
(
$username
)
{
global
$REMOTEWWWROOT
;
require_once
(
'import.php'
);
require_once
(
get_config
(
'docroot'
)
.
'import
/lib
.php'
);
list
(
$user
,
$authinstance
)
=
find_remote_user
(
$username
,
$REMOTEWWWROOT
);
if
(
!
$user
)
{
...
...
@@ -289,16 +289,7 @@ function send_content_intent($username) {
throw
$e
;
}
// generate a token, insert it into the queue table
$queue
=
new
StdClass
;
$queue
->
token
=
generate_token
();
$queue
->
host
=
$REMOTEWWWROOT
;
$queue
->
usr
=
$user
->
id
;
$queue
->
queue
=
(
int
)
!
(
Importer
::
import_immediately_allowed
());
$queue
->
ready
=
0
;
$queue
->
expirytime
=
db_format_timestamp
(
time
()
+
(
60
*
60
*
24
));
insert_record
(
'import_queue'
,
$queue
);
$queue
=
PluginImport
::
create_new_queue
(
$user
->
id
,
null
,
$REMOTEWWWROOT
,
0
);
return
array
(
'sendtype'
=>
((
$queue
->
queue
)
?
'queue'
:
'immediate'
),
...
...
@@ -308,7 +299,7 @@ function send_content_intent($username) {
function
send_content_ready
(
$token
,
$username
,
$format
,
$importdata
,
$fetchnow
=
false
)
{
global
$REMOTEWWWROOT
;
require_once
(
'import.php'
);
require_once
(
get_config
(
'docroot'
)
.
'import
/lib
.php'
);
list
(
$user
,
$authinstance
)
=
find_remote_user
(
$username
,
$REMOTEWWWROOT
);
if
(
!
$user
)
{
...
...
@@ -327,7 +318,7 @@ function send_content_ready($token, $username, $format, $importdata, $fetchnow=f
$queue
->
format
=
$format
;
$class
=
null
;
try
{
$class
=
Import
er
::
class_from_format
(
$format
);
$class
=
Plugin
Import
::
class_from_format
(
$format
);
}
catch
(
Exception
$e
)
{
throw
new
ImportException
(
'Invalid format $format'
);
}
...
...
@@ -352,11 +343,12 @@ function send_content_ready($token, $username, $format, $importdata, $fetchnow=f
update_record
(
'import_queue'
,
$queue
);
$result
=
new
StdClass
;
if
(
$fetchnow
&&
Import
er
::
import_immediately_allowed
())
{
if
(
$fetchnow
&&
Plugin
Import
::
import_immediately_allowed
())
{
// either immediately spawn a curl request to go fetch the file
$importer
=
Import
er
::
create_importer
(
$queue
->
id
,
$queue
);
$importer
=
Plugin
Import
::
create_importer
(
$queue
->
id
,
$queue
);
$importer
->
prepare
();
$importer
->
process
();
$importer
->
cleanup
();
delete_records
(
'import_queue'
,
'id'
,
$queue
->
id
);
$result
->
status
=
true
;
$result
->
type
=
'complete'
;
...
...
htdocs/artefact/blog/export/html/lib.php
0 → 100644
View file @
5a83c883
<?php
/**
* Mahara: Electronic portfolio, weblog, resume builder and social networking
* Copyright (C) 2006-2008 Catalyst IT Ltd (http://www.catalyst.net.nz)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package mahara
* @subpackage artefact-blog-export-html
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006-2008 Catalyst IT Ltd http://catalyst.net.nz
*
*/
defined
(
'INTERNAL'
)
||
die
();
class
HtmlExportBlog
extends
HtmlExportArtefactPlugin
{
private
$blogcount
;
public
function
dump_export_data
()
{
if
(
$blogs
=
get_column
(
'artefact'
,
'id'
,
'owner'
,
$this
->
exporter
->
get
(
'user'
)
->
get
(
'id'
),
'artefacttype'
,
'blog'
))
{
foreach
(
$blogs
as
$blogid
)
{
$blog
=
artefact_instance_from_id
(
$blogid
);
// Create directory for storing the blog
$dirname
=
preg_replace
(
'#[^a-zA-Z0-9_-]+#'
,
'-'
,
$blog
->
get
(
'title'
));
if
(
!
check_dir_exists
(
$this
->
fileroot
.
$dirname
))
{
throw
new
SystemException
(
"Couldn't create blog directory
{
$this
->
fileroot
}{
$dirname
}
"
);
}
$smarty
=
$this
->
exporter
->
get_smarty
(
'../../../'
);
$smarty
->
assign
(
'title'
,
$blog
->
get
(
'title'
));
$rendered
=
$blog
->
render_self
(
array
());
$smarty
->
assign
(
'rendered_blog'
,
$rendered
[
'html'
]);
$content
=
$smarty
->
fetch
(
'export:html/blog:index.tpl'
);
if
(
false
===
file_put_contents
(
$this
->
fileroot
.
$dirname
.
'/index.html'
,
$content
))
{
throw
new
SystemException
(
"Unable to create index.html for blog
$blogid
"
);
}
}
}
$this
->
blogcount
=
count
(
$blogs
);
}
public
function
get_summary
()
{
return
array
(
'title'
=>
'Blogs'
,
'description'
=>
"<p>You have
{
$this
->
blogcount
}
blogs</p>"
,
);
}
public
function
get_summary_weight
()
{
return
10
;
}
}
?>
htdocs/artefact/blog/export/html/theme/default/index.tpl
0 → 100644
View file @
5a83c883
{
include
file
=
"export:html:header.tpl"
}
<h2>
Blog:
{
$title
|
escape
}
</h2>
{
$rendered_blog
}
{
include
file
=
"export:html:footer.tpl"
}
htdocs/artefact/blog/export/leap/lib.php
0 → 100644
View file @
5a83c883
<?php
/**
* Mahara: Electronic portfolio, weblog, resume builder and social networking
* Copyright (C) 2006-2008 Catalyst IT Ltd (http://www.catalyst.net.nz)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package mahara
* @subpackage artefact-blog-export-leap
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006-2008 Catalyst IT Ltd http://catalyst.net.nz
*
*/
defined
(
'INTERNAL'
)
||
die
();
class
LeapExportElementBlogpost
extends
LeapExportElement
{
public
function
add_links
()
{
parent
::
add_links
();
// add on attachments
if
(
!
$attachments
=
$this
->
artefact
->
get_attached_files
())
{
return
;
}
foreach
(
$attachments
as
&
$attachment
)
{
$f
=
artefact_instance_from_id
(
$attachment
->
id
);
$this
->
add_artefact_link
(
$f
,
'has_attachment'
);
}
}
public
function
replace_content_placeholders
(
$content
)
{
$content
=
parent
::
replace_content_placeholders
(
$content
,
'ARTEFACT(DL|VIEW)LINK'
);
return
$content
;
}
public
function
assign_smarty_vars
()
{
parent
::
assign_smarty_vars
();
$this
->
smarty
->
assign
(
'contenttype'
,
'xhtml'
);
}
public
function
get_content
()
{
//$rendered = $this->artefact->render_base(array('icons' => false));
//$rendered = $rendered['html'];
//return $this->replace_content_placeholders(clean_html($rendered));
// Probably need replace content placeholders!
return
clean_html
(
$this
->
artefact
->
get
(
'description'
));
}
public
function
get_categories
()
{
if
(
!
$this
->
artefact
->
get
(
'published'
))
{
return
array
(
array
(
'scheme'
=>
'readiness'
,
'term'
=>
'Unready'
,
)
);
}
return
array
();
}
}
class
LeapExportElementBlog
extends
LeapExportElement
{
public
function
get_leap_type
()
{
return
'selection'
;
}
public
function
get_categories
()
{
return
array
(
array
(
'scheme'
=>
'selection_type'
,
'term'
=>
'Blog'
,
)
);
}
public
function
assign_smarty_vars
()
{
parent
::
assign_smarty_vars
();
$this
->
smarty
->
assign
(
'contenttype'
,
'xhtml'
);
}
public
function
get_content
()
{
return
clean_html
(
$this
->
artefact
->
get
(
'description'
));
}
}
htdocs/artefact/blog/import/leap/lib.php
0 → 100644
View file @
5a83c883
<?php
/**
* Mahara: Electronic portfolio, weblog, resume builder and social networking
* Copyright (C) 2006-2008 Catalyst IT Ltd (http://www.catalyst.net.nz)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package mahara
* @subpackage artefact-blog-import-leap
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006-2008 Catalyst IT Ltd http://catalyst.net.nz
*
*/
defined
(
'INTERNAL'
)
||
die
();
/**
* Implements LEAP2A import of blog related entries into Mahara
*
* For more information about LEAP blog importing, see:
* http://wiki.mahara.org/Developer_Area/Import%2f%2fExport/LEAP_Import/Blog_Artefact_Plugin
*
* TODO:
* - Get entries that feel they're part of the blog, not just entries the blog feels are part of it
* - Import raw ATOM feed entries as blog posts
* - Provide a default strategy for importing anything into a 'miscellaneous' blog
* - Handle importing things that don't have inline entry content into a blogpost
*/
class
LeapImportBlog
extends
LeapImportArtefactPlugin
{
/**
* Import an entry as a blog, with associated blog posts and attachments
*/
const
STRATEGY_IMPORT_AS_BLOG
=
1
;
/**
* Import entry as an simple blog post into a catch-all blog
*/
const
STRATEGY_IMPORT_AS_ENTRY
=
2
;
public
static
function
get_import_strategies_for_entry
(
SimpleXMLElement
$entry
,
PluginImport
$importer
)
{
$strategies
=
array
();
// TODO: when the xpath has an error in it, count(error) == 1 also.. so should check return type
$correctrdftype
=
count
(
$entry
->
xpath
(
'rdf:type['
.
$importer
->
curie_xpath
(
'@rdf:resource'
,
PluginImportLeap
::
NS_LEAPTYPE
,
'selection'
)
.
']'
))
==
1
;
$correctcategoryscheme
=
count
(
$entry
->
xpath
(
'a:category[('
.
$importer
->
curie_xpath
(
'@scheme'
,
PluginImportLeap
::
NS_CATEGORIES
,
'selection_type#'
)
.
') and @term="Blog"]'
))
==
1
;
if
(
$correctrdftype
&&
$correctcategoryscheme
)
{
$otherrequiredentries
=
array
();
// Get entries that this blog feels are a part of it
foreach
(
$entry
->
link
as
$link
)
{
if
(
$importer
->
curie_equals
(
$link
[
'rel'
],
PluginImportLeap
::
NS_LEAP
,
'has_part'
)
&&
isset
(
$link
[
'href'
]))
{
$otherrequiredentries
[]
=
(
string
)
$link
[
'href'
];
}
}
// TODO: Get entries that feel they should be a part of this blog.
// We can compare the lists and perhaps warn if they're different
// $otherentries = $importer->xml->xpath('//a:feed/a:entry/a:link[@rel="leap:is_part_of" and @href="' . $entryid . '"]/../a:id');
$otherrequiredentries
=
array_unique
(
$otherrequiredentries
);
$strategies
[]
=
array
(
'strategy'
=>
self
::
STRATEGY_IMPORT_AS_BLOG
,
'score'
=>
100
,
'other_required_entries'
=>
$otherrequiredentries
,
);
}
else
{
// The blog can import any entry as a literal blog post
$strategies
[]
=
array
(
'strategy'
=>
self
::
STRATEGY_IMPORT_AS_ENTRY
,
'score'
=>
10
,
'other_required_entries'
=>
array
(),
);
}
return
$strategies
;
}
public
static
function
import_using_strategy
(
SimpleXMLElement
$entry
,
PluginImport
$importer
,
$strategy
,
array
$otherentries
)
{
$artefactmapping
=
array
();
switch
(
$strategy
)
{
case
self
::
STRATEGY_IMPORT_AS_BLOG
:
// First, the blog
$blog
=
new
ArtefactTypeBlog
();
$blog
->
set
(
'title'
,
(
string
)
$entry
->
title
);
$blog
->
set
(
'description'
,
PluginImportLeap
::
get_entry_content
(
$entry
,
$importer
));
$blog
->
set
(
'owner'
,
$importer
->
get
(
'usr'
));
if
(
$published
=
strtotime
((
string
)
$entry
->
published
))
{
$blog
->
set
(
'ctime'
,
$published
);
}
if
(
$updated
=
strtotime
((
string
)
$entry
->
updated
))
{
$blog
->
set
(
'mtime'
,
$updated
);
}
$blog
->
set
(
'tags'
,
PluginImportLeap
::
get_entry_tags
(
$entry
));
$blog
->
commit
();
$artefactmapping
[(
string
)
$entry
->
id
]
=
array
(
$blog
->
get
(
'id'
));
// Then, the blog posts
foreach
(
$otherentries
as
$entryid
)
{
$blogentry
=
$importer
->
get_entry_by_id
(
$entryid
);
if
(
!
$blogentry
)
{
// TODO: what to do here? Also - should this be checked here or earlier?
$importer
->
trace
(
"WARNING: Blog
$entry->id
claims to have part
$entryid
which doesn't exist"
);
continue
;
}
$artefactmapping
[
$entryid
]
=
self
::
create_blogpost
(
$blogentry
,
$importer
,
$blog
->
get
(
'id'
));
}
break
;
case
self
::
STRATEGY_IMPORT_AS_ENTRY
:
$blogid
=
self
::
ensure_catchall_blog
(
$importer
);
$artefactmapping
[(
string
)
$entry
->
id
]
=
self
::
create_blogpost
(
$entry
,
$importer
,
$blogid
);
break
;
default
:
throw
new
ImportException
(
$importer
,
'TODO: get_string: unknown strategy chosen for importing entry'
);
}
return
$artefactmapping
;
}
/**
* Attaches files to blog posts
*
* We look at the leap relationships to add attachments. Currently this
* looks explicitly for the has_attachment relationship.
*
* If importing an entry resulted in importing a new file (caused by the
* entry having out-of-line content), we attach that file to the entry.
*/
public
static
function
setup_relationships
(
SimpleXMLElement
$entry
,
PluginImport
$importer
,
$strategy
,
array
$otherentries
)
{
switch
(
$strategy
)
{
case
self
::
STRATEGY_IMPORT_AS_BLOG
:
foreach
(
$otherentries
as
$entryid
)
{
$blogpostentry
=
$importer
->
get_entry_by_id
(
$entryid
);
// Get all attachments this blogpost things are attached to it
// TODO: get all entries that think they're attached to the blogpost.
// I think we can only look for files, Mahara doesn't understand
// attaching something that isn't a file to a blogpost
foreach
(
$blogpostentry
->
link
as
$blogpostlink
)
{
$blogpost
=
null
;
if
(
$importer
->
curie_equals
(
$blogpostlink
[
'rel'
],
PluginImportLeap
::
NS_LEAP
,
'has_attachment'
)
&&
isset
(
$blogpostlink
[
'href'
]))
{
if
(
!
$blogpost
)
{
$artefactids
=
$importer
->
get_artefactids_imported_by_entryid
((
string
)
$blogpostentry
->
id
);
$blogpost
=
new
ArtefactTypeBlogPost
(
$artefactids
[
0
]);
}
$importer
->
trace
(
"Attaching file
$blogpostlink[href]
to blog post
$blogpostentry->id
"
,
PluginImportLeap
::
LOG_LEVEL_VERBOSE
);
$artefactids
=
$importer
->
get_artefactids_imported_by_entryid
((
string
)
$blogpostlink
[
'href'
]);
$blogpost
->
attach_file
(
$artefactids
[
0
]);
}
if
(
$blogpost
)
{
$blogpost
->
commit
();
}
}
self
::
setup_outoflinecontent_relationship
(
$blogpostentry
,
$importer
);
}
break
;
case
self
::
STRATEGY_IMPORT_AS_ENTRY
:
self
::
setup_outoflinecontent_relationship
(
$blogpostentry
,
$importer
);
break
;
default
:
throw
new
ImportException
(
$importer
,
'TODO: get_string: unknown strategy chosen for importing entry'
);
}
}
/**
* Creates a catch-all blog if one doesn't exist already
*
* @param PluginImportLeap $importer The importer
* @return int The artefact ID of the catch-all blog
*/
private
static
function
ensure_catchall_blog
(
PluginImportLeap
$importer
)
{
static
$blogid
=
null
;
if
(
is_null
(
$blogid
))
{
$time
=
time
();
// TODO maybe the importer will get a time field to record time of import
$blog
=
new
ArtefactTypeBlog
();
// TODO: i18n
$title
=
$importer
->
get
(
'xml'
)
->
xpath
(
'//a:feed/a:title'
);
$blog
->
set
(
'title'
,
'Data imported from '
.
(
string
)
$title
[
0
]);
$blog
->
set
(
'description'
,
'Entries imported from a LEAP export, that were not abel to be imported elsewhere'
);
$blog
->
set
(
'owner'
,
$importer
->
get
(
'usr'
));
$blog
->
set
(
'ctime'
,
$time
);
$blog
->
set
(
'mtime'
,
$time
);
$blog
->
commit
();
$blogid
=
$blog
->
get
(
'id'
);
}
return
$blogid
;
}
/**
* 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='
.
$fileid
.
'"'
.
' 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
{
$blogpost
->
set
(
'description'
,
PluginImportLeap
::
get_entry_content
(
$entry
,
$importer
));
}
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
;
}
/**
* Checks to see if a blogpost had out-of-line content, and if it did,
* attaches the generated file to it
*
* @param SimpleXMLElement $entry The entry to check
* @param PluginImportLeap $importer The importer
*/
private
static
function
setup_outoflinecontent_relationship
(
SimpleXMLElement
$entry
,
PluginImportLeap
$importer
)
{
$artefactids
=
$importer
->
get_artefactids_imported_by_entryid
((
string
)
$entry
->
id
);
if
(
count
(
$artefactids
)
==
2
)
{
// In this case, a file was created as a result of
// importing a blog entry with out-of-line content. We
// attach the file to this post.
$blogpost
=
new
ArtefactTypeBlogPost
(
$artefactids
[
0
]);
$blogpost
->
attach_file
(
$artefactids
[
1
]);
$blogpost
->
commit
();
}
}
}
?>