Fresh Paste
?
Must select a language or plain text.
Language (Highlight):
Plain Text / Other
PHP
MySQL
Javascript
Python
Ruby
-----------------------
Actionscript
Ada
Apache Config
AppleScript
Assembly
ASP
Bash
C
Cold Fusion
C++
C#
CSS
D
Delphi
UNIX Diff
Eiffel
Fortran
HTML 4 Strict
Ini
Java
Java5
LaTeX
LISP
Lua
MATLAB
Perl
QBasic / QuickBASIC
Robots
SQL
TCL
Visual BASIC
VB.NET
Winbatch
XML
Description (Optional):
Code:
<? php /** SimpleNews 2.0.1 - Zumbie edition @date April, 2008 @description Last release of SimpleNews, which is compatible with Joomla! 1.5. I have no intentions to mantain this software anymore. @author Matheus Mendes (bigodines ["at"] gmail.com) @package simpleNews @license GPL */ /** NOTE THAT THIS FILE ALONE DOES NOTHING. You must replace the original SimpleNews.php inside your simpleNews' directory as this is just a patch. */ /** Main Class - Please configure according to your system. */ class SimpleNews { /** Database Configuration */ /** host @string */ var $host = "localhost"; //$mosConfig_host; /** database name @string */ var $db = "my_db"; //$mosConfig_db; /** database user @string */ var $dbuser = "my_user";// $mosConfig_user; /** database password @string */ var $dbpass = "my_pass"; /** table prefix @string */ var $prefix = "jos_"; /** group id that will be the the minimum required to post news. @int */ var $gid = 1; /** SimpleNews Configuration */ /** width of the resized image (in pixels) - leave null and the image will be proportional to the Height @int */ var $mainImageWidth = 500; /** height of the resized image (in pixels) - leave null and the image will be proportional to the Width @int */ var $mainImageHeight = null; /** thumb width */ var $thumbImageWidth = 150; /** thumb height */ var $thumbImageHeight = null; /** where is your joomla installation? (copy and paste the content of $mosConfig_live_site) @string */ var $liveSite = 'http://localhost/'; /** the pathway where store the images uploaded by SimpleNews (e.g.: joomla's stories directory) *** PLEASE INCLUDE THE FINAL SLASH ('/') *** @string */ var $imagePath = "/home/me/public_html/images/stories/"; /** the url to access the images uploaded by SimpleNews *** PLEASE INCLUDE THE FINAL SLASH ('/') *** @string */ var $imageURL = "http://localhost/images/stories/"; /** inside which section will the user be allowed to insert content? ( 0 = all ) @int */ var $mySection = 0; /** inside which category will the user be allowed to insert content? ( 0 = all ) @int */ var $myCategory = 0; //0; /** new items start published? @bool */ var $published = true; /** new items will be shown on frontpage? @bool */ var $frontpage = true; /** please select the language @string */ var $language = "brazilian_portuguese"; // default: 'english' /** use a WYSIWYG editor? (FCKeditor) @bool */ var $editor = false; /** this array will store all languages installed on joomlafish @private @array */ var $languages = array(); /** this var stores the user id. @private @int */ var $uid = null; /** this var will be set automatically and will store there default language. */ var $firstLanguage = null; /******************************************** DONE! SimpleNews is configurated. ********************************************/ /** Constructor */ function SimpleNews( ) { if (!file_exists("languages/" . $this->language . ".php") ) { die("Cannot find the language file. Check your configuration please"); } require_once("languages/" . $this->language . ".php"); require_once("View.php"); //$this->logged = $_SESSION['logged']; } /** this is the function that will handle the screens. Basically, simpleNews has 5 screens: Three main screens: - The login screen (only if you use it not as a component) - The Main Form screen - A 'thank you' screen And two screens related to image upload: - The main form for image uploads - A thank you / error message. The image form is the same for both thumbnails and the main image. Feel free to customize these screens the way you want (you may edit View.php for that) *** ADDED: PREVIEW FEATURE *** */ function show($opt = null, $msg = null, $extra=null) { $screen = new SimpleNewsHTML; if ($opt != "preview") $screen->Start($this->mySection, $this->myCategory); /* default... show the login screen */ if ($opt == "login" || $this->logged == false || $opt == null) { $screen->showLogin($msg); } /* main form */ if ($opt == "form") { $screen->showForm($msg, $this->firstLanguage, $this->editor, $this->mySection, $this->myCategory, $this->prefix); } if ($opt == "imgForm") { $screen->showImgForm($msg, $extra); } if ($opt == "imgSuccess") { $screen->showImgSuccess(); } /* final screen: success */ if ($opt == "success") { $screen->showSuccess($msg); } if ($opt == "preview") { // to fix : make this thing works dynamically :P /* the parameter is the URL of the site. */ $screen->preview($this->liveSite); } if ($opt != "preview") $screen->footer(); } /** Simple function that validates a user @param string username @param string password @return boolean */ function validate($usr, $pass) { if (!$this->link) { $this->init_db(); } $usr = mysql_real_escape_string($usr); $table = $this->prefix . 'users'; /* fix to work with salted passwords!! */ $query = "SELECT id, name, username, password, usertype, block, gid" . "\n FROM $table" . "\n WHERE username = '$usr'"; $tmp = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_assoc($tmp); list($hash, $salt) = explode(':', $row['password']); $cryptpass = md5($pass.$salt); if ($hash != $cryptpass) { return false; // didn't match! } else { $this->uid = mysql_result($tmp,0,0); return true; } } /** Initiates a connection with the database... a bit amateur, but it works. @private */ function init_db() { $this->link = mysql_connect($this->host, $this->dbuser, $this->dbpass) or die(mysql_error()); mysql_select_db($this->db, $this->link) or die(mysql_error()); // @mysql_query("SET NAMES 'utf8'", $this->link); // uncomment this line to use with UTF-8 databases } /** Detects if Joomlafish is installed @return bool */ function detectJoomlafish() { if(!$this->link) { $this->init_db(); } /* looking for joomlafish tables */ $res = mysql_query("SHOW TABLES FROM ".$this->db ." LIKE '%_mbf%'"); $cnt = mysql_num_rows($res); // flag :P if ($cnt == 0) return false; /* populating language's array (I really hope alex doesn't change the name of mambelfish tables :D) */ $res = mysql_query("SELECT id, name, ordering FROM `".$this->prefix."mbf_language` ORDER BY ordering ,id LIMIT 0,20") or die( mysql_error() ); while( $row = mysql_fetch_array($res) ) { $this->addLanguage($row['id'], $row['name']); } $this->firstLanguage = $this->getFirstLanguage(); return true; } function addLanguage($id, $name) { $this->languages[$id] = $name; } function getLanguages() { return $this->languages; } function getFirstLanguage() { reset($this->languages); $firstLanguageId = key($this->languages); // do we need this second reset? reset($this->languages); return $firstLanguageId; } /** Small function that populates the combobox with all categories from the given section */ function loadCategories($sec) { if (!$this->link) { $this->init_db(); } $sql = "SELECT DISTINCT title, id FROM ".$this->prefix."categories WHERE section = '$sec' "; $result = mysql_query($sql); $num_rows = mysql_num_rows($result); ?> <html> <head> <? //echo ' <meta http-equiv="content-type" content="text/html; charset=UTF-8"> '; // uncomment this line to use with a utf-8 database ?> <script language="JavaScript"> <?php if ($num_rows > 0) { while ($row = mysql_fetch_row($result)) { print "window.parent.adiciona('".addslashes($row[0])."','".addslashes($row[1])."','categoria');\n"; } } ?> </script> </head> <body> </body> </html> <? } /* the same from version 1.2 :P it may sucks, but it works */ function uploadImage() { require_once("ImageResizeFactory.php"); $maxSize = "1048576"; // 1MB upload size of the file. if ($_POST['extra'] == "main") { $width = $this->mainImageWidth; $height = $this->mainImageHeight; } else { $width = $this->thumbImageWidth; $height = $this->thumbImageHeight; } $path_imagens = $this->imagePath; $allowedExtensions = array("jpg", "JPG", "JPEG", "png", "PNG"); $uploadedFileName = $_FILES['filename']['name']; if($_FILES['filename']['size'] > $maxSize) { $error = _ERR_IMG_FILE_SIZE; } $extension = pathinfo($_FILES['filename']['name']); $extension = $extension["extension"]; foreach($allowedExtensions as $key=>$ext) { if(strcasecmp($ext, $extension) == 0) { $boolValidExt = true; break; } } if($boolValidExt) { if(empty($error)) { if(is_uploaded_file($_FILES['filename']['tmp_name'])) { copy($_FILES['filename']['tmp_name'], $path_imagens . $uploadedFileName); } } } else { $error = _ERR_IMG_FILE_EXTENSION; echo $error; exit; } if(empty($error)) { $srcFile = $path_imagens . $uploadedFileName; $destFile = $path_imagens . "sn_" . time() . $uploadedFileName; // getting the image size (width and height) // $arrImgSize = getimagesize($srcFile); // Instantiate the correct object depending on type of image i.e jpg or png $objResize = ImageResizeFactory::getInstanceOf($srcFile, $destFile, $width, $height); // Call the method to resize the image $objResize->getResizedImage(); unlink($srcFile); unset($objResize); //header("Location:" . $destFile); // debug ?> <html> <head> <title><?php echo _PAGE_TITLE ?></title> <link href="layout/css/css.css" rel="stylesheet" type="text/css"> <? // echo ' <meta http-equiv="content-type" content="text/html; charset=UTF-8"> '; // uncomment this line to use with a utf-8 database ?> </head> <? if ($_POST['extra'] == 'main') { ?> <body onload="window.opener.setImg('<?=$destFile; ?>');"> <table width="80%" border="0" align="center" cellpadding="5" cellspacing="0" class="contorno"> <tr> <td bgcolor="#DDDDDD"><div align="center"><? echo _IMG_SUCCESS ?></div></td> </tr> <tr> <td bgcolor="#DDDDDD"><a href="#" onClick="javascript:window.close();"><? echo _CLOSE ?></a> </td> </tr> </table></body></html> <? } else { ?> <body onload="window.opener.setThumb('<?=$destFile; ?>');"> <table width="80%" border="0" align="center" cellpadding="5" cellspacing="0" class="contorno"> <tr> <td bgcolor="#DDDDDD"><div align="center"><? echo _IMG_SUCCESS ?></div></td> </tr> <tr> <td bgcolor="#DDDDDD"><a href="#" onClick="javascript:window.close();"><? echo _CLOSE ?></a> </td> </tr> </table></body></html> <? } exit; } else $this->show("imgForm", $error, $type); } /** attempt to get rid of the quotes problem */ function workQuotes($sql) { $sql = trim( $sql ); $prefix = $this->prefix; $escaped = false; $quoteChar = ''; $n = strlen( $sql ); $startPos = 0; $literal = ''; while ($startPos < $n) { $ip = strpos($sql, $prefix, $startPos); if ($ip === false) { break; } $j = strpos( $sql, "'", $startPos ); $k = strpos( $sql, '"', $startPos ); if (($k !== FALSE) && (($k < $j) || ($j === FALSE))) { $quoteChar = '"'; $j = $k; } else { $quoteChar = "'"; } if ($j === false) { $j = $n; } $literal .= str_replace( $prefix, $this->prefix, substr( $sql, $startPos, $j - $startPos ) ); $startPos = $j; $j = $startPos + 1; if ($j >= $n) { break; } // quote comes first, find end of quote while (TRUE) { $k = strpos( $sql, $quoteChar, $j ); $escaped = false; if ($k === false) { break; } $l = $k - 1; while ($l >= 0 && $sql{$l} == '\\') { $l--; $escaped = !$escaped; } if ($escaped) { $j = $k+1; continue; } break; } if ($k === FALSE) { // error in the query - no end quote; ignore it break; } $literal .= substr( $sql, $startPos, $k - $startPos + 1 ); $startPos = $k+1; } if ($startPos < $n) { $literal .= substr( $sql, $startPos, $n - $startPos ); } return $literal; } /** add a new content item into your joomla/mambo website. */ function insert() { if ( empty($_POST) ) { die(_ERR_NO_INFO); } if(!$this->link) { $this->init_db(); } /* as the language forms were built dynamically, we need to separate the prefix of the field and the id of the language */ $i=0; $vet_lang = ""; $vet_var = ""; foreach($_POST as $k => $v){ $$k = $v; // echo "<strong>$$k</strong> = $v<br> "; // debug if (is_numeric(substr($k,-1))){ // verifica último digito para saber o idioma if ($$k != NULL){ // testa se a variável de outro idioma não está vazia $arr = explode("_", $k); $vet_lang[$i] = $arr[1]; // armazena no vetor de linguagens o número dos idiomas $vet_var[$i] = $k; // armazena o nome das variáveis de outro idioma $i++; } // echo "is numeric<br>Vet = $vet_lang[$i]<br>arr[0] = $arr[0]<br>arr[1] = $arr[1]<hr>e k vale = $k e kk vale $$k<hr>"; // debug } } if (!$olho || !$titulo) die( _ERR_PREENCHA_TUDO ); if (!$categoria || !$secao) die( _ERR_CATEGORIA_SECAO ); if ($thumbImage && $thumbImage != _NENHUMA_IMAGEM) { $thumbImage = str_replace($this->imagePath, $this->imageURL, $thumbImage); } if ($imagem && $imagem != _NENHUMA_IMAGEM) { $imagem = str_replace($this->imagePath, $this->imageURL, $imagem); $texto = "<img src=\"$imagem\" align=\"center\" vspace=\"5\"><br />" . $texto; } $olho .= "\n"; $olho = mysql_real_escape_string(nl2br($olho)); $texto = '<p>'.mysql_real_escape_string(nl2br($texto)).'</p>'; $titulo = mysql_real_escape_string($titulo); $arr_date = explode("-",$dt_publicacao); if (count($arr_date) > 1) $dt_publicacao = $arr_date[2]."-".$arr_date[1]."-".$arr_date[0] . " 00:00:00"; ///// / / / / / / / / / / aqui vai o foreach /////////////////// foreach( $categoria as $k => $v ) { // converting from boolean to integer. Just to avoid any trouble with the current system $publicado = ($this->published == true) ? 1 : 0; $sql_insere = 'INSERT INTO '.$this->prefix.'content (`title`, `title_alias`, `introtext`, `fulltext`, `state`, `created` , `created_by` , `sectionid`, `catid`, `images`, `publish_up`, `publish_down`)'; $sql_insere .= 'VALUES (\''.$titulo.'\', \''.$titulo.'\', \''.$olho.'\', \''.$texto.'\', \''.$publicado.'\','; $sql_insere .= $dt_publicacao ? '\''.$dt_publicacao.'\'' : 'NOW()'; $sql_insere .= ', \''.$this->uid.'\' ,\''.$secao.'\', \''.$v.'\', \''.$imagem.'\','; $sql_insere .= $dt_publicacao ? '\''.$dt_publicacao.'\'' : 'NOW()'; $sql_insere .= ", "; $sql_insere .= ($dt_vigencia && $dt_vigencia > 0) ? 'date_add(now(), interval '.$dt_vigencia.' day) ' : '\'\''; $sql_insere .= ')'; //echo $sql_insere; // debug //$sql_insere = $this->workQuotes($sql_insere); $insere = mysql_query($sql_insere) or die('2:'._ERR_INESPERADO .mysql_error()); // last item... $ultimo_id = mysql_insert_id(); //echo "ultimo id = $ultimo_id<br>"; // configuração para inserir na página principal. if ($this->frontpage == true) { $ultimo = $ultimo_id; $res = mysql_query("SELECT MAX(ordering) FROM ".$this->prefix."content_frontpage"); $ordem = mysql_result($res,0); if ($ordem == 0) $ordem = 1; if ($ordem > 0 && $ultimo > 0) { $ordem++; mysql_query("INSERT INTO ".$this->prefix."content_frontpage (content_id, ordering) VALUES ('$ultimo', '$ordem')") or die("fudeu nego. chama o lambari"); } } } // foreach - categories /* tests if there are items in other languages to be insert. */ if ($vet_var != NULL){ foreach($vet_var as $k => $v){ $var = explode("_",$k); $k = $v; //echo "$k = $v e k $$k e v ".$$v."<br>"; // debug $mega_id = explode("_",$k); $mega_id = $mega_id[1]; // language id if (strstr($k, "olho") != false){ $campo = "introtext"; $valor = $$v . '<br />'; $original = $olho; } else if(strstr($k, "titulo") != false){ $campo = "title"; $valor = $$v; $original = $titulo; } else if(strstr($k, "texto") != false){ $campo = "fulltext"; $valor = $$v; if ($imagem && $imagem != _NENHUMA_IMAGEM) { $imagem = str_replace($path_imagens, $url_imagens, $imagem); $valor = "<img src=\"$imagem\" align=\"center\"><br />" . $valor; } $original = $texto; } //$valor = $$v; // gambiarra não né fio! $sql = "INSERT INTO ".$this->prefix."mbf_content (language_id, reference_id, reference_table, reference_field, value, original_value, modified, modified_by) VALUES ('$mega_id', '$ultimo_id', 'content', '$campo', '$valor', '$original', now(), '$row[0]')"; $gurda = mysql_query($sql) or die ("jah era".mysql_error()); } }// fim teste $vet_var $this->show("success"); } /* Insert with Joomlafish */ /* Developer note: guys, sorry about this portuguese comments/varnames. This snippet was based on an older version of simpleNews and I didn't have time to document it. :) */ function insertAll() { if(!$this->link) { $this->init_db(); } if (!$this->firstLanguage) { } $i=0; $vet_lang = ""; $vet_var = ""; foreach($_POST as $k => $v){ $$k = $v; // echo "<strong>$$k</strong> = $v<br> "; if (is_numeric(substr($k,-1))){ // verifica último digito para saber o idioma if ($$k != NULL){ // testa se a variável de outro idioma não está vazia $arr = explode("_", $k); $vet_lang[$i] = $arr[1]; // armazena no vetor de linguagens o número dos idiomas $vet_var[$i] = $k; // armazena o nome das variáveis de outro idioma $i++; } // echo "is numeric<br>Vet = $vet_lang[$i]<br>arr[0] = $arr[0]<br>arr[1] = $arr[1]<hr>e k vale = $k e kk vale $$k<hr>"; } } $senha = md5($senha); if (!$olho || !$titulo) die( sprintf(_ERR_PREENCHA_TUDO,'$dt_vigencia', '$olho', '$texto', '$titulo', '$thumbImage', '$imagem') ); if (!$categoria || !$secao) die( _ERR_CATEGORIA_SECAO ); // user validation $sql_login = "SELECT id FROM ".$this->prefix."users WHERE username = '$login' AND password = '$senha'"; $query_login = mysql_query($sql_login) or die (mysql_error()); if(($row = mysql_fetch_array($query_login)) == "") { echo _ERR_LOGIN; echo '<a href="index.php"><h2>' . _VOLTAR . '<h2></a> '; } else { // logged in! if ($imagem && $imagem != _NENHUMA_IMAGEM) { $imagem = str_replace($path_imagens, $url_imagens, $imagem); $texto = "<img src=\"$imagem\" align=\"center\"><br />" . $texto; } $olho .= "\n"; $olho = nl2br($olho); $texto = nl2br($texto); $arr_data = explode ("-",$dt_publicacao); $dt_publicacao = "$arr_data[2]"."-"."$arr_data[1]"."-"."$arr_data[0]"; $sql_insere = "INSERT INTO ".$this->prefix."content (`title`, `title_alias`, `introtext`, `fulltext`, `state`, `created` , `sectionid`, `catid`, `images`, `publish_up`, `publish_down`) VALUES ('$titulo', '$titulo', '$olho', '$texto', '$conf_publicado', NOW() , '$secao', '$categoria', '$imagem',"; $sql_insere .= $dt_publicacao ? "'$dt_publicacao'" : "NOW()"; $sql_insere .= ", "; $sql_insere .= ($dt_vigencia && $dt_vigencia > 0) ? "date_add(now(), interval $dt_vigencia day) " : "''"; $sql_insere .= ")"; $insere = mysql_query($sql_insere) or die('1: ' . _ERR_INESPERADO .mysql_error()); // pega o ultimo id $ultimo_id = mysql_insert_id(); //echo "ultimo id = $ultimo_id<br>"; // configuração para inserir na página principal. if ($conf_principal == 1) { $ultimo = mysql_insert_id(); $res = mysql_query("SELECT MAX(ordering) FROM ".$this->prefix."content_frontpage"); $ordem = mysql_result($res,0); if ($ordem == 0) $ordem = 1; if ($ordem > 0 && $ultimo > 0) { $ordem++; mysql_query("INSERT INTO ".$this->prefix."content_frontpage (content_id, ordering) VALUES ('$ultimo', '$ordem')") or die("fudeu nego. chama o lambari"); } } if ($vet_var != NULL){ // testa se existem item de outra linguagem a serem inseridos foreach($vet_var as $k => $v){ $var = explode("_",$k); $k = $v; //echo "$k = $v e k $$k e v ".$$v."<br>"; // debug $mega_id = explode("_",$k); $mega_id = $mega_id[1]; // id da linguagem if (strstr($k, "olho") != false){ $campo = "introtext"; $valor = $$v . '<br />'; $original = $olho; } else if(strstr($k, "titulo") != false){ $campo = "title"; $valor = $$v; $original = $titulo; } else if(strstr($k, "texto") != false){ $campo = "fulltext"; $valor = $$v; if ($imagem && $imagem != _NENHUMA_IMAGEM) { $imagem = str_replace($path_imagens, $url_imagens, $imagem); $valor = "<img src=\"$imagem\" align=\"center\"><br />" . $valor; } $original = $texto; } //$valor = $$v; // gambiarra não né fio! $sql = "INSERT INTO ".$this->prefix."mbf_content (language_id, reference_id, reference_table, reference_field, value, original_value, modified, modified_by) VALUES ('$mega_id', '$ultimo_id', 'content', '$campo', '$valor', '$original', now(), '$row[0]')"; $gurda = mysql_query($sql) or die ("jah era".mysql_error()); } }// fim teste $vet_var echo _SUCESSO; echo '<a href="index.php"><h2>' . _VOLTAR . '<h2></a> '; } } } ?>