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
11 require_once('../env.inc.php');
12 require_once $gfcommon.'include/pre.php';
13 require_once $gfwww.'snippet/snippet_utils.php';
16 * create_snippet_hash() - A little utility function to reduce duplicated code in snippet_mainpage()
18 * @param qpa Array A query+parameter array
19 * @param field String The field name - either 'language' or 'category'
20 * @return An associative array filled with the results of the SQL query
22 function create_snippet_hash($qpa, $field) {
23 $res = db_query_qpa($qpa);
25 while ($row = db_fetch_array($res)) {
26 $target[$row[$field]] = $row['count'];
32 * snippet_mainpage() - Show the main page for the snippet library.
34 function snippet_mainpage() {
35 global $SCRIPT_LANGUAGE,$SCRIPT_CATEGORY;
36 $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>').'
39 <table width="100%" border="0">
43 <strong>'._('Browse by Language').':</strong>
46 $qpa = db_construct_qpa (false, 'SELECT language, count(*) as count from snippet group by language') ;
47 $existing_snippets = create_snippet_hash($qpa, "language");
48 for ($i=1; $i<count($SCRIPT_LANGUAGE); $i++) {
49 $return .= '<li>'.util_make_link ('/snippet/browse.php?by=lang&lang='.$i,$SCRIPT_LANGUAGE[$i]).' (';
51 if (isset($existing_snippets[$i])) {
52 $return .= $existing_snippets[$i].')</li>';
60 <strong>'._('Browse by Category').':</strong>
63 $qpa = db_construct_qpa (false, 'SELECT category, count(*) as count from snippet group by category') ;
64 $existing_categories = create_snippet_hash($qpa, "category");
65 for ($i=1; $i<count($SCRIPT_CATEGORY); $i++) {
67 @$return .= '<li>'.util_make_link ('/snippet/browse.php?by=cat&cat='.$i,$SCRIPT_CATEGORY[$i]).' (';
69 if (isset($existing_categories[$i])) {
70 $return .= $existing_categories[$i].')</li>';
76 $return .= '</ul></td> </tr> </table>';
80 snippet_header(array('title'=>_('Snippet Library'), 'header'=>'Snippet Library'));
81 echo snippet_mainpage();
82 snippet_footer(array());
86 // c-file-style: "bsd"