示例#1
0
<?php

function BubbleSort($arr)
{
    $temp = "";
    for ($i = 0; $i < count($arr); $i++) {
        //这个从第一个数据开始  跟后面的其他数据开始比较
        for ($j = $i + 1; $j < count($arr); $j++) {
            //从刚开始的数据开始  跟后面的数据开始
            //如果后面的比前面的小 就开始交换数据
            if ($arr[$i] > $arr[$j]) {
                $temp = $arr[$i];
                $arr[$i] = $arr[$j];
                $arr[$j] = $temp;
            }
        }
    }
    return $arr;
}
$arr = array(9, 4, 5, 6, 8, 3, 2, 7, 10, 1);
print_r(BubbleSort($arr));
/**
The xml should be
<Address>
<Value></Value>
<Info></Info>
<Stops>
<Stop>
<Name></Name>
<Latitude></Latitude>
<Longitude></Longitude>
<Distance></Distance>
<Buses></Buses>
</Stop>
.
.
</Stops>
<Result>
<BusStop></BusStop>
<BusStopLatitude></BusStopLatitude>
<BusStopLongitude></BusStopLongitude>
<Offset></Offset>
</Result>
</Address>
 **/
function getStopForAddress($addr, $log, $mediaType)
{
    //echo $addr;
    $stopDataString = '';
    $originalRequestedLatitude = 0;
    $originalRequestedLongitude = 0;
    // create a xml string
    $stopXMLString = '<Address>';
    $query = "Select StopName, Latitude, Longitude from Stops Where StopName = '" . $addr . "'";
    $result = mysql_query($query);
    $rowsnum = mysql_num_rows($result);
    //find from the stop table..more than one stop found
    //	if($rowsnum>1)
    //	{
    //		if($DEBUG)
    //			echo "more than one stops are found with your search criteria <br/>";
    //		$log->LogDebug("[".$mediaType."] The address ".$addr." matches more than one in stops table. taking the first one ");
    //		$stopXMLString=$stopXMLString."<Info>More than one stops are found with your search criteria</Info>";
    //		$stopXMLString=$stopXMLString."<ErrorCode>MS</ErrorCode>";
    //		$stopXMLString=$stopXMLString."<Stops>";
    //		// this is the case wehre we can check which is the best choice in terms of buses coming thourgh..E.g. Marathahalli
    //		$maxBus=0;
    //		for($i=0;$i<$rowsnum;$i++)
    //		{
    //			$row=mysql_fetch_row($result);
    //			$stopXMLString=$stopXMLString."<Stop>";
    //		   if($DEBUG)
    //			 echo $row[0]."<br/>";
    //
    //			$stopXMLString=$stopXMLString."<Name>".htmlentities($row[0])."</Name>";
    //			$stopXMLString=$stopXMLString."<Latitude>".$row[1]."</Latitude>";
    //			$stopXMLString=$stopXMLString."<Longitude>".$row[2]."</Longitude>";
    //			$stopXMLString=$stopXMLString."<Distance>-1</Distance>";
    //			$stopXMLString=$stopXMLString."<Buses>".getBusesForStop($row[0])."</Buses>";
    //
    //			// $stopDetails=$row[0];
    //			//$map->addMarkerByCoords($row[2],$row[1],$row[0],getBusesForStop($row[0]),'');
    //			$NumberOfBus=getNumberOfBusesForStop($row[0]);
    //			if($NumberOfBus>$maxBus)
    //			{
    //				$maxBus=$NumberOfBus;
    //				$stopDataString=$row[0].":".$row[1].":".$row[2].":0";
    //			}
    //			$stopXMLString=$stopXMLString."</Stop>";
    //		}
    //		$stopXMLString=$stopXMLString."</Stops>";
    //	}
    //	else //only one stop is found
    // if the stop is found
    if ($rowsnum == 1) {
        $stopXMLString = $stopXMLString . "<Info>Your address matches the correct stop name</Info>";
        $stopXMLString = $stopXMLString . "<ErrorCode>OS</ErrorCode>";
        $stopXMLString = $stopXMLString . "<Stops>";
        $stopXMLString = $stopXMLString . "<Stop>";
        $row = mysql_fetch_row($result);
        //        if($DEBUG)
        //            echo " Your stop is ".$row[0]."<br/>";
        $log->LogDebug("[" . $mediaType . "] The address " . $addr . " is a valid stopname ");
        $stopXMLString = $stopXMLString . "<Name>" . htmlentities($row[0]) . "</Name>";
        $stopXMLString = $stopXMLString . "<Latitude>" . $row[1] . "</Latitude>";
        $stopXMLString = $stopXMLString . "<Longitude>" . $row[2] . "</Longitude>";
        $stopXMLString = $stopXMLString . "<Distance>-1</Distance>";
        $stopXMLString = $stopXMLString . "<Buses>" . getBusesForStop($row[0]) . "</Buses>";
        $stopXMLString = $stopXMLString . "</Stop>";
        // $map->addMarkerByCoords($row[2],$row[1],$row[0],getBusesForStop($row[0]),'');
        $stopDataString = $row[0] . ":" . $row[1] . ":" . $row[2] . ":0";
        $stopXMLString = $stopXMLString . "</Stops>";
    } else {
        //no stop found..user must have entered some free string
        if ($rowsnum == 0) {
            //First check in the road database if the address meets
            //echo "going to the roads database"."<br/>";
            // Checking in the road database
            $query = "Select * from newRoadAddresses Where Address ='" . $addr . "'";
            $result = mysql_query($query);
            $rowsnum = mysql_num_rows($result);
            //the address was not found in the road database so get it from internet
            if ($rowsnum == 0) {
                //                if($DEBUG)
                //                    echo "The address not found in the database so fetching from internet <br/>";
                //$stopXMLString=$stopXMLString."<Info>The address ".$addr." not found in the database so fetching from internet</Info>";
                $logString = "[" . $mediaType . "] The address " . $addr . " not found in the database so fetching from internet ";
                //$log->LogDebug("[".$mediaType."] The address ".$addr." not found in the database so fetching from internet ");
                // fimd from the net
                $addressString = "http://maps.google.com/maps/api/geocode/json?address=" . urlencode($addr) . ",+Bangalore,+Karnataka,+India&sensor=false";
                $geocode = file_get_contents($addressString);
                $formattedAddress = return_between($geocode, "formatted_address", "\",", EXCL);
                $formattedAddressNoiseRemoved = return_between($formattedAddress, ":", "India", INCL);
                $place = substr($formattedAddressNoiseRemoved, 3);
                //echo $place."<br/>";
                //exit(0);
                ///echo $place."<br/>";
                //$arr=array();
                $arr = explode(",", $place);
                //the address was not at all valid
                if (strcmp(trim($arr[0]), "Bangalore") == 0 && strcmp(trim($arr[1]), "Karnataka") == 0 && strcmp(trim($arr[2]), "India") == 0) {
                    $log->LogDebug($logString . ". Invalid Address provided ");
                    $stopXMLString = $stopXMLString . "<Info>Address is not valid. Try giving some locality name</Info>";
                    $stopXMLString = $stopXMLString . "<ErrorCode>AM</ErrorCode>";
                    $stopXMLString = $stopXMLString . "<Stops>";
                    $stopXMLString = $stopXMLString . "<Stop>";
                    $stopXMLString = $stopXMLString . "</Stop>";
                    $stopXMLString = $stopXMLString . "</Stops>";
                    //                    if($DEBUG)
                    //                        echo "<h3>".trim($addr)."  Address is not valid"."</h3><br/>";
                    $stopDataString = "0:0:0:0";
                } else {
                    $locations = return_between($geocode, "location", "}", EXCL);
                    //echo $locations;
                    $latitude = return_between($locations, "lat\"", ",", EXCL);
                    $latitude = substr($latitude, 3);
                    //echo $latitude;
                    list($lat, $long) = explode(",", $locations);
                    list($cap, $val) = explode(":", $long);
                    //echo trim($val);
                    $addrLat = trim($latitude);
                    $addrLong = trim($val);
                    $originalRequestedLatitude = $addrLat;
                    $originalRequestedLongitude = $addrLong;
                    // add the marker for the searched address
                    //$map->addMarkerIcon("marker_star.png","marker_shadow.png",15,29,15,3);
                    //$map->addMarkerByCoords($addrLong,$addrLat,$addr,'','');
                    //Now check that we have any stop that is within 1 km of the stop.
                    //we need to use the direct method to calculate the distance
                    // we could have used the heversine formaula also but this is OK
                    $query = "SELECT  StopName, Latitude, Longitude FROM Stops WHERE (Latitude - " . $addrLat . " < .009) AND (Latitude - " . $addrLat . " > - .009) AND (Longitude - " . $addrLong . " > - .009) AND (Longitude - " . $addrLong . " < 0.009)";
                    //echo $query."<br/>";
                    $result = mysql_query($query);
                    $rowsnum = mysql_num_rows($result);
                    //we could not find any stops near to this address.
                    if ($rowsnum == 0) {
                        // this is the case when you gave an address that even could not be found usign the internet search
                        $log->LogDebug($logString . ". No Stops nearby");
                        $stopXMLString = $stopXMLString . "<Info>Sorry we could not find any stops nearby</Info>";
                        $stopXMLString = $stopXMLString . "<ErrorCode>AM</ErrorCode>";
                        $stopXMLString = $stopXMLString . "<Stops>";
                        $stopXMLString = $stopXMLString . "<Stop>";
                        $stopXMLString = $stopXMLString . "</Stop>";
                        $stopXMLString = $stopXMLString . "</Stops>";
                        //                        if($DEBUG)
                        //                            echo "<h3>".trim($addr)."  Address is not valid"."</h3><br/>";
                        $stopDataString = "0:0:0:0";
                    } else {
                        $arrBusStops = array();
                        for ($i = 0; $i < $rowsnum; $i++) {
                            $row = mysql_fetch_row($result);
                            //echo $row[0];
                            $dist = distance($addrLat, $addrLong, $row[1], $row[2], "K");
                            $BDS = new BusDataStructure($row[0], $row[1], $row[2], $dist);
                            array_push($arrBusStops, $BDS);
                            //echo distance($addrLat, $addrLong, $row[1],$row[2], "K") . " kilometers<br>";
                            //$map->addMarkerByCoords($row[2],$row[1],$row[0].distance($addrLat, $addrLong, $row[1],$row[2], "K"),'','');
                        }
                        // now do the comparison of the data
                        //sort the stops in the order of some preference
                        $tempSortedArray = BubbleSort($arrBusStops, $rowsnum);
                        // this is the place to do One more level of filtering based on the number of buses
                        $sortedArray = applyFilterForAddress($tempSortedArray);
                        //print_r($sortedArray);
                        $log->LogDebug($logString . ". Valid Address found via internet");
                        $stopXMLString = $stopXMLString . "<Info>Address Found via Internet</Info>";
                        $formattedPlace = preg_replace('/Bangalore, Karnataka, India$/', '', $place);
                        $formattedPlaceRemovingTrailingComma = rtrim(trim($formattedPlace), ",");
                        $stopXMLString = $stopXMLString . "<InternetAddress>" . $formattedPlaceRemovingTrailingComma . "</InternetAddress>";
                        $stopXMLString = $stopXMLString . "<ErrorCode>IA</ErrorCode>";
                        $stopXMLString = $stopXMLString . "<Stops>";
                        for ($i = 0; $i < sizeof($sortedArray); $i++) {
                            //echo $sortedArray[$i]->getStopName().$sortedArray[$i]->getDistance()."<br/>";
                            $stopXMLString = $stopXMLString . "<Stop>";
                            //$map->addMarkerByCoords($sortedArray[$i]->getLongitude(),$sortedArray[$i]->getLatitude(),$sortedArray[$i]->getStopName().$sortedArray[$i]->getDistance(),getBusesForStop($sortedArray[$i]->getStopName()),'');
                            $stopXMLString = $stopXMLString . "<Name>" . htmlentities($sortedArray[$i]->getStopName()) . "</Name>";
                            $stopXMLString = $stopXMLString . "<Latitude>" . $sortedArray[$i]->getLatitude() . "</Latitude>";
                            $stopXMLString = $stopXMLString . "<Longitude>" . $sortedArray[$i]->getLongitude() . "</Longitude>";
                            $stopXMLString = $stopXMLString . "<Distance>" . $sortedArray[$i]->getDistance() . "</Distance>";
                            $stopXMLString = $stopXMLString . "<Buses>" . getBusesForStop($sortedArray[$i]->getStopName()) . "</Buses>";
                            $stopXMLString = $stopXMLString . "</Stop>";
                        }
                        $stopXMLString = $stopXMLString . "</Stops>";
                        $stopDataString = $sortedArray[0]->getStopName() . ":" . $sortedArray[0]->getLatitude() . ":" . $sortedArray[0]->getLongitude() . ":" . $sortedArray[0]->getDistance();
                    }
                }
            } else {
                if ($rowsnum > 1) {
                    $stopXMLString = $stopXMLString . "<Info>More than one matching address found in road database. Kindly add some more specifics</Info>";
                    $stopXMLString = $stopXMLString . "<ErrorCode>MA</ErrorCode>";
                    $stopXMLString = $stopXMLString . "<Stops>";
                    $stopXMLString = $stopXMLString . "<Stop>";
                    $stopXMLString = $stopXMLString . "</Stop>";
                    $stopXMLString = $stopXMLString . "</Stops>";
                    //                if($DEBUG)
                    //                    echo "More than one matching address found in road database. Kindly add some more specifics";
                    $stopDataString = "m:m:m:m";
                } else {
                    //                if($DEBUG)
                    //                    echo "Found in the road database"."<br/>";
                    // we found the address in th road data base but unfortunately all the stops are more than KM .
                    // this issue will not be there after we have the pegging of the stops.
                    // in the first sql itself we will know the stop that is meant for this road address
                    $log->LogDebug("[" . $mediaType . "] The address " . $addr . " found in the road database ");
                    $row = mysql_fetch_row($result);
                    $addrLat = $row[3];
                    $addrLong = $row[4];
                    $stopNumber = $row[5];
                    $stopName = $row[6];
                    $vicinityDistance = $row[7];
                    $originalRequestedLatitude = $addrLat;
                    $originalRequestedLongitude = $addrLong;
                    //get the latutude/logitude of the stop
                    $sqlStop = "Select * from Stops where SNo='" . $stopNumber . "'";
                    $resultStop = mysql_query($sqlStop);
                    $rowStop = mysql_fetch_row($resultStop);
                    $stopLat = $rowStop[2];
                    $stopLon = $rowStop[3];
                    $stopXMLString = $stopXMLString . "<Info>Address Found in the Road Database</Info>";
                    $stopXMLString = $stopXMLString . "<ErrorCode>RA</ErrorCode>";
                    $stopXMLString = $stopXMLString . "<Stops>";
                    $stopXMLString = $stopXMLString . "<Stop>";
                    //$map->addMarkerByCoords($sortedArray[$i]->getLongitude(),$sortedArray[$i]->getLatitude(),$sortedArray[$i]->getStopName().$sortedArray[$i]->getDistance(),getBusesForStop($sortedArray[$i]->getStopName()),'');
                    $stopXMLString = $stopXMLString . "<Name>" . htmlentities($stopName) . "</Name>";
                    $stopXMLString = $stopXMLString . "<Latitude>" . $stopLat . "</Latitude>";
                    $stopXMLString = $stopXMLString . "<Longitude>" . $stopLon . "</Longitude>";
                    $stopXMLString = $stopXMLString . "<Distance>" . $vicinityDistance . "</Distance>";
                    $stopXMLString = $stopXMLString . "<Buses>" . getBusesForStop($stopName) . "</Buses>";
                    $stopXMLString = $stopXMLString . "</Stop>";
                    $stopXMLString = $stopXMLString . "</Stops>";
                    $stopDataString = $stopName . ":" . $stopLat . ":" . $stopLon . ":" . $vicinityDistance;
                    //echo $addrLat;
                    //$map->addMarkerByCoords($addrLong,$addrLat,$addr,'','');
                    /*$query="SELECT  StopName, Latitude, Longitude FROM Stops WHERE (Latitude - ".$addrLat." < .009) AND (Latitude - ".$addrLat." > - .009) AND (Longitude - ".$addrLong." > - .009) AND (Longitude - ".$addrLong." < 0.009)";
                                    //echo $query."<br/>";
                                    $result= mysql_query($query);
                                    $rowsnum = mysql_num_rows($result);
                                    if($rowsnum==0)
                                    {
                                        $stopXMLString=$stopXMLString."<Info>All stops are more then 1 km far</Info>";
                                        $stopXMLString=$stopXMLString."<ErrorCode>KM</ErrorCode>";
                                        $stopXMLString=$stopXMLString."<Stops>";
                                        $stopXMLString=$stopXMLString."<Stop>";
                                        $stopXMLString=$stopXMLString."</Stop>";
                                        $stopXMLString=$stopXMLString."</Stops>";
                                        //echo "All stops are more then 1 km far";
                                    }
                                    else
                                    {
                                        // we should try to show nearest 5 at the max
                                        // one way is to create a array of datastructure and then sort them on the basis of distance.
                                        // also find the buses for the finalised stops
                                        $arrBusStops= array();
                                        $stopXMLString=$stopXMLString."<Info>Address Found in the Road Database</Info>";
                                        $stopXMLString=$stopXMLString."<ErrorCode>RA</ErrorCode>";
                                        for($i=0;$i<$rowsnum;$i++)
                                        {
                                            $row=mysql_fetch_row($result);
                                            $dist=distance($addrLat, $addrLong, $row[1],$row[2], "K");
                                            $BDS= new BusDataStructure($row[0],$row[1],$row[2],$dist);
                                            array_push($arrBusStops,$BDS);
                    
                                        }
                                        // now do the comparison of the data
                                        $tempSortedArray=BubbleSort($arrBusStops,$rowsnum);
                                        // this is the place to do One more level of filtering based on the number of buses
                                        $sortedArray=applyFilterForAddress($tempSortedArray);
                                        //print_r($sortedArray);
                                        $stopXMLString=$stopXMLString."<Stops>";
                                        for($i=0;$i<sizeof($sortedArray);$i++)
                                        {
                                            //echo $sortedArray[$i]->getStopName().$sortedArray[$i]->getDistance()."<br/>";
                                        $stopXMLString=$stopXMLString."<Stop>";	//$map->addMarkerByCoords($sortedArray[$i]->getLongitude(),$sortedArray[$i]->getLatitude(),$sortedArray[$i]->getStopName().$sortedArray[$i]->getDistance(),getBusesForStop($sortedArray[$i]->getStopName()),'');
                                        $stopXMLString=$stopXMLString."<Name>".htmlentities($sortedArray[$i]->getStopName())."</Name>";
                                        $stopXMLString=$stopXMLString."<Latitude>".$sortedArray[$i]->getLatitude()."</Latitude>";
                                        $stopXMLString=$stopXMLString."<Longitude>".$sortedArray[$i]->getLongitude()."</Longitude>";
                                        $stopXMLString=$stopXMLString."<Distance>".$sortedArray[$i]->getDistance()."</Distance>";
                                        $stopXMLString=$stopXMLString."<Buses>".getBusesForStop($sortedArray[$i]->getStopName())."</Buses>";
                                        $stopXMLString=$stopXMLString."</Stop>";
                    
                                        }
                                        $stopXMLString=$stopXMLString."</Stops>";
                                        $stopDataString=$sortedArray[0]->getStopName().":".$sortedArray[0]->getLatitude().":".$sortedArray[0]->getLongitude().":".$sortedArray[0]->getDistance();
                    
                                    }*/
                }
            }
        }
    }
    $stopXMLString = $stopXMLString . "<Result>";
    list($BusStop, $BusLatitude, $BusLongitude, $BusOffset) = explode(":", $stopDataString);
    $stopXMLString = $stopXMLString . "<BusStop>" . htmlentities($BusStop) . "</BusStop>";
    $stopXMLString = $stopXMLString . "<BusStopLatitude>" . $BusLatitude . "</BusStopLatitude>";
    $stopXMLString = $stopXMLString . "<BusStopLongitude>" . $BusLongitude . "</BusStopLongitude>";
    $stopXMLString = $stopXMLString . "<Offset>" . $BusOffset . "</Offset>";
    $stopXMLString = $stopXMLString . "<Buses>" . getBusesForStopWithFrequency($BusStop) . "</Buses>";
    $stopXMLString = $stopXMLString . "<OriginalStopLatitude>" . $originalRequestedLatitude . "</OriginalStopLatitude>";
    $stopXMLString = $stopXMLString . "<OriginalStopLongitude>" . $originalRequestedLongitude . "</OriginalStopLongitude>";
    $stopXMLString = $stopXMLString . "</Result>";
    $stopXMLString = $stopXMLString . "</Address>";
    return $stopXMLString;
}
示例#3
0
/**
* getJunctionsForIndirectBuses: function to find the junction. The junction is same as the stop only difference is that some
* of the stops have mulitple names we need to normalize them. It will combine the buses that are passing to the same 
* junction. The function is mailnly to control the way the informatioin is displayed to the user

change: 27Dec2011
In case when either the bus from the start stop to first junction is not present or the bus from the second jucntion to the end stop is not present
I am removing that particular entry (error code6) but we can as well say in the javascript that this is the case when the user can just walk to/from the 
junction .. Need to chekc on this

The error codes
0: Direct buses are found
1: only one jucntion found same as search" Bellandur" to Forum Mall
2.: One junction but then the user needs to walk to the endpoint. no need to take a bus: search string abhi yaad nahin aa rahi
3: two junctions. User needs to walk between the junction search "Bellandur" "Meanee Avenue Road"
4: No route was found ....give some junk values
5: Distance is walkable no bus to take search Bellandur and Accenture
6: Ignore this particular enetry


**/
function getJunctionsForIndirectBuses($arrBuses, $startStop, $endStop, $startOffsetDistance, $endOffsetDistance)
{
    //print_r($arrBuses);
    $array_size = sizeof($arrBuses);
    // check if the buses are direct buses
    list($firstBus, $secondBus) = split(":", $arrBuses[0]);
    if ($array_size > 0 && strcmp($firstBus, $secondBus) == 0) {
        return displayDirectBuses($arrBuses);
    } else {
        $arrFirstJunctions = array();
        $arrSecondJunctions = array();
        $arrFirstBuses = array();
        $arrSecondBuses = array();
        for ($i = 0; $i < $array_size; $i++) {
            list($firstBus, $secondBus) = split(":", $arrBuses[$i]);
            array_push($arrFirstBuses, $firstBus);
            array_push($arrSecondBuses, $secondBus);
        }
        //print_r($arrFirstBuses);
        $arrayUniqueJunctions = array();
        for ($i = 0; $i < $array_size; $i++) {
            list($firstBus, $secondBus) = split(":", $arrBuses[$i]);
            list($firstBus, $firstBusRouteNumber, $firstJunction, $secondBus, $secondBusRouteNumber, $secondJunction, $distance) = split(":", getIntermediateStopsAndDistance($firstBus, $secondBus));
            if (strlen($firstBus) == 0) {
                continue;
            }
            // this is the case of wrong combinations
            //  echo getIntermediateStopsAndDistance($firstBus,$secondBus)."<br/>";
            // find the uniue combinations of fisrt and second junctions
            if ($distance < 0.6) {
                if (checkUniqueJunctions($arrayUniqueJunctions, $firstJunction, $secondJunction, $distance) == 0) {
                    // also chekc that the endstop or the start stop is not same as the juntion as in case of marathahalli bridge and multiplex
                    if (strcmp(getNormalizedStopName($firstJunction), $startStop) == 0 || strcmp(getNormalizedStopName($firstJunction), $endStop) == 0 || strcmp(getNormalizedStopName($secondJunction), $startStop) == 0 || strcmp(getNormalizedStopName($secondJunction), $endStop) == 0) {
                        continue;
                    } else {
                        $element = getNormalizedStopName($firstJunction) . ":" . getNormalizedStopName($secondJunction) . ":" . $distance;
                        array_push($arrayUniqueJunctions, $element);
                    }
                }
            }
        }
        //print_r($arrayUniqueJunctions);
        // module to sort the results on the basids of the total distance
        $displayJunctionsDataArray = array();
        for ($i = 0; $i < sizeof($arrayUniqueJunctions); $i++) {
            $tempJunctionString = $arrayUniqueJunctions[$i];
            list($firstJnName, $secondJnName, $distanceJn) = split(":", $arrayUniqueJunctions[$i]);
            $tot = getTotalRouteDistance($startStop, $firstJnName, $secondJnName, $distanceJn, $endStop, $startOffsetDistance, $endOffsetDistance);
            $element = new DisplayJunctionsData($tempJunctionString, $tot);
            array_push($displayJunctionsDataArray, $element);
        }
        $SortedJunctionsDataArray = prioritizeAndSortJunctionArray(BubbleSort($displayJunctionsDataArray, sizeof($displayJunctionsDataArray)));
        //echo "sdsd";
        //print_r($SortedJunctionsDataArray);
        // display the results
        $strRoute = '';
        if (sizeof($SortedJunctionsDataArray) == 0) {
            $strRoute = '<Routes>';
            $strRoute = $strRoute . '<Route>';
            $strRoute = $strRoute . '<IsDirectRoute>N</IsDirectRoute>';
            $strRoute = $strRoute . '<ErrorCode>4</ErrorCode>';
            $strRoute = $strRoute . '</Route>';
            $strRoute = $strRoute . '</Routes>';
        } else {
            $strRoute = '<Routes>';
            // there can be chances that when we are filling the xml all the details are not properly found. In that case we need to
            // remove that entry. If at the end this check counter becomes equals to the sizeof($SortedJunctionsDataArray). It means every entry had a problem
            // and we will return the error code 4
            $FalseAlarmCounter = 0;
            for ($i = 0; $i < sizeof($SortedJunctionsDataArray); $i++) {
                $isCorrectEntry = 1;
                // check if this particular entry is correct. Since the node need to be removed otherwise
                if ($i > 2) {
                    // this will restrict the indirect results to 3
                    break;
                }
                list($firstJnName, $secondJnName, $distanceJn) = split(":", $SortedJunctionsDataArray[$i]->getJunctionString());
                //get all the buses for firstJn
                $strRoute = $strRoute . '<Route>';
                $strRoute = $strRoute . '<IsDirectRoute>N</IsDirectRoute>';
                //get all the buses for second jun
                if ($distanceJn == 0 && strcmp(getNormalizedStopName($firstJnName), $startStop) != 0) {
                    $getCommonBusesForFirstJunction = getCommonBusesForNormalizedStopName($firstJnName, $arrFirstBuses);
                    $getCommonBusesForSecondJunction = getCommonBusesForNormalizedStopName($secondJnName, $arrSecondBuses);
                    if (strlen($getCommonBusesForFirstJunction) > 0 && strlen($getCommonBusesForSecondJunction) > 0) {
                        $strRoute = $strRoute . '<ErrorCode>1</ErrorCode>';
                        $routeDetail = htmlentities($startStop) . ":" . $getCommonBusesForFirstJunction . ":";
                        $routeDetail = $routeDetail . htmlentities(getNormalizedStopName($firstJnName)) . ":" . getLatitudeLongitude(getNormalizedStopName($firstJnName)) . ":0:";
                        $routeDetail = $routeDetail . htmlentities(getNormalizedStopName($firstJnName)) . ":" . getLatitudeLongitude(getNormalizedStopName($firstJnName)) . ":" . $getCommonBusesForSecondJunction . ":";
                        $routeDetail = $routeDetail . htmlentities($endStop);
                    } else {
                        $strRoute = $strRoute . '<ErrorCode>6</ErrorCode>';
                        $FalseAlarmCounter++;
                    }
                } else {
                    // if the end point is same as the second junction it may happend that you juct have to walk from the first junction to the end point
                    if (strcmp(getNormalizedStopName($secondJnName), $endStop) == 0) {
                        $strRoute = $strRoute . '<ErrorCode>2</ErrorCode>';
                        $routeDetail = htmlentities($startStop) . ":" . getCommonBusesForNormalizedStopName($firstJnName, $arrFirstBuses) . ":";
                        $routeDetail = $routeDetail . htmlentities(getNormalizedStopName($firstJnName)) . ":" . getLatitudeLongitude(getNormalizedStopName($firstJnName)) . ":" . $distanceJn . ":";
                        $routeDetail = $routeDetail . htmlentities(getNormalizedStopName($firstJnName)) . ":" . getLatitudeLongitude(getNormalizedStopName($firstJnName)) . ":" . getCommonBusesForNormalizedStopName($secondJnName, $arrSecondBuses) . ":";
                        $routeDetail = $routeDetail . htmlentities($endStop);
                    } else {
                        $getCommonBusesForFirstJunction = getCommonBusesForNormalizedStopName($firstJnName, $arrFirstBuses);
                        $getCommonBusesForSecondJunction = getCommonBusesForNormalizedStopName($secondJnName, $arrSecondBuses);
                        if (strlen($getCommonBusesForFirstJunction) > 0 && strlen($getCommonBusesForSecondJunction) > 0) {
                            $strRoute = $strRoute . '<ErrorCode>3</ErrorCode>';
                            $routeDetail = htmlentities($startStop) . ":" . getCommonBusesForNormalizedStopName($firstJnName, $arrFirstBuses) . ":";
                            $routeDetail = $routeDetail . htmlentities(getNormalizedStopName($firstJnName)) . ":" . getLatitudeLongitude(getNormalizedStopName($firstJnName)) . ":" . $distanceJn . ":";
                            $routeDetail = $routeDetail . htmlentities(getNormalizedStopName($secondJnName)) . ":" . getLatitudeLongitude(getNormalizedStopName($secondJnName)) . ":" . getCommonBusesForNormalizedStopName($secondJnName, $arrSecondBuses) . ":";
                            $routeDetail = $routeDetail . htmlentities($endStop);
                        } else {
                            $FalseAlarmCounter++;
                        }
                    }
                }
                //echo "The approximate route distance="."<b>".$SortedJunctionsDataArray[$i]->getDistance()."KM</b>";
                $routeDetail = $routeDetail . ":" . $SortedJunctionsDataArray[$i]->getDistance();
                $strRoute = $strRoute . '<RouteDetails>' . $routeDetail . '</RouteDetails>';
                //echo "<hr/>";
                $strRoute = $strRoute . '</Route>';
                //echo $strRoute;
            }
            $strRoute = $strRoute . '</Routes>';
            // check if every thing was wrong that means we need to send the erro codes.
            if ($FalseAlarmCounter == sizeof($SortedJunctionsDataArray)) {
                $strRoute = '<Routes>';
                $strRoute = $strRoute . '<Route>';
                $strRoute = $strRoute . '<IsDirectRoute>N</IsDirectRoute>';
                $strRoute = $strRoute . '<ErrorCode>4</ErrorCode>';
                $strRoute = $strRoute . '</Route>';
                $strRoute = $strRoute . '</Routes>';
            }
        }
        return $strRoute;
    }
}
function TagCloud($c, $crono, $m, $e, $tb1, $tbn, $page, $tag_color, $bgcolor, $minSize, $maxSize, $dbh, $selection_list, $tag_cloud_title, $correlated, $tag_mode, $legend = false, $search = false, $tag_minimum_date = '0000-00-00', $children = "", $tag_hilite_color = "", $hilite_size = 0, $main_crono = -1, $language = 0, $locales = "")
{
    if ($crono == 0) {
        if ($tag_mode == 0) {
            $query = "SELECT COUNT(tag_x_message.tag_id) AS r, tag.tag_id, tag.tag_name, tag.tag_group_id, tag.is_study FROM tag,tag_x_message,message WHERE tag.tag_id = tag_x_message.tag_id AND tag_x_message.message_id = message.message_id AND message.channel_id = {$c} AND DATE(message.message_date) > '{$tag_minimum_date}' GROUP BY tag.tag_name ORDER BY r DESC LIMIT 0,{$m}";
        } else {
            $query = "SELECT COUNT(DISTINCT(message.message_sender)) AS r, tag.tag_id, tag.tag_name, tag.tag_group_id, tag.is_study FROM tag,tag_x_message,message WHERE tag.tag_id = tag_x_message.tag_id AND tag_x_message.message_id = message.message_id AND message.channel_id = {$c} AND DATE(message.message_date) > '{$tag_minimum_date}' GROUP BY tag.tag_name ORDER BY r DESC LIMIT 0,{$m}";
        }
    } else {
        if ($c == -3) {
            $filter = "AND tag.in_map = 1";
        } else {
            //$filter=RefineChannelFilter("",$c,1,$dbh);
            $filter = RefineChannelTagFilter($c, $dbh);
            if ($filter != "") {
                //$filter="AND message.message_id ".$filter;
                $filter = "AND tag.tag_id " . $filter;
            }
        }
        if ($tag_mode == 0) {
            if ($children == "") {
                $query = "SELECT COUNT(tag_x_message.tag_id) AS r, tag.tag_id, tag.tag_name, tag.tag_group_id, tag.is_study FROM tag,tag_x_message,message,channel WHERE tag.tag_id = tag_x_message.tag_id AND message.message_id = tag_x_message.message_id AND DATE(message.message_date) > '{$tag_minimum_date}' AND channel.channel_id = message.channel_id AND channel.is_visible = 1 AND channel.is_study = 0 AND channel.channel_id NOT IN ({$e}) " . $filter . " GROUP BY tag.tag_name ORDER BY r DESC LIMIT 0,{$m}";
            } else {
                $query = "SELECT COUNT(tag_x_message.tag_id) AS r, tag.tag_id, tag.tag_name, tag.tag_group_id, tag.is_study FROM tag,tag_x_message,message,channel WHERE tag.tag_id = tag_x_message.tag_id AND message.message_id = tag_x_message.message_id AND DATE(message.message_date) > '{$tag_minimum_date}' AND channel.channel_id = message.channel_id AND channel.is_visible = 1 AND channel.is_study = 0 AND channel.channel_id NOT IN ({$e}) AND channel.channel_id IN (" . $children . ") " . $filter . " GROUP BY tag.tag_name ORDER BY r DESC LIMIT 0,{$m}";
            }
        } else {
            if ($children == "") {
                $query = "SELECT COUNT(DISTINCT(message.message_sender)) AS r, tag.tag_id, tag.tag_name, tag.tag_group_id, tag.is_study FROM tag,tag_x_message,message,channel WHERE tag.tag_id = tag_x_message.tag_id AND message.message_id = tag_x_message.message_id AND DATE(message.message_date) > '{$tag_minimum_date}' AND channel.channel_id = message.channel_id AND channel.is_visible = 1 AND channel.is_study = 0 AND channel.channel_id NOT IN ({$e}) " . $filter . " GROUP BY tag.tag_name ORDER BY r DESC LIMIT 0,{$m}";
            } else {
                $query = "SELECT COUNT(DISTINCT(message.message_sender)) AS r, tag.tag_id, tag.tag_name, tag.tag_group_id, tag.is_study FROM tag,tag_x_message,message,channel WHERE tag.tag_id = tag_x_message.tag_id AND message.message_id = tag_x_message.message_id AND DATE(message.message_date) > '{$tag_minimum_date}' AND channel.channel_id = message.channel_id AND channel.is_visible = 1 AND channel.is_study = 0 AND channel.channel_id NOT IN ({$e}) AND channel.channel_id IN (" . $children . ") " . $filter . " GROUP BY tag.tag_name ORDER BY r DESC LIMIT 0,{$m}";
            }
        }
    }
    if ($correlated == "-1" && $search == false) {
        $deactivate = false;
        $x = "";
    } else {
        $deactivate = true;
        $x = explode(",", $correlated);
    }
    $result = mysql_query($query, $dbh);
    $ct = 0;
    $max = 0;
    $min = 9999;
    $cloud = "";
    $title = "";
    while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
        $name = GetTagTranslation($row[1], $language, $dbh);
        if ($name == "") {
            $name = $row[2];
        }
        if ($row[4] == 1) {
            $name = $name . "*";
        }
        if ($c == -3) {
            $gt = IsGeoTagged($dbh, $row[1]);
        } else {
            $gt = true;
        }
        if ($row[0] > 0 && $gt) {
            if ($ct < 10) {
                $title .= $name . " ";
            }
            $tags[$ct] = array("id" => $row[1], "name" => $name, "times" => $row[0], "group" => $row[3]);
            $ct++;
        }
    }
    if ($ct > 0) {
        $tags = CompressTags($tags, $tag_mode, $c, $crono, $dbh, $language);
        for ($i = 0; $i < sizeof($tags); $i++) {
            if ($tags[$i]["times"] > $max) {
                $max = $tags[$i]["times"];
            }
            if ($tags[$i]["times"] < $min) {
                $min = $tags[$i]["times"];
            }
        }
        if ($locales != "") {
            $locale = $locales[$language];
        } else {
            $locale = "";
        }
        $tags = BubbleSort($tags, $locale);
        $diff = $max - $min;
        if ($diff > 0) {
            $step = ($maxSize - $minSize) / $diff;
        } else {
            $step = 0;
        }
        $selection_list = str_replace("/", ",", $selection_list);
        $a = explode(",", $selection_list);
        for ($i = 0; $i < sizeof($tags); $i++) {
            $size = $minSize + ($tags[$i]["times"] - $min) * $step;
            if ($tags[$i]["times"] == 1) {
                $toolbox = $tb1[$tag_mode];
            } else {
                $toolbox = $tags[$i]["times"] . $tbn[$tag_mode];
            }
            if (strpos($tags[$i]["name"], "*") > 0) {
                $tags[$i]["name"] = str_replace("*", "", $tags[$i]["name"]);
                $tags[$i]["name"] = "<i>" . $tags[$i]["name"] . "</i>";
            }
            $color = $tag_color;
            $backcolor = $bgcolor;
            if ($search == false) {
                for ($j = 1; $j < sizeof($a); $j++) {
                    $b = explode(",", $tags[$i]["id"]);
                    for ($k = 0; $k < sizeof($b); $k++) {
                        if ($a[$j] == $b[$k]) {
                            $color = $bgcolor;
                            $backcolor = $tag_color;
                            break;
                        }
                    }
                }
            }
            if ($deactivate == false) {
                if ($legend == false) {
                    if ($c == -4) {
                        if ($size >= $hilite_size) {
                            $cloud = $cloud . "<li style=\"display: inline\"><a href=\"" . $page . "?c={$main_crono}&tag=" . $tags[$i]["id"] . "\" style=\"font-size: " . $size . "em; font-family: Arial,Helvetica; color: " . $tag_hilite_color . "; background-color: " . $backcolor . "\" title=\"" . $toolbox . "\">" . $tags[$i]["name"] . "</a></li> ";
                        } else {
                            $cloud = $cloud . "<li style=\"display: inline\"><a href=\"" . $page . "?c={$main_crono}&tag=" . $tags[$i]["id"] . "\" style=\"font-size: " . $size . "em; font-family: Arial,Helvetica; color: " . $color . "; background-color: " . $backcolor . "\" title=\"" . $toolbox . "\">" . $tags[$i]["name"] . "</a></li> ";
                        }
                    } else {
                        $cloud = $cloud . "<li style=\"display: inline\"><a href=\"" . $page . "?c={$c}&tag=" . $tags[$i]["id"] . "\" style=\"font-size: " . $size . "em; font-family: Arial,Helvetica; color: " . $color . "; background-color: " . $backcolor . "\" title=\"" . $toolbox . "\">" . $tags[$i]["name"] . "</a></li> ";
                    }
                } else {
                    $legend_tag_color = GetTagColor($dbh, $tags[$i]["id"]);
                    $cloud = $cloud . "<li style=\"display: inline\"><img src=\"includes/images/marker" . $legend_tag_color . "_ball.png\" align=\"absbottom\"><a href=\"" . $page . "?c={$c}&tag=" . $tags[$i]["id"] . "\" style=\"font-size: " . $size . "em; font-family: Arial,Helvetica; color: " . $color . "; background-color: " . $backcolor . "\" title=\"" . $toolbox . "\">" . $tags[$i]["name"] . "</a></li> ";
                }
            } else {
                $found = false;
                if ($search == false) {
                    for ($k = 0; $k < sizeof($x); $k++) {
                        $y = explode(",", $tags[$i]["id"]);
                        for ($l = 0; $l < sizeof($y); $l++) {
                            if ($x[$k] == $y[$l]) {
                                $found = true;
                                break;
                            }
                        }
                        if ($found == true) {
                            break;
                        }
                    }
                }
                if ($found == true) {
                    if ($legend == false) {
                        $cloud = $cloud . "<li style=\"display: inline\"><a href=\"" . $page . "?c={$c}&tag=" . $tags[$i]["id"] . "\" style=\"font-size: " . $size . "em; font-family: Arial,Helvetica; color: " . $color . "; background-color: " . $backcolor . "\" title=\"" . $toolbox . "\">" . $tags[$i]["name"] . "</a></li> ";
                    } else {
                        $legend_tag_color = GetTagColor($dbh, $tags[$i]["id"]);
                        $cloud = $cloud . "<li style=\"display: inline\"><img src=\"includes/images/marker" . $legend_tag_color . "_ball.png\" align=\"absbottom\"><a href=\"" . $page . "?c={$c}&tag=" . $tags[$i]["id"] . "\" style=\"font-size: " . $size . "em; font-family: Arial,Helvetica; color: " . $color . "; background-color: " . $backcolor . "\" title=\"" . $toolbox . "\">" . $tags[$i]["name"] . "</a></li> ";
                    }
                } else {
                    if ($legend == false) {
                        $cloud = $cloud . "<li style=\"display: inline\"><font style=\"font-size: " . $size . "em; font-family: Arial,Helvetica; color: " . $color . "; background-color: " . $backcolor . "\">" . $tags[$i]["name"] . "</font></li> ";
                    } else {
                        $legend_tag_color = GetTagColor($dbh, $tags[$i]["id"]);
                        $cloud = $cloud . "<li style=\"display: inline\"><img src=\"includes/images/marker" . $legend_tag_color . "_ball.png\" align=\"absbottom\"><font style=\"font-size: " . $size . "em; font-family: Arial,Helvetica; color: " . $color . "; background-color: " . $backcolor . "\">" . $tags[$i]["name"] . "</font></li> ";
                    }
                }
            }
        }
    }
    if ($cloud != "") {
        $cloud = "<li style=\"display: inline\"><font style=\"font-size:" . $maxSize . "em; color:" . $bgcolor . "; background-color:" . $tag_color . ";\">{$tag_cloud_title}</font></li> " . $cloud;
    }
    $tc[0] = $cloud;
    $tc[1] = $title;
    return $tc;
}
示例#5
0
/**
* getJunctionsForIndirectBuses: function to find the junction. The junction is same as the stop only difference is that some
* of the stops have mulitple names we need to normalize them. It will combine the buses that are passing to the same 
* junction. The function is mailnly to control the way the informatioin is displayed to the user
**/
function getJunctionsForIndirectBuses($arrBuses,$startStop,$endStop,$startOffsetDistance,$endOffsetDistance)
{
	//print_r($arrBuses);
	$array_size=sizeof($arrBuses);
	// check if the buses are direct buses
	list($firstBus,$secondBus)=split(":",$arrBuses[0]);
	if(strcmp($firstBus,$secondBus)==0)
		displayDirectBuses($arrBuses);
	
	// indirect buses
	else
	{
		$arrFirstJunctions=array();
		$arrSecondJunctions=array();
		$arrFirstBuses=array();
		$arrSecondBuses=array();
	

		for($i=0;$i<$array_size;$i++)
		{
			list($firstBus,$secondBus)=split(":",$arrBuses[$i]);
			
			array_push($arrFirstBuses,$firstBus);
			array_push($arrSecondBuses,$secondBus);
			
		}
		//print_r($arrFirstBuses);
		$arrayUniqueJunctions=array();
		for($i=0;$i<$array_size;$i++)
		{
			list($firstBus,$secondBus)=split(":",$arrBuses[$i]);
			list($firstBus,$firstBusRouteNumber,$firstJunction,$secondBus,$secondBusRouteNumber,$secondJunction,$distance)=split(":",getIntermediateStopsAndDistance($firstBus,$secondBus));
			if(strlen($firstBus)==0)
				continue;// this is the case of wrong combinations
		  //  echo getIntermediateStopsAndDistance($firstBus,$secondBus)."<br/>";
			// find the uniue combinations of fisrt and second junctions
			if($distance<1)// make suere that the distance between the junctions is not more than 1 km.
			{
				if(checkUniqueJunctions($arrayUniqueJunctions,$firstJunction,$secondJunction,$distance)==0)
				{
					$element=getNormalizedStopName($firstJunction).":".getNormalizedStopName($secondJunction).":".$distance;
					array_push($arrayUniqueJunctions,$element);
				}
			}
		}
		
		//echo "the unique ones are "."<br/>";
		//print_r($arrayUniqueJunctions);
		echo "<br/>";
		
		// module to sort the results on the basids of the total distance
		$displayJunctionsDataArray=array();
		for($i=0;$i<sizeof($arrayUniqueJunctions);$i++)
		{
			$tempJunctionString=$arrayUniqueJunctions[$i];
			list($firstJnName,$secondJnName,$distanceJn)=split(":",$arrayUniqueJunctions[$i]);
			$tot=getTotalRouteDistance($startStop,$firstJnName,$secondJnName,$distanceJn,$endStop,$startOffsetDistance,$endOffsetDistance);
			$element=new DisplayJunctionsData($tempJunctionString,$tot);
			array_push($displayJunctionsDataArray,$element);

		}
		
		$SortedJunctionsDataArray=BubbleSort($displayJunctionsDataArray,sizeof($displayJunctionsDataArray));
		//print_r($SortedJunctionsDataArray);
		// print the buses
		/*for($i=0;$i<sizeof($arrayUniqueJunctions);$i++)
		{
			list($firstJnName,$secondJnName,$distanceJn)=split(":",$arrayUniqueJunctions[$i]);
			//get all the buses for firstJn
			echo "From "."<b>".$startStop." (Starting Point)</b> take ". getCommonBusesForNormalizedStopName($firstJnName,$arrFirstBuses)." and go to ". "<b>".getNormalizedStopName($firstJnName)."</b><br/>" ;

			//get all the buses for second jun
			if($distanceJn==0)
			{
				echo "Now from ". "<b>".getNormalizedStopName($firstJnName)."</b>". " take one of the". getCommonBusesForNormalizedStopName($secondJnName,$arrSecondBuses)." buses to go to ". "<b>".$endStop. " (Your Destination)</b><br/>";
				//echo "The distance between the junction is ". $distanceJn ."<br/>";
			}
			else
			{
				echo "You need to walk to  "."<b>".getNormalizedStopName($secondJnName)."</b>" ." which is ".$distanceJn. "KM from ". "<b>".$firstJnName."</b><br/>";
				echo "Now from ". "<b>".getNormalizedStopName($secondJnName)."</b>"."take one of the". getCommonBusesForNormalizedStopName($secondJnName,$arrSecondBuses)." buses to go to ". "<b>".$endStop. "(Your Destination)</b><br/>";
			}
			
			echo "The approximate route distance="."<b>".getTotalRouteDistance($startStop,$firstJnName,$secondJnName,$distanceJn,$endStop,$startOffsetDistance,$endOffsetDistance)."KM</b>";
			echo "<hr/>";
			
			
		}*/
		for($i=0;$i<sizeof($SortedJunctionsDataArray);$i++)
		{
			list($firstJnName,$secondJnName,$distanceJn)=split(":",$SortedJunctionsDataArray[$i]->getJunctionString());
			//get all the buses for firstJn
			echo "From "."<b>".$startStop." (Starting Point)</b> take ". getCommonBusesForNormalizedStopName($firstJnName,$arrFirstBuses)." and go to ". "<b>".getNormalizedStopName($firstJnName)."</b><br/>" ;

			//get all the buses for second jun
			if($distanceJn==0)
			{
				echo "Now from ". "<b>".getNormalizedStopName($firstJnName)."</b>". " take one of the". getCommonBusesForNormalizedStopName($secondJnName,$arrSecondBuses)." buses to go to ". "<b>".$endStop. " (Your Destination)</b><br/>";
				//echo "The distance between the junction is ". $distanceJn ."<br/>";
			}
			else
			{
				if(strcmp(getNormalizedStopName($secondJnName),$endStop)==0)
				{
					echo "You need to walk from  "."<b>".getNormalizedStopName($firstJnName)."</b>" ." which is ".$distanceJn. "KM from ". "<b>".$endStop."</b><br/>";
				

				}
				else
				{
				echo "You need to walk to  "."<b>".getNormalizedStopName($secondJnName)."</b>" ." which is ".$distanceJn. "KM from ". "<b>".$firstJnName."</b><br/>";
				echo "Now from ". "<b>".getNormalizedStopName($secondJnName)."</b>"."take one of the". getCommonBusesForNormalizedStopName($secondJnName,$arrSecondBuses)." buses to go to ". "<b>".$endStop. "(Your Destination)</b><br/>";
				}
			}
			
			echo "The approximate route distance="."<b>".$SortedJunctionsDataArray[$i]->getDistance()."KM</b>";
			echo "<hr/>";
			
			
		}

	}
}
/**
 * Add FF comments to WP comments array Function
 * 
 * This function adds FF comments to WP comments array
 * 
 * @param array
 * 
 * @return array
 * 
 */
function set_comments_with_friendfeed($comments)
{
    global $post, $wpdb;
    $ff_item = $wpdb->get_row($wpdb->prepare("SELECT * FROM " . TABLE_NAME . " WHERE post_id = %d", $post->ID));
    /**
     * Eğer POST FF üzerine kayıt edilmemiş ise
     * Normal yorumları döndür
     */
    if (!$ff_item) {
        return $comments;
    }
    /**
     * Yorumları FF üzerinden check ediyoruz
     * Eğer FF üzerinde olan blog üzerinde olmayan yorum varsa
     * Veritabanına kaydediyoruz
     */
    get_ff_comments_from_ff($ff_item->friendfeed_id);
    $ff_comments = get_ff_comments_from_db($post->ID);
    if ($ff_comments != false) {
        foreach ($ff_comments as $comment) {
            $comments[] = $comment;
        }
    }
    return BubbleSort($comments, 'comment_date', 0);
}
示例#7
0
<?php 
function BubbleSort($arr)
{
    $swap = true;
    $j = 0;
    //$tmp = null;
    while ($swap) {
        $swap = false;
        $j++;
        for ($i = 0; $i < sizeof($arr) - $j; $i++) {
            if ($arr[$i] > $arr[$i + 1]) {
                $tmp = $arr[$i];
                $arr[$i] = $arr[$i + 1];
                $arr[$i + 1] = $tmp;
                $swap = true;
            }
        }
    }
    return $arr;
}
//$array = [2, 3, 4, 5, 1];
$array = [2, 3, 4, -5, 1, -1, 0, 56, 78];
var_dump(BubbleSort($array));