function cg2_listpage_getCode() { $tableName = @$_REQUEST['tableName']; $schema = loadSchema($tableName); $menuName = coalesce(@$schema['menuName'], $tableName); // define variable names $tableRecordsVar = '$' . preg_replace("/[^\\w]/", '_', $tableName) . "Records"; $metaDataVar = '$' . preg_replace("/[^\\w]/", '_', $tableName) . "MetaData"; $recordVar = '$record'; // define getRecords() options $options = array(); $options[] = "'tableName' => '{$tableName}',"; if (@$_REQUEST['howMany'] == 'firstN') { $options[] = "'limit' => '{$_REQUEST['limit']}',"; } else { if (@$_REQUEST['howMany'] == 'paged') { $options[] = "'perPage' => '{$_REQUEST['perPage']}',"; } else { /* default to showing all */ } } if (@$_REQUEST['orderBy'] == 'random') { $options[] = "'orderBy' => 'RAND()',"; } if (@$_REQUEST['showUploads'] == 'all') { $options[] = "'loadUploads' => true,"; } elseif (@$_REQUEST['showUploads'] == 'limit') { $options[] = "'loadUploads' => true,"; } else { $options[] = "'loadUploads' => false,"; } if (@$_REQUEST['allowSearching']) { $options[] = "'allowSearch' => true,"; } else { $options[] = "'allowSearch' => false,"; } $padding = " "; $getRecordsOptions = "\n{$padding}" . implode("\n{$padding}", $options) . "\n "; ### generate code ob_start(); ?> <#php header('Content-type: text/html; charset=utf-8'); #> <#php /* STEP 1: LOAD RECORDS - Copy this PHP code block near the TOP of your page */ <?php cg2_code_loadLibraries(); ?> // load records from '<?php echo $tableName; ?> ' list(<?php echo $tableRecordsVar; ?> , <?php echo $metaDataVar; ?> ) = getRecords(array(<?php echo $getRecordsOptions; ?> )); #><?php cg2_code_header(); cg2_code_instructions('List'); ?> <!-- STEP2: Display Records (Paste this where you want your records to be listed) --> <h1><?php echo $menuName; ?> - <?php echo t('List Page Viewer'); ?> </h1> <#php foreach (<?php echo $tableRecordsVar; ?> as <?php echo $recordVar; ?> ): #> <?php cg2_code_schemaFields($schema, $recordVar, $tableName); if (@$_REQUEST['showUploads']) { cg2_code_uploads($schema, $recordVar); } ?> <hr/> <#php endforeach #> <#php if (!<?php echo $tableRecordsVar; ?> ): #> <?php echo t('No records were found!'); ?> <br/><br/> <#php endif #> <!-- /STEP2: Display Records --> <?php if (@$_REQUEST['howMany'] == 'paged') { ?> <!-- STEP3: Display Page Links (Paste anywhere below "Load Record List") --> <#php if (<?php echo $metaDataVar; ?> ['prevPage']): #> <a href="<#php echo <?php echo $metaDataVar; ?> ['prevPageLink'] #>"><?php echo t('<< prev'); ?> </a> <#php else: #> << prev <#php endif #> - page <#php echo <?php echo $metaDataVar; ?> ['page'] #> of <#php echo <?php echo $metaDataVar; ?> ['totalPages'] #> - <#php if (<?php echo $metaDataVar; ?> ['nextPage']): #> <a href="<#php echo <?php echo $metaDataVar; ?> ['nextPageLink'] #>"><?php echo t('next'); ?> >></a> <#php else: #> next >> <#php endif #> <!-- /STEP3: Display Page Links --> <?php } cg2_code_footer(); ?> <?php // return code $code = ob_get_clean(); return $code; }
function cg2_combopage_getCode() { $tableName = @$_REQUEST['tableName']; $schema = loadSchema($tableName); $menuName = coalesce(@$schema['menuName'], $tableName); // define variable names $tableRecordsVar = '$' . preg_replace("/[^\\w]/", '_', $tableName) . "Records"; $metaDataVar = '$' . preg_replace("/[^\\w]/", '_', $tableName) . "MetaData"; $listRecordVar = '$listRecord'; $detailRecordVar = '$detailRecord'; // list records - define getRecords() options $options = array(); $options[] = "'tableName' => '{$tableName}',"; if (@$_REQUEST['howMany'] == 'firstN') { $options[] = "'limit' => '{$_REQUEST['limit']}',"; } $options[] = "'loadUploads' => false,"; $options[] = "'allowSearch' => false,"; $padding = " "; $listRecordsOptions = "\n{$padding}" . implode("\n{$padding}", $options) . "\n "; // detail record - define getRecords() options $options = array(); $options[] = "'tableName' => '{$tableName}',"; $options[] = "'where' => whereRecordNumberInUrl(1), // If no record # is specified then latest record is shown"; if (@$_REQUEST['showUploads'] == 'all') { $options[] = "'loadUploads' => true,"; } elseif (@$_REQUEST['showUploads'] == 'limit') { $options[] = "'loadUploads' => true,"; } else { $options[] = "'loadUploads' => false,"; } $options[] = "'allowSearch' => false,"; $options[] = "'limit' => '1',"; $detailRecordOptions = "\n{$padding}" . implode("\n{$padding}", $options) . "\n "; ### generate code ob_start(); ?> <#php header('Content-type: text/html; charset=utf-8'); #> <#php /* STEP 1: LOAD RECORDS - Copy this PHP code block near the TOP of your page */ <?php cg2_code_loadLibraries(); ?> // load detail record from '<?php echo $tableName; ?> ' list(<?php echo $tableRecordsVar; ?> , <?php echo $metaDataVar; ?> ) = getRecords(array(<?php echo $detailRecordOptions; ?> )); <?php echo $detailRecordVar; ?> = @<?php echo $tableRecordsVar; ?> [0]; // get first record if (!<?php echo $detailRecordVar; ?> ) { dieWith404("Record not found!"); } // show error message if no record found // load list records from '<?php echo $tableName; ?> ' list(<?php echo $tableRecordsVar; ?> , <?php echo $metaDataVar; ?> ) = getRecords(array(<?php echo $listRecordsOptions; ?> )); #><?php cg2_code_header(); cg2_code_instructions('Combo'); ?> <h1><?php echo $menuName; ?> - <?php echo t('Combo Page Viewer'); ?> </h1> <table border="1" cellspacing="2" cellpadding="4"> <tr> <td valign="top"> <!-- STEP2: Display Record List (Paste this where you want your record list) --> <b>Record List</b><br/> <#php foreach (<?php echo $tableRecordsVar; ?> as <?php echo $listRecordVar; ?> ): #> <#php $isSelected = (<?php echo $listRecordVar; ?> ['num'] == <?php echo $detailRecordVar; ?> ['num']); #> <#php if ($isSelected) { print "<b>"; } #> <a href="<#php echo htmlencode(<?php echo $listRecordVar; ?> ['_link']) #>"><#php echo htmlencode(<?php echo $listRecordVar; ?> ['<?php echo @$_REQUEST['titleField']; ?> ']) #></a><br/> <#php if ($isSelected) { print "</b>"; } #> <#php endforeach #> <#php if (!<?php echo $tableRecordsVar; ?> ): #> No records were found!<br/><br/> <#php endif #> <!-- /STEP2: Display Record List --> </td> <td valign="top"> <!-- STEP2: Display Record Detail (Paste this where you want your record details) --> <b>Record Detail</b><br/> <?php cg2_code_schemaFields($schema, $detailRecordVar, $tableName); if (@$_REQUEST['showUploads']) { cg2_code_uploads($schema, $detailRecordVar); } ?> <a href="mailto:?subject=<#php echo urlencode(thisPageUrl()) #>">Email this Page</a> <!-- /STEP2: Display Record Detail --> </td> </tr> </table> <?php cg2_code_footer(); // return code $code = ob_get_clean(); return $code; }
function cg2_rssfeed_getCode() { $tableName = @$_REQUEST['tableName']; $schema = loadSchema($tableName); $menuName = coalesce(@$schema['menuName'], $tableName); // define variable names $tableRecordsVar = '$' . preg_replace("/[^\\w]/", '_', $tableName) . "Records"; $metaDataVar = '$' . preg_replace("/[^\\w]/", '_', $tableName) . "MetaData"; $recordVar = '$record'; // define getRecords() options $options = array(); $options[] = "'tableName' => '{$tableName}',"; if (@$_REQUEST['howMany'] == 'firstN') { $options[] = "'limit' => '{$_REQUEST['limit']}',"; } else { /* default to showing all */ } $options[] = "'orderBy' => '', // use default database order"; $options[] = "'loadUploads' => false,"; $options[] = "'allowSearch' => false,"; $padding = " "; $getRecordsOptions = "\n{$padding}" . implode("\n{$padding}", $options) . "\n "; ### generate code ob_start(); ?> <#php /* STEP 1: LOAD RECORDS - Copy this PHP code block near the TOP of your page */ <?php cg2_code_loadLibraries(); ?> // load records from '<?php echo $tableName; ?> ' list(<?php echo $tableRecordsVar; ?> , <?php echo $metaDataVar; ?> ) = getRecords(array(<?php echo $getRecordsOptions; ?> )); <?php /* not used // get updated and created times <?php if (@$schema['updatedDate']): ?> $lastUpdated = max(coalesce(array_map('strtotime', array_pluck(<?php echo $tableRecordsVar ?>, 'updatedDate')), array(time()))); <?php else: ?> $lastUpdated = time(); <?php endif ?> <?php if (@$schema['createdDate']): ?> $lastCreated = max(coalesce(array_map('strtotime', array_pluck(<?php echo $tableRecordsVar ?>, 'createdDate')), array(time()))); <?php else: ?> $lastCreated = time(); <?php endif ?> */ ?> #> <#php header('Content-type: application/xml; charset=utf-8'); #><#php echo '<'.'?xml version="1.0" encoding="UTF-8"?>'; #> <rss version="2.0"> <channel> <title><?php echo htmlencode(@$_REQUEST['feedTitle']); ?> </title> <link><?php echo htmlencode(@$_REQUEST['feedLink']); ?> </link> <description><?php echo htmlencode(@$_REQUEST['feedDescription']); ?> </description> <pubDate><#php echo date('r') #></pubDate> <language><?php echo htmlencode(@$_REQUEST['feedLanguage']); ?> </language> <#php foreach (<?php echo $tableRecordsVar; ?> as <?php echo $recordVar; ?> ): #> <item> <title><#php echo htmlencode($record['<?php echo @$_REQUEST['titleField']; ?> ']) #></title> <link>http://<#php echo $_SERVER['HTTP_HOST']; #>/<#php echo <?php echo $recordVar; ?> ['_link'] #></link> <description><![CDATA[<#php echo <?php echo $recordVar; ?> ['<?php echo @$_REQUEST['descriptionField']; ?> '] #>]]></description> <?php if (@$schema['createdDate']) { ?> <pubDate><#php echo date('r', strtotime(<?php echo $recordVar; ?> ['createdDate'])) #></pubDate> <?php } ?> <guid isPermaLink="true"><#php echo <?php echo $recordVar; ?> ['_link'] #></guid> </item> <#php endforeach #> </channel> </rss> <?php // return code $code = ob_get_clean(); return $code; }
function cg2_detailpage_getCode() { $tableName = @$_REQUEST['tableName']; $schema = loadSchema($tableName); $menuName = coalesce(@$schema['menuName'], $tableName); // define variable names $tableRecordsVar = '$' . preg_replace("/[^\\w]/", '_', $tableName) . "Records"; $metaDataVar = '$' . preg_replace("/[^\\w]/", '_', $tableName) . "MetaData"; $recordVar = '$' . preg_replace("/[^\\w]/", '_', $tableName) . "Record"; // define getRecords() options $options = array(); $options[] = "'tableName' => '{$tableName}',"; if (@$_REQUEST['whichRecord'] == 'first') { $options[] = "'where' => '', // load first record"; } elseif (@$_REQUEST['whichRecord'] == 'url') { $options[] = "'where' => whereRecordNumberInUrl(0),"; } elseif (@$_REQUEST['whichRecord'] == 'custom') { $options[] = "'where' => \"`num` = '" . intval(@$_REQUEST['recordNumCustom']) . "'\","; } if (@$_REQUEST['showUploads'] == 'all') { $options[] = "'loadUploads' => true,"; } elseif (@$_REQUEST['showUploads'] == 'limit') { $options[] = "'loadUploads' => true,"; } else { $options[] = "'loadUploads' => false,"; } $options[] = "'allowSearch' => false,"; $options[] = "'limit' => '1',"; $padding = " "; $getRecordsOptions = "\n{$padding}" . implode("\n{$padding}", $options) . "\n "; ### generate code ob_start(); ?> <#php header('Content-type: text/html; charset=utf-8'); #> <#php /* STEP 1: LOAD RECORDS - Copy this PHP code block near the TOP of your page */ <?php cg2_code_loadLibraries(); ?> // load record from '<?php echo $tableName; ?> ' list(<?php echo $tableRecordsVar; ?> , <?php echo $metaDataVar; ?> ) = getRecords(array(<?php echo $getRecordsOptions; ?> )); <?php echo $recordVar; ?> = @<?php echo $tableRecordsVar; ?> [0]; // get first record if (!<?php echo $recordVar; ?> ) { dieWith404("Record not found!"); } // show error message if no record found #><?php cg2_code_header(); cg2_code_instructions('Detail'); ?> <!-- STEP2: Display Record (Paste this where you want your record to appear) --> <h1><?php echo $menuName; ?> - Detail Page Viewer</h1> <?php cg2_code_schemaFields($schema, $recordVar, $tableName); if (@$_REQUEST['showUploads']) { cg2_code_uploads($schema, $recordVar); } ?> <!-- /STEP2: Display Record --> <hr/> <a href="<#php echo <?php echo $metaDataVar; ?> ['_listPage'] ?>"><< <?php echo t('Back to list page'); ?> </a> <a href="mailto:?subject=<#php echo urlencode(thisPageUrl()) #>"><?php echo t('Email this Page'); ?> </a> <?php cg2_code_footer(); ?> <?php // return code $code = ob_get_clean(); return $code; }
function cg2_categorypage_getCode() { $tableName = @$_REQUEST['tableName']; $schema = loadSchema($tableName); $menuName = coalesce(@$schema['menuName'], $tableName); // define variable names $categoryRecordsVar = '$' . preg_replace("/[^\\w]/", '_', $tableName) . "Records"; $selectedCategoryVar = '$selected' . ucfirst(preg_replace("/[^\\w]/", '_', $tableName)); $categoryRecordVar = '$categoryRecord'; ### generate code ob_start(); ?> <#php header('Content-type: text/html; charset=utf-8'); #> <#php /* STEP 1: LOAD RECORDS - Copy this PHP code block near the TOP of your page */ <?php cg2_code_loadLibraries(); ?> // load records from '<?php echo $tableName; ?> ' list(<?php echo $categoryRecordsVar; ?> , <?php echo $selectedCategoryVar; ?> ) = getCategories(array( 'tableName' => '<?php echo $tableName; ?> ', // 'categoryFormat' => '<?php echo $_REQUEST['categoryFormat']; ?> ', // showall, onelevel, twolevel, breadcrumb 'defaultCategory' => '<?php echo $_REQUEST['defaultCategory'] == 'num' ? $_REQUEST['defaultCategoryNum'] : $_REQUEST['defaultCategory']; ?> ', // Enter 'first', a category number, or leave blank '' for none // advanced options (you can safely ignore these) 'rootCategoryNum' => '<?php echo $_REQUEST['rootCategoryNum']; ?> ', // Only categories _below_ this one will be shown (defaults to blank or 0 for all) 'ulAttributes' => '', // add html attributes to <ul> tags, eg: 'class="menuUL"' would output <ul class="menuUL"> 'selectedCategoryNum' => '', // this record number is returned as the "selected category", defaults to getLastNumberInUrl() 'ulAttributesCallback' => '', // ADVANCED: custom function to return ul attributes, eg: 'myUlAttr' and function myUlAttr($category) { return "id='ul_uniqueId_{$category['num']}'"; } 'liAttributesCallback' => '', // ADVANCED: custom function to return li attributes, eg: 'myLiAttr' and function myLiAttr($category) { return "id='li_uniqueId_{$category['num']}'"; } 'loadCreatedBy' => false, // loads createdBy.* fields for user who created category record (false is faster) 'loadUploads' => true, // loads upload fields, eg: $category['photos'] gets defined with array of uploads (false is faster) 'ignoreHidden' => false, // false = hide records with 'hidden' flag set, true = ignore status of hidden flag when loading records 'debugSql' => false, // display the MySQL query being used to load records (for debugging) )); #><?php cg2_code_header(); cg2_code_instructions('Category'); ?> <table border="1" cellspacing="0" cellpadding="2" width="100%"> <tr> <td valign="top" width="200"> <?php if (@$_REQUEST['outputHtmlStyle'] == 'list') { ?> <h3>Category Menu</h3> <ul> <#php foreach (<?php echo $categoryRecordsVar; ?> as <?php echo $categoryRecordVar; ?> ): #> <#php echo <?php echo $categoryRecordVar; ?> ['_listItemStart'] #> <#php if (<?php echo $categoryRecordVar; ?> ['_isSelected']): #> <b><a href="<#php echo <?php echo $categoryRecordVar; ?> ['_link'] #>"><#php echo <?php echo $categoryRecordVar; ?> ['name'] #></a></b> <#php else: #> <a href="<#php echo <?php echo $categoryRecordVar; ?> ['_link'] #>"><#php echo <?php echo $categoryRecordVar; ?> ['name'] #></a> <#php endif; #> <#php echo <?php echo $categoryRecordVar; ?> ['_listItemEnd'] #> <#php endforeach; #> </ul> <?php } else { ?> <h3>Category Menu</h3> <#php foreach (<?php echo $categoryRecordsVar; ?> as <?php echo $categoryRecordVar; ?> ): #> <#php echo str_repeat(" ", <?php echo $categoryRecordVar; ?> ['depth']); #> <#php if (<?php echo $categoryRecordVar; ?> ['_isSelected']): #><b><#php endif; #> <a href="<#php echo <?php echo $categoryRecordVar; ?> ['_link'] #>"><#php echo <?php echo $categoryRecordVar; ?> ['name'] #></a> <#php if (<?php echo $categoryRecordVar; ?> ['_isSelected']): #></b><#php endif; #> <br/> <#php endforeach; #> <?php } ?> </td> <td valign="top"> <h3>Selected Category</h3> <#php if (!<?php echo $selectedCategoryVar; ?> ): #> <?php echo t('No category is selected!'); ?> <br/> <#php endif #> <#php if (<?php echo $selectedCategoryVar; ?> ): #> <?php cg2_code_schemaFields($schema, $selectedCategoryVar, $tableName); cg2_code_uploads($schema, $selectedCategoryVar); ?> <#php endif #> <#php if (<?php echo $selectedCategoryVar; ?> ): #> <div class="instructions"> <b>Advanced Code Snippets and Field List</b> (you can safely remove this section)</b><br/> <#php $selectedNum = intval($selectedCategory['num']); $recordsOnBranch = mysql_select('category', "lineage LIKE '%:$selectedNum:%'"); $branchNums = array_pluck($recordsOnBranch, 'num'); $branchNumsAsCSV = mysql_getValuesAsCSV($branchNums); #> Selected category num: <#php echo $selectedCategory['num']; #><br/> All nums in branch: <#php echo $branchNumsAsCSV; #><br/> All fields available for the selected record:<br/> <div style="margin-left: 25px; font-family: monospace"> <#php echo nl2br(str_replace(' ', ' ', htmlencode(print_r($selectedCategory, true)))); #> </div> </div> <#php endif #> <br/><br/> </td> </tr> </table> <?php cg2_code_footer(); ?> <?php // return code $code = ob_get_clean(); return $code; }