We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 16278
    • 928 Posts
    OK, so here’s the recipe I have tested for adding a second tagging TV. I’m not sure it’s the best way - I suspect it would be both feasible and more elegant to let the &tags parameter be an array, and loop through that in the main include file. But for now, this way adds a second tag set without too much change to the code:

    1) Create your second tagging TV, which can be radio options, checkbox, or a selection list. I called mine pkTagsPlus, and I’ve tried it with each of these types.
    Note: to use a multiple selection list, a couple of lines must be corrected in optionsbuilder.class.inc.php
    /* 	old code, lines 75-76
    		$output .= '<select multiple id="' . $this->setName . '"';
    		$output .= ' name="' . $this->setName . '"' . $class . ">\n";
    */
    // replace with:
    		$output .= '<select multiple="multiple" id="' . $this->setName . '"';
    		$output .= ' name="' . $this->setName . '[]"' . $class . ">\n";
    


    2) Set up the relevant field in your input form, using a different name from the TV.
    <fieldset id="tagsPlus"><legend>TagsPlus</legend>[+tagsPlus+]</fieldset>


    3) In your item class:
    3.1) Add the TV’s name to the list in the tvs array:
    	public $tvs = array(
    	    'pkDate' => NULL,
    		     .....
    	    'pkTagsPlus' => NULL
    	    );
    

    3.2) Expand the constructor function to read the value of the field on postback; create an OptionButtons object from the TV; generate suitable HTML tags for the options set or list (using optionsBuilder); and set the placeholder for it
    function __construct($pid, $fields, $lang) {
    	global $modx;
    							.......
    	$this->tvs['pkTagsPlus'] = $fields['tagsPlus'];
    
    	$this->tags2 = new OptionButtons('pkTagsPlus', 'tagsPlus');
    
    	if (is_array($fields['tagsPlus'])) {
    	    $tagsArray = $fields['tagsPlus'];
            } else {
          	    $tagsArray = array($fields['tagsPlus']);
            }
    
    	$selectTag = $this->tags2->buildset($tagsArray);
    	$modx->setPlaceholder('tagsPlus', $selectTag);
    							.......
    

    3.3) Expand the customFields function to retrieve the TV value on re-edit and set a placeholder for it
    function CustomFields($fields, $doc) {
    	global $modx;
    							.......
            $tagsPlusArray  = explode('||', $fields['pkTagsPlus']);
    	$modx->setPlaceholder('tagsPlus', $this->tags2->buildset($tagsPlusArray));
    							.......
    

    4) In pubKit.inc.class.php, around lines 458-462, test for existing placeholders in the loop that sets a placeholder for each field name (to preserve the one set by the item object)
    	foreach($fields as $n=>$v) {
    		if (is_string($v)) {
    	        $v = htmlspecialchars($v);
    		}
    // set placeholders for any fields not already set (e.g. extra tags postback)
    		$ph = $modx->getPlaceholder($n);
    		if (empty($ph)) {
    			$modx->setPlaceholder($n, $v);
    		}
    	}
    


    Hope this does what is required.
    laugh KP
      • 22427
      • 793 Posts
      Hi all,
      admitting not to have much experience in PHP, I am confused about the formatting of date values.

      Having modified the pubKit templates for my needs, in the input form for news I suddenly got the error message that my date format was incorrect. It should be [tt]29 Nov 10[/tt] , but it was [tt]29 Nov 2010[/tt] . That latter date was not entered by me, it was the actual date which automatically shows up in the Date input field. And changing it to the wanted form did not solve the issue: the error message remained.

      In the file [tt]pubKit.functions.php[/tt] I found a comment saying that the function [tt]DateValid[/tt] is not used in PubKit. So why I got that error message?

      In the following I tried to display the date values in the Form [tt]2010-11-29[/tt] . For that reason I changed line 6 of the file [tt]pubKit/lang/english.inc.php[/tt] to
      	'dateFormat' => '%Y-%m-%d',
      
      and line 23 I changed to
      	'err_dateFormat' => 'Date format is incorrect; use ' . strftime('%Y-%m-%d'),
      

      Nevertheless (and to my irritation ) I had to modify the TV [tt][+pkDate+][/tt] in the pubKit templates (f. i. in [tt]pk.news.main.tpl[/tt] and in [tt]pk.news.manage.tpl[/tt] ) - I had to write [tt][+pkDate:date=`%Y-%m-%d`+][/tt] ; otherwise the unformatted integer time stamp would show up.

      But (again to my irritation) the TV [tt][+displayDate+][/tt] f.i. in [tt]pk.ConfirmDeletion.tpl[/tt] displays already formatted; when I tried to modify it to [tt][+displayDate:date=`%Y-%m-%d`+][/tt] I got the formatted output of the time stamp 0, that is [tt]1970-01-01[/tt] .

      There remains no unsolved problem - I just would like to understand what’s going on.

      Kind regards
      ottogal
        • 16278
        • 928 Posts
        Hmmm, yeah, I find dates confusing as well, but I hope this will clarify things a little:

        The date validity check is carried out in the class definitions. For a news, blog or event item in the package, it’s in the Resource class defined in resource.class.inc.php. The routine in the functions file is there for compatibility with pkBlog, the forerunner to PubKit.
        			case 'date':
        			if ($features[1] == 'Req' && strlen($fields[$field]) < 1) {
        				$errors[] = $lang[$features[2]] . ': ' . $lang['err_blank'];
        			}
        			elseif (!empty($fields[$field])
        				AND strtotime($fields[$field]) === FALSE) {
        				$errors[] = $lang[$features[2]] . ': ' . $lang['err_dateFormat'];
        			}
        			break;
        

        So, a date field that is specified as "required" in the item type’s "validate" array must not be blank, and must evaluate to something other than False when fed to the PHP strtotime() function. (This assumes PHP 5.1 or later; you’d need to check for -1 as a bad format in earlier versions). In fact, you can input anything that the function sees as valid, regardless of the setting in your language file’s format string.

        The string that comes back in the error message does need updating to the 4-digit year for my own preferred format - I just find it clearer now that we’ve gone beyond "09" for 2009. It should match whatever you have in the dateFormat string. I plumped for %d %b %Y as an unambiguous date format to prompt for.

        When an error is detected, the date field just comes back as previously entered, as POST data. When the form is displayed for re-editing (returning from the preview, or from the management list), the format string from your language file is applied to it in the constructor function of the item type’s class file. The &debug=`1` parameter is quite handy when you’re sorting this kind of thing out.

        Re the confirm deletion template, this is actually an alternative form to the new/re-edit input form. The one in the package has only placeholders for title and headline fields. If you want to add a date, you’ll need to use a custom delete confirmation form. Have a look at event.class.inc.php to see how that is handled.

        pk.news.main.tpl and pk.news.manage.tpl are pure Ditto tpl chunks - they know nothing of the settings in the PubKit files, hence the need to use PHx rules to convert the dates. I dare say you could include snippets at this point (maybe some custom PHx modifiers) to keep all the date formats in line, but it would add to the complexity (isn’t it complex enough already???). I also tend to build from the output backwards - that is, create items by hand and get them to display as I want, then add the PubKit input and management functions to make routine operation easier.

        Hope this helps soothe your nerves
        grin KP
          • 22427
          • 793 Posts
          Many thanks, KP, for the quick reply and the detailed explanations - it’s much clearer now for me.
          Have a nice weekend!
          ottogal
            • 22427
            • 793 Posts
            I have got an issue with the rich-text TV for the news body (likely an issue not with PubKit but with TinyMCE). If I reedit an already published news item in the Manage news items page and click the Publish button, the news content will be bracketed by empty paragraphs, that is one <p></p> at the beginning and one <p></p> at the end. May be it’s a question of the TinyMCE configuration - but not of the parameter force_root_block which is set to false (it’s not a <p>...</p> pair bracketing the content). Any idea?
            Thanks in advance
            ottogal
            Edit: Same effect clicking the Preview button.
            MODx 1.0.4
            TinyMCE 3.3.2
              • 22427
              • 793 Posts
              Found something. The default content of the rich-text TV, [tt][+newsBody+][/tt] , was formatted as paragraph, so the code became [tt]<p>[+newsBody+]</p>[/tt] .
              So republishing it this would be token as the actual value of [tt][+newsBody+][/tt] .
              I assume that the syntactically incorrect result [tt]<p><p>[+newsBody+]</p></p>[/tt] is automatically corrected by TinyMCE, inserting the "missing" parts of the p-tags.
              Tank you, anyway.
                • 7807
                • 5 Posts
                Hello all

                I am having a problem with TinyMCE when using PubKit. When posting from the front end of the site I can’t post video’s using the TinyMCE media button. No errors, but the video never posts. TinyMCE works fine when logged in through the manager. Any ideas on what I am doing wrong?

                Thank you


                p.s. I am using Modx 1.0.4 with TinyMCE 3.3.5.1 Javascript WYSIWYG Editor


                Ok I found the answer to my own question. It only took 3 days. After looking through the Pubkit Snippet code I found the lines
                // define tags that can be used in rich content
                $allowedTags =  '<p><br><a><i><em><b><strong><pre><table><th><td><tr><img>';
                $allowedTags .= '<span><div><h1><h2><h3><h4><h5><font><ul><ol><li><dl><dt><dd>';
                
                . I was missing <embed>,<object>. I just added and it seems to work.

                Thanks for your help.

                wink