* 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 core * @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 * */ define('INTERNAL', 1); define('JSON', 1); require dirname(dirname(__FILE__)) . '/init.php'; require_once get_config('libroot') . 'view.php'; if (!($data = View::new_token(param_integer('view')))) { json_reply(true, get_string('createviewtokenfailed', 'view')); } json_reply(false, array('message' => null, 'data' => $data));
function newurl_submit(Pieform $form, $values) { global $view, $collection; $viewid = $view->get('id'); if ($collection) { $collection->new_token(); $viewid = reset($collection->get_viewids()); } else { View::new_token($viewid); } redirect('/view/urls.php?id=' . $viewid); }
/** * Submits a view or collection for assessment by a remote service * * @param string $username * @param int $id The ID of the view or collection to be submitted * @param boolean $iscollection Indicates whether it's a view or a collection * @return array An array of data for the web service to consume */ function submit_view_for_assessment($username, $id, $iscollection = false) { global $REMOTEWWWROOT; list($user, $authinstance) = find_remote_user($username, $REMOTEWWWROOT); if (!$user) { return false; } $id = (int) $id; if (!$id) { return false; } require_once 'view.php'; $remotehost = $authinstance->config['wwwroot']; $userid = $user->get('id'); db_begin(); if ($iscollection) { require_once 'collection.php'; $collection = new Collection($id); $title = $collection->get('name'); $description = $collection->get('description'); // Check whether the collection is already submitted if ($collection->is_submitted()) { // If this is already submitted to something else, throw an exception if ($collection->get('submittedgroup') || $collection->get('submittedhost') !== $REMOTEWWWROOT) { throw new CollectionSubmissionException(get_string('collectionalreadysubmitted', 'view')); } // It may have been submitted to a different assignment in the same remote // site, but there's no way we can tell. So we'll just send the access token // back. $access = $collection->get_invisible_token(); } else { $collection->submit(null, $remotehost, $userid); $access = $collection->new_token(false); } // If the collection is empty, $access will be false if (!$access) { throw new CollectionSubmissionException(get_string('cantsubmitemptycollection', 'view')); } } else { $view = new View($id); $title = $view->get('title'); $description = $view->get('description'); if ($view->is_submitted()) { // If this is already submitted to something else, throw an exception if ($view->get('submittedgroup') || $view->get('submittedhost') !== $REMOTEWWWROOT) { throw new ViewSubmissionException(get_string('viewalreadysubmitted', 'view')); } // It may have been submitted to a different assignment in the same remote // site, but there's no way we can tell. So we'll just send the access token // back. $access = View::get_invisible_token($id); } else { View::_db_submit(array($id), null, $remotehost, $userid); $access = View::new_token($id, false); } } $data = array('id' => $id, 'title' => $title, 'description' => $description, 'fullurl' => get_config('wwwroot') . 'view/view.php?mt=' . $access->token, 'url' => '/view/view.php?mt=' . $access->token, 'accesskey' => $access->token); // Provide each artefact plugin the opportunity to handle the remote submission and // provide return data for the webservice caller foreach (plugins_installed('artefact') as $plugin) { safe_require('artefact', $plugin->name); $classname = generate_class_name('artefact', $plugin->name); if (is_callable($classname . '::view_submit_external_data')) { $data[$plugin->name] = call_static_method($classname, 'view_submit_external_data', $id, $iscollection); } } db_commit(); return $data; }
function submit_view_for_assessment($username, $viewid) { global $REMOTEWWWROOT; list($user, $authinstance) = find_remote_user($username, $REMOTEWWWROOT); if (!$user) { return false; } $viewid = (int) $viewid; if (!$viewid) { return false; } require_once 'view.php'; $view = new View($viewid); $view->set('submittedhost', $authinstance->config['wwwroot']); $view->set('submittedtime', db_format_timestamp(time())); // Create secret key $access = View::new_token($view->get('id'), false); $data = array('id' => $view->get('id'), 'title' => $view->get('title'), 'description' => $view->get('description'), 'fullurl' => get_config('wwwroot') . 'view/view.php?id=' . $view->get('id') . '&mt=' . $access->token, 'url' => '/view/view.php?id=' . $view->get('id') . '&mt=' . $access->token, 'accesskey' => $access->token); foreach (plugins_installed('artefact') as $plugin) { safe_require('artefact', $plugin->name); $classname = generate_class_name('artefact', $plugin->name); if (is_callable($classname . '::view_submit_external_data')) { $data[$plugin->name] = call_static_method($classname, 'view_submit_external_data', $view->get('id')); } } $view->commit(); // Lock view contents require_once get_config('docroot') . 'artefact/lib.php'; ArtefactType::update_locked($user->get('id')); return $data; }
/** * Creates a new secret url for this collection * @param int $collectionid * @param false $visible * @return object The view_access record for the first view's secret URL */ public function new_token($visible = 1) { $viewids = $this->get_viewids(); // It's not possible to add a secret key to a collection with no pages if (!$viewids) { return false; } reset($viewids); $access = View::new_token(current($viewids), $visible); while (next($viewids)) { $todb = new stdClass(); $todb->view = current($viewids); $todb->visible = $access->visible; $todb->token = $access->token; $todb->ctime = $access->ctime; insert_record('view_access', $todb); } return $access; }