예제 #1
0
 /**
  * Display module content
  *
  * @return     void
  */
 public function display()
 {
     include_once Component::path('com_tools') . DS . 'helpers' . DS . 'utils.php';
     include_once Component::path('com_tools') . DS . 'tables' . DS . 'job.php';
     include_once Component::path('com_tools') . DS . 'tables' . DS . 'view.php';
     include_once Component::path('com_tools') . DS . 'tables' . DS . 'viewperm.php';
     include_once Component::path('com_tools') . DS . 'tables' . DS . 'session.php';
     include_once Component::path('com_tools') . DS . 'tables' . DS . 'host.php';
     include_once Component::path('com_tools') . DS . 'tables' . DS . 'hosttype.php';
     include_once Component::path('com_tools') . DS . 'tables' . DS . 'recent.php';
     include_once __DIR__ . DS . 'app.php';
     $params = $this->params;
     $mconfig = Component::params('com_tools');
     // Ensure we have a connection to the middleware
     $this->can_launch = true;
     if (!$mconfig->get('mw_on') || $mconfig->get('mw_on') > 1 && !User::authorize('com_tools', 'manage')) {
         $this->can_launch = false;
     }
     // See if we have an incoming string of favorite tools
     // This should only happen on AJAX requests
     $this->fav = Request::getVar('fav', '');
     $this->no_html = Request::getVar('no_html', 0);
     $rconfig = Component::params('com_resources');
     $this->supportedtag = $rconfig->get('supportedtag');
     $database = \App::get('db');
     if ($this->supportedtag) {
         include_once Component::path('com_resources') . DS . 'helpers' . DS . 'tags.php';
         $this->rt = new \Components\Resources\Helpers\Tags(0);
         $this->supportedtagusage = $this->rt->getTagUsage($this->supportedtag, 'alias');
     }
     if ($this->fav || $this->no_html) {
         // We have a string of tools! This means we're updating the
         // favorite tools pane of the module via AJAX
         $favs = explode(',', $this->fav);
         $favs = array_map('trim', $favs);
         $this->favtools = $this->fav ? $this->_getToollist($favs) : array();
     } else {
         // Get a list of recent tools
         $rt = new \Components\Tools\Tables\Recent($database);
         $rows = $rt->getRecords(User::get('id'));
         $recent = array();
         if (!empty($rows)) {
             foreach ($rows as $row) {
                 $recent[] = $row->tool;
             }
         }
         // Get the user's list of favorites
         $fav = $params->get('favs');
         if ($fav) {
             $favs = explode(',', $fav);
         } else {
             $favs = array();
         }
         $this->favs = $favs;
         // Get a list of applications that the user might invoke.
         $this->rectools = $this->_getToollist($recent);
         $this->favtools = $this->_getToollist($favs);
         $this->alltools = $this->_getToollist();
     }
     require $this->getLayoutPath();
 }
예제 #2
0
 /**
  * Records the event of the current tool having been used
  * This is used for the favorites list of the My Tools module
  *
  * @param      string  $app Name of app called
  * @param      integer $uid User ID
  * @return     void
  */
 private function _recordUsage($app, $uid)
 {
     include_once dirname(dirname(__DIR__)) . DS . 'tables' . DS . 'version.php';
     $tool = new \Components\Tools\Tables\Version($this->database);
     $tool->loadFromName($app);
     $created = Date::toSql();
     // Get a list of all their recent tools
     include_once dirname(dirname(__DIR__)) . DS . 'tables' . DS . 'recent.php';
     $rt = new \Components\Tools\Tables\Recent($this->database);
     $rows = $rt->getRecords($uid);
     $thisapp = 0;
     for ($i = 0, $n = count($rows); $i < $n; $i++) {
         if ($app == trim($rows[$i]->tool)) {
             $thisapp = $rows[$i]->id;
         }
     }
     // Get the oldest entry. We may need this later.
     $oldest = end($rows);
     // Check if any recent tools are the same as the one just launched
     if ($thisapp) {
         // There was one, so just update its creation time
         $rt->id = $thisapp;
         $rt->uid = $uid;
         $rt->tool = $app;
         $rt->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
             $rt->uid = $uid;
             $rt->tool = $app;
             $rt->created = $created;
         } else {
             // We reached the limit, so update the oldest entry effectively replacing it
             $rt->id = $oldest->id;
             $rt->uid = $uid;
             $rt->tool = $app;
             $rt->created = $created;
         }
     }
     if (!$rt->store()) {
         App::abort(500, $rt->getError());
         return;
     }
 }
예제 #3
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;
 }