Topic: PubKit: 0.6.4 (02 Jul 10): front-end document and record creation and management  (Read 1711 times)

Pages: [1] 2  All   Go Down

#1: 7-Jun-2010, 08:35 AM


kp52
Posts: 541

WWW
At last I have managed to put together a package and some documentation for PubKit, a snippet for creating and publishing MODx documents using front-end web page forms. Full details and download are available at http://www.pogwatch.com/pubkit.html, or you can download from here with less documentation.

Though I have used various elements of PubKit on live sites, I'm classing it as beta software, and would like to have some feedback before publishing to the MODx Extras repository.

PubKit goes beyond the capabilities of its predecessor pkBlog. Key features include:
- PHP classes define types of item, so a variety of formats can be defined without fiddling with the core code;
- classes permit you to create specialized methods and properties for specific types of item, e.g. data validation;
- possibility of using custom tables as well as MODx resources as the basis of your item (you still need to create the tables with phpMyAdmin or a MODx module);
- update any built-in or custom template variable using the snippet (in the sample files, set or clear the published field or an archive flag from the management list);
- hooks to use different language files for prompts and error messages

I know there's still plenty that could be improved - including better safeguards against item duplication (if you use Back from the preview), and simple arrangements to cater for multiple-author blogs. And there are plenty of comments in the code starting "TO DO...". All the same, I hope you'll find it worth a try, and let me know how you get on.
 Cool KP

* PubKit-0.6.4.zip (121.38 KB - downloaded 18 times.)
* changelog.txt (0.93 KB - downloaded 22 times.)
« Last Edit: 2-Jul-2010, 11:43 AM by kp52 »

#2: 7-Jun-2010, 03:49 PM

Coding Team

sottwell
Posts: 12,652

WWW
Great! I've been looking forward to this. PKBlog has been very useful, but there's so many hard-coded presumptions in it (like required fields) that I've had to modify  Tongue
How MODx Works
Log in to an Evo Manager username guest, password guestuser.

#3: 14-Jun-2010, 07:02 PM

apcherry
Posts: 48

WWW
Hi,

It looks very promising. I'm trying to set up a site where various area groups can post the latest news from their neck of the woods. Most of them would be put off by the modx backend manager for creating new reports. A simple front end web page for them to stick in a few updates would be ideal - is this something that PubKit could do?

I can edit the backend code myself but I'm trying to get something easy for the non-technical users could be comfortable with. Is their a demo site so that I could see how PubKit works for adding new articles?

Regards

Adrian
 

#4: 14-Jun-2010, 11:22 PM

Coding Team

sottwell
Posts: 12,652

WWW
I haven't had the opportunity to look at PubKit, but I have used PubKitBlog for this. We set up an unpublished page to act as the front-end Manager (logged-in manager users can see unpublished pages) and set its ID as the login home ID for the Manager users involved. We also added that page as a custom link in QuickManager. That front-end Manager page had links to the various resources (in an unpublished Tools container/document) where a customized PubKitBlog was installed for editing/creating the relevant resources. Between that and using Jot (or a customized hack of it I call Notes) for simpler lists of things (like events, FAQ question/answer lists, or restaurant menus) the client never needs to see the back-end at all.
How MODx Works
Log in to an Evo Manager username guest, password guestuser.

#5: 15-Jun-2010, 03:52 AM

apcherry
Posts: 48

WWW
Thanks for the info - I'll have a deeper look at PubKit then.
Adrian

#6: 15-Jun-2010, 07:39 AM


kp52
Posts: 541

WWW
Quote
A simple front end web page for them to stick in a few updates
was my starting point, too!

I've hacked pkBlog around for various purposes, but you need to get to know the main entry points and places where data changes to do that. The main point of PubKit is to make customization separate from the core processing loop, consigning site-specific aspects to PHP classes when they're not catered for by parameters. This approach has also made it possible to handle custom tables in a similar way, from a single snippet, though with different include files for the CRUD business.

Quite a few queries about PubKitBlog have concerned multiple-user scenarios (I haven't had to provide any myself as yet). I'm sure the necessary arrangements can be made, if you get a good idea early on as to likely numbers of users, and how segregated you need them to be when it comes to the control panel (management screen) - should users be able to view others' lists and publish/depublish/update/delete etc. others' posts?

Incidentally, publish/depublish from the management screen is another frequent request for pkBlog, easy to achieve in PubKit.

A small update to PubKit is in the pipeline - main change fixes a bug with event listings, so that single-day events automatically get the next day as depublication date. It also adds possibility of ranking resource-based items by menuindex for ordered lists.

 Smiley KP

#7: 15-Jun-2010, 08:47 AM

apcherry
Posts: 48

WWW

Quite a few queries about PubKitBlog have concerned multiple-user scenarios (I haven't had to provide any myself as yet). I'm sure the necessary arrangements can be made, if you get a good idea early on as to likely numbers of users, and how segregated you need them to be when it comes to the control panel (management screen) - should users be able to view others' lists and publish/depublish/update/delete etc. others' posts?

Incidentally, publish/depublish from the management screen is another frequent request for pkBlog, easy to achieve in PubKit.

Thanks for the info - it looks promising. We're a small but happy and social group of modellers just posting updates from around the country. We have area group representatives who I envisage will do the updates so probably no more than a dozen users adding entries. Each will probably just look after their own postings but I've often found that the game plan has to change once you let the users loose on the system! So who knows.

Never considered the depublish option before but I can see how that can be useful.

Regards

Adrian

#8: 24-Jun-2010, 12:57 PM


sharkbait
Posts: 2,045

Hey Keith,

downloaded the package ... and WOW! you've put a lot of hard work into it Shocked just wanted to say thank you!! // need to play with it. that's a lot of code in there! Smiley

pagination works via Ditto? if so, also with custom DB tables? ...and this is for WebUsers/Groups, right?
« Last Edit: 24-Jun-2010, 01:14 PM by sharkbait »

#9: 29-Jun-2010, 03:12 PM

pixelstation
Posts: 41

Hi kp52

Ok I have a few questions. Im trying to setup a blog but for multiple webusers to have their own blog items. I therefore need to be able to store the name of the author i.e. username of the webuser that is logged in. I made these changes to postblog.class.inc.php (a copy of post.class.inc.php) however it is not working. I was trying to follow the documentation with exactly what I need to do for custom fields and was not particularly understanding it.

Code:
<?php
class Postblog extends Resource
{
public $defaultDate// set using function in constructor
       
public $authorPost// <-- added line

public $tvs = array(
'pkDate'=>NULL,
'pkDateTo'=>NULL,
              
'authorPost'=>NULL // <-- added line
);

public $validate = array(
'pagetitle'=>'string||Req||title',
'longtitle'=>'string||Req||postHeadline',
'tvpkRichContent'=>'string||Req||postContent',
'displayDate'=>'date||Req||displayDate',
'displayFrom'=>'date||Opt||fromDate',
'displayTo'=>'date||Opt||toDate'
);

function 
__construct($pid$fields$lang) {
$this->defaultDate strftime($lang['dateFormat']);
       
$this->authorPost $_SESSION['webShortname'];     // <-- added line
$this->tvs['pkPreviewFlag'] = (isset($fields['preview'])) ? 1:0;
parent::__construct($pid$fields$lang);
}

function 
CustomFields($fields$doc) {
$customFields = array();

    
$customFields['displayDate'] = strftime($this->lang['dateFormat'], strtotime($fields['pkDate']));
    
$customFields['displayTo']   = ($fields['pkDateTo'] > 0) ?
strftime($this->lang['dateFormat'], strtotime($fields['pkDateTo'])) : "";
    
$customFields['displayFrom'] = ($doc->Get('pub_date') > 0) ?
strftime($this->lang['dateFormat'], $doc->Get('pub_date')) : "";

return $customFields;
}

}
?>

« Last Edit: 29-Jun-2010, 03:54 PM by pixelstation »

#10: 2-Jul-2010, 01:27 AM

idoremus
Posts: 18

This looks like a great package. I carefully installed all the TV's, Snippets, Chunks, etc. for the basic blog page demo. I am getting the basic functionality but there are a couple things that crop up.

1). In the blog post, the single and double quotes are getting escaped. For example She said "stop." turns into, she said \"stop.\"

2). Posts that were made prior to installing PubKit show a creation date of 1969 (not a big deal, just an observation).

3). I am unable to get dates from either [+pub_date:dateIfSet=`%d-%m-%y`+] or [+pkDateTo:dateIfSet=`%d-%m-%y`+], even when set when the post was published.

4). In the document tree, when logged in as Administrator, I am unable to look at any of the new documents, created from PubKit, from the backend. I am told "You don't have enough privileges for this action!"

5). Will there be an option in the future to edit and re-save a post without re-publishing the post (making a duplicate)?

Suggestions?

Thanks for all the work, Ian
« Last Edit: 2-Jul-2010, 01:42 AM by idoremus »

#11: 2-Jul-2010, 03:59 AM


kp52
Posts: 541

WWW
I think some PHP/MODx issues are interfering here:
Quote
1). In the blog post, the single and double quotes are getting escaped. For example She said "stop." turns into, she said \"stop.\"
This is down to PHP "magic quotes" being enabled. It will seriously intefere with any form processing, and is highly undesirable in any up-to-date PHP setup. If you have access to your php.ini file, insert the line
Code:
magic_quotes_gpc = Off
to disable it. There are quite a few threads on this issue in the forum, including other ways to switch it off if you are not able to use php.ini.

Quote
2). Posts that were made prior to installing PubKit show a creation date of 1969.
If you're using pkDate as the item date, and it's empty, you get a zero result as the timestamp, or 0000 on 1st Jan 1970 (slipping back to 2300 31 Dec 1969 because of DST). I haven't tried it, but if you set a default date for pkDate that might give you something more credible; or you may be able to use the DocManager module to set some values in the TV en masse.

Quote
3). I am unable to get dates from either [+pub_date:dateIfSet=`%d-%m-%y`+] or [+pkDateTo:dateIfSet=`%d-%m-%y`+]
Are you sure you have named the PHx modifier snippet correctly (phx:dateIfSet)? What output do you get with an unmodified placeholder such as [+pub_date+], or the built-in PHx modifier [+pub_date:date=`%d-%m-%y`+]?

Quote
4). In the document tree, when logged in as Administrator, I am unable to look at any of the new documents

Not sure about this, but it sounds like a MODx installation issue - try searching for the error message.

Quote
5). Will there be an option in the future to edit and re-save a post without re-publishing the post (making a duplicate)?
This should be the standard action already! Opening the page containing your PubKit call (e.g. post-edit.html) with ?docId=99&command=edit as the query string or equivalent POST values should mean you are reediting document 99. This is what the hyperlink from the management list should do. I use it all the time, because I'm always spotting typos just after publishing something.

The risk of duplicates with PubKit as it stands is when you are in the Preview screen, if you use the browser's Back function instead of the Edit button.

Thanks for the feedback!
 Smiley KP

#12: 2-Jul-2010, 11:51 AM


kp52
Posts: 541

WWW
PubKit 0.6.4 is now available from the original post of this topic, and from the Pogwatch site. The changelog has also been posted.

Bug fixed: automatic unpublication after expiry date now works

Other changes:
- snippet parameters are now available to the class functions via the $fields array
- ordering of resources using menuindex can now be handled (pkBlog feature that fell off the cart earlier)

Documentation is the same as 0.6.3. For the time being, that is.
 Smiley KP


#13: 2-Jul-2010, 04:20 PM


kp52
Posts: 541

WWW
@pixelstation: sorry I didn't have time to look at this earlier. Here's what I came up with, taking the task as:

- record the (full) name of the original author of an item in a TV belonging to it
- display the name in the input form when re-editing, if required

My TV was a simple Text type called blogAuthor attached to the relevant template. There are loops in the original document Save code in pubKit.inc.php (lines 194-202 in PubKit 0.6.4) and retrieve-for-editing code (lines 313-317) that transfer all the TVs to and from the document object as long as their name and format don't need to change. hence no need for any processing as custom fields - that stuff is only needed when the data format or the name of your form field is different from what is stored.

So my special class (called newsItem in my test) looks like this:
Code:
<?php
class newsItem extends Resource
{
public $defaultDate// set using function in constructor

public $tvs = array(
'pkDate'=>NULL,
'pkDateTo'=>NULL,
'blogAuthor' =>NULL
);

public $validate = array(
'pagetitle'=>'string||Req||title',
'longtitle'=>'string||Req||postHeadline',
'tvpkRichContent'=>'string||Req||postContent',
'displayDate'=>'date||Req||displayDate',
'displayFrom'=>'date||Opt||fromDate',
'displayTo'=>'date||Opt||toDate'
);

function 
__construct($pid$fields$lang) {
$this->defaultDate strftime($lang['dateFormat']);
$this->tvs['pkPreviewFlag'] = (isset($fields['preview'])) ? 1:0;
if (empty($pid)) {
$this->tvs['blogAuthor'] = $_SESSION['webFullname'];
} else {
global $modx;
$author $modx->getTemplateVar('blogAuthor''id'$pid);
$this->tvs['blogAuthor'] = $author['value'];
}
parent::__construct($pid$fields$lang);
}

function 
CustomFields($fields$doc) {
$customFields = array();

    
$customFields['displayDate'] = strftime($this->lang['dateFormat'], strtotime($fields['pkDate']));
    
$customFields['displayTo']   = ($fields['pkDateTo'] > 0) ?
strftime($this->lang['dateFormat'], strtotime($fields['pkDateTo'])) : "";
    
$customFields['displayFrom'] = ($doc->Get('pub_date') > 0) ?
strftime($this->lang['dateFormat'], $doc->Get('pub_date')) : "";

return $customFields;
}

}
?>
The if/else is needed in the constructor function so that the author name is only recorded when the item is new (has no ID). When re-edited, you have to retrieve the name and insert it into the tvs array, otherwise the null value in the definition zaps it when next saved.

The name is now in the $fields array when re-editing, so you can display it in the form with the placeholder [+blogAuthor+] if required.
 Smiley KP

#14: 3-Jul-2010, 01:55 AM

pixelstation
Posts: 41

I appreciate it KP52, will check this out again.

#15: 3-Jul-2010, 10:37 PM

idoremus
Posts: 18

KP,

Thank you for such a quick and detailed response. I added a php.ini to my MODx root with:

Code:
magic_quotes_gpc = off

This fixed #1, #4 and some other abnormal behavior. For example I noticed that the magic quotes turned phx:dateIfSet and phx:statusFormat into phx~dateIfSet and phx~statusFormat.

I am still troubleshooting #3.

Do you have a demo account that shows how you setup the back-end to PubKit? It would be helpful to some of us greener MODx users to see the power of what can be done.

Thanks again for the help,
Ian
« Last Edit: 3-Jul-2010, 10:50 PM by idoremus »

#16: 15-Jul-2010, 07:31 AM

BobbyG66
Posts: 77

I am having problems with adding an item for a News item.
When I preview the news-manage page and click "add item" I get sent to my home page and my browser says I am at "/admin/news-edit".
When I preview my news-edit page it says "You do not have permission to post items here".

I think it may be an issue with my file layout and Ditto calls to the correct page.

My file are setup like this:
News (9)
--First article (13)
--Second article (14)
Admin (41)
--News manage page (38)
--News edit page (38)

My Ditto call on the manage page only shows the "add item" page when the call is this "[!Ditto?parents=`37`"
If I set it to `9` or `38` I get the MODx parse errors.

Thanks for any help
BG66

#17: 18-Jul-2010, 02:03 AM

apcherry
Posts: 48

WWW
I am having problems with adding an item for a News item.
When I preview the news-manage page and click "add item" I get sent to my home page and my browser says I am at "/admin/news-edit".
When I preview my news-edit page it says "You do not have permission to post items here".

I think it may be an issue with my file layout and Ditto calls to the correct page.

My Ditto call on the manage page only shows the "add item" page when the call is this "[!Ditto?parents=`37`"
If I set it to `9` or `38` I get the MODx parse errors.


Hi, I've just started with PubKit so I'm still on the learning curve as well, however there are a couple of things to mention.

First I presume your news manage page is actually id = 37 (you've listed 2 page 38s in your structure.), otherwise I don't see a problem with your layout.
On the news manage page the ditto call should be parents=`9` as this defines the start id for the news articles. Presumably this gives you the error messages.

One thing to check is the news manage page, near the top there is the code for adding a new item. The string in action="", must reference the friendly url for your news edit page id 38. On my setup I'm using it for Area group reports so mine looks like this.
Code:
<form method="post" action="/welcome/area-reports/area-edit" id="addItem">

For the news edit page permissions in your pubKit call do you have a parameter &canPost= defined? In my setup I define a web user group here
Code:
&canPost=`full member`
So only people logged in and members of this web user group will actually get permission to add entries. According to the documentation if you leave it blank then anyone can post. What do you have in your news edit page?

I hope this helps

Adrian

#18: 18-Jul-2010, 09:11 AM

BobbyG66
Posts: 77

Thanks apcherry,

1) Typo on my part when posting. My News Edit page is (37).

2) My news manage page (38) is this:
Code:
<form method="post" action="../admin/news-edit" id="addItem"> <input type="submit" value="Add item" />
</form>
<div>
<table>
<thead><tr>
<th colspan="2">Item and status</th><th>Date</th><th>Publish</th>
<th>To</th></tr></thead>
<tbody>
[!Ditto?parents=`9` &tpl=`news.manage.tpl` &showPublishedOnly=`0` &orderBy=`pkDate DESC,editedon DESC` &extenders=`pkStatus` &tagData=`acNews` &debug=`0`!]
</tbody>
</table>
</div>

My News Edit page (37) is this:
Code:
[!PubKit?class=`post` &folder=`9` &template=`` &tags=`acNews` &rtcontent=`pkRichContent` &formtpl=`news.input.tpl` &tagFormat=`chk` &canPost=`editor` &debug=`0`!]

When changing to "folder=`9`" I get a MODx Parse Error.

3) When previewing my News Edit page, the details input box is not shown.
I tracked it down through the TV [*pkRichContent*]
The default value is [+newsBody+]
I do not have a TV by that name and do not see it referenced in the docs anywhere.
What are the parameters for that TV?

#19: 18-Jul-2010, 02:47 PM

apcherry
Posts: 48

WWW

2) My news manage page (38) is this:
Code:
<form method="post" action="../admin/news-edit" id="addItem"> <input type="submit" value="Add item" />
Hi, I don't think you need the .. at the beginning of the action - I presume that the URL alias for your Admin page(41) is admin and your news-edit page (38) URL alias is news-edit then I'd expect the following to work
Code:
<form method="post" action="/admin/news-edit" id="addItem"> <input type="submit" value="Add item" />

My News Edit page (37) is this:
Code:
[!PubKit?class=`post` &folder=`9` &template=`` &tags=`acNews` &rtcontent=`pkRichContent` &formtpl=`news.input.tpl` &tagFormat=`chk` &canPost=`editor` &debug=`0`!]

When changing to "folder=`9`" I get a MODx Parse Error.
Does the MODx Parse error give you any clues?

3) When previewing my News Edit page, the details input box is not shown.
I tracked it down through the TV [*pkRichContent*]
The default value is [+newsBody+]
I do not have a TV by that name and do not see it referenced in the docs anywhere.
What are the parameters for that TV?
Not sure about this - actually I don't have a TV called newsBody and it still works for me. I presume this is just a default template to stick in the news edit page when creating a new item. I suppose if you want posters to follow a certain format then you can use this field.

What settings have you used for for pkRichContent? On my setup the width at 100% was too wide for my template and it flowed off the bottom. I reduced the width to 60% and it slotted into place.

Does the rest of the add item form appear - title, intro, buttons etc? As defined in your news.input.tpl chunk. Which should include the details section as follows.

Code:
<div class="row">
<span class="edLabel"><label for="detail">Details</label></span>
<span class="edField" id="detail">[*pkRichContent*]</span>
</div>

Sorry I don't know what else to suggest, I've only just started using PubKit so I'm just going off what has worked for me - so no guarantee that I'm doing it correctly.
Regards

Adrian

#20: 18-Jul-2010, 06:50 PM

BobbyG66
Posts: 77

Adrian,

Thanks for the feedback.

I removed the ".." in front of "../admin/news-edit".
I was trying that out, but made no difference in or out.

MODx Parse Error:
I removed "editedon DESC" from:
Code:
[!Ditto?parents=`156` &tpl=`news.manage.tpl` &showPublishedOnly=`0` &orderBy=`pkDate DESC,editedon DESC` &extenders=`pkStatus` &tagData=`acNews` &debug=`0`!]
and that got rid of the Parse Error.

I played around with the settings for "pkRichContent" with no effects. Everything shows up except for the "Details" section.

I will keep messing around with it.
BG66
Pages: [1] 2  All   Go Up
0 Members and 1 Guest are viewing this topic.