Skip to content
This repository has been archived by the owner on Mar 21, 2022. It is now read-only.

Commit

Permalink
add options page to configure the c2_navigation block
Browse files Browse the repository at this point in the history
  • Loading branch information
mkalam-alami committed Jun 18, 2016
1 parent 9a26e4b commit 0542556
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 7 deletions.
3 changes: 3 additions & 0 deletions compo/plugins/compo2/compo2.php
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ function compo2_number_format($v) {


require_once dirname(__FILE__)."/install.php";
require_once dirname(__FILE__)."/options.php";
require_once dirname(__FILE__)."/main.php";

require_once dirname(__FILE__)."/active.php";
Expand All @@ -405,6 +406,8 @@ function compo2_number_format($v) {

require_once dirname(__FILE__)."/mike.php";

add_action('admin_menu', 'compo2_options_menu');

//add_filter('the_content','compo2_the_content');
//add_action('wp_head', 'compo2_wp_head');
add_action('compo2_cache_begin', 'compo2_cache_begin');
Expand Down
39 changes: 37 additions & 2 deletions compo/plugins/compo2/mike.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,44 @@ function c2_set_game($event_id,$user_id,$game) {
}

// This Function is called in the style sheet to display Navigation //
function c2_navigation($slug,$name,$name_url) {
function c2_navigation() {

//if ( !is_paged() ) { // First Page Only //
{

// Fetch navigation enabled
if (function_exists('apcu_fetch')) {
$navInfo = apcu_fetch('c2_navigation_cache');
if ($navInfo) {
$enabled = $navInfo['enabled'];
}
}
if (!$navInfo) {
$enabled = get_option('c2_navigation_enable');
}

if ($enabled) {

// Fetch navigation options
if ($navInfo) {
$slug = $navInfo['slug'];
$name = $navInfo['name'];
$name_url = $navInfo['name_url'];
}
else {
$slug = get_option('c2_navigation_slug');
$name = get_option('c2_navigation_name');
$name_url = get_option('c2_navigation_name_url');
if (function_exists('apcu_store')) {
apcu_store('c2_navigation_cache', array(
'enabled' => $enabled,
'slug' => $slug,
'name' => $name,
'name_url' => $name_url
));
}
}

// Fetch user/event info
$user_id = get_current_user_id();
$event_id = 0;
$underscore_slug = str_replace( '-', '_', $slug );
Expand Down
72 changes: 72 additions & 0 deletions compo/plugins/compo2/options.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php


function compo2_options_menu() {
add_options_page('Compo2 Options', 'Compo2', 'manage_options', 'compo2-settings-options', 'compo2_options');
}

function compo2_options() {
if ( !current_user_can( 'manage_options' ) ) {
wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
}

if(isset($_POST["submit"])) {
update_option('c2_navigation_enable', $_POST['enable'] == 'on');
update_option('c2_navigation_slug', $_POST['slug']);
update_option('c2_navigation_name', $_POST['name']);
update_option('c2_navigation_name_url', $_POST['name_url']);
$showSavedMessage = true;

if (function_exists('apcu_delete')) {
apcu_delete('c2_navigation_cache');
}
}

$enable = get_option('c2_navigation_enable');
$slug = get_option('c2_navigation_slug');
$name = get_option('c2_navigation_name');
$name_url = get_option('c2_navigation_name_url');

echo '<h1>Compo2 Options</h1>';
if (isset($showSavedMessage)) {
echo '<div class="updated"><p><strong>Settings saved.</strong></p></div>';
}

?>

<h3 class="title">Navigation block</h3>
<p>These settings control the homepage block featuring handy links to the user entry and the event in general. It should be enabled from the kickoff of the event to the end of the rating phase.</p>

<form name="compo2" method="post" action="">

<table class="form-table">
<tbody>
<tr>
<th scope="row">Event page ID</th>
<td><input type="text" name="slug" value="<?php echo $slug; ?>" placeholder="e.g. ludum-dare-XX" class="regular-text code" /></td>
</tr>
<tr>
<th scope="row">Event name</th>
<td><input type="text" name="name" value="<?php echo $name; ?>" placeholder="e.g. Ludum Dare XX" class="regular-text" /></td>
</tr>
<tr>
<th scope="row">Announcement post URL</th>
<td><input type="text" name="name_url" value="<?php echo $name_url; ?>" placeholder="e.g. /compo/2000/01/01/welcome-to-ludum-dare-xx/" class="regular-text code" style="width: 90%" /></td>
</tr>
</tbody>
</table>

<p>
<input type="checkbox" name="enable" id="enable" <?php checked($enable, 1); ?> />
<label for="enable">Enable navigation block</label>
</p>

<?php submit_button(); ?>

</form>

</div>
<?php

}
?>
6 changes: 1 addition & 5 deletions compo/themes/ludum/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@
<!-- Event -->
<?php if ( function_exists('ldjam_show_bar') ) { echo ldjam_show_bar(); } ?>
<?php if ( function_exists('c2_navigation') ) {
/*c2_navigation(
"ludum-dare-35",
"Ludum Dare 35",
"/compo/2016/04/13/welcome-to-ludum-dare-35/"
);*/
c2_navigation();
} ?>
<!-- Posts -->
<?php if (have_posts()) { ?>
Expand Down

0 comments on commit 0542556

Please sign in to comment.