当前位置: 首页>>代码示例>>PHP>>正文


PHP Skin::new_font_name方法代码示例

本文整理汇总了PHP中Skin::new_font_name方法的典型用法代码示例。如果您正苦于以下问题:PHP Skin::new_font_name方法的具体用法?PHP Skin::new_font_name怎么用?PHP Skin::new_font_name使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Skin的用法示例。


在下文中一共展示了Skin::new_font_name方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: gwfontform_submit

function gwfontform_submit(Pieform $form, $values)
{
    global $USER, $SESSION;
    require_once 'file.php';
    require_once 'uploadmanager.php';
    $fontpath = get_config('dataroot') . 'skins/fonts/';
    check_dir_exists($fontpath, true, true);
    $currentfont = null;
    $licence = null;
    $previewfont = null;
    $variants = array();
    $variants['regular'] = array("variant" => "regular", "font-weight" => "normal", "font-style" => "normal");
    $zip = new ZipArchive();
    if ($zip->open($values['gwfzipfile']['tmp_name'])) {
        $currentfont = dirname($zip->getNameIndex(0));
        for ($i = 0; $i < $zip->numFiles; $i++) {
            $extractfiles = array();
            $fontname = dirname($zip->getNameIndex($i));
            $filename = basename($zip->getNameIndex($i));
            $makefolder = false;
            if (empty($fontname) || $fontname == '.') {
                $fontname = substr($values['gwfzipfile']['name'], 0, -1 * strlen('.zip'));
                $makefolder = true;
            }
            // Find correct licence file...
            if (substr($zip->getNameIndex($i), -3) == 'txt') {
                $licence = $filename;
                $extractfiles[] = $zip->getNameIndex($i);
            }
            // Find correct TTF font file for generating skin previews...
            $possiblenames = array(str_replace("_", "", $fontname) . ".ttf", str_replace("_", "", $fontname) . "-Regular.ttf", str_replace("_", "", $fontname) . "-Normal.ttf");
            if (in_array($filename, $possiblenames)) {
                $previewfont = $filename;
                $extractfiles[] = $zip->getNameIndex($i);
            }
            // Reset settings for each new font...
            if (!is_null($licence) && !is_null($previewfont)) {
                $foldername = preg_replace(Skin::FONTNAME_FILTER_CHARACTERS, '', $fontname);
                // Assign a new name, if the font with the same name already exists...
                $foldername = Skin::new_font_name($foldername);
                if ($makefolder == true) {
                    $fontpath .= $foldername . '/';
                    check_dir_exists($fontpath, true, true);
                }
                $installfont = array("name" => $foldername, "title" => str_replace("_", " ", $fontname), "licence" => $licence, "notice" => "", "previewfont" => $previewfont, "variants" => serialize($variants), "fonttype" => "google", "onlyheading" => 0, "fontstack" => "'" . escape_css_string(str_replace("_", " ", $fontname)) . "'", "genericfont" => "sans-serif");
                // Install fonts (write data into database). Check if the record doesn't exist!!!
                ensure_record_exists('skin_fonts', (object) array('name' => $installfont['name']), (object) $installfont);
                // Extract installed fonts
                foreach ($extractfiles as $extractfile) {
                    $fullfontpath = $fontpath . $foldername . '/';
                    check_dir_exists($fullfontpath, true, true);
                    copy("zip://" . $values['gwfzipfile']['tmp_name'] . "#" . $extractfile, $fullfontpath . $previewfont);
                }
                $currentfont = $fontname;
                $licence = null;
                $previewfont = null;
            }
        }
        $SESSION->add_ok_msg(get_string('gwfontadded', 'skin'));
    } else {
        $SESSION->add_error_msg(get_string('archivereadingerror', 'skin'));
    }
    redirect('/admin/site/fonts.php');
}
开发者ID:janaece,项目名称:globalclassroom4_clean,代码行数:64,代码来源:installgwf.php

示例2: importskinform_submit


//.........这里部分代码省略.........
        // TODO: Background image file support for site skins
        if ($siteskin) {
            $skin['body_background_image'] = 0;
            $skin['view_background_image'] = 0;
        } else {
            $items = $skindata->getElementsByTagName('image');
            foreach ($items as $item) {
                // Write necessary data in 'artefact' table...
                // TODO: When we rework the file upload code to make it more general,
                // rewrite this to reuse content from filebrowser.php
                $now = date("Y-m-d H:i:s");
                $artefact = (object) array_merge((array) unserialize($item->getAttribute('artefact')), (array) unserialize($item->getAttribute('artefact_file_files')), (array) unserialize($item->getAttribute('artefact_file_image')));
                unset($artefact->id);
                unset($artefact->fileid);
                $artefact->owner = $USER->get('id');
                $artefact->author = $USER->get('id');
                $artefact->atime = $now;
                $artefact->ctime = $now;
                $artefact->mtime = $now;
                $artobj = new ArtefactTypeImage(0, $artefact);
                $artobj->commit();
                $id = $artobj->get('id');
                // Create folder and file inside it. then write contents into it...
                $imagedir = get_config('dataroot') . ArtefactTypeFile::get_file_directory($id);
                if (!check_dir_exists($imagedir, true, true)) {
                    throw new SystemException("Unable to create folder {$imagedir}");
                } else {
                    // Write contents to a file...
                    $imagepath = $imagedir . '/' . $id;
                    $contents = base64_decode($item->getAttribute('contents'));
                    $fp = fopen($imagepath, 'w');
                    fwrite($fp, $contents);
                    fclose($fp);
                    // We can keep going, but the skin will be missing one of its files
                    if ($clamerror = mahara_clam_scan_file($imagepath)) {
                        $SESSION->add_error_msg($clamerror);
                    }
                    chmod($imagepath, get_config('filepermissions'));
                }
                $type = $item->getAttribute('type');
                if ($type == 'body-background-image') {
                    $skin['body_background_image'] = $id;
                }
                if ($type == 'view-background-image') {
                    $skin['view_background_image'] = $id;
                }
            }
        }
        $viewskin = array();
        if ($skindata->getAttribute('title') != '') {
            $viewskin['title'] = $skindata->getAttribute('title');
        }
        $viewskin['description'] = $skindata->getAttribute('description');
        $viewskin['owner'] = $USER->get('id');
        $viewskin['type'] = $values['skintype'];
        $viewskin['viewskin'] = $skin;
        // Fonts element...
        // Only admins can install site fonts
        if ($USER->get('admin')) {
            $fonts = $skindata->getElementsByTagName('font');
            foreach ($fonts as $font) {
                $fontname = preg_replace("#[^A-Za-z0-9]#", "", $font->getAttribute('name'));
                $fontname = Skin::new_font_name($fontname);
                // Only upload font if it doesn't already exist on the site
                if (!Skin::font_exists($font->getAttribute('title'))) {
                    $fontdata = array('name' => $fontname, 'title' => $font->getAttribute('title'), 'licence' => $font->getAttribute('font-licence'), 'previewfont' => $font->getAttribute('font-preview'), 'variants' => base64_decode($font->getAttribute('font-variants')), 'fonttype' => $font->getAttribute('font-type'), 'onlyheading' => $font->getAttribute('heading-font-only'), 'fontstack' => $font->getAttribute('font-stack'), 'genericfont' => $font->getAttribute('generic-font'));
                    insert_record('skin_fonts', $fontdata);
                    $fontpath = get_config('dataroot') . 'skins/fonts/' . $fontdata['name'] . '/';
                    if (!check_dir_exists($fontpath, true, true)) {
                        throw new SystemException("Unable to create folder {$fontpath}");
                    } else {
                        $files = $font->getElementsByTagName('file');
                        foreach ($files as $file) {
                            // Read the filename and the contents of each file from XML...
                            $filename = $file->getAttribute('name');
                            $contents = base64_decode($file->getAttribute('contents'));
                            // Import and copy each file to the appropriate folder...
                            $fp = fopen($fontpath . $filename, 'wb');
                            fwrite($fp, $contents);
                            fclose($fp);
                            // We can keep going, but the skin will be missing one of its files
                            if ($clamerror = mahara_clam_scan_file($fontpath . $filename)) {
                                $SESSION->add_error_msg($clamerror);
                            }
                            chmod($fontpath . $filename, get_config('filepermissions'));
                        }
                    }
                }
            }
        }
        Skin::create($viewskin);
        db_commit();
    }
    $SESSION->add_ok_msg(get_string('skinimported', 'skin'));
    if ($values['skintype'] == 'site') {
        redirect('/admin/site/skins.php');
    } else {
        redirect('/skin/index.php');
    }
}
开发者ID:patkira,项目名称:mahara,代码行数:101,代码来源:import.php

示例3: addfontform_submit

function addfontform_submit(Pieform $form, $values)
{
    global $USER, $SESSION;
    $foldername = preg_replace(Skin::FONTNAME_FILTER_CHARACTERS, '', $values['fonttitle']);
    // Assign a new name, if the font with the same name already exists...
    $foldername = Skin::new_font_name($foldername);
    $fontpath = get_config('dataroot') . 'skins/fonts/' . $foldername . '/';
    check_dir_exists($fontpath, true, true);
    // If we are uploading a zip file
    if (!empty($values['fontfileZip'])) {
        safe_require('artefact', 'file');
        $zip = new ZipArchive();
        if ($zip->open($values['fontfileZip']['tmp_name'])) {
            for ($i = 0; $i < $zip->numFiles; $i++) {
                $fontname = dirname($zip->getNameIndex($i));
                $filename = basename($zip->getNameIndex($i));
                if (empty($fontname) || $fontname == '.') {
                    $fontname = substr($values['fontfileZip']['name'], 0, -1 * strlen('.zip'));
                }
                // Check that all the needed files exist in the zip file
                $check = uploadfiles_info();
                foreach ($check as $key => $item) {
                    if (end(explode('.', $zip->getNameIndex($i))) == $item['suffix']) {
                        // Extract font file
                        $zip->extractTo($fontpath, $zip->getNameIndex($i));
                        $values['fontfile' . strtoupper($item['suffix'])]['name'] = $zip->getNameIndex($i);
                    }
                }
            }
        }
    }
    // Get SVG id from SVG font file...
    $tempname = !empty($values['fontfileZip']) ? $fontpath . $values['fontfileSVG']['name'] : $values['fontfileSVG']['tmp_name'];
    $filename = $values['fontfileSVG']['name'];
    $xmlDoc = simplexml_load_string(file_get_contents($tempname));
    $svg_id = (string) $xmlDoc->defs->font->attributes()->id;
    // Insert new record with font data into 'skin_fonts' table in database...
    // $foldername equals (only alphanumerical) font name, e.g. 'Nimbus Roman No.9' -> 'NimbusRomanNo9'
    // $foldername is also used as primary key in 'skin_fonts' table.
    switch ($values['fontstyle']) {
        case 'regular':
            $font_variant = 'regular';
            $font_weight = 'normal';
            $font_style = 'normal';
            break;
        case 'bold':
            $font_variant = 'bold';
            $font_weight = 'bold';
            $font_style = 'normal';
            break;
        case 'italic':
            $font_variant = 'italic';
            $font_weight = 'normal';
            $font_style = 'italic';
            break;
        case 'bolditalic':
            $font_variant = 'bolditalic';
            $font_weight = 'bold';
            $font_style = 'italic';
            break;
    }
    $variantdata = array('variant' => $font_variant, 'EOT' => $values['fontfileEOT']['name'], 'SVG' => $values['fontfileSVG']['name'], 'SVGid' => $svg_id, 'TTF' => $values['fontfileTTF']['name'], 'WOFF' => $values['fontfileWOFF']['name'], 'font-weight' => $font_weight, 'font-style' => $font_style);
    // We'll create the database record before we copy the files over, so that
    // Mahara will know about this font in order to be able to delete its contents
    // from the filesystem if something goes wrong.
    ensure_record_exists('skin_fonts', (object) array('name' => $foldername), (object) array('name' => $foldername, 'title' => $values['fonttitle'], 'licence' => $values['fontfilelicence']['name'], 'notice' => $values['fontnotice'], 'previewfont' => $values['fontfileTTF']['name'], 'variants' => serialize(array($font_variant => $variantdata)), 'fonttype' => 'site', 'onlyheading' => $values['fonttype'] == 'heading' ? 1 : 0, 'fontstack' => '\'' . escape_css_string($values['fonttitle']) . '\'', 'genericfont' => $values['genericfont']));
    if (empty($values['fontfileZip'])) {
        // Copy SVG font file to folder...
        $tempname = $values['fontfileSVG']['tmp_name'];
        $filename = $values['fontfileSVG']['name'];
        move_uploaded_file($tempname, $fontpath . $filename);
        // Copy EOT font file.
        $tempname = $values['fontfileEOT']['tmp_name'];
        $filename = $values['fontfileEOT']['name'];
        move_uploaded_file($tempname, $fontpath . $filename);
        // Copy TTF font file to folder...
        $tempname = $values['fontfileTTF']['tmp_name'];
        $filename = $values['fontfileTTF']['name'];
        move_uploaded_file($tempname, $fontpath . $filename);
        // Copy WOFF font file to folder...
        $tempname = $values['fontfileWOFF']['tmp_name'];
        $filename = $values['fontfileWOFF']['name'];
        move_uploaded_file($tempname, $fontpath . $filename);
        // Copy optional font licence file to folder, if it exists...
        if (!empty($values['fontfilelicence'])) {
            $tempname = $values['fontfilelicence']['tmp_name'];
            $filename = $values['fontfilelicence']['name'];
            move_uploaded_file($tempname, $fontpath . $filename);
        }
    }
    $SESSION->add_ok_msg(get_string('fontinstalled', 'skin'));
    redirect('/admin/site/fonts.php');
}
开发者ID:kienv,项目名称:mahara,代码行数:93,代码来源:install.php


注:本文中的Skin::new_font_name方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。