- <?
- 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
- */
- /**
- 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( ) {
- }
- 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();
- }
- $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'";
- if ($hash != $cryptpass) {
- return false; // didn't match!
- }
- else {
- return true;
- }
- }
- /**
- Initiates a connection with the database... a bit amateur, but it works.
- @private
- */
- function init_db() {
- // @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 */
- 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() );
- $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() {
- // do we need this second reset?
- 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' ";
- ?>
- <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) {
- }
- }
- ?>
- </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;
- $uploadedFileName = $_FILES['filename']['name'];
- if($_FILES['filename']['size'] > $maxSize)
- {
- $error = _ERR_IMG_FILE_SIZE;
- }
- $extension = $extension["extension"];
- foreach($allowedExtensions as $key=>$ext) {
- {
- $boolValidExt = true;
- break;
- }
- }
- if($boolValidExt) {
- }
- }
- }
- else
- {
- $error = _ERR_IMG_FILE_EXTENSION;
- echo $error;
- exit;
- }
- {
- $srcFile = $path_imagens . $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();
- //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>
- </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>
- </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) {
- $prefix = $this->prefix;
- $escaped = false;
- $quoteChar = '';
- $startPos = 0;
- $literal = '';
- while ($startPos < $n) {
- if ($ip === false) {
- break;
- }
- if (($k !== FALSE) && (($k < $j) || ($j === FALSE))) {
- $quoteChar = '"';
- $j = $k;
- } else {
- $quoteChar = "'";
- }
- if ($j === false) {
- $j = $n;
- }
- $startPos = $j;
- $j = $startPos + 1;
- if ($j >= $n) {
- break;
- }
- // quote comes first, find end of quote
- while (TRUE) {
- $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;
- }
- $startPos = $k+1;
- }
- if ($startPos < $n) {
- }
- return $literal;
- }
- /**
- add a new content item into your joomla/mambo website.
- */
- function insert() {
- }
- 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 ($$k != NULL){ // testa se a variável de outro idioma não está vazia
- $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 ($thumbImage && $thumbImage != _NENHUMA_IMAGEM) {
- }
- if ($imagem && $imagem != _NENHUMA_IMAGEM) {
- $texto = "<img src=\"$imagem\" align=\"center\" vspace=\"5\"><br />" . $texto;
- }
- $olho .= "\n";
- $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);
- // last item...
- //echo "ultimo id = $ultimo_id<br>";
- // configuração para inserir na página principal.
- if ($this->frontpage == true) {
- $ultimo = $ultimo_id;
- if ($ordem == 0) $ordem = 1;
- if ($ordem > 0 && $ultimo > 0) {
- $ordem++;
- }
- }
- } // foreach - categories
- /* tests if there are items in other languages to be insert. */
- if ($vet_var != NULL){
- foreach($vet_var as $k => $v){
- $k = $v;
- //echo "$k = $v e k $$k e v ".$$v."<br>"; // debug
- $mega_id = $mega_id[1]; // language id
- $campo = "introtext";
- $valor = $$v . '<br />';
- $original = $olho;
- }
- $campo = "title";
- $valor = $$v;
- $original = $titulo;
- }
- $campo = "fulltext";
- $valor = $$v;
- if ($imagem && $imagem != _NENHUMA_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]')";
- }
- }// 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 ($$k != NULL){ // testa se a variável de outro idioma não está vazia
- $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>";
- }
- }
- // user validation
- $sql_login = "SELECT id FROM ".$this->prefix."users WHERE username = '$login' AND password = '$senha'";
- echo _ERR_LOGIN;
- }
- else
- { // logged in!
- if ($imagem && $imagem != _NENHUMA_IMAGEM) {
- $texto = "<img src=\"$imagem\" align=\"center\"><br />" . $texto;
- }
- $olho .= "\n";
- $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 .= ")";
- // pega o ultimo id
- //echo "ultimo id = $ultimo_id<br>";
- // configuração para inserir na página principal.
- if ($conf_principal == 1) {
- if ($ordem == 0) $ordem = 1;
- if ($ordem > 0 && $ultimo > 0) {
- $ordem++;
- }
- }
- if ($vet_var != NULL){ // testa se existem item de outra linguagem a serem inseridos
- foreach($vet_var as $k => $v){
- $k = $v;
- //echo "$k = $v e k $$k e v ".$$v."<br>"; // debug
- $mega_id = $mega_id[1]; // id da linguagem
- $campo = "introtext";
- $valor = $$v . '<br />';
- $original = $olho;
- }
- $campo = "title";
- $valor = $$v;
- $original = $titulo;
- }
- $campo = "fulltext";
- $valor = $$v;
- if ($imagem && $imagem != _NENHUMA_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]')";
- }
- }// fim teste $vet_var
- echo _SUCESSO;
- }
- }
- }
- ?>
Adaptação do simpleNews para fazê-lo funcionar com Joomla! 1.5
