• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

[MAAC] Simple news ticker system

averatec

Advanced OT User
Joined
Jun 1, 2007
Messages
2,243
Solutions
4
Reaction score
159
Location
Poland
features
  1. includes js script script to hide/show content(needed jquery, that is normally included maac)
  2. admin panel
    • adding tickers
    • deleting tickers
  3. config
    • tickers limit
    • words limit - ticker before will be fully showed by clicking "+", will show some initial words and that's count of these words

now we need to install this mess

#1
execute this query
Code:
	CREATE TABLE `newsticker` (
	 `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
	 `date` INT(11) NOT NULL ,
	 `text` TEXT NOT NULL 
	) ENGINE=MYISAM ;

#2
add these values to config.php
PHP:
	$config['newsTickerLimit'] = 10;
	$config['newsTickerWords'] = 4;
#3
add to system/application/models/admin_model
PHP:
	public function getTickerList() {
		$this->load->helper("url");
		$page = $this->uri->segment(3);
			if(empty($page))
				$page = "0";
		
		return $this->db->get("newsticker", 10, $page)->result_array();
	}

	public function getTickerAmount() {
		return $this->db->count_all('newsticker');
	}

	public function addTicker($body) {
		$data = array('text' => $body,
			'date' => $_SERVER['REQUEST_TIME']);
			
		$this->db->insert('newsticker', $data);
	}

	public function deleteTicker($id) {
		$this->db->delete('newsticker', array('id' => $id));
	}
#4
add to system/application/views/admin_menu
PHP:
echo "<a href='".WEBSITE."/index.php/admin/ticker'>Tickers</a> | ";
#5
create new file system/application/views/add_ticker.php
PHP:
	<?php 
	echo error(validation_errors());
	echo form_open("admin/add_ticker");
	echo "<textarea name='text' class='tinymce'>".set_value('body')."</textarea><br />";
	echo "<input type='submit' value='Add ticker'>";
	echo "</form>";

	?>
#6
create new file system/application/views/admin_ticker_show.php
PHP:
	<?php 
	echo "<div class='toolbar'>";
	echo "<a href='".WEBSITE."/index.php/admin/add_ticker'>Add ticker</a> | ";
	echo "</div>";
	$this->load->helper('text');
	if(count($news) == 0) 
		alert("There is no tickers yet.");
	else {
		echo "<table width='100%'>";
		echo "<tr><td><center><b>ID</b></center></td><td><center><b>Created</b></center></td><td><center><b>Introduce</b></center></td><td><center><b>Edit</b></center></td></tr>";
		foreach($news as $value) {
			echo "<tr class='highlight'><td><center>".$value['id']."</center></td><td><center>".UNIX_TimeStamp($value['date'])."</center></td><td><center>".word_limiter($value['text'], $wordLimit)."</center></td><td><center><a href='#' onClick=\"if(confirm('Are you sure you want to remove?')) window.location.href='".WEBSITE."/index.php/admin/delete_ticker/".$value['id']."';\"><img src='".WEBSITE."/public/images/false.gif'></a></center></td></tr>";
		}
		echo "</table>";
	}

	echo "<center>".$pages."</center>";
	?>
#7
add to system/application/controllers/admin
PHP:
public function ticker() {
		require("config.php");
		$ide = new IDE;
		$ide->requireAdmin();
		$data = array();
		$this->load->model("admin_model");
		$data['news'] = $this->admin_model->getTickerList();
		$this->load->library('pagination');
		$config['base_url'] = WEBSITE.'/index.php/admin/ticker/';
		$config['total_rows'] = $this->admin_model->getTickerAmount();
		$config['per_page'] = $config['newsTickerLimit'];
		$this->pagination->initialize($config); 
		$data['pages'] = $this->pagination->create_links();
		$data['wordLimit'] = $config['newsTickerWords'];
		$this->load->view("admin_menu");
		$this->load->view("admin_ticker_show", $data);
	}
	
	public function add_ticker() {
		$ide = new IDE;
		$ide->requireAdmin();
		$this->load->helper("form_helper");
		$this->load->library("form_validation");
			if($_POST) {
				$this->form_validation->set_rules('text', 'Text', 'required');
				if($this->form_validation->run() == true) {
					$body = $_POST['text'];
					$this->load->model("admin_model");
					$this->admin_model->addTicker($body);
					success("Ticker has been added.");
					$ide->redirect(WEBSITE."/index.php/admin/ticker", 2);
				}
			}
		$this->load->view("admin_menu");
		$this->load->view("add_ticker");
	}
	
	public function delete_ticker() {
		$ide = new IDE;
		$ide->requireAdmin();
		$this->load->model("admin_model");
		$this->admin_model->deleteTicker($id);
		$ide->goPrevious();
		success("Ticker has been deleted.");
		$ide->redirect(WEBSITE."/index.php/admin/ticker", 2);
	}
#8
add to system/application/controllers/home
in function index after line with $date['news'] = ....
PHP:
$data['tickers'] = $this->home_model->getTickers();
#9
add to system/application/models/home_model
PHP:
public function getTickers() {
		require("config.php");
		$this->db->order_by('id desc');
		$sql = $this->db->get('newsticker', $config['newsTickerLimit']);
		$ret['amount'] = $sql->num_rows;
		$ret['news'] = $sql->result_array();
		return $ret;
	}
#10
edit file system/application/views/home
before line
PHP:
foreach($news['news'] as $value) {
add it
PHP:
echo "<div id='tickers'>";
	$this->load->helper('text');
	?>
	<script type="text/javascript">
	$(document).ready(function() { 
		$(".tickerButton").each(function() { 
			$(this).click(function() {
				if ($(this).html() == "-")
					$(this).html("+")
				else
					$(this).html("-")
				$(this).parent().find("span").each(function() {
					$(this).toggle();
				});
			});
		});
	});
	</script>
	<?php
	foreach($tickers['news'] as $value) {
		echo '<div style="border: 1px black dotted; padding: 3px 3px 3px 3px; margin-bottom: 3px;"><a href="#" class="tickerButton">+</a>'.date('d M Y',$value['date']).', <span>'.word_limiter($value['text'], $config['newsTickerWords']).'</span><span style="display: none">'.$value['text'].'</span></div>';
		//
	}
	echo "</div><br/>";


Now simple tickers system will work.
 
couldn't edit my post, not working btw.. it came up with a clear white page .. o.0
 
If you did everything right, it should work, I can talk with u via skype and show u it works.
 
It very annoying I can't edit my posts... anyway some patch to admin controller:
before patch
PHP:
	public function delete_ticker() {
		$ide = new IDE;
		$ide->requireAdmin();
		$this->load->model("admin_model");
		$this->admin_model->deleteTicker($id);
		$ide->goPrevious();
		success("Ticker has been deleted.");
		$ide->redirect(WEBSITE."/index.php/admin/ticker", 2);
	}
after patch should look(missing param $id in def of function)
PHP:
	public function delete_ticker($id) {
		$ide = new IDE;
		$ide->requireAdmin();
		$this->load->model("admin_model");
		$this->admin_model->deleteTicker($id);
		$ide->goPrevious();
		success("Ticker has been deleted.");
		$ide->redirect(WEBSITE."/index.php/admin/ticker", 2);
	}
Some screens:

1.jpg
2.jpg
3.jpg
 
It works somehow fine, but the borders are some ugly and when you press the button + it takes you to the upper part of the site...

Here I leave you a code that works very fine and simple and you may be able to "fusion" some how to fix this error:

PHP:
echo '<tr bgcolor=#F1E0C6><td><font size="2">&raquo;</font> 
		<b><font color="#5c120f" size=1>Marzo 21 2012</b></font> <small>Cambios en experience stages, mas altos...
		<div align=right>
			<a href="#" onClick="if($(this).parent().find(\'p\').is(\':visible\')) {$(this).parent().find(\'p\').hide(); $(this).text(\'+\');} else {$(this).parent().find(\'p\').show(); $(this).text(\'-\');} return false;">+</a>
				<p style="display: none" align="left">
					Text
					
				</p>
		</div></td></tr></small>';

And also it says the newstickers like this:

Code:
-20 Apr 2012, Porbsndsaod asdk askd sadns aldsaohd sand sadihsadknjsald asldkasdsjald Porbsndsaod asdk askd sadns aldsaohd sand sadihsadknjsald asldkasdsjald Porbsndsaod asdk askd sadns aldsaohd sand sadihsadknjsald

And it should be like:
Code:
-20 Apr 2012, Porbsndsaod asdk askd sadns aldsaohd sand sadihsadknjsald 
              asldkasdsjald Porbsndsaod asdk askd sadns aldsaohd sand 
              sadihsadknjsald asldkasdsjald Porbsndsaod asdk askd sadns
              aldsaohd sand sadihsadknjsald.
 
you can do it by your self, but if u want help tell me on monday or later xd you know... parties xd
 
you can do it by your self, but if u want help tell me on monday or later xd you know... parties xd

The first part can be done easily, the problem is this part:

Code:
-20 Apr 2012, Porbsndsaod asdk askd sadns aldsaohd sand sadihsadknjsald 
              asldkasdsjald Porbsndsaod asdk askd sadns aldsaohd sand 
              sadihsadknjsald asldkasdsjald Porbsndsaod asdk askd sadns
              aldsaohd sand sadihsadknjsald.
 
i got 3 errors when i added news on the ticker /views/home.php

A PHP Error was encountered
Severity: Notice
Message: Undefined index: title
Filename: views/home.php
Line Number: 33

A PHP Error was encountered
Severity: Notice
Message: Undefined index: body
Filename: views/home.php
Line Number: 34

A PHP Error was encountered
Severity: Notice
Message: Undefined index: time
Filename: views/home.php
Line Number: 39

here is my home.php after editing
Code:
<?php 
require("config.php");
$ide = new IDE;
try { $ide->loadInjections("home"); }catch(Exception $e) { error($e->getMessage());}

echo "<div id='tickers'>"; 
    $this->load->helper('text'); 
    ?> 
    <script type="text/javascript"> 
    $(document).ready(function() {  
        $(".tickerButton").each(function() {  
            $(this).click(function() { 
                if ($(this).html() == "-") 
                    $(this).html("+") 
                else 
                    $(this).html("-") 
                $(this).parent().find("span").each(function() { 
                    $(this).toggle(); 
                }); 
            }); 
        }); 
    }); 
    </script> 
    <?php 
    foreach($tickers['news'] as $value) { 
        echo '<div style="border: 1px black dotted; padding: 3px 3px 3px 3px; margin-bottom: 3px;"><a href="#" class="tickerButton">+</a>'.date('d M Y',$value['date']).', <span>'.word_limiter($value['text'], $config['newsTickerWords']).'</span><span style="display: none">'.$value['text'].'</span></div>'; 
        // 
    } 
    echo "</div><br/>";

foreach($news['news'] as $value) {
	echo "<div class='news'>";
	echo "<div class='newsTitle'>".$value['title']."</div>";
	echo "<div class='newsBody'>".$value['body']."</div>";	
	echo "<div class='newsFooter'>";	
	if($config['facebook']) {
		echo "<iframe src='http://www.facebook.com/widgets/like.php?href=".WEBSITE."/index.php/home/view/".$value['id']."' scrolling='no' frameborder='0'style='border: none; width: 400px; height: 24px;'></iframe><br/>";
	}
	echo "Posted on: ".UNIX_TimeStamp($value['time'])." </div>";
	echo "<div class='viewComments'><a href='".WEBSITE."/index.php/home/view/".$value['id']."'>View comments</a></div>";
	echo "</div>";
}
echo "<div class='readArchive'><a href='".WEBSITE."/index.php/home/archive'>Go to archive posts</a></div>";
?>
 
show me your controllers/Home::index()

here is it

Code:
<?php

class Home extends Controller {

	public function index() {
		require("config.php");
		$this->load->model("home_model");
		$data = array();
		$data['news'] = $data['tickers'] = $this->home_model->getTickers();  
		$this->load->view("home", $data);
	}
	
	public function archive() {
		require("config.php");
		$this->load->model("home_model");
		$data = array();
		$this->load->library('pagination');
		$config['base_url'] = WEBSITE.'/index.php/home/archive/';
		$config['total_rows'] = $this->home_model->getNewsAmount();
		$config['per_page'] = $config['newsLimit']; 
		$this->pagination->initialize($config); 
		$data['pages'] = $this->pagination->create_links();
		$data['news'] = $this->home_model->getArchiveNews();
		$this->load->view("archive", $data);
	}
	
	public function _checkPlayer($id) {
		$this->load->model("home_model");
		if($this->home_model->playerExistsOnAccount($id)) return true; else { $this->form_validation->set_message('_checkPlayer', 'This character does not belongs to you.'); return false; }
	}
	
	function _checkCaptcha($word) {
			if(strtolower($word) == strtolower($_SESSION['captcha']) && !empty($_SESSION['captcha'])) {
				return true;
			}
			else {
				$this->form_validation->set_message('_checkCaptcha', 'Captcha word is incorrect.');
				return false;
			}
		}
	
	public function view($id) {
		require("config.php");
		$id = (int)$id;
		$ide = new IDE;
		if(empty($id)) $ide->redirect(WEBSITE."/index.php/home/");
		$this->load->model("home_model");
		$data = array();
		$data['news'] = $this->home_model->loadNews($id);
		$this->load->plugin('captcha');
		$vals = array(
					'word'		 => '',
					'img_path'	 => 'system/captcha/',
					'img_url'	 => WEBSITE.'/system/captcha/',
					'font_path'	 => WEBSITE.'/system/fonts/texb.ttf',
					'img_width'	 => '156',
					'img_height' => 30,
					'expiration' => 120
				);
			if(!$_POST) {
				$cap = create_captcha($vals);	
			}
			if($data['news'] == false) {
				error("Could not find news.");
				$ide->redirect(WEBSITE."/index.php/home", 2);
			}
			else {
					if($_POST) {
						$this->load->library("form_validation");
						$this->form_validation->set_rules('character', 'Character', 'required|callback__checkPlayer');
						$this->form_validation->set_rules('body', 'Comment', 'required|min_lenght[3]|max_lenght[300]');
						$this->form_validation->set_rules('captcha', 'Captcha', 'required|callback__checkCaptcha');
						if($this->form_validation->run() == TRUE) {
							$this->home_model->addComment($id, $_POST['character'], $_POST['body']);
							success("Comment has been posted.");
							$cap = create_captcha($vals);
							$_POST['body'] = "";
						}
						else {
							$cap = create_captcha($vals);
						}
					}
				$this->load->library('pagination');
				$config['base_url'] = WEBSITE.'/index.php/home/view/'.$id.'/';
				$config['total_rows'] = $this->home_model->getCommentsAmount($id);
				$data['comments'] = $this->home_model->getComments($id);
				$config['per_page'] = $config['commentLimit'];
				$config['uri_segment'] = 4;
				$this->pagination->initialize($config); 
				$data['pages'] = $this->pagination->create_links();
				$data['characters'] = $this->home_model->getCharacters();
				$this->load->helper("form_helper");
				$data['id'] = $id;
				$_SESSION['captcha'] = @$cap['word'];
				$data['captcha'] = @$cap['image'];
				$this->load->view("view_news", $data);
				
			}	
	}
	
	public function delete_comment($id) {
		$ide = new IDE;
		$this->load->model("home_model");
		$comment = $this->home_model->getComment($id);
		if(empty($comment))
			$ide->redirect(WEBSITE."/index.php/home");
		else {
			if($ide->isAdmin()) {
				$this->home_model->deleteComment($id);
				$ide->redirect(WEBSITE."/index.php/home/view/".$comment[0]['news_id']);
			}
			else {
				$characters = $this->home_model->getCharacters();
				if(in_array($comment[0]['author'], $characters[0])) {
					$this->home_model->deleteComment($id);
					$ide->redirect(WEBSITE."/index.php/home/view/".$comment[0]['news_id']);
				}
				else {
					$ide->redirect(WEBSITE."/index.php/home/view/".$comment[0]['news_id']);
				}
			}
		}
	}
	
	
}

/* End of file welcome.php */
/* Location: ./system/application/controllers/welcome.php */
 
here is it

Code:
<?php

class Home extends Controller {

	public function index() {
		require("config.php");
		$this->load->model("home_model");
		$data = array();
		[B]$data['news'] = $data['tickers'] = $this->home_model->getTickers();  [/B]
		$this->load->view("home", $data);
	}
	
	public function archive() {
		require("config.php");
		$this->load->model("home_model");
		$data = array();
		$this->load->library('pagination');
		$config['base_url'] = WEBSITE.'/index.php/home/archive/';
		$config['total_rows'] = $this->home_model->getNewsAmount();
		$config['per_page'] = $config['newsLimit']; 
		$this->pagination->initialize($config); 
		$data['pages'] = $this->pagination->create_links();
		$data['news'] = $this->home_model->getArchiveNews();
		$this->load->view("archive", $data);
	}
	
	public function _checkPlayer($id) {
		$this->load->model("home_model");
		if($this->home_model->playerExistsOnAccount($id)) return true; else { $this->form_validation->set_message('_checkPlayer', 'This character does not belongs to you.'); return false; }
	}
	
	function _checkCaptcha($word) {
			if(strtolower($word) == strtolower($_SESSION['captcha']) && !empty($_SESSION['captcha'])) {
				return true;
			}
			else {
				$this->form_validation->set_message('_checkCaptcha', 'Captcha word is incorrect.');
				return false;
			}
		}
	
	public function view($id) {
		require("config.php");
		$id = (int)$id;
		$ide = new IDE;
		if(empty($id)) $ide->redirect(WEBSITE."/index.php/home/");
		$this->load->model("home_model");
		$data = array();
		$data['news'] = $this->home_model->loadNews($id);
		$this->load->plugin('captcha');
		$vals = array(
					'word'		 => '',
					'img_path'	 => 'system/captcha/',
					'img_url'	 => WEBSITE.'/system/captcha/',
					'font_path'	 => WEBSITE.'/system/fonts/texb.ttf',
					'img_width'	 => '156',
					'img_height' => 30,
					'expiration' => 120
				);
			if(!$_POST) {
				$cap = create_captcha($vals);	
			}
			if($data['news'] == false) {
				error("Could not find news.");
				$ide->redirect(WEBSITE."/index.php/home", 2);
			}
			else {
					if($_POST) {
						$this->load->library("form_validation");
						$this->form_validation->set_rules('character', 'Character', 'required|callback__checkPlayer');
						$this->form_validation->set_rules('body', 'Comment', 'required|min_lenght[3]|max_lenght[300]');
						$this->form_validation->set_rules('captcha', 'Captcha', 'required|callback__checkCaptcha');
						if($this->form_validation->run() == TRUE) {
							$this->home_model->addComment($id, $_POST['character'], $_POST['body']);
							success("Comment has been posted.");
							$cap = create_captcha($vals);
							$_POST['body'] = "";
						}
						else {
							$cap = create_captcha($vals);
						}
					}
				$this->load->library('pagination');
				$config['base_url'] = WEBSITE.'/index.php/home/view/'.$id.'/';
				$config['total_rows'] = $this->home_model->getCommentsAmount($id);
				$data['comments'] = $this->home_model->getComments($id);
				$config['per_page'] = $config['commentLimit'];
				$config['uri_segment'] = 4;
				$this->pagination->initialize($config); 
				$data['pages'] = $this->pagination->create_links();
				$data['characters'] = $this->home_model->getCharacters();
				$this->load->helper("form_helper");
				$data['id'] = $id;
				$_SESSION['captcha'] = @$cap['word'];
				$data['captcha'] = @$cap['image'];
				$this->load->view("view_news", $data);
				
			}	
	}
	
	public function delete_comment($id) {
		$ide = new IDE;
		$this->load->model("home_model");
		$comment = $this->home_model->getComment($id);
		if(empty($comment))
			$ide->redirect(WEBSITE."/index.php/home");
		else {
			if($ide->isAdmin()) {
				$this->home_model->deleteComment($id);
				$ide->redirect(WEBSITE."/index.php/home/view/".$comment[0]['news_id']);
			}
			else {
				$characters = $this->home_model->getCharacters();
				if(in_array($comment[0]['author'], $characters[0])) {
					$this->home_model->deleteComment($id);
					$ide->redirect(WEBSITE."/index.php/home/view/".$comment[0]['news_id']);
				}
				else {
					$ide->redirect(WEBSITE."/index.php/home/view/".$comment[0]['news_id']);
				}
			}
		}
	}
	
	
}

/* End of file welcome.php */
/* Location: ./system/application/controllers/welcome.php */


now look, it's my index function:
PHP:
	public function index() {
		require("config.php");
		$this->load->model("home_model");
		$data = array();
[B]		$data['news'] = $this->home_model->getAllNews();
		$data['tickers'] = $this->home_model->getTickers();[/B]
		
		$this->load->view("home", $data);
	}
 
Could you post the files that have been edited to download? In my Modern Acc errors occurred in all my attempts made.
 
Back
Top