CakeMODxHello,
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!
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();
?>
NoteThis class is not related to MODx team and is a 3rd party.
HintIn 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;
}
Good luck
AHHP