<?php
/**
 * Title: Footer Hooks
 *
 * Description: Defines actions/hooks for footer content.
 *
 * Please do not edit this file. This file is part of the CyberChimps Framework and all modifications
 * should be made in a child theme.
 *
 * @category CyberChimps Framework
 * @package  Framework
 * @since    1.0
 * @author   CyberChimps
 * @license  http://www.opensource.org/licenses/gpl-license.php GPL v3.0 (or later)
 * @link     http://www.cyberchimps.com/
 */

/**
 * Adds the CyberChimps credit.
 *
 * @since 1.0
 */
function cyberchimps_footer_credit() {
	?>
	<div class="container-full-width" id="after_footer">
		<div class="container">
			<footer class="site-footer">
				<div class="row">
					<div class="col-xs-12 col-sm-6 col-md-6 col-lg-6">
						<div id="credit 123">
							<a href="<?php esc_url( __( '//cyberchimps.com/','cyberchimps_core' ) ); ?>" target="_blank" title="CyberChimps Themes" rel="noindex, nofollow">									
								<h4 class="cc-credit-text"><?php _e( 'CyberChimps WordPress Themes', 'cyberchimps_core' ); ?></h4>
								<span class="screen-reader-text "><?php __( 'Theme home page (will open in a new window)', 'cyberchimps_core' ); ?></span>
							</a>								
						</div>
					</div>
					<!-- Adds the afterfooter copyright area -->
					<?php $copyright = ( get_theme_mod( 'footer_copyright_text' ) ) ? get_theme_mod( 'footer_copyright_text' ) : '&copy; ' . date( 'Y' ) . ' <a href="' . esc_url( home_url( '/' ) ) . '" title="' . esc_attr( get_bloginfo( 'name', 'display' ) ) . '">' . esc_attr( get_bloginfo( 'name' ) ) . '</a>'; ?>
					<div class="col-xs-12 col-sm-6 col-md-6 col-lg-6">
						<div id="copyright">
							<?php echo wp_kses_post( $copyright ); ?>
						</div>
					</div>
				</div> <!-- end of div row-->
			</footer><!-- .site-footer -->
		</div><!-- .container -->
	</div><!-- #after_footer -->
<?php
}

add_action( 'cyberchimps_footer', 'cyberchimps_footer_credit' );

// Start new row of footer widgets with a new row div so that it keeps the fluid layout.
function cyberchimps_footer_widgets( $params ) {

	// Checked if it's footer widgets.
	if ( 'Footer Widgets' == $params[0]['name'] ) {

		// Declare a widget counter globally so that we can increase it in each iteration.
		global $footer_widget_counter;
		$footer_widget_counter++;

		// If it's 5(or multiple of 5)th widget then we need to close the current row div and start a new one.
		if ( 0 == $footer_widget_counter % 5 ) {
			echo '</div> <div class="row">';
		}
	}

	return $params;
}
add_filter( 'dynamic_sidebar_params', 'cyberchimps_footer_widgets' );
