xaizek / rocketgit (License: AGPLv3+) (since 2018-12-09)
Light and fast Git hosting solution suitable to serve both as a hub or as a personal code storage with its tickets, pull requests, API and much more.
<root> / inc / demo.inc.php (f86d76e54c5209c948c9e7cec39e491e6574aeab) (3,659B) (mode 100644) [raw]
<?php
// This is the files that controls the tutorials

/*
 * Load available tutorials (generating $rg_demos)
 */
function rg_demo_list()
{
	global $rg_scripts;

	$ret = array();

	$dir = $rg_scripts . '/root/themes/default/doc/demo/demos';
	$r = rg_dir_load($dir);
	if ($r === FALSE)
		return $ret;

	rg_log_ml('DEBUG: list: ' . print_r($r, TRUE));

	return $ret;
}

/*
 * Load a tutorial
 */
function rg_demo_load($name)
{
	global $rg_scripts;

	$ret = array();

	$dir = $rg_scripts . '/root/themes/default/doc/demo/demos/';

	$demo_dir = $dir . $name;
	$rpath = @realpath($demo_dir);
	if ($rpath === FALSE) {
		rg_internal_error('Demo ' . $name . ' does not exists!');
		return $ret;
	}
	if (strncmp($rpath, $dir, strlen($dir)) != 0) {
		rg_internal_error('Demo ' . $name . ' is outside the path!');
		return $ret;
	}

	$r = rg_dir_load($rpath);
	if ($r === FALSE) {
		rg_log('Cannot load demo ' . $name);
		return $ret;
	}

	rg_log_ml('DEBUG: demo dir: ' . print_r($r, TRUE));

	return $r;
}

/*
 * Tutorials dispatched
 */
function rg_demo($rg, $paras)
{
	global $rg_demos;

	//rg_log_ml('demo: paras: ' . print_r($paras, TRUE));

	if (empty($paras))
		return rg_template('doc/demo/list.html', $rg, TRUE /*xss*/);

	$demo = array_shift($paras);

	if (!isset($rg_demos[$demo]))
		return rg_template('doc/demo/invalid.html', $rg, TRUE /*xss*/);

	$d = $rg_demos[$demo];

	$rg['is_demo'] = 1;
	$rg['demo']['demo'] = $demo;
	$rg['demo']['HTML:demo_name'] = rg_template('doc/demo/demos/' . $demo
		. '/name.html', $rg, TRUE /*xss*/);

	if (empty($paras)) {
		$page = '0';
	} else {
		$page = array_shift($paras);
		$page = rg_force_alphanum($page);
	}

	$pi = FALSE;
	foreach ($d as $i => $_pi) {
		if (strcmp($page, $_pi['page']) == 0) {
			$pi = $_pi;
			break;
		}
	}
	if ($pi === FALSE) {
		rg_log('Invalid page: ' . $page);
		return rg_template('doc/demo/invalid_page.html',
			$rg, TRUE /*xss*/);
	}

	rg_log_ml('DEBUG: pi: ' . print_r($pi, TRUE));
	foreach ($pi as $k => $v)
		$rg['demo'][$k] = $v;

	// toc
	$c = array();
	foreach ($d as $i => $_pi) {
		if (strcmp($page, $_pi['page']) == 0)
			$_pi['class'] = 'demo_toc_sel';
		else
			$_pi['class'] = 'demo_toc_notsel';

		$_pi['HTML:page_name'] = rg_template('doc/demo/demos/'
			. $demo . '/' . $_pi['page'] . '/name.html',
			$rg, TRUE /*xss*/);
		$c[] = $_pi;
	}
	$rg['demo']['HTML:toc'] = rg_template_table('doc/demo/toc', $c, $rg);

	$rg['demo']['HTML:page_name'] = rg_template('doc/demo/demos/'
		. $demo . '/' . $page . '/name.html', $rg, TRUE /*xss*/);

	$rg['demo']['HTML:content'] = rg_template(
		'doc/demo/demos/' . $demo . '/' . $page . '/main.html',
		$rg, TRUE /*xss*/);

	return rg_template('doc/demo/container.html', $rg, TRUE /*xss*/);
}

$rg_demos = array(
	'ci-1' => array(
		array(
			'page' => '0',
			'prev' => '',
			'next' => 'about'
		),
		array(
			'page' => 'about',
			'prev' => '0',
			'next' => 'add_hook'
		),
		array(
			'page' => 'add_hook',
			'prev' => 'about',
			'next' => 'trigger'
		),
		array(
			'page' => 'trigger',
			'prev' => 'add_hook',
			'next' => 'python1'
		),
		array(
			'page' => 'python1',
			'prev' => 'trigger',
			'next' => ''
		)
	),
	'config' => array(
		array(
			'page' => '0',
			'prev' => '',
			'next' => 'openssh'
		),
		array(
			'page' => 'openssh',
			'prev' => '0',
			'next' => ''
		)
	),
	'artifacts' => array(
		array(
			'page' => '0',
			'prev' => '',
			'next' => 'define'
		),
		array(
			'page' => 'define',
			'prev' => '0',
			'next' => 'see'
		),
		array(
			'page' => 'see',
			'prev' => 'define',
			'next' => 'blendergraph'
		),
		array(
			'page' => 'blendergraph',
			'prev' => 'see',
			'next' => ''
		)
	)
);

Hints

Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/rocketgit

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/rocketgit

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master