コード例 #1
0
ファイル: geo.php プロジェクト: mined-gatech/hubzero-cms
 /**
  * This method should handle any login logic and report back to the subject
  *
  * @param array $user    holds the user data
  * @param array $options holding options (remember, autoregister, group)
  * @return bool
  */
 public function onUserLogin($user, $options = array())
 {
     // Get params
     $groupAlias = $this->params->get('group', false);
     $location = $this->params->get('location', false);
     // Make sure params were set
     if (!$groupAlias || !$location) {
         return;
     }
     // Check user location
     if (\Hubzero\Geocode\Geocode::is_iplocation($_SERVER['REMOTE_ADDR'], $location)) {
         // Get user groups and instances of access groups
         $group = \Hubzero\User\Group::getInstance($groupAlias);
         // Update group if that group exists
         if (is_object($group)) {
             $group->add('members', array(\User::getInstance($user['username'])->get('id')));
             $group->update();
         }
     }
 }
コード例 #2
0
ファイル: Country.php プロジェクト: kevinwojo/framework
 /**
  * Method to get the field options.
  *
  * @return  array  The field option objects.
  */
 protected function getOptions()
 {
     // Initialize variables.
     $options = array();
     if (!self::$countries) {
         self::$countries = array();
         $countries = Geocode::countries();
         if ($countries && !empty($countries)) {
             self::$countries = $countries;
         }
     }
     if ($this->element['option_blank']) {
         $options[] = Dropdown::option('', App::get('language')->txt('- Select -'), 'value', 'text');
     }
     foreach (self::$countries as $option) {
         // Create a new option object based on the <option /> element.
         $tmp = Dropdown::option((string) $option->code, App::get('language')->alt(trim((string) $option->name), preg_replace('/[^a-zA-Z0-9_\\-]/', '_', $this->fieldname)), 'value', 'text');
         // Add the option object to the result set.
         $options[] = $tmp;
     }
     reset($options);
     return $options;
 }
コード例 #3
0
ファイル: default.php プロジェクト: mined-gatech/hubzero-cms
								</div>
							</div>
						</li>
					<?php 
        }
        ?>
				<?php 
    }
    ?>
			<?php 
}
?>

			<?php 
// get countries list
$co = \Hubzero\Geocode\Geocode::countries();
?>
			<?php 
if ($this->registration->Citizenship != REG_HIDE && $this->profile->get('countryorigin')) {
    ?>
				<?php 
    if ($this->params->get('access_countryorigin') == 0 || $this->params->get('access_countryorigin') == 1 && $loggedin || $this->params->get('access_countryorigin') == 2 && $isUser) {
        ?>
					<li class="profile-countryorigin field">
						<div class="field-content">
							<div class="key"><?php 
        echo Lang::txt('PLG_GROUPS_PROFILE_CITIZENSHIP');
        ?>
</div>
							<?php 
        $img = '';
コード例 #4
0
 /**
  * Get a zone based on location
  *
  * Second param is a list of zone IDs to check against. That list
  * is pulled from the #__tool_version_zone table.
  *
  * @param      string $ip
  * @param      array  $allowed List of zone IDs to check against
  * @return     object
  */
 public function zoning($ip = null, $allowed = array())
 {
     if (!$ip) {
         return new Zone();
     }
     // Find by IP
     $zones = $this->zones('list', array('state' => 'up', 'id' => $allowed, 'ip' => $ip), true);
     if ($zones->total() > 0) {
         foreach ($zones as $zone) {
             return $zone;
         }
     }
     // Find by city
     // Find by region
     // Find by country
     $country = Geocode::ipcountry($ip);
     if (!$country) {
         return new Zone();
     }
     $zones = $this->zones('list', array('state' => 'up', 'id' => $allowed, 'countrySHORT' => $country), true);
     if ($zones->total() > 0) {
         foreach ($zones as $zone) {
             return $zone;
         }
     }
     // Find by continent
     $continent = Geocode::getContinentByCountry($country);
     if (!$continent) {
         return new Zone();
     }
     $zones = $this->zones('list', array('state' => 'up', 'id' => $allowed, 'continent' => $continent), true);
     if ($zones->total() > 0) {
         foreach ($zones as $zone) {
             return $zone;
         }
     }
     return new Zone();
 }
コード例 #5
0
ファイル: sessions.php プロジェクト: kevinwojo/hubzero-cms
 /**
  * Check export controls
  * Is the user in a country that has access to this tool?
  *
  * @param      string $exportcontrol Control [us, d1, pu]
  * @return     boolean False if user does NOT have access
  */
 private function _getToolExportControl($exportcontrol)
 {
     $exportcontrol = strtolower($exportcontrol);
     $ip = Request::ip();
     $country = \Hubzero\Geocode\Geocode::ipcountry($ip);
     if (empty($country) && in_array($exportcontrol, array('us', 'd1', 'pu'))) {
         $this->setError(Lang::txt('COM_TOOLS_ERROR_ACCESS_DENIED_EXPORT_UNKNOWN'));
         Log::debug("mw::_getToolExportControl({$exportcontrol}) FAILED location export control check");
         return false;
     }
     if (\Hubzero\Geocode\Geocode::is_e1nation(\Hubzero\Geocode\Geocode::ipcountry($ip))) {
         $this->setError(Lang::txt('COM_TOOLS_ERROR_ACCESS_DENIED_EXPORT_E1'));
         Log::debug("mw::_getToolExportControl({$exportcontrol}) FAILED E1 export control check");
         return false;
     }
     switch ($exportcontrol) {
         case 'us':
             if (\Hubzero\Geocode\Geocode::ipcountry($ip) != 'us') {
                 $this->setError(Lang::txt('COM_TOOLS_ERROR_ACCESS_DENIED_EXPORT_USA_ONLY'));
                 Log::debug("mw::_getToolExportControl({$exportcontrol}) FAILED US export control check");
                 return false;
             }
             break;
         case 'd1':
             if (\Hubzero\Geocode\Geocode::is_d1nation(\Hubzero\Geocode\Geocode::ipcountry($ip))) {
                 $this->setError(Lang::txt('COM_TOOLS_ERROR_ACCESS_DENIED_EXPORT_LICENSE'));
                 Log::debug("mw::_getToolExportControl({$exportcontrol}) FAILED D1 export control check");
                 return false;
             }
             break;
         case 'pu':
             if (!\Hubzero\Geocode\Geocode::is_iplocation($ip, $exportcontrol)) {
                 $this->setError(Lang::txt('COM_TOOLS_ERROR_ACCESS_DENIED_EXPORT_PURDUE_ONLY'));
                 Log::debug("mw::_getToolExportControl({$exportControl}) FAILED PURDUE export control check");
                 return false;
             }
             break;
     }
     return true;
 }
コード例 #6
0
ファイル: default.php プロジェクト: sumudinie/hubzero-cms
                $i = 0;
                //$data[$ky] = array();
                $r[$ky] = array();
            }
            //$data[$ky][] = $row;
            if (!isset($colors[$i])) {
                $i = 0;
            }
            $r[$ky][] = '{label: \'' . addslashes($row->name) . '\', data: ' . number_format($row->value) . ', color: \'' . $colors[$i] . '\'}' . "\n";
            if ($row->rank != '0') {
                $total += $row->value;
            }
            $names[] = $row->name;
            $i++;
        }
        $codes = \Hubzero\Geocode\Geocode::getCodesByNames($names);
        $cls = 'even';
        //$pie = array();
        $i = 0;
        $total = $total ? $total : 1;
        foreach ($dataset as $row) {
            if ($row->rank == '0') {
                continue;
            }
            if ($row->name == '?') {
                $row->name = Lang::txt('PLG_RESOURCES_USAGE_UNIDENTIFIED');
            }
            $cls = $cls == 'even' ? 'odd' : 'even';
            ?>
							<tr rel="<?php 
            echo $row->name;
コード例 #7
0
ファイル: usage.php プロジェクト: mined-gatech/hubzero-cms
 /**
  * Get data for orgs, countries, domains for a given time period
  * (1 = country, 2 = domain, 3 = org)
  *
  * @param      integer $id       Resource ID
  * @param      string  $datetime Timestamp YYYY-MM-DD
  * @return     array
  */
 public function getTopValues($id, $datetime)
 {
     $period = Request::getInt('period', 14);
     $colors = array($this->params->get('pie_chart_color1', '#7c7c7c'), $this->params->get('pie_chart_color2', '#515151'), $this->params->get('pie_chart_color3', '#d9d9d9'), $this->params->get('pie_chart_color4', '#3d3d3d'), $this->params->get('pie_chart_color5', '#797979'), $this->params->get('pie_chart_color6', '#595959'), $this->params->get('pie_chart_color7', '#e5e5e5'), $this->params->get('pie_chart_color8', '#828282'), $this->params->get('pie_chart_color9', '#404040'), $this->params->get('pie_chart_color10', '#6a6a6a'), $this->params->get('pie_chart_color1', '#bcbcbc'), $this->params->get('pie_chart_color2', '#515151'), $this->params->get('pie_chart_color3', '#d9d9d9'), $this->params->get('pie_chart_color4', '#3d3d3d'), $this->params->get('pie_chart_color5', '#797979'), $this->params->get('pie_chart_color6', '#595959'), $this->params->get('pie_chart_color7', '#e5e5e5'), $this->params->get('pie_chart_color8', '#828282'), $this->params->get('pie_chart_color9', '#404040'), $this->params->get('pie_chart_color10', '#3a3a3a'));
     $json = new stdClass();
     $database = App::get('db');
     $tid = $this->getTid($id, $datetime, $period);
     $orgs = $this->getTopValue($id, 3, $tid, $datetime, $period);
     $r = array();
     if ($orgs) {
         $i = 0;
         foreach ($orgs as $row) {
             $ky = str_replace('-', '/', str_replace('-00 00:00:00', '-01', $row->datetime));
             if ($row->datetime && preg_match("/([0-9]{4})-([0-9]{2})-([0-9]{2})[ ]([0-9]{2}):([0-9]{2}):([0-9]{2})/", $row->datetime, $regs)) {
                 $ky = $regs[1] . '/' . $regs[2] . '/01';
                 //mktime($regs[4], $regs[5], $regs[6], , $regs[3], );
             }
             if (!isset($r[$ky])) {
                 $i = 0;
                 $r[$ky] = array();
             }
             if (!isset($colors[$i])) {
                 $i = 0;
             }
             $obj = new stdClass();
             $obj->label = $row->name;
             $obj->data = (int) $row->value;
             $obj->color = $colors[$i];
             $obj->code = '';
             $r[$ky][] = $obj;
             //'{label: \'' . addslashes($row->name) . '\', data: ' . number_format($row->value) . ', color: \'' . $colors[$i] . '\'}';
             $i++;
         }
     }
     $json->orgs = $r;
     $countries = $this->getTopValue($id, 1, $tid, $datetime, $period);
     $r = array();
     if ($countries) {
         $names = array();
         foreach ($countries as $row) {
             $names[] = $row->name;
         }
         $codes = \Hubzero\Geocode\Geocode::getCodesByNames($names);
         $i = 0;
         foreach ($countries as $row) {
             $ky = str_replace('-', '/', str_replace('-00 00:00:00', '-01', $row->datetime));
             if ($row->datetime && preg_match("/([0-9]{4})-([0-9]{2})-([0-9]{2})[ ]([0-9]{2}):([0-9]{2}):([0-9]{2})/", $row->datetime, $regs)) {
                 $ky = $regs[1] . '/' . $regs[2] . '/01';
                 //mktime($regs[4], $regs[5], $regs[6], , $regs[3], );
             }
             if (!isset($r[$ky])) {
                 $i = 0;
                 $r[$ky] = array();
             }
             if (!isset($colors[$i])) {
                 $i = 0;
             }
             $obj = new stdClass();
             $obj->label = $row->name;
             $obj->data = (int) $row->value;
             $obj->color = $colors[$i];
             $obj->code = isset($codes[$row->name]) ? strtolower($codes[$row->name]['code']) : '';
             $r[$ky][] = $obj;
             //'{label: \'' . addslashes($row->name) . '\', data: ' . number_format($row->value) . ', color: \'' . $colors[$i] . '\'}';
             $i++;
         }
     }
     $json->countries = $r;
     $domains = $this->getTopValue($id, 2, $tid, $datetime, $period);
     $r = array();
     if ($domains) {
         $i = 0;
         foreach ($domains as $row) {
             $ky = str_replace('-', '/', str_replace('-00 00:00:00', '-01', $row->datetime));
             if ($row->datetime && preg_match("/([0-9]{4})-([0-9]{2})-([0-9]{2})[ ]([0-9]{2}):([0-9]{2}):([0-9]{2})/", $row->datetime, $regs)) {
                 $ky = $regs[1] . '/' . $regs[2] . '/01';
                 //mktime($regs[4], $regs[5], $regs[6], , $regs[3], );
             }
             if (!isset($r[$ky])) {
                 $i = 0;
                 $r[$ky] = array();
             }
             if (!isset($colors[$i])) {
                 $i = 0;
             }
             $obj = new stdClass();
             $obj->label = $row->name;
             $obj->data = (int) $row->value;
             $obj->color = $colors[$i];
             $obj->code = '';
             $r[$ky][] = $obj;
             //'{label: \'' . addslashes($row->name) . '\', data: ' . number_format($row->value) . ', color: \'' . $colors[$i] . '\'}';
             $i++;
         }
     }
     $json->domains = $r;
     ob_clean();
     echo json_encode($json);
     die;
 }
コード例 #8
0
ファイル: finalize.php プロジェクト: mined-gatech/hubzero-cms
" />

						<h2><?php 
echo Lang::txt('COM_STORE_ORDER_WILL_SHIP');
?>
</h2>
						<pre><?php 
echo isset($this->posted['name']) ? $this->escape($this->posted['name']) : $this->escape(User::get('name'));
?>

<?php 
echo isset($this->posted['address']) ? $this->escape($this->posted['address']) : '';
?>

<?php 
echo isset($this->posted['country']) ? $this->escape($this->posted['country']) : $this->escape(\Hubzero\Geocode\Geocode::getcountry($this->xprofile->get('countryresident')));
?>
						</pre>
					</fieldset>
					<fieldset>
						<h4><?php 
echo Lang::txt('COM_STORE_CONTACT_INFO');
?>
</h4>
						<p>
							<?php 
if (isset($this->posted['phone'])) {
    ?>
								<?php 
    echo Lang::txt('Phone');
    ?>
コード例 #9
0
ファイル: utils.php プロジェクト: zooley/hubzero-cms
 /**
  * Return a tool export access
  *
  * @param	$export_control 	Export control level for tool
  *
  * @return     BOOL
  */
 public static function getToolExportAccess($export_control)
 {
     //instaniate objects
     $export_access = new stdClass();
     $ip = Request::ip();
     //get the export control level
     $export_control = strtolower($export_control);
     //get the users country based on ip address
     $country = \Hubzero\Geocode\Geocode::ipcountry($ip);
     //if we dont know the users location and its a restricted to we have to deny access
     if (empty($country) && in_array($export_control, array('us', 'd1', 'pu'))) {
         $export_access->valid = 0;
         $export_access->error->message = 'This tool may not be accessed from your unknown current location due to export/license restrictions.';
         \Log::debug("mw::_getToolExportControl({$export_control}) FAILED location export control check");
         return $export_access;
     }
     //if the user is in an E1 nation
     if (\Hubzero\Geocode\Geocode::is_e1nation(\Hubzero\Geocode\Geocode::ipcountry($ip))) {
         $export_access->valid = 0;
         $export_access->error->message = 'This tool may not be accessed from your current location due to E1 export/license restrictions.';
         \Log::debug("mw::_getToolExportControl({$export_control}) FAILED E1 export control check");
         return $export_access;
     }
     //run checks depending on the export ac
     switch ($export_control) {
         case 'us':
             if (\Hubzero\Geocode\Geocode::ipcountry($ip) != 'us') {
                 $export_access->valid = 0;
                 $export_access->error->message = 'This tool may only be accessed from within the U.S. due to export/licensing restrictions.';
                 \Log::debug("mw::_getToolExportControl({$export_control}) FAILED US export control check");
                 return $export_access;
             }
             break;
         case 'd1':
             if (\Hubzero\Geocode\Geocode::is_d1nation(\Hubzero\Geocode\Geocode::ipcountry($ip))) {
                 $export_access->valid = 0;
                 $export_access->error->message = 'This tool may not be accessed from your current location due to export/license restrictions.';
                 \Log::debug("mw::_getToolExportControl({$export_control}) FAILED D1 export control check");
                 return $export_access;
             }
             break;
         case 'pu':
             if (!\Hubzero\Geocode\Geocode::is_iplocation($ip, $export_control)) {
                 $export_access->valid = 0;
                 $export_access->error->message = 'This tool may only be accessed by authorized users while on the West Lafayette campus of Purdue University due to license restrictions.';
                 \Log::debug("mw::_getToolExportControl({$export_control}) FAILED PURDUE export control check");
                 return $export_access;
             }
             break;
     }
     //passed all checks
     $export_access->valid = 1;
     return $export_access;
 }
コード例 #10
0
ファイル: checkout.php プロジェクト: mined-gatech/hubzero-cms
						<label for="country">
							<?php 
echo Lang::txt('COM_STORE_COUNTRY');
?>
 <span class="required"><?php 
echo Lang::txt('COM_STORE_REQUIRED');
?>
</span>
							<select name="country" id="country" class="input-select">
								<option value=""><?php 
echo Lang::txt('(select from list)');
?>
</option>
								<?php 
$countries = \Hubzero\Geocode\Geocode::countries();
$mycountry = isset($this->posted['country']) ? $this->posted['country'] : \Hubzero\Geocode\Geocode::getcountry($this->xprofile->get('countryresident'));
foreach ($countries as $country) {
    ?>
									<option value="<?php 
    echo $this->escape($country->name);
    ?>
"<?php 
    echo $country->name == $mycountry ? ' selected="selected"' : '';
    ?>
><?php 
    echo $this->escape($country->name);
    ?>
</option>
									<?php 
}
?>
コード例 #11
0
ファイル: popover.php プロジェクト: sumudinie/hubzero-cms
    ?>
 />Yes</label>
								<label><input type="radio" class="option" name="countryresident_us" id="cores_usno" value="no" <?php 
    if (!empty($_POST['countryresident']) && strtolower($country) != 'us' || isset($_POST['countryresident_us']) && $_POST['countryresident_us'] == 'no') {
        echo 'checked="checked"';
    }
    ?>
 />No</label>
							</div>

							<div class="indented">
								<label for="countryresident">If not, please select the country where you currently reside</label>
								<select style="display: block" name="countryresident" id="countryresident">
									<option value="">Select country...</option>
								<?php 
    $countries = \Hubzero\Geocode\Geocode::getcountries();
    if (!$countries) {
        $countries = $defaultCountries;
    }
    foreach ($countries as $c) {
        echo '<option value="' . $c['code'] . '"';
        if ($country == $c['code']) {
            echo ' selected="selected"';
        }
        echo '>' . htmlentities($c['name'], ENT_COMPAT, 'UTF-8') . '</option>' . "\n";
    }
    ?>
								</select>
							</div>
					</li>
				<?php 
コード例 #12
0
ファイル: citation.php プロジェクト: kevinwojo/hubzero-cms
 /**
  * Build query
  *
  * @param   array    $filter  Filters to apply
  * @param   boolean  $admin   User has admin access
  * @return  string
  */
 public function buildQuery($filter = array(), $admin = true)
 {
     if (!isset($filter['published'])) {
         $filter['published'] = array(1);
     }
     $query = " WHERE r.published IN (" . implode(',', $filter['published']) . ")";
     //search term match
     if (isset($filter['search']) && $filter['search'] != '') {
         $query .= " AND (MATCH(r.title, r.isbn, r.doi, r.abstract, r.author, r.publisher) AGAINST (" . $this->_db->quote($filter['search']) . " IN BOOLEAN MODE) > 0)";
         //if ($admin = true)
         //{
         //	$query .= " OR LOWER(u.username) = " . $this->_db->quote(strtolower($filter['search'])) . "
         //				OR r.uid = " . $this->_db->quote($filter['search']);
         //}
     }
     //tag search
     if (isset($filter['tag']) && $filter['tag'] != '') {
         //if we have multiple tags we must explode them
         if (strstr($filter['tag'], ",")) {
             $tags = array_filter(array_map('trim', explode(',', $filter['tag'])));
         } else {
             $tags = array($filter['tag']);
         }
         //prevent SQL injection
         foreach ($tags as &$tag) {
             $tag = $this->_db->quote($tag);
         }
         $query .= " AND tago.tbl='citations' AND tag.tag IN (" . implode(",", $tags) . ")";
     }
     //type filter
     if (isset($filter['type']) && $filter['type'] != '') {
         $query .= " AND r.type=" . $this->_db->quote($filter['type']);
     }
     //author filter
     if (isset($filter['author']) && $filter['author'] != '') {
         $query .= " AND r.author LIKE " . $this->_db->quote('%' . $filter['author'] . '%');
     }
     //published in filter
     if (isset($filter['publishedin']) && $filter['publishedin'] != '') {
         $query .= " AND (r.booktitle LIKE " . $this->_db->quote('%' . $filter['publishedin'] . '%') . " OR r.journal LIKE " . $this->_db->quote('%' . $filter['publishedin'] . '%') . ")";
     }
     //year filter
     if (isset($filter['year_start']) && is_numeric($filter['year_start']) && $filter['year_start'] > 0) {
         $query .= " AND (r.year >=" . $this->_db->quote($filter['year_start']) . " OR r.year IS NULL OR r.year=0)";
     }
     if (isset($filter['year_end']) && is_numeric($filter['year_end']) && $filter['year_end'] > 0) {
         $query .= " AND (r.year <=" . $this->_db->quote($filter['year_end']) . " OR r.year IS NULL OR r.year=0)";
     }
     if (isset($filter['startuploaddate']) && isset($filter['enduploaddate'])) {
         $query .= " AND r.created >= " . $this->_db->quote($filter['startuploaddate']) . " AND r.created <= " . $this->_db->quote($filter['enduploaddate']);
     }
     //affiated? filter
     if (isset($filter['filter']) && $filter['filter'] != '') {
         if ($filter['filter'] == 'aff') {
             $query .= " AND r.affiliated=1";
         } else {
             $query .= " AND r.affiliated=0";
         }
     }
     //reference type check
     if (isset($filter['reftype'])) {
         // make sure its valid
         if (!is_array($filter['reftype'])) {
             throw new Exception(Lang::txt('Citations: Invalid search param "reftype"'), 500);
         }
         if (isset($filter['reftype']['research']) && $filter['reftype']['research'] == 1 && (isset($filter['reftype']['education']) && $filter['reftype']['education'] == 1) && (isset($filter['reftype']['eduresearch']) && $filter['reftype']['eduresearch'] == 1) && (isset($filter['reftype']['cyberinfrastructure']) && $filter['reftype']['cyberinfrastructure'] == 1)) {
             // Show all
         } else {
             $query .= " AND";
             $multi = 0;
             $o = 0;
             foreach ($filter['reftype'] as $g) {
                 if ($g == 1) {
                     $multi++;
                 }
             }
             if ($multi) {
                 $query .= " (";
             }
             if (isset($filter['reftype']['research']) && $filter['reftype']['research'] == 1) {
                 $query .= " ((ref_type LIKE '%R%' OR ref_type LIKE '%N%' OR ref_type LIKE '%S%') AND ref_type NOT LIKE '%E%')";
                 if ($multi) {
                     $o = 1;
                 }
             }
             if (isset($filter['reftype']['education']) && $filter['reftype']['education'] == 1) {
                 if ($multi) {
                     $query .= $o == 1 ? " OR" : "";
                     $o = 1;
                 }
                 $query .= " ((ref_type NOT LIKE '%R%' AND ref_type NOT LIKE '%N%' AND ref_type NOT LIKE '%S%') AND ref_type LIKE '%E%')";
             }
             if (isset($filter['reftype']['eduresearch']) && $filter['reftype']['eduresearch'] == 1) {
                 if ($multi) {
                     $query .= $o == 1 ? " OR" : "";
                     $o = 1;
                 }
                 $query .= " (ref_type LIKE '%R%E%' OR ref_type LIKE '%E%R%' AND ref_type LIKE '%N%E%' OR ref_type LIKE '%E%N%' OR ref_type LIKE '%S%E%' OR ref_type LIKE '%E%S%')";
             }
             if (isset($filter['reftype']['cyberinfrastructure']) && $filter['reftype']['cyberinfrastructure'] == 1) {
                 if ($multi) {
                     $query .= $o == 1 ? " OR" : "";
                     $o = 1;
                 }
                 $query .= " ((ref_type LIKE '%C%' OR ref_type LIKE '%A%' OR ref_type LIKE '%HD%' OR ref_type LIKE '%I%') AND (ref_type NOT LIKE '%R%' AND ref_type NOT LIKE '%N%' AND ref_type NOT LIKE '%S%' AND ref_type NOT LIKE '%E%'))";
             }
             if ($multi) {
                 $query .= ")";
             }
         }
     }
     //author affiliation filter
     if (isset($filter['aff'])) {
         if (isset($filter['aff']['university']) && $filter['aff']['university'] == 1 && (isset($filter['aff']['industry']) && $filter['aff']['industry'] == 1) && (isset($filter['aff']['government']) && $filter['aff']['government'] == 1)) {
             // Show all
         } else {
             $query .= " AND ca.cid=r.id AND";
             $multi = 0;
             $o = 0;
             foreach ($filter['aff'] as $g) {
                 if ($g == 1) {
                     $multi++;
                 }
             }
             if ($multi) {
                 $query .= " (";
             }
             if (isset($filter['aff']['university']) && $filter['aff']['university'] == 1) {
                 $query .= " (ca.orgtype LIKE '%education%' OR ca.orgtype LIKE 'university%')";
                 if ($multi) {
                     $o = 1;
                 }
             }
             if (isset($filter['aff']['industry']) && $filter['aff']['industry'] == 1) {
                 if ($multi) {
                     $query .= $o == 1 ? " OR" : "";
                     $o = 1;
                 }
                 $query .= " ca.orgtype LIKE '%industry%'";
             }
             if (isset($filter['aff']['government']) && $filter['aff']['government'] == 1) {
                 if ($multi) {
                     $query .= $o == 1 ? " OR" : "";
                     $o = 1;
                 }
                 $query .= " ca.orgtype LIKE '%government%'";
             }
             if ($multi) {
                 $query .= ")";
             }
         }
     }
     //author geo filter
     if (isset($filter['geo'])) {
         if (isset($filter['geo']['us']) && $filter['geo']['us'] == 1 && (isset($filter['geo']['na']) && $filter['geo']['na'] == 1) && (isset($filter['geo']['eu']) && $filter['geo']['eu'] == 1) && (isset($filter['geo']['as']) && $filter['geo']['as'] == 1)) {
             // Show all
         } else {
             $query .= " AND ca.cid=r.id AND";
             $multi = 0;
             $o = 0;
             foreach ($filter['geo'] as $g) {
                 if ($g == 1) {
                     $multi++;
                 }
             }
             if ($multi) {
                 $query .= " (";
             }
             if (isset($filter['geo']['us']) && $filter['geo']['us'] == 1) {
                 $query .= " LOWER(ca.countryresident) = 'us'";
                 if ($multi) {
                     $o = 1;
                 }
             }
             if (isset($filter['geo']['na']) && $filter['geo']['na'] == 1) {
                 $countries = Geocode::getCountriesByContinent('na');
                 $c = implode("','", $countries);
                 if ($multi) {
                     $query .= $o == 1 ? " OR" : "";
                     $o = 1;
                 }
                 $query .= " LOWER(ca.countryresident) IN ('" . strtolower($c) . "')";
             }
             if (isset($filter['geo']['eu']) && $filter['geo']['eu'] == 1) {
                 $countries = Geocode::getCountriesByContinent('eu');
                 $c = implode("','", $countries);
                 if ($multi) {
                     $query .= $o == 1 ? " OR" : "";
                     $o = 1;
                 }
                 $query .= " LOWER(ca.countryresident) IN ('" . strtolower($c) . "')";
             }
             if (isset($filter['geo']['as']) && $filter['geo']['as'] == 1) {
                 $countries = Geocode::getCountriesByContinent('as');
                 $c = implode("','", $countries);
                 if ($multi) {
                     $query .= $o == 1 ? " OR" : "";
                     $o = 1;
                 }
                 $query .= " LOWER(ca.countryresident) IN ('" . strtolower($c) . "')";
             }
             if ($multi) {
                 $query .= ")";
             }
         }
     }
     if (isset($filter['id']) && $filter['id'] > 0) {
         $query .= " AND r.id=" . $filter['id'];
     }
     // scope & scope Id
     if (isset($filter['scope']) && $filter['scope'] != '') {
         if ($filter['scope'] == 'hub') {
             $query .= "\tAND (r.scope IS NULL OR r.scope = 'hub' OR r.scope = '')";
         } elseif ($filter['scope'] == 'all') {
             $query .= 'OR r.scope IS NULL OR r.scope IS NOT NULL';
         } else {
             $query .= " AND r.scope=" . $this->_db->quote($filter['scope']);
         }
     }
     if (isset($filter['scope_id']) && $filter['scope_id'] != NULL) {
         $query .= " AND r.scope_id=" . $this->_db->quote($filter['scope_id']);
     }
     if (!isset($filter['scope']) && !isset($filter['scope_id']) && $filter['scope'] != 'all') {
         $query .= ' AND r.scope = "" AND r.scope_id = ""';
     }
     //group by
     if (isset($filter['tag']) && $filter['tag'] != '') {
         $query .= " GROUP BY r.id HAVING uniques=" . count($tags);
     }
     //if we had a search term lets order by search match
     if (isset($filter['search']) && $filter['search'] != '') {
         $query .= " ORDER BY MATCH(r.title, r.isbn, r.doi, r.abstract, r.author, r.publisher) AGAINST (" . $this->_db->quote($filter['search']) . " IN BOOLEAN MODE) DESC";
         $filter['sort'] = '';
     }
     //sort filter
     if (isset($filter['sort']) && $filter['sort'] != '') {
         if (isset($filter['search']) && $filter['search'] != '') {
             $query .= ", " . $filter['sort'];
         } else {
             $query .= " ORDER BY " . $filter['sort'];
         }
     }
     //limit
     if (isset($filter['limit']) && $filter['limit'] > 0) {
         $query .= " LIMIT " . intval($filter['start']) . "," . intval($filter['limit']);
     }
     return $query;
 }
コード例 #13
0
 /**
  * Retrieves option values for a profile field
  *
  * @apiMethod GET
  * @apiUri    /members/fieldValues
  * @apiParameter {
  * 		"name":        "field",
  * 		"description": "Profile field of interest",
  * 		"type":        "string",
  * 		"required":    true,
  * 		"default":     ""
  * }
  * @return  void
  */
 public function fieldValuesTask()
 {
     $name = Request::getVar('field', '');
     $field = Field::all()->whereEquals('name', $name)->row();
     if (!$field->get('id')) {
         App::abort(404, 'Field not found');
     }
     // Create object with values
     $response = new stdClass();
     $response->type = $field->get('type');
     $values = array();
     if ($field->get('type') == 'country') {
         $countries = \Hubzero\Geocode\Geocode::countries();
         foreach ($countries as $option) {
             // Create a new option object based on the <option /> element.
             $tmp = new stdClass();
             $tmp->value = (string) $option->code;
             $tmp->label = trim((string) $option->name);
             // Add the option object to the result set.
             $values[] = $tmp;
         }
     } else {
         foreach ($field->options()->ordered()->rows() as $option) {
             $values[] = $option->toObject();
         }
     }
     $response->values = $values;
     // Return object
     $this->send($response);
 }