We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 33992 ☆ A M B ☆
    • 455 Posts
    CakeMODx

    Hello,
    I’ve created some APIs for some routine actions while developing MODx Evo. These APIs are as methods of a class named CakeMODx(!)
    This version is beta and in development so there is no WARRANTY for missing data.

    These are methods which available to use:

    Document management methods

    • newDocument: Creates a new MODx document.
    • updateDocument: Update/Edit a MODx document.
    • deleteDocument: Delete a MODx document with all details.
    • getDocField: Get fields from `site_content` table for one or more MODx document.
    • emptyTrash: Empty MODx recycle bin.
    • getChildrenCount: Get count of all sub-document for one or more parent documents.
    • getSiteDocumentCount: Get count of all documents of site.
    • getDocumentOutput: Print output of a document. New in 1.3!
    • updateCache: Renew the site cache.


    Template Variable methods

    • setTV: Set a TV value for a document.
    • getTV: Get value of a TV.
    • unsetTV: Delete a TV value of one or more documents.
    • updateTV: Update/Edit a TV value.


    Web user methods

    • newUser: Create new web user.
    • updateUserProfile: Update/Edit profile for one/more user(s).
    • unsetUser: Delete one/more user(s).
    • getUserField: Get data from one/more user(s).
    • getAssignedDocs: Get document which the user has been assigned to them in his/her webgroups.
    • getForbiddenDocs: Get document which the user has NOT been assigned to them in his/her webgroups.


    Web/Doc group methods

    • newDocgroup: Create new Document Group.
    • renameDocgroup: Rename a Document Group.
    • unsetDocgroup: Delete a Document Group and ALL links to it’s members.
    • joinDocgroup: Join document(s) to a Docgroup.
    • getDocgroupMembers: Get all members of a Docgroup.
    • newWebgroup: Create new Web Group.
    • renameWebgroup: Rename a Webument Group.
    • unsetWebgroup: Delete a Web Group and ALL links to it’s members.
    • joinWebgroup: Join user(s) to a Webgroup.
    • getWebgroupMembers: Get all members of a Webgroup.
    • linkGroups: Assign a Webgroup to a Docgroup.
    • unlinkGroups: Unlink a Webgroup from a Docgroup.


    Jot Comment methods

    • comment_byDoc: Get a comment by document container.
    • comment_byParent: Get a comment by parent of document containers.
    • comment_byWhere: Get a comment by SQL WHERE statement.
    • commentCount_byDoc: Get a comments count by document container.
    • commentCount_byParent: Get a comments count by parent of document containers.
    • commentCount_byWhere: Get a comments count by SQL WHERE statement.
    • comment_subscriptions_byDoc: Get a subscriptions by document container.
    • comment_subscriptions_byParent: Get a subscriptions by parent of document containers.
    • comment_subscriptions_byWhere: Get a subscriptions by SQL WHERE statement.
    • comment_new: Create a new comment. New in 1.3!
    • comment_move: Move comments to another document. New in 1.3!


    Misc methods

    • doc_id2title: Get pagetitle by document ID.
    • TV_name2id: Get ID of TV by it’s name.
    • user_id2fullname: Get fullname by User ID.
    • str_highlight: Highlight a string in text without corrupting HTML tags (by Aidan Lister).
    • escape: Escape strings to use in SQL commands (DBAPI::escape with magic_quotes checking).
    • arr_escape: Escape array values for SQL commands.
    • sendMail: Send email to some addresses.
    • PHPMailer: Get PHPMailer object.
    • stripModxTags: Strip MODx and/or HTML tags. New in 1.3!
    • getIP: Get IP. New in 1.3!


    [b][u]Usage Example
    <?php
    
    include "CakeModx.class.php";
    $CakeModx = new CakeModx;
    
    $fields = array(
    	"pagetitle" => "The Cake",
    	"content" => "Very good weather",
    	"published" => 1
    );
    
    $id = $CakeModx->newDocument($fields);
    if($id)
    	$CakeModx->updateCache();
    
    ?>


    [b][u]Note
    This class is not related to MODx team and is a 3rd party.

    [b][u]Hint
    In fact it is a complex of functions, it means you can cut methods you need and use as single functions after some tiny hacks. Many of methods are not depends on others.
    for example you can use these two functions instead CakeMODx::comment_byDoc :
    <?php
    function comment_byDoc($doc, $fields='content', $tagid='')
    {
    	global $modx; 	// ADDED
    	if(is_string($fields))		$fields = array($fields);
    	$fields = "jot." . join(', jot.' , $fields);
    	$tagid_where = ($tagid == '') ? '' : " AND jot.tagid='$tagid'";
    	
    	/*
    	$sql = "
    		SELECT $fields , jfld.label AS fieldLabel, jfld.content AS fieldValue FROM " .$this->getFullTableName('jot_content'). " jot
    		LEFT JOIN " .$this->getFullTableName('jot_fields')." jfld ON jot.id=jfld.id WHERE jot.uparent=$doc $tagid_where
    	";
    	*/
    	$sql = "
    		SELECT $fields , jfld.label AS fieldLabel, jfld.content AS fieldValue FROM " .$modx->getFullTableName('jot_content'). " jot
    		LEFT JOIN " .$modx->getFullTableName('jot_fields')." jfld ON jot.id=jfld.id WHERE jot.uparent=$doc $tagid_where
    	";
    	
    	//return $this->comment_query($sql);
    	return comment_query($sql);
    }
    
    function comment_query($sql)
    {
    	global $modx; 	// ADDED
    	//$select = $modx->db->query($sql);
    	$select = $modx->db->query($sql);
    	
    	//$counts = $this->db->getRecordCount($select);
    	$counts = $modx->db->getRecordCount($select);
    	
    	//if($counts == 1)	return $this->db->getRow($select);
    	if($counts == 1)	return $modx->db->getRow($select);
    	
    	if($counts == 0)	return "0";
    	
    	$comments = array();
    	
    	//while($Row = $this->db->getRow($select))	$comments[] = $Row;
    	while($Row = $modx->db->getRow($select))	$comments[] = $Row;
    	
    	return $comments;
    }



    Get it from Extras


    Good luck
    AHHP
      God loves me. 【ツ】


      MODX.ir (Persian Support)

      Boplo.ir/modx/ (Persian)
      • 36823
      • 334 Posts
      "404 - Attachment Not Found"
        • 22303 MODX Staff
        • 10,725 Posts
        Quote from: Andrei at May 10, 2009, 05:45 PM

        "404 - Attachment Not Found"
        Sorry folks, thanks to the efforts of the "skiddies", we are going to have to disable all new attachments (and avatars) until further notice. I’ll provide more information in an announcement thread as soon as is prudent.
          • 33992 ☆ A M B ☆
          • 455 Posts
          Quote from: Andrei at May 10, 2009, 05:45 PM

          "404 - Attachment Not Found"
          Sorry, you would download it now.....
            God loves me. 【ツ】


            MODX.ir (Persian Support)

            Boplo.ir/modx/ (Persian)
            • 25663 MODX Staff
            • 12,272 Posts
            There might be some confusion on this with the CakePHP project. Any relation whatsoever?

            Great set of APIs indeed though. Thank you!
              Ryan Thrash, MODX Co-Founder
              Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
              • 10164
              • 27 Posts
              This looks like a great set of extenders/handles but i agree with Ryan, when i saw the post title i thought a PHPcake framework/terminal mashup with MODx ! How about a biscuit instead of a cake??
                • 33992 ☆ A M B ☆
                • 455 Posts
                biscuit?! This is my Cake in MODx and i liike it wink
                  God loves me. 【ツ】


                  MODX.ir (Persian Support)

                  Boplo.ir/modx/ (Persian)
                  • 20413
                  • 2,877 Posts
                  Cool! Makin your own API!  cool

                  /Help! When downloading I get a file without extension and I can’t edit in any editor!?
                    @hawproductions | http://mrhaw.com/

                    Infograph: MODX Advanced Install in 7 steps:
                    http://forums.modx.com/thread/96954/infograph-modx-advanced-install-in-7-steps

                    Recap: Portland, OR (PDX) MODX CMS Meetup, Oct 6, 2015. US Bancorp Tower
                    http://mrhaw.com/modx_portland_oregon_pdx_modx_cms_meetup_oct_2015_us_bancorp_tower
                    • 16183
                    • 1,390 Posts
                    Works for me...a zip file it is.....Quote from: mrhaw at May 12, 2009, 10:45 AM



                    /Help! When downloading I get a file without extension and I can’t edit in any editor!?

                    Works for me....a zip file it is...

                    cheers/k

                    ps: Välkommen tillbaka mrhaw o grattis på bröllopet!
                      • 33992 ☆ A M B ☆
                      • 455 Posts
                      Quote from: mrhaw at May 12, 2009, 10:45 AM

                      /Help! When downloading I get a file without extension and I can’t edit in any editor!? 

                      The Zip file contains:
                      CakeMODx dir
                          CakeMODx.class.php
                          errorlog.html
                          documention.html
                          cakemodx.jpg
                      index.html

                      what file do you talking about?
                        God loves me. 【ツ】


                        MODX.ir (Persian Support)

                        Boplo.ir/modx/ (Persian)