Is there any event when user copy the page?

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
cve
Forum Members
Forum Members
Posts: 44
Joined: Wed Jul 07, 2010 10:54 am

Is there any event when user copy the page?

Post by cve »

Hi, i'm working on a module, and i need run some kind of code when user copy the page in cms made simple... Is there any event when this action is runing?
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: Is there any event when user copy the page?

Post by calguy1000 »

Nope. Sorry, there is not.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
psy
Power Poster
Power Poster
Posts: 463
Joined: Sat Jan 22, 2005 11:19 am

Re: Is there any event when user copy the page?

Post by psy »

What Calguy says is true but there's more than one way to skin a cat.

There are events you can compare, ie ContentEditPre and ContentEditPost. If the page has a content id of -1, it's a new page. Doesn't matter how/where it was created, whether by manually adding a new page or copying an another one.

Firstly, create an event in ContentEditPre that stores the page in a session var if it's active, and test for the content id. If it's -1, it's a new page.

Code: Select all

$contentobj = $params['content'];
if ($contentobj->Id() == -1){ // It's a new page 
  // do somthing;
}

// make sure the new page is Active
if ($contentobj->Active() == 1) {
  $_SESSION['mynewpage_active'] = 1;
}
OK, so we've made a temporary session var letting us know we have a new, active page.

Next compare that with the event ContentEditPost:

Code: Select all

$content = $params['content'];
$contentops = ContentOperations::get_instance();
$content_id = $content->Id();
$contentobj = $contentops->LoadContentFromId($content_id);

if ($contentobj)
{
  $hid = $contentobj->Hierarchy();
  if (!$hid) {
    // New pages are only partially saved. We need to set/get the hierarchy stuff
    $contentops->SetHierarchyPosition($contentobj->Id());
    $hid = $contentobj->Hierarchy();
  }
  $contentops->CreateFriendlyHierarchyPosition($hid);

  // Ensure the newly created page is active
  if (isset($_SESSION['mynewpage_active'])  ) {
    unset ($_SESSION['mynewpage_active']);    
    // do what you want with the new active page that has now been fully written to the db....
}
hth
psy
Post Reply

Return to “Developers Discussion”