<?php

add_action( 'after_setup_theme', 'coffeetime_default_options' );
function coffeetime_default_options() {
    if ( ! get_option( 'coffeetime_options' ) ) {
        $options = array(
            'logo' => get_template_directory_uri() . '/img/logo.png',
            'favicon' => get_template_directory_uri() . '/img/icon.png',
        );
        update_option( 'coffeetime_options', $options );
    }     
}

add_action( 'admin_menu', 'coffeetime_add_page' );
function coffeetime_add_page() {
    $coffeetime_options_page = add_theme_page( 'ctlogo', 'Coffee Time Options', 'manage_options', 'ctlogo', 'coffeetime_options_page' );
    add_action( 'admin_print_scripts-' . $coffeetime_options_page, 'coffeetime_print_scripts' );
} 
function coffeetime_options_page() {
?>

<div class='wrap' style="font-size:120%;">

<div id='icon-tools' class='icon32'><br/></div>
<h2>Coffee Time  v<?php $my_theme = wp_get_theme(); echo $my_theme->Version; ?></h2>
<p><i>It's Coffee Time! Thanks for using this theme!</i></p>
<p>Suggestions are welcome! If you find a problem or error, please <a href="<?php echo esc_url(__('http://wordpress.org/support/theme/coffee-time','coffeetime')); ?>" target="_blank">advise</a>.</p>
<p>No guarantees, no free personalized support.</p>
<p>Note: This theme does not have feature cascading menu or submenu, ie, all links are shown on a simple and continuous line.</p>
<hr/>
<h2>How to set author's avatar and description</h2>
<p>It is optional, but very recommended.</p>
<p>Use an email associated with a <a href="<?php echo esc_url(__('http://gravatar.com','coffeetime')); ?>" target="_blank">Gravatar's account</a> to show your photo: <i>Users -> Your profile -> Contact Info -> E-mail</i></p>
<p>Create a description to author's profile: <i>Users -> Your profile -> About Yourself -> Biographical Info</i></p>
<p>Another option is set default avatar in <i>Settings -> Discussion -> Avatars</i></p>
<hr/>
<h2>Show excerpt or full post content on frontpage</h2>

<p>The default config is full content of latest posts. Not much pretty :/.</p>

<p>Go to <i>Appearance -> Customize -> Static Front Page</i>, check "A static page", leave "Front page" blank and click "Save & Publish" to show only excerpts. This is more atractive. Or, If you like, also can chose a specific page in "Front page".</p>
<hr/>

<h2>CSS customization tips</h2>
<p><i>Add codes below in "CSS Edit" according to your need.</i></p>
<h3>Blog of one man only? Hide authors list:</h3>
<code>
span.team {
	display: none;
	visibility: hidden;
}
</code><br/>
<h3>Do not show avatar:</h3>
<code>
span.fotoautor { /* in author page */
	display: none;
	visibility: hidden;
}
</code><br/>
<code>
div.credito img:first-of-type { /* in single post */
	display: none;
	visibility: hidden;
}
</code><br/>
<code>
article.chamada p small img { /* in excerpts */
	display: none;
	visibility: hidden;
}
</code><br/>
<code>
span img.avatar { /* in pages */
	display: none;
	visibility: hidden;
}
</code>
<p>Or this way for more simple code:</p>
<code>
span.fotoautor, div.credito img:first-of-type, article.chamada p small img, span img.avatar {
	display: none;
	visibility: hidden;
}

</code>


<h3>Change font of general text:</h3>
<code>
@font-face {
	font-family: 'NAME-OF-YOURFONT';
	font-weight: 400;
	src: url('http://URL-OF-YOUR-FONT.ttf') format("truetype");
}

body {
	font-family: 'NAME-OF-YOURFONT', 'Merriweather', 'Georgia', 'Cambria', 'Times New Roman', 'Times', serif;
}
</code>
<h3>Change general size text of contents:</h3>
<code>
.entry-content p {
	font-size: 1.25em; /* default size */
}
</code>


<hr/>
<h2>Logo and icon options</h2>

<?php if ( isset( $_GET['settings-updated'] ) && $_GET['settings-updated'] ) : ?>
<div class='updated'><p><strong>Settings saved.</strong></p></div>
<?php endif; ?>
<form action='options.php' method='post'>
<?php settings_fields( 'coffeetime_options' ); ?>
<?php do_settings_sections( 'ctlogo' ); ?>
<?php submit_button(); ?>
</form>

<p>To return default images, copy and paste the url on field and click in "Save Changes".</p>
<p><strong>Logo:</strong> <i><?php echo get_template_directory_uri(); ?>/img/logo.png</i><br/>
<strong>Icon:</strong> <i><?php echo get_template_directory_uri(); ?>/img/icon.png</i></p>
<p>Its not recommended, but leave field blank and click "Save Changes" if you don't want logo/icon. Without logo, is recommended create a link to home through menu.</p>
<hr/>
<h2>Like this theme?</h2>

<p>Why not do any of the following:</p>

<ol>
<li>Link to it so other folks can find out about it.</li>
<li>Give it a good rating on <a href="<?php echo esc_url(__('http://wordpress.org/support/view/theme-reviews/coffee-time','coffeetime')); ?>" target="_blank">WordPress.org</a>.</li>
<li>Donate a token of your appreciation.</li>
</ol>
<p>PayPal <form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="P9X6G3SLPLFRA">
<input type="image" src="https://www.paypalobjects.com/pt_BR/i/btn/btn_donate_SM.gif" border="0" name="submit" alt="PayPal">
<img alt="" border="0" src="https://www.paypalobjects.com/pt_BR/i/scr/pixel.gif" width="1" height="1">
</form></p>
<p>PagSeguro <form target="pagseguro" action="https://pagseguro.uol.com.br/checkout/v2/donation.html" method="post">
<input type="hidden" name="receiverEmail" value="robertostrabelli@gmail.com" />
<input type="hidden" name="currency" value="BRL" />
<input type="image" src="https://p.simg.uol.com.br/out/pagseguro/i/botoes/doacoes/84x35-doar.gif" name="submit" alt="PagSeguro" />
</form></p>

<hr/>
<h2>Copyright</h2>
<p>Coffee Time WordPress theme, Copyright (C) 2013 robertostrabelli</p>
<ul>
<li>Coffee Time and all its parts is distributed under the terms of the <a href="<?php echo esc_url(__('http://www.gnu.org/licenses/gpl.html','coffeetime')); ?>" target="_blank">GNU General Public License</a>.</li>
<li>Header's photo by <a href="<?php echo esc_url(__('http://betinho.org','coffeetime')); ?>" target="_blank">Roberto Strabelli</a>.</li>
<li>Coffee cup icon by <a href="<?php echo esc_url(__('http://www.icon-king.com/','coffeetime')); ?>" target="_blank">David Vignoni</a> - Source: <a href="<?php echo esc_url(__('http://www.iconfinder.com/icondetails/1393/128/coffee_cup_hot_tea_icon','coffeetime')); ?>" target="_blank">http://www.iconfinder.com/icondetails/1393/128/coffee_cup_hot_tea_icon</a>.</li>
</ul>

<hr/>
<h3>CHANGELOG</h3>
<ul>
<li>2.1.4 - Increase features: links to category/author rss and time read count.</li>
<li>2.1.3 - Code reorganization, fixes and cleaning. Links to comments.</li>
<li>2.1.2 - Fixes on front page and static page options. More and best use instructions.</li>
<li>2.1 - Code reorganization and cleaning. Thumbnails, post-formats and option to change logo and icon was included. More and best widgets.</li>
<li>2.0.1 - Fixes in menus. Increase theme URI.</li>
<li>2.0 - Rebuilt from scratch.</li>
<li>1.3.6 - ...</li>
<li>1.3.5 - Fixes in functions and style.</li>
<li>1.3.4 - Header's image and icon change. General fixes.</li>
<li>1.3.3 - Header's image and icon change.</li>
<li>1.3.2 - Header's image and icon change. General code cleaning.</li>
<li>1.3.1 - Fixes in functions and standards Guideline WordPress.</li>
<li>1.3 - First submit to WordPress.org.</li>
</ul>

<img src="<?php echo get_template_directory_uri(); ?>/img/alf.png" alt="ALF" />
</div>

<?php 
}

add_action( 'admin_init', 'coffeetime_add_options' );
function coffeetime_add_options() {
    register_setting( 'coffeetime_options', 'coffeetime_options', 'coffeetime_options_validate' );
    add_settings_section( 'coffeetime_section', '', 'coffeetime_section_callback', 'ctlogo' );
    add_settings_field( 'coffeetime_logo', 'Logo - Recommended:  PNG or GIF - background transparent - square, 44x44. Max. 100x100.', 'coffeetime_logo_callback', 'ctlogo', 'coffeetime_section' );
    add_settings_field( 'coffeetime_favicon', 'Favicon - Recommended: PNG - background transparent - square, 57x57, 72x72, 114x114 or 144x144.', 'coffeetime_favicon_callback', 'ctlogo', 'coffeetime_section' );
}

function coffeetime_options_validate($values) { 
    foreach ( $values as $n => $v ) 
        $values[$n] = esc_url($v);
    return $values; 
}

function coffeetime_section_callback() {  };

function coffeetime_logo_callback() {
    $options = get_option( 'coffeetime_options' ); 
?>
    <div>
	<img style='max-width: 100px; max-height:100px; border-color:lightgray;border-style:solid;border-width:1px;background-image:-webkit-linear-gradient(bottom,rgba(0,0,0,0.5) 0,rgba(0,0,0,0.3) 70%,rgba(0,0,0,0) 100%);
 background-image:-moz-linear-gradient(bottom,rgba(0,0,0,0.5) 0,rgba(0,0,0,0.3) 70%,rgba(0,0,0,0) 100%); 
 background-image:-ms-linear-gradient(bottom,rgba(0,0,0,0.5) 0,rgba(0,0,0,0.3) 70%,rgba(0,0,0,0) 100%); 
 background-image:-o-linear-gradient(bottom,rgba(0,0,0,0.5) 0,rgba(0,0,0,0.3) 70%,rgba(0,0,0,0) 100%); 
 background-image:linear-gradient(to top,rgba(0,0,0,0.5) 0,rgba(0,0,0,0.3) 70%,rgba(0,0,0,0) 100%);' src='<?php echo esc_url($options["logo"]); ?>' /> 
        <input type='text' id='coffeetime_logo' class='regular-text text-upload' name='coffeetime_options[logo]' value='<?php echo esc_url($options["logo"]); ?>'/>
        <input type='button' class='button button-upload' value='Upload an image'/>        
    </div>
<?php
}

function coffeetime_favicon_callback() {
    $options = get_option( 'coffeetime_options' ); 
?>
    <div>
	<img style='width:44px;' src='<?php echo esc_url($options["favicon"]); ?>' /> 
        <input type='text' id='coffeetime_favicon' class='regular-text text-upload' name='coffeetime_options[favicon]' value='<?php echo esc_url($options["favicon"]); ?>'/>
        <input type='button' class='button button-upload' value='Upload an image'/>        
    </div>
<?php
}

function coffeetime_print_scripts() {
    wp_enqueue_style( 'thickbox' ); 
    wp_enqueue_script( 'thickbox' );
    wp_enqueue_script( 'media-upload' );
    wp_enqueue_script( 'ctlogo-upload', get_template_directory_uri() . '/js/logo-upload.js', array( 'thickbox', 'media-upload' ) );
}

function coffeetime_add_favicon() {
	$coffeetime_options = get_option( 'coffeetime_options' );
	$coffeetime_favicon = $coffeetime_options['favicon'];
?>
	<link rel="icon" type="image/png" href="<?php echo esc_url($coffeetime_favicon); ?>">
<?php
}
add_action( 'wp_head', 'coffeetime_add_favicon' );
?>