function mp_fb_poster_hook()
{
    if (time() - (int) get_option('mp-deal-poster-last-run') < get_option('mp-fb-deal-poster-time', 7200)) {
        return;
    }
    $last_id = get_option('mp-fb-deal-poster-last-id');
    $next_id = mp_get_next_id($last_id);
    if (!$next_id || $next_id == $last_id) {
        return false;
    }
    $post = get_post($next_id);
    if (!empty($post)) {
        mp_getdeal_post_on_fb($post);
    }
    update_option('mp-deal-poster-last-run', time());
    mp_fb_deal_send_report((int) $next_id . ' at ' . time());
}
function mp_fb_poster_hook()
{
    if (time() - (int) get_option('mp-deal-poster-last-run') < get_option('mp-fb-deal-poster-time', 7200)) {
        // return;
    }
    $deal_cat = isset($_GET['dealcat']) ? $_GET['dealcat'] : '';
    global $fivy_options;
    switch ($deal_cat) {
        case 'food':
            $last_id = 1;
            //get_option('mp-fb-deal-poster-last-id-food');
            $deal_cat_id = isset($fivy_options['home_deal_cat1']) ? $fivy_options['home_deal_cat1'] : 0;
            break;
        case 'fun':
            $last_id = get_option('mp-fb-deal-poster-last-id-fun');
            $deal_cat_id = isset($fivy_options['home_deal_cat2']) ? $fivy_options['home_deal_cat2'] : 0;
            break;
        case 'vacation':
            $last_id = get_option('mp-fb-deal-poster-last-id-vacation');
            $deal_cat_id = isset($fivy_options['home_deal_cat5']) ? $fivy_options['home_deal_cat5'] : 0;
            break;
        case 'gadget':
            $last_id = get_option('mp-fb-deal-poster-last-id-gadget');
            $deal_cat_id = isset($fivy_options['home_deal_cat3']) ? $fivy_options['home_deal_cat3'] : 0;
            break;
        case 'small':
            $last_id = get_option('mp-fb-deal-poster-last-id-small');
            $deal_cat_id = isset($fivy_options['home_deal_cat4']) ? $fivy_options['home_deal_cat4'] : 0;
            break;
        default:
            die('Wrong URL');
            break;
    }
    $next_id = mp_get_next_id($last_id, 'deal', $deal_cat_id);
    if (!$next_id || $next_id == $last_id) {
        return false;
    }
    $post = get_post($next_id);
    if (!empty($post)) {
        mp_getdeal_post_on_fb($post);
    }
    update_option('mp-deal-poster-last-run', time());
    mp_fb_deal_send_report((int) $next_id . ' at ' . time());
}