4 * SourceForge Code Snippets Repository
6 * SourceForge: Breaking Down the Barriers to Open Source Development
7 * Copyright 1999-2001 (c) VA Linux Systems
8 * http://sourceforge.net
13 require_once('../env.inc.php');
14 require_once('pre.php');
15 require_once('www/snippet/snippet_utils.php');
18 * create_snippet_hash() - A little utility function to reduce duplicated code in snippet_mainpage()
20 * @param sql String A SQL query to fetch either snippets or categories from the database
21 * @param field String The field name - either 'language' or 'category'
22 * @return An associative array filled with the results of the SQL query
24 function create_snippet_hash($sql, $field) {
25 $res = db_query($sql);
27 while ($row = db_fetch_array($res)) {
28 $target[$row[$field]] = $row['count'];
34 * snippet_mainpage() - Show the main page for the snippet library.
36 function snippet_mainpage() {
37 global $SCRIPT_LANGUAGE,$SCRIPT_CATEGORY;
39 $return .=_('<p>The purpose of this archive is to let you share your code snippets, scripts, and functions with the Open Source Software Community.</p><p>You can create a "new snippet", then post additional versions of that snippet quickly and easily.</p><p>Once you have snippets posted, you can then create a "Package" of snippets. That package can contain multiple, specific versions of other snippets.</p><p> </p><h3>Browse Snippets</h3> <p>You can browse the snippet library quickly:</p>').'
42 <table width="100%" border="0">
46 <strong>'._('Browse by Language').':</strong>
49 $existing_snippets = create_snippet_hash("SELECT language, count(*) as count from snippet group by language", "language");
50 for ($i=1; $i<count($SCRIPT_LANGUAGE); $i++) {
51 $return .= '<li><a href="'.$GLOBALS['sys_urlprefix'].'/snippet/browse.php?by=lang&lang='.$i.'">'.$SCRIPT_LANGUAGE[$i].'</a> (';
52 if ($existing_snippets[$i]) {
53 $return .= $existing_snippets[$i].')</li>';
61 <strong>'._('Browse by Category').':</strong>
64 $existing_categories = create_snippet_hash("SELECT category, count(*) as count from snippet group by category", "category");
65 for ($i=1; $i<count($SCRIPT_CATEGORY); $i++) {
66 $return .= '<li><a href="'.$GLOBALS['sys_urlprefix'].'/snippet/browse.php?by=cat&cat='.$i.'">'.$SCRIPT_CATEGORY[$i].'</a> (';
67 if ($existing_categories[$i]) {
68 $return .= $existing_categories[$i].')</li>';
74 $return .= '</ul></td> </tr> </table>';
78 snippet_header(array('title'=>_('Snippet Library'), 'header'=>'Snippet Library'));
79 echo snippet_mainpage();
80 snippet_footer(array());