Commit 9ebfaa4f authored by Penny Leach's avatar Penny Leach
Browse files

Merge commit 'origin/master' into groupforums

Conflicts:

	htdocs/artefact/lib.php
	htdocs/lib/artefact.php
parents 52d4c615 f6161c02
......@@ -40,7 +40,7 @@ class PluginBlocktypeBlog extends PluginBlocktype {
$configdata = $bi->get('configdata');
if (!empty($configdata['artefactid'])) {
require_once(get_config('docroot') . 'lib/artefact.php');
require_once(get_config('docroot') . 'artefact/lib.php');
$blog = artefact_instance_from_id($configdata['artefactid']);
return $blog->get('title');
}
......@@ -60,7 +60,7 @@ class PluginBlocktypeBlog extends PluginBlocktype {
$result = '';
if (!empty($configdata['artefactid'])) {
require_once(get_config('docroot') . 'lib/artefact.php');
require_once(get_config('docroot') . 'artefact/lib.php');
$blog = artefact_instance_from_id($configdata['artefactid']);
$configdata['hidetitle'] = true;
$configdata['viewid'] = $instance->get('view');
......
......@@ -40,7 +40,7 @@ class PluginBlocktypeBlogpost extends PluginBlocktype {
$configdata = $bi->get('configdata');
if (!empty($configdata['artefactid'])) {
require_once(get_config('docroot') . 'lib/artefact.php');
require_once(get_config('docroot') . 'artefact/lib.php');
$blogpost = artefact_instance_from_id($configdata['artefactid']);
return $blogpost->get('title');
}
......@@ -60,7 +60,7 @@ class PluginBlocktypeBlogpost extends PluginBlocktype {
$result = '';
if (!empty($configdata['artefactid'])) {
require_once(get_config('docroot') . 'lib/artefact.php');
require_once(get_config('docroot') . 'artefact/lib.php');
$blogpost = artefact_instance_from_id($configdata['artefactid']);
$configdata['hidetitle'] = true;
$configdata['viewid'] = $instance->get('view');
......
......@@ -491,7 +491,7 @@ class ArtefactTypeBlogPost extends ArtefactType {
$attachments = $this->get_attached_files();
if ($attachments) {
$this->add_to_render_path($options);
require_once('artefact.php');
require_once(get_config('docroot') . 'artefact/lib.php');
foreach ($attachments as &$attachment) {
$f = artefact_instance_from_id($attachment->id);
$attachment->size = $f->describe_size();
......
......@@ -41,7 +41,7 @@ class PluginBlocktypeFiledownload extends PluginBlocktype {
}
public static function render_instance(BlockInstance $instance) {
require_once(get_config('docroot') . 'lib/artefact.php');
require_once(get_config('docroot') . 'artefact/lib.php');
$configdata = $instance->get('configdata');
$result = '';
......
......@@ -41,7 +41,7 @@ class PluginBlocktypeImage extends PluginBlocktype {
}
public static function render_instance(BlockInstance $instance) {
require_once(get_config('docroot') . 'lib/artefact.php');
require_once(get_config('docroot') . 'artefact/lib.php');
$configdata = $instance->get('configdata'); // this will make sure to unserialize it for us
$configdata['viewid'] = $instance->get('view');
......
......@@ -62,7 +62,7 @@ class PluginBlocktypeInternalmedia extends PluginBlocktype {
return '';
}
$result = self::get_js_source();
require_once('artefact.php');
require_once(get_config('docroot') . 'artefact/lib.php');
$artefact = artefact_instance_from_id($configdata['artefactid']);
$width = (!empty($configdata['width'])) ? hsc($configdata['width']) : '300';
$height = (!empty($configdata['height'])) ? hsc($configdata['height']) : '300';
......
......@@ -52,7 +52,7 @@ $data->adminfiles = (int)$adminfiles;
if ($oldid = ArtefactTypeFileBase::file_exists($data->title, $data->owner, $parentfolder, $adminfiles)) {
if ($collideaction == 'replace') {
require_once('artefact.php');
require_once(get_config('docroot') . 'artefact/lib.php');
$obj = artefact_instance_from_id($oldid);
$obj->delete();
}
......
......@@ -70,7 +70,7 @@ function xmldb_artefact_file_upgrade($oldversion=0) {
$images = get_column('artefact', 'id', 'artefacttype', 'image');
log_debug(count($images));
require_once('artefact.php');
require_once(get_config('docroot') . 'artefact/lib.php');
foreach ($images as $imageid) {
$image = artefact_instance_from_id($imageid);
$path = $image->get_path();
......
......@@ -33,7 +33,7 @@ json_headers();
$fileid = param_integer('id');
require_once('artefact.php');
require_once(get_config('docroot') . 'artefact/lib.php');
$artefact = artefact_instance_from_id($fileid);
$artefact->delete();
......
......@@ -28,7 +28,6 @@ define('INTERNAL', 1);
define('PUBLIC', 1);
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
safe_require('artefact', 'file');
require_once('artefact.php');
require_once('file.php');
$fileid = param_integer('file');
......
......@@ -34,7 +34,7 @@ json_headers();
$artefactid = param_integer('artefact'); // Artefact being moved
$newparentid = param_integer('newparent'); // Folder to move it to
require_once('artefact.php');
require_once(get_config('docroot') . 'artefact/lib.php');
$artefact = artefact_instance_from_id($artefactid);
global $USER;
......
......@@ -29,7 +29,6 @@ define('JSON', 1);
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
safe_require('artefact', 'file');
require_once('artefact.php');
json_headers();
......
......@@ -55,7 +55,6 @@ $result->uploadnumber = $uploadnumber;
if ($oldid = ArtefactTypeFileBase::file_exists($title, $data->owner, $parentfolder, $adminfiles)) {
if ($collideaction == 'replace') {
require_once('artefact.php');
$obj = artefact_instance_from_id($oldid);
$obj->delete();
}
......
......@@ -41,7 +41,7 @@ class PluginBlocktypeContactinfo extends PluginBlocktype {
}
public static function render_instance(BlockInstance $instance) {
require_once(get_config('docroot') . 'lib/artefact.php');
require_once(get_config('docroot') . 'artefact/lib.php');
$smarty = smarty_core();
$configdata = $instance->get('configdata');
......@@ -125,6 +125,7 @@ class PluginBlocktypeContactinfo extends PluginBlocktype {
'blocktype' => 'contactinfo',
'limit' => 655360, // 640K profile fields is enough for anyone!
'selectone' => false,
'search' => false,
'artefacttypes' => array_diff(PluginArtefactInternal::get_contactinfo_artefact_types(), array('email')),
'template' => 'artefact:internal:artefactchooser-element.tpl',
);
......
......@@ -41,7 +41,7 @@ class PluginBlocktypeProfileinfo extends PluginBlocktype {
}
public static function render_instance(BlockInstance $instance) {
require_once(get_config('docroot') . 'lib/artefact.php');
require_once(get_config('docroot') . 'artefact/lib.php');
$smarty = smarty_core();
$configdata = $instance->get('configdata');
......@@ -186,6 +186,7 @@ class PluginBlocktypeProfileinfo extends PluginBlocktype {
'blocktype' => 'profileinfo',
'limit' => 655360, // 640K profile fields is enough for anyone!
'selectone' => false,
'search' => false,
'artefacttypes' => array_diff(PluginArtefactInternal::get_artefact_types(), array('profileicon', 'email')),
'template' => 'artefact:internal:artefactchooser-element.tpl',
);
......
......@@ -25,7 +25,6 @@
*/
defined('INTERNAL') || die();
require_once('artefact.php');
/**
* Base artefact plugin class
......@@ -584,4 +583,148 @@ function artefact_check_plugin_sanity($pluginname) {
}
}
function rebuild_artefact_parent_cache_dirty() {
// this will give us a list of artefacts, as the first returned column
// is not unqiue, but that's ok, it's what we want.
if (!$dirty = get_records_array('artefact_parent_cache', 'dirty', 1, '', 'DISTINCT(artefact)')) {
return;
}
db_begin();
delete_records('artefact_parent_cache', 'dirty', 1);
foreach ($dirty as $d) {
$parentids = array();
$current = $d->artefact;
delete_records('artefact_parent_cache', 'artefact', $current);
$parentids = array_keys(artefact_get_parents_for_cache($current));
foreach ($parentids as $p) {
$apc = new StdClass;
$apc->artefact = $d->artefact;
$apc->parent = $p;
$apc->dirty = 0;
insert_record('artefact_parent_cache', $apc);
}
}
db_commit();
}
function rebuild_artefact_parent_cache_complete() {
db_begin();
delete_records('artefact_parent_cache');
if ($artefactids = get_column('artefact', 'id')) {
foreach ($artefactids as $id) {
$parentids = array_keys(artefact_get_parents_for_cache($id));
foreach ($parentids as $p) {
$apc = new StdClass;
$apc->artefact = $id;
$apc->parent = $p;
$apc->dirty = 0;
insert_record('artefact_parent_cache', $apc);
}
}
}
db_commit();
}
function artefact_get_parents_for_cache($artefactid, &$parentids=false) {
static $blogsinstalled;
if (!isset($blogsinstalled)) {
$blogsinstalled = get_field('artefact_installed', 'active', 'name', 'blog');
}
$current = $artefactid;
if (empty($parentids)) { // first call
$parentids = array();
}
while (true) {
if (!$parent = get_record('artefact', 'id', $current)) {
break;
}
// get any blog posts it may be attached to
if (($parent->artefacttype == 'file' || $parent->artefacttype == 'image') && $blogsinstalled
&& $associated = get_column('artefact_blog_blogpost_file', 'blogpost', 'file', $parent->id)) {
foreach ($associated as $a) {
$parentids[$a] = 1;
artefact_get_parents_for_cache($a, $parentids);
}
}
if (!$parent->parent) {
break;
}
$parentids[$parent->parent] = 1;
$current = $parent->parent;
}
return $parentids;
}
function artefact_can_render_to($type, $format) {
return in_array($format, call_static_method(generate_artefact_class_name($type), 'get_render_list'));
}
function artefact_instance_from_id($id) {
$sql = 'SELECT a.*, i.plugin
FROM {artefact} a
JOIN {artefact_installed_type} i ON a.artefacttype = i.name
WHERE a.id = ?';
if (!$data = get_record_sql($sql, array($id))) {
throw new ArtefactNotFoundException(get_string('artefactnotfound', 'mahara', $id));
}
$classname = generate_artefact_class_name($data->artefacttype);
safe_require('artefact', $data->plugin);
return new $classname($id, $data);
}
/**
* This function will return an instance of any "0 or 1" artefact. That is any
* artefact that each user will have at most one instance of (e.g. profile
* fields).
*
* @param string Is the type of artefact to return
* @param string The user_id who owns the fetched artefact. (defaults to the
* current user)
*
* @returns ArtefactType Instance of the artefact.
*/
function artefact_instance_from_type($artefact_type, $user_id=null) {
global $USER;
if ($user_id === null) {
$user_id = $USER->get('id');
}
safe_require('artefact', get_field('artefact_installed_type', 'plugin', 'name', $artefact_type));
if (!call_static_method(generate_artefact_class_name($artefact_type), 'is_singular')) {
throw new ArtefactNotFoundException("This artefact type is not a 'singular' artefact type");
}
// email is special (as in the user can have more than one of them, but
// it's treated as a 0 or 1 artefact and the primary is returned
if ($artefact_type == 'email') {
$id = get_field('artefact_internal_profile_email', 'artefact', 'owner', $user_id, 'principal', 1);
if (!$id) {
throw new ArtefactNotFoundException("Artefact of type '${artefact_type}' doesn't exist");
}
$classname = generate_artefact_class_name($artefact_type);
safe_require('artefact', 'internal');
return new $classname($id);
}
else {
$sql = 'SELECT a.*, i.plugin
FROM {artefact} a
JOIN {artefact_installed_type} i ON a.artefacttype = i.name
WHERE a.artefacttype = ? AND a.owner = ?';
if (!$data = get_record_sql($sql, array($artefact_type, $user_id))) {
throw new ArtefactNotFoundException("Artefact of type '${artefact_type}' doesn't exist");
}
$classname = generate_artefact_class_name($artefact_type);
safe_require('artefact', $data->plugin);
return new $classname($data->id, $data);
}
throw new ArtefactNotFoundException("Artefact of type '${artefact_type}' doesn't exist");
}
?>
......@@ -41,7 +41,7 @@ class PluginBlocktypeResumefield extends PluginBlocktype {
}
public static function render_instance(BlockInstance $instance) {
require_once(get_config('docroot') . 'lib/artefact.php');
require_once(get_config('docroot') . 'artefact/lib.php');
$smarty = smarty_core();
$configdata = $instance->get('configdata');
$configdata['viewid'] = $instance->get('view');
......@@ -94,6 +94,7 @@ class PluginBlocktypeResumefield extends PluginBlocktype {
'blocktype' => 'resumefield',
'limit' => 655360, // 640K profile fields is enough for anyone!
'selectone' => true,
'search' => false,
'artefacttypes' => PluginArtefactResume::get_artefact_types(),
'template' => 'artefact:resume:artefactchooser-element.tpl',
);
......
......@@ -28,7 +28,7 @@ define('INTERNAL', 1);
define('JSON', 1);
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
require('artefact.php');
require_once(get_config('docroot') . 'artefact/lib.php');
$id = param_integer('id');
$artefact = param_integer('artefact');
......
......@@ -30,7 +30,7 @@ define('MENUITEM', 'profile/myresume');
require_once(dirname(dirname(dirname(__FILE__))) . '/init.php');
require_once('pieforms/pieform.php');
require_once('pieforms/pieform/elements/calendar.php');
require('artefact.php');
require_once(get_config('docroot') . 'artefact/lib.php');
$id = param_integer('id');
$artefact = param_integer('artefact');
......
......@@ -32,7 +32,7 @@ define('SECTION_PAGE', 'goals');
require_once(dirname(dirname(dirname(__FILE__))) . '/init.php');
require_once('pieforms/pieform.php');
require('artefact.php');
require_once(get_config('docroot') . 'artefact/lib.php');
$personal = null;
$academic = null;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment