Ejemplo n.º 1
0
 /**
  * Return data on a resource view (this will be some form of HTML)
  *
  * @param   object  $resource  Current resource
  * @param   string  $option    Name of the component
  * @param   array   $areas     Active area(s)
  * @param   string  $rtrn      Data to be returned
  * @return  array
  */
 public function onResources($model, $option, $areas, $rtrn = 'all')
 {
     $arr = array('area' => $this->_name, 'html' => '', 'metadata' => '');
     // Check if our area is in the array of areas we want to return results for
     if (is_array($areas)) {
         if (!array_intersect($areas, $this->onResourcesAreas($model)) && !array_intersect($areas, array_keys($this->onResourcesAreas($model)))) {
             $rtrn = 'metadata';
         }
     }
     // Display only for tools
     if (!$model->isTool()) {
         return $arr;
     }
     if ($rtrn == 'all' || $rtrn == 'html') {
         $database = App::get('db');
         $tv = new \Components\Tools\Tables\Version($database);
         $rows = $tv->getVersions($model->resource->alias);
         // Get contribtool params
         $tconfig = Component::params('com_tools');
         // Instantiate a view
         $view = $this->view('default', 'browse')->set('tconfig', $tconfig)->set('option', $option)->set('resource', $model->resource)->set('rows', $rows);
         // Return the output
         $arr['html'] = $view->loadTemplate();
     }
     if ($rtrn == 'all' || $rtrn == 'metadata') {
         $arr['metadata'] = '';
     }
     return $arr;
 }
Ejemplo n.º 2
0
 /**
  * Generate module contents
  *
  * @return  void
  */
 public function run()
 {
     include_once Component::path('com_resources') . DS . 'tables' . DS . 'resource.php';
     $database = \App::get('db');
     //Get the admin configured settings
     $filters = array('limit' => 1, 'start' => 0, 'type' => trim($this->params->get('type')), 'sortby' => 'random', 'minranking' => trim($this->params->get('minranking')), 'tag' => trim($this->params->get('tag')), 'access' => 'public', 'toolState' => 7);
     $row = null;
     // No - so we need to randomly choose one
     // Initiate a resource object
     $rr = new \Components\Resources\Tables\Resource($database);
     // Get records
     $rows = $rr->getRecords($filters, false);
     if (count($rows) > 0) {
         $row = $rows[0];
     }
     $this->cls = trim($this->params->get('moduleclass_sfx'));
     $this->txt_length = trim($this->params->get('txt_length'));
     // Did we get any results?
     if ($row) {
         $config = Component::params('com_resources');
         // Resource
         $id = $row->id;
         include_once Component::path('com_resources') . DS . 'helpers' . DS . 'html.php';
         $path = DS . trim($config->get('uploadpath', '/site/resources'), DS);
         $path = \Components\Resources\Helpers\Html::build_path($row->created, $row->id, $path);
         if ($row->type == 7) {
             include_once Component::path('com_tools') . DS . 'tables' . DS . 'version.php';
             $tv = new \Components\Tools\Tables\Version($database);
             $versionid = $tv->getVersionIdFromResource($id, 'current');
             $picture = $this->getToolImage($path, $versionid);
         } else {
             $picture = $this->getImage($path);
         }
         $thumb = $path . DS . $picture;
         if (!is_file(PATH_APP . $thumb)) {
             $thumb = DS . trim($config->get('defaultpic'));
         }
         $row->typetitle = trim(stripslashes($row->typetitle));
         if (substr($row->typetitle, -1, 1) == 's' && substr($row->typetitle, -3, 3) != 'ies') {
             $row->typetitle = substr($row->typetitle, 0, strlen($row->typetitle) - 1);
         }
         $this->id = $id;
         $this->thumb = $thumb;
     }
     $this->row = $row;
     require $this->getLayoutPath();
 }
Ejemplo n.º 3
0
 /**
  * Get the access level for this user and tool
  *
  * @param      string $tool  Tool name
  * @param      string $login Username
  * @return     boolean True if the user has access
  */
 private function _getToolAccess($tool, $login = '')
 {
     include_once dirname(dirname(__DIR__)) . DS . 'tables' . DS . 'tool.php';
     include_once dirname(dirname(__DIR__)) . DS . 'tables' . DS . 'group.php';
     include_once dirname(dirname(__DIR__)) . DS . 'tables' . DS . 'version.php';
     // Ensure we have a tool
     if (!$tool) {
         $this->setError(Lang::txt('COM_TOOLS_ERROR_TOOL_NOT_FOUND'));
         Log::debug("mw::_getToolAccess({$tool},{$login}) FAILED null tool check");
         return false;
     }
     // Ensure we have a login
     if ($login == '') {
         $login = User::get('username');
         if ($login == '') {
             Log::debug("mw::_getToolAccess({$tool},{$login}) FAILED null user check");
             return false;
         }
     }
     $tv = new \Components\Tools\Tables\Version($this->database);
     $tv->loadFromInstance($tool);
     if (empty($tv->id)) {
         Log::debug("mw::_getToolAccess({$tool},{$login}) FAILED null tool version check");
         return false;
     }
     $tg = new \Components\Tools\Tables\Group($this->database);
     $this->database->setQuery("SELECT * FROM " . $tg->getTableName() . " WHERE toolid=" . $tv->toolid);
     $toolgroups = $this->database->loadObjectList();
     if (empty($toolgroups)) {
         //Log::debug("mw::_getToolAccess($tool,$login) WARNING: no tool member groups");
     }
     $xgroups = \Hubzero\User\Helper::getGroups(User::get('id'), 'members');
     if (empty($xgroups)) {
         //Log::debug("mw::_getToolAccess($tool,$login) WARNING: user not in any groups");
     }
     // Check if the user is in any groups for this app
     $ingroup = false;
     $groups = array();
     $indevgroup = false;
     if ($xgroups) {
         foreach ($xgroups as $xgroup) {
             $groups[] = $xgroup->cn;
         }
         if ($toolgroups) {
             foreach ($toolgroups as $toolgroup) {
                 if (in_array($toolgroup->cn, $groups)) {
                     $ingroup = true;
                     if ($toolgroup->role == 1) {
                         $indevgroup = true;
                     }
                 }
             }
         }
     }
     $admin = false;
     $ctconfig = Component::params('com_tools');
     if ($ctconfig->get('admingroup') != '' && in_array($ctconfig->get('admingroup'), $groups)) {
         $admin = true;
     }
     $exportAllowed = $this->_getToolExportControl($tv->exportControl);
     $tisPublished = $tv->state == 1;
     $tisDev = $tv->state == 3;
     $tisGroupControlled = $tv->toolaccess == '@GROUP';
     if ($tisDev) {
         if ($indevgroup) {
             //Log::debug("mw::_getToolAccess($tool,$login): DEV TOOL ACCESS GRANTED (USER IN DEVELOPMENT GROUP)");
             return true;
         } else {
             if ($admin) {
                 //Log::debug("mw::_getToolAccess($tool,$login): DEV TOOL ACCESS GRANTED (USER IN ADMIN GROUP)");
                 return true;
             } else {
                 Log::debug("mw::_getToolAccess({$tool},{$login}): DEV TOOL ACCESS DENIED (USER NOT IN DEVELOPMENT OR ADMIN GROUPS)");
                 $this->setError(Lang::txt('COM_TOOLS_ERROR_ACCESS_DENIED_DEV_GROUP'));
                 return false;
             }
         }
     } else {
         if ($tisPublished) {
             if ($tisGroupControlled) {
                 if ($ingroup) {
                     //Log::debug("mw::_getToolAccess($tool,$login): PUBLISHED TOOL ACCESS GRANTED (USER IN ACCESS GROUP)");
                     return true;
                 } else {
                     if ($admin) {
                         //Log::debug("mw::_getToolAccess($tool,$login): PUBLISHED TOOL ACCESS GRANTED (USER IN ADMIN GROUP)");
                         return true;
                     } else {
                         Log::debug("mw::_getToolAccess({$tool},{$login}): PUBLISHED TOOL ACCESS DENIED (USER NOT IN ACCESS OR ADMIN GROUPS)");
                         $this->setError(Lang::txt('COM_TOOLS_ERROR_ACCESS_DENIED_ACCESS_GROUP'));
                         return false;
                     }
                 }
             } else {
                 if (!$exportAllowed) {
                     Log::debug("mw::_getToolAccess({$tool},{$login}): PUBLISHED TOOL ACCESS DENIED (EXPORT DENIED)");
                     return false;
                 } else {
                     if ($admin) {
                         //Log::debug("mw::_getToolAccess($tool,$login): PUBLISHED TOOL ACCESS GRANTED (USER IN ADMIN GROUP)");
                         return true;
                     } else {
                         if ($indevgroup) {
                             //Log::debug("mw::_getToolAccess($tool,$login): PUBLISHED TOOL ACCESS GRANTED (USER IN DEVELOPMENT GROUP)");
                             return true;
                         } else {
                             //Log::debug("mw::_getToolAccess($tool,$login): PUBLISHED TOOL ACCESS GRANTED");
                             return true;
                         }
                     }
                 }
             }
         } else {
             Log::debug("mw::_getToolAccess({$tool},{$login}): UNPUBLISHED TOOL ACCESS DENIED (TOOL NOT PUBLISHED)");
             $this->setError(Lang::txt('COM_TOOLS_ERROR_ACCESS_DENIED_VERSION_UNPUBLISHED'));
             return false;
         }
     }
     return false;
 }
Ejemplo n.º 4
0
 /**
  * Get a list of parents of this resource
  *   Accepts either a numeric array index
  *   If index, it'll return the entry matching that index in the list
  *
  * @param      mixed $idx Index value
  * @return     array
  */
 public function revisions($idx = null)
 {
     if (!$this->exists()) {
         return array();
     }
     if (!isset($this->revisions)) {
         $this->revisions = array();
         $alltools = array();
         $tv = new \Components\Tools\Tables\Version($this->_db);
         $tv->getToolVersions('', $alltools, $this->resource->alias);
         if ($alltools) {
             $this->revisions = $alltools;
         }
     }
     if ($idx !== null && is_numeric($idx)) {
         if (isset($this->revisions[$idx])) {
             return $this->revisions[$idx];
         } else {
             if (is_string($idx)) {
                 switch (strtolower($idx)) {
                     case 'current':
                         $curtool = null;
                         foreach ($this->revisions as $tool) {
                             // Current version
                             if ($tool->state == 1 && (count($this->revisions) == 1 || count($this->revisions) > 1 && $this->revisions[1]->version == $tool->version)) {
                                 $curtool = $tool;
                                 break;
                                 // No need to go further
                             }
                         }
                         return $curtool;
                         break;
                     case 'dev':
                         $devtool = null;
                         foreach ($this->revisions as $tool) {
                             // Current version
                             if ($tool->state == 3) {
                                 $devtool = $tool;
                                 break;
                                 // No need to go further
                             }
                         }
                         return $devtool;
                         break;
                     default:
                         $rtool = null;
                         foreach ($this->revisions as $tool) {
                             if ($tool->revision == $idx) {
                                 $rtool = $tool;
                                 break;
                                 // No need to go further
                             }
                         }
                         return $rtool;
                         break;
                 }
             }
         }
     }
     return $this->revisions;
 }
Ejemplo n.º 5
0
 /**
  * Save a question and redirect to the main listing when done
  *
  * @return     void
  */
 private function _save()
 {
     // Login required
     if (User::isGuest()) {
         return $this->_browse();
     }
     // Check for request forgeries
     Request::checkToken();
     Lang::load('com_answers');
     // Incoming
     $tags = Request::getVar('tags', '');
     $funds = Request::getInt('funds', 0);
     $reward = Request::getInt('reward', 0);
     // If offering a reward, do some checks
     if ($reward) {
         // Is it an actual number?
         if (!is_numeric($reward)) {
             App::abort(500, Lang::txt('COM_ANSWERS_REWARD_MUST_BE_NUMERIC'));
             return;
         }
         // Are they offering more than they can afford?
         if ($reward > $funds) {
             App::abort(500, Lang::txt('COM_ANSWERS_INSUFFICIENT_FUNDS'));
             return;
         }
     }
     // Initiate class and bind posted items to database fields
     $fields = Request::getVar('question', array(), 'post', 'none', 2);
     $row = new \Components\Answers\Models\Question($fields['id']);
     if (!$row->bind($fields)) {
         $this->setError($row->getError());
         return $this->_new($row);
     }
     if ($reward && $this->banking) {
         $row->set('reward', 1);
     }
     // Ensure the user added a tag
     /*
     if (!$tags)
     {
     	$this->setError(Lang::txt('COM_ANSWERS_QUESTION_MUST_HAVE_TAG'));
     	return $this->_new($row);
     }
     */
     // Store new content
     if (!$row->store(true)) {
         $row->set('tags', $tags);
         $this->setError($row->getError());
         return $this->_new($row);
     }
     // Hold the reward for this question if we're banking
     if ($reward && $this->banking) {
         $BTL = new \Hubzero\Bank\Teller($this->database, User::get('id'));
         $BTL->hold($reward, Lang::txt('COM_ANSWERS_HOLD_REWARD_FOR_BEST_ANSWER'), 'answers', $row->get('id'));
     }
     // Add the tags
     $row->tag($tags);
     // Add the tag to link to the resource
     $tag = $this->model->isTool() ? 'tool:' . $this->model->resource->alias : 'resource:' . $this->model->resource->id;
     $row->addTag($tag, User::get('id'), $this->model->isTool() ? 0 : 1);
     // Get users who need to be notified on every question
     $config = Component::params('com_answers');
     $apu = $config->get('notify_users', '');
     $apu = explode(',', $apu);
     $apu = array_map('trim', $apu);
     $receivers = array();
     // Get tool contributors if question is about a tool
     if ($tags) {
         $tags = explode(',', $tags);
         if (count($tags) > 0) {
             require_once PATH_CORE . DS . 'components' . DS . 'com_tools' . DS . 'tables' . DS . 'author.php';
             require_once PATH_CORE . DS . 'components' . DS . 'com_tools' . DS . 'tables' . DS . 'version.php';
             $TA = new \Components\Tools\Tables\Author($this->database);
             $objV = new \Components\Tools\Tables\Version($this->database);
             if ($this->model->isTool()) {
                 $toolname = $this->model->resource->alias;
                 $rev = $objV->getCurrentVersionProperty($toolname, 'revision');
                 $authors = $TA->getToolAuthors('', 0, $toolname, $rev);
                 if (count($authors) > 0) {
                     foreach ($authors as $author) {
                         $receivers[] = $author->uidNumber;
                     }
                 }
             }
         }
     }
     if (!empty($apu)) {
         foreach ($apu as $u) {
             $user = User::getInstance($u);
             if ($user) {
                 $receivers[] = $user->get('id');
             }
         }
     }
     $receivers = array_unique($receivers);
     // Send the message
     if (!empty($receivers)) {
         // Send a message about the new question to authorized users (specified admins or related content authors)
         $from = array('email' => Config::get('mailfrom'), 'name' => Config::get('sitename') . ' ' . Lang::txt('COM_ANSWERS_ANSWERS'), 'multipart' => md5(date('U')));
         // Build the message subject
         $subject = Lang::txt('COM_ANSWERS_ANSWERS') . ', ' . Lang::txt('new question about content you author or manage');
         // Build the message
         $eview = new \Hubzero\Mail\View(array('base_path' => PATH_CORE . DS . 'components' . DS . 'com_answers' . DS . 'site', 'name' => 'emails', 'layout' => 'question_plaintext'));
         $eview->option = 'com_answers';
         $eview->sitename = Config::get('sitename');
         $eview->question = $row;
         $eview->id = $row->get('id', 0);
         $eview->boundary = $from['multipart'];
         $message['plaintext'] = $eview->loadTemplate(false);
         $message['plaintext'] = str_replace("\n", "\r\n", $message['plaintext']);
         // HTML message
         $eview->setLayout('question_html');
         $message['multipart'] = $eview->loadTemplate();
         $message['multipart'] = str_replace("\n", "\r\n", $message['multipart']);
         if (!Event::trigger('xmessage.onSendMessage', array('new_question_admin', $subject, $message, $from, $receivers, 'com_answers'))) {
             $this->setError(Lang::txt('COM_ANSWERS_MESSAGE_FAILED'));
         }
     }
     // Redirect to the question
     App::redirect(Route::url('index.php?option=' . $this->option . '&id=' . $this->model->resource->id . '&active=' . $this->_name));
 }
Ejemplo n.º 6
0
 /**
  * Display a list of authors
  *
  * @param   integer  $id  Resource ID
  * @return  void
  */
 public function displayTask($id = null)
 {
     // Incoming
     if (!$id) {
         $id = Request::getInt('rid', 0);
     }
     // Ensure we have an ID to work with
     if (!$id) {
         App::abort(500, Lang::txt('COM_TOOLS_CONTRIBUTE_NO_ID'));
     }
     $this->view->version = Request::getVar('version', 'dev');
     // Get all contributors of this resource
     $helper = new \Components\Resources\Helpers\Helper($id, $this->database);
     if ($this->view->version == 'dev') {
         $helper->getCons();
     } else {
         $obj = new \Components\Tools\Tables\Tool($this->database);
         $toolname = $obj->getToolnameFromResource($id);
         $objV = new \Components\Tools\Tables\Version($this->database);
         $revision = $objV->getCurrentVersionProperty($toolname, 'revision');
         $helper->getToolAuthors($toolname, $revision);
     }
     // Get a list of all existing contributors
     include_once PATH_CORE . DS . 'components' . DS . 'com_resources' . DS . 'tables' . DS . 'contributor' . DS . 'roletype.php';
     $resource = new \Components\Resources\Tables\Resource($this->database);
     $resource->load($id);
     $rt = new \Components\Resources\Tables\Contributor\RoleType($this->database);
     // Output HTML
     $this->view->config = $this->config;
     $this->view->contributors = $helper->_contributors;
     $this->view->id = $id;
     $this->view->roles = $rt->getRolesForType($resource->type);
     $this->view->setErrors($this->getErrors())->setLayout('display')->display();
 }
Ejemplo n.º 7
0
 /**
  * Format an entry
  *
  * @param      object  $row       Database row
  * @param      string  $tbl       Format type
  * @param      number  $txtLength Max text length to display
  * @param      integer $getid     Just return the ID or not
  * @return     string HTML
  */
 private function _composeEntry($row, $tbl, $txtLength = 100, $getid = 0)
 {
     $yearFormat = 'Y';
     $monthFormat = 'm';
     $out = '';
     // Do we have a picture?
     $thumb = '';
     switch ($tbl) {
         case 'profiles':
             if ($getid) {
                 return $row->uidNumber;
             }
             // Load their bio
             $profile = \Hubzero\User\Profile::getInstance($row->uidNumber);
             $title = $row->name;
             if (!trim($title)) {
                 $title = $row->givenName . ' ' . $row->surname;
             }
             $out .= '<span class="spotlight-img"><a href="' . Route::url('index.php?option=com_members&id=' . $row->uidNumber) . '"><img width="30" height="30" src="' . $profile->getPicture() . '" alt="' . htmlentities($title) . '" /></a></span>' . "\n";
             $out .= '<span class="spotlight-item"><a href="' . Route::url('index.php?option=com_members&id=' . $row->uidNumber) . '">' . $title . '</a></span>, ' . $row->organization . "\n";
             $out .= ' - ' . Lang::txt('Contributions') . ': ' . $this->_countContributions($row->uidNumber) . "\n";
             $out .= '<div class="clear"></div>' . "\n";
             break;
         case 'blog':
             $thumb = trim($this->params->get('default_blogpic', '/core/modules/mod_spotlight/assets/img/default.gif'));
             if ($thumb == '/modules/mod_spotlight/default.gif') {
                 $thumb = '/core/modules/mod_spotlight/assets/img/default.gif';
             }
             $profile = \Hubzero\User\Profile::getInstance($row->created_by);
             if ($getid) {
                 return $row->id;
             }
             if (!$row->title) {
                 $out = '';
             } else {
                 $out .= '<span class="spotlight-img"><a href="' . Route::url('index.php?option=com_members&id=' . $row->created_by . '&active=blog&task=' . Date::of($row->publish_up)->toLocal($yearFormat) . '/' . Date::of($row->publish_up)->toLocal($monthFormat) . '/' . $row->alias) . '"><img width="30" height="30" src="' . rtrim(Request::base(true), '/') . $thumb . '" alt="' . htmlentities(stripslashes($row->title)) . '" /></a></span>' . "\n";
                 $out .= '<span class="spotlight-item"><a href="' . Route::url('index.php?option=com_members&id=' . $row->created_by . '&active=blog&task=' . Date::of($row->publish_up)->toLocal($yearFormat) . '/' . Date::of($row->publish_up)->toLocal($monthFormat) . '/' . $row->alias) . '">' . $row->title . '</a></span> ';
                 $out .= ' by <a href="' . Route::url('index.php?option=com_members&id=' . $row->created_by) . '">' . $profile->get('name') . '</a> - ' . Lang::txt('in Blogs') . "\n";
                 $out .= '<div class="clear"></div>' . "\n";
             }
             break;
         case 'topics':
             if ($getid) {
                 return $row->id;
             }
             $url = $row->group_cn && $row->scope ? 'groups' . DS . $row->scope . DS . $row->pagename : 'topics' . DS . $row->pagename;
             $thumb = trim($this->params->get('default_topicpic', '/core/modules/mod_spotlight/assets/img/default.gif'));
             if ($thumb == '/modules/mod_spotlight/default.gif') {
                 $thumb = '/core/modules/mod_spotlight/assets/img/default.gif';
             }
             $out .= '<span class="spotlight-img"><a href="' . Route::url('index.php?option=com_topics&pagename=' . $row->pagename) . '"><img width="30" height="30" src="' . rtrim(Request::base(true), '/') . $thumb . '" alt="' . htmlentities(stripslashes($row->title)) . '" /></a></span>' . "\n";
             $out .= '<span class="spotlight-item"><a href="' . $url . '">' . stripslashes($row->title) . '</a></span> ';
             $out .= ' - ' . Lang::txt('in') . ' <a href="' . Route::url('index.php?option=com_topics') . '">' . Lang::txt('Topics') . '</a>' . "\n";
             $out .= '<div class="clear"></div>' . "\n";
             break;
         case 'answers':
             if ($getid) {
                 return $row->id;
             }
             $thumb = trim($this->params->get('default_questionpic', '/core/modules/mod_spotlight/assets/img/default.gif'));
             if ($thumb == '/modules/mod_spotlight/default.gif') {
                 $thumb = '/core/modules/mod_spotlight/assets/img/default.gif';
             }
             $name = Lang::txt('Anonymous');
             if ($row->anonymous == 0) {
                 $user = User::getInstance($row->created_by);
                 if (is_object($user)) {
                     $name = $user->get('name');
                 }
             }
             $out .= '<span class="spotlight-img"><a href="' . Route::url('index.php?option=com_answers&task=question&id=' . $row->id) . '"><img width="30" height="30" src="' . rtrim(Request::base(true), '/') . $thumb . '" alt="' . htmlentities(stripslashes($row->subject)) . '" /></a></span>' . "\n";
             $out .= '<span class="spotlight-item"><a href="' . Route::url('index.php?option=com_answers&task=question&id=' . $row->id) . '">' . stripslashes($row->subject) . '</a></span> ';
             $out .= ' - ' . Lang::txt('asked by') . ' ' . $name . ', ' . Lang::txt('in') . ' <a href="' . Route::url('index.php?option=com_answers') . '">' . Lang::txt('Answers') . '</a>' . "\n";
             $out .= '<div class="clear"></div>' . "\n";
             break;
         default:
             if ($getid) {
                 return $row->id;
             }
             if ($tbl == 'itunes') {
                 $thumb = trim($this->params->get('default_itunespic', '/core/modules/mod_spotlight/assets/img/default.gif'));
                 if ($thumb == '/modules/mod_spotlight/default.gif') {
                     $thumb = '/core/modules/mod_spotlight/assets/img/default.gif';
                 }
             } else {
                 $rconfig = Component::params('com_resources');
                 $path = substr(PATH_APP, strlen(PATH_ROOT)) . DS . trim($rconfig->get('uploadpath', '/site/resources'), DS);
                 $path = DS . trim($path, DS);
                 $path = $this->_buildPath($row->created, $row->id, $path);
                 if ($row->type == 7) {
                     include_once Component::path('com_tools') . DS . 'tables' . DS . 'version.php';
                     $tv = new \Components\Tools\Tables\Version($this->database);
                     $versionid = $tv->getVersionIdFromResource($row->id, 'current');
                     $picture = $this->_getToolImage($path, $versionid);
                 } else {
                     $picture = $this->_getImage($path);
                 }
                 $thumb = $path . DS . $picture;
                 if (!is_file(PATH_ROOT . $thumb) or !$picture) {
                     $thumb = DS . trim($rconfig->get('defaultpic', '/core/modules/mod_spotlight/assets/img/default.gif'), DS);
                     if ($thumb == '/modules/mod_spotlight/default.gif') {
                         $thumb = '/core/modules/mod_spotlight/assets/img/default.gif';
                     }
                 }
                 if (substr($thumb, 0, strlen('/modules')) == '/modules' || substr($thumb, 0, strlen('/components')) == '/components') {
                     $thumb = '/core' . $thumb;
                 }
                 $thumb = str_replace('com_resources/assets', 'com_resources/site/assets', $thumb);
             }
             $normalized = preg_replace("/[^a-zA-Z0-9]/", '', strtolower($row->typetitle));
             $row->typetitle = trim(stripslashes($row->typetitle));
             $row->title = stripslashes($row->title);
             $chars = strlen($row->title . $row->typetitle);
             $remaining = $txtLength - $chars;
             $remaining = $remaining <= 0 ? 0 : $remaining;
             $titlecut = $remaining ? 0 : $txtLength - strlen($row->typetitle);
             if ($titlecut) {
                 $title = \Hubzero\Utility\String::truncate($row->title, $titlecut);
             } else {
                 $title = $row->title;
             }
             // resources
             $out .= '<span class="spotlight-img">';
             $out .= "\t" . '<a href="' . Route::url('index.php?option=com_resources&id=' . $row->id) . '">' . "\n";
             $out .= "\t\t" . '<img width="30" height="30" src="' . rtrim(Request::base(true), '/') . $thumb . '" alt="' . htmlentities($row->title) . '" />' . "\n";
             $out .= "\t" . '</a>' . "\n";
             $out .= '</span>' . "\n";
             $out .= '<span class="spotlight-item">' . "\n";
             $out .= "\t" . '<a href="' . Route::url('index.php?option=com_resources&id=' . $row->id) . '">' . $title . '</a>' . "\n";
             $out .= '</span>' . "\n";
             if ($row->type == 7 && $remaining > 30) {
                 // Show bit of description for tools
                 if ($row->introtext) {
                     $out .= ': ' . \Hubzero\Utility\String::truncate($this->_encodeHtml(strip_tags($row->introtext)), $txtLength);
                 } else {
                     $out .= ': ' . \Hubzero\Utility\String::truncate($this->_encodeHtml(strip_tags($row->fulltxt)), $txtLength);
                 }
             }
             if ($tbl == 'itunes') {
                 $out .= ' - ' . Lang::txt('featured on') . ' <a href="/itunes">' . Lang::txt('iTunes') . ' U</a>' . "\n";
             } else {
                 $out .= ' - ' . Lang::txt('in') . ' <a href="' . Route::url('index.php?option=com_resources&type=' . $normalized) . '">' . $row->typetitle . '</a>' . "\n";
             }
             $out .= '<div class="clear"></div>' . "\n";
             break;
     }
     return $out;
 }
Ejemplo n.º 8
0
 /**
  * Preview the resource
  *
  * @return     void
  */
 public function previewTask()
 {
     // Incoming
     $alias = Request::getVar('app', '');
     $version = Request::getVar('editversion', 'dev');
     $rid = Request::getInt('rid', 0);
     // Load the tool
     $obj = new \Components\Tools\Tables\Tool($this->database);
     $this->_toolid = $obj->getToolId($alias);
     if (!$this->_toolid) {
         // not a tool resource page
         App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=pipeline'));
         return;
     }
     // Make sure user is authorized to go further
     if (!$this->_checkAccess($this->_toolid)) {
         App::abort(403, Lang::txt('COM_TOOLS_ALERTNOTAUTH'));
         return;
     }
     // Get tool version (dev or current) information
     $obj->getToolStatus($this->_toolid, $this->_option, $status, $version);
     // Instantiate our tag object
     $tagcloud = new \Components\Resources\Helpers\Tags($rid);
     $tags = Request::getVar('tags', '', 'post');
     $tagfa = Request::getVar('tagfa', '', 'post');
     // Process new tags
     $newtags = '';
     if ($tagfa) {
         $newtags = $tagfa . ', ';
     }
     if ($tags) {
         $newtags .= $tags;
     }
     $tagcloud->setTags($newtags, User::get('id'));
     // Get some needed libraries
     include_once PATH_CORE . DS . 'components' . DS . 'com_resources' . DS . 'helpers' . DS . 'html.php';
     // Load the resource object
     $resource = new \Components\Resources\Tables\Resource($this->database);
     $resource->loadAlias($alias);
     if (!User::isGuest()) {
         $xgroups = \Hubzero\User\Helper::getGroups(User::get('id'), 'all');
         // Get the groups the user has access to
         $usersgroups = $this->_getUsersGroups($xgroups);
     } else {
         $usersgroups = array();
     }
     // Get updated version
     $objV = new \Components\Tools\Tables\Version($this->database);
     $thistool = $objV->getVersionInfo('', $version, $resource->alias, '');
     $thistool = $thistool ? $thistool[0] : '';
     // Replace resource info with requested version
     $objV->compileResource($thistool, '', $resource, 'dev', $this->rconfig);
     // get language library
     $lang = Lang::getRoot();
     if (!$lang->load(strtolower('com_resources'), JPATH_BASE)) {
         $this->setError(Lang::txt('COM_TOOLS_ERROR_LOADING_LANGUAGE'));
     }
     // Set the document title
     $this->view->title = Lang::txt(strtoupper($this->_option)) . ': ' . Lang::txt('COM_TOOLS_PREVIEW_TOOL_PAGE') . ' (' . $resource->alias . ')';
     Document::setTitle($this->view->title);
     // Set the document pathway (breadcrumbs)
     if (Pathway::count() <= 0) {
         Pathway::append(Lang::txt(strtoupper($this->_name)), 'index.php?option=' . $this->_option);
     }
     if (Pathway::count() <= 1) {
         Pathway::append(Lang::txt('COM_TOOLS_STATUS_FOR', $thistool->toolname), 'index.php?option=' . $this->_option . '&controller=pipeline&task=status&app=' . $alias);
         Pathway::append(Lang::txt('COM_TOOLS_EDIT_TOOL_PAGE'), 'index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&app=' . $alias . '&task=start&step=1');
     }
     $this->view->toolid = $this->_toolid;
     $this->view->step = 5;
     $this->view->version = $version;
     $this->view->resource = $resource;
     $this->view->config = $this->rconfig;
     $this->view->usersgroups = $usersgroups;
     $this->view->status = $status;
     // Pass error messages to the view
     foreach ($this->getErrors() as $error) {
         $this->view->setError($error);
     }
     // Output HTML
     $this->view->display();
 }
Ejemplo n.º 9
0
 /**
  * Display a list of screenshots for this entry
  *
  * @param      integer $rid     Resource ID
  * @param      string  $version Tool version
  * @return     void
  */
 public function displayTask($rid = NULL, $version = NULL)
 {
     $this->view->setLayout('display');
     // Incoming
     if (!$rid) {
         $rid = Request::getInt('rid', 0);
     }
     if (!$version) {
         $version = Request::getVar('version', 'dev');
     }
     // Ensure we have an ID to work with
     if (!$rid) {
         App::abort(500, Lang::txt('COM_TOOLS_CONTRIBUTE_NO_ID'));
         return;
     }
     // Get resource information
     $resource = new \Components\Resources\Tables\Resource($this->database);
     $resource->load($rid);
     // Get version id
     $objV = new \Components\Tools\Tables\Version($this->database);
     $vid = $objV->getVersionIdFromResource($rid, $version);
     // Do we have a published tool?
     $this->view->published = $objV->getCurrentVersionProperty($resource->alias, 'id');
     // Get screenshot information for this resource
     $ss = new \Components\Resources\Tables\Screenshot($this->database);
     $this->view->shots = $ss->getScreenshots($rid, $vid);
     // Build paths
     include_once PATH_CORE . DS . 'components' . DS . 'com_resources' . DS . 'helpers' . DS . 'html.php';
     $path = \Components\Resources\Helpers\Html::build_path($resource->created, $rid, '');
     $this->view->upath = PATH_APP . DS . trim($this->rconfig->get('uploadpath'), DS) . $path;
     $this->view->wpath = DS . trim($this->rconfig->get('uploadpath'), DS) . $path;
     if ($vid) {
         $this->view->upath .= DS . $vid;
         $this->view->wpath .= DS . $vid;
     }
     // Make sure wpath is preceded by app
     if (substr($this->view->wpath, 0, 4) != DS . 'app') {
         $this->view->wpath = DS . 'app' . $this->view->wpath;
     }
     // get config
     $this->view->cparams = Component::params('com_resources');
     $this->view->version = $version;
     $this->view->rid = $rid;
     foreach ($this->getErrors() as $error) {
         $this->view->setError($error);
     }
     // Output HTML
     $this->view->display();
 }
Ejemplo n.º 10
0
 /**
  * Record Tool Usage
  *
  * @param		$tool		Alias of tool
  * @param		$userid		User ID
  *
  * @return 		BOOL
  */
 public static function recordToolUsage($tool, $userid = '')
 {
     //include needed files
     include_once dirname(__DIR__) . DS . 'tables' . DS . 'version.php';
     include_once dirname(__DIR__) . DS . 'tables' . DS . 'recent.php';
     //instantiate needed objects
     $database = \App::get('db');
     //load tool version
     $toolVersion = new \Components\Tools\Tables\Version($database);
     $toolVersion->loadFromName($tool);
     //make sure we have a user id
     if (!$userid) {
         $userid = User::get('id');
     }
     //get recent tools
     $recentTool = new \Components\Tools\Tables\Recent($database);
     $rows = $recentTool->getRecords($userid);
     //check to see if any recently used tools are this one
     $thisapp = 0;
     for ($i = 0, $n = count($rows); $i < $n; $i++) {
         if ($tool == trim($rows[$i]->tool)) {
             $thisapp = $rows[$i]->id;
         }
     }
     // Get the oldest entry. We may need this later.
     $oldest = end($rows);
     //createed date
     $created = Date::toSql();
     // Check if any recent tools are the same as the one just launched
     if ($thisapp) {
         // There was one, so just update its creation time
         $recentTool->id = $thisapp;
         $recentTool->uid = $userid;
         $recentTool->tool = $tool;
         $recentTool->created = $created;
     } else {
         // Check if we've reached 5 recent tools or not
         if (count($rows) < 5) {
             // Still under 5, so insert a new record
             $recentTool->uid = $userid;
             $recentTool->tool = $tool;
             $recentTool->created = $created;
         } else {
             // We reached the limit, so update the oldest entry effectively replacing it
             $recentTool->id = $oldest->id;
             $recentTool->uid = $userid;
             $recentTool->tool = $tool;
             $recentTool->created = $created;
         }
     }
     //store usage
     if (!$recentTool->store()) {
         return false;
     }
     return true;
 }
Ejemplo n.º 11
0
 /**
  * Update a tool version
  *
  * @return     void
  */
 public function updateTask()
 {
     // get vars
     if (!$this->_toolid) {
         $this->_toolid = Request::getInt('toolid', 0);
     }
     // Create a Tool object
     $obj = new \Components\Tools\Tables\Tool($this->database);
     // do we have an alias?
     if ($this->_toolid == 0) {
         if ($alias = Request::getVar('app', '')) {
             $this->_toolid = $obj->getToolId($alias);
         }
     }
     if (!$this->_error) {
         $this->_error = Request::getVar('error', '');
     }
     $error = '';
     //$id = $this->_toolid;
     // make sure user is authorized to go further
     if (!$this->_checkAccess($this->_toolid)) {
         App::abort(403, Lang::txt('COM_TOOLS_ALERTNOTAUTH'));
         return;
     }
     $newstate = Request::getVar('newstate', '');
     $priority = Request::getVar('priority', 3);
     $comment = Request::getVar('comment', '');
     $access = Request::getInt('access', 0);
     $newversion = Request::getVar('newversion', '');
     $editversion = Request::getVar('editversion', 'dev');
     $hzt = \Components\Tools\Models\Tool::getInstance($this->_toolid);
     $hztv = $hzt->getRevision($editversion);
     $oldstatus = $hztv ? $hztv->toArray() : array();
     $oldstatus['toolstate'] = $hzt->state;
     if ($newstate && !intval($newstate)) {
         $newstate = \Components\Tools\Helpers\Html::getStatusNum($newstate);
     }
     if (intval($newstate) && $newstate != $oldstatus['toolstate']) {
         Log::debug(__FUNCTION__ . "() state changing");
         if ($newstate == \Components\Tools\Helpers\Html::getStatusNum('Approved') && \Components\Tools\Models\Tool::validateVersion($oldstatus['version'], $error, $hzt->id)) {
             $this->_error = $error;
             Log::debug(__FUNCTION__ . "() state changing to approved, action confirm");
             $this->_action = 'confirm';
             $this->_task = Lang::txt('COM_TOOLS_CONTRIBTOOL_APPROVE_TOOL');
             $this->versionsTask();
             return;
         } else {
             if ($newstate == \Components\Tools\Helpers\Html::getStatusNum('Approved')) {
                 $this->_error = $error;
                 Log::debug(__FUNCTION__ . "() state changing to approved, action new");
                 $this->_action = 'new';
                 $this->_task = Lang::txt('COM_TOOLS_CONTRIBTOOL_APPROVE_TOOL');
                 $this->versionsTask();
                 return;
             } else {
                 if ($newstate == \Components\Tools\Helpers\Html::getStatusNum('Published')) {
                     Log::debug(__FUNCTION__ . "() state changing to published");
                     $hzt->published = '1';
                 }
             }
         }
         $this->_error = $error;
         // update dev screenshots of a published tool changes status
         if ($oldstatus['state'] == \Components\Tools\Helpers\Html::getStatusNum('Published')) {
             // Create a Tool Version object
             $objV = new \Components\Tools\Tables\Version($this->database);
             Log::debug(__FUNCTION__ . "() state changing away from  published");
             // Get version ids
             $rid = \Components\Tools\Models\Tool::getResourceId($hzt->toolname, $hzt->id);
             $to = $objV->getVersionIdFromResource($rid, 'dev');
             $from = $objV->getVersionIdFromResource($rid, 'current');
             $dev_hztv = $hzt->getRevision('dev');
             $current_hztv = $hzt->getRevision('current');
             Log::debug("update: to={$to} from={$from}   dev=" . $dev_hztv->id . " current=" . $current_hztv->id);
             if ($to && $from) {
                 require_once __DIR__ . DS . 'screenshots.php';
                 $ss = new Screenshots();
                 $ss->transfer($from, $to, $rid);
             }
         }
         // If the tool was cancelled ...
         if ($oldstatus['state'] == \Components\Tools\Helpers\Html::getStatusNum('Abandoned')) {
             include_once __DIR__ . DS . 'resource.php';
             $r = new \Components\Resources\Tables\Resource($this->database);
             $r->loadAlias($hzt->toolname);
             if ($r && $r->id) {
                 $rstatus = 2;
                 if ($newstate == \Components\Tools\Helpers\Html::getStatusNum('Published')) {
                     $rstatus = 1;
                 }
                 $resource = new Resource();
                 $resource->updatePage($r->id, $oldstatus, $rstatus);
             }
         }
         Log::debug(__FUNCTION__ . "() state changing to {$newstate}");
         $hzt->state = $newstate;
         $hzt->state_changed = Date::toSql();
     }
     // if priority changes
     if (intval($priority) && $priority != $oldstatus['priority']) {
         $hzt->priority = $priority;
     }
     // save tool info
     $hzt->update();
     $hztv->update();
     //@FIXME: look
     // get tool status after updates
     $status = $hztv->toArray();
     $status['toolstate'] = $hzt->state;
     // update history ticket
     Log::debug(__FUNCTION__ . "() before newUpdateTicket test");
     if ($oldstatus != $status || !empty($comment)) {
         Log::debug(__FUNCTION__ . "() before newUpdateTicket");
         $this->_newUpdateTicket($hzt->id, $hzt->ticketid, $oldstatus, $status, $comment, $access, 1);
         Log::debug(__FUNCTION__ . "() after newUpdateTicket");
     }
     $this->_msg = Lang::txt('COM_TOOLS_NOTICE_STATUS_CHANGED');
     $this->statusTask();
 }
Ejemplo n.º 12
0
 /**
  * Method to view tool session
  *
  * @apiMethod GET
  * @apiUri    /tools/{session}
  * @return    void
  */
 public function readTask()
 {
     //get the userid and attempt to load user profile
     $userid = App::get('authn')['user_id'];
     $result = User::getInstance($userid);
     //make sure we have a user
     if (!$result->get('id')) {
         throw new Exception(Lang::txt('Unable to find user.'), 404);
     }
     //include needed tool libs
     include_once dirname(dirname(__DIR__)) . DS . 'tables' . DS . 'version.php';
     require_once dirname(dirname(__DIR__)) . DS . 'tables' . DS . 'session.php';
     require_once dirname(dirname(__DIR__)) . DS . 'tables' . DS . 'viewperm.php';
     //instantiate db objects
     $database = \App::get('db');
     $mwdb = \Components\Tools\Helpers\Utils::getMWDBO();
     //get request vars
     $sessionid = Request::getVar('sessionid', '');
     $ip = Request::ip();
     //make sure we have the session
     if (!$sessionid) {
         throw new Exception(Lang::txt('Session ID Needed'), 400);
     }
     //create app object
     $app = new stdClass();
     $app->sess = $sessionid;
     $app->ip = $ip;
     //load the session
     $ms = new \Components\Tools\Models\Middleware\Session($mwdb);
     $row = $ms->loadSession($app->sess);
     //if we didnt find a session
     if (!is_object($row) || !$row->appname) {
         throw new Exception(Lang::txt('Session Doesn\'t Exist.'), 404);
     }
     //get the version
     if (strstr($row->appname, '_')) {
         $v = substr(strrchr($row->appname, '_'), 1);
         $v = str_replace('r', '', $v);
         Request::setVar('version', $v);
     }
     //load tool version
     $tv = new \Components\Tools\Tables\Version($database);
     $parent_toolname = $tv->getToolname($row->appname);
     $toolname = $parent_toolname ? $parent_toolname : $row->appname;
     $tv->loadFromInstance($row->appname);
     //command to run on middleware
     $command = "view user="******" ip=" . $app->ip . " sess=" . $app->sess;
     //app vars
     $app->caption = $row->sessname;
     $app->name = $row->appname;
     $app->username = $row->username;
     // Get plugins
     Plugin::import('mw', $app->name);
     // Trigger any events that need to be called before session start
     Event::trigger('mw.onBeforeSessionStart', array($toolname, $tv->revision));
     // Call the view command
     $status = \Components\Tools\Helpers\Utils::middleware($command, $output);
     // Trigger any events that need to be called after session start
     Event::trigger('mw.onAfterSessionStart', array($toolname, $tv->revision));
     //add the session id to the result
     $output->session = $sessionid;
     //add tool title to result
     $output->tool = $tv->title;
     $output->session_title = $app->caption;
     $output->owner = $row->viewuser == $row->username ? 1 : 0;
     $output->readonly = $row->readonly == 'Yes' ? 1 : 0;
     //return result
     if ($status) {
         $this->send($output);
     }
 }
Ejemplo n.º 13
0
 /**
  * Display a license for a resource
  *
  * @return     void
  */
 public function licenseTask()
 {
     // Get tool instance
     $resource = Request::getInt('resource', 0);
     $tool = Request::getVar('tool', '');
     // Ensure we have a tool to work with
     if (!$tool && !$resource) {
         App::abort(404, Lang::txt('COM_RESOURCES_RESOURCE_NOT_FOUND'));
         return;
     }
     if ($tool) {
         // Load the tool version
         $row = new \Components\Tools\Tables\Version($this->database);
         $row->loadFromInstance($tool);
     } else {
         $row = new Resource($this->database);
         $row->load($resource);
         include_once dirname(dirname(__DIR__)) . DS . 'tables' . DS . 'license.php';
         $rt = new License($this->database);
         $rt->load('custom' . $resource);
         $row->license = stripslashes($rt->text);
     }
     // Output HTML
     if (!$row) {
         App::abort(404, Lang::txt('COM_RESOURCES_RESOURCE_NOT_FOUND'));
         return;
     }
     // Set the page title
     $this->view->title = stripslashes($row->title) . ': ' . Lang::txt('COM_RESOURCES_LICENSE');
     // Write title
     Document::setTitle($this->view->title);
     // Instantiate a new view
     $this->view->config = $this->config;
     $this->view->row = $row;
     $this->view->tool = $tool;
     $this->view->no_html = Request::getVar('no_html', 0);
     // Output HTML
     foreach ($this->getErrors() as $error) {
         $this->view->setError($error);
     }
     $this->view->setName('license')->setLayout('default')->display();
 }
Ejemplo n.º 14
0
 /**
  * Publish a tool
  *
  * @return     void
  */
 public function publishTask()
 {
     // Set the layout (note: all the views for this controller use the same layout)
     $this->view->setLayout('display');
     // Create a Tool object
     $obj = new \Components\Tools\Tables\Tool($this->database);
     // Do we have an alias?
     if ($alias = Request::getVar('app', '')) {
         $this->_toolid = $obj->getToolId($alias);
     }
     // Do we have a tool ID
     if (!$this->_toolid) {
         App::abort(403, Lang::txt('COM_TOOLS_ERROR_TOOL_NOT_FOUND'));
         return;
     }
     // Get the tool status
     $obj->getToolStatus($this->_toolid, $this->_option, $status, 'dev');
     // Check for a status
     if (count($status) <= 0) {
         App::abort(500, Lang::txt('COM_TOOLS_ERR_CANNOT_RETRIEVE'));
         return;
     }
     $result = true;
     Log::debug("publish(): checkpoint 1:{$result}");
     // get config
     // Create a Tool Version object
     $objV = new \Components\Tools\Tables\Version($this->database);
     $objV->getToolVersions($this->_toolid, $tools, '', 1);
     // make checks
     if (!is_numeric($status['revision'])) {
         // bad format
         $result = false;
         $this->setError(Lang::txt('COM_TOOLS_ERR_MISSING_REVISION_OR_BAD_FORMAT'));
     } else {
         if (count($tools) > 0 && $status['revision']) {
             // check for duplicate revision
             foreach ($tools as $t) {
                 if ($t->revision == $status['revision']) {
                     $result = false;
                     $this->setError(Lang::txt('COM_TOOLS_ERR_REVISION_EXISTS') . ' ' . $status['revision']);
                 }
             }
             // check that revision number is greater than in previous version
             $currentrev = $objV->getCurrentVersionProperty($status['toolname'], 'revision');
             if ($currentrev && intval($currentrev) > intval($status['revision'])) {
                 $result = false;
                 $this->setError(Lang::txt('COM_TOOLS_ERR_REVISION_GREATER'));
             }
         }
     }
     // Log checkpoint
     Log::debug("publish(): checkpoint 2:{$result}, check revision");
     // check if version is valid
     if (!\Components\Tools\Models\Tool::validateVersion($status['version'], $error_v, $this->_toolid)) {
         $result = false;
         $this->setError($error_v);
     }
     // Log checkpoint
     Log::debug("publish(): checkpoint 3:{$result}, running finalize tool");
     // Run finalizetool
     if (!$this->getError()) {
         if ($this->_finalizeTool($out)) {
             $this->setMessage(Lang::txt('COM_TOOLS_Version finalized.'));
         } else {
             $this->setError($out);
             $result = false;
         }
     }
     Log::debug("publish(): checkpoint 4:{$result}, running doi stuff");
     // Register DOI handle
     if ($result && $this->config->get('new_doi', 0)) {
         include_once PATH_CORE . DS . 'components' . DS . 'com_resources' . DS . 'tables' . DS . 'doi.php';
         // Collect metadata
         $url = Request::base() . ltrim(Route::url('index.php?option=com_resources&id=' . $status['resourceid'] . '&rev=' . $status['revision']), DS);
         // Check if DOI exists for this revision
         $objDOI = new \Components\Resources\Tables\Doi($this->database);
         $bingo = $objDOI->getDoi($status['resourceid'], $status['revision'], '', 1);
         // DOI already exists for this revision
         if ($bingo) {
             $this->setError(Lang::txt('COM_TOOLS_ERR_DOI_ALREADY_EXISTS') . ': ' . $bingo);
         } else {
             // Get latest DOI label
             $latestdoi = $objDOI->getLatestDoi($status['resourceid']);
             $newlabel = $latestdoi ? intval($latestdoi) + 1 : 1;
             // Collect metadata
             $metadata = array('targetURL' => $url, 'title' => htmlspecialchars(stripslashes($status['title'])), 'version' => $status['version'], 'abstract' => htmlspecialchars(stripslashes($status['description'])));
             // Get authors
             $objA = new \Components\Tools\Tables\Author($this->database);
             $authors = $objA->getAuthorsDOI($status['resourceid']);
             // Register DOI
             $doiSuccess = $objDOI->registerDOI($authors, $this->config, $metadata, $doierr);
             // Save [new] DOI record
             if ($doiSuccess) {
                 if (!$objDOI->loadDOI($status['resourceid'], $status['revision'])) {
                     if ($objDOI->saveDOI($status['revision'], $newlabel, $status['resourceid'], $status['toolname'], 0, $doiSuccess)) {
                         $this->setMessage(Lang::txt('COM_TOOLS_SUCCESS_DOI_CREATED') . ' ' . $doiSuccess);
                     } else {
                         $this->setError(Lang::txt('COM_TOOLS_ERR_DOI_STORE_FAILED'));
                         $result = false;
                     }
                 } else {
                     $this->setError(Lang::txt('COM_TOOLS_DOI already exists: ') . $objDOI->doi);
                 }
             } else {
                 $this->setError(Lang::txt('COM_TOOLS_ERR_DOI_STORE_FAILED'));
                 $this->setError($doierr);
                 $result = false;
             }
         }
     }
     if ($result) {
         $invokedir = rtrim($this->config->get('invokescript_dir', DS . 'apps'), "\\/");
         $hzt = \Components\Tools\Models\Tool::getInstance($this->_toolid);
         $hztv_cur = $hzt->getCurrentVersion();
         $hztv_dev = $hzt->getDevelopmentVersion();
         Log::debug("publish(): checkpoint 6:{$result}, running database stuff");
         // create tool instance in the database
         $newtool = $status['toolname'] . '_r' . $status['revision'];
         // get version id
         $currentid = is_object($hztv_cur) ? $hztv_cur->id : null;
         $new = $currentid ? 0 : 1;
         $devid = $hztv_dev->id;
         $exportmap = array('@OPEN' => null, '@GROUP' => null, '@US' => 'us', '@PU' => 'pu', '@D1' => 'd1');
         $new_hztv = \Components\Tools\Models\Version::createInstance($status['toolname'], $newtool);
         $new_hztv->toolname = $status['toolname'];
         $new_hztv->instance = $newtool;
         $new_hztv->toolid = $this->_toolid;
         $new_hztv->state = 1;
         $new_hztv->title = $status['title'];
         $new_hztv->version = $status['version'];
         $new_hztv->revision = $status['revision'];
         $new_hztv->description = $status['description'];
         $new_hztv->toolaccess = $status['exec'];
         $new_hztv->codeaccess = $status['code'];
         $new_hztv->wikiaccess = $status['wiki'];
         $new_hztv->vnc_geometry = $status['vncGeometry'];
         $new_hztv->vnc_command = $invokedir . DS . $status['toolname'] . DS . 'r' . $status['revision'] . DS . 'middleware' . DS . 'invoke -T r' . $status['revision'];
         $new_hztv->mw = $status['mw'];
         $new_hztv->released = Date::toSql();
         $new_hztv->released_by = User::get('username');
         $new_hztv->license = $status['license'];
         $new_hztv->fulltxt = $status['fulltxt'];
         $new_hztv->exportControl = $exportmap[strtoupper($status['exec'])];
         $new_hztv->owner = $hztv_dev->owner;
         $new_hztv->member = $hztv_dev->member;
         $new_hztv->vnc_timeout = $hztv_dev->vnc_timeout;
         $new_hztv->hostreq = $hztv_dev->hostreq;
         $new_hztv->params = $status['params'];
         if (!$new_hztv->update()) {
             $this->setError(Lang::txt('COM_TOOLS_ERROR_UPDATING_INSTANCE'));
             $result = false;
         } else {
             $this->_setTracAccess($new_hztv->toolname, $new_hztv->codeaccess, $new_hztv->wikiaccess);
             // update tool entry
             $hzt = \Components\Tools\Models\Tool::getInstance($this->_toolid);
             $hzt->add('version', $new_hztv->instance);
             $hzt->update();
             if ($hzt->published != 1) {
                 $hzt->published = 1;
                 // save tool info
                 if (!$hzt->update()) {
                     $this->setError(Lang::txt('COM_TOOLS_ERROR_UPDATING_INSTANCE'));
                 } else {
                     $this->setMessage(Lang::txt('COM_TOOLS_NOTICE_TOOL_MARKED_PUBLISHED'));
                 }
             }
             // unpublish previous version
             if (!$new) {
                 if ($hzt->unpublishVersion($hztv_cur->instance)) {
                     $this->setMessage(Lang::txt('COM_TOOLS_NOTICE_UNPUBLISHED_PREV_VERSION_DB'));
                 } else {
                     $this->setError(Lang::txt('COM_TOOLS_ERR_FAILED_TO_UNPUBLISH_PREV_VERSION_DB'));
                 }
             }
             // get version id
             $currentid = $new_hztv->id;
             // save authors for this version
             $objA = new \Components\Tools\Tables\Author($this->database);
             if ($objA->saveAuthors($status['developers'], $currentid, $status['resourceid'], $status['revision'], $status['toolname'])) {
                 $this->setMessage(Lang::txt('COM_TOOLS_AUTHORS_SAVED'));
             } else {
                 $this->setError(Lang::txt('COM_TOOLS_ERROR_SAVING_AUTHORS', $currentid));
             }
             // transfer screenshots
             if ($devid && $currentid) {
                 include_once __DIR__ . DS . 'screenshots.php';
                 $screenshots = new Screenshots();
                 if ($screenshots->transfer($devid, $currentid, $status['resourceid'])) {
                     $this->setMessage(Lang::txt('COM_TOOLS_SCREENSHOTS_TRANSFERRED'));
                 } else {
                     $this->setError(Lang::txt('COM_TOOLS_ERROR_TRANSFERRING_SCREENSHOTS'));
                 }
             }
             include_once __DIR__ . DS . 'resource.php';
             $resource = new Resource();
             // update and publish resource page
             $resource->updatePage($status['resourceid'], $status, '1', $new);
         }
     }
     Log::debug("publish(): checkpoint 7:{$result}, gather output");
     // Set errors to view
     foreach ($this->getErrors() as $error) {
         $this->view->setError($error);
     }
     // Set messages to view
     $this->view->messages = $this->getMessages();
     // Output HTML
     if (!($no_html = Request::getInt('no_html', 0))) {
         App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=pipeline&task=status&app=' . $alias));
         return;
     }
     $this->view->display();
 }
Ejemplo n.º 15
0
 /**
  * Save a question
  *
  * @return     void
  */
 public function saveqTask()
 {
     // Check for request forgeries
     Request::checkToken();
     // Login required
     if (User::isGuest()) {
         $this->setError(Lang::txt('COM_ANSWERS_PLEASE_LOGIN'));
         $this->loginTask();
         return;
     }
     if (!User::authorise('core.edit', $this->_option) && !User::authorise('core.create', $this->_option) && !User::authorise('core.manage', $this->_option)) {
         throw new Exception(Lang::txt('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN'), 403);
     }
     // Incoming
     $fields = Request::getVar('fields', array(), 'post', 'none', 2);
     $tags = Request::getVar('tags', '');
     if (!isset($fields['reward'])) {
         $fields['reward'] = 0;
     }
     // If offering a reward, do some checks
     if ($fields['reward']) {
         // Is it an actual number?
         if (!is_numeric($fields['reward'])) {
             throw new Exception(Lang::txt('COM_ANSWERS_REWARD_MUST_BE_NUMERIC'), 500);
         }
         // Are they offering more than they can afford?
         if ($fields['reward'] > $fields['funds']) {
             throw new Exception(Lang::txt('COM_ANSWERS_INSUFFICIENT_FUNDS'), 500);
         }
     }
     // clean input
     array_walk($fields, function (&$field, $key) {
         $field = \Hubzero\Utility\Sanitize::clean($field);
     });
     // Initiate class and bind posted items to database fields
     $row = new Question($fields['id']);
     if (!$row->bind($fields)) {
         throw new Exception($row->getError(), 500);
     }
     if ($fields['reward'] && $this->config->get('banking')) {
         $row->set('reward', 1);
     }
     // Store new content
     if (!Request::checkHoneypot()) {
         $this->setError(Lang::txt('JLIB_APPLICATION_ERROR_INVALID_CONTENT'));
         $this->newTask($row);
         return;
     }
     // Ensure the user added a tag
     if (!$tags) {
         $this->setError(Lang::txt('COM_ANSWERS_QUESTION_MUST_HAVE_TAG'));
         $this->newTask($row);
         return;
     }
     // We need to temporarily set this so the store() method
     // has access to the tags string to be able to run it
     // through spam checkers and validation.
     $row->set('tags', $tags);
     // Store new content
     if (!$row->store(true)) {
         Request::setVar('tag', $tags);
         $this->setError($row->getError());
         $this->newTask($row);
         return;
     }
     // Hold the reward for this question if we're banking
     if ($fields['reward'] && $this->config->get('banking')) {
         $BTL = new Teller($this->database, User::get('id'));
         $BTL->hold($fields['reward'], Lang::txt('COM_ANSWERS_HOLD_REWARD_FOR_BEST_ANSWER'), 'answers', $row->get('id'));
     }
     // Add the tags
     $row->tag($tags);
     // Get users who need to be notified on every question
     $apu = $this->config->get('notify_users', '');
     $apu = explode(',', $apu);
     $apu = array_map('trim', $apu);
     $receivers = array();
     // Get tool contributors if question is about a tool
     if ($tags) {
         $tags = preg_split("/[,;]/", $tags);
         if (count($tags) > 0) {
             require_once PATH_CORE . DS . 'components' . DS . 'com_tools' . DS . 'tables' . DS . 'author.php';
             require_once PATH_CORE . DS . 'components' . DS . 'com_tools' . DS . 'tables' . DS . 'version.php';
             $TA = new \Components\Tools\Tables\Author($this->database);
             $objV = new \Components\Tools\Tables\Version($this->database);
             foreach ($tags as $tag) {
                 if ($tag == '') {
                     continue;
                 }
                 if (preg_match('/tool:/', $tag)) {
                     $toolname = preg_replace('/tool:/', '', $tag);
                     if (trim($toolname)) {
                         $rev = $objV->getCurrentVersionProperty($toolname, 'revision');
                         $authors = $TA->getToolAuthors('', 0, $toolname, $rev);
                         if (count($authors) > 0) {
                             foreach ($authors as $author) {
                                 $receivers[] = $author->uidNumber;
                             }
                         }
                     }
                 }
             }
         }
     }
     if (!empty($apu)) {
         foreach ($apu as $u) {
             $user = User::getInstance($u);
             if ($user) {
                 $receivers[] = $user->get('id');
             }
         }
     }
     $receivers = array_unique($receivers);
     // Send the message
     if (!empty($receivers)) {
         // Send a message about the new question to authorized users (specified admins or related content authors)
         $from = array('email' => Config::get('mailfrom'), 'name' => Config::get('sitename') . ' ' . Lang::txt('COM_ANSWERS_ANSWERS'), 'multipart' => md5(date('U')));
         // Build the message subject
         $subject = Lang::txt('COM_ANSWERS_ANSWERS') . ', ' . Lang::txt('new question about content you author or manage');
         $message = array();
         // Plain text message
         $eview = new \Hubzero\Mail\View(array('name' => 'emails', 'layout' => 'question_plaintext'));
         $eview->option = $this->_option;
         $eview->sitename = Config::get('sitename');
         $eview->question = $row;
         $eview->id = $row->get('id', 0);
         $eview->boundary = $from['multipart'];
         $message['plaintext'] = $eview->loadTemplate(false);
         $message['plaintext'] = str_replace("\n", "\r\n", $message['plaintext']);
         // HTML message
         $eview->setLayout('question_html');
         $message['multipart'] = $eview->loadTemplate();
         $message['multipart'] = str_replace("\n", "\r\n", $message['multipart']);
         if (!Event::trigger('xmessage.onSendMessage', array('new_question_admin', $subject, $message, $from, $receivers, $this->_option))) {
             $this->setError(Lang::txt('COM_ANSWERS_MESSAGE_FAILED'));
         }
     }
     // Redirect to the question
     App::redirect(Route::url('index.php?option=' . $this->_option . '&task=question&id=' . $row->get('id')), Lang::txt('COM_ANSWERS_NOTICE_QUESTION_POSTED_THANKS'));
 }