/**
  * 将json字符串auth转换成数组
  */
 public static function toArray($auth)
 {
     $return = [];
     if (empty($auth)) {
         return [];
     }
     $json = json_decode($auth);
     function analyse($obj)
     {
         $return = [];
         foreach ($obj as $k => $v) {
             $return[$k] = $v;
         }
         return $return;
     }
     foreach ($json as $key => $row) {
         $return[$key] = analyse($row);
     }
     return $return;
 }
Example #2
0
function addUser()
{
    $phone = getvar('phone', 'post');
    if (preg_match('/(^0\\d{11})|(^1\\d{10})/', $phone, $matches)) {
        //查看电话是否已经被注册
        $reserve = new Reserve();
        $have = $reserve->findByPhone($matches[0]);
        if (!$have) {
            $arr = array("ip" => getIP(), "agent" => $_SERVER['HTTP_USER_AGENT'], "referer" => $_SERVER['HTTP_REFERER'], 'browser' => analyse($_SERVER['HTTP_USER_AGENT']), "service" => (int) getvar('service', 'post'), "phone" => $matches[0], "status" => 0, "date" => date('Y-m-d H:m:s'));
            $r = $reserve->add($arr);
            if ($r) {
                redirect('reserveSuccess');
            }
        } else {
            setHint('您输入的电话号码已经存在,请重新输入');
            redirect('reserve');
        }
    } else {
        setHint('电话号码有误,请重新输入');
        redirect('reserve');
    }
}
    $xmlRecord->appendChild(new DOMElement('relative_cost', $realCost));
    $xmlRecord->appendChild(new DOMElement('product_name', $product['product_name']));
    $xmlRecord->appendChild(new DOMElement('family_id', $product['family_id']));
    $xmlRecord->appendChild(new DOMElement('family_name', $product['family_name']));
    $totalCost += $realCost;
    $offset++;
    $pBar->updateValue($offset);
}
print "\n";
$xml->appendChild(new DOMElement('total_cost', $totalCost));
print $xml->saveXML();
print sprintf("this script lasted %d seconds !\n", intval(date("U") - $startTime));
// analysis part
function analyse($info)
{
    $total = $saved = $repeated = 0;
    foreach ($info as $id => $count) {
        if ($count > 1) {
            $saved += $count - 1;
            $repeated++;
        }
        $total += $count;
    }
    print_r(array('total' => $total, 'repeated' => $repeated, 'saved' => $saved, 'count' => count($info)));
}
analyse($analysis);
$content = "";
foreach ($analysis as $id => $count) {
    $content .= sprintf("%s,%d\n", $id, $count);
}
file_put_contents('analysis.csv', $content);
Example #4
0
    function analyse_result($original, $target)
    {
        $return = analyse($original, $target);
        $table1 = draw_table($return[0], 1, 'org_');
        $table2 = draw_table($return[1], 0, 'tar_');
        $table1_fix = $table2[2] > $table1[2] ? $table2[2] - $table1[2] : 0;
        $table2_fix = $table1[2] > $table2[2] ? $table1[2] - $table2[2] : 0;
        $str = '<style>
		.compare{
			width:480px;
			float:left;
			table-layout:fixed;
			overflow:auto;
			height:430px;
			float:left;
		}
	
		.code{
			width:40%;
			word-break:keep-all;
			white-space:nowrap;
			overflow:hidden;
			text-overflow:ellipsis;
		}
	
		.fix
		{
			background-color:#EADAEB;
		}
	
		.notsame
		{
			background-color:#DD5C67;
		}
	
		.span_diff
		{
			background-color:#DD5C67;
		}
	
		.span_same
		{
			background:transparent;
		}
	
		.blank
		{
			background-color:#FFFFFF;
		}
	
		.hover
		{
			background-color:#ffffce;
		}
		</style>
		<script>
			$(document).ready(
			function(){
				jQuery("tr").each(
					function(){
						$(this).mouseover(
							function(){
								var id = this.id.substr(4);
								$("#org_" + id).addClass("hover");
								$("#tar_" + id).addClass("hover");
							}
						);
						$(this).mouseout(
							function(){
								var id = this.id.substr(4);
								$("#org_" + id).removeClass("hover");
								$("#tar_" + id).removeClass("hover");
							}
						);
					}
				);
				jQuery(".compare").each(
					function(){
						$(this).scroll(
							function(){
								var id = this.id.substr(4);
								$("#org_" + id).scrollTop($(this).scrollTop());
								$("#tar_" + id).scrollTop($(this).scrollTop());
								$("#org_" + id).scrollLeft($(this).scrollLeft());
								$("#tar_" + id).scrollLeft($(this).scrollLeft());
							}
						);
					}
				);
			}
			);
		</script>';
        $str_1 = '<div style="float:left;"><div class="comp-head"><div class="comp-thead">原模板内容</div><div class="comp-thead">新模板内容</div></div>';
        $str1 = $str . $str_1 . '<div class="compare" id="org_container" ><table border="0" cellspacing="0" cellpadding="0" class="">';
        $str1 .= $table1[0];
        $str3 = '';
        for ($i = 1; $i <= $table1_fix; $i++) {
            $str1 . '<tr class="fix" id="org_' . $table1[2] . '"><td colspan="2">' . ($i + $table1[1]) . '</td></tr>';
            $table1[2]++;
        }
        $str1 .= '</table></div>';
        $str2 = $str . '<div class="compare" id="tar_container"><table border="0" cellspacing="0" cellpadding="0" class="">';
        $str2 .= $table2[0];
        $str3 .= $table2[0];
        for ($i = 1; $i <= $table2_fix; $i++) {
            $str2 .= '<tr class="fix" id="tar_' . $table2[2] . '"><td colspan="2">&nbsp;</td></tr>';
            $table2[2]++;
        }
        $str2 .= '</table></div></div>';
        $table = array($str1, $str2, $target);
        return $table;
    }
Example #5
0
function analyse($fname, $searchstr, $nbligne, $searchstr2, $searchnot)
{
    $res = "";
    //  echo "analyse $fname for $searchstr<br />";
    if (is_dir($fname)) {
        //    $res.="<tr><td>digging in dir <b>$fname</b></td>";
        $lines = @file($fname);
        $count = count($lines);
        if ($count == 0 or !isset($line)) {
            //		  $res.="<tr><td>pb with file ".$fname."</td>";
        }
        for ($ii = 0; $ii < $count; $ii++) {
            $res .= analyse($line[$ii], $searchstr, $nbligne, $searchstr2, $searchnot);
        }
    } else {
        $res .= showfile($fname, $searchstr, $nbligne, $searchstr2, $searchnot);
    }
    return $res;
}
Example #6
0
$authorization = "Basic INCLUDE HTTP BASIC AUTH";
if (file_exists('config.php')) {
    include 'config.php';
}
// Start with the first result that Europeana finds.
$index = 1;
// Call 96 results starting from index
$responds = call($index, $key);
$total = $responds["totalResults"];
// Let's not get let not waste the first 96 respondses
analyse($responds, $authorization);
$total - 96;
// loop over remaining respondses
while ($total > 0) {
    $index += 96;
    analyse(call($index, $key), $authorization);
    $total -= 96;
}
// Calls the API for all objects that have direct links, AND SEARCHES FOR MAARTEN AS A TEST SET
function call($index, $key)
{
    $api = "http://europeana.eu/api/v2/search.json?";
    // FOR TESTING: Remove the query=octopus by query=*:* here to get to the 15 million objects, it now returns ~200 objects.
    $search = "&rows=96&profile=standard+portal+rich+facets&query=octopus&qf=provider_aggregation_edm_isShownBy:*+TYPE:IMAGE";
    $call = $api . $search . "&start=" . $index . $key;
    return json_decode(file_get_contents($call), true);
}
// Analyses a serie of works in a Europeana API responds (items)
function analyse($works, $authorization)
{
    $items = $works['items'];