|
You last visited: Today at 05:44
Advertisement
[In-Orbit][Script] Newspart
Discussion on [In-Orbit][Script] Newspart within the DarkOrbit forum part of the Browsergames category.
10/20/2014, 19:57
|
#1
|
elite*gold: 1
Join Date: Jun 2011
Posts: 1,464
Received Thanks: 1,065
|
[In-Orbit][Script] Newspart
If you use the In-Orbit CMS you maybe want to have a workings newsletter.
Everything is working well and you can add news by inserting rows to db
requirements: version of in-orbit
SQL
Code:
CREATE TABLE IF NOT EXISTS `news` (
`nID` int(11) NOT NULL AUTO_INCREMENT,
`newsID` varchar(50) NOT NULL DEFAULT 'default',
`image` varchar(50) NOT NULL DEFAULT 'default.gif',
`icon` varchar(50) NOT NULL DEFAULT 'default.gif',
`headline` varchar(100) NOT NULL DEFAULT 'Default Headline',
`text` text NOT NULL,
PRIMARY KEY (`newsID`),
UNIQUE KEY `nID` (`nID`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8;
INSERT INTO `news` (`nID`, `newsID`, `image`, `icon`, `headline`, `text`) VALUES
(7, 'firstnews', 'default.gif', 'default.gif', 'News!', 'Not working/bugged: (~progress)<br><br>\n <ul>\n <li><b class="breakingNewsHighlightBlue">-> GalaxyGateGenerator (40%)</b></li>\n <li><b class="breakingNewsHighlightBlue">-> Skylab (40%)</b></li>\n <li><b class="breakingNewsHighlightBlue">-> Equipment (95%)</b></li>\n <li><b class="breakingNewsHighlightBlue">-> Pilotbio (2%)</b></li>\n <li><b class="breakingNewsHighlightBlue">-> more minor things..</b></li>\n <li><b class="breakingNewsHighlightBlue">alot more..</b></li>\n </ul>\n <br><br> Do not try to use this features. You will NOT get refunded.\n \n <br><br>\n <br><br>\n Your DarkPlanets team'),
(6, 'premium', 'benefitPremium.gif', 'benefitPremium.gif', 'Premium!', 'Get premium today and help<br>this server to grow!<br><br><br><br>Your DarkPlanets-Team'),
(8, 'serverstatus', 'default.gif', 'default.gif', 'Serverstatus!', '<b class="breakingNewsHighlightBlue">As you might already saw, is the spacemap offline. We do some bugfixing and updates to get rid of some annoying bugs e.g. losing ammo, missing drones and others. Maybe we finish that until monday, maybe earlier, or maybe not. We do our best to keep this downtime as short as possible.</b><br><br>\n\n \n <br><br>\n <br><br>\n ~Underworld');
add this to init.php (\KERNEL-DOCMS\)
PHP Code:
require_once 'Class.news.php';
create this file in the same directory (Class.news.php)
PHP Code:
<?php class news { /** * /do_img/global/events/ * /do_img/global/events/icons/ */ private $con; private $data; private $cnt; public function __construct() { $this->con = $GLOBALS['DB']; } public function init(){ $qry = $this->con->prepare("SELECT * FROM news ORDER BY nID DESC LIMIT 7"); if ($qry->execute()){ if ($qry->rowCount() != 0){ $this->cnt = $qry->rowCount(); $arr = $qry->fetchAll(PDO::FETCH_ASSOC); $this->data = array_combine(range(1, count($arr)), array_values($arr)); return TRUE; }else return FALSE; }else return FALSE; } public function get($type){ $ret = ""; for($i=1;$i<=$this->cnt;$i++){ if($type == "icons"){ $spc = ($i != 1) ? "style=\"margin-left: 6px;\"" : ""; $ret .= "<img id=\"newsIcon_" . $this->data[$i]['newsID'] . "\" class=\"breakingNewsIcon\" src=\"./do_img/global/events/icons/" . $this->data[$i]['icon'] . "\" width=\"21\" height=\"21\" " . $spc . ">"; }elseif($type == "news"){ $spc = ($i != 1) ? "style=\"display: none;\"" : ""; $ret .= "<div id=\"newsText_" . $this->data[$i]['newsID'] . "\" class=\"newsTextContainer\" " . $spc . "><h3>" . $this->data[$i]['headline'] . "</h3>" . $this->data[$i]['text'] . "</div>"; }elseif($type == "images"){ $spc = ($i != 1) ? "style=\"display: none;\"" : "style=\"display: block;\""; $ret .= "<img id=\"newsImage_" . $this->data[$i]['newsID'] . "\" src=\"./do_img/global/events/" . $this->data[$i]['image'] . "\" class=\"newsImage oldNews\" " . $spc . ">"; }elseif($type == "jsarray"){ $ret .= "newsItemIds.push('" . $this->data[$i]['newsID'] . "');"; }elseif($type == "jsarray2"){ $ret .= "uploadedNewsIds.push('" . $this->data[1]['newsID'] . "');"; break; } } return $ret; } } ?>
go to \KERNEL-DOCMS\Files\en_US\INDEXINTERNAL\internalStart_Body .php
and find
Code:
<div id="homeNewsContent">
replace the whole container with this
Code:
<div id="homeNewsContent">
<?php
// news
$newsC = new news();
$newsC->init(); ?>
<script type="text/javascript" language="javascript">
var newsItemIds = new Array();
<?php echo $newsC->get("jsarray"); ?>
var uploadedNewsIds = new Array();
<?php echo $newsC->get("jsarray2"); ?>
</script>
<div id="breakingNewsHeadline">
<span class="bnHead_<?php echo ($Users->DataRow['factionId'] === '1') ? 'mmo' : (($Users->DataRow['factionId'] === '2') ? 'eic' : 'vru'); ?>"><?php echo ($Users->DataRow['factionId'] === '1') ? 'MMO' : (($Users->DataRow['factionId'] === '2') ? 'EIC' : 'VRU'); ?></span> NEWSLETTER
</div>
<div id="breakingNewsTop">
<div class="empty"></div>
<div id="newsImageOverlay" style="display: block;"></div>
<?php echo $newsC->get("images"); ?>
</div>
<div id="breakingNewsLeftArrow" class="breakingNewsArrow"></div>
<div id="breakingNewsRightArrow" class="breakingNewsArrow"></div>
<div id="breakingNewsIconWrapper">
<?php echo $newsC->get("icons"); ?>
<div id="newsIconHighlight" style="left: 54px;"></div>
</div>
<div id="breakingNewsTopGradiant"></div>
<div id="breakingNewsBottomGradiant"></div>
<div id="breakingNewsText" class="js-scroll-pane" tabindex="0" style="overflow: auto; padding: 0px; width: 320px; height: 229px;">
<?php echo $newsC->get("news"); ?>
</div>
</div>
that's it
|
|
|
10/20/2014, 20:39
|
#2
|
elite*gold: 0
Join Date: Sep 2014
Posts: 270
Received Thanks: 21
|
heheh very nice tutorials , are you gonna release other cool tutos?
|
|
|
10/22/2014, 22:26
|
#3
|
elite*gold: 0
Join Date: Sep 2014
Posts: 280
Received Thanks: 42
|
To fix this error?:
Quote:
Notice: Undefined index: DB in C:\Program Files (x86)\xampp\htdocs\KERNEL-DOCMS\Class.news.php on line 14
Fatal error: Call to a member function prepare() on a non-object in C:\Program Files (x86)\xampp\htdocs\KERNEL-DOCMS\Class.news.php on line 18
|
image:
|
|
|
10/23/2014, 05:14
|
#4
|
elite*gold: 1
Join Date: Jun 2011
Posts: 1,464
Received Thanks: 1,065
|
Quote:
Originally Posted by steppdroid
To fix this error?:
image:
|
obviously you do not use the pdo-db-class. prepare() is a method of this class.
Copy this to init.php
PHP Code:
require_once 'Class.db.php'; $db = new DB(); $db::getInstance(); $GLOBALS['DB'] = $db::$instance;
create this file (Class.db.php) in the same folder (\KERNEL-DOCMS\) (Change connection-settings)
PHP Code:
<?php /* * FOLLOW SCRIPT WAS MADE BY BAU - MEDIANET IVS DENMARK * disabled some methods ~underworld */ class DB { public static $instance;
public function __construct() {} public static function getInstance() { if(empty(self::$instance)) { $db_info = array( "db_host" => "127.0.0.1", "db_port" => "3306", "db_user" => "root", "db_pass" => "", "db_name" => "darkorbit", "db_charset" => "UTF-8" ); try { self::$instance = new PDO("mysql:host=".$db_info['db_host'].';port='.$db_info['db_port'].';dbname='.$db_info['db_name'], $db_info['db_user'], $db_info['db_pass']); self::$instance->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT ); //self::$instance->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); //self::$instance->query('SET NAMES utf8'); //self::$instance->query('SET CHARACTER SET utf8');
} catch(PDOException $e) { echo $e->getMessage(); } } return self::$instance; }
static function getUserIP() { $client = @$_SERVER['HTTP_CLIENT_IP']; $forward = @$_SERVER['HTTP_X_FORWARDED_FOR']; $remote = $_SERVER['REMOTE_ADDR'];
if(filter_var($client, FILTER_VALIDATE_IP)) { $ip = $client; } elseif(filter_var($forward, FILTER_VALIDATE_IP)) { $ip = $forward; } else { $ip = $remote; }
return $ip; }
/*public static function setLog($pid, $des){ if($pid==0){ }else{ $con = self::getInstance(); $sql = "INSERT INTO `server_1_log` (`playerID`, `descrip`) VALUES (?, ?)"; $stmt = $con->prepare($sql); $stmt->bindParam(1, $pid, PDO::PARAM_INT); $stmt->bindParam(2, $des, PDO::PARAM_STR); $stmt->execute(); } }*/ /*public static function pmc($pid, $des, $location){ if($pid==0){ }else{ $con = self::$instance; $sql = "INSERT INTO `pmc_log` (`playerID`, `descrip` , `location`) VALUES (?, ?, ?)"; $stmt = $con->prepare($sql); $stmt->bindParam(1, $pid, PDO::PARAM_INT); $stmt->bindParam(2, $des, PDO::PARAM_STR); $stmt->bindParam(3, $location, PDO::PARAM_STR); $stmt->execute(); } }*/ /* static function safe($s = '') { $db_info = array( "db_host" => "127.0.0.1", "db_port" => "3306", "db_user" => "root", "db_pass" => "", "db_name" => "darkorbit", "db_charset" => "UTF-8" ); $con = $MySQLi = new mysqli($db_info["db_host"], $db_info["db_user"], $db_info['db_pass'], $db_info['db_name']); //TODO: finish this... not exactly perfect return mysqli_real_escape_string($con, $s); }*/
} ?>
|
|
|
10/23/2014, 12:02
|
#5
|
elite*gold: 0
Join Date: Sep 2014
Posts: 280
Received Thanks: 42
|
Quote:
Originally Posted by ǝnd1ǝss-ɯonǝʎ
obviously you do not use the pdo-db-class. prepare() is a method of this class.
Copy this to init.php
PHP Code:
require_once 'Class.db.php'; $db = new DB(); $db::getInstance(); $GLOBALS['DB'] = $db::$instance;
create this file (Class.db.php) in the same folder (\KERNEL-DOCMS\) (Change connection-settings)
PHP Code:
<?php /* * FOLLOW SCRIPT WAS MADE BY BAU - MEDIANET IVS DENMARK * disabled some methods ~underworld */ class DB { public static $instance;
public function __construct() {} public static function getInstance() { if(empty(self::$instance)) { $db_info = array( "db_host" => "127.0.0.1", "db_port" => "3306", "db_user" => "root", "db_pass" => "", "db_name" => "darkorbit", "db_charset" => "UTF-8" ); try { self::$instance = new PDO("mysql:host=".$db_info['db_host'].';port='.$db_info['db_port'].';dbname='.$db_info['db_name'], $db_info['db_user'], $db_info['db_pass']); self::$instance->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT ); //self::$instance->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); //self::$instance->query('SET NAMES utf8'); //self::$instance->query('SET CHARACTER SET utf8');
} catch(PDOException $e) { echo $e->getMessage(); } } return self::$instance; }
static function getUserIP() { $client = @$_SERVER['HTTP_CLIENT_IP']; $forward = @$_SERVER['HTTP_X_FORWARDED_FOR']; $remote = $_SERVER['REMOTE_ADDR'];
if(filter_var($client, FILTER_VALIDATE_IP)) { $ip = $client; } elseif(filter_var($forward, FILTER_VALIDATE_IP)) { $ip = $forward; } else { $ip = $remote; }
return $ip; }
/*public static function setLog($pid, $des){ if($pid==0){ }else{ $con = self::getInstance(); $sql = "INSERT INTO `server_1_log` (`playerID`, `descrip`) VALUES (?, ?)"; $stmt = $con->prepare($sql); $stmt->bindParam(1, $pid, PDO::PARAM_INT); $stmt->bindParam(2, $des, PDO::PARAM_STR); $stmt->execute(); } }*/ /*public static function pmc($pid, $des, $location){ if($pid==0){ }else{ $con = self::$instance; $sql = "INSERT INTO `pmc_log` (`playerID`, `descrip` , `location`) VALUES (?, ?, ?)"; $stmt = $con->prepare($sql); $stmt->bindParam(1, $pid, PDO::PARAM_INT); $stmt->bindParam(2, $des, PDO::PARAM_STR); $stmt->bindParam(3, $location, PDO::PARAM_STR); $stmt->execute(); } }*/ /* static function safe($s = '') { $db_info = array( "db_host" => "127.0.0.1", "db_port" => "3306", "db_user" => "root", "db_pass" => "", "db_name" => "darkorbit", "db_charset" => "UTF-8" ); $con = $MySQLi = new mysqli($db_info["db_host"], $db_info["db_user"], $db_info['db_pass'], $db_info['db_name']); //TODO: finish this... not exactly perfect return mysqli_real_escape_string($con, $s); }*/
} ?>
|
Now Work! Thanks! Do you know how fix also hall of fame ?
|
|
|
10/23/2014, 21:00
|
#6
|
elite*gold: 61
Join Date: Oct 2010
Posts: 1,188
Received Thanks: 2,403
|
I love my PDO class :i<3
|
|
|
10/24/2014, 02:10
|
#7
|
elite*gold: 0
Join Date: May 2014
Posts: 6
Received Thanks: 0
|
Parse error: syntax error, unexpected '[' in /home/u723079466/public_html/KERNEL-DOCMS/Init.php on line 16
|
|
|
10/24/2014, 07:35
|
#8
|
elite*gold: 61
Join Date: Oct 2010
Posts: 1,188
Received Thanks: 2,403
|
Quote:
Originally Posted by Sues1de
Parse error: syntax error, unexpected '[' in /home/u723079466/public_html/KERNEL-DOCMS/Init.php on line 16
|
Use PHP version 5.4 or higher.
Best regards bau
|
|
|
10/24/2014, 08:24
|
#9
|
elite*gold: 1
Join Date: Jun 2011
Posts: 1,464
Received Thanks: 1,065
|
Basicly the globalspart is obsolete bc it's singleton
|
|
|
10/24/2014, 13:02
|
#10
|
elite*gold: 0
Join Date: Oct 2014
Posts: 84
Received Thanks: 100
|
Very nice tutorial, I look forward to seeing many more releases/tutorials from you in the future.
To Bau, nice CMS release, it's a very good one, I love your work, you're my idol, I don't mean that in any weird way either xD
Best Regards,
DarkSkiesDO
|
|
|
All times are GMT +2. The time now is 05:44.
|
|