Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Whishlist for the Hollidays... (will make a Donation.. ;) )

Dr_SommerDr_Sommer Dr. of tender Programing ;) ✭✭
edited November 2013 in Vanilla 2.0 - 2.8

OK... thats it.... my humble mini Knowledge of PHP, Javascript and HTML is unable overcome this Hurdles... ;(

So I am searching for a programmer that could help me out here...

_It doesn't need to be perfect, quick & Dirty should also be ok.. ;) _

1. How do I Save and load new Data fields with a new discussion:

I have this Date Field that I would like to save with a new Discussion... if you insert a Date or not, just save the data (when Empty = NULL)
Also I would like to show it when Editing, or in the Discussion Overview...

The Goal of this is to make a external Event Calendar, with the Event Date and the 1st Discussion Text as link:

image

I had this for my PhpBB3, and I urgently need it for Vanilla..

2. Emotify ant the Smilie/Cursor Problem:

If I place the Cursor somewhere in the Text, the Smilies I klick are NOT putted where the Cursor is, there where placed always at the End of the text...
I am Using the Plugin Emotify with the CLEditor

I am willing to pay for helping me here, I would even more be pleased, if you choose a Charity Organization I could send some Money... ;)

To try it out:

http://caba.de/CaBaFoRuM/index.php?p=/discussion/1806/test#latest

Name= testuser

Passw= testuserpass

Thank you for any Help.. ;)

Comments

  • R_JR_J Ex-Fanboy Munich Admin
  • Dr_SommerDr_Sommer Dr. of tender Programing ;) ✭✭

    ThX, R_J... ;)

    I was struggling whit this, till i found a small Syntax in your Plugin:

     'MobileFriendly'=>TRUE; 
    corrected it to
     'MobileFriendly'=>TRUE,
    

    (I corrected it in the Documentation)

    So the plugin is now working, showing the Fields in the Profile...
    But what Controller do I need to show the fields like in the above image, so the Date Field appears just over the Category List?

    Is it the DiscussionController or the DiscussionsController?

    I found this list:

    http://codes-libres.org/apps/vanilla/nav.html?_functions/index.html

    No clue where to start... still puzzling.. ;))

    Thanx.. ;)

  • R_JR_J Ex-Fanboy Munich Admin

    That's what a wiki is made for, thanks for your help!

    Try the awesome eventi plugin (but not on your live installation!) to find out what event you would like to hook. I assume it will be one hook of a discussion view but eventi will show you some possibilities: just activate that plugin and open up a discussion.

  • R_JR_J Ex-Fanboy Munich Admin

    My assumption concerning the discussion view was wrong, but if you've already activated eventi, you've noticed that. I think you would like to hook PostController_BeforeBodyInput_Handler to put the date below the discussion title.

    btw: don't forget to specify your version if you ask. I've seen that it is Vanilla 2.1b2 but not everybody would visit your homepage to look for that.

  • Dr_SommerDr_Sommer Dr. of tender Programing ;) ✭✭
    edited November 2013

    THIS IS SOOO EXITING!!!! Thank You Sooo Much R_J... let me send you an Virtual HUG... ;):)

    As you see, my answers are coming with a big delay... I am working my *** off to understand and to make it work... at the end it's so little code and so simple... ;))

    OK, here is my Code (default.php of Plugin):

    <?php if (!defined('APPLICATION')) exit();
    
    $PluginInfo['CaBaCaLeNDaR'] = array(
       'Name' => 'CaBa Calendar',
       'Description'    => 'CaBa Calendar',
       'Version' => '0.1',
       'Author' => 'CaBa with Help from the mighty R_J',
       'RequiredApplications' => array('Vanilla' => '>=2.0.18'),
       'MobileFriendly'=>TRUE,
       'RequiredTheme' => FALSE, 
       'RequiredPlugins' => FALSE,
       'License' => 'GPLv2'
    );
     class CabaCalendar extends Gdn_Plugin
    {   
       // add column on enabling plugin
       public function Setup()  {
          Gdn::Structure()->Table('Discussion')
             ->Column('cabacalendardate', 'varchar(10)', TRUE)
             ->Set(FALSE, FALSE);
       }
    
       // add input field to edit profile
       public function PostController_BeforeBodyInput_Handler($Sender) {
       echo '<div id="cabacalendardatediv">';
       //echo $Sender->Form->CheckBox('cabacalendardatecheck');
       echo $Sender->Form->Label(T("CaBa Eventdatum:"), 'cabacalendardate');
       echo $Sender->Form->TextBox('cabacalendardate', array('class' => 'inputcabaeventdate'));
     echo '</div>';
       }
    
    }
    

    This is working flawlessly... It inputs the Dates and show them again, when Edited... ;)

    here is the ALPHA Version of the Calendar:
    http://www.caba.de/CaBaFoRuM/plugins/CaBaCaLeNDaR/Calendar/kalenderindex.php

    I do still have issues, one of the biggest is, that when i do not enter any DATE into the input field, it saves as "0000-00-00" into the Database...
    and then, when I stop XAMPP, it will not start again!!! MySQL will not Start!!!

    So I left it as "Varchar" in my online forum...

    I reinstalled XAMPP/Vanilla and put the DEFAULT Value of the date "1900-01-01", but it still saves "0000-00-00" when nothing is insertd in the Date Field of the Form.

    I can't use VarChar, because I need to Order by Date.....

    Is there a way to validate the inputs, before they are saved??

    Thanks again, you saved my day... ;)

    p.s.: Yes, you're absolutley Right... usually I always specify the Vanilla Version and the Browsers I'm using, this time I forgot..;)

    p.p.s.: Please tell me a Charity Organization of your choice, so i could donate something to them.. thx.. ;)

  • R_JR_J Ex-Fanboy Munich Admin

    I also love the simplicity and I think that is what Garden really makes a great framework!
    There are some things that come to my mind when looking at your code:
    1. line 23 should be updated or deleted ;)
    2. you will learn a lot about what is possible if you look at the source code! Get a local copy of your forum and then search in that files for "function column". You'll find the documented function and you'll see that you can give default values to columns when you create them. So you could change ->Column('cabacalendardate', 'varchar(10)', TRUE) to ->Column('cabacalendardate', 'varchar(10)', '1900-01-01') 3. you've already planned to use a flag in order to tell if a discussion is an event or not but that line is commented out. Create a column for that information (I think there is no boolean datatype so use tinyint). Depending on the state of that checkbox you can show or hide the date input field with javascript. 4. It might look nicer to have that controls below the message window, because there will be more discussions than events, but I'm not sure about that... 5. You've started to make your plugin translatable, that's great! (You've used the function T(), if you don't know yet, what I'm talking about). But the Label function translates automatically. I have not known that when I wrote the wiki article so that should be changed there. I would write the plugin in English (just because it is Vanillas default language) and make a translation file for yourself. To make your plugin translatable, you have to add'HasLocale' => TRUE,to the plugin info array. Create the fileCaBaCalendar/locale/de-DE/definitions.php` with following content:

    <?php if (!defined('APPLICATION')) exit();
    
    $Definition['CaBa Event Date:'] = 'CaBa Eventdatum:';
    

    and change echo $Sender->Form->Label(T("CaBa Eventdatum:"), 'cabacalendardate'); to echo $Sender->Form->Label('CaBa Event Date:', 'cabacalendardate');
    6. Validation. Search for "function addrule" and "function applyrule". In general, you will have to add a new rule to the validation of the controller and afterwards apply it. But there is a standard rule called "Date" so you even do not have to add that rule. Just apply the standard rule to your field: $Sender->Validation->ApplyRule('cabacalendardate', 'Date', T('You have to enter a date.'));
    7. And after all that, try to follow the Vanilla conventions concerning variable names: make the column names CabaCalendarDate and CabaCalendarDateCheck.

  • Dr_SommerDr_Sommer Dr. of tender Programing ;) ✭✭

    Uh... I see... bye bye sleep, bye bye marvelous days of eating chips and watching TV while gently fondling my stomach ... :D:D:)

    Ok, I'll try 2 work off your list... ;)

    Till then, I played on the Calendar Style... looking gooooddd.... :D:D:D

    To try it out you have to first login to the Forum::

    http://caba.de/CaBaFoRuM/index.php?p=/discussion/1806/test#latest

    Name= testuser
    Passw= testuserpass

    and then the Calendar:

    http://www.caba.de/CaBaFoRuM/plugins/CaBaCaLeNDaR/Calendar/kalenderindex.php

    or just look the Attachement.. ;)

    I integrated an onklick event, so the rows show the 1st Disscussion on klick.. ;)

    p.s.: Donation is on the way.. ;)

  • R_JR_J Ex-Fanboy Munich Admin

    There are two checkboxes now.
    You have $PluginInfo['CaBaCaLeNDaR'] but class CabaCalendar extends Gdn_Plugin. I'm not sure if anything there is case sensitive, but it should be consistent.

    Here are some snippets you might find useful for your plugin:

    If you want a sexy link to your calendar, you can set up a custom route. You can make the link dynamic if you make it translatable. Admins would only need to translate CalendarLink in order to set up the custom url where the calendar could be accessed (last line refers not to Plugin but to Vanilla, I'll come to that later)
    Credits go to x00. The following code is a shortened version of something I've seen in his source code

       public function Base_BeforeLoadRoutes_Handler($Sender, $Args){
          $Slug = '^'.T('CalendarLink', 'calendar').'(/.*)?$';
          $Route = str_replace('_','/',base64_encode($Slug));
          $Args['Routes'][$Route] = array('Vanilla/CaBaCalendar$1','Internal');
       }
    

    That function will add a link to your menu with the function AddLink($Group, $Text, $Url...

       public function Base_Render_Before($Sender) {
          if ($Sender->Menu) {
             $Sender->Menu->AddLink(T('Calendar'), T('CaBaCaLeNDaR'), T('CalendarLink', 'calendar'));
          }
       }   
    

    If you want your plugin to render on a page that looks like it is vanilla, make it a vanilla page! Don't create your index from Plugin controller (because you will have to start from zero) but from Vanilla controller.
    The following code sets up a default page, adds all standard css and your custom css and js files and a few modules to the sidebar. It sets the breadcrumb, gets the discussion data from database and calls the view you need. You can access the results you've stored with $Sender->SetData('CabaCalendarEvents', $Result); in your view with $this->Data('CabaCalendarEvents')

       public function VanillaController_Calendar_Create($Sender, $Args) {
          $Sender->ClearCssFiles();
          $Sender->AddCssFile('style.css');
          $Sender->AddCssFile('cabacalendar.css', 'plugins/CabaCalendar');
          $Sender->AddJsFile('cabacalendar.js', 'plugins/CabaCalendar');
    
          // render a normal vanilla page
          $Sender->MasterView = 'default';
    
          // Add modules
          $Sender->AddModule('NewDiscussionModule');
          $Sender->AddModule('CategoriesModule');
          $Sender->AddModule('BookmarkedModule');
    
          // Set Breadcrumbs. Try leaving out the outer array - I'm not sure about that
          $Sender->SetData('Breadcrumbs', array(
             array('Name' => T('CabaCalendar'), 'Url' => T('CalendarLink', 'calendar'))));
    
          // maybe useful for SEO
          $Sender->CanonicalUrl(Url('index', TRUE));
    
          // get discussions from db
          $Query = GDN::SQL();
          $Query->Select('d.DiscusssionID, d.CategoryID, d.Name, d.Body, d.CabaCalendarDate') // add whatever fields you need
             ->From('Discussion d')
             ->Where('d.CabaCalendarDateCheck', '1');
    
          // use permissions for categories
          $Perms = DiscussionModel::CategoryPermissions();
          if ($Perms !== TRUE) {
             $Query->WhereIn('p.CategoryID', $Perms);
          }         
    
          // fetch results from db
          $Result = $Query->Get()->ResultArray();      
    
          $Sender->SetData('CabaCalendarEvents', $Result);      
    
          // render view
          $Sender->Render('index', '', 'plugins/CabaCalendar');
       }
    

    I have not fully tested anything of that, but simply copied most of it from a calendar plugin I was just about to write by myself and changed it in a way I think that could be helpful for you. So there might be some adjustments necessary...

  • Dr_SommerDr_Sommer Dr. of tender Programing ;) ✭✭
    edited November 2013

    Wow... you're killing me, Brother.. hehe.. i like it.... :D:D:)

    Please be patient with me, I'm slow as Hell... If my Mother could see my Code She would say: "This crap looks like your room... dirty, messy and full of Girls lingerie!!!" :):D:)

    I Integrated all my Stuff from PhpBB, like the "Dabeier" (affiliate system) ,the Table (for planning) and linked the Calendar to the Discussions... quick and Dirty of course... ;)

    http://www.caba.de/CaBaFoRuM/plugins/CaBaCaLeNDaR/Calendar/kalenderindex.php

    Now let me do it step by step:

    the first thing is the checkbox:

    How do I integrate a "onklick" Event to Show/Hide the Data Field?

    I had this working, but Wrong of course... :)

    I put this into my Theme>view>post>discussion.php :

    echo '<input type="checkbox" id="CheckDabei" name="CheckDabei" value="x" onClick="DatumVisible(); " /> CaBa Event? <span id="DatumInput">';
    echo '<input type="text" id="quantity" size="15"  name="quantity" /> (Event Datum eingeben!)</span>';
    

    And Javascript:

    <script type="text/javascript">
        function DatumVisible() {
            var checkbox = document.getElementById("CheckDabei");
            var datumfeld = document.getElementById("DatumInput");
            if(checkbox.checked == false){
                 datumfeld.style.display = 'none';
            }else if(checkbox.checked == true) {
                 datumfeld.style.display = 'inline'; // or block
            }
        }
    
    </script>
    

    How can I do this with the Checkbox, generated with Garden Framework??

  • Dr_SommerDr_Sommer Dr. of tender Programing ;) ✭✭
    edited November 2013

    Second Question:

    When starting a new discussion, the new DATE Input field allows only "YYYY-MM-DD" Format....
    How can I set it to accept German Format like "MM.DD.YYYY" ??

    ThX.. ;)

    These are the 2 Questions, that I have to solve soon... after that there will be no confusion among my Users and I can concentrate on "Pluginfying" the Calendar... :):D

  • R_JR_J Ex-Fanboy Munich Admin

    That's the HTML of your new discussion page right now:

    <div id="CabaCalendarDatediv">
       <input type="checkbox" value="1" name="CabaCalendarDateCheck" id="Form_CabaCalendarDateCheck">
       <input type="hidden" value="CabaCalendarDateCheck" name="Checkboxes[]">
       <label for="Form_CabaCalendarDate">CaBa Eventdatum:</label>
       <input type="text" class="inputcabaeventdate" value="" name="CabaCalendarDate" id="Form_CabaCalendarDate">
    </div>
    

    Make it something like this:

    <div id="CabaCalendarContainer">
       <label for="Form_CabaCalendarDateCheck">CaBa Event:</label>
       <input type="checkbox" value="1" name="CabaCalendarDateCheck" id="Form_CabaCalendarDateCheck">
       <input type="hidden" value="CabaCalendarDateCheck" name="Checkboxes[]">
       <div id="CabaCalendarDateContainer">
          <label for="Form_CabaCalendarDate">CaBa Eventdatum:</label>
          <input type="text" class="inputcabaeventdate" value="" name="CabaCalendarDate" id="Form_CabaCalendarDate">
       </div>
    </div>
    

    The most cleanest way (to my opinion) would be to ceate a script, that will set/delete a class to CabaCalendarDateContainer depending of the state of the checkbox.
    So you will need a CSS and a JS file. Create yourplugin/design/yourplugin.css and yourplugin/js/yourplugin.js.

    Your CSS file should have something like that:

    .cabadatehidden{display:none}
    

    When you look at the sourcecode of a new discussion, you'll find the id of the Checkbox: Form_CabaCalendarDateCheck. So you'll have to create a script that will check if the class of the input box is set, delete it if yes and set it if no. The script you've posted doesn't use jQuery. If you know that you have to access to a library, you could use it's functions. jQuery is a library and as such slower than plain js, but you don't have to speed optimize that so using jQuery keeps the source small and readable:

    $('#Form_CabaCalendarDateCheck').change(function() {
       if ($(this).is(':checked')) {
          $('#CabaCalendarDateContainer').removeClass('cabadatehidden')
       } else {
          $('#CabaCalendarDateContainer').addClass('cabadatehidden')
       }
    });
    

    You'll have to add CSS an JS file to your source.

    public function PostController_BeforeBodyInput_Handler($Sender) {
    
    $Sender->AddCssFile('yourplugin.css', 'plugins/yourplugin');
    

    JS might be more complicated because I think it must be added after the DOM tree was built, but visitors arrived right now, so I have to stop now...

  • R_JR_J Ex-Fanboy Munich Admin

    That happens when you don't look at what you have written... Quote my post to see the html I've used above.

    Save that to your yourplugin.js:

    $('#Form_CabaCalendarDateCheck').on('change', function() {
       if ($(this).is(':checked')) {
          $('#CabaCalendarDateContainer').removeClass('cabadatehidden')
       } else {
          $('#CabaCalendarDateContainer').addClass('cabadatehidden')
       }
    });
    

    Add the following line to your public function PostController_BeforeBodyInput_Handler($Sender) {

        $Sender->AddJsFile('yourplugin.js', 'plugins/yourplugin');
    

    That should make it possible to toggle your event date input fields visibility

  • R_JR_J Ex-Fanboy Munich Admin

    The German date is a problem, I think. You can validate it with that function (it is just a slight modification of the validation that's used for the standard "Date" rule):

    function ValidateGermanDate($Value) {
       // Dates should must be DD.MM.YYYY
       if (empty($Value)) {
          return TRUE; // blank dates validated through required.
       } else {
          $Matches = array();
          if(preg_match('/^(\d{2}).(\d{2}).(\d{4})$/', $Value, $Matches)) {
             $Day = $Matches[1];
             $Month = $Matches[2];
             $Year = $Matches[3];
    
             return checkdate($Month, $Day, $Year);
    // I'd even add something like an additional date check to test if the date is in a defined period.
          } 
       }
    
       return FALSE;
    }
    

    But you have to use it in a custom rule: $Sender->Validation->AddRule('GermanDate', 'function:ValidateGermanDate'));and afterwards you can apply that rule $Sender->Validation->ApplyRule('cabacalendardate', 'GermanDate', T('You have to enter a date.'));

    Maybe anyone else can help with that:

    I think you'll have to use input as a string in the database, which is not very desirable. I don't know a way to accept "DD.MM.YYYY" as input for a date column.

    If there will be no other solution, you could think of giving the user 3 drop down fields day|month|year to choose the date from

  • Dr_SommerDr_Sommer Dr. of tender Programing ;) ✭✭

    ThX, R_J, will look into that as soon as possible... ;)

    Had to do some Sports over the Weekend, Work is twisting my hairstyle AND have to Compose a Song for the Holidays, so muuuuuch to do but Time is lacking... ;( :D

    For now, the CaBaCaLeNDaR it is really looking good... from the outside... :D
    Inside is messy Coding, but I'll Clean that up before Pluginning it.. ;)

    image

    image

    What about the others of the Vanilla Community? Is there a need for such kind of Calendar ?
    Asking just out of interest.. ;)

Sign In or Register to comment.