Coded something up in Couch in an interesting way? Have a snippet or shortcode to share? Post it here for the community to benefit.
18 posts Page 2 of 2
@Paolo
Does the addon work with a very old couchcms version?

It requires at least v2.0. Won't work on any version older than this.
What about front-end usage? Is there a way of using this from the front-end?
atisz wrote: What about front-end usage? Is there a way of using this from the front-end?

Yes, I guess Administrators may see a link that leads to a copied page in admin panel.

UPDATE: I pushed an example to repo: Tweakus Vars → k__clonepage_link
trendoman wrote: Yes, I guess Administrators may see a link that leads to a copied page in admin panel.

UPDATE: I pushed an example to repo: Tweakus Vars → k__clonepage_link


Great job, trendoman!
I have tested your solution and it's working.

But unfortunately, my use-case is different. I need to use it with member module, so the users have no access to the admin panel. The "copy to new" option should be available for every logged in member, and all the action should happen on the front-end.

Is it possible to adapt this functionality to work only from front-end, with no need to be logged into Couch CMS admin panel?
Thank you @trendoman!

Strangely, your last post, containing the solution for cloning pages from the front-end, has dissapeared.But it saved me! Thanks again! Now I know a new use-case for cms:db_persist :D And you were right.... it's more flexible, submitted data can be customized, not just simply duplicated.
atisz wrote: Thank you @trendoman!

Strangely, your last post, containing the solution for cloning pages from the front-end, has dissapeared.But it saved me! Thanks again! Now I know a new use-case for cms:db_persist :D And you were right.... it's more flexible, submitted data can be customized, not just simply duplicated.


You are welcome. :) Glad it helped. The posting has been moved to repository Ctrl-CV-Snippets → `db_persist` (create)
I have made a repack with a few tweaks.

copy-to-new_by_anton.zip
(16.06 KiB) Downloaded 1873 times

Base code is almost the same, just the paths are not tied to /couch/addons/ folder and became relevant.

Additional tweaks are in separate files and include: alert on a clone, frontend link, reverse_relation fix by KK and a more detailed README which includes the example with cms:db_persist tag discussed in later posts (as repo links are no longer valid).

copy-to-new-alert.png
copy-to-new-alert.png (5.6 KiB) Viewed 28444 times

Repack was necessary to fit the addon into my new way of loading addons and other scripts outlined in topic viewtopic.php?f=2&t=13473 So the Installation mostly is the same, I'll quote from README, with only difference to regular method is using a new connector file (which is actually a good way for any other addon that might be extended without adding a separate line in kfunctions :!: ) :

## Installation

Move addon to `/addons-enabled/` folder (if using autoloader) or follow the regular method -

1. Extract the folder named 'copy-to-new' from the attached zip and place it in 'couch/addons' folder.
2. Activate the addon by adding the following entry in 'couch/addons/kfunctions.php' file (if this file is not present, rename 'kfunctions.example.php' to 'kfunctions.php') -

```php
require_once( K_COUCH_DIR.'addons/copy-to-new/__autoload.php' );
```


And that __autoload.php file is a very basic connector in the zip which you can edit to remove some tweaks if not interested in them:

Code: Select all
<?php
    if ( !defined('K_COUCH_DIR') ) die(); // cannot be loaded directly

    // base addon
    require_once( __DIR__ . '/copy-to-new.php' );

    // addition by KK to copy reverse relation fields
    require_once( __DIR__ . '/copy-reverse-relation.php' );

    // alert to save on a new clone
    require_once( __DIR__ . '/copy-to-new-alert.php' );

    // variable with a link to clone from the frontend
    require_once( __DIR__ . '/k__clonepage_link.php' );


P.S. A new thing, better than it was in repo, is that the alert is integrated with addon with PHP code, so no need to copy paste a snippet to template's config_form_view tag to activate alert. Just install addon and it's enabled.
A tip: if you wish to enable this addon for all suitable templates then edit config.php —

Code: Select all
$cfg['tpls'] = $_GET['o'];

This will make addon believe it is enabled for the currently visited template.
18 posts Page 2 of 2