Beispiel #1
0
 /**
  * Determine task and execute it
  * 
  * @return  void
  */
 public function execute()
 {
     foreach (array('SCRIPT_URL', 'URL', 'REDIRECT_SCRIPT_URL', 'REDIRECT_URL') as $k) {
         if (isset($_SERVER[$k])) {
             $this->base = $_SERVER[$k];
             break;
         }
     }
     $base = explode('/', $this->base);
     $base = array_map('urldecode', $base);
     $base = array_map('trim', $base);
     foreach ($base as $i => $segment) {
         $segment = trim($segment, '"');
         $segment = trim($segment, "'");
         if (strstr($segment, '=')) {
             unset($base[$i]);
             continue;
         }
         $segment = urlencode($segment);
         $base[$i] = $segment;
     }
     $this->base = implode('/', $base);
     $this->req = new Request($_GET);
     $this->conf = Configuration::instance();
     $this->perPage = \Config::get('list_limit', 50);
     $this->registerTask('page', 'index');
     $this->registerTask('__default', 'index');
     // Try to execute
     try {
         Pathway::append(Lang::txt('COM_SEARCH'), 'index.php?option=' . $this->_option);
         parent::execute();
     } catch (Exception $ex) {
         // Log the error
         Log::error($ex->getMessage());
         // If not displaying inline...
         if (!defined('HG_INLINE')) {
             App::get('session')->set('searchfallback', time() + 60);
             // Redirect back to this component wil the fallback flag set
             // so it knows to load the default, basic controller.
             $terms = \Request::getVar('terms', '', 'get');
             App::redirect(Route::url('index.php?option=' . $this->_option . ($terms ? '&terms=' . $terms : ''), false), App::get('config')->get('debug') ? $ex->getMessage() : null, App::get('config')->get('debug') ? 'error' : null);
             return;
         }
     }
 }
Beispiel #2
0
 /**
  * Description...
  *
  * @param   unknown  $method
  * @param   unknown  $url
  * @param   unknown  $entity
  * @return  array
  */
 private static function http($method, $url, $entity = NULL)
 {
     $conf = Configuration::instance();
     if (!($sock = @fsockopen($conf['host'], $conf['port'], $_errno, $errstr, 1))) {
         throw new ConnectionError('unable to establish HubGraph connection using ' . $conf['host'] . ': ' . $errstr);
     }
     fwrite($sock, "{$method} {$url} HTTP/1.1\r\n");
     fwrite($sock, "Host: localhost\r\n");
     fwrite($sock, "X-HubGraph-Request: " . sha1(uniqid()) . "\r\n");
     if ($entity) {
         fwrite($sock, "Content-Length: " . strlen($entity) . "\r\n");
     }
     fwrite($sock, "Connection: close\r\n\r\n");
     if ($entity) {
         fwrite($sock, $entity);
     }
     $first = true;
     $inHeaders = true;
     $status = NULL;
     $body = '';
     while ($chunk = fgets($sock, self::CHUNK_LEN)) {
         if ($first && !preg_match('/^HTTP\\/1\\.1\\ (\\d{3})/', $chunk, $code)) {
             throw new Exception('Unable to determine response status');
         } elseif ($first) {
             if (($status = intval($code[1])) === 204) {
                 break;
             }
             $first = false;
         } elseif ($inHeaders && preg_match('/^[\\r\\n]+$/', $chunk)) {
             $inHeaders = false;
         } elseif (!$inHeaders) {
             $body .= $chunk;
         }
     }
     fclose($sock);
     return array($status, $body);
 }
Beispiel #3
0
 /**
  * Return data on a group view (this will be some form of HTML)
  *
  * @param      object  $group      Current group
  * @param      string  $option     Name of the component
  * @param      string  $authorized User's authorization level
  * @param      integer $limit      Number of records to pull
  * @param      integer $limitstart Start of records to pull
  * @param      string  $action     Action to perform
  * @param      array   $access     What can be accessed
  * @param      array   $areas      Active area(s)
  * @return     array
  */
 public function onGroup($group, $option, $authorized, $limit = 0, $limitstart = 0, $action = '', $access, $areas = null)
 {
     $return = 'html';
     $active = 'resources';
     // The output array we're returning
     $arr = array('html' => '');
     //get this area details
     $this_area = $this->onGroupAreas();
     // Check if our area is in the array of areas we want to return results for
     if (is_array($areas) && $limit) {
         if (!in_array($this_area['name'], $areas)) {
             $return = 'metadata';
         }
     }
     //set group members plugin access level
     $group_plugin_acl = $access[$active];
     //get the group members
     $members = $group->get('members');
     if ($return == 'html') {
         //if set to nobody make sure cant access
         if ($group_plugin_acl == 'nobody') {
             $arr['html'] = '<p class="info">' . Lang::txt('GROUPS_PLUGIN_OFF', ucfirst($active)) . '</p>';
             return $arr;
         }
         //check if guest and force login if plugin access is registered or members
         if (User::isGuest() && ($group_plugin_acl == 'registered' || $group_plugin_acl == 'members')) {
             $area = Request::getWord('area', 'resource');
             $url = Route::url('index.php?option=com_groups&cn=' . $group->get('cn') . '&active=' . $active . '&area=' . $area);
             App::redirect(Route::url('index.php?option=com_users&view=login&return=' . base64_encode($url)), Lang::txt('GROUPS_PLUGIN_REGISTERED', ucfirst($active)), 'warning');
             return;
         }
         //check to see if user is member and plugin access requires members
         if (!in_array(User::get('id'), $members) && $group_plugin_acl == 'members' && $authorized != 'admin') {
             $arr['html'] = '<p class="info">' . Lang::txt('GROUPS_PLUGIN_REQUIRES_MEMBER', ucfirst($active)) . '</p>';
             return $arr;
         }
         require_once PATH_CORE . DS . 'components' . DS . 'com_search' . DS . 'models' . DS . 'hubgraph' . DS . 'client.php';
         $hgConf = \Components\Search\Models\Hubgraph\Configuration::instance();
         if ($hgConf->isOptionEnabled('com_groups')) {
             $view = $this->view('default', 'results');
             // Pass the view some info
             $view->option = $option;
             $view->group = $group;
             ob_start();
             $_GET['group'] = $group->gidNumber;
             define('HG_INLINE', 1);
             require PATH_CORE . DS . 'components' . DS . 'com_search' . DS . 'controllers' . DS . 'hubgraph.php';
             $controller = new \Components\Search\Controllers\Hubgraph();
             $controller->execute();
             $controller->redirect();
             $view->hubgraphResponse = ob_get_clean();
             return array('html' => $view->loadTemplate('hubgraph'));
         }
     }
     $database = App::get('db');
     // Incoming paging vars
     $sort = Request::getVar('sort', 'date');
     if (!in_array($sort, array('date', 'title', 'ranking', 'rating'))) {
         $sort = 'date';
     }
     $access = Request::getVar('access', 'all');
     if (!in_array($access, array('all', 'public', 'protected', 'private'))) {
         $access = 'date';
     }
     $config = Component::params('com_resources');
     if ($return == 'metadata') {
         if ($config->get('show_ranking')) {
             $sort = 'ranking';
         } elseif ($config->get('show_rating')) {
             $sort = 'rating';
         }
     }
     // Trigger the functions that return the areas we'll be using
     $rareas = $this->getResourcesAreas();
     // Get the active category
     $area = Request::getWord('area', 'resources');
     if ($area) {
         $activeareas = array($area);
     } else {
         $limit = 5;
         $activeareas = $rareas;
     }
     if ($return == 'metadata') {
         $ls = -1;
     } else {
         $ls = $limitstart;
     }
     // Get the search result totals
     $ts = $this->getResources($group, $authorized, 0, $ls, $sort, $access, $activeareas);
     $totals = array($ts);
     // Get the total results found (sum of all categories)
     $i = 0;
     $total = 0;
     $cats = array();
     foreach ($rareas as $c => $t) {
         $cats[$i]['category'] = $c;
         // Do sub-categories exist?
         if (is_array($t) && !empty($t)) {
             // They do - do some processing
             $cats[$i]['title'] = ucfirst($c);
             $cats[$i]['total'] = 0;
             $cats[$i]['_sub'] = array();
             $z = 0;
             // Loop through each sub-category
             foreach ($t as $s => $st) {
                 // Ensure a matching array of totals exist
                 if (is_array($totals[$i]) && !empty($totals[$i]) && isset($totals[$i][$z])) {
                     // Add to the parent category's total
                     $cats[$i]['total'] = $cats[$i]['total'] + $totals[$i][$z];
                     // Get some info for each sub-category
                     $cats[$i]['_sub'][$z]['category'] = $s;
                     $cats[$i]['_sub'][$z]['title'] = $st;
                     $cats[$i]['_sub'][$z]['total'] = $totals[$i][$z];
                 }
                 $z++;
             }
         } else {
             // No sub-categories - this should be easy
             $cats[$i]['title'] = $t;
             $cats[$i]['total'] = !is_array($totals[$i]) ? $totals[$i] : 0;
         }
         // Add to the overall total
         $total = $total + intval($cats[$i]['total']);
         $i++;
     }
     // Do we have an active area?
     if (count($activeareas) == 1 && !is_array(current($activeareas))) {
         $active = $activeareas[0];
     } else {
         $active = '';
     }
     // Get the search results
     $r = $this->getResources($group, $authorized, $limit, $limitstart, $sort, $access, $activeareas);
     $results = array($r);
     // Build the output
     switch ($return) {
         case 'html':
             // Instantiate a vew
             $view = $this->view('default', 'results');
             // Pass the view some info
             $view->option = $option;
             $view->group = $group;
             $view->authorized = $authorized;
             $view->totals = $totals;
             $view->results = $results;
             $view->cats = $cats;
             $view->active = $active;
             $view->limitstart = $limitstart;
             $view->limit = $limit;
             $view->total = $total;
             $view->sort = $sort;
             $view->access = $access;
             foreach ($this->getErrors() as $error) {
                 $view->setError($error);
             }
             // Return the output
             $arr['metadata']['count'] = $total;
             $arr['html'] = $view->loadTemplate();
             break;
         case 'metadata':
             $arr['metadata']['count'] = $total;
             break;
     }
     // Return the output
     return $arr;
 }