Page 1 of 1

Error "eval()'d code" when UDT used through a CMSMS Event

Posted: Mon Mar 23, 2009 10:56 am
by monbouc
Hi all,
I named this topic after an exiting one, available at the following address, but "more than 120 days old" and suggesting to start a new one to get an answer.
http://forum.cmsmadesimple.org/index.php/topic,13267.30.html

I wrote a simple User Defined Tag that is supposed to give me the alias of a modified page. The idea is to develop a bit more and get the script send a notification email when a content is modified, as it is written in the forum post that I mentionned. But as I can't get it working, I simplified to get the single Alias value. Whatever I try (including copy/paste of the examples found in the forum and wiki pages) the error is always the same, as stated a bit later. Here is my code :

Code: Select all

global $gCms;
$manager =& $gCms->GetHierarchyManager();
$thisPage = $gCms->variables['content_id'];
$currentNode = &$manager->sureGetNodeById($thisPage);
$currentContent =& $currentNode->getContent();
$mail_content = 'Alias : '.$currentContent->Alias();
This UDT works fine when included as a normal {udt} in the page content. For example, the "echo" instruction prints the correct $mail_content value, no problem.

It's when the UDT is used by an event, added to the ContentEditPost event, as this page instructs, that ot all goes wrong :
http://wiki.cmsmadesimple.org/index.php/User_Handbook/Admin_Panel/Extensions/Event_Manager

I'm running the actual last version 1.5.3 "Arecibo" on a PHP5/Apache Server and here is the error that I keep getting :

Code: Select all

Call to a member function getContent() on a non-object in [...]\www\lib\classes\class.usertagoperations.inc.php(158) : eval()'d code on line [...] 
Could anyone tell me how to use this getContent function in the Event's environnement ? My programmer skills are unfortunately too short for me to see it by myself.

Thank you by advance.

Re: Error "eval()'d code" when UDT used through a CMSMS Event

Posted: Mon Mar 23, 2009 11:58 am
by alby
monbouc wrote:

Code: Select all

$thisPage = $gCms->variables['content_id'];
$currentNode = &$manager->sureGetNodeById($thisPage);
I don't think that you have $gCms->variables['content_id'], this is create in frontend page generator
Look in Event help which params you have and call with $params

Alby

Re: Error "eval()'d code" when UDT used through a CMSMS Event

Posted: Mon Mar 23, 2009 12:26 pm
by monbouc
Thanks for the reply, alby.
It looks like you're pretty right, $gCms->variables['content_id'] is empty. However, I guess that many values could be reached by $param.

Here is what var_dump($param) returns :

Code: Select all

array(1) {
  ["content"]=>
  &object(Content)#27 (35) {
    ["additionalContentBlocks"]=>
    array(0) {
    }
    ["addtContentBlocksLoaded"]=>
    bool(true)
    ["mId"]=>
    string(2) "53"
    ["mName"]=>
    string(11) "My page title"
    ["mType"]=>
    string(7) "content"
    ["mOwner"]=>
    string(1) "1"
    ["mProperties"]=>
    object(ContentProperties)#28 (4) {
      ["mPropertyNames"]=>
      array(11) {
        [0]=>
        string(20) "Second_Content_Block"
        [1]=>
        string(6) "target"
        [2]=>
        string(8) "pagedata"
        [3]=>
        string(6) "extra1"
        [4]=>
        string(6) "extra2"
        [5]=>
        string(6) "extra3"
        [6]=>
        string(5) "image"
        [7]=>
        string(9) "thumbnail"
        [8]=>
        string(10) "searchable"
        [9]=>
        string(15) "disable_wysiwyg"
        [10]=>
        string(10) "content_en"
      }
      ["mPropertyTypes"]=>
      array(11) {
        ["content_en"]=>
        string(6) "string"
        ["target"]=>
        string(6) "string"
        ["pagedata"]=>
        string(6) "string"
        ["extra1"]=>
        string(6) "string"
        ["extra2"]=>
        string(6) "string"
        ["extra3"]=>
        string(6) "string"
        ["image"]=>
        string(6) "string"
        ["thumbnail"]=>
        string(6) "string"
        ["searchable"]=>
        string(6) "string"
        ["disable_wysiwyg"]=>
        string(6) "string"
        ["Second_Content_Block"]=>
        string(6) "string"
      }
      ["mPropertyValues"]=>
      array(11) {
        ["content_en"]=>
        string(1972) "<p>My first html content</p>"
        ["target"]=>
        string(0) ""
        ["pagedata"]=>
        string(0) ""
        ["extra1"]=>
        string(0) ""
        ["extra2"]=>
        string(0) ""
        ["extra3"]=>
        string(0) ""
        ["image"]=>
        string(2) "-1"
        ["thumbnail"]=>
        string(0) ""
        ["searchable"]=>
        string(1) "1"
        ["disable_wysiwyg"]=>
        string(1) "0"
        ["Second_Content_Block"]=>
        string(1377) "<p>My second html content</p>"
      }
      ["mAllowedPropertyNames"]=>
      array(10) {
        [0]=>
        string(10) "content_en"
        [1]=>
        string(6) "target"
        [2]=>
        string(8) "pagedata"
        [3]=>
        string(6) "extra1"
        [4]=>
        string(6) "extra2"
        [5]=>
        string(6) "extra3"
        [6]=>
        string(10) "searchable"
        [7]=>
        string(5) "image"
        [8]=>
        string(9) "thumbnail"
        [9]=>
        string(15) "disable_wysiwyg"
      }
    }
    ["mPropertiesLoaded"]=>
    bool(true)
    ["mParentId"]=>
    string(2) "57"
    ["mOldParentId"]=>
    string(2) "57"
    ["mTemplateId"]=>
    string(2) "20"
    ["mItemOrder"]=>
    string(1) "1"
    ["mOldItemOrder"]=>
    string(1) "1"
    ["mMetadata"]=>
    string(0) ""
    ["mTitleAttribute"]=>
    string(0) ""
    ["mAccessKey"]=>
    string(0) ""
    ["mTabIndex"]=>
    string(0) ""
    ["mHierarchy"]=>
    string(11) "00001.00001"
    ["mIdHierarchy"]=>
    string(5) "57.53"
    ["mHierarchyPath"]=>
    string(16) "my-page-alias"
    ["mMenuText"]=>
    string(11) "my page title"
    ["mActive"]=>
    bool(true)
    ["mAlias"]=>
    string(7) "my-page-alias"
    ["mOldAlias"]=>
    string(7) "my-page-alias"
    ["mCachable"]=>
    bool(true)
    ["mPreview"]=>
    bool(true)
    ["mShowInMenu"]=>
    bool(true)
    ["mDefaultContent"]=>
    bool(false)
    ["mMarkup"]=>
    string(4) "html"
    ["mLastModifiedBy"]=>
    string(1) "5"
    ["mCreationDate"]=>
    string(19) "2007-12-03 11:59:21"
    ["mModifiedDate"]=>
    string(19) "2009-03-23 13:01:36"
    ["mAdditionalEditors"]=>
    array(0) {
    }
    ["mReadyForEdit"]=>
    bool(true)
    ["mChildCount"]=>
    int(0)
  }
}
int(1)
I just don't know how to write the right syntax to reach the object(Content)#27 and object(ContentProperties)#28 arrays inside values, and then be able tu use the 'mName', 'content_en', 'Second_Content_Block' data that I need in the end to make run correctly the UDT by the Event.

I'm grumbling to appear so weak  :-\
Any suggestion is welcome.

Re: Error "eval()'d code" when UDT used through a CMSMS Event

Posted: Mon Mar 23, 2009 12:43 pm
by alby
have you tried with:
var_dump($params["content"]->mAlias);

Alby

Re: Error "eval()'d code" when UDT used through a CMSMS Event

Posted: Mon Mar 23, 2009 12:51 pm
by monbouc
Okay ! $params["content"]->mAlias works fine, that's simply what I missed (stupid me).

Sorry for the loss of time and thank you for the help.
I'll soon post the solution that I now should be able to write by myself, whatever it's worth.

Thanks !

[solved] Re: Error "eval()'d code" when UDT used through a CMSMS Event

Posted: Mon Mar 23, 2009 5:08 pm
by monbouc
Here is the UDT, now working for me. The error was due to a misunderstanding of mine, cleared through this topic. It came from a bad copy/paste of a line from a similar code dedicated to the News notifications treatment.

I post my final script to close this discussion.

Code: Select all

//	sends an email to the $mail_to1 address when a page is modified
//	if specified, BCC to $mail_to2 
//	(needs to be added to the go to the Events Handler page: go to Extensions->Events, edit ContentEditPost, select UDT in the dropdown list, and add it)
//

global $gCms;
$content =& $params['content'];

$editorName		=	$gCms->variables['username'];

$mail_to1		=	"name@domain.ext";
$mail_to2		=	"";
$mail_subject		=	"Page change notification, by : " . $editorName;
$mail_content		= 	'

<p>A content has been modified.</p>
<p>
Edited by 	: ' . $editorName . '<br />
Title		: ' . $content->Name() . '<br />
Page ID		: ' . $content->Id() . '<br />
Page Alias	: ' . $content->Alias() . '<br />
Page Type	: ' . $content->Type(). '<br />
Created on	: ' . $content->GetCreationDate().'<br />
Modified on	: ' . $content->GetModifiedDate().'<br />
URL		: <a href="' . $content->GetURL() . '">' . $content->GetURL() . '</a></p>

<p>Here comes the new content.</p>
<hr />
' . $content->mProperties->mPropertyValues["content_en"]. '
<hr />
' . $content->mProperties->mPropertyValues["Second_Content_Block"];

$cmsmailer =& $gCms->modules['CMSMailer']['object'];
$cmsmailer->AddAddress($mail_to1);
$cmsmailer->AddBCC($mail_to2);
$cmsmailer->SetBody($mail_content);
$cmsmailer->IsHTML(true);
$cmsmailer->SetSubject($mail_subject);
$cmsmailer->Send();
Thank you Alby.