Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
mahara
mahara
Commits
575d9267
Commit
575d9267
authored
Jul 15, 2016
by
Robert Lyon
Committed by
Gerrit Code Review
Jul 15, 2016
Browse files
Merge "Fixing issues in embedded images in copied pages"
parents
33cb4217
4ff6350b
Changes
6
Hide whitespace changes
Inline
Side-by-side
htdocs/artefact/blog/db/upgrade.php
View file @
575d9267
...
...
@@ -59,5 +59,26 @@ function xmldb_artefact_blog_upgrade($oldversion=0) {
delete_records
(
'institution_config'
,
'field'
,
'progressbaritem_blog_blog'
);
}
if
(
$oldversion
<
2015082600
)
{
$records
=
get_records_select_array
(
'artefact'
,
"artefacttype = ? AND description LIKE '%artefact/file/download.php%'"
,
array
(
'blogpost'
),
'id'
,
'id, description, author'
);
if
(
$records
)
{
require_once
(
'embeddedimage.php'
);
foreach
(
$records
as
$rec
)
{
set_field
(
'artefact'
,
'description'
,
EmbeddedImage
::
prepare_embedded_images
(
$rec
->
description
,
'blogpost'
,
$rec
->
id
,
null
,
$rec
->
author
),
'id'
,
$rec
->
id
);
}
}
}
return
true
;
}
htdocs/artefact/blog/lib.php
View file @
575d9267
...
...
@@ -574,8 +574,8 @@ class ArtefactTypeBlog extends ArtefactType {
foreach
(
$artefactcopies
[
$oldid
]
->
oldembeds
as
$a
)
{
if
(
isset
(
$artefactcopies
[
$a
]))
{
// Change the old image id to the new one
$regexp
[]
=
'#<img([^>]+)src="'
.
get_config
(
'wwwroot'
)
.
'artefact/file/download.php\?file='
.
$a
.
'(
&|&)embedded=1(.*?"[^>]+
)#'
;
$replacetext
[]
=
'<img$1src="'
.
get_config
(
'wwwroot'
)
.
'artefact/file/download.php?file='
.
$artefactcopies
[
$a
]
->
newid
.
'$2
embedded=1$3
'
;
$regexp
[]
=
'#<img([^>]+)src="'
.
get_config
(
'wwwroot'
)
.
'artefact/file/download.php\?file='
.
$a
.
'(
[^0-9]
)#'
;
$replacetext
[]
=
'<img$1src="'
.
get_config
(
'wwwroot'
)
.
'artefact/file/download.php?file='
.
$artefactcopies
[
$a
]
->
newid
.
'$2'
;
}
}
require_once
(
'embeddedimage.php'
);
...
...
@@ -1226,8 +1226,8 @@ class ArtefactTypeBlogPost extends ArtefactType {
foreach
(
$artefactcopies
[
$oldid
]
->
oldembeds
as
$a
)
{
if
(
isset
(
$artefactcopies
[
$a
]))
{
// Change the old image id to the new one
$regexp
[]
=
'#<img([^>]+)src="'
.
get_config
(
'wwwroot'
)
.
'artefact/file/download.php\?file='
.
$a
.
'(
&|&)embedded=1(.*?"[^>]+
)#'
;
$replacetext
[]
=
'<img$1src="'
.
get_config
(
'wwwroot'
)
.
'artefact/file/download.php?file='
.
$artefactcopies
[
$a
]
->
newid
.
'$2
embedded=1$3
'
;
$regexp
[]
=
'#<img([^>]+)src="'
.
get_config
(
'wwwroot'
)
.
'artefact/file/download.php\?file='
.
$a
.
'(
[^0-9]
)#'
;
$replacetext
[]
=
'<img$1src="'
.
get_config
(
'wwwroot'
)
.
'artefact/file/download.php?file='
.
$artefactcopies
[
$a
]
->
newid
.
'$2'
;
}
}
require_once
(
'embeddedimage.php'
);
...
...
htdocs/artefact/blog/version.php
View file @
575d9267
...
...
@@ -12,5 +12,5 @@
defined
(
'INTERNAL'
)
||
die
();
$config
=
new
StdClass
;
$config
->
version
=
20150
115
00
;
$config
->
release
=
'1.
1.1
'
;
$config
->
version
=
20150
826
00
;
$config
->
release
=
'1.
2.0
'
;
htdocs/artefact/internal/lib.php
View file @
575d9267
...
...
@@ -924,8 +924,8 @@ class ArtefactTypeHtml extends ArtefactType {
foreach
(
$artefactcopies
[
$oldid
]
->
oldembeds
as
$a
)
{
if
(
isset
(
$artefactcopies
[
$a
]))
{
// Change the old image id to the new one
$regexp
[]
=
'#<img([^>]+)src="'
.
get_config
(
'wwwroot'
)
.
'artefact/file/download.php\?file='
.
$a
.
'(
&|&)embedded=1(.*?"[^>]+
)#'
;
$replacetext
[]
=
'<img$1src="'
.
get_config
(
'wwwroot'
)
.
'artefact/file/download.php?file='
.
$artefactcopies
[
$a
]
->
newid
.
'$2
embedded=1$3
'
;
$regexp
[]
=
'#<img([^>]+)src="'
.
get_config
(
'wwwroot'
)
.
'artefact/file/download.php\?file='
.
$a
.
'(
[^0-9]
)#'
;
$replacetext
[]
=
'<img$1src="'
.
get_config
(
'wwwroot'
)
.
'artefact/file/download.php?file='
.
$artefactcopies
[
$a
]
->
newid
.
'$2'
;
}
}
require_once
(
'embeddedimage.php'
);
...
...
htdocs/blocktype/text/lib.php
View file @
575d9267
...
...
@@ -313,16 +313,8 @@ class PluginBlocktypeText extends MaharaCoreBlocktype {
$replacetext
=
array
();
foreach
(
$artefactcopies
as
$copyobj
)
{
// Change the old image id to the new one
$regexp
[]
=
'#<img([^>]+)src=("|\\")'
.
preg_quote
(
get_config
(
'wwwroot'
)
.
'artefact/file/download.php?file='
.
$copyobj
->
oldid
)
.
'(&|&)embedded=1([^"]*)"#'
;
$replacetext
[]
=
'<img$1src="'
.
get_config
(
'wwwroot'
)
.
'artefact/file/download.php?file='
.
$copyobj
->
newid
.
'&embedded=1"'
;
$regexp
[]
=
'#<img([^>]+)src="'
.
get_config
(
'wwwroot'
)
.
'artefact/file/download.php\?file='
.
$copyobj
->
oldid
.
'([^0-9])#'
;
$replacetext
[]
=
'<img$1src="'
.
get_config
(
'wwwroot'
)
.
'artefact/file/download.php?file='
.
$copyobj
->
newid
.
'$2'
;
}
$configdata
[
'text'
]
=
preg_replace
(
$regexp
,
$replacetext
,
$configdata
[
'text'
]);
return
$configdata
;
...
...
htdocs/lib/embeddedimage.php
View file @
575d9267
...
...
@@ -27,15 +27,30 @@ class EmbeddedImage {
* @param string $resourcetype The type of resource which the TinyMCE editor is used in, e.g. 'forum', 'topic', 'post' for forum text boxes
* @param int $resourceid The id of the resourcetype
* @param int $groupid The id of the group the resource is in if applicable
* @param int $userid The user trying to embed the image (current user if null)
* @return string The updated $fieldvalue
*/
public
static
function
prepare_embedded_images
(
$fieldvalue
,
$resourcetype
,
$resourceid
,
$groupid
=
NULL
)
{
public
static
function
prepare_embedded_images
(
$fieldvalue
,
$resourcetype
,
$resourceid
,
$groupid
=
NULL
,
$userid
=
NULL
)
{
if
(
empty
(
$fieldvalue
)
||
empty
(
$resourcetype
)
||
empty
(
$resourceid
))
{
return
$fieldvalue
;
}
global
$USER
;
if
(
$userid
==
null
)
{
$user
=
$USER
;
}
else
{
$user
=
new
User
();
try
{
$user
->
find_by_id
(
$userid
);
}
catch
(
AuthUnknownUserException
$e
)
{
log_warn
(
'No user found with ID '
.
$userid
);
return
$fieldvalue
;
}
}
$dom
=
new
DOMDocument
();
$dom
->
encoding
=
'utf-8'
;
$oldval
=
libxml_use_internal_errors
(
true
);
...
...
@@ -63,7 +78,7 @@ class EmbeddedImage {
foreach
(
$matches
[
1
]
as
$imgid
)
{
$file
=
artefact_instance_from_id
(
$imgid
);
if
(
!
(
$file
instanceof
ArtefactTypeImage
)
||
!
$
USER
->
can_publish_artefact
(
$file
)
||
!
$
user
->
can_publish_artefact
(
$file
)
)
{
return
$fieldvalue
;
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment