Important announcements from CouchCMS team
29 posts Page 3 of 3
How would you customise the toolbar?

cms:inline_edit tag supports both the 'toolbar' as well as 'custom_toolbar' parameters of cms:editable type richtext. Please see http://www.couchcms.com/docs/tags-refer ... htext.html for details on how to use them for customizing the toolbar.

That said, I wonder why you wish to use inline_edit for images, Patrick? popup_edit seems to be the more suitable method. Any reason in particular?
hello! I've read through the on page editing docs and am looking forward to using on my upcoming site. A question which I think I know the answer to ... but will ask it anyway - am I right in assuming that the only way of generating a new cloneable page will be via the Admin Panel?

I am hoping that in the next version of Couch cloned pages can themselves be cloned to form the basis of a new cloned page. Many of the sites I do would really benefit from this facility - for example an events listing, with too many details to use repeatable regions, which often means a new event with very similar data to an existing cloned page, but with a different date and venue - the client would love to be able to copy and amend, rather than enter everything all over again. If copying of cloned pages is implemented in the next release of Couch - will it be possible to clone them via on page editing?
Hi potato,

You are right - 'create' and 'delete' functions are yet unimplemented in On-page editing.

The 'copy' function you mentioned is on the cards and we should, hopefully, have it in the next version.
Marvelous! Thank you .... looking forward to it.
potato wrote: I am hoping that in the next version of Couch cloned pages can themselves be cloned to form the basis of a new cloned page.

Sorry if I'm swerving away from the topic of on-page-editing here. But it seemed like it would be pretty easy to hack up a way to do this from the front end. My idea was to use the db_persist tag from the page view of a clonable template to create a new page pre-populated with the current page's values. And it worked!... uh... mostly.

Just pop the following code into your page view somewhere near the top. This shows a "Clone Me" button that's available only to logged in site admins. When clicked it creates a new auto-titled, unpublished page using the current page's data. The admin can edit the new page as needed before publishing it.

The region names in the db_persist tag should match the template's editable regions, and sessions and data-bound forms should be enabled in addons/kfunctions.php.

This works for most of the common editable region types that I tried, including richtext. But for some reason it chokes on image-type regions, throwing the error:
Fatal error: Call to undefined function k_resize_image() in /path/to/couch/page.php on line 1075

Maybe someone else knows how to solve this problem. Nonetheless, if you need this capability and don't have any image type regions in your template (or you could just skip image regions and leave them blank), this is a pretty simple trick for cloning a new page from an existing one.

Again, sorry about going off on a tangent. I'm just following on from the conversation and playing around with the idea. Maybe it will be useful to someone.
Code: Select all
<cms:if k_user_access_level ge '7'>
    <cms:set submit_success="<cms:get_flash 'submit_success' />" />
    <cms:if submit_success >
        <h4>This page has been successfully cloned.</h4>
    </cms:if>
   
    <cms:form
        method='post'
        anchor='0'
    >
       
        <cms:if k_success >
            <cms:db_persist
                _masterpage=k_template_name
                _mode='create'
                _invalidate_cache='0'
                _auto_title='1'
                k_publish_date='0000-00-00 00:00:00'
                region1=region1
                region2=region2
                region3=region3
            />
           
            <cms:set_flash name='submit_success' value='1' />
            <cms:redirect k_page_link />
        </cms:if>
       
        <cms:if k_error >
            <h4>This shouldn't be possible, but....</h4>
            <cms:each k_error >
                <br><cms:show item />
            </cms:each>
        </cms:if>

        <cms:input name="submit" type="submit" value="Clone Me" />
       
    </cms:form>
   
</cms:if>
@tim - can't wait to try this out - am away for a bit - but will come back to this! Thanks.
That PHP error was corrected in 1.4.5 @tim. There is no specific commit for the fix in the GitHub repository because it accidentally slipped in to 1.4.5RC2.
While we are on the topic of cloning existing pages, allow me to post a solution that I created for a client recently.

He actually wanted to clone *all* the existing pages of a particular template.
As a first step of doing that, the solution created a tag named cms:clone_page which when used in the context of a page-view would create a copy of the page. As the final step we used this tag in a 'staggered' manner as we do in CSV importer (viewtopic.php?f=5&t=8803) to run the tag through all existing pages without the risk of running out of memory or timing out.

I think you'll find the first step (i.e. the cms:clone_page tag) useful.

Following is the full solution I proposed -

Please copy and add the following in your 'couch/addons/kfunctions.php' file (if the file is not present, you'll have to rename 'kfunctions.example.php' to 'kfunctions.php').

Code: Select all
$FUNCS->register_tag( 'clone_page', clone_page_handler ); 

function clone_page_handler( $params, $node ){
    global $CTX, $FUNCS, $DB;
   
    if( count($node->children) ){ die("ERROR: Tag \"".$node->name."\" is a self closing tag"); }

    // get page_id (return if used in any other context except page)
    if( $CTX->get('k_is_page') ){
        $page_id = $CTX->get('k_page_id');
        $template_id = $CTX->get('k_template_id');
    }
    else{
        die("ERROR: Tag \"".$node->name."\" can be used only in the context of a page to clone e.g. in a page-view or within cms:pages block");
    }

    // get page object
    $pg = new KWebpage( $template_id, $page_id );
    if( $pg->error ){
        die( "ERROR: Tag \"".$node->name."\" - " . $pg->err_msg );
    }
   
    // and clone it
    $DB->begin();
    $cur_time = $FUNCS->get_current_desktop_time();
    $rs = $DB->insert( K_TBL_PAGES,
            array(
                'template_id'=>$pg->tpl_id,
                'page_title'=>$pg->page_title . '-Copy',
                'creation_date'=>$cur_time,
                'modification_date'=>$cur_time,
                'publish_date'=>'0000-00-00 00:00:00',
                'page_folder_id'=>$pg->page_folder_id,
                'access_level'=>$pg->access_level,
                'comments_open'=>$pg->comments_open,
                )
    );
    if( $rs!=1 ){ $DB->rollback();  die( "ERROR: Tag \"".$node->name."\" - " . "Failed to insert record in K_TBL_PAGES for clone" ); }
    $cloned_page_id = $DB->last_insert_id;

    $res = $pg->_create_fields( $cloned_page_id, $pg->page_title, 1 );
    if( $FUNCS->is_error($res) ){ $DB->rollback();  die( "ERROR: Tag \"".$node->name."\" - " . $rs->err_msg ); }

    $DB->commit();
       
    return;
}

The code above makes available a new tag named cms:clone_page that if you can use to clone existing pages.
For example, if we place the tag above within a cms:pages loop that is fetching all your existing product pages, we'll get a clone of all those pages - e.g.
Code: Select all
<cms:pages masterpage='products.php'>
    <cms:clone_page />
</cms:pages>

However, the code above risks running out of memory or timing-out if the number of pages you have are large.

So, we'll use the 'staggered' technique (described here for the csv importer - viewtopic.php?f=5&t=8803) to create a 'cloner' script that can work with any number of pages.

I'm attaching a very minimally modified version of the csv importer that automatically loops through your pages and clones them as it goes along. All the cloned pages will be in 'unpublished' state but will have all the data of the original pages.. You can then edit them as you wish

Please make sure to change the 'masterpage' parameter of the cms:pages within it to point to the products template.

Hope it helps.

Attachments

Pls does do you have a couchified template with a blog section just like Aurelius but responsive.
Thanks!
29 posts Page 3 of 3