/** * 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; }
$l0id = isset($_REQUEST['l0id']) && preg_match('/^\\d{1,10}$/', $_REQUEST['l0id']) ? $_REQUEST['l0id'] : mt_rand(1000, 9999999); } // Check logged in user $user = isset($_SESSION['osm_user']) ? $_SESSION['osm_user'] : false; $loggedin = isset($_SESSION['osm_token']); // Read edited data if (!isset($text) || !$text) { $text = isset($_REQUEST['data']) ? $_REQUEST['data'] : ''; } // Generate $basedata and $userdata arrays $error = false; $messages = array(); $validation = array(); // of (severe?, line, description) read_base(); parse_text($text); // Now process actions if ($action == 'login' || isset($_REQUEST['login'])) { if ($loggedin) { $error = _('Yor are already logged in.'); } else { if (count($userdata) || count($basedata)) { $_SESSION['l0id'] = $l0id; store_user($text); } oauth_login(); } } elseif ($action == 'callback') { oauth_callback(); } elseif ($action == 'logout' || isset($_REQUEST['logout'])) { oauth_logout();
function Scrivi($txt) { global $sxw, $par_left, $par_right, $par_center, $par_justify; $parts = preg_split('!<(/?center|/?left|/?right|/?justify)>!i', $txt, -1, PREG_SPLIT_DELIM_CAPTURE); $prev_par = $cur_par = $par_left; $sxw->SetParagraph($par_left); foreach ($parts as $p) { if ($p[0] == '/') { continue; } if (strtolower($p) == 'left') { $prev_par = $cur_par; $cur_par = $par_left; $sxw->SetParagraph($par_left); continue; } if (strtolower($p) == 'right') { $prev_par = $cur_par; $cur_par = $par_right; $sxw->SetParagraph($par_right); continue; } if (strtolower($p) == 'center') { $prev_par = $cur_par; $cur_par = $par_center; $sxw->SetParagraph($par_center); continue; } if (strtolower($p) == 'justify') { $prev_par = $cur_par; $cur_par = $par_justify; $sxw->SetParagraph($par_justify); continue; } $sxw->Write(parse_text($p)); $sxw->SetParagraph($prev_par); } }