RandomBanner - Classe para mostrar banner aleatório em imagem ou flash
Publicado por Jonathas Rodrigues (última atualização em 05/01/2010)
[ Hits: 7.825 ]
Homepage: http://jonathas.com
Essa classe coloca os banners num array, depois escolhe aleatoriamente e pega a extensão do arquivo para gerar o HTML necessário para mostrar flash ou imagens.
Obs.: Os comentários estão em inglês pois tive que traduzir para postar no PHPClasses.org.
Mais informações e exemplo de uso no meu blog: http://bit.ly/5ogEts
Essa é a minha segunda contribuição ao site. Então, por favor, podem deixar algum comentário sobre como melhorar, ou crítica construtiva.
Obrigado.
<?php /** * Class RandomBanner * - Show random banners (Image or Flash) * * @author Jonathas Rodrigues <jonathas at archlinux dot us> * @copyright 2009, Jonathas Rodrigues * @version 1.5 * @license http://opensource.org/licenses/gpl-license.php GNU Public License */ class RandomBanner { private $content; private $links; private $height; private $width; private $banner; /* * This method adds a banner. * The associated values below, are the default ones for the parameters. * To add an image, $content and $link are necessary. * To add a Flash Banner, $content, $type and $pos are necessary, and * anything other than "img" must be associated to $type. * If you want the Flash Banner to be a sidebar banner, anything other than "top" must be associated to $pos. * The height and width for the top or sidebar Flash Banners can be changed below. * @access public * @param String $content * @param String $link * @param String $type * @param String $pos * @return void */ public function setBanner($content,$link="nothing",$type="img",$pos="top") { $this->links[] = $link; $this->content[] = $content; if($type != "img") { if($pos == "top") { $this->height = "142"; $this->width = "709"; } else { $this->height = "371"; $this->width = "117"; } } } /* * This method randomizes the Banner * @access private * @return void */ private function randomizeBanner() { $total = count($this->content); $total--; $this->banner = rand(0,$total); } /* * This method generates the banner's HTML. * It calls randomizeBanner(), finds out the file extension, * and if it is swf, it generates HTML to insert the Flash Banner. * If it is anything other than swf, it generates HTML to insert an image. * @access private * @return String */ private function generateBanner() { $this->randomizeBanner(); $ext = array_reverse(explode(".",$this->content[$this->banner])); if($ext[0] == "swf") { $result = "<object id=\"FlashID\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" width=\"".$this->width."\" height=\"".$this->height."\"> <param name=\"movie\" value=\"".$this->content[$this->banner]."\" /> <param name=\"quality\" value=\"high\" /> <param name=\"wmode\" value=\"opaque\" /> <param name=\"swfversion\" value=\"9.0.45.0\" /> <!-- This param tag prompts users with Flash Player 6.0 r65 and higher to download the latest version of Flash Player. Delete it if you don’t want users to see the prompt. --> <param name=\"expressinstall\" value=\"Scripts/expressInstall.swf\" /> <!-- Next object tag is for non-IE browsers. So hide it from IE using IECC. --> <!--[if !IE]>--> <object type=\"application/x-shockwave-flash\" data=\"".$this->content[$this->banner]."\" width=\"".$this->width."\" height=\"".$this->height."\"> <!--<![endif]--> <param name=\"quality\" value=\"high\" /> <param name=\"wmode\" value=\"opaque\" /> <param name=\"swfversion\" value=\"9.0.45.0\" /> <param name=\"expressinstall\" value=\"Scripts/expressInstall.swf\" /> <!-- The browser displays the following alternative content for users with Flash Player 6.0 and older. --> <div> <h4>Content on this page requires a newer version of Adobe Flash Player.</h4> <p><a href=\"http://www.adobe.com/go/getflashplayer\"><img src=\"http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif\" alt=\"Get Adobe Flash player\" width=\"112\" height=\"33\" /></a></p> </div> <!--[if !IE]>--> </object> <!--<![endif]--> </object> <script type=\"text/javascript\"> <!-- swfobject.registerObject(\"FlashID\"); //--> </script>"; } else { $result = "<a href=\"javascript:void(0);\" onclick=\"window.open('".$this->links[$this->banner]."');\"> <img class=\"banner\" src=\"".$this->content[$this->banner]."\" alt=\"Banner\" /></a>"; } return $result; } /* * This method shows the random Banner. * @access public * @return void */ public function showBanner() { echo $this->generateBanner(); } } ?>
Nenhum comentário foi encontrado.
Automatizando digitação de códigos 2FA no browser
Resolver problemas de Internet
Como compartilhar a tela do Ubuntu com uma Smart TV (LG, Samsung, etc.)
Como converter imagens PNG/JPEG para SVG em linha de comando
Fez porcaria no teu repositório Git? Aprenda a restaurar uma versão anterior do seu código!
Restaurando Fontes de Download do Hydra no Linux
Atualizando "na marra" o YT-DLP quando começa a dar erro de downloads
Como instalar o WPS com interface e corretor ortográfico em PT-BR no Arch Linux
Java é uma linguagem de brinquedo? (1)
Linux não desliga a tela da TV nunca (4)
Mudar ícone do favorito "encerrar sessão" do Debian 12.10, c... (2)