Mysidia Adoptables Support Forum

Mysidia Adoptables Support Forum (http://www.mysidiaadoptables.com/forum/index.php)
-   Mys v1.3.x Mods (http://www.mysidiaadoptables.com/forum/forumdisplay.php?f=42)
-   -   Mys v1.3.4 News System (http://www.mysidiaadoptables.com/forum/showthread.php?t=4392)

parayna 12-11-2014 08:36 AM

Well, I tried and failed :cfrown: I think your way would work but I can't make sense of putting it together... I have no idea what to put or where. I understand that you need to edit the database but I have no idea what to write into the code to update each field (I am a very novice coder....) I have been trying for a while now but I can't seem to get it right.. :mii: I have even been looking at other files from the script to see if there is similar coding that I could use and there probably is but I can't make sense from it.. ^_^''

...could you please help me when you have some spare moments? Thank you... >.<

~Parayna

IntoRain 12-11-2014 06:32 PM

Quote:

Originally Posted by parayna (Post 31635)
Well, I tried and failed :cfrown: I think your way would work but I can't make sense of putting it together... I have no idea what to put or where. I understand that you need to edit the database but I have no idea what to write into the code to update each field (I am a very novice coder....) I have been trying for a while now but I can't seem to get it right.. :mii: I have even been looking at other files from the script to see if there is similar coding that I could use and there probably is but I can't make sense from it.. ^_^''

...could you please help me when you have some spare moments? Thank you... >.<

~Parayna

I will post it tomorrow asap! I'm sorry, I was going to code it after you answered, but it's the last week of the semester and I have 4 projects to deliver in a few days xD

parayna 12-12-2014 11:59 AM

Thank you! It's fine, to be honest I can't wait until I have learnt coding more and can code things myself XD I know it's a matter of time but I really want to be able to do things like this myself instead of relying on other people who may or may not be busy >.< But thanks all the same! XD

~Parayna

parayna 12-16-2014 09:57 PM

...bump... ^_^

IntoRain 12-18-2014 06:18 PM

Sorry for the late

Adding a "send message to all users" option:
  1. Go to your database, and select your news table.
  2. At the top, if you are using phpMyAdmin, select to edit the table's structure.
  3. At the bottom you will see an "Add (1) columns..." click execute
  4. Create a new columns like this:
    • Name: allowmessage
    • Type: varchar
    • Size: 3
    • Predefined: As defined -> "no"
    • Select "Null" checkbox
  5. Go to your class_news.php file and change it to this: (new stuff is commented with "NEW!")
    PHP Code:

    <?php

    use Resource\Native\Object;
    use 
    Resource\Native\Arrays;

    class 
    News extends Object {


        private 
    $id;
        private 
    $user;
        private 
    $title;
        private 
    $content;
        private 
    $date;
        private 
    $posted;
        private 
    $comments;
        private 
    $allowcomment;
        private 
    $allowmessage;//NEW!

         
    public function __construct($id){
             
    $mysidia Registry::get("mysidia");
             
    $whereClause "id = '{$id}'";
             
    $row $mysidia->db->select("news",array(),$whereClause)->fetchObject();
             if(!
    is_object($row)) throw new NoPermissionException("News doesn't exist");
             foreach(
    $row as $key => $val){
                        
    $this->$key $val;              
                }
                
    $this->comments $mysidia->db->select("newscomments",array("id"),"newsID = {$this->id} ORDER BY date,id");    
            }
            
            public function 
    getID(){
                return 
    $this->id;
        }
        
        public function 
    getUser(){
            return 
    $this->user;
        }
        
        public function 
    getUserObject(){
            
    $mysidia Registry::get("mysidia");
            
    $user = new Member($this->user);
            return 
    $user;
        }
        public function 
    getTitle(){
            return 
    $this->title;
        }
        
        public function 
    getContent(){
            return 
    $this->content;
        }
        
        public function 
    getDate(){
            return 
    $this->date;
        }
        
        public function 
    getPosted(){
            return 
    $this->posted;
        }
        
        public function 
    getAllowComment(){
            return 
    $this->allowcomment;
        }

    //NEW!
        
    public function getAllowMessage(){
            return 
    $this->allowmessage;
        }
            
        public function 
    changeAllowComment($allow){
            
    $mysidia Registry::get("mysidia");
            if(
    $this->allowcomment != $allow){
                
    $this->allowcomment $allow;
                
    $mysidia->db->update("news",array("allowcomment" => $this->allowcomment),"id = {$this->id}");
            }
            
        }

    //NEW!
        
    public function changeAllowMessage($allow){
            
    $mysidia Registry::get("mysidia");
            if(
    $this->allowmessage != $allow){
                
    $this->allowmessage $allow;
                
    $mysidia->db->update("news",array("allowmessage" => $this->allowmessage),"id = {$this->id}");
            }
            
        }
            
        public function 
    addComment($content,$date,$user){
            
    $mysidia Registry::get("mysidia");
            
    $mysidia->db->insert("newscomments",array("comment" => $this->format($content), "date" => $date"userID" => $user"newsID" => $this->id));
            
    $this->comments $mysidia->db->select("newscomments",array("id"),"newsID = {$this->id} ORDER BY date,id");
        }
        
        private function 
    format($text){
                 
    $text html_entity_decode($text);
                 
    $text stripslashes($text);
                 
    $text str_replace("rn","",$text);
                 return 
    $text;
            }
        
        public function 
    saveDraft(){
            
    $mysidia Registry::get("mysidia");
            
    $todayDate $this->todayDate();
            if(
    $this->date != $todayDate$this->newDate($todayDate);
            
    $this->posted "no";
            
    $mysidia->db->update("news",array("posted" => $this->posted),"id = {$this->id}");
        }
        
        public function 
    post(){
            
    $mysidia Registry::get("mysidia");
            
    $todayDate $this->todayDate();
            if(
    $this->date != $todayDate$this->newDate($todayDate);
            
    $this->posted "yes";
            
    $mysidia->db->update("news",array("posted" => $this->posted),"id = {$this->id}");
    //NEW!
            
    if($this->allowmessage == "yes")
                
    $this->sendToAllUsers($todayDate);
        }
     
    //NEW!       
            
    public function sendToAllUsers($dateToday) {
                    
    $mysidia Registry::get("mysidia");
            
    $allusers $mysidia->db->select("users", array("username"), "");        
            
    $messageTitle "Update";
            
    $messagetext "A new news was posted on the site! Click <a href='/news'>here</a> to view!<br>";
            
            while(
    $user $allusers->fetchColumn()){
                
    $mysidia->db->insert("messages", array("fromuser" => "SYSTEM""touser" => $user"status" => "unread""datesent" => $dateToday"messagetitle" => $messageTitle"messagetext" => $messagetext), ""); 
            }
               }
               
            public function 
    editContent($content){
                
    $mysidia Registry::get("mysidia");
                
    $this->content $content;
                
    $mysidia->db->update("news",array("content" => $this->content),"id = {$this->id}");
            }
            
            public function 
    editTitle($title){
                 
    $mysidia Registry::get("mysidia");
                
    $this->title $title;
                
    $mysidia->db->update("news",array("title" => $this->title),"id = {$this->id}");
            }
            
            public function 
    todayDate(){
                
    $dateTime = new DateTime;
                
    $date $dateTime->format('Y-m-d H:i:s');
                return 
    $date;
            }
            public function 
    newDate($date){
                
    $mysidia Registry::get("mysidia");
                
    $this->date $date;
                
    $mysidia->db->update("news",array("date" => $this->date),"id = {$this->id}");
            }
            
            public function 
    getCommentNumber(){
                
    $count $this->comments->rowCount();
                return 
    $count;
            }
            
            public function 
    getComments(){
                return 
    $this->comments;
            }
            
    }

    ?>

  6. Go to your newsview.php file inside the admincp folder and change it to this: (new stuff is commented with "NEW!")
    PHP Code:

    <?php

    use Resource\Native\String;
    use 
    Resource\Collection\LinkedList;
    use 
    Resource\Collection\LinkedHashMap;

    class 
    ACPNewsView extends View{
        
        private 
    $editor;
        
        public function 
    index(){
            
    //parent::index();
            
    $mysidia Registry::get("mysidia");
            
    $document $this->document;    
            
    $document->setTitle("Manage News And Comments");
            
            
    $pagesTable = new TableBuilder("news");
            
    $pagesTable->setAlign(new Align("center""middle"));
            
            
    $pagesTable->buildHeaders("News Title""Author""Date""Edit""Publish/Save""Delete""View Comments""View News");
            
            
    $allnews $this->getField("news")->get();
            
            if(
    $mysidia->input->post("submit")){
                
    $id $mysidia->input->post("submit");
                
    $newsObj = new News($id);
                
    $newsObj->saveDraft();
                
    $document->add(new Comment("<b>Successfully saved news as draft</b>",TRUE));            
            }
            
            if(
    $mysidia->input->post("submit1")){
                
    $id $mysidia->input->post("submit1");
                
    $newsObj = new News($id);
                
    $newsObj->post();
                
    $document->add(new Comment("<b>Successfully added and published news.</b>",TRUE));
            }
            
            if(
    $mysidia->input->post("submit2")){
                
    $id $mysidia->input->post("submit2");
                
    $newsObj = new News($id);
                
    $document->add(new Comment("Are you sure you wish to delete this news?",TRUE));
                
    $form = new Form("title","","post");
                
    $form->add(new Button("Yes","submit5",$id));
                
    $document->add($form);        
                
            }
            if(
    $mysidia->input->post("submit5")){
                
    $id $mysidia->input->post("submit5");
                
    $mysidia->db->delete("news","id = {$id}");
                
    $document->add(new Comment("Successfully deleted news",TRUE));
                
    $allnews $mysidia->db->select("news",array("id"),"");
            }
                
            while(
    $news $allnews->fetchColumn()){
                
    $newsObj = new News($news);
                
    $cells = new LinkedList;
                (
    $newsObj->getPosted() == "yes")? $draft "":$draft "(draft)";
                
    $title "{$newsObj->getTitle()} {$draft}";
                
    $cells->add(new TCell($title));
                
    $cells->add(new TCell($newsObj->getUserObject()->getUsername()));
                
    $cells->add(new TCell($newsObj->getDate()));
                
    $cells->add(new TCell(new Link("admincp/news/edit/{$news}","Edit")));
                
                
    $form = new Form("title","","post");
                
    $form->add(new Button("Save As Draft","submit",$news));
                
    $form2 = new Form("title","","post");
                
    $form2->add(new Button("Publish","submit1",$news));
                
    $form3 = new Form("title","","post");
                
    $form3->add(new Button("Delete","submit2",$news));
                        
                (
    $newsObj->getPosted() == "yes")? $cells->add(new TCell($form)) : $cells->add(new TCell($form2));
                
    $cells->add(new TCell($form3));
                
    $cells->add(new TCell(new Link("admincp/news/viewcomments/{$news}","View Comments")));
                
    $cells->add(new TCell(new Link("news/view/{$news}","View News On Site")));
                
    $pagesTable->buildRow($cells);    
            }
            
            
    $document->add($pagesTable);
            
    $document->add(new Comment("<a href='/admincp/news/create'>Create</a>",TRUE));
           
        }
        
        public function 
    viewcomments(){
            
    $mysidia Registry::get("mysidia");
            
    $document $this->document;
            
    $document->setTitle("editing comments");
            
    $news $this->getField("news");
            
            
    $newsComments $news->getComments();
            
            
            
    $pagesTable = new TableBuilder("news");
            
    $pagesTable->setAlign(new Align("center""middle"));
            
            
    $pagesTable->buildHeaders("Author""Date""Content""Edit""Delete");
            
            if(
    $mysidia->input->post("submit")){
                
    $document->add(new Comment("Are you sure you wish to delete this comment?",FALSE));
                
    $id $mysidia->input->post("submit");
                
    $form = new Form("title","","post");
                
    $form->add(new Button("Yes","submit2",$id));
                
    $document->add($form);

            }
                        
            if(
    $mysidia->input->post("submit2")){
                    
    $id $mysidia->input->post("submit2");
                    
    //echo $id;
                    
    $mysidia->db->delete("newscomments","id = {$id}");
                    
    $document->add(new Comment("<b>Comment deleted successfully.</b>",FALSE));
                    
    $news $this->getField("news2");
                    
    $newsComments $news->getComments();
            }
                
            while(
    $newsID $newsComments->fetchColumn()){
                try{
                    
    $newsComment = new NewsComments($newsID);
                    
    $cells = new LinkedList;
                    
    $cells->add(new TCell($newsComment->getUserObject()->getUsername()));
                    
    $cells->add(new TCell($newsComment->getDate()));
                    
    $cells->add(new TCell($newsComment->getContent()));
                    
    $cells->add(new TCell(new Link("admincp/news/editcomment/{$newsComment->getID()}","Edit")));
                    
    $form = new Form("form","","post");
                    
    $form->add(new Button("Delete","submit",$newsID));
                    
    $cells->add(new TCell($form));
                    
    $pagesTable->buildRow($cells);
                }
                catch(
    NoPermissionException $e){
                    
                }
                
            }
            
            
    $document->add($pagesTable);
        }
        
        public function 
    editcomment(){
            
    $mysidia Registry::get("mysidia");
            
    $document $this->document;
            
    $document->setTitle("editing comments");
            
    $newsComment $this->getField("newscomments");
            
    $editor $this->getField("editor")->get();
            
            if(
    $mysidia->input->post("submit")){
                    
    $newsComment->setContent($mysidia->input->post("commentcontent"));
                    
    $document->add(new Comment("<b>Edited news comment successfully. Text displayed is the old one.<br></b>",FALSE));
                    
    $newsComment $this->getField("newscomments");
                    
    $editor $this->getField("editor")->get();
            }
            
            
    $document->add(new Comment("Author: {$newsComment->getUserObject()->getUsername()} / Date: {$newsComment->getDate()}",FALSE));
            
    $form = new Form("form","","post");
            
            
    $form->add(new Comment($editor,FALSE));
            
    $form->add(new Button("Submit","submit","submit"));
            
    $document->add($form);
        }
        
        public function 
    edit(){
        
            
            
    //include_once("../inc/ckeditor/ckeditor.php");     
            
    $mysidia Registry::get("mysidia");
                
    //$this->editor = new CKEditor;    
                //$this->editor->basePath = '../../../inc/ckeditor/';
            
    $document $this->document;
            
    $document->setTitle("Edit");
            
            
                
    $news $this->getField("news");
                        
                if(
    $mysidia->input->post("submit")){
                
    /*if(!$mysidia->input->post("newstitle")) throw new BlankFieldException("No title");
                if(!$mysidia->input->post("newscontent")) throw new BlanKFieldException("No content");*/
                
                
    ($mysidia->input->post("allowcomments"))?$allow "yes":$allow "no";
    //NEW!
                
    ($mysidia->input->post("allowmessage"))?$allowM "yes":$allowM "no";
                
                
    $news->editTitle($mysidia->input->post("newstitle"));
                
    $news->editContent($this->format($mysidia->input->post("pagecontent")));
                
    $news->changeAllowComment($allow);
    //NEW!
                
    $news->changeAllowMessage($allowM);
                
                if(
    $mysidia->input->post("submit") == "submitDraft"){
                    
    $news->saveDraft();
                }
                
                else{
                    
    $news->post();
                }
                
    $document->add(new Comment("<b>Successfully changed news.</b>"));
            }
            
            
    $editor $this->getField("editor")->get()->editor("pagecontent"$this->format($news->getContent()));
            
    $form = new Form("title","","post");
            
    $form->add(new Comment("<b>Date</b>:{$news->getDate()} and <b>Author</b>: {$news->getUserObject()->getUsername()} and <b>Published</b>: {$news->getPosted()}"));
            
    $form->add(new Comment("<b>Title</b>:"));
            
    $form->add(new TextField("newstitle",$news->getTitle()));
            
    $form->add(new Comment("<b>Contents</b>:"));
            
    $form->add(new Comment($editor));
            
    $comments = new CheckBox("Allow comments on this news""allowcomments"1"array");
            if(
    $news->getAllowComment() == "yes")
                
    $comments->setChecked("allowcomments");
            
    $comments2 = new CheckBox("Send message to all users notifying about the existence of an update""allowmessage"2"array");
            
    $form->add($comments);
            
    $form->add($comments2);
            
    $form->add(new Button("Save as draft","submit","submitDraft"));
            
    $form->add(new Button("Publish","submit","submitPublish"));
            
    $document->add($form);
            
            
    //echo $mysidia->user->uid;
        
        
    }
        
        public function 
    create(){
            
    $mysidia Registry::get("mysidia");
            
    $document $this->document;
            
    $document->setTitle("Create");
            
            if(
    $mysidia->input->post("submit")){
                
    $todayDate = new DateTime;
                
    //H:i:s
                
    $todayDate->setTimezone(new DateTimeZone('Europe/London'));
                
    $date $todayDate->format('Y-m-d H:i:s');
                
    /*if(!$mysidia->input->post("newstitle")) throw new BlankFieldException("No title");
                if(!$mysidia->input->post("newscontent")) throw new BlanKFieldException("No content");*/
            
                
    ($mysidia->input->post("allowcomments"))?$allow "yes":$allow "no";
                (
    $mysidia->input->post("allowmessage"))?$allowM "yes":$allowM "no";
                    
                
                if(
    $mysidia->input->post("submit") == "submitDraft"){
                                
                
    $mysidia->db->insert("news",array("title" => $mysidia->input->post("newstitle"), "content" => $this->format($mysidia->input->post("pagecontent")), "user" => $mysidia->user->uid"date" => $date"posted" => "no","allowcomment" => $allow"allowmessage" => $allowM));
                }
                
                else{
                                
                
    $mysidia->db->insert("news",array("title" => $mysidia->input->post("newstitle"), "content" => $this->format($mysidia->input->post("pagecontent")), "user" => $mysidia->user->uid"date" => $date"posted" => "yes","allowcomment" => $allow"allowmessage" => $allowM));
                
                    if(
    $mysidia->input->post("allowmessage")){
    //NEW!
                        
    $allusers $mysidia->db->select("users", array("username"), "");
                        
                        
    $today = new DateTime;
                        
    $dateToday $today->format('Y-m-d');
                        
    $messageTitle "Update";
                        
    $messagetext "A new news was posted on the site! Click <a href='/news'>here</a> to view!<br>";
                        
                        while(
    $user $allusers->fetchColumn()){
                            
    $mysidia->db->insert("messages", array("fromuser" => "SYSTEM""touser" => $user"status" => "unread""datesent" => $dateToday"messagetitle" => $messageTitle"messagetext" => $messagetext), ""); 
                        }
                    
                    }
                }
                
    $document->add(new Comment("<b>Successfully changed news. Fill this page again to create a new post. Click <a href='/news' target='_blank'>here</a> to see the news page.</b>"));
            }
            
    $todayDate = new DateTime;
            
    $date $todayDate->format('Y-m-d');
            
    $editor $this->getField("editor")->get();
            
    $form = new Form("title","","post");
            
    $form->add(new Comment("<b>Date</b>:{$date} and <b>Author</b>: {$mysidia->user->username} and <b>Published</b>: No"));
            
    $form->add(new Comment("<b>Title</b>:"));
            
    $form->add(new TextField("newstitle",""));
            
    $form->add(new Comment("<b>Contents</b>:"));
            
    $form->add(new Comment($editor));
            
    $comments = new CheckBox("Allow comments on this news""allowcomments"1"array");
            
    $comments2 = new CheckBox("Send message to all users notifying about the existence of an update""allowmessage"2"array");
            
    $form->add($comments);
            
    $form->add($comments2);
            
    $form->add(new Button("Save as draft","submit","submitDraft"));
            
    $form->add(new Button("Publish","submit","submitPublish"));
            
    $document->add($form);
        }
        
            private function 
    format($text){
             
    $text html_entity_decode($text);
             
    $text stripslashes($text);
             
    $text str_replace("rn","",$text);
             return 
    $text;
        }
    }
    ?>


parayna 12-19-2014 07:46 AM

Thank you IntoRain ^_^

IntoRain 12-19-2014 02:29 PM

Quote:

Originally Posted by parayna (Post 31721)
Thank you IntoRain ^_^

No problem! ^^

MikiHeart 01-16-2015 03:46 AM

I really love your news script. Do you mind if I built on top of it?
I want to add more to it, like the ability to report comments for moderation.

I also have one concern, since the pagination just hides the other news, wouldn't it make the page heavy to load if you have like 100 news with images in each once? Or is it set to load when it's clicked. I don't know much about jQuery.

I also want to addon an archive system. So when a piece of news is a certain age, it will go into the archive, and can no longer be commented.

I also want to add a captcha to help prevent spam.

Kyttias 01-16-2015 10:35 AM

Nah, paginated stuff isn't even pulled to load. Your adopts page is also paginated, past 10 pets or so. I can confirm by right clicking to inspect the source that pets past that number aren't even loaded, so, I assume the same for the news?

MikiHeart 01-16-2015 10:52 AM

I hope so. I can't tell on my local server @.@ Because it loads fast.

Edit: Just a heads up, html can be submitted to the comment form. I tested to see if PHP works, but I couldn't get it to.
This should be roughly tested to make sure no one can put malicious code. @.@


All times are GMT -5. The time now is 03:47 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.