<?
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();
}
$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'";
$cryptpass =
md5($pass.
$salt);
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 */
$res =
mysql_query("SHOW TABLES FROM ".
$this->
db .
" LIKE '%_mbf%'");
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() {
$firstLanguageId =
key($this->
languages);
// 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;
$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) {
{
$boolValidExt = true;
break;
}
}
if($boolValidExt) {
copy($_FILES['filename']['tmp_name'],
$path_imagens .
$uploadedFileName);
}
}
}
else
{
$error = _ERR_IMG_FILE_EXTENSION;
}
{
$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();
//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>
<? }
}
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) {
$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(!$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 (!
$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;
}
&n