Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP]Problem z kodem
Forum PHP.pl > Forum > Przedszkole
Nocturnal
Witam.


W kwestii php jestem kompletnym laikiem, a potrzebuję przerobić pewien skrypt pod siebie. O pomoc prosiłem już na oficjalnym forum supportu WBB (woltlab burning board) ale tam mi nie pomogli, tak więc zwracam się do Was z nadzieją że mnie nie zostawicie w potrzebie. Jeśli będzie taka potrzeba jestem w stanie sypnąć groszem za okazaną mi pomoc (przelew). A teraz do rzeczy.

  1. <?php
  2. require_once(WCF_DIR.'lib/data/message/bbcode/BBCodeParser.class.php');
  3. require_once(WCF_DIR.'lib/data/message/bbcode/BBCode.class.php');
  4.  
  5. /**
  6.  * BBCode for [soundcloud] Tag
  7.  * examples:
  8.  * - [soundcloud]http://soundcloud.com/zedsdead/mini-mix-for-bbc-radio-1[/soundcloud]
  9.  * - [soundcloud="width=100%,height=81,show_comments=true,auto_play=false,color=ff7700"]http://soundcloud.com/zedsdead/mini-mix-for-bbc-radio-1[/soundcloud]
  10.  *
  11.  * @author Torben Brodt
  12.  * @package com.woltlab.wcf.soundcloud
  13.  * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-3.0.html>
  14.  */
  15. class SoundcloudBBCode implements BBCode {
  16.  
  17. /**
  18. * allowed attributes
  19. * @var array
  20. */
  21. protected static $allowed = array(
  22. 'width' => '\d+%?',
  23. 'height' => '\d+',
  24. 'show_comments' => '(true|false)',
  25. 'auto_play' => '(false)', // no sense in thread page
  26. 'color' => '[abcdef0-9]{3,6}',
  27. );
  28.  
  29. /**
  30. * @return boolean
  31. */
  32. protected function isValidURL($url) {
  33. $row = @parse_url( $url );
  34. if(!isset($row['host'])) {
  35. return false;
  36. }
  37. return preg_match('/^(.+\.)?(((staging|sandbox)-)?soundcloud\.com$)/', $row['host']);
  38. }
  39.  
  40. /**
  41. * @see BBCode::getParsedTag()
  42. */
  43. public function getParsedTag($openingTag, $content, $closingTag, BBCodeParser $parser) {
  44. $url = $content;
  45. if(!$this->isValidURL($url)) {
  46. return 'SoundCloud: invalid url';
  47. }
  48.  
  49. $attributes = array(
  50. 'width' => '100%',
  51. 'height' => '81',
  52. 'show_comments' => 'true',
  53. 'auto_play' => 'false',
  54. 'color' => 'ff7700',
  55. );
  56.  
  57. if(isset($openingTag['attributes']) && count($openingTag['attributes'])) {
  58. foreach($openingTag['attributes'] as $val) {
  59. $val = explode('=', $val, 2);
  60. if(count($val) != 2) {
  61. continue;
  62. }
  63. $key = ltrim($val[0], '"');
  64. $val = rtrim($val[1], '"');
  65. if(!isset(self::$allowed[$key]) || !preg_match('/^'.self::$allowed[$key].'$/', $val)) {
  66. continue;
  67. }
  68. $attributes[$key] = $val;
  69. }
  70. }
  71. $url .= '?'.http_build_query($attributes);
  72. $encodedurl = urlencode($url);
  73.  
  74. if ($parser->getOutputType() == 'text/html') {
  75. return '<object height="'.$attributes['height'].'" width="'.$attributes['width'].'"> <param name="movie" value="http://player.soundcloud.com/player.swf?url='.$encodedurl.'"></param> <param name="allowscriptaccess" value="always"></param> <embed allowscriptaccess="always" height="'.$attributes['height'].'" src="http://player.soundcloud.com/player.swf?url='.$encodedurl.'" type="application/x-shockwave-flash" width="'.$attributes['width'].'"></embed> </object>';
  76. }
  77. else if ($parser->getOutputType() == 'text/plain') {
  78. return $url;
  79. }
  80. }
  81. }
  82. ?>


To skrypt bbcode który ma za zadanie dodać odtwarzacz soundcloud do tematu (po wklejeniu do tematu linku piosenki w serwisie soundcloud.com)
Chcę tak przerobić ten skrypt by obsługiwał linki z hulkshare.com
Link do odtwarzacza hulkshare (wystarczy na końcu dodać kod utworu np. c42sofv99d7u) http://www.hulkshare.com/embed_mp3.php?fn=
Dodatkowe info: wysokość playera - 49px | trzeba dodać dwa atrybuty 'bg' => '000000', oraz 'fg' => '71C90C',

Za okazaną pomoc serdecznie dziękuję.
przemo191
  1. <?php
  2. require_once(WCF_DIR.'lib/data/message/bbcode/BBCodeParser.class.php');
  3. require_once(WCF_DIR.'lib/data/message/bbcode/BBCode.class.php');
  4.  
  5. /**
  6.  * BBCode for [soundcloud] Tag
  7.  * examples:
  8.  * - [soundcloud]http://soundcloud.com/zedsdead/mini-mix-for-bbc-radio-1[/soundcloud]
  9.  * - [soundcloud="width=100%,height=81,show_comments=true,auto_play=false,color=ff7700"]http://soundcloud.com/zedsdead/mini-mix-for-bbc-radio-1[/soundcloud]
  10.  *
  11.  * @author Torben Brodt
  12.  * @package com.woltlab.wcf.soundcloud
  13.  * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-3.0.html>
  14.  */
  15. class SoundcloudBBCode implements BBCode {
  16.  
  17. /**
  18. * allowed attributes
  19. * @var array
  20. */
  21. protected static $allowed = array(
  22. 'width' => '\d+%?',
  23. 'height' => '\d+',
  24. 'show_comments' => '(true|false)',
  25. 'auto_play' => '(false)', // no sense in thread page
  26. 'color' => '[abcdef0-9]{3,6}',
  27. );
  28.  
  29. /**
  30. * @return boolean
  31. */
  32. protected function isValidURL($url) {
  33. $row = @parse_url( $url );
  34. if(!isset($row['host'])) {
  35. return false;
  36. }
  37. return preg_match('/^(.+\.)?(((staging|sandbox)-)?soundcloud\.com$)/', $row['host']);
  38. }
  39.  
  40. /**
  41. * @see BBCode::getParsedTag()
  42. */
  43. public function getParsedTag($openingTag, $content, $closingTag, BBCodeParser $parser) {
  44. $url = $content;
  45. if(!$this->isValidURL($url)) {
  46. return 'SoundCloud: invalid url';
  47. }
  48.  
  49. $attributes = array(
  50. 'width' => '100%',
  51. 'height' => '81',
  52. 'show_comments' => 'true',
  53. 'auto_play' => 'false',
  54. 'color' => 'ff7700',
  55. 'bgcolor' => '000000',
  56. );
  57.  
  58. if(isset($openingTag['attributes']) && count($openingTag['attributes'])) {
  59. foreach($openingTag['attributes'] as $val) {
  60. $val = explode('=', $val, 2);
  61. if(count($val) != 2) {
  62. continue;
  63. }
  64. $key = ltrim($val[0], '"');
  65. $val = rtrim($val[1], '"');
  66. if(!isset(self::$allowed[$key]) || !preg_match('/^'.self::$allowed[$key].'$/', $val)) {
  67. continue;
  68. }
  69. $attributes[$key] = $val;
  70. }
  71. }
  72. $url .= '?'.http_build_query($attributes);
  73. $encodedurl = urlencode($url);
  74.  
  75. if ($parser->getOutputType() == 'text/html') {
  76. return '<object bgcolor="'.$attributes['bgcolor'].'" height="'.$attributes['height'].'" width="'.$attributes['width'].'"> <param name="movie" value="http://player.soundcloud.com/player.swf?url='.$encodedurl.'"></param> <param name="allowscriptaccess" value="always"></param> <embed bgcolor="'.$attributes['bgcolor'].'" allowscriptaccess="always" height="'.$attributes['height'].'" src="http://player.soundcloud.com/player.swf?url='.$encodedurl.'" type="application/x-shockwave-flash" width="'.$attributes['width'].'"></embed> </object>';
  77. }
  78. else if ($parser->getOutputType() == 'text/plain') {
  79. return $url;
  80. }
  81. }
  82. }
  83. ?>


Pewnie czegoś nie wiem, ale co to jest fg?questionmark.gif
Nocturnal
fg to kolor buttona

http://hulkshare.com/a7ak3x1cstfc - kliknij sobie embed

@phpion

Nie mam takiej mozliwosci, nie widze przycisku "edytuj"
phpion
Proszę poprawnie zatytułować wątek - tutaj praktycznie każdy ma "problem z kodem".
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.