Exemplo n.º 1
1
function getGeo($ip)
{
    $geoplugin = new geoPlugin();
    $geoplugin->locate($ip);
    $geoip = geoip_record_by_name($ip);
    $geo = false;
    if (!empty($geoip)) {
        $geoip = array2object($geoip);
        // geoip delivers (sometimes)the strings in ISO-8859-1, convert non utf-8 into  UTF8 ( not UTF-8 )
        foreach ($geoip as $key => $val) {
            if (in_array($key, array('city', 'country_name'))) {
                $encoding = mb_detect_encoding($geoip->{$key});
                if ($encoding != 'UTF-8') {
                    $geoip->{$key} = iconv($encoding, 'UTF8//IGNORE', $geoip->{$key});
                }
            }
        }
        $geo = normalize_geo(false, $geoplugin);
        utf8_encode_deep($geo);
    }
    return $geo;
}
Exemplo n.º 2
0
function guifi_domain_load($id, $ret = 'array')
{
    guifi_log(GUIFILOG_FULL, 'function guifi_domain_load()');
    $domain = db_fetch_array(db_query('
    SELECT d.*
    FROM {guifi_dns_domains} d, {guifi_services} l
    WHERE d.id = %d
    AND d.sid = l.id', $id));
    if (empty($domain)) {
        drupal_set_message(t('Domain (%num) does not exist.', array('%num' => $id)));
        return;
    }
    $qr = db_query('
    SELECT *
    FROM {guifi_dns_hosts}
    WHERE id = %d ORDER BY counter', $id);
    $rc = 0;
    while ($host = db_fetch_array($qr)) {
        $rc++;
        $domain['hosts'][$host['counter']] = $host;
    }
    if ($ret == 'array') {
        return $domain;
    } else {
        foreach ($domain as $k => $field) {
            $var->{$k} = $field;
        }
        return array2object($domain);
    }
}
Exemplo n.º 3
0
/**
 * Method to convert Array -> Object -> Array.
 *
 * @param hash $data Containing array object
 * 
 * @return stdClass Object $object   Containing stdClass object
 *
 * @since    3.4
 */
function array2object($data)
{
    if (!is_array($data)) {
        return $data;
    }
    $object = new stdClass();
    foreach ($data as $name => $value) {
        if (isset($name)) {
            $name = strtolower(trim($name));
            $object->{$name} = array2object($value);
        }
    }
    return $object;
}
Exemplo n.º 4
0
function processOpenSRS($type = "", $data = "")
{
    if (empty($data)) {
        trigger_error("OSRS Error - No data found.");
        return null;
    } else {
        $dataArray = array();
        switch (strtolower($type)) {
            case "array":
                $dataArray = $data;
                break;
            case "json":
                $json = str_replace("\\\"", "\"", $data);
                //  Replace  \"  with " for JSON that comes from Javascript
                $dataArray = json_decode($json, true);
                break;
            case "yaml":
                $dataArray = Spyc::YAMLLoad($data);
                break;
            default:
                $dataArray = $data;
        }
        // Convert associative array to object
        $dataObject = array2object($dataArray);
        $classCall = null;
        if (class_exists($dataObject->func)) {
            $classCall = new $dataObject->func($type, $dataObject);
        } else {
            trigger_error("OSRS Error - Unable to find the function {$dataObject->func}.  Either the function is misspelled or there are incorrect file paths set in openSRS_config.php.");
        }
        return $classCall;
    }
}
Exemplo n.º 5
0
function processOpenSRS($type = "", $data = "")
{
    if ($type != "" && $data != "") {
        if ($type == "array") {
            $dataArray = $data;
        }
        // ARRAY
        if ($type == "json") {
            // JSON
            $json = str_replace("\\\"", "\"", $data);
            //  Replace  \"  with " for JSON that comes from Javascript
            $dataArray = json_decode($json, true);
        }
        if ($type == "yaml") {
            $dataArray = Spyc::YAMLLoad($data);
        }
        // YAML
        // Convert associative array to object
        $dataObject = array2object($dataArray);
    }
    // Call appropriate class
    if (class_exists($dataObject->func)) {
        $classCall = new $dataObject->func($type, $dataObject);
    } else {
        $classCall = null;
        trigger_error("OSRS Error - Unable to find the function passed.  Either the function is misspelled or there are incorrect file paths set in openSRS_config.php.");
    }
    return $classCall;
}
Exemplo n.º 6
0
function guifi_device_form_validate($form, &$form_state)
{
    global $user;
    guifi_log(GUIFILOG_TRACE, 'function guifi_device_form_validate()', $form_state['values']);
    guifi_log(GUIFILOG_TRACE, 'function guifi_device_form_validate(vlans)', $form_state['values'][vlans]);
    guifi_log(GUIFILOG_TRACE, 'function guifi_device_form_validate(aggregations)', $form_state['values'][aggregations]);
    guifi_log(GUIFILOG_TRACE, 'function guifi_device_form_validate(ipv4)', $form_state['values'][ipv4]);
    // nick
    if (isset($form['main']['nick'])) {
        guifi_validate_nick($form_state['values']['nick']);
        $query = db_query("\n      SELECT nick\n      FROM {guifi_devices}\n      WHERE lcase(nick)=lcase('%s')\n       AND id <> %d", strtolower($form_state['values']['nick']), $form_state['values']['id']);
        while (db_fetch_object($query)) {
            form_set_error('nick', t('Nick already in use.'));
        }
    }
    // ssid
    if (empty($form_state['values']['ssid'])) {
        $form_state['values']['ssid'] = $form_state['values']['nick'];
    }
    // Validate ip address(es)
    // Finding duplicates
    $ips = array();
    if (!empty($form_state['values']['ipv4'])) {
        // first checking local IPs
        foreach ($form_state['values']['ipv4'] as $keyS => $valueS) {
            if (empty($valueS[ipv4])) {
                continue;
            }
            // duplicate ip?
            if (in_array($valueS[ipv4], $ips)) {
                form_set_error("ipv4][{$keyS}][ipv4", t('address %addr is duplicated', array('%addr' => $valueS[ipv4])));
            }
            $ips[] = $valueS[ipv4];
            $valueSIPCalc = _ipcalc($valueS[ipv4], $valueS[netmask]);
            // Now looking into remote IPs
            foreach ($valueS[subnet] as $keyI => $valueI) {
                if (empty($valueI[ipv4])) {
                    continue;
                }
                guifi_log(GUIFILOG_TRACE, 'function guifi_device_form_validate(ipv4s)', $valueS[ipv4] . ' / ' . $valueI[ipv4] . ' ' . $valueI[did]);
                // duplicate ip?
                if (in_array($valueI[ipv4], $ips)) {
                    if ($valueI['new']) {
                        $field = "ipv4][{$keyS}][subnet][{$keyI}][ipv4txt";
                    } else {
                        $field = "ipv4][{$keyS}][subnet][{$keyI}][ipv4";
                    }
                    form_set_error($field, t('address %addr is duplicated', array('%addr' => $valueI[ipv4])));
                }
                $ips[] = $valueI[ipv4];
                // same subnet as related IP?
                $valueIIPCalc = _ipcalc($valueI[ipv4], $valueS[netmask]);
                if ($valueSIPCalc[netid] != $valueIIPCalc[netid] or $valueSIPCalc[maskbits] != $valueIIPCalc[maskbits]) {
                    form_set_error("ipv4][{$keyS}][subnet][{$keyI}][ipv4", t('address %addr1 not at same subnet as %addr2', array('%addr1' => $valueI[ipv4], '%addr2' => $valueS[ipv4])));
                }
                // remote id should be populated
                if (empty($valueI[did])) {
                    form_set_error("ipv4][{$keyS}][subnet][{$keyI}][did", t('Remote device for address %addr1 not specified', array('%addr1' => $valueI[ipv4])));
                }
            }
            // for remote IPs
        }
        // for local IPs
        /*   if (db_affected_rows(db_query("
              SELECT i.id
              FROM {guifi_interfaces} i,{guifi_ipv4} a
              WHERE i.id=a.interface_id AND a.ipv4='%s'
                AND i.device_id != %d",
              $form_state['values']['ipv4'],
              $form_state['values']['id']))) {
              $message = t('IP %ipv4 already taken in the database. Choose another or leave the address blank.',
                array('%ipv4' => $form_state['values']['ipv4']));
              form_set_error('ipv4',$message); 
            } */
    }
    // Validating vlans & aggregations
    foreach (array('vlans', 'aggregations') as $vtype) {
        foreach ($form_state['values'][$vtype] as $kvlan => $vlan) {
            // interface_type (name) should have a value
            if (empty($vlan['interface_type']) and !form_get_errors()) {
                $vlan['interface_type'] = substr($vtype, 0, 4) . $kvlan;
                form_set_value(array('#parents' => array($vtype, $kvlan, 'interface_type')), $vlan['interface_type'], $form_state);
                $form_state['rebuild'] = TRUE;
                drupal_set_message(t('Setting interface name to %name', array('%name' => $vlan['interface_type'])), 'warning');
            }
            // parent should exists
            if (empty($vlan['related_interfaces'])) {
                form_set_error("{$vtype}][{$kvlan}][related_interfaces", t('%name should have related interface(s)', array('%name' => $vlan[interface_type])));
            }
        }
    }
    // foreach vlans, aggregations
    // No duplicate names on interface names
    $ifs = guifi_get_currentInterfaces($form_state['values']);
    $iChecked = array();
    foreach ($ifs as $k => $iname) {
        if (in_array($iname, $iChecked)) {
            guifi_log(GUIFILOG_TRACE, 'function guifi_device_form_validate()', $iname);
            foreach (array('interfaces', 'vlans', 'aggregations', 'tunnels') as $iClass) {
                if (isset($form_state[values][$iClass][$k])) {
                    $f = $iClass . "][{$k}][interface_type";
                }
                form_set_error($f, t('Interface name %name duplicated', array('%name' => $iname)));
            }
        }
        $iChecked[] = $iname;
    }
    if (count($form_state['values']['radios'])) {
        foreach ($form_state['values']['radios'] as $k => $v) {
            guifi_radios_validate($k, $v, $form_state['values']);
        }
    }
    guifi_maintainers_validate(array2object($form_state['values']));
    guifi_funders_validate(array2object($form_state['values']));
}
Exemplo n.º 7
0
 /**
  * Метод, предназначенный для обработки результата запроса, возвращая данные в виде объекта.
  *
  * @return object
  * @access public
  */
 function FetchRow()
 {
     if (is_array($this->_result)) {
         $a = $this->FetchAssocArray();
         return array2object($a);
     }
     return @mysqli_fetch_object($this->_result);
 }
function importPage($title)
{
    global $usercache;
    echo "\n<!-- Importing page " . xmlCommentSafe($title) . " -->\n";
    $page = fetchPage($title);
    $newtitle = xmlsafe(str_replace('_', ' ', recodeText($title)));
    $munged = mungeFormat($page->text);
    if ($munged != $page->text) {
        /**
         * Save a *new* revision with the conversion, and put the
         * previous last version into the history.
         */
        $next = array2object(array('text' => $munged, 'minor' => 1, 'username' => 'Conversion script', 'host' => '127.0.0.1', 'ts' => time(), 'summary' => 'link fix'));
        $revisions = array($page, $next);
    } else {
        /**
         * Current revision:
         */
        $revisions = array($page);
    }
    $xml = <<<END
\t<page>
\t\t<title>{$newtitle}</title>

END;
    # History
    $revisions = array_merge($revisions, fetchKeptPages($title));
    if (count($revisions) == 0) {
        return $sql;
    }
    foreach ($revisions as $rev) {
        $text = xmlsafe(recodeText($rev->text));
        $minor = $rev->minor ? '<minor/>' : '';
        list($userid, $username) = checkUserCache($rev->username, $rev->host);
        $username = xmlsafe(recodeText($username));
        $timestamp = xmlsafe(timestamp2ISO8601($rev->ts));
        $comment = xmlsafe(recodeText($rev->summary));
        $xml .= <<<END
\t\t<revision>
\t\t\t<timestamp>{$timestamp}</timestamp>
\t\t\t<contributor><username>{$username}</username></contributor>
\t\t\t{$minor}
\t\t\t<comment>{$comment}</comment>
\t\t\t<text>{$text}</text>
\t\t</revision>

END;
    }
    $xml .= "</page>\n\n";
    return $xml;
}
Exemplo n.º 9
0
					<textarea id="productid_' . $key . '" style="width:140px;height:45px">' . $box[5] . '</textarea> 
				</div>
				<div class="not_expanded_' . $key . '" style="display:none">
					' . $dhl->l('Category IDs') . '
					<br />
					<textarea id="categoryid_' . $key . '" style="width:140px;height:45px">' . $box[6] . '</textarea> 
				</div>
				<div class="not_expanded_' . $key . '" style="display:none">
					' . $dhl->l('Manufacturer IDs') . '
					<br />
					<textarea id="manufacturerid_' . $key . '" style="width:140px;height:45px">' . $box[7] . '</textarea> 
				</div>
				<div class="not_expanded_' . $key . '" style="display:none">
					' . $dhl->l('Supplier IDs') . '
					<br />
					<textarea id="supplierid_' . $key . '" style="width:140px;height:45px">' . $box[8] . '</textarea> 
				</div>
			</td>' : '') . '
			<td align="left" valign="top"><img src="' . _MODULE_DIR_ . 'dhl/img/update.gif" id="edit_box_' . $key . '" style="cursor:pointer;" onclick="edit_box(' . $key . ')" /></td>
			<td align="left" valign="top"><img src="' . _MODULE_DIR_ . 'dhl/img/delete.gif" style="cursor:pointer;" onclick="remove_box(' . $key . ')" /></td>
	</tr>';
}
$html .= "</table>";
$return['boxes'] = $html;
ob_end_clean();
if (!function_exists('json_decode')) {
    $j = new JSON();
    print $j->serialize(array2object($return));
} else {
    print json_encode($return);
}