Ir para conteúdo
  • 0

Pagina Videos com problema ao adicionar


brunonyyu

Pergunta

Olá, ao adicionar um video na pagina videos.php pelo painel do adm ele me volta o seguinte erro:

 

Linha com erro

 

$info = new SimpleXMLElement(file_get_contents("http://gdata.youtube.com/feeds/api/videos/$link"));

 

 

Citar

Warning: file_get_contents(http://gdata.youtube.com/feeds/api/videos/_uYFR1_EyZM) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.0 404 Not Found in C:\xampp\htdocs\03 - Genesis Nok\pages\videos.php on line 264

Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in C:\xampp\htdocs\03 - Genesis Nok\pages\videos.php:264 Stack trace: #0 C:\xampp\htdocs\03 - Genesis Nok\pages\videos.php(264): SimpleXMLElement->__construct('') #1 C:\xampp\htdocs\03 - Genesis Nok\system\load.page.php(7): include('C:\xampp\htdocs...') #2 C:\xampp\htdocs\03 - Genesis Nok\index.php(37): include_once('C:\xampp\htdocs...') #3 {main} thrown in C:\xampp\htdocs\03 - Genesis Nok\pages\videos.php on line 264

Codigo da pagina 

<?php


    # Variaveis globais.
    $action = $_GET["action"];
    $act = $_GET["act"];
    $db = $SQL;
    $accessLevel = ($logged && $account_logged->getPageAccess() > 0) ? TRUE : FALSE;
    
    # Checa se as tabelas existem.
    $res = $db->query("SHOW TABLES");
    if($res){
        foreach($res as $tabela){
            if($tabela[0] == "videos"){
                $videos = TRUE;
            }
            if($tabela[0] == "videos_categorias"){
                $videos_categorias = TRUE;
            }
            if($tabela[0] == "videos_comentarios"){
                $videos_comentarios = TRUE;
            }
        }
        if(!$videos){
            try{
                $db->exec("
                    CREATE TABLE `videos` (
                    `id` int(11) NOT NULL AUTO_INCREMENT,
                    `titulo` varchar(255) NOT NULL,
                    `descricao` text NOT NULL,
                    `categoria` int(11) NOT NULL,
                    `link` varchar(11) NOT NULL,
                    `ativo` int(1) NOT NULL DEFAULT '1',
                    PRIMARY KEY (`id`)
                    ) ENGINE=MyISAM DEFAULT CHARSET=latin1
                ");
            } catch (PDOException $e){
                $main_content = "Erro:<br />".$e->getMessage();
            }
        }
        
        if(!$videos_categorias){
            try{
                $db->exec("
                    CREATE TABLE `videos_categorias` (
                     `id` int(11) NOT NULL AUTO_INCREMENT,
                     `nome` varchar(255) NOT NULL,
                     PRIMARY KEY (`id`)
                    ) ENGINE=MyISAM DEFAULT CHARSET=latin1
                ");
            } catch (PDOException $e){
                $main_content = "Erro:<br />".$e->getMessage();
            }
        }
        
        if(!$videos_comentarios){
            try{
                $db->exec("
                    CREATE TABLE `videos_comentarios` (
                     `id` int(11) NOT NULL AUTO_INCREMENT,
                     `mensagem` text NOT NULL,
                     `character` varchar(255) NOT NULL,
                     `ip` varchar(15) NOT NULL,
                     `topico` int(11) NOT NULL,
                     `data` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
                     `ativo` int(1) NOT NULL DEFAULT '1',
                     PRIMARY KEY (`id`)
                    ) ENGINE=MyISAM DEFAULT CHARSET=latin1
                ");
            } catch (PDOException $e){
                $main_content = "Erro:<br />".$e->getMessage();
            }
        }
    }else{
        $main_content = "Erro ao adicionar tabelas ao banco de dados!";
    }
    # Se as tabelas existirem.
    if($videos && $videos_categorias && $videos_comentarios){
    # Se nao existir nenhuma acao.
        if(empty($action) && !isset($action)){
            $catFilter = (isset($_GET["cat"]) && !empty($_GET["cat"]) && is_numeric($_GET["cat"])) ? " AND `categoria` = ".$_GET["cat"]."" : "";
            $resul = $db->query("SELECT `id`,`titulo`,`link` FROM `videos` WHERE `ativo` = 1".$catFilter.";");
            $main_content  = "<div class=\"conteudo\" style=\"background-image:url(layouts/tibiacom/images/content/scroll.gif);\">";
            $main_content .= "<center><a href=\"?subtopic=videos\"><img src=\"images/youtube.png\"></a></center>";
            $main_content .= ($accessLevel) ? "<center><a href=\"?subtopic=videos&action=adminpanel\">Painel de Administra&ccedil;&atilde;o</a></center>" : "";
            if($resul->rowCount() <= 0){
                $mc = "<br /><center><table cellpadding=\"5\" cellspacing=\"1\"><tr><td width=\"560px\" bgcolor=\"#F1E0C6\"><center>Nenhum v&iacute;deo cadastrado!<br /></center></td></tr>";
                $div2 = "</div>";
            }
            $categorias = $db->query("SELECT `id`, `nome` FROM `videos_categorias` ORDER BY nome ASC;");
            if($categorias->rowCount() <= 0){
                $mcs = "Nenhuma categoria cadastrada!";
            }
            $tudos = "";
            $t = "";
            $i = 0;
            foreach($categorias as $categoria){
                $barra = ($i != 0) ? "|" : "";
                $space = ($i = count($categorias)-1) ? "" : " ";
                $adm = ($accessLevel) ? "<a href=\"?subtopic=videos&action=adminpanel&act=editcat&id=".$categoria["id"]."\"><img src=\"images/edit.png\" height=\"15\" weight=\"15\" /></a><a href=\"?subtopic=videos&action=adminpanel&act=delcat&id=".$categoria["id"]."\"><img src=\"images/del.png\" height=\"15\" weight=\"15\" /></a>" : "";
                $tudos .= "$barra $adm<a href=\"?subtopic=videos&cat=".$categoria["id"]."\">".html_entity_decode($categoria["nome"])."</a>$space";
                $t .= "$barra ".html_entity_decode($categoria["nome"])."$space";
                $i++;
            }
            $tx = (strlen($t) > 0) ? "<a href=\"?subtopic=videos\">Todas</a> |" : "";
            $tam = (strlen($t)*8 < 560) ? "560" : strlen($t)*8;
            $add = ($accessLevel) ? "<a href=\"?subtopic=videos&action=adminpanel&act=addcat\"><img src=\"images/add.png\" weight=\"15\" height=\"15\" /></a>" : "";
            $main_content .= "<center><table cellpadding=\"5\" cellspacing=\"1\"><tr><td width=\"".$tam ."px\" colspan=\"3\" bgcolor=\"#555555\"><font color=\"white\" size=\"3\"><b><center>Categorias</center></b></font></td></tr>";
            $main_content .= "<tr><td width=\"".$tam ."px\" bgcolor=\"#F1E0C6\"><b><center>$mcs$tx$tudos$add</center></b></td></tr>";
            # Loop para os resultados que vem da database com os videos.
            foreach($resul as $res){
                $id = (int)$res["id"];
                $titulo = html_entity_decode($res["titulo"]);
                if($accessLevel){
                    $editar = "<a href=\"?subtopic=videos&action=adminpanel&act=edit&id=$id\">Editar V&iacute;deo</a> &hArr;";
                    $deletar = '<a href="?subtopic=videos&action=adminpanel&act=del&id='.$id.'"> Deletar V&iacute;deo</a>';
                }
                $embed = '<iframe width="560" height="349" src="http://www.youtube.com/embed/'.$res["link"].'" frameborder="0" allowfullscreen></iframe>';
                $main_content .= "<br /><center><table cellpadding=\"5\" cellspacing=\"1\"><tr><td width=\"550px\" bgcolor=\"#D4C0A1\"><center><b><a href=\"?subtopic=videos&id=$id\">$titulo</a></b></center></td></tr>";
                $main_content .= "<br /><tr><td width=\"550px\" bgcolor=\"#F1E0C6\"><center>$embed $editar $deletar<br /></center></td></tr>";
                $div = "</div>";
            }
            $main_content .= "$mc</div>$div</table>".$div2."$div</center>";
            if(isset($_GET["id"])){
                $id = (int)$_GET['id'];
                $res = $db->query("SELECT `titulo`,`link`, `descricao` FROM `videos` WHERE `ativo` = 1 AND `id` = $id LIMIT 1;")->fetch();
                if(!$res){
                    $main_content = "V&iacute;deo inexistente!<br /><a href=\"?subtopic=videos\">&lArr; Voltar</a>";
                }else{
                    $resul = $db->query("SELECT `id`, `mensagem`, `character`, `data`, `ativo` FROM `videos_comentarios` WHERE `topico` = $id");
                    $resuls = $db->query("SELECT `id` FROM `videos_comentarios` WHERE `topico` = $id AND `ativo` = 1")->fetchAll();
                    $numM = $db->query("SELECT COUNT(`id`) FROM `videos_comentarios` WHERE `topico` = $id AND `ativo` = 1")->fetch();
                    $numM = ($numM[0] > 0) ? $numM[0]." " : "";
                    $s = ($numM > 1 || $numM == 0) ? "s" : "";
                    $main_content  = "<div class=\"conteudo\" style=\"background-image:url(layouts/tibiacom/images/content/scroll.gif);\">";
                    $main_content .= "<center><table cellpadding=\"5\" cellspacing=\"1\"><tr><td width=\"200px\" colspan=\"3\" bgcolor=\"#505050\"><font color=\"white\" size=\"2\"><center><b>".$res["titulo"]."</b></center></font></td></tr>";
                    $main_content .= "<tr><td width=\"500px\" bgcolor=\"#F1E0C6\"><center><iframe width=\"560\" height=\"349\" src=\"http://www.youtube.com/embed/".$res['link']."\" frameborder=\"0\" allowfullscreen></center></iframe></td></tr>";
                    if($res["descricao"]){
                        $main_content .= "<tr><td width=\"200px\" colspan=\"3\" bgcolor=\"#505050\"><font color=\"white\" size=\"2\"><center><b>Descri&ccedil;&atilde;o</b></font></td></tr>";
                        $main_content .= "<tr><td width=\"200px\" colspan=\"3\" bgcolor=\"#F1E0C6\"><center>".html_entity_decode($res["descricao"])."</center></td></tr>";
                    }
                    $main_content .= "<tr><td width=\"500px\" bgcolor=\"#505050\"><center><span style=\"color:white; font-weight:bold;\">".$numM."Coment&aacute;rio$s</span></center></td></tr>";
                    foreach($resul as $resz){
                        preg_match_all("/(\d{4})-(\d{2})-(\d{2})\ (\d{2}):(\d{2}):(\d{2})/", $resz["data"], $matches);
                        $ifAccess = ($accessLevel && $resz["ativo"]) ? " <a href=\"?subtopic=videos&action=adminpanel&act=delcom&id=".$resz["id"]."\"><img src=\"images/del.png\" height=\"15\" weight=\"15\" /></a>" : "";
                        $msg = preg_replace("/(.{100})/i", "$1<br />", html_entity_decode($resz["mensagem"]));
                        if($resz["ativo"]){
                            $main_content .= "<tr><td width=\"200px\" colspan=\"3\" bgcolor=\"#D4C0A5\"><center><b>[".$matches[3][0]."/".$matches[2][0]."] [<a href=\"?subtopic=characters&name=".urlencode($resz["character"])."\">".$resz["character"]."</a>] [".$matches[4][0].":".$matches[5][0]."]</b></center></td></tr>";
                            $main_content .= "<tr><td width=\"200px\" colspan=\"3\" bgcolor=\"#F1E0C6\"><font color=\"black\" size=\"2\"></span><center>".$msg."$ifAccess</center></font></td></tr>";
                        }elseif(!$resz["ativo"] && $accessLevel){
                            $existe = TRUE;
                            $main_content .= "<tr><td width=\"200px\" colspan=\"3\" bgcolor=\"#D4C0A5\"><center><b>[".$matches[3][0]."/".$matches[2][0]."] [<a href=\"?subtopic=characters&name=".urlencode($resz["character"])."\">".$resz["character"]."</a>] [".$matches[4][0].":".$matches[5][0]."]</b></center></td></tr>";
                            $main_content .= "<tr><td width=\"200px\" colspan=\"3\" bgcolor=\"#F1E0C6\"><font color=\"black\" size=\"2\"></span><center><strike>".$msg."</strike> <a href=\"?subtopic=videos&action=adminpanel&act=ativarcom&id=".$resz["id"]."\"><img src=\"images/ativar.png\" height=\"15\" weight=\"15\" /></a></center></font></td></tr>";
                        }
                    }
                    
                    if(!count($resuls)){
                        if($accessLevel && $existe){
                        
                        }else{
                            $main_content .= "<tr><td width=\"500px\" bgcolor=\"#D4C0A5\"><center>Nenhum coment&aacute;rio foi feito!</center></td></tr>";
                        }
                    }
                    $todosChars = "";
                    if($account_logged){
                        $accountPlayers = $account_logged->getPlayersList();
                        $accountPlayers->orderBy('name');
                        foreach($accountPlayers as $char){
                            $todosChars .= "<option value=\"".$char->getName()."\">".$char->getName()."</option>";
                        }
                        $temChar = (!$accountPlayers) ? TRUE : FALSE;
                    }
                    $ifLogged = "
                        <tr><td width=\"500px\" bgcolor=\"#505050\"><span style=\"color:white; font-weight:bold;\">
                            <form action=\"?subtopic=videos&id=$id\" method=\"post\">
                                <fieldset>
                                <legend>Deixe um coment&aacute;rio</legend><br />
                                <select style=\"border-radius:3px;-webkit-border-radius:3px;-moz-border-radius:3px;-o-border-radius:3px;-khtml-border-radius:3px;padding: 4px 2px; border: 1px solid #b2babe; background: #fff;\" name=\"character\">
                                $todosChars
                                </select> Character *<br />
                                <input type=\"hidden\" name=\"topico\" value=\"$id\" />
                                <textarea style=\"border-radius:3px;-webkit-border-radius:3px;-moz-border-radius:3px;-o-border-radius:3px;-khtml-border-radius:3px;padding: 4px 2px; border: 1px solid #b2babe; background: #fff;\" cols=\"70\" rows=\"13\" name=\"mensagem\"></textarea>
                                <input type=\"submit\" style=\"border-radius:3px;-webkit-border-radius:3px;-moz-border-radius:3px;-o-border-radius:3px;-khtml-border-radius:3px;padding: 4px 2px; border: 1px solid #b2babe; background: #fff;\" name=\"comment\" id=\"comment\" value=\"Comentar\" />
                                </fieldset>
                            </form>
                        </span></td></tr>
                    ";
                    $main_content .= ($logged && !$temChar) ? $ifLogged : "<tr><td width=\"500px\" bgcolor=\"#505050\"><center><span style=\"color:white; font-weight:bold;\">Voc&ecirc; deve estar logado e ter um character para comentar!</span></center></td></tr>";
                    $main_content .= "</div></div></table></div></center>";
                    
                    if(isset($_POST["comment"]) && !empty($_POST["comment"])){
                        $accountPlayers = $account_logged->getPlayersList();
                        foreach($accountPlayers as $char){
                            if($char->getName() == $_POST["character"]){
                                $character = TRUE;
                            }
                        }
                        if(strlen($_POST["mensagem"]) < 1){
                            $main_content = "Voc&ecirc; deve escrever uma mensagem para comentar!<br /><a href='?subtopic=videos&id=".$_POST["topico"]."'>&lArr; Voltar</a>";
                        }else{
                            if(!$character){
                                $main_content = "Voc&ecirc; deve escolher um character para comentar!<br /><a href='?subtopic=videos&id=".$_POST["topico"]."'>&lArr; Voltar</a>";
                            }else{
                                try{
                                    $reszs = $db->exec("INSERT INTO `videos_comentarios` (`mensagem`, `character`, `ip`, `topico`) VALUES (".$db->quote(htmlentities(strip_tags($_POST["mensagem"]))).", ".$db->quote(htmlentities($_POST["character"])).", ".$db->quote($_SERVER["REMOTE_ADDR"]).",".(int)$_POST["topico"].")");
                                } catch (PDOException $e){
                                    $main_content = "Erro:<br />".$e->getMessage();
                                }
                            
                                if($reszs){
                                    $main_content = "Coment&aacute;rio adicionado com sucesso!<br /><a href='?subtopic=videos&id=".$_POST["topico"]."'>&lArr; Voltar</a>";
                                }
                            }
                        }
                    }
                }
            }
        }
        
        if(isset($action) && !empty($action) && $action == "adminpanel" && $accessLevel){
            $main_content  = "<br /><div class=\"conteudo\" style=\"background-image:url(layouts/tibiacom/images/content/scroll.gif);\">";
            $main_content .= "<center><table cellpadding=\"5\" cellspacing=\"1\"><tr><td width=\"500px\" colspan=\"3\" bgcolor=\"#555555\"><font color=\"white\" size=\"3\"><b>Painel de Controle</b></font></td></tr><tr><td width=\"250px\" bgcolor=\"#F1E0C6\"><b>Op&ccedil;&otilde;es</b></td></tr>";
            $main_content .= "<tr><td width=\"250px\" bgcolor=\"#D4C0A1\"><a href=\"?subtopic=videos&action=adminpanel&act=addcat\">Adicionar Categoria</a></td></tr>";
            $main_content .= "<tr><td width=\"250px\" bgcolor=\"#D4C0A1\"><a href=\"?subtopic=videos&action=adminpanel&act=add\">Adicionar V&iacute;deo</a></td></tr>";
            $main_content .= "<tr><td width=\"250px\" bgcolor=\"#D4C0A1\"><a href=\"?subtopic=videos\">Editar V&iacute;deos</a></td></tr>";
            $main_content .= "<tr><td width=\"250px\" bgcolor=\"#D4C0A1\"><a href=\"?subtopic=videos\">Deletar V&iacute;deos</a></td></tr>";
            $main_content .= "</div></div></table></div></center>";
        }elseif(isset($action) && !empty($action) && $action == "adminpanel" && !$accessLevel){
            $main_content = "Voc&ecirc; n&atilde;o pode acessar esta &aacute;rea!";
        }
        
        if(isset($action) && !empty($action) && $action == "adminpanel" && $accessLevel && $act == "add"){
            $main_content  = "<fieldset>";
            $main_content .= "<legend>Adicionar V&iacute;deo</legend>";
            $main_content .= "<form id=\"add\" name=\"add\" method=\"post\" action=\"?subtopic=videos&action=adminpanel&act=add\">";
            $main_content .= "<p style=\"font-size: 1.8em;\">"; 
            $main_content .= "<label for=\"link\">Link do V&iacute;deo</label>";
            $main_content .= "<br /><input name=\"link\" type='text' id=\"link\" style=\"border-radius:3px;-webkit-border-radius:3px;-moz-border-radius:3px;-o-border-radius:3px;-khtml-border-radius:3px;padding: 4px 2px; border: 1px solid #b2babe; background: #fff;\" />";
            $main_content .= "</p>";
            $main_content .= "<p>";
            $main_content .= "<input type=\"submit\" style=\"border-radius:3px;-webkit-border-radius:3px;-moz-border-radius:3px;-o-border-radius:3px;-khtml-border-radius:3px;padding: 4px 2px; border: 1px solid #b2babe; background: #fff;\" name=\"button\" id=\"button\" value=\"Adicionar\" />";
            $main_content .= "</p>";
            $main_content .= "</form></fieldset>";
            
            if(isset($_POST["button"]) && !empty($_POST["button"]) && $accessLevel){
                $link = $_POST["link"];
                $res = $db->query("SELECT `id`,`nome` FROM `videos_categorias`;");
                $tudo = "";
                foreach($res as $cat_info){
                    $cat_tudo .= "<option name='".$cat_info["id"]."' value='".$cat_info["id"]."'>".html_entity_decode($cat_info["nome"])."</option>";
                }
                if(strlen($link) != 11){
                    preg_match_all("/([[:alnum:]|\_|\-]{11}?)/", $link, $matches);
                    if(count($matches[0]) > 1){
                        $link = "Alexx Pirado lol";
                    }else{
                        $link = $matches[0][0];
                    }
                }
                if(strlen($link) != 11){
                    $erro = "O link do v&iacute;deo est&aacute; errado ou incompleto.<br />Por favor, coloque a parte do link como o exemplo abaixo:<br />http://www.youtube.com/watch?v=<b><i>5abamRO41fE</i></b><br /><a href='?subtopic=videos&action=adminpanel&act=add'>&lArr; Voltar</a>";
                }
                if(empty($erro) && !isset($erro)){
                    $info = new SimpleXMLElement(file_get_contents("http://gdata.youtube.com/feeds/api/videos/$link"));
                    $titulo = $info->title;
                    $main_content  = "<br /><div class=\"conteudo\" style=\"background-image:url(layouts/tibiacom/images/content/scroll.gif);\">";
                    $main_content .= "<form action='?subtopic=videos&action=adminpanel&act=add' method='post'><input type='hidden' name='link' value='$link'>";
                    $main_content .= "<center><table cellpadding=\"5\" cellspacing=\"1\"><tr><td width=\"800px\" colspan=\"3\" bgcolor=\"#555555\"><font color=\"white\" size=\"3\"><b>Informa&ccedil;&otilde;es do V&iacute;deo</b></font></td></tr><tr><td width=\"250px\" bgcolor=\"#F1E0C6\"><b>Informa&ccedil;&atilde;o</b></td><td width=\"250px\" bgcolor=\"#F1E0C6\"><b>Valor</b></td></tr>";
                    $main_content .= "<tr><td width=\"300px\" bgcolor=\"#D4C0A1\"><b>Link</b><span style='color:red;'>*</span></td><td width=\"300px\" bgcolor=\"#D4C0A1\"><a href='http://www.youtube.com/watch?v=$link'>http://www.youtube.com/watch?v=$link</a></td></tr>";
                    $main_content .= "<tr><td width=\"250px\" bgcolor=\"#D4C0A1\"><b>T&iacute;tulo</b><span style='color:red;'>*</span></td><td width=\"250px\" bgcolor=\"#D4C0A1\"><input type='text' name='titulo' value='$titulo' size='".strlen($titulo)."'></td></tr>";
                    $main_content .= "<tr><td width=\"250px\" bgcolor=\"#D4C0A1\"><b>Descri&ccedil;&atilde;o</b></td><td width=\"250px\" bgcolor=\"#D4C0A1\"><textarea id=\"descricao\" name=\"descricao\" cols=\"40\" rows=\"10\" onfocus=\"if(this.innerHTML == 'Coloque uma descrição no vídeo!') this.innerHTML = '';\" onblur=\"if(this.innerHTML == '') this.innerHTML = 'Coloque uma descrição no vídeo!';\">Coloque uma descri&ccedil;&atilde;o no v&iacute;deo!</textarea></td></tr>";
                    $main_content .= "<tr><td width=\"250px\" bgcolor=\"#D4C0A1\"><b>Categoria</b><span style='color:red;'>*</span></td><td width=\"250px\" bgcolor=\"#D4C0A1\"><select name='categoria'><option value=\"0\">Nenhuma</option>$cat_tudo</select></td></tr>";
                    $main_content .= "</div></div></table>Os campos com <span style='color:red;margin:left;'>*</span> s&atilde;o obrigat&oacute;rios!<br /><input type='submit' style=\"border-radius:3px;-webkit-border-radius:3px;-moz-border-radius:3px;-o-border-radius:3px;-khtml-border-radius:3px;padding: 4px 2px; border: 1px solid #b2babe; background: #fff;\" name='avancar' value='Avan&ccedil;ar'></center></div>";
                }else{
                    $main_content = $erro;
                }
            }
            
            if(isset($_POST["avancar"]) && !empty($_POST["avancar"]) && $accessLevel){
                $link = $_POST["link"];
                $titulo = $_POST["titulo"];
                $categoria = htmlentities($_POST["categoria"]);
                $descricao = ($_POST["descricao"] != "Coloque uma descrição no vídeo!" && $_POST["descricao"] != "Coloque uma descri&ccedil;&atilde;o no v&iacute;deo!") ? nl2br($_POST["descricao"]) : NULL;
                if(!empty($link) && isset($link) & $link != 11){
                    if(!empty($titulo) && isset($titulo)){
                        try {
                            $res = $db->query("INSERT INTO `videos` (`titulo`, `descricao`, `categoria`, `link`) VALUES (".$db->quote(htmlentities($titulo)).", ".$db->quote(htmlentities($descricao)).", $categoria, ".$db->quote($link).")");
                        } catch (PDOException $e){
                            $main_content = "Erro ao adicionar o v&iacute;deo!<br />".$e->getMessage()."<br /><a href='?subtopic=videos&action=adminpanel&act=add'>&lArr; Voltar</a>";
                        }
                        if($res){
                            $main_content = "V&iacute;deo adicionado com sucesso!<br /><a href='?subtopic=videos'>&lArr; Voltar</a>";
                        }
                    }else{
                        $main_content = "O t&iacute;tulo n&atilde;o pode ficar em branco!<br /><a href='?subtopic=videos&action=adminpanel&act=add'>&lArr; Voltar</a>";
                    }
                }else{
                    $main_content = "Voc&ecirc; deve fornecer um link para adicionar um v&iacute;deo!<br /><a href='?subtopic=videos&action=adminpanel&act=add'>&lArr; Voltar</a>";
                }
            }
        }
        
        if(isset($action) && !empty($action) && $action == "adminpanel" && isset($act) && !empty($act) && $act == "del" && $accessLevel){
            $id = (int)$_GET["id"];
            $main_content = "Voc&ecirc; realmente deseja excluir o v&iacute;deo #$id?<br />
                <form action=\"?subtopic=videos&action=adminpanel&act=del\" method=\"post\">
                    <input type=\"hidden\" name=\"id\" value=\"$id\">
                    <input type=\"submit\" name=\"botao\" value=\"Concluir\" style=\"border-radius:3px;-webkit-border-radius:3px;-moz-border-radius:3px;-o-border-radius:3px;-khtml-border-radius:3px;padding: 4px 2px; border: 1px solid #b2babe; background: #fff;\">
                </form>
            ";
            if(isset($_POST["botao"]) && !empty($_POST["botao"])){
                $id = (int)$_POST["id"];
                if(!empty($id) && isset($id) && is_numeric($id)){
                    $id = (int)$id;
                    try {
                        $res = $db->exec("DELETE FROM `videos` WHERE `id` = $id");
                    } catch (PDOException $e){
                        $main_content = "Houve um erro ao deletar o v&iacute;deo n&uacute;mero $id.<br />".$e->getMessage()."<br /><a href='?subtopic=videos'>&lArr; Voltar</a>";
                    }
                    if($res){
                        $main_content = "V&iacute;deo #$id deletado com sucesso!<br /><a href='?subtopic=videos'>&lArr; Voltar</a>";
                    }
                }else{
                    $main_content = "V&iacute;deo n&atilde;o encontrado!<br /><a href='?subtopic=videos'>&lArr; Voltar</a>";
                }
            }
        }
        
        if(isset($action) && !empty($action) && $action == "adminpanel" && isset($act) && !empty($act) && $act == "edit" && $accessLevel){
            $res = $db->query("SELECT `id`,`titulo`,`link`,`descricao` FROM `videos` WHERE `ativo` = 1 AND `id` = ".$_GET["id"]." LIMIT 1;")->fetch();
            $resul = $db->query("SELECT `id`,`nome` FROM `videos_categorias`;");
            $resz = $db->query("SELECT `categoria` as `id` FROM `videos` WHERE `id` = ".$_GET["id"]." LIMIT 1;")->fetch();
            $cat_tudo = "";
            foreach($resul as $cat_info){
                if($cat_info["id"] == $resz["id"]){
                    $c = " selected=\"selected\"";
                }
                $cat_tudo .= "<option name='".$cat_info["id"]."' $c value='".$cat_info["id"]."'>".html_entity_decode($cat_info["nome"])."</option>";
            }
            $main_content  = "<fieldset>";
            $main_content .= "<legend>Editar V&iacute;deo</legend>";
            $main_content .= "
                <center>
                    <span style=\"font-size:1.8em; font-color:black;\"><strong>".html_entity_decode($res['titulo'])."</span></strong><hr>
                    <iframe width=\"560\" height=\"349\" src=\"http://www.youtube.com/embed/".$res["link"]."\" frameborder=\"0\" allowfullscreen></iframe><hr />
                    <br /><br />
                </center>
            ";
            $main_content .= "<form id=\"add\" name=\"add\" method=\"POST\" action=\"\">";
            $main_content .= "<p style=\"font-size: 1.8em;\">"; 
            $main_content .= "<label for=\"titulo\">T&iacute;tulo do V&iacute;deo</label>";
            $main_content .= "<br /><input name=\"titulo\" type=\"text\" id=\"titulo\" size=\"".strlen($res["link"])*3 ."\" style=\"border-radius:3px;-webkit-border-radius:3px;-moz-border-radius:3px;-o-border-radius:3px;-khtml-border-radius:3px;padding: 4px 2px; border: 1px solid #b2babe; background: #fff;\" value=\"".$res['titulo']."\"/>";
            $main_content .= "</p>";
            $main_content .= "<p style=\"font-size: 1.8em;\">"; 
            $main_content .= "<label for=\"link\">Link do V&iacute;deo</label>";
            $main_content .= "<br /><input name=\"link\" type='text' id=\"link\" size=\"25\" maxlength=\"11\" style=\"border-radius:3px;-webkit-border-radius:3px;-moz-border-radius:3px;-o-border-radius:3px;-khtml-border-radius:3px;padding: 4px 2px; border: 1px solid #b2babe; background: #fff;\" value=\"".$res['link']."\"/>";
            $main_content .= "<br /><br /><label for=\"descricao\">Descri&ccedil;&atilde;o do V&iacute;deo</label>";
            $main_content .= "<br /><textarea id=\"descricao\" name=\"descricao\" cols=\"40\" rows=\"10\" style=\"border-radius:3px;-webkit-border-radius:3px;-moz-border-radius:3px;-o-border-radius:3px;-khtml-border-radius:3px;padding: 4px 2px; border: 1px solid #b2babe; background: #fff;\">".html_entity_decode($res["descricao"])."</textarea>";
            $main_content .= "</p>";
            $main_content .= "<p style=\"font-size: 1.8em;\">"; 
            $main_content .= "Categoria<br /><select name='categoria'><option value=\"0\">Nenhuma</option>$cat_tudo</select>";
            $main_content .= "</p>";
            $main_content .= "<p>";
            $main_content .= "<input type=\"hidden\" name=\"id\" value=\"".$res["id"]."\"><input type=\"submit\" style=\"border-radius:3px;-webkit-border-radius:3px;-moz-border-radius:3px;-o-border-radius:3px;-khtml-border-radius:3px;padding: 4px 2px; border: 1px solid #b2babe; background: #fff;\" name=\"button\" id=\"button\" value=\"Editar\" />";
            $main_content .= "</p>";
            $main_content .= "</form></div></fieldset>";
            
            if(isset($_POST['button']) && !empty($_POST["button"])){
                if(($_POST["link"] != $res["link"]) || ($_POST["titulo"] != $res["titulo"]) || ($_POST["descricao"] != $res["descricao"]) || ($_POST["categoria"] != $resz["id"])){
                    try {
                        $res = $db->exec("UPDATE `videos` SET `link` = '".$_POST["link"]."', `titulo` = ".$db->quote(htmlentities($_POST["titulo"])).", `descricao` = ".$db->quote(htmlentities($_POST["descricao"])).", `categoria` = ".(int)$_POST["categoria"]." WHERE `id` = ".$_POST["id"].";");
                    } catch (PDOException $e){
                        $main_content = "Houve um erro ao tentar editar o v&iacute;deo #".$_POST["id"]."!<br />".$e->getMessage();
                    }
                    if($res){
                        $main_content = "V&iacute;deo #".$_POST["id"]." editado com sucesso!<br /><a href='?subtopic=videos'>&lArr; Voltar</a>";
                    }
                }else{
                    $main_content = "V&iacute;deo #".$_POST["id"]." editado com sucesso!<br /><a href='?subtopic=videos'>&lArr; Voltar</a>";
                }
            }
        }
        
        if(isset($action) && !empty($action) && $action == "adminpanel" && isset($act) && !empty($act) && $act == "addcat" && $accessLevel){
            $main_content = "
                <form action=\"?subtopic=videos&action=adminpanel&act=addcat\" method=\"post\">
                    <fieldset>
                        <legend>Adicionar Categoria</legend><br />
                        <label for=\"catNome\" style=\"margin-left:3px;\">Nome da Categoria</label><br />
                        <input type=\"text\" name=\"catNome\" style=\"border-radius:3px;-webkit-border-radius:3px;-moz-border-radius:3px;-o-border-radius:3px;-khtml-border-radius:3px;padding: 4px 2px; border: 1px solid #b2babe; background: #fff;\" /><br />
                        <input type=\"submit\" name=\"botao\" value=\"Adicionar\" style=\"border-radius:3px;-webkit-border-radius:3px;-moz-border-radius:3px;-o-border-radius:3px;-khtml-border-radius:3px;padding: 4px 2px; border: 1px solid #b2babe; background: #fff;\" />
                    </fieldset>
                </form>
            ";
            
            if(isset($_POST["botao"]) && !empty($_POST["botao"]) && $accessLevel){
                if(isset($_POST["catNome"]) && !empty($_POST["catNome"]) && strlen($_POST["catNome"]) > 0){
                    try {
                        $res = $db->exec("INSERT INTO `videos_categorias` (`nome`) VALUES (".$db->quote(htmlentities($_POST["catNome"])).");");
                    } catch (PDOException $e){
                        $main_content = "Houve um erro ao adicionar a categoria!<br />".$e->getMessage()."<br /><a href='?subtopic=videos'>&lArr; Voltar</a>";
                    }
                    if($res) $main_content = "Categoria adicionada com sucesso!<br /><a href='?subtopic=videos'>&lArr; Voltar</a>";
                }else{
                    $main_content = "O campo <b>Nome da Categoria</b> &eacute; obrigat&oacute;rio!<br /><a href='?subtopic=videos&action=adminpanel&act=addcat'>&lArr; Voltar</a>";
                }
            }
        }
        
        if(isset($action) && !empty($action) && $action == "adminpanel" && isset($act) && !empty($act) && $act == "delcat" && $accessLevel){
            if(!isset($_GET["id"]) && empty($_GET["id"]) & $accessLevel){
                $main_content = "Voc&ecirc; deve definir uma categoria para deletar!";
            }else{
                $res = $db->query("SELECT `id`, `nome` FROM `videos_categorias` WHERE `id` = ".$_GET["id"]." LIMIT 1;")->fetch();
                $main_content = "
                    <form action=\"?subtopic=videos&action=adminpanel&act=delcat&id=".$res["id"]."\" method=\"post\">
                        <fieldset>
                            <legend>Deletar Categoria</legend><br />
                            <span style=\"margin-left:3px;\">Voc&ecirc; realmente deseja deletar a categoria <b>".$res["nome"]."</b>?</span><br />
                            <input type=\"hidden\" name=\"catId\" value=\"".$res["id"]."\" />
                            <input type=\"hidden\" name=\"catNome\" value=\"".$res["nome"]."\" />
                            <input type=\"submit\" name=\"botao\" value=\"Deletar Categoria\" style=\"border-radius:3px;-webkit-border-radius:3px;-moz-border-radius:3px;-o-border-radius:3px;-khtml-border-radius:3px;padding: 4px 2px; border: 1px solid #b2babe; background: #fff;\" />
                            <input type=\"submit\" name=\"botao2\" value=\"Deletar categoria e v&iacute;deos desta categoria\" style=\"border-radius:3px;-webkit-border-radius:3px;-moz-border-radius:3px;-o-border-radius:3px;-khtml-border-radius:3px;padding: 4px 2px; border: 1px solid #b2babe; background: #fff;\" />
                        </fieldset>
                    </form>
                ";
                
                if(isset($_POST["botao"]) && !empty($_POST["botao"]) && $accessLevel){
                    try {
                        $res = $db->exec("DELETE FROM `videos_categorias` WHERE `id` = ".$_POST["catId"].";");
                        $res = $db->exec("UPDATE `videos` SET `categoria` = 0 WHERE `categoria` = ".$_POST["catId"].";");
                    } catch (PDOException $e) {
                        $main_content = "Houve um erro ao deletar a categoria ".$_POST["catNome"]."!<br />".$e->getMessage();
                    }
                    
                    if($res){
                        $main_content = "Categoria deletada com sucesso!<br /><a href='?subtopic=videos'>&lArr; Voltar</a>";
                    }
                }
                
                if(isset($_POST["botao2"]) && !empty($_POST["botao2"]) && $accessLevel){
                    try {
                        $res = $db->exec("DELETE FROM `videos_categorias` WHERE `id` = ".$_POST["catId"].";");
                        $resul = $db->exec("DELETE FROM `videos` WHERE `categoria` = ".$_POST["catId"].";");
                    } catch (PDOException $e) {
                        $main_content = "Houve um erro ao deletar a categoria ".$_POST["catNome"]."!<br />".$e->getMessage();
                    }
                    
                    if($res && $resul){
                        $main_content = "Categoria deletada com sucesso!<br /><a href='?subtopic=videos'>&lArr; Voltar</a>";
                    }
                }
            }
        }
        
        if(isset($action) && !empty($action) && $action == "adminpanel" && isset($act) && !empty($act) && $act == "editcat" && $accessLevel){
            if(!isset($_GET["id"]) && empty($_GET["id"]) & $accessLevel){
                $main_content = "Voc&ecirc; deve definir uma categoria para deletar!";
            }else{
                $res = $db->query("SELECT `id`, `nome` FROM `videos_categorias` WHERE `id` = ".$_GET["id"]." LIMIT 1;")->fetch();
                $main_content = "
                    <form action=\"?subtopic=videos&action=adminpanel&act=editcat&id=".$res["id"]."\" method=\"post\">
                        <fieldset>
                            <legend>Editar Categoria</legend><br />
                            <p style=\"font-size: 1.8em;\">
                            <label for=\"catNome\" style=\"margin-left:3px;\">Nome da Categoria</label><br /></p>
                            <input type=\"hidden\" name=\"nome\" value=\"".$res["nome"]."\" />
                            <input type=\"hidden\" name=\"id\" value=\"".$res["id"]."\" />
                            <input type=\"text\" name=\"catNome\" style=\"border-radius:3px;-webkit-border-radius:3px;-moz-border-radius:3px;-o-border-radius:3px;-khtml-border-radius:3px;padding: 4px 2px; border: 1px solid #b2babe; background: #fff;\" value=\"".$res["nome"]."\" /><br />
                            <br /><input type=\"submit\" name=\"botao\" value=\"Editar Categoria\" style=\"border-radius:3px;-webkit-border-radius:3px;-moz-border-radius:3px;-o-border-radius:3px;-khtml-border-radius:3px;padding: 4px 2px; border: 1px solid #b2babe; background: #fff;\" />
                        </fieldset>
                    </form>
                ";
                
                if(isset($_POST["botao"]) && !empty($_POST["botao"]) && $accessLevel){
                    try {
                        $res = $db->exec("UPDATE `videos_categorias` SET `nome` = ".$db->quote(htmlentities($_POST["catNome"]))." WHERE `id` = ".$_POST["id"].";");
                    } catch (PDOException $e) {
                        $main_content = "Houve um erro ao editar a categoria ".$_POST["nome"]."!<br />".$e->getMessage();
                    }
                    
                    if($res){
                        $main_content = "Categoria editada com sucesso!<br /><a href='?subtopic=videos'>&lArr; Voltar</a>";
                    }
                }
            }
        }
        
        if(isset($action) && !empty($action) && $action == "adminpanel" && isset($act) && !empty($act) && $act == "delcom" && $accessLevel){
            if(!isset($_GET["id"]) && empty($_GET["id"]) & $accessLevel){
                $main_content = "Voc&ecirc; deve escolher um coment&aacute;rio para deletar!";
            }else{
                $res = $db->query("SELECT `id`, `mensagem`, `topico` FROM `videos_comentarios` WHERE `id` = ".(int)$_GET["id"]." LIMIT 1;")->fetch();
                $main_content = "
                    <form action=\"?subtopic=videos&action=adminpanel&act=delcom&id=".$res["id"]."\" method=\"post\">
                        <fieldset>
                            <legend>Deletar Coment&aacute;rio</legend><br />
                            <span style=\"margin-left:3px;\">Voc&ecirc; realmente deseja deletar o coment&aacute;rio <b>".html_entity_decode($res["mensagem"])."</b>?</span><br />
                            <input type=\"hidden\" name=\"comId\" value=\"".$res["id"]."\" />
                            <input type=\"hidden\" name=\"comTopico\" value=\"".$res["topico"]."\" />
                            <input type=\"hidden\" name=\"comCom\" value=\"".html_entity_decode($res["mensagem"])."\" />
                            <input type=\"submit\" name=\"botao\" value=\"Deletar Coment&aacute;rio\" style=\"border-radius:3px;-webkit-border-radius:3px;-moz-border-radius:3px;-o-border-radius:3px;-khtml-border-radius:3px;padding: 4px 2px; border: 1px solid #b2babe; background: #fff;\" />
                        </fieldset>
                    </form>
                ";
                
                if(isset($_POST["botao"]) && !empty($_POST["botao"]) && $accessLevel){
                    try {
                        $res = $db->exec("UPDATE `videos_comentarios` SET `ativo` = 0 WHERE `id` = ".(int)$_POST["comId"]." AND `ativo` = 1;");
                    } catch (PDOException $e) {
                        $main_content = "Houve um erro ao deletar o coment&aacute;rio ".$_POST["comCom"]."!<br />".$e->getMessage();
                    }
                    
                    if($res){
                        $main_content = "Coment&aacute;rio deletado com sucesso!<br /><a href='?subtopic=videos&id=".(int)$_POST["comTopico"]."'>&lArr; Voltar</a>";
                    }
                }
            }
        }
        
        if(isset($action) && !empty($action) && $action == "adminpanel" && isset($act) && !empty($act) && $act == "ativarcom" && $accessLevel){
            if(!isset($_GET["id"]) && empty($_GET["id"]) & $accessLevel){
                $main_content = "Voc&ecirc; deve escolher um coment&aacute;rio para restaurar!";
            }else{
                $res = $db->query("SELECT `id`, `mensagem`, `topico` FROM `videos_comentarios` WHERE `id` = ".(int)$_GET["id"]." LIMIT 1;")->fetch();
                $main_content = "
                    <form action=\"?subtopic=videos&action=adminpanel&act=ativarcom&id=".$res["id"]."\" method=\"post\">
                        <fieldset>
                            <legend>Restaurar Coment&aacute;rio</legend><br />
                            <span style=\"margin-left:3px;\">Voc&ecirc; realmente deseja restaurar o coment&aacute;rio <b>".html_entity_decode($res["mensagem"])."</b>?</span><br />
                            <input type=\"hidden\" name=\"comId\" value=\"".$res["id"]."\" />
                            <input type=\"hidden\" name=\"comTopico\" value=\"".$res["topico"]."\" />
                            <input type=\"hidden\" name=\"comCom\" value=\"".html_entity_decode($res["mensagem"])."\" />
                            <input type=\"submit\" name=\"botao\" value=\"Restaurar Coment&aacute;rio\" style=\"border-radius:3px;-webkit-border-radius:3px;-moz-border-radius:3px;-o-border-radius:3px;-khtml-border-radius:3px;padding: 4px 2px; border: 1px solid #b2babe; background: #fff;\" />
                        </fieldset>
                    </form>
                ";
                
                if(isset($_POST["botao"]) && !empty($_POST["botao"]) && $accessLevel){
                    try {
                        $res = $db->exec("UPDATE `videos_comentarios` SET `ativo` = 1 WHERE `id` = ".(int)$_POST["comId"]." AND `ativo` = 0;");
                    } catch (PDOException $e) {
                        $main_content = "Houve um erro ao restaurar o coment&aacute;rio ".$_POST["comCom"]."!<br />".$e->getMessage();
                    }
                    
                    if($res){
                        $main_content = "Coment&aacute;rio restaurado com sucesso!<br /><a href='?subtopic=videos&id=".(int)$_POST["comTopico"]."'>&lArr; Voltar</a>";
                    }
                }
            }
        }
    }
    
?>

 

Editado por brunonyyu
Link para o comentário
Compartilhar em outros sites

3 respostass a esta questão

Posts Recomendados

  • 1

Olá, boa tarde, tudo bem?

Se não me falha a memoria, essa api ta desativada(isso se não me falha a memoria).
No caso, teria que usar a api da google, pois eles tem uma que faz a mesma coisa desse link.

1 hora atrás, brunonyyu disse:

$info = new SimpleXMLElement(file_get_contents("http://gdata.youtube.com/feeds/api/videos/$link"));

 

Link para o comentário
Compartilhar em outros sites

  • 0
8 horas atrás, Akzs disse:

Olá, boa tarde, tudo bem?

Se não me falha a memoria, essa api ta desativada(isso se não me falha a memoria).
No caso, teria que usar a api da google, pois eles tem uma que faz a mesma coisa desse link.

Obrigado irmao, vou olhar uma outra api para usar e testar

Link para o comentário
Compartilhar em outros sites

  • Quem Está Navegando   0 membros estão online

    • Nenhum usuário registrado visualizando esta página.
×
×
  • Criar Novo...