/**
* FUNCTIONS FOR BEST PRACTICES
*/
function best_practices($page)
{
    //read categories
    $lang = lang($page);
    $handle = fopen(TEXT_PATH . $lang . DIRECTORY_SEPARATOR . 'meta' . DIRECTORY_SEPARATOR . 'categories.csv', "r");
    $categories = csv2array($handle);
    //read and sort list of examples
    $handle = fopen(TEXT_PATH . $lang . DIRECTORY_SEPARATOR . $page . DIRECTORY_SEPARATOR . 'examples.csv', "r");
    $examples = csv2array($handle);
    foreach ($examples as $key => $row) {
        $s[$key] = (double) $row['weight'];
    }
    array_multisort($s, SORT_ASC, $examples);
    //read examples, parse categories
    include 'Parsedown.php';
    $Parsedown = new Parsedown();
    foreach ($examples as $key => $example) {
        $url = TEXT_PATH . $lang . DIRECTORY_SEPARATOR . $page . DIRECTORY_SEPARATOR . 'examples' . DIRECTORY_SEPARATOR . $example['code'] . '.md';
        $file_headers = @get_headers($url);
        if (strpos($file_headers[0], '404')) {
            $exists = false;
        } else {
            $exists = true;
        }
        if ($exists) {
            $contents = file_get_contents($url);
            $parsed = parse_text($Parsedown->text($contents));
            $examples[$key]['text'] = $parsed['text'];
            $examples[$key]['header'] = $parsed['header'];
            $examples[$key]['teaser'] = $parsed['teaser'];
            $examples[$key]['rest'] = $parsed['rest'];
            $examples[$key]['body'] = $parsed['body'];
            $examples[$key]['categories'] = parse_categories($examples[$key]['categories'], $categories);
        } else {
            unset($examples[$key]);
        }
    }
    //filter category
    $filter = false;
    $get_category = false;
    if (!isset($_GET['category'])) {
        if (isset($_GET['c'])) {
            $get_category = $_GET['c'];
        }
    } else {
        $get_category = [$_GET['category']];
    }
    if ($get_category) {
        foreach ($examples as $key => $example) {
            $in = false;
            foreach ($example['categories'] as $cat) {
                if (in_array($cat, $get_category)) {
                    $in = true;
                }
            }
            if (!$in) {
                unset($examples[$key]);
            }
        }
        foreach ($get_category as $gc) {
            $filter[] = $categories[$gc];
        }
    }
    $out = ['categories' => $categories, 'examples' => $examples, 'filter' => $filter];
    return $out;
}
Exemplo n.º 2
0
function getAllSubCategories()
{
    $query = sprintf("SELECT c.category_name, s.subcategory_name\n\t\t\tFROM categories c\n\t\t\tJOIN subcategories s \n\t\t\tON c.category_id = s.category_id");
    $results = do_query($query);
    if ($results) {
        $rows = parse_categories($results);
        return array("status" => 1, "title" => "Success", "msg" => "Succesfully retrieved subcategories.", "results" => $rows);
    } else {
        return array("status" => 0, "title" => "Failure", "msg" => "Failed to connect to server.");
    }
}
Exemplo n.º 3
0
    $int = intval($int);
    for ($i = 0; $i < $cnt - strlen($int); $i++) {
        $nulls .= '0';
    }
    return $nulls . $int;
}
function gen_data_dir($id)
{
    $floor = $id - $id % 100;
    $zfilled = add_nulls($floor, 5);
    $xed = substr($zfilled, 0, 3) . "XX";
    return $xed;
}
$data['desc'] = cleanup_html($data['desc']);
$data['links'] = parse_links($data['links']);
$data['categories'] = parse_categories($data['categories']);
$data['copyright'] = cleanup_html($data['copyright']);
$data['path_to_lores_img'] = $path_to_data . "lores/" . gen_data_dir($id) . "/" . add_nulls($id, 5) . ".jpg";
$data['path_to_thumb_img'] = $path_to_data . "thumbs/" . gen_data_dir($id) . "/" . add_nulls($id, 5) . ".jpg";
$data['path_to_hires_img'] = $path_to_data . "hires/" . gen_data_dir($id) . "/" . add_nulls($id, 5) . ".tif";
/* deprecated: we gave up on sqlite
$db_filename = "sqlite:/home/pyrak/workspace/collect-phil-cdc/phil.cdc.sqlite";
$db_handle = sqlite_open($db_filename);
$db_selectall_query = "select * from phil";
$id = 1;
$db_select_by_id_query = "select * from phil where id = " + $id;
sqlite_unbuffered_query($db_handle, $db_select_by_id_query);
 */
?>