4images Forum & Community

4images Modifications / Modifikationen => Mods & Plugins (Releases & Support) => Topic started by: Rembrandt on September 21, 2013, 06:41:19 AM

Title: [Mod] Category Message Box
Post by: Rembrandt on September 21, 2013, 06:41:19 AM
Hi!

With this modification, it is possible to display a message in a category.
By clicking on the "Close" button a Chookie is saved and the message no longer appears, even with repeated visit the category.
When a new text written the message window is visible again.
The message box text and buttons are configurable via CSS.

Demo (http://entwicklung.vienna-pictures.com/categories.php?cat_id=3)

Required: [Mod]Additional Category fields (http://www.4homepages.de/forum/index.php?topic=31231.0)

1.) Creating a new table field in the database "cat_message":
Code: [Select]
ALTER TABLE 4images_categories ADD cat_message TEXT NOT NULLAlternatively, copy the file "install_cat_message.php" from the Attachment in your root, login as Admin and call it to.

2.) Copy the file "no.png" from the Attachment in templates/your template/images  

3.) search in lang/your Lang/main.php and insert above "?>" :
(Deutsch)

$lang['cat_message']="Nachricht :";

(English)

$lang['cat_message']="Message :";


4.) search in includes/db_field_definitions.php "?>" and insert above "?>" :

$additional_category_fields['cat_message'] = array($lang['cat_message'], "textarea", 0);


5.) search in categories.php:

//-----------------------------------------------------
//--- Clickstream -------------------------------------

insert above:

if($cat_cache[$cat_id]['cat_message']){
  $user_token = "";
  $cookie_token ="4images_catmessage_".$cat_id;
  $cookie_token = $_COOKIE[$cookie_token];
  $message_token = sha1(substr($cat_cache[$cat_id]['cat_message'], 0, 5));
  $user_token = ($message_token != $cookie_token) ? 1:0;

  $site_template->register_vars(array(
    "user_token" => $user_token,
    "message_token" => $message_token
  ));
}


6.) insert in templates/your templates/categroies.html where ever you want:

{if cat_message}
<script type="text/javascript">                    
  function hiddeMsgs(){
    document.getElementById('message_box').style.display = 'none';
  }

  function createCookie(name, value, days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    }
    else var expires = "";
    document.cookie = name + "=" + value + expires + "; path=/";
    hiddeMsgs();
  }
</script>

{if user_token}
<div id="message_box" class="message_box">
  <p class="message_button">
    <a  href="Javascript:createCookie('4images_catmessage_{cat_id}','{message_token}',30);" alt="delete"><img style="border:none;"src="{template_url}/images/no.png"></a>
  </p>
  <p class="message_text">{cat_message}</p>
</div>
{endif user_token}
{endif cat_message}


7.) insert in templates/your templates/style.css :
Code: [Select]
.message_box{
  border:3px solid #000000;
  padding:3px;
  position:absolute;
  width:750px;
  background-color:#ddddee;
  margin:0px auto;
}
.message_text{
  font-family: Tahoma,Verdana,Arial,Helvetica,sans-serif;
  font-size: 14px;
  font-weight:bold;
  color: #000000;
  margin:0px 20px 20px 20px;
  padding:0;
  overflow:visible;
}
.message_button{
  text-align:right;
  margin:0;
  padding:0;
}

mfg Andi
Title: Re: [Mod] Category Message Box
Post by: Jan-Lukas on October 09, 2013, 08:21:54 PM
Perfekt  :lol:

Danke
Title: Re: [Mod] Category Message Box
Post by: Rembrandt on October 09, 2013, 09:28:22 PM
Fein,... noch etwas zur Gültigkeitsdauer der COOKIES, in diesen Mod habe ich die Dauer auf 30 Tage gestellt ('{message_token}',30)).
Das bedeutet wenn der User nach dreißig Tagen die Seite wieder besucht erscheint wiederum das Nachrichtenfenster.
Wenn du die Zeit verlängern oder verkürzen möchtest dann kannst du das im link, Step 6.) im Mod, ändern:
Code: [Select]
<a  href="Javascript:createCookie('4images_catmessage_{cat_id}','{message_token}',30);" alt="delete"><img style="border:none;"src="{template_url}/images/no.png"></a>

mfg Andi