/** * Delete comment * * @return void */ protected function _deleteComment() { // Check permission if (!$this->model->access('content')) { App::abort(403, Lang::txt('ALERTNOTAUTH')); } // Incoming $cid = Request::getInt('cid', 0); // Instantiate comment $objC = new \Components\Projects\Tables\Comment($this->_database); if ($objC->load($cid)) { $activityid = $objC->activityid; // delete comment if ($objC->deleteComment()) { $this->_msg = Lang::txt('PLG_PROJECTS_BLOG_COMMENT_DELETED'); } // delete associated activity $objAA = $this->model->table('Activity'); if ($activityid && $objAA->load($activityid)) { $objAA->deleteActivity(); } } // Pass error or success message if ($this->getError()) { Notify::message($this->getError(), 'error', 'projects'); } elseif (!empty($this->_msg)) { Notify::message($this->_msg, 'success', 'projects'); } // Redirect App::redirect(Route::url($this->model->link())); }
/** * List/unlist on public project page * * @return string */ protected function _list() { // Incoming $id = trim(Request::getInt('p', 0)); // Load requested page $page = $this->note->page($id); if (!$page->get('id')) { App::redirect(Route::url($this->model->link('notes'))); return; } $listed = $this->_task == 'publist' ? 1 : 0; // Get/update public stamp for page if ($this->note->getPublicStamp($page->get('id'), true, $listed)) { $this->_msg = $this->_task == 'publist' ? Lang::txt('COM_PROJECTS_NOTE_MSG_LISTED') : Lang::txt('COM_PROJECTS_NOTE_MSG_UNLISTED'); \Notify::message($this->_msg, 'success', 'projects'); App::redirect(Route::url('index.php?option=' . $this->_option . '&scope=' . $page->get('scope') . '&pagename=' . $page->get('pagename'))); return; } App::redirect(Route::url($this->model->link('notes'))); return; }
/** * Set notifications * * @param string $message * @param string $type * @return void */ public function setNotification($message, $type = 'success') { // If message is set push to notifications if ($message != '') { \Notify::message($message, $type, $this->_option); } }
/** * Save comment * * @return void, redirect */ protected function _saveComment() { // Check for request forgeries Request::checkToken(); // Check permission if (!$this->model->access('content')) { throw new Exception(Lang::txt('ALERTNOTAUTH'), 403); return; } // Incoming $itemid = Request::getInt('itemid', 0, 'post'); $comment = trim(Request::getVar('comment', '', 'post')); $parent_activity = Request::getInt('parent_activity', 0, 'post'); // Clean-up $comment = \Hubzero\Utility\Sanitize::stripScripts($comment); $comment = \Hubzero\Utility\Sanitize::stripImages($comment); $comment = \Hubzero\Utility\String::truncate($comment, 800); // Instantiate comment $objC = new \Components\Projects\Tables\Comment($this->_database); if ($comment) { $objC->itemid = $itemid; $objC->tbl = 'todo'; $objC->parent_activity = $parent_activity; $objC->comment = $comment; $objC->created = Date::toSql(); $objC->created_by = $this->_uid; if (!$objC->store()) { $this->setError($objC->getError()); } else { $this->_msg = Lang::txt('PLG_PROJECTS_TODO_COMMENT_POSTED'); } // Get new entry ID if (!$objC->id) { $objC->checkin(); } // Record activity if ($objC->id) { $what = Lang::txt('COM_PROJECTS_TODO_ITEM'); $url = Route::url($this->model->link('todo') . '&action=view&todoid=' . $itemid); $aid = $this->model->recordActivity(Lang::txt('COM_PROJECTS_COMMENTED') . ' ' . Lang::txt('COM_PROJECTS_ON') . ' ' . $what, $objC->id, $what, $url, 'quote', 0); } // Store activity ID if ($aid) { $objC->activityid = $aid; $objC->store(); } } // Pass error or success message if ($this->getError()) { \Notify::message($this->getError(), 'error', 'projects'); } elseif (!empty($this->_msg)) { \Notify::message($this->_msg, 'success', 'projects'); } // Redirect App::redirect(Route::url($this->model->link('todo') . '&action=view&todoid=' . $itemid)); return; }
/** * Unpublish version/delete draft * * @return string */ public function cancelDraft() { // Incoming $pid = $this->_pid ? $this->_pid : Request::getInt('pid', 0); $confirm = Request::getInt('confirm', 0); $version = Request::getVar('version', 'default'); $ajax = Request::getInt('ajax', 0); // Check permission if (!$this->model->access('content')) { throw new Exception(Lang::txt('ALERTNOTAUTH'), 403); return; } // Load publication model $pub = new \Components\Publications\Models\Publication($pid, $version); if (!$pub->exists() || !$pub->belongsToProject($this->model->get('id'))) { throw new Exception(Lang::txt('PLG_PROJECTS_PUBLICATIONS_PUBLICATION_VERSION_NOT_FOUND'), 404); return; } // Save version ID $vid = $pub->version->get('id'); // Append breadcrumbs if (!$ajax) { Pathway::append(stripslashes($pub->version->get('title')), $pub->link('edit')); } $baseUrl = Route::url($pub->link('editbase')); $baseEdit = Route::url($pub->link('edit')); // Can only unpublish published version or delete a draft if ($pub->version->get('state') != 1 && $pub->version->get('state') != 3 && $pub->version->get('state') != 4) { $this->setError(Lang::txt('PLG_PROJECTS_PUBLICATIONS_CANT_DELETE')); } // Unpublish/delete version if ($confirm) { if (!$this->getError()) { $pubtitle = \Hubzero\Utility\String::truncate($pub->version->get('title'), 100); if ($pub->version->get('state') == 1) { // Unpublish published version $pub->version->set('published_down', Date::toSql()); $pub->version->set('modified', Date::toSql()); $pub->version->set('modified_by', $this->_uid); $pub->version->set('state', 0); if (!$pub->version->store()) { throw new Exception(Lang::txt('PLG_PROJECTS_PUBLICATIONS_PUBLICATION_UNPUBLISH_FAILED'), 403); return; } else { $this->_msg = Lang::txt('PLG_PROJECTS_PUBLICATIONS_PUBLICATION_VERSION_UNPUBLISHED'); // Add activity $action = Lang::txt('PLG_PROJECTS_PUBLICATIONS_ACTIVITY_UNPUBLISHED'); $action .= ' ' . strtolower(Lang::txt('version')) . ' ' . $pub->version->get('version_label') . ' ' . Lang::txt('PLG_PROJECTS_PUBLICATIONS_OF') . ' ' . strtolower(Lang::txt('publication')) . ' "' . $pubtitle . '" '; $aid = $this->model->recordActivity($action, $pid, $pubtitle, Route::url($pub->link('editversion')), 'publication', 0); } } elseif ($pub->version->get('state') == 3 || $pub->version->get('state') == 4) { $vlabel = $pub->version->get('version_label'); // Delete draft version if (!$pub->version->delete()) { throw new Exception(Lang::txt('PLG_PROJECTS_PUBLICATIONS_PUBLICATION_DELETE_DRAFT_FAILED'), 403); return; } // Delete authors $pa = new \Components\Publications\Tables\Author($this->_database); $authors = $pa->deleteAssociations($vid); // Delete attachments $pContent = new \Components\Publications\Tables\Attachment($this->_database); $pContent->deleteAttachments($vid); // Delete screenshots $pScreenshot = new \Components\Publications\Tables\Screenshot($this->_database); $pScreenshot->deleteScreenshots($vid); // Build publication path $path = PATH_APP . DS . trim($this->_pubconfig->get('webpath'), DS) . DS . \Hubzero\Utility\String::pad($pid); // Build version path $vPath = $path . DS . \Hubzero\Utility\String::pad($vid); // Delete all version files if (is_dir($vPath)) { Filesystem::deleteDirectory($vPath); } // Delete access accosiations $pAccess = new \Components\Publications\Tables\Access($this->_database); $pAccess->deleteGroups($vid); // Delete audience $pAudience = new \Components\Publications\Tables\Audience($this->_database); $pAudience->deleteAudience($vid); // Delete publication existence if ($pub->versionCount() == 0) { // Delete all files if (is_dir($path)) { Filesystem::delete($path); } $pub->publication->delete($pid); $pub->publication->deleteExistence($pid); // Delete related publishing activity from feed $objAA = $this->model->table('Activity'); $objAA->deleteActivityByReference($this->model->get('id'), $pid, 'publication'); } // Add activity $action = Lang::txt('PLG_PROJECTS_PUBLICATIONS_ACTIVITY_DRAFT_DELETED'); $action .= ' ' . $vlabel . ' '; $action .= Lang::txt('PLG_PROJECTS_PUBLICATIONS_OF_PUBLICATION') . ' "' . $pubtitle . '"'; $aid = $this->model->recordActivity($action, $pid, '', '', 'publication', 0); $this->_msg = Lang::txt('PLG_PROJECTS_PUBLICATIONS_PUBLICATION_DRAFT_DELETED'); } } } else { $view = new \Hubzero\Plugin\View(array('folder' => 'projects', 'element' => 'publications', 'name' => 'cancel')); // Output HTML $view->option = $this->_option; $view->database = $this->_database; $view->project = $this->model; $view->uid = $this->_uid; $view->pid = $pid; $view->pub = $pub; $view->publishedCount = $pub->version->getPublishedCount($pid); $view->task = $this->_task; $view->config = $this->model->config(); $view->pubconfig = $this->_pubconfig; $view->ajax = $ajax; $view->title = $this->_area['title']; // Get messages and errors $view->msg = $this->_msg; if ($this->getError()) { $view->setError($this->getError()); } return $view->loadTemplate(); } // Pass error or success message if ($this->getError()) { \Notify::message($this->getError(), 'error', 'projects'); } elseif (!empty($this->_msg)) { \Notify::message($this->_msg, 'success', 'projects'); } App::redirect($baseUrl); return; }
/** * Update database * * @return array */ public function act_update() { // Check permission if (!$this->model->access('content')) { throw new Exception(Lang::txt('ALERTNOTAUTH'), 403); return; } // Incoming $id = Request::getVar('db_id', false); $title = Request::getVar('db_title', false); $description = Request::getVar('db_description', false); // Get project database object $objPD = new \Components\Projects\Tables\Database($this->_database); if ($objPD->loadRecord($id)) { $dd = json_decode($objPD->data_definition, true); if ($title != '' && $objPD->project == $this->model->get('id')) { // Setting title and description $objPD->title = $title; $dd['title'] = $title; $objPD->description = $description; $objPD->data_definition = json_encode($dd); $objPD->store(); $this->_msg = Lang::txt('PLG_PROJECTS_DATABASES_UPDATED'); } } $url = str_replace($_SERVER['SCRIPT_URL'], '', $_SERVER['SCRIPT_URI']) . "/projects/" . $this->model->get('alias') . "/databases/"; // Pass success message if (!empty($this->_msg)) { \Notify::message($this->_msg, 'success', 'projects'); } // Redirect App::redirect($url); return; }
/** * red method * * Shortcut for sending an error message * * @param mixed $fails * @param mixed $params * @return void * @access public */ static function red($fails, $params) { list($title, $message) = Notify::_normalize($params); Notify::message($title, $message, -2, 'error'); }
/** * Subscribe * * @return HTML */ private function _save() { // Check for request forgeries Request::checkToken(); // Login required if (User::isGuest() || !$this->project->exists()) { App::redirect(Route::url($this->publication->link())); } // Incoming $email = User::get('email'); $categories = Request::getVar('category', array()); $frequency = Request::getWord('frequency', 'immediate'); // Save subscription $this->watch->loadRecord($this->project->get('id'), 'project', User::get('id'), $email); $this->watch->item_id = $this->project->get('id'); $this->watch->item_type = 'project'; $this->watch->created_by = User::get('id'); $this->watch->state = empty($categories) ? 2 : 1; $cats = array('blog' => 0, 'quote' => 0, 'team' => 0, 'files' => 0, 'publications' => 0, 'todo' => 0, 'notes' => 0); $in = ''; foreach ($cats as $param => $value) { if (isset($categories[$param])) { $value = intval($categories[$param]); } if ($param == 'quote' && isset($categories['blog'])) { $value = 1; } $in .= $in ? "\n" : ''; $in .= $param . '=' . $value; } $this->watch->params = $in; if ($this->watch->check()) { $this->watch->store(); } if ($this->watch->getError()) { App::redirect(Route::url($this->project->link()), $this->watch->getError(), 'error'); } else { \Notify::message(Lang::txt('PLG_PROJECTS_WATCH_SUCCESS_SAVED'), 'success', 'projects'); App::redirect(Route::url($this->project->link())); } }
/** * Saves a project * Redirects to main listing * * @return void */ public function saveTask($redirect = false) { // Check for request forgeries Request::checkToken(); // Config $setup_complete = $this->config->get('confirm_step', 0) ? 3 : 2; // Incoming $formdata = $_POST; $id = Request::getVar('id', 0); $action = Request::getVar('admin_action', ''); $message = rtrim(\Hubzero\Utility\Sanitize::clean(Request::getVar('message', ''))); // Load model $model = new Models\Project($id); if (!$model->exists()) { App::redirect('index.php?option=' . $this->_option, Lang::txt('COM_PROJECTS_NOTICE_ID_NOT_FOUND'), 'error'); return; } $title = $formdata['title'] ? rtrim($formdata['title']) : $model->get('title'); $type = isset($formdata['type']) ? $formdata['type'] : 1; $model->set('title', $title); $model->set('about', rtrim(\Hubzero\Utility\Sanitize::clean($formdata['about']))); $model->set('type', $type); $model->set('modified', Date::toSql()); $model->set('modified_by', User::get('id')); $model->set('private', Request::getVar('private', 0)); $this->_message = Lang::txt('COM_PROJECTS_SUCCESS_SAVED'); // Was project suspended? $suspended = false; if ($model->isInactive()) { $suspended = $model->table('Activity')->checkActivity($id, Lang::txt('COM_PROJECTS_ACTIVITY_PROJECT_SUSPENDED')); } $subject = Lang::txt('COM_PROJECTS_PROJECT') . ' "' . $model->get('alias') . '" '; $sendmail = 0; // Get project managers $managers = $model->table('Owner')->getIds($id, 1, 1); // Admin actions if ($action) { switch ($action) { case 'delete': $model->set('state', 2); $what = Lang::txt('COM_PROJECTS_ACTIVITY_PROJECT_DELETED'); $subject .= Lang::txt('COM_PROJECTS_MSG_ADMIN_DELETED'); $this->_message = Lang::txt('COM_PROJECTS_SUCCESS_DELETED'); break; case 'suspend': $model->set('state', 0); $what = Lang::txt('COM_PROJECTS_ACTIVITY_PROJECT_SUSPENDED'); $subject .= Lang::txt('COM_PROJECTS_MSG_ADMIN_SUSPENDED'); $this->_message = Lang::txt('COM_PROJECTS_SUCCESS_SUSPENDED'); break; case 'reinstate': $model->set('state', 1); $what = $suspended ? Lang::txt('COM_PROJECTS_ACTIVITY_PROJECT_REINSTATED') : Lang::txt('COM_PROJECTS_ACTIVITY_PROJECT_ACTIVATED'); $subject .= $suspended ? Lang::txt('COM_PROJECTS_MSG_ADMIN_REINSTATED') : Lang::txt('COM_PROJECTS_MSG_ADMIN_ACTIVATED'); $this->_message = $suspended ? Lang::txt('COM_PROJECTS_SUCCESS_REINSTATED') : Lang::txt('COM_PROJECTS_SUCCESS_ACTIVATED'); break; } // Add activity $model->recordActivity($what, 0, '', '', 'project', 0, $admin = 1); $sendmail = 1; } elseif ($message) { $subject .= ' - ' . Lang::txt('COM_PROJECTS_MSG_ADMIN_NEW_MESSAGE'); $sendmail = 1; $this->_message = Lang::txt('COM_PROJECTS_SUCCESS_MESSAGE_SENT'); } // Save changes if (!$model->store()) { $this->setError($model->getError()); return false; } // Incoming tags $tags = Request::getVar('tags', '', 'post'); // Save the tags $cloud = new Models\Tags($model->get('id')); $cloud->setTags($tags, User::get('id'), 1); // Save params $incoming = Request::getVar('params', array()); if (!empty($incoming)) { foreach ($incoming as $key => $value) { if ($key == 'quota' || $key == 'pubQuota') { // convert GB to bytes $value = Helpers\Html::convertSize(floatval($value), 'GB', 'b'); } $model->saveParam($key, $value); } } // Add members if specified $this->model = $model; $this->_saveMember(); // Change ownership $this->_changeOwnership(); // Send message if ($this->config->get('messaging', 0) && $sendmail && count($managers) > 0) { // Email config $from = array(); $from['name'] = Config::get('sitename') . ' ' . Lang::txt('COM_PROJECTS'); $from['email'] = Config::get('mailfrom'); // Html email $from['multipart'] = md5(date('U')); // Message body $eview = new \Hubzero\Mail\View(array('name' => 'emails', 'layout' => 'admin_plain')); $eview->option = $this->_option; $eview->subject = $subject; $eview->action = $action; $eview->project = $model; $eview->message = $message; $body = array(); $body['plaintext'] = $eview->loadTemplate(false); $body['plaintext'] = str_replace("\n", "\r\n", $body['plaintext']); // HTML email $eview->setLayout('admin_html'); $body['multipart'] = $eview->loadTemplate(); $body['multipart'] = str_replace("\n", "\r\n", $body['multipart']); // Send HUB message Event::trigger('xmessage.onSendMessage', array('projects_admin_notice', $subject, $body, $from, $managers, $this->_option)); } \Notify::message($this->_message, 'success'); // Redirect to edit view? if ($redirect) { App::redirect(Route::url('index.php?option=' . $this->_option . '&task=edit&id=' . $id, false)); } else { App::redirect(Route::url('index.php?option=' . $this->_option, false)); } }
/** * Attach a citation to a publication (in non-curated flow) * * @return string */ public function savecite() { // Incoming $cite = Request::getVar('cite', array(), 'post', 'none', 2); $pid = Request::getInt('pid', 0); $version = Request::getVar('version', 'dev'); $new = $cite['id'] ? false : true; include_once PATH_CORE . DS . 'components' . DS . 'com_citations' . DS . 'tables' . DS . 'citation.php'; include_once PATH_CORE . DS . 'components' . DS . 'com_citations' . DS . 'tables' . DS . 'association.php'; if (!$pid || !$cite['type'] || !$cite['title']) { $this->setError(Lang::txt('PLG_PROJECTS_PUBLICATIONS_CITATIONS_ERROR_MISSING_REQUIRED')); } else { $citation = new \Components\Citations\Tables\Citation($this->_database); if (!$citation->bind($cite)) { $this->setError($citation->getError()); } else { $citation->created = $new == true ? Date::toSql() : $citation->created; $citation->uid = $new == true ? $this->_uid : $citation->uid; $citation->published = 1; if (!$citation->store(true)) { // This really shouldn't happen. $this->setError(Lang::txt('PLG_PROJECTS_PUBLICATIONS_CITATIONS_ERROR_SAVE')); } } // Create association if (!$this->getError() && $new == true && $citation->id) { $assoc = new \Components\Citations\Tables\Association($this->_database); $assoc->oid = $pid; $assoc->tbl = 'publication'; $assoc->type = 'owner'; $assoc->cid = $citation->id; // Store new content if (!$assoc->store()) { $this->setError($assoc->getError()); } } \Notify::message(Lang::txt('PLG_PROJECTS_LINKS_CITATION_SAVED'), 'success', 'projects'); } // Pass success or error message if ($this->getError()) { \Notify::message($this->getError(), 'error', 'projects'); } // Build pub url $route = $this->model->isProvisioned() ? 'index.php?option=com_publications&task=submit' : 'index.php?option=com_projects&alias=' . $this->model->get('alias') . '&active=publications'; App::redirect(Route::url($route . '&pid=' . $pid . '&version=' . $version . '§ion=citations')); return; }
/** * Set notifications * * @param string $message * @param string $type * @return void */ protected function _setNotification($message, $type = 'success') { // If message is set push to notifications if ($message != '') { \Notify::message($message, $type, 'projects'); } }
/** * Finalize the purchase process * * @return void */ public function finalizeTask() { // Check for request forgeries Request::checkToken(); // Set page title $this->_buildTitle(); // Set the pathway $this->_buildPathway(); // Check authorization if (User::isGuest()) { $this->loginTask(); return; } $now = \Date::toSql(); // Get cart object $item = new Cart($this->database); // Calculate total $cost = $item->getCartItems(User::get('id'), 'cost'); // Check available user funds $BTL = new Teller(User::get('id')); $balance = $BTL->summary(); $credit = $BTL->credit_summary(); $funds = $balance - $credit; $funds = $funds > 0 ? $funds : '0'; // Get cart items $items = $item->getCartItems(User::get('id')); if (!$items or $cost > $funds) { $this->cartTask(); return; } // Get shipping info $shipping = array_map('trim', $_POST); // make sure email address is valid $email = \Hubzero\Utility\Validate::email($shipping['email']) ? $shipping['email'] : User::get('email'); // Format posted info $details = Lang::txt('COM_STORE_SHIP_TO') . ':' . "\r\n"; $details .= $shipping['name'] . "\r\n"; $details .= Sanitize::stripAll($shipping['address']) . "\r\n"; $details .= Lang::txt('COM_STORE_COUNTRY') . ': ' . $shipping['country'] . "\r\n"; $details .= '----------------------------------------------------------' . "\r\n"; $details .= Lang::txt('COM_STORE_CONTACT') . ': ' . "\r\n"; if ($shipping['phone']) { $details .= $shipping['phone'] . "\r\n"; } $details .= $email . "\r\n"; $details .= '----------------------------------------------------------' . "\r\n"; $details .= Lang::txt('COM_STORE_DETAILS') . ': '; $details .= $shipping['comments'] ? "\r\n" . Sanitize::stripAll($shipping['comments']) : 'N/A'; // Register a new order $order = new Order($this->database); $order->uid = User::get('id'); $order->total = $cost; $order->status = '0'; // order placed $order->ordered = $now; $order->email = $email; $order->details = $details; // Store new content if (!$order->store()) { throw new Exception($order->getError(), 500); } // Get order ID $objO = new Order($this->database); $orderid = $objO->getOrderID(User::get('id'), $now); if ($orderid) { // Transfer cart items to order foreach ($items as $itm) { $orderitem = new OrderItem($this->database); $orderitem->uid = User::get('id'); $orderitem->oid = $orderid; $orderitem->itemid = $itm->itemid; $orderitem->price = $itm->price; $orderitem->quantity = $itm->quantity; $orderitem->selections = $itm->selections; // Save order item if (!$orderitem->store()) { throw new Exception($orderitem->getError(), 500); } } // Put the purchase amount on hold $BTL = new Teller(User::get('id')); $BTL->hold($order->total, Lang::txt('COM_STORE_BANKING_HOLD'), 'store', $orderid); $message = new \Hubzero\Mail\Message(); $message->setSubject(Config::get('sitename') . ' ' . Lang::txt('COM_STORE_EMAIL_SUBJECT_NEW_ORDER', $orderid)); $message->addFrom(Config::get('mailfrom'), Config::get('sitename') . ' ' . Lang::txt(strtoupper($this->_option))); // Plain text email $eview = new \Hubzero\Mail\View(array('name' => 'emails', 'layout' => 'confirmation_plain')); $eview->option = $this->_option; $eview->controller = $this->_controller; $eview->orderid = $orderid; $eview->cost = $cost; $eview->shipping = $shipping; $eview->details = $details; $eview->items = $items; $plain = $eview->loadTemplate(false); $plain = str_replace("\n", "\r\n", $plain); $message->addPart($plain, 'text/plain'); // HTML email $eview->setLayout('confirmation_html'); $html = $eview->loadTemplate(); $html = str_replace("\n", "\r\n", $html); $message->addPart($html, 'text/html'); // Send e-mail $message->setTo(array(User::get('email'))); $message->send(); } // Empty cart $item->deleteCartItem('', User::get('id'), 'all'); if ($this->getError()) { \Notify::message($this->getError(), 'error'); } else { \Notify::message(Lang::txt('COM_STORE_SUCCESS_MESSAGE', $orderid), 'success'); } App::redirect(Route::url('index.php?option=' . $this->_option)); return; }
/** * main method * * Check for the existance of a tmp/autopilot_running file. If it exists - and is less than an hour * old do not do anything to prevent the possibility of running autotest several times in parallel * on the same files. If the file is more than an hour old delete it and continue. * Delete the tmp/autopilot_stop file if it exists and being autopilot test/checking process. * * @return void * @access public */ function main() { if (!$this->_registerPid()) { $this->out('Unable to register Pid'); $this->_stop(); } if (file_exists($this->params['working'] . DS . '.autotest')) { include $this->params['working'] . DS . '.autotest'; } if (!empty($this->params['notify'])) { $this->settings['notify'] = $this->params['notify']; } if (!empty($this->params['mode'])) { $this->settings['mode'] = $this->params['mode']; } $suffix = ''; if (!empty($this->settings['mode'])) { $suffix = ' (' . $this->settings['mode'] . ' mode)'; } Notify::$method = $this->settings['notify']; $this->addHooks(); Notify::message('Autopilot Starting', 'in ' . APP_DIR . $suffix, 0, false); $this->buildPaths(); $this->run(); }
/** * Processes file annotations * * @return void */ public function annotateit() { // Check permission if (!$this->model->access('content')) { throw new Exception(Lang::txt('ALERTNOTAUTH'), 403); return; } // Get the file entity $file = trim($this->subdir, '/') . '/' . trim(Request::getVar('item', '')); $entity = Entity::fromPath($file, $this->connection->adapter()); // Grab annotations $keys = Request::getVar('key', []); $values = Request::getVar('value', []); $metadata = []; foreach ($keys as $idx => $key) { $key = trim($key); $value = trim($values[$idx]); if (!empty($key) && !empty($value)) { $metadata[$key] = $value; } } // Look for plugins that know how to handle them $plugins = Plugin::byType('metadata'); if (count($plugins) == 0) { \Notify::message(Lang::txt('PLG_PROJECTS_FILES_ERROR_NO_ANNOTATION_PLUGINS'), 'error', 'projects'); } else { // Send the data off to the plugins $response = Event::trigger('metadata.onMetadataSave', [$entity, $metadata]); if (empty($response)) { \Notify::message(Lang::txt('PLG_PROJECTS_FILES_ANNOTATED_SUCCESS'), 'success', 'projects'); } else { \Notify::message(Lang::txt('PLG_PROJECTS_FILES_ERROR_ANNOTATE_FAILED'), 'error', 'projects'); } } // Redirect to file list $url = $this->model->link('files') . '&action=browse&connection=' . $this->connection->id; $url .= $this->subdir ? '&subdir=' . urlencode($this->subdir) : ''; // Redirect App::redirect(Route::url($url, false)); }
/** * Quit project * * @return void, redirect */ protected function _quit() { $html = ''; // Incoming $confirm = Request::getInt('confirm', 0, 'post'); // Instantiate project owner $objO = $this->model->table('Owner'); // Check to make sure we are not deleting last manager $onlymanager = 0; if ($this->model->access('manager')) { $managers = $objO->getIds($this->model->get('id'), $role = 1); if (count($managers) == 1) { $onlymanager = 1; } } // Remove member from team if not owner & other managers exist if ($confirm && !$onlymanager && !$this->model->access('owner')) { $deleted = $objO->removeOwners($this->model->get('id'), array($this->_uid)); if ($deleted) { $this->_msg = Lang::txt('PLG_PROJECTS_TEAM_MEMBER_QUIT_SUCCESS'); // Record activity $aid = $this->model->recordActivity(Lang::txt('PLG_PROJECTS_TEAM_PROJECT_QUIT'), 0, '', '', 'team', 0); // Sync with system group $objO->sysGroup($this->model->get('alias'), $this->model->config('group_prefix', 'pr-')); } } else { // Output HTML $view = new \Hubzero\Plugin\View(array('folder' => 'projects', 'element' => 'team', 'name' => 'quit')); $view->group = $this->model->groupOwner('id'); $view->onlymanager = $onlymanager; $view->option = $this->_option; $view->database = $this->_database; $view->model = $this->model; $view->uid = $this->_uid; $view->config = $this->_config; $view->msg = isset($this->_msg) ? $this->_msg : ''; $view->title = $this->_area['title']; if ($this->getError()) { $view->setError($this->getError()); } return $view->loadTemplate(); } // Pass error or success message if ($this->getError()) { \Notify::message($this->getError(), 'error', 'projects'); } elseif (!empty($this->_msg)) { \Notify::message($this->_msg, 'success', 'projects'); } App::redirect(Route::url('index.php?option=' . $this->_option)); return; }
/** * Event call after file update * * @param object $model * @param array $changes * @return void */ public function onAfterUpdate($model = NULL, $changes = array()) { $activity = ''; $message = ''; $ref = ''; $sync = 0; $model = $model ? $model : $this->model; if (empty($changes)) { // Get session $jsession = App::get('session'); // Get values from session $updated = $jsession->get('projects.' . $model->get('alias') . '.updated'); $uploaded = $jsession->get('projects.' . $model->get('alias') . '.uploaded'); $failed = $jsession->get('projects.' . $model->get('alias') . '.failed'); $deleted = $jsession->get('projects.' . $model->get('alias') . '.deleted'); $restored = $jsession->get('projects.' . $model->get('alias') . '.restored'); $expanded = $jsession->get('projects.' . $model->get('alias') . '.expanded'); // Clean up session values $jsession->set('projects.' . $model->get('alias') . '.failed', ''); $jsession->set('projects.' . $model->get('alias') . '.updated', ''); $jsession->set('projects.' . $model->get('alias') . '.uploaded', ''); $jsession->set('projects.' . $model->get('alias') . '.deleted', ''); $jsession->set('projects.' . $model->get('alias') . '.restored', ''); $jsession->set('projects.' . $model->get('alias') . '.expanded', ''); } else { $updated = !empty($changes['updated']) ? $changes['updated'] : NULL; $uploaded = !empty($changes['uploaded']) ? $changes['uploaded'] : NULL; $failed = !empty($changes['failed']) ? $changes['failed'] : NULL; $deleted = !empty($changes['deleted']) ? $changes['deleted'] : NULL; $restored = !empty($changes['restored']) ? $changes['restored'] : NULL; $expanded = !empty($changes['expanded']) ? $changes['expanded'] : NULL; } // Provisioned project? if ($model->isProvisioned() || !$model->get('id')) { return false; } // Pass success or error message if (!empty($failed) && !$uploaded && !$uploaded) { \Notify::message(Lang::txt('PLG_PROJECTS_FILES_ERROR_FAILED_TO_UPLOAD') . $failed, 'error', 'projects'); } elseif ($uploaded || $updated || $expanded) { $uploadParts = explode(',', $uploaded); $updateParts = explode(',', $updated); $sync = 1; if ($uploaded) { if (count($uploadParts) > 2) { $message = 'uploaded ' . basename($uploadParts[0]) . ' and ' . (count($uploadParts) - 1) . ' more files '; } else { $message = 'uploaded '; $u = 0; foreach ($uploadParts as $part) { $message .= basename($part); $u++; $message .= count($uploadParts) == $u ? '' : ', '; } } // Save referenced files $ref = $uploaded; } if ($updated) { $message .= $uploaded ? '. Updated ' : 'updated '; if (count($updateParts) > 2) { $message .= basename($updateParts[0]) . ' and ' . (count($updateParts) - 1) . ' more files '; } else { $u = 0; foreach ($updateParts as $part) { $message .= basename($part); $u++; $message .= count($updateParts) == $u ? '' : ', '; } } } $activity = $message . ' ' . strtolower(Lang::txt('PLG_PROJECTS_FILES_IN_PROJECT_FILES')); $message = 'Successfully ' . $message; $message .= $failed ? ' There was a problem uploading ' . $failed : ''; \Notify::message($message, 'success', 'projects'); } elseif ($deleted) { // Save referenced files $ref = $deleted; $sync = 1; $delParts = explode(',', $deleted); $what = count($delParts) == 1 ? $deleted : count($delParts) . ' ' . Lang::txt('PLG_PROJECTS_FILES_ITEMS'); // Output message \Notify::message(Lang::txt('PLG_PROJECTS_FILES_SUCCESS_DELETED') . ' ' . $what, 'success', 'projects'); } elseif ($restored) { // Save referenced files $ref = $restored; $sync = 1; $resParts = explode(',', $restored); $activity = 'restored deleted file ' . basename($resParts[0]); // Output message \Notify::message(Lang::txt('PLG_PROJECTS_FILES_SUCCESS_RESTORED') . ' ' . basename($resParts[0]), 'success', 'projects'); } // Add activity to feed if ($activity && $model->repo()->isLocal()) { $refParts = explode(',', $ref); $parsedRef = ''; $selected = array(); foreach ($refParts as $item) { $file = $model->repo()->getMetadata(trim($item)); $params = array('file' => $file); if ($file->exists()) { $hash = $model->repo()->getLastRevision($params); if ($hash) { $selected[] = substr($hash, 0, 10) . ':' . trim($file->get('localPath')); // Generate preview (regular and medium-size) $file->getPreview($model, $hash); $file->getPreview($model, $hash, '', 'medium'); } } } // Save hash and file name in a reference if ($selected) { foreach ($selected as $sel) { if (strlen($parsedRef) + strlen($sel) <= 254) { $parsedRef .= $sel . ','; } else { break; } } $parsedRef = substr($parsedRef, 0, strlen($parsedRef) - 1); } // Check to make sure we are not over in char length if (strlen($parsedRef) > 255) { $parsedRef = \Components\Projects\Helpers\Html::shortenText($parsedRef); } // Force sync if ($sync) { //$this->model->saveParam('google_sync_queue', 1); $this->set('forceSync', 1); } // Record activity $aid = $model->recordActivity($activity, $parsedRef, 'files', Route::url($model->link('files')), 'files', 1); } }
/** * Subscribe * * @return void */ private function _save() { // Check for request forgeries Request::checkToken(); // Login required if (User::isGuest() || !$this->project->exists()) { App::redirect(Route::url($this->project->link())); } // Incoming $email = User::get('email'); $categories = Request::getVar('category', array()); $frequency = Request::getWord('frequency', 'immediate'); // Save subscription $watch = \Hubzero\Item\Watch::oneByScope($this->project->get('id'), 'project', User::get('id'), $email); $watch->set('item_id', $this->project->get('id')); $watch->set('item_type', 'project'); $watch->set('created_by', User::get('id')); $watch->set('state', empty($categories) ? 2 : 1); $cats = array('blog' => 0, 'quote' => 0, 'team' => 0, 'files' => 0, 'publications' => 0, 'todo' => 0, 'notes' => 0); $params = new \Hubzero\Config\Registry($watch->get('params', '')); $params->set('frequency', $frequency); foreach ($cats as $param => $value) { if (isset($categories[$param])) { $value = intval($categories[$param]); } if ($param == 'quote' && isset($categories['blog'])) { $value = 1; } $params->set($param, $value); } $watch->set('params', $params->toString()); $watch->save(); if ($err = $watch->getError()) { Notify::error($err); } else { Notify::message(Lang::txt('PLG_PROJECTS_WATCH_SUCCESS_SAVED'), 'success', 'projects'); } App::redirect(Route::url($this->project->link())); }