コード例 #1
0
ファイル: themewizard.php プロジェクト: erico-deh/ocPortal
/**
 * Generate a logo from the template.
 *
 * @param  string		The site name.
 * @param  string		The site slogan.
 * @param  boolean	Whether to output the logo to the browser, destroy then image, and exit the script (i.e. never returns)
 * @param  ?string	The theme to use the logo template from (NULL: default root zone theme).
 * @param  string		The logo img file to base upon.
 * @return resource  The image resource.
 */
function generate_logo($name, $slogan, $raw = false, $theme = NULL, $use = 'logo-template')
{
    require_code('character_sets');
    if (is_null($theme)) {
        $theme = $GLOBALS['SITE_DB']->query_value('zones', 'zone_theme', array('zone_name' => ''));
        if ($theme == '' || $theme == '-1') {
            $theme = 'default';
        }
    }
    $logo_wizard_details = array();
    if ($theme != 'default') {
        $ini_path = get_custom_file_base() . '/themes/' . filter_naughty($theme) . '/theme.ini';
        if (file_exists($ini_path)) {
            $logo_wizard_details += better_parse_ini_file($ini_path);
        }
    }
    $ini_path = get_file_base() . '/themes/default/theme.ini';
    $logo_wizard_details += better_parse_ini_file($ini_path);
    $logo_url = $GLOBALS['SITE_DB']->query_value_null_ok('theme_images', 'path', array('theme' => $theme, 'id' => $use));
    if (!is_null($logo_url)) {
        $file_path_stub = convert_url_to_path($logo_url);
    }
    if (is_null($logo_url) || !file_exists($file_path_stub)) {
        $logo_url = find_theme_image($use, false, false, $theme);
    } else {
        if (url_is_local($logo_url)) {
            $logo_url = (strpos($logo_url, 'themes/default/') !== false ? get_base_url() : get_custom_base_url()) . '/' . $logo_url;
        }
    }
    $file_path_stub = convert_url_to_path($logo_url);
    if (!is_null($file_path_stub)) {
        if (!file_exists($file_path_stub)) {
            $file_path_stub = get_file_base() . '/themes/default/images/trimmed-logo-template.png';
        }
        // Exceptional situation. Maybe theme got corrupted?
        $data = file_get_contents($file_path_stub);
    } else {
        $data = http_download_file($logo_url);
    }
    $img = imagecreatefromstring($data);
    if ($img === false) {
        warn_exit(do_lang_tempcode('CORRUPT_FILE', escape_html($logo_url)));
    }
    $ttf_font = get_file_base() . '/data/fonts/Vera.ttf';
    if (!function_exists('imagettftext') || !array_key_exists('FreeType Support', gd_info()) || !file_exists($ttf_font) || @imagettfbbox(26.0, 0.0, get_file_base() . '/data/fonts/Vera.ttf', 'test') === false) {
        $font = intval($logo_wizard_details['site_name_font_size_small_non_ttf']);
        $font_width = imagefontwidth($font) * strlen($name);
        $font_height = imagefontheight($font);
    } else {
        list(, , $font_width, , , , , $font_height) = imagettfbbox(26.0, 0.0, $ttf_font, foxy_utf8_to_nce($name));
        $font_height = max($font_height, -$font_height);
    }
    $white = imagecolorallocate($img, hexdec(substr($logo_wizard_details['site_name_colour'], 0, 2)), hexdec(substr($logo_wizard_details['site_name_colour'], 2, 2)), hexdec(substr($logo_wizard_details['site_name_colour'], 4, 2)));
    $black = imagecolorallocate($img, 0, 0, 0);
    $matches = array();
    if (file_exists(get_custom_file_base() . '/themes/' . $theme . '/css_custom/global.css')) {
        $css_file = file_get_contents(get_custom_file_base() . '/themes/' . $theme . '/css_custom/global.css');
    } else {
        $css_file = file_get_contents(get_file_base() . '/themes/default/css/global.css');
    }
    if (preg_match('/#(\\w\\w)(\\w\\w)(\\w\\w); \\/\\* \\{\\$,wizard, 100% medborder.border}/', $css_file, $matches) != 0) {
        $blue = imagecolorallocate($img, hexdec($matches[1]), hexdec($matches[2]), hexdec($matches[3]));
    } else {
        $blue = imagecolorallocate($img, hexdec(substr($logo_wizard_details['slogan_colour'], 0, 2)), hexdec(substr($logo_wizard_details['slogan_colour'], 2, 2)), hexdec(substr($logo_wizard_details['slogan_colour'], 4, 2)));
    }
    $do = array(array($slogan, intval($logo_wizard_details['slogan_x_offset']), intval($logo_wizard_details['slogan_y_offset']), intval($logo_wizard_details['slogan_font_size']), $ttf_font, $white));
    if ($font_width > intval($logo_wizard_details['site_name_split']) && strpos($name, ' ') !== false) {
        if (function_exists('imagettftext') && array_key_exists('FreeType Support', gd_info()) && file_exists($ttf_font) && @imagettfbbox(26.0, 0.0, get_file_base() . '/data/fonts/Vera.ttf', 'test') !== false) {
            list(, , $font_width, , , , , $font_height) = imagettfbbox(floatval($logo_wizard_details['site_name_font_size_small']), 0.0, $ttf_font, foxy_utf8_to_nce($name));
            $font_height = max($font_height, -$font_height);
        }
        $bits = explode(' ', $name);
        $a = '';
        $b = '';
        foreach ($bits as $bit) {
            if (strlen($a) < intval(round(floatval(strlen($name)) / 2.0))) {
                $a .= $bit . ' ';
            } else {
                $b .= $bit . ' ';
            }
        }
        $do[] = array($a, intval($logo_wizard_details['site_name_x_offset']), intval($logo_wizard_details['site_name_y_offset_small']) + $font_height, intval($logo_wizard_details['site_name_font_size_small']), $ttf_font, $blue);
        $do[] = array($b, intval($logo_wizard_details['site_name_x_offset']), intval($logo_wizard_details['site_name_y_offset_small']) + $font_height * 2 + intval($logo_wizard_details['site_name_split_gap']), intval($logo_wizard_details['site_name_font_size_small']), $ttf_font, $blue);
    } elseif ($font_width > intval($logo_wizard_details['site_name_split'])) {
        if (function_exists('imagettftext') && array_key_exists('FreeType Support', gd_info()) && file_exists($ttf_font) && @imagettfbbox(26.0, 0.0, get_file_base() . '/data/fonts/Vera.ttf', 'test') !== false) {
            list(, , $font_width, , , , , $font_height) = imagettfbbox(floatval($logo_wizard_details['site_name_font_size_small']), 0.0, $ttf_font, foxy_utf8_to_nce($name));
            $font_height = max($font_height, -$font_height);
        }
        $do[] = array($name, intval($logo_wizard_details['site_name_x_offset']), intval($logo_wizard_details['site_name_y_offset']) + $font_height, intval($logo_wizard_details['site_name_font_size_small']), $ttf_font, $blue);
    } else {
        $do[] = array($name, intval($logo_wizard_details['site_name_x_offset']), intval($logo_wizard_details['site_name_y_offset']) + $font_height, floatval($logo_wizard_details['site_name_font_size']), $ttf_font, $blue);
    }
    foreach ($do as $i => $doing) {
        //if ($i==1) continue;
        if (function_exists('imagettftext') && array_key_exists('FreeType Support', gd_info()) && file_exists($doing[4]) && @imagettfbbox(26.0, 0.0, get_file_base() . '/data/fonts/Vera.ttf', 'test') !== false) {
            imagettftext($img, (double) $doing[3], 0.0, $doing[1], $doing[2], $doing[5], $doing[4], foxy_utf8_to_nce($doing[0]));
        } else {
            imagestring($img, $doing[3] == intval($logo_wizard_details['site_name_font_size_small']) ? intval($logo_wizard_details['site_name_font_size_nonttf']) : $font, $doing[1], $doing[2] - 11, $doing[0], $doing[5]);
        }
    }
    if ($raw) {
        header('Content-type: image/png');
        /*if (strstr(ocp_srv('HTTP_USER_AGENT'),'MSIE')!==false)
        			header('Content-Disposition: filename="-logo.png"');
        		else
        			header('Content-Disposition: attachment; filename="-logo.png"');*/
        imagepng($img);
        imagedestroy($img);
        exit;
    }
    return $img;
}
コード例 #2
0
 /**
  * Show the header row for permission editor (all the usergroups, except admin usergroups).
  *
  * @param  array			List of admin usergroups
  * @param  array			Map of usergroups (id=>name)
  * @return tempcode		The header row
  */
 function _access_header($admin_groups, $groups)
 {
     require_code('themes2');
     $css_path = get_custom_file_base() . '/themes/' . $GLOBALS['FORUM_DRIVER']->get_theme() . '/templates_cached/' . user_lang() . '/global.css';
     $color = 'FF00FF';
     if (file_exists($css_path)) {
         $tmp_file = file_get_contents($css_path);
         $matches = array();
         if (preg_match('#\\nth[\\s,][^\\}]*\\sbackground-color:\\s*\\#([\\dA-Fa-f]*);#sU', $tmp_file, $matches) != 0) {
             $color = $matches[1];
         }
     }
     require_code('character_sets');
     // Column headers (groups)
     $header_cells = new ocp_tempcode();
     foreach ($groups as $id => $name) {
         if (in_array($id, $admin_groups)) {
             continue;
         }
         $header_cells->attach(do_template('PERMISSION_HEADER_CELL', array('_GUID' => 'c77bd5d8d9dedb6a3e61c477910a06b7', 'COLOR' => $color, 'GROUP' => foxy_utf8_to_nce($name))));
     }
     $header_cells->attach(do_template('PERMISSION_HEADER_CELL', array('_GUID' => '33fde6c008293f20bb3a51e912748c67', 'COLOR' => $color, 'GROUP' => foxy_utf8_to_nce('+/-'))));
     return $header_cells;
 }
コード例 #3
0
 /**
  * Utility method for writing text onto images.
  *
  * @param  ID_TEXT	ID.
  * @param  array		A map of parameters.
  * @param  URLPATH	The image path.
  * @return mixed		URL of completed image OR tempcode error.
  */
 function _do_image($cache_id, &$map, $img_path)
 {
     if (!array_key_exists('font_size', $map)) {
         $map['font_size'] = '8';
     }
     if (!array_key_exists('data', $map)) {
         $map['data'] = do_lang('FILL_IN_DATA_PARAM');
     }
     // Cache to auto_thumbs
     if (!file_exists(get_custom_file_base() . '/uploads/auto_thumbs/' . $cache_id . '.png') || get_option('is_on_block_cache') == '0') {
         // Ok so not cached yet
         $pos_x = intval(array_key_exists('x', $map) ? $map['x'] : '0');
         $pos_y = intval(array_key_exists('y', $map) ? $map['y'] : '12');
         $_color = array_key_exists('color', $map) ? $map['color'] : 'FFFFFF';
         if (substr($_color, 0, 1) == '#') {
             $_color = substr($_color, 1);
         }
         $font = array_key_exists('font', $map) ? $map['font'] : 'Vera';
         $center = (array_key_exists('center', $map) ? $map['center'] : '0') == '1';
         $file_base = get_custom_file_base() . '/data_custom/fonts/';
         if (!file_exists($file_base . '/' . $font . '.ttf')) {
             $file_base = get_file_base() . '/data/fonts/';
         }
         $file_contents = file_get_contents((strpos($img_path, '/default/images/') !== false ? get_file_base() : get_custom_file_base()) . '/' . $img_path, FILE_BINARY);
         $img = @imagecreatefromstring($file_contents);
         if ($img === false) {
             return paragraph(do_lang_tempcode('CORRUPT_FILE', escape_html($img_path)));
         }
         imagealphablending($img, true);
         imagesavealpha($img, true);
         list(, , , , $width, , , ) = imagettfbbox(floatval($map['font_size']), 0.0, $file_base . $font . '.ttf', $map['data']);
         $colour = imagecolorallocate($img, hexdec(substr($_color, 0, 2)), hexdec(substr($_color, 2, 2)), hexdec(substr($_color, 4, 2)));
         $width = max($width, -$width);
         if ($center) {
             $pos_x += intval(imagesx($img) / 2 - $width / 2);
         }
         if ($pos_x < 0) {
             $pos_x = 0;
         }
         $pos_x--;
         require_code('character_sets');
         $text = foxy_utf8_to_nce($map['data']);
         if (strpos($text, '&#') === false) {
             $previous = mixed();
             $nxpos = 0;
             for ($i = 0; $i < strlen($text); $i++) {
                 if (!is_null($previous)) {
                     list(, , $rx1, , $rx2) = imagettfbbox(floatval($map['font_size']), 0.0, $file_base . $font . '.ttf', $previous);
                     $nxpos += max($rx1, $rx2) + 1;
                 }
                 imagettftext($img, floatval($map['font_size']), 0.0, $pos_x + $nxpos, $pos_y, $colour, $file_base . $font . '.ttf', $text[$i]);
                 $previous = $text[$i];
             }
         } else {
             imagettftext($img, floatval($map['font_size']), 0.0, $pos_x, $pos_y, $colour, $file_base . $font . '.ttf', $text);
         }
         imagepng($img, get_custom_file_base() . '/uploads/auto_thumbs/' . $cache_id . '.png');
         imagedestroy($img);
     }
     $url = get_custom_base_url() . '/uploads/auto_thumbs/' . $cache_id . '.png';
     return $url;
 }