Commit 13fc2089 authored by Cecilia Vela Gurovic's avatar Cecilia Vela Gurovic

Bug 1520028: Add portfolio links in TinyMCE link plugin

Added a field in the 'link' plugin to add a URL to a selected personal page or collection. This is only available in a personal portfolio area, but not a group, site, or institution area. Removed from annotation.js duplicated function already defined in mahara.js behatnotneeded Change-Id: Iccf4c4ca08e142bfd77ab824217cbee5dc35a7bd
parent c06a3565
......@@ -8,21 +8,7 @@
* @copyright For copyright information on Mahara, please see the README file distributed with this software.
*/
/**
* Return the specified request variable from the URL.
* This should be moved to mahara.js to everyone can use it.
*/
function getURLParameter(variable) {
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i = 0; i < vars.length; i++) {
var pair = vars[i].split("=");
if (pair[0] == variable) {
return pair[1];
}
}
return false;
}
function isTinyMceUsed(elementname) {
return (tinyMCE !== undefined && tinyMCE.get(elementname) !== undefined);
......@@ -38,8 +24,8 @@ function initTinyMCE(formname){
function modifyAnnotationFeedbackSuccess(form, data) {
var formname = form.name;
var limit = getURLParameter('limit');
var offset = getURLParameter('offset');
var limit = getUrlParameter('limit');
var offset = getUrlParameter('offset');
if (limit === false && offset === false) {
// Pagination is not used.
......@@ -81,8 +67,8 @@ function modifyAnnotationFeedbackSuccess(form, data) {
function addAnnotationFeedbackSuccess(form, data) {
var formname = form.name;
var blockid = jQuery('#' + formname + '_blockid').val();
var limit = getURLParameter('limit');
var offset = getURLParameter('offset');
var limit = getUrlParameter('limit');
var offset = getUrlParameter('offset');
var tinymce = jQuery('#' + form.id + '_message');
if (limit === false && offset === false) {
......
......@@ -39,6 +39,7 @@ if ($id = param_integer('id', null)) {
}
else {
define('TITLE', get_string('creategroup', 'group'));
define('CREATEGROUP', true);
if (!group_can_create_groups()) {
throw new AccessDeniedException(get_string('accessdenied', 'error'));
......
......@@ -9,6 +9,8 @@
*
*/
// Expects strings array
function get_string(name) {
// Flatten the arguments in case string parameters were passed as an array
......
<?php
/**
*
* @package mahara
* @subpackage core
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later
* @copyright For copyright information on Mahara, please see the README file distributed with this software.
*
*/
define('INTERNAL', 1);
define('JSON', 1);
require(dirname(dirname(__FILE__)) . '/init.php');
global $USER;
require_once(get_config('libroot') . 'view.php');
$viewid = param_integer('viewid', null);
$linklist= array();
list($collections, $views) = View::get_views_and_collections( $USER->get('id'));
if (!empty($views) || !empty($collections)) {
foreach ($views as $view) {
if ($viewid != $view['id']) { // dont list the current view
$linklist[] = array(
'title' => $view['name'],
'value' => $view['url'],
);
}
}
foreach ($collections as $collection) {
$collectionitem = array();
if (!isset($collection['views'][$viewid])) { // dont list the collection that contains the current view
$collectionitem['title'] = $collection['name'];
usort($collection['views'], function($a, $b) {return $a['displayorder'] > $b['displayorder'];});
foreach ($collection['views'] as $view) {
if ($viewid != $view['id']) {
$collectionitem['menu'][] = array(
'title' => $view['name'],
'value' => $view['url'],
);
}
}
$linklist[] = $collectionitem;
}
}
}
usort($linklist, function($a, $b) {
return strnatcasecmp($a['title'], $b['title']);
});
json_reply(false, array('data' => json_encode($linklist), 'count' => count($linklist)));
......@@ -6347,7 +6347,8 @@ class View {
db_format_tsfield('v.submittedtime', 'submittedtime') . ", v.submittedstatus,
c.id AS cid, c.name AS cname, c.framework,
c.submittedgroup AS csubmitgroup, c.submittedhost AS csubmithost, " .
db_format_tsfield('c.submittedtime', 'csubmittime') . ", c.submittedstatus AS csubmitstatus
db_format_tsfield('c.submittedtime', 'csubmittime') . ", c.submittedstatus AS csubmitstatus,
cv.displayorder
FROM {view} v
LEFT JOIN {collection_view} cv ON v.id = cv.view
LEFT JOIN {collection} c ON cv.collection = c.id
......@@ -6403,6 +6404,7 @@ class View {
'submittedhost' => $r['submittedhost'],
'submittedtime' => $r['submittedtime'],
'submittedstatus' => $r['submittedstatus'],
'displayorder' => $r['displayorder'],
);
if (isset($r['user'])) {
$v['ownername'] = display_name($r['user']);
......
......@@ -112,6 +112,15 @@ function get_stylesheets_for_current_page($stylesheets, $extraconfig) {
return $stylesheets;
}
/**
* True if we are not in admin, institution or admin section
*/
function user_personal_section() {
$usersection = !defined('ADMIN') && !defined('STAFF') && !defined('INSTITUTIONALADMIN') &&
!defined('INSTITUTIONALSTAFF') && !defined('GROUP') && !defined('CREATEGROUP');
return $usersection ? 1 : 0;
}
/**
* This function creates a Smarty object and sets it up for use within our
......@@ -141,7 +150,7 @@ function get_stylesheets_for_current_page($stylesheets, $extraconfig) {
function smarty($javascript = array(), $headers = array(), $pagestrings = array(), $extraconfig = array()) {
global $USER, $SESSION, $THEME, $HEADDATA, $langselectform, $CFG;
global $USER, $SESSION, $THEME, $HEADDATA, $langselectform, $CFG, $viewid;
if (!is_array($headers)) {
$headers = array();
......@@ -217,6 +226,15 @@ function smarty($javascript = array(), $headers = array(), $pagestrings = array(
if (is_html_editor_enabled()) {
$checkarray = array(&$javascript, &$headers);
$found_tinymce = false;
$tinymceviewid = 'null';
if ($inpersonalarea = user_personal_section()) {
if (defined('SECTION_PAGE') && (SECTION_PAGE == 'view' || SECTION_PAGE == 'blocks' || SECTION_PAGE == 'editlayout')) {
if (isset($viewid) && $viewid > 0) {
$tinymceviewid = $viewid;
}
}
}
foreach ($checkarray as &$check) {
if (($key = array_search('tinymce', $check)) !== false || ($key = array_search('tinytinymce', $check)) !== false) {
if (!$found_tinymce) {
......@@ -327,6 +345,26 @@ tinyMCE.init({
remove_script_host: false,
relative_urls: false,
target_list: false,
link_list: function(success) {
// Only show the list of links in the normal user section
if ({$inpersonalarea}) {
var params = {
'viewid': {$tinymceviewid}
}
sendjsonrequest(config['wwwroot'] + 'json/tinymceviewlist.json.php', params, 'POST', function(data) {
if (data.count > 0) {
success(JSON.parse(data.data));
}
else {
success(''); // stop showing list with only option being 'none'
}
});
}
else {
success(''); // stop showing list with only option being 'none'
}
},
cache_suffix: '?v={$CFG->cacheversion}',
{$extramceconfig}
setup: function(ed) {
......
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