/**
 * Redirect to rtPanel on theme activation
 * 
 * @param String $themename
 * @param Boolean $theme
 */
function rtp_theme_activation($themename, $theme = false)
{
    global $rtp_general;
    $update = 0;
    if (isset($rtp_general['logo_show']) && $rtp_general['logo_show']) {
        $update++;
        $rtp_general['logo_use'] = 'image';
        unset($rtp_general['logo_show']);
    } elseif (isset($rtp_general['logo_show'])) {
        $update++;
        $rtp_general['logo_use'] = 'site_title';
        unset($rtp_general['logo_show']);
    }
    if (isset($rtp_general['use_logo']) && $rtp_general['logo_use'] == 'use_logo_url') {
        $update++;
        $rtp_general['logo_upload'] = $rtp_general['logo_url'];
        $id = rtp_get_attachment_id_from_src($rtp_general['logo_upload'], true);
        $img_dimensions = rtp_get_image_dimensions($rtp_general['logo_upload'], true, '', $id);
        $rtp_general['logo_id'] = $id;
        $rtp_general['logo_width'] = $img_dimensions['width'];
        $rtp_general['logo_height'] = $img_dimensions['height'];
        unset($rtp_general['use_logo']);
        unset($rtp_general['logo_url']);
    } elseif (isset($rtp_general['use_logo']) && $rtp_general['use_logo'] == 'use_logo_upload') {
        $update++;
        $id = rtp_get_attachment_id_from_src($rtp_general['logo_upload'], true);
        $img_dimensions = rtp_get_image_dimensions($rtp_general['logo_upload'], true, '', $id);
        $rtp_general['logo_id'] = $id;
        $rtp_general['logo_width'] = $img_dimensions['width'];
        $rtp_general['logo_height'] = $img_dimensions['height'];
        unset($rtp_general['use_logo']);
    }
    if (isset($rtp_general['favicon_show']) && $rtp_general['favicon_show']) {
        $update++;
        $rtp_general['favicon_use'] = 'image';
        unset($rtp_general['favicon_show']);
    } elseif (isset($rtp_general['favicon_show'])) {
        $update++;
        $rtp_general['favicon_use'] = 'disable';
        unset($rtp_general['favicon_show']);
    }
    if (isset($rtp_general['use_favicon']) && $rtp_general['use_favicon'] == 'use_favicon_url') {
        $update++;
        $rtp_general['favicon_upload'] = $rtp_general['favicon_url'];
        $id = rtp_get_attachment_id_from_src($rtp_general['favicon_upload'], true);
        $img_dimensions = rtp_get_image_dimensions($rtp_general['favicon_upload'], true, '', $id);
        $rtp_general['favicon_id'] = $id;
        unset($rtp_general['use_favicon']);
    } elseif (isset($rtp_general['use_favicon']) && $rtp_general['use_favicon'] == 'use_favicon_upload') {
        $update++;
        $rtp_general['favicon_id'] = rtp_get_attachment_id_from_src($rtp_general['favicon_upload'], true);
        unset($rtp_general['use_favicon']);
        unset($rtp_general['favicon_url']);
    }
    if ($update) {
        update_option('rtp_general', $rtp_general);
    }
}
/**
 * Used to get the image dimensions, provided the 'src'
 *
 * @param string $image_src The Image Source
 * @return mixed
 *
 * @since rtPanel 2.1
 * @param String  $src The image source
 * @param Array   $array whether to get the output in the form of array or not
 * @param String  $deprecated Whether function is deprecated
 * @param Integer $id attachment id
 * @param String  $size Size of the image
 */
function rtp_get_image_dimensions($src, $array = false, $deprecated = '', $id = 0, $size = null)
{
    global $rtp_general;
    if (!empty($deprecated)) {
        _rtp_deprecated_argument(__FUNCTION__, '3.0');
    }
    $id = $id ? $id : rtp_get_attachment_id_from_src($src, true);
    if (!$id) {
        $width = $rtp_general['logo_width'];
        $height = $rtp_general['logo_height'];
    } else {
        $metadata = wp_get_attachment_metadata($id);
        $response = wp_remote_get(preg_replace('/-\\d+x\\d+(?=\\.(jpg|jpeg|png|gif)$)/i', '', $src));
        if ((!preg_match('/(\\d+x\\d+)(\\.(jpg|jpeg|png|gif)$)/i', $src) || 200 != wp_remote_retrieve_response_code($response)) && (isset($metadata) && isset($metadata['width']) && isset($metadata['height']))) {
            $width = $metadata['width'];
            $height = $metadata['height'];
        } elseif (isset($metadata['sizes'])) {
            $pathinfo = pathinfo($src);
            foreach ($metadata['sizes'] as $size) {
                if ($size['file'] == $pathinfo['basename']) {
                    $width = $size['width'];
                    $height = $size['height'];
                    break;
                }
            }
        }
    }
    if (!isset($width) || !isset($height)) {
        return null;
    }
    if ($array) {
        return array('width' => $width, 'height' => $height);
    }
    return ' width="' . $width . '" height="' . $height . '"';
}