Пример #1
0
 /**
  * Event call to get the latest records
  *
  * @param   integer  $num
  * @param   string   $dateField
  * @param   string   $sort
  * @return  array
  */
 public function onGetLatest($num = 5, $dateField = 'created', $sort = 'DESC')
 {
     $model = Resource::getLatest($num, $dateField, $sort)->rows()->toObject();
     $objects = array();
     foreach ($model as $m) {
         $object = new stdClass();
         $object->title = $m->title;
         $object->body = htmlspecialchars_decode($m->introtext);
         $object->date = Date::of($m->publish_up)->toLocal("F j, Y");
         $object->path = 'resources/' . $m->id;
         $object->id = $m->id;
         array_push($objects, $object);
     }
     return $objects;
 }
Пример #2
0
 /**
  * Display a list of authors
  *
  * @param   integer  $id  Resource ID
  * @return  void
  */
 public function displayTask($id = null)
 {
     // Incoming
     if (!$id) {
         $id = Request::getInt('id', 0);
     }
     // Ensure we have an ID to work with
     if (!$id) {
         App::abort(404, Lang::txt('CONTRIBUTE_NO_ID'));
     }
     // Get all contributors of this resource
     $resource = Resource::oneOrFail($id);
     $authors = $resource->authors()->ordered()->rows();
     // Get all roles for this resoruce type
     $roles = $resource->type()->roles()->rows();
     // Output view
     $this->view->set('config', $this->config)->set('id', $id)->set('contributors', $authors)->set('roles', $roles)->setErrors($this->getErrors())->setLayout('display')->display();
 }
Пример #3
0
 /**
  * Remove one or more types
  *
  * @return  void  Redirects back to main listing
  */
 public function removeTask()
 {
     // Check for request forgeries
     Request::checkToken();
     if (!User::authorise('core.delete', $this->_option)) {
         App::abort(403, Lang::txt('JERROR_ALERTNOAUTHOR'));
     }
     // Incoming (expecting an array)
     $ids = Request::getVar('id', array());
     $ids = !is_array($ids) ? array($ids) : $ids;
     // Ensure we have an ID to work with
     if (empty($ids)) {
         // Redirect with error message
         Notify::warning(Lang::txt('COM_RESOURCES_NO_ITEM_SELECTED'));
         return $this->cancelTask();
     }
     $i = 0;
     foreach ($ids as $id) {
         // Check if the type is being used
         $rt = Type::oneOrFail($id);
         $usage = Resource::all()->whereEquals('type', $id)->total();
         if ($usage) {
             Notify::error(Lang::txt('COM_RESOURCES_TYPE_BEING_USED', $id));
             continue;
         }
         // Delete the type
         if (!$rt->destroy()) {
             Notify::error($rt->getError());
             continue;
         }
         $i++;
     }
     if ($i) {
         Notify::success(Lang::txt('COM_RESOURCES_ITEMS_REMOVED', $i));
     }
     // Redirect
     $this->cancelTask();
 }
Пример #4
0
 /**
  * Display sessions
  *
  * @return  void
  */
 public function sessionsTask()
 {
     // Get filters
     $filters = array('appname' => urldecode(Request::getState($this->_option . '.' . $this->_controller . '.appname', 'appname', '')), 'sort' => Request::getState($this->_option . '.' . $this->_controller . '.sort', 'filter_order', 'start'), 'sort_Dir' => Request::getState($this->_option . '.' . $this->_controller . '.sortdir', 'filter_order_Dir', 'DESC'), 'limit' => Request::getState($this->_option . '.' . $this->_controller . '.limit', 'limit', Config::get('list_limit'), 'int'), 'start' => Request::getState($this->_option . '.' . $this->_controller . '.limitstart', 'limitstart', 0, 'int'));
     // Get the list of sessions
     $rows = array();
     // Get a count of all sessions (for pagination)
     $total = count($rows);
     // Get a list of all apps for the filters bar
     $apps = Resource::all()->whereEquals('type', $this->config->get('windows_type'))->rows();
     // Get a list of all active sessions for specified app
     $appname = Request::getVar('appname', '');
     $sessions = array();
     if (!empty($appname)) {
         exec('/usr/bin/hz-aws-appstream getappsessions --appid' . ' "' . $appname . '"', $rawsessions);
         $sessions = array();
         foreach ($rawsessions as $s) {
             $sessionsArray = explode("|", $s);
             if (sizeof($sessionsArray) == 4) {
                 $sessions[] = array("sessionid" => $sessionsArray[0], "status" => $sessionsArray[2], "opaquedata" => $sessionsArray[3]);
             }
             //else
             //	$sessions[] = array("sessionid" => $sessionsArray[0], "status" => "cannot parse", "opaquedata" => "cannot parse");
         }
         usort($sessions, function ($a, $b) {
             return strcmp($a['status'], $b['status']);
         });
     }
     // Output the HTML
     $this->view->set('filters', $filters)->set('rows', $rows)->set('apps', $apps)->set('sessions', $sessions)->set('total', 0)->setErrors($this->getErrors())->setLayout('sessions')->display();
 }
Пример #5
0
 /**
  * Check if the review step is completed
  *
  * @param   integer  $id  Resource ID
  * @return  integer  1 = step completed, 0 = not completed
  */
 public function step_review_check($id)
 {
     $resource = Resource::oneOrNew($id);
     if ($resource->get('published') == 1) {
         return 1;
     }
     return 0;
 }
Пример #6
0
 /**
  * Display an upload form and file listing
  *
  * @return  void
  */
 public function displayTask()
 {
     // Incoming directory (this should be a path built from a resource ID and its creation year/month)
     $resource = Request::getInt('resource', 0);
     if (!$resource) {
         echo '<p class="error">' . Lang::txt('No resource ID provided.') . '</p>';
         return;
     }
     if ($resource < 1 || substr($resource, 0, 4) == '9999') {
         $row = Resource::blank();
     } else {
         $row = Resource::oneOrFail($resource);
     }
     $row->set('id', $resource);
     // Incoming sub-directory
     $subdir = Request::getVar('subdir', '');
     // Allow for temp resource uploads
     if (!$row->get('created') || $row->get('created') == '0000-00-00 00:00:00') {
         $row->set('created', Date::format('Y-m-d 00:00:00'));
     }
     $path = $row->filespace() . DS . 'media';
     $folders = array();
     $docs = array();
     if (is_dir($path)) {
         // Loop through all files and separate them into arrays of images, folders, and other
         $dirIterator = new \DirectoryIterator($path);
         foreach ($dirIterator as $file) {
             if ($file->isDot()) {
                 continue;
             }
             $name = $file->getFilename();
             if ($file->isDir()) {
                 $folders[$path . DS . $name] = $name;
                 continue;
             }
             if ($file->isFile()) {
                 if ('cvs' == strtolower($name) || '.svn' == strtolower($name)) {
                     continue;
                 }
                 $docs[$path . DS . $name] = $name;
             }
         }
         ksort($folders);
         ksort($docs);
     }
     // Output the HTML
     $this->view->set('resource', $resource)->set('row', $row)->set('subdir', $subdir)->set('path', $path)->set('docs', $docs)->set('folders', $folders)->setErrors($this->getErrors())->setLayout('display')->display();
 }
Пример #7
0
 /**
  * Display a list of attachments
  *
  * @param   integer  $id  Resource ID
  * @return  void
  */
 public function displayTask($id = null)
 {
     // Incoming
     if (!$id) {
         $id = Request::getInt('id', 0);
     }
     // Ensure we have an ID to work with
     if (!$id) {
         App::abort(404, Lang::txt('CONTRIBUTE_NO_ID'));
     }
     // Initiate a resource
     $resource = Resource::oneOrFail($id);
     $children = $resource->children()->order('ordering', 'ASC')->rows();
     // Output HTML
     $this->view->set('config', $this->config)->set('children', $children)->set('path', '')->set('id', $id)->setErrors($this->getErrors())->setLayout('display')->display();
 }