WebOrbiton
v1.0.0.1

StocketBase

52 lines · 3.0 KB
  1. <?php
  2. ​
  3. declare(strict_types=1);
  4. ​
  5. final class SocialIcons
  6. {
  7. private const BUILTIN = [
  8. 'twitter' => '<svg viewBox="0 0 24 24"><path d="M18.9 2h3.3l-7.2 8.2L23.5 22h-6.6l-5.2-6.8L5.8 22H2.5l7.7-8.8L1.5 2h6.8l4.7 6.2L18.9 2zm-1.2 18h1.8L7.4 4h-2l12.3 16z"/></svg>',
  9. 'facebook' => '<svg viewBox="0 0 24 24"><path d="M22 12.06C22 6.5 17.52 2 12 2S2 6.5 2 12.06c0 5 3.66 9.15 8.44 9.94v-7.03H7.9v-2.9h2.54V9.86c0-2.5 1.5-3.89 3.78-3.89 1.1 0 2.24.2 2.24.2v2.46h-1.26c-1.24 0-1.63.77-1.63 1.56v1.87h2.78l-.45 2.9h-2.33V22c4.78-.79 8.44-4.94 8.44-9.94z"/></svg>',
  10. 'instagram' => '<svg viewBox="0 0 24 24"><path d="M12 2.2c3.2 0 3.6 0 4.85.07 1.17.05 2.02.24 2.75.52a5.5 5.5 0 0 1 2 1.3 5.5 5.5 0 0 1 1.3 2c.28.73.47 1.58.52 2.75.07 1.25.07 1.65.07 4.85s0 3.6-.07 4.85c-.05 1.17-.24 2.02-.52 2.75a5.5 5.5 0 0 1-1.3 2 5.5 5.5 0 0 1-2 1.3c-.73.28-1.58.47-2.75.52-1.25.07-1.65.07-4.85.07s-3.6 0-4.85-.07c-1.17-.05-2.02-.24-2.75-.52a5.5 5.5 0 0 1-2-1.3 5.5 5.5 0 0 1-1.3-2c-.28-.73-.47-1.58-.52-2.75C2.2 15.6 2.2 15.2 2.2 12s0-3.6.07-4.85c.05-1.17.24-2.02.52-2.75a5.5 5.5 0 0 1 1.3-2 5.5 5.5 0 0 1 2-1.3c.73-.28 1.58-.47 2.75-.52C8.4 2.2 8.8 2.2 12 2.2zm0 3.16a6.64 6.64 0 1 0 0 13.28 6.64 6.64 0 0 0 0-13.28zm0 10.95a4.31 4.31 0 1 1 0-8.62 4.31 4.31 0 0 1 0 8.62zm6.9-11.2a1.55 1.55 0 1 1-3.1 0 1.55 1.55 0 0 1 3.1 0z"/></svg>',
  11. 'youtube' => '<svg viewBox="0 0 24 24"><path d="M23 12s0-3.6-.46-5.3a2.9 2.9 0 0 0-2.05-2.05C18.8 4.2 12 4.2 12 4.2s-6.8 0-8.5.45A2.9 2.9 0 0 0 1.45 6.7C1 8.4 1 12 1 12s0 3.6.46 5.3a2.9 2.9 0 0 0 2.05 2.05c1.7.45 8.5.45 8.5.45s6.8 0 8.5-.45a2.9 2.9 0 0 0 2.05-2.05C23 15.6 23 12 23 12zM9.75 15.5v-7l6.1 3.5z"/></svg>',
  12. 'tiktok' => '<svg viewBox="0 0 24 24"><path d="M16.6 2h-3.2v13.7a2.9 2.9 0 1 1-2.05-2.77v-3.28a6.1 6.1 0 1 0 5.25 6.05V8.4a7.6 7.6 0 0 0 4.4 1.4V6.6a4.4 4.4 0 0 1-4.4-4.4z"/></svg>',
  13. 'linkedin' => '<svg viewBox="0 0 24 24"><path d="M4.98 3.5a2.5 2.5 0 1 1 0 5 2.5 2.5 0 0 1 0-5zM3 9h4v12H3zM9 9h3.8v1.7h.05c.53-.95 1.83-1.95 3.77-1.95 4.03 0 4.78 2.55 4.78 5.87V21h-4v-5.5c0-1.3-.02-2.98-1.83-2.98-1.83 0-2.11 1.4-2.11 2.88V21H9z"/></svg>',
  14. ];
  15. ​
  16. public static function builtinLabels(): array
  17. {
  18. return [
  19. 'twitter' => 'Twitter / X',
  20. 'facebook' => 'Facebook',
  21. 'instagram' => 'Instagram',
  22. 'youtube' => 'YouTube',
  23. 'tiktok' => 'TikTok',
  24. 'linkedin' => 'LinkedIn',
  25. ];
  26. }
  27. ​
  28. public static function builtinSvg(string $key): string
  29. {
  30. return self::BUILTIN[$key] ?? '';
  31. }
  32. ​
  33. public static function isBuiltin(string $key): bool
  34. {
  35. return isset(self::BUILTIN[$key]);
  36. }
  37. ​
  38. public static function sanitizeCustomSvg(string $svg): string
  39. {
  40. $svg = trim($svg);
  41. if ($svg === '' || !str_starts_with($svg, '<svg')) {
  42. return '';
  43. }
  44. ​
  45. if (preg_match('/<script|<foreignobject|<iframe|<embed|<object|on\w+\s*=|javascript:|data:text\/html/i', $svg)) {
  46. return '';
  47. }
  48. ​
  49. return $svg;
  50. }
  51. }
  52. ​