<?php if(!defined('barlall') && barlall!='Public') die('Access denied');
if(!isset($DB)) {
$DB = new db();
}
$URL = Bootstrap(1);
$code_unique = md5($URL);
include CfgPath.'prism.php';
$TPL->SetSiteTitle($LANG['Syntax_Highlighter']);
$TPL->SetMetaDescription($LANG['Syntax_Highlighter_Desc']);
$TPL->Load('bootstrap-select');
$TPL->Load('select_picker');
if($URL) {
$DB->query('SELECT code_id,code_url,code_title,code_lang,code_text,code_notes,code_author,code_password,code_editpassword,created,updated FROM '.TBL_syntaxhigh.' WHERE code_unique=:code_unique AND deleted IS NULL LIMIT 1');
$DB->str(':code_unique',$code_unique);
if($code = $DB->fetch_row()) {
if($code = $DB->fetch_row()) {
if($code['code_password'] && !isset($_SESSION[$code['code_url']]) && $_SESSION[$code['code_url']]!='access') {
$show_title=$lang_row=$show_notes='';
if($code['code_title']) {
$TPL->set('code_title',$code['code_title']);
$show_title = $TPL->writeTpl('Syntax-Highlighter/show/title');
$TPL->SetSiteTitle($code['code_title'].' « '.$LANG['Syntax_Highlighter']);
}
$code_lang = isset($_POST['code_lang']) && $_POST['code_lang']!='' ? $_POST['code_lang']:$code['code_lang'];
foreach ($_PRISM_LANGUAGES as $prism_language => $prism_class) {
$selected = $prism_class==$code_lang ? ' selected':'';
$lang_row.= '<option value="'.$prism_class.'"'.$selected.'>'.HTMLChars($prism_language).'</option>';
}
if($code['code_notes']) {
$TPL->set('notes',HTMLChars($code['code_notes']));
$show_notes = $TPL->writeTpl('Syntax-Highlighter/show/notes');
}
$TPL->set('url',$_SERVER['SERVER_NAME'].REQUEST_URI);
$TPL->set('code_lang',HTMLChars($code_lang));
$TPL->set('code_text',HTMLChars($code['code_text']));
$TPL->set('lang_row',$lang_row);
$TPL->set('show_title',$show_title);
$TPL->set('show_notes',$show_notes);
$TPL->LoadPrism();
$BODY.= $TPL->writeTpl('Syntax-Highlighter/show/show');
}
}
} else {
$TPL->NotFound();
}
}
if(!$BODY) {
$lang = isset($_POST['lang']) && $_POST['lang']!='' ? $_POST['lang']:array_keys($_PRISM_LANGUAGES)[0];
$code = isset($_POST['code']) && $_POST['code']!='' ? $_POST['code']:'';
$lang_row='';
foreach ($_PRISM_LANGUAGES as $prism_language => $prism_class) {
$selected = $prism_language==$lang ? ' selected':'';
$lang_row.= '<option value="'.$prism_class.'"'.$selected.'>'.HTMLChars($prism_language).'</option>';
}
function CreateURL() {
$USER = new user();
$DB = new db();
$string = $USER->RandStr(8,true);
$md5 = $string ? md5($string):'';
$DB->query('SELECT code_id FROM '.TBL_syntaxhigh.' WHERE code_unique=:code_unique LIMIT 1');
$DB->str('code_unique',$md5);
if($q = $DB->fetch_row()) {
$string = CreateURL();
}
if(!$string) {
$string = CreateURL();
}
return $string;
}
if(isset($_POST['store']) && $lang && $code) {
$code_url = CreateURL();
$code_unique = md5($code_url);
$title = isset($_POST['title']) && $_POST['title']!='' ? $_POST['title']:'';
$notes = isset($_POST['notes']) && $_POST['notes']!='' ? $_POST['notes']:'';
$code_password = isset($_POST['show-password']) && $_POST['show-password']!='' ? password_hash($_POST['show-password'], PASSWORD_DEFAULT):'';
$code_editpassword = isset($_POST['edit-password']) && $_POST['edit-password']!='' ? password_hash($_POST['edit-password'], PASSWORD_DEFAULT):'';
$DB->query('INSERT '.TBL_syntaxhigh.'
(code_unique,code_url,code_title,code_lang,code_text,code_notes,code_author,code_password,code_editpassword,created)
VALUES
(:code_unique,:code_url,:code_title,:code_lang,:code_text,:code_notes,:code_author,:code_password,:code_editpassword,:created)');
$DB->str('code_unique',$code_unique);
$DB->str('code_url',$code_url);
$DB->str('code_title',$title);
$DB->str('code_lang',$lang);
$DB->str('code_text',$code);
$DB->str('code_notes',$notes);
$DB->str('code_author',$USER->id());
$DB->str('code_password',$code_password);
$DB->str('code_editpassword',$code_editpassword);
$DB->str('created',$DB->datetime());
$DB->execute();
$USER->redirect('/'.$SITE.'/'.$code_url);
}
$TPL->set('title',isset($_POST['title']) && $_POST['title']!='' ? HTMLChars($_POST['title']):'');
$TPL->set('code',isset($_POST['code']) && $_POST['code']!='' ? HTMLChars($_POST['code']):'');
$TPL->set('notes',isset($_POST['notes']) && $_POST['notes']!='' ? HTMLChars($_POST['notes']):'');
$TPL->set('lang_row',$lang_row);
$BODY.= $TPL->writeTpl('Syntax-Highlighter/Syntax-Highlighter');
}