本文整理汇总了PHP中core_useragent::supports_svg方法的典型用法代码示例。如果您正苦于以下问题:PHP core_useragent::supports_svg方法的具体用法?PHP core_useragent::supports_svg怎么用?PHP core_useragent::supports_svg使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类core_useragent
的用法示例。
在下文中一共展示了core_useragent::supports_svg方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: icon
public function icon($icon)
{
global $OUTPUT;
if (core_useragent::supports_svg()) {
switch ($icon) {
case 'retweet':
return '<svg class="retweeticon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 75 72"><title>' . get_string('retweet', 'block_twitter') . '</title><path d="M70.676 36.644C70.166 35.636 69.13 35 68 35h-7V19c0-2.21-1.79-4-4-4H34c-2.21 0-4 1.79-4 4s1.79 4 4 4h18c.552 0 .998.446 1 .998V35h-7c-1.13 0-2.165.636-2.676 1.644-.51 1.01-.412 2.22.257 3.13l11 15C55.148 55.545 56.046 56 57 56s1.855-.455 2.42-1.226l11-15c.668-.912.767-2.122.256-3.13zM40 48H22c-.54 0-.97-.427-.992-.96L21 36h7c1.13 0 2.166-.636 2.677-1.644.51-1.01.412-2.22-.257-3.13l-11-15C18.854 15.455 17.956 15 17 15s-1.854.455-2.42 1.226l-11 15c-.667.912-.767 2.122-.255 3.13C3.835 35.365 4.87 36 6 36h7l.012 16.003c.002 2.208 1.792 3.997 4 3.997h22.99c2.208 0 4-1.79 4-4s-1.792-4-4-4z"/></svg>';
break;
case 'reply':
return '<svg class="replyicon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 65 72"><title>' . get_string('reply', 'block_twitter') . '</title><path d="M41 31h-9V19c0-1.14-.647-2.183-1.668-2.688-1.022-.507-2.243-.39-3.15.302l-21 16C5.438 33.18 5 34.064 5 35s.437 1.82 1.182 2.387l21 16c.533.405 1.174.613 1.82.613.453 0 .908-.103 1.33-.312C31.354 53.183 32 52.14 32 51V39h9c5.514 0 10 4.486 10 10 0 2.21 1.79 4 4 4s4-1.79 4-4c0-9.925-8.075-18-18-18z"/></svg>';
break;
case 'like':
return '<svg class="likeicon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 54 72"><title>' . get_string('like', 'block_twitter') . '</title><path d="M38.723,12c-7.187,0-11.16,7.306-11.723,8.131C26.437,19.306,22.504,12,15.277,12C8.791,12,3.533,18.163,3.533,24.647 C3.533,39.964,21.891,55.907,27,56c5.109-0.093,23.467-16.036,23.467-31.353C50.467,18.163,45.209,12,38.723,12z"/></svg>';
break;
default:
return '';
break;
}
} else {
switch ($icon) {
case 'retweet':
return $OUTPUT->pix_icon('retweet', get_string('retweet', 'block_twitter'), 'block_twitter', array('class' => 'icon default')) . $OUTPUT->pix_icon('retweet_hover', get_string('retweet', 'block_twitter'), 'block_twitter', array('class' => 'icon hover'));
break;
case 'reply':
return $OUTPUT->pix_icon('reply', get_string('reply', 'block_twitter'), 'block_twitter', array('class' => 'icon default')) . $OUTPUT->pix_icon('reply_hover', get_string('reply', 'block_twitter'), 'block_twitter', array('class' => 'icon hover'));
break;
case 'like':
return $OUTPUT->pix_icon('like', get_string('like', 'block_twitter'), 'block_twitter', array('class' => 'icon default')) . $OUTPUT->pix_icon('like_hover', get_string('like', 'block_twitter'), 'block_twitter', array('class' => 'icon hover'));
break;
default:
return '';
break;
}
}
}
示例2: use_svg_icons
/**
* Return true if we should look for SVG images as well.
*
* @return bool
*/
public function use_svg_icons()
{
global $CFG;
if ($this->usesvg === null) {
if (!isset($CFG->svgicons) || !is_bool($CFG->svgicons)) {
$this->usesvg = core_useragent::supports_svg();
} else {
// Force them on/off depending upon the setting.
$this->usesvg = $CFG->svgicons;
}
}
return $this->usesvg;
}
示例3: test_supports_svg
/**
* Modifies $_SERVER['HTTP_USER_AGENT'] manually to check if supports_svg
* works as expected.
*/
public function test_supports_svg()
{
$this->assertTrue(core_useragent::supports_svg());
// MSIE 5.0 is not considered a browser at all: known false positive.
core_useragent::instance(true, $this->user_agents['MSIE']['5.0']['Windows 98']);
$this->assertTrue(core_useragent::supports_svg());
core_useragent::instance(true, $this->user_agents['MSIE']['5.5']['Windows 2000']);
$this->assertFalse(core_useragent::supports_svg());
core_useragent::instance(true, $this->user_agents['MSIE']['6.0']['Windows XP SP2']);
$this->assertFalse(core_useragent::supports_svg());
core_useragent::instance(true, $this->user_agents['MSIE']['7.0']['Windows XP SP2']);
$this->assertFalse(core_useragent::supports_svg());
core_useragent::instance(true, $this->user_agents['MSIE']['8.0']['Windows Vista']);
$this->assertFalse(core_useragent::supports_svg());
core_useragent::instance(true, $this->user_agents['MSIE']['9.0']['Windows 7']);
$this->assertTrue(core_useragent::supports_svg());
core_useragent::instance(true, $this->user_agents['MSIE']['9.0i']['Windows 7']);
$this->assertFalse(core_useragent::supports_svg());
core_useragent::instance(true, $this->user_agents['MSIE']['10.0']['Windows 8']);
$this->assertTrue(core_useragent::supports_svg());
core_useragent::instance(true, $this->user_agents['MSIE']['10.0i']['Windows 8']);
$this->assertTrue(core_useragent::supports_svg());
core_useragent::instance(true, $this->user_agents['MSIE']['11.0']['Windows 8.1']);
$this->assertTrue(core_useragent::supports_svg());
core_useragent::instance(true, $this->user_agents['MSIE']['11.0i']['Windows 8.1']);
$this->assertTrue(core_useragent::supports_svg());
core_useragent::instance(true, $this->user_agents['WebKit Android']['525']['G1 Phone']);
$this->assertFalse(core_useragent::supports_svg());
core_useragent::instance(true, $this->user_agents['WebKit Android']['530']['Nexus']);
$this->assertFalse(core_useragent::supports_svg());
core_useragent::instance(true, $this->user_agents['WebKit Android']['537']['Samsung GT-9505']);
$this->assertTrue(core_useragent::supports_svg());
core_useragent::instance(true, $this->user_agents['Opera']['9.0']['Windows XP']);
$this->assertFalse(core_useragent::supports_svg());
core_useragent::instance(true, $this->user_agents['Chrome']['8']['Mac OS X']);
$this->assertTrue(core_useragent::supports_svg());
core_useragent::instance(true, $this->user_agents['Firefox']['18.0']['Mac OS X']);
$this->assertTrue(core_useragent::supports_svg());
}
示例4: filter
function filter($text, array $options = array())
{
global $CFG, $DB;
/// Do a quick check using stripos to avoid unnecessary work
if (!preg_match('/<tex/i', $text) && strpos($text, '$$') === false && strpos($text, '\\[') === false && strpos($text, '\\(') === false && !preg_match('/\\[tex/i', $text)) {
return $text;
}
# //restrict filtering to forum 130 (Maths Tools on moodle.org)
# $scriptname = $_SERVER['SCRIPT_NAME'];
# if (!strstr($scriptname,'/forum/')) {
# return $text;
# }
# if (strstr($scriptname,'post.php')) {
# $parent = forum_get_post_full($_GET['reply']);
# $discussion = $DB->get_record("forum_discussions", array("id"=>$parent->discussion));
# } else if (strstr($scriptname,'discuss.php')) {
# $discussion = $DB->get_record("forum_discussions", array("id"=>$_GET['d']));
# } else {
# return $text;
# }
# if ($discussion->forum != 130) {
# return $text;
# }
$text .= ' ';
preg_match_all('/\\$(\\$\\$+?)([^\\$])/s', $text, $matches);
for ($i = 0; $i < count($matches[0]); $i++) {
$replacement = str_replace('$', '$', $matches[1][$i]) . $matches[2][$i];
$text = str_replace($matches[0][$i], $replacement, $text);
}
// <tex> TeX expression </tex>
// or <tex alt="My alternative text to be used instead of the TeX form"> TeX expression </tex>
// or $$ TeX expression $$
// or \[ TeX expression \] // original tag of MathType and TeXaide (dlnsk)
// or [tex] TeX expression [/tex] // somtime it's more comfortable than <tex> (dlnsk)
$rules = array('<tex(?:\\s+alt=["\'](.*?)["\'])?>(.+?)<\\/tex>', '\\$\\$(.+?)\\$\\$', '\\\\\\[(.+?)\\\\\\]', '\\\\\\((.+?)\\\\\\)', '\\[tex\\](.+?)\\[\\/tex\\]');
$megarule = '/' . implode($rules, '|') . '/is';
preg_match_all($megarule, $text, $matches);
for ($i = 0; $i < count($matches[0]); $i++) {
$texexp = '';
for ($j = 0; $j < count($rules); $j++) {
$texexp .= $matches[$j + 2][$i];
}
$alt = $matches[1][$i];
$texexp = str_replace('<nolink>', '', $texexp);
$texexp = str_replace('</nolink>', '', $texexp);
$texexp = str_replace('<span class="nolink">', '', $texexp);
$texexp = str_replace('</span>', '', $texexp);
$texexp = preg_replace("/<br[[:space:]]*\\/?>/i", '', $texexp);
//dlnsk
$align = "middle";
if (preg_match('/^align=bottom /', $texexp)) {
$align = "text-bottom";
$texexp = preg_replace('/^align=bottom /', '', $texexp);
} else {
if (preg_match('/^align=top /', $texexp)) {
$align = "text-top";
$texexp = preg_replace('/^align=top /', '', $texexp);
}
}
// decode entities encoded by editor, luckily there is very little chance of double decoding
$texexp = html_entity_decode($texexp, ENT_QUOTES, 'UTF-8');
if ($texexp === '') {
continue;
}
$md5 = md5($texexp);
if (!$DB->record_exists("cache_filters", array("filter" => "tex", "md5key" => $md5))) {
$texcache = new stdClass();
$texcache->filter = 'tex';
$texcache->version = 1;
$texcache->md5key = $md5;
$texcache->rawtext = $texexp;
$texcache->timemodified = time();
$DB->insert_record("cache_filters", $texcache, false);
}
$convertformat = get_config('filter_tex', 'convertformat');
if ($convertformat == 'svg' && !core_useragent::supports_svg()) {
$convertformat = 'png';
}
$filename = $md5 . ".{$convertformat}";
$text = str_replace($matches[0][$i], filter_text_image($filename, $texexp, 0, 0, $align, $alt), $text);
}
return $text;
}
示例5: test_useragent_supports
/**
* @dataProvider user_agents_providers
*/
public function test_useragent_supports($useragent, $tests)
{
// Setup the core_useragent instance.
core_useragent::instance(true, $useragent);
// Supports SVG.
if (!isset($tests['supports_svg']) || $tests['supports_svg']) {
$this->assertTrue(core_useragent::supports_svg(), "SVG Support was not reported (and should have been)");
} else {
$this->assertFalse(core_useragent::supports_svg(), "SVG Support was reported (and should not have been)");
}
// Supports JSON ContentType.
if (!isset($tests['supports_json_contenttype']) || $tests['supports_json_contenttype']) {
$this->assertTrue(core_useragent::supports_json_contenttype(), "JSON ContentType Support was not reported (and should have been)");
} else {
$this->assertFalse(core_useragent::supports_json_contenttype(), "JSON ContentType Support was reported (and should not have been)");
}
}
示例6: filter
function filter($text, array $options = array())
{
global $CFG, $DB, $PAGE;
$texfilterenabled = array_key_exists("tex", filter_get_active_in_context($PAGE->context));
if ($texfilterenabled) {
print_error("disable regular TeX notation filter!");
}
$mathjaxenabled = array_key_exists("mathjaxloader", filter_get_active_in_context($PAGE->context));
/// Do a quick check using stripos to avoid unnecessary work
if (!preg_match('/<tex/i', $text) && strpos($text, '$$') === false && strpos($text, '\\[') === false && strpos($text, '\\(') === false && !preg_match('/\\[tex/i', $text)) {
return $text;
}
$text .= ' ';
preg_match_all('/\\$(\\$\\$+?)([^\\$])/s', $text, $matches);
for ($i = 0; $i < count($matches[0]); $i++) {
$replacement = str_replace('$', '$', $matches[1][$i]) . $matches[2][$i];
$text = str_replace($matches[0][$i], $replacement, $text);
}
// <tex> TeX expression </tex>
// or <tex alt="My alternative text to be used instead of the TeX form"> TeX expression </tex>
// or $$ TeX expression $$
// or \[ TeX expression \] // original tag of MathType and TeXaide (dlnsk)
// or [tex] TeX expression [/tex] // somtime it's more comfortable than <tex> (dlnsk)
$rules = array('<tex(?:\\s+alt=["\'](.*?)["\'])?>(.+?)<\\/tex>', '\\$\\$(.+?)\\$\\$', '\\\\\\[(.+?)\\\\\\]', '\\\\\\((.+?)\\\\\\)', '\\[tex\\](.+?)\\[\\/tex\\]');
if ($mathjaxenabled == true) {
$rules = array('<tex(?:\\s+alt=["\'](.*?)["\'])?>(.+?)<\\/tex>', '\\$\\$(.+?)\\$\\$', '\\[tex\\](.+?)\\[\\/tex\\]');
}
$megarule = '/' . implode($rules, '|') . '/is';
preg_match_all($megarule, $text, $matches);
for ($i = 0; $i < count($matches[0]); $i++) {
$texexp = '';
for ($j = 0; $j < count($rules); $j++) {
$texexp .= $matches[$j + 2][$i];
}
$alt = $matches[1][$i];
$texexp = str_replace('<nolink>', '', $texexp);
$texexp = str_replace('</nolink>', '', $texexp);
$texexp = str_replace('<span class="nolink">', '', $texexp);
$texexp = str_replace('</span>', '', $texexp);
$texexp = preg_replace("/<br[[:space:]]*\\/?>/i", '', $texexp);
//dlnsk
$align = "middle";
if (preg_match('/^align=bottom /', $texexp)) {
$align = "text-bottom";
$texexp = preg_replace('/^align=bottom /', '', $texexp);
} else {
if (preg_match('/^align=top /', $texexp)) {
$align = "text-top";
$texexp = preg_replace('/^align=top /', '', $texexp);
}
}
// decode entities encoded by editor, luckily there is very little chance of double decoding
$texexp = html_entity_decode($texexp, ENT_QUOTES, 'UTF-8');
if ($texexp === '') {
continue;
}
$md5 = md5($texexp);
if (!$DB->record_exists("cache_filters", array("filter" => "texwjax", "md5key" => $md5))) {
$texcache = new stdClass();
$texcache->filter = 'texwjax';
$texcache->version = 1;
$texcache->md5key = $md5;
$texcache->rawtext = $texexp;
$texcache->timemodified = time();
$DB->insert_record("cache_filters", $texcache, false);
}
$convertformat = get_config('filter_texwjax', 'convertformat');
if ($convertformat == 'svg' && !core_useragent::supports_svg()) {
$convertformat = 'png';
}
$filename = $md5 . ".{$convertformat}";
$text = str_replace($matches[0][$i], filter_text_image_wjax($filename, $texexp, 0, 0, $align, $alt), $text);
}
return $text;
}