示例#1
0
function make_tree($nodes, $parent_id = 0)
{
    $tree = array();
    foreach ($nodes as $node) {
        if ($node['parent_id'] == $parent_id) {
            $node['children'] = make_tree($nodes, $node['id']);
            $tree[] = $node;
        }
    }
    return $tree;
}
示例#2
0
 public static function tree($root_id = 0)
 {
     if ($root_id) {
         $root = static::findOrFail($root_id);
         $categories = static::whereRaw('parents LIKE ?', array($root->parents . $root_id . '/%'))->get();
     } else {
         $categories = static::all();
     }
     $tree = make_tree($categories, $root_id);
     return $tree;
 }
示例#3
0
 public function tree(Request $request)
 {
     $parent_id = $request->input('parent_id', 0);
     $query = $this->resources;
     if ($parent_id) {
         $parent = Category::findOrFail($parent_id);
         $query->where('parents', 'LIKE', "{$parent->parents}/{$parent_id}/%");
     }
     $categories = $query->get();
     return make_tree($categories);
 }
示例#4
0
function make_tree($level, $root, $nodes = NULL)
{
    global $people;
    global $everyone;
    global $tree;
    global $managers;
    global $visible_managers;
    print "\n" . $tree->format_item($everyone, $root, $nodes == NULL);
    if ($nodes !== NULL && in_array($root, $managers)) {
        $visible_managers[] = $root;
    }
    if (is_array($nodes)) {
        print "\n<ul>";
        usort($nodes, array($tree, "sort_items"));
        foreach ($nodes as $node) {
            if (!empty($people[$node])) {
                make_tree($level + 1, $node, $people[$node]);
            } else {
                make_tree($level + 1, $node);
            }
        }
        print "\n</ul>";
    }
}
示例#5
0
function main()
{
    global $debug;
    global $DEFAULT_DEPTHS;
    if ($debug) {
        printf("Garbage Collector Test\n");
        printf("Stretching memory with a binary tree of depth %d\n", kStretchTreeDepth);
    }
    $t_start = microtime(true);
    $temp_tree = make_tree(kStretchTreeDepth);
    if ($debug) {
        printf(" Creating a long-lived binary tree of depth %d\n", kLongLivedTreeDepth);
    }
    $long_lived_tree = new Node();
    populate(kLongLivedTreeDepth, $long_lived_tree);
    if ($debug) {
        printf(" Creating a long-lived array of %d doubles\n", kArraySize);
    }
    $long_lived_array = array(0.0);
    for ($i = 1; $i < kArraySize; $i++) {
        $long_lived_array[] = 1 / $i;
    }
    time_constructions($DEFAULT_DEPTHS, $debug);
    $t_finish = microtime(true);
    return $t_finish - $t_start;
}
if (stristr($VERSION, '-rc') !== false) {
    $STABILITY = "beta";
}
verify_stability($STABILITY);
verify_version($VERSION, $STABILITY);
$changelog = __DIR__ . "/../RELEASE-" . $VERSION;
verify_changelog($changelog);
$currtime = new DateTime('now', new DateTimeZone('UTC'));
$DATE = $currtime->format('Y-m-d');
$TIME = $currtime->format('H:i:s');
$fullnotes = file($changelog, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
$NOTES = array();
foreach ($fullnotes as $note) {
    $note = "    " . str_replace("&", "&amp;", trim($note));
    /* PHP PHPC JIRA Project */
    if (strstr($note, "PHPC-") !== false) {
        $NOTES[] = $note;
        continue;
    }
    /* Coverity ID */
    if (strstr($note, "CID-") !== false) {
        $NOTES[] = $note;
        continue;
    }
}
$TREE = make_tree(get_files());
$contents = file_get_contents(__DIR__ . "/package.xml.in");
$REPLACE = array("%RELEASE_DATE%" => $DATE, "%RELEASE_TIME%" => $TIME, "%RELEASE_VERSION%" => $VERSION, "%RELEASE_STABILITY%" => $STABILITY, "%RELEASE_NOTES%" => join("\n", $NOTES), "%RELEASE_FILES%" => join("\n", $TREE));
$contents = str_replace(array_keys($REPLACE), array_values($REPLACE), $contents);
file_put_contents(__DIR__ . "/../package.xml", $contents);
echo "Wrote package.xml\n";
function json_viewer($json)
{
    $curly = strpos($json, "{");
    $square = strpos($json, "[");
    // No curly or square bracket means this is not JSON data
    if ($curly === false && $square === false) {
        return "Invalid JSON data (no '{' or '[' found)";
    } else {
        // There is a case when you have a feed with [{
        // so get the first one
        if ($curly !== false && $square !== false) {
            if ($curly < $square) {
                $square = false;
            } else {
                $curly = false;
            }
        }
        // get the last curly or square brace
        if ($curly !== false) {
            $firstchar = $curly;
            $lastchar = strrpos($json, "}");
        } else {
            if ($square !== false) {
                $firstchar = $square;
                $lastchar = strrpos($json, "]");
            }
        }
        if ($lastchar === false) {
            return "Invalid JSON data (no closing '}' or ']' found)";
        }
        // Give warning if $firstchar is not the first character
        if ($firstchar > 0) {
            $warning = "---WARNING---\n";
            $warning .= "Invalid JSON data that does not begin with '{' or '[' might give unexpected results\n";
        }
    }
    // get the JSON data between the first and last curly or square brace
    $json = substr($json, $firstchar, $lastchar - $firstchar + 1);
    // decode json data
    $data = json_decode($json, true);
    if (!$data) {
        if (isset($_POST['showinvalidjson'])) {
            // Show invalid JSON anyway, do sanitize some stuff
            return "This JSON data is invalid, but we show it anyway: <br />" . htmlentities($json);
        } else {
            return "Invalid JSON data (could not decode JSON data)";
        }
    }
    if (isset($warning)) {
        echo $warning;
    }
    // Check for 'raw output'
    if (isset($_POST['rawoutput'])) {
        die(print_r($data, false));
    }
    // we need to make the first 'root' tree element
    //  $out  = '<ul id="root"><li><img src="images/arrow.png" class="arrow" alt="+" />ROOT<ul id="first">';
    $out = '';
    $out .= make_tree($data, null);
    $out .= "</ul></li></ul>";
    $tree = '';
    return $out;
}
示例#8
0
function json_viewer($json)
{
    // Some API's deliver invalid JSON, such as Flickr and Google Suggest,
    // usually because they deliver the JSON as a JavaScript variable, e.g.
    // 'JSONResult = ({"foo": "bar"});
    // We can 'fix' this by stripping that out before and after
    // the { and [ characters. Unfortunately that takes a little bit of
    // extra code, and we are essentialy fixing things that Google or Yahoo
    // should fix, but because these feeds are so popular we do it anyway.
    // get first occurence of curly brace and square brace
    $curly = strpos($json, "{");
    $square = strpos($json, "[");
    // No curly or square bracket means this is not JSON data
    if ($curly === false && $square === false) {
        return "Invalid JSON data (no '{' or '[' found)";
    } else {
        // There is a case when you have a feed with [{
        // so get the first one
        if ($curly !== false && $square !== false) {
            if ($curly < $square) {
                $square = false;
            } else {
                $curly = false;
            }
        }
        // get the last curly or square brace
        if ($curly !== false) {
            $firstchar = $curly;
            $lastchar = strrpos($json, "}");
        } else {
            if ($square !== false) {
                $firstchar = $square;
                $lastchar = strrpos($json, "]");
            }
        }
        if ($lastchar === false) {
            return "Invalid JSON data (no closing '}' or ']' found)";
        }
        // Give warning if $firstchar is not the first character
        if ($firstchar > 0) {
            $warning = "---WARNING---\n";
            $warning .= "Invalid JSON data that does not begin with '{' or '[' might give unexpected results\n";
        }
    }
    // get the JSON data between the first and last curly or square brace
    $json = substr($json, $firstchar, $lastchar - $firstchar + 1);
    // decode json data
    $data = json_decode($json, true);
    if (!$data) {
        if (isset($_POST['showinvalidjson'])) {
            // Show invalid JSON anyway, do sanitize some stuff
            return "This JSON data is invalid, but we show it anyway: <br />" . htmlentities($json);
        } else {
            return "Invalid JSON data (could not decode JSON data)";
        }
    }
    if (isset($warning)) {
        echo $warning;
    }
    // Check for 'raw output'
    if (isset($_POST['rawoutput'])) {
        die(print_r($data, false));
    }
    // we need to make the first 'root' tree element
    $out = '<ul id="root"><li><img src="img/arrow.png" class="arrow" alt="+" />ROOT<ul id="first">';
    $out .= make_tree($data);
    $out .= "</ul></li></ul>";
    $tree = '';
    return $out;
}