[Cs-cms-commits] SF.net SVN: cs-cms:[10] trunk/0.1
Status: Alpha
Brought to you by:
crazedsanity
From: <cra...@us...> - 2009-02-20 05:54:01
|
Revision: 10 http://cs-cms.svn.sourceforge.net/cs-cms/?rev=10&view=rev Author: crazedsanity Date: 2009-02-20 05:53:54 +0000 (Fri, 20 Feb 2009) Log Message: ----------- Moving more files around & renaming appropriately... converting blogger to be a CMS may be a bit more complicated than I initially thought. Modified Paths: -------------- trunk/0.1/abstract/cs_cms.abstract.class.php trunk/0.1/abstract/cs_cmsDataLayer.abstract.class.php Added Paths: ----------- trunk/0.1/abstract/cs_location.class.php trunk/0.1/abstract/cs_permission.class.php Removed Paths: ------------- trunk/0.1/cs_location.class.php trunk/0.1/cs_permission.class.php Modified: trunk/0.1/abstract/cs_cms.abstract.class.php =================================================================== --- trunk/0.1/abstract/cs_cms.abstract.class.php 2009-02-20 05:48:19 UTC (rev 9) +++ trunk/0.1/abstract/cs_cms.abstract.class.php 2009-02-20 05:53:54 UTC (rev 10) @@ -1,8 +1,8 @@ <?php -require_once(dirname(__FILE__) .'/csb_dataLayer.abstract.class.php'); +require_once(dirname(__FILE__) .'/cs_cmsDataLayer.abstract.class.php'); -class csb_blogAbstract extends csb_dataLayerAbstract { +class cs_cmsAbstract extends cs_cmsDataLayerAbstract { /** Internal name of blog (looks like a permalink) */ protected $blogName; Modified: trunk/0.1/abstract/cs_cmsDataLayer.abstract.class.php =================================================================== --- trunk/0.1/abstract/cs_cmsDataLayer.abstract.class.php 2009-02-20 05:48:19 UTC (rev 9) +++ trunk/0.1/abstract/cs_cmsDataLayer.abstract.class.php 2009-02-20 05:53:54 UTC (rev 10) @@ -3,11 +3,11 @@ require_once(dirname(__FILE__) .'/../../cs-content/cs_phpDB.class.php'); require_once(dirname(__FILE__) .'/../../cs-content/cs_globalFunctions.class.php'); require_once(dirname(__FILE__) .'/../../cs-versionparse/cs_version.abstract.class.php'); -require_once(dirname(__FILE__) .'/../csb_location.class.php'); -require_once(dirname(__FILE__) .'/../csb_permission.class.php'); +require_once(dirname(__FILE__) .'/cs_location.class.php'); +require_once(dirname(__FILE__) .'/cs_permission.class.php'); -abstract class csb_dataLayerAbstract extends cs_versionAbstract { +abstract class cs_cmsDataLayerAbstract extends cs_versionAbstract { /** */ protected $gfObj; Copied: trunk/0.1/abstract/cs_location.class.php (from rev 8, trunk/0.1/cs_location.class.php) =================================================================== --- trunk/0.1/abstract/cs_location.class.php (rev 0) +++ trunk/0.1/abstract/cs_location.class.php 2009-02-20 05:53:54 UTC (rev 10) @@ -0,0 +1,128 @@ +<?php + +require_once(dirname(__FILE__) .'/abstract/csb_dataLayer.abstract.class.php'); + +class csb_location extends csb_dataLayerAbstract { + + //------------------------------------------------------------------------- + public function __construct(array $dbParams=null) { + parent::__construct($dbParams); + + $this->gfObj = new cs_globalFunctions(); + + }//end __construct() + //------------------------------------------------------------------------- + + + + //------------------------------------------------------------------------- + public function add_location($location) { + if(is_string($location) && strlen($location) > 3) { + if(!preg_match('/^\//', $location)) { + $location = "/". $location; + } + $location = $this->fix_location($location); + $location = $this->gfObj->cleanString($location, "sql_insert"); + $sql = "INSERT INTO csblog_location_table (location) " . + "VALUES ('". $location ."')"; + + try { + $numrows = $this->run_sql($sql); + + + if($numrows == 1) { + //okay, retrieve the id inserted. + $retval = $this->db->get_currval('csblog_location_table_location_id_seq'); + } + else { + throw new exception(__METHOD__ .": failed to create location (". $location ."), " . + "numrows=(". $numrows .")"); + } + } + catch(exception $e) { + cs_debug_backtrace($this->gfObj->debugPrintOpt); + throw new exception(__METHOD__ .": failed to create location (". $location .")... DETAILS::: ". $e->getMessage()); + } + } + else { + throw new exception(__METHOD__ .": invalid location (". $location .")"); + } + + return($retval); + }//end add_location() + //------------------------------------------------------------------------- + + + + //------------------------------------------------------------------------- + public function get_location_id($location) { + if(is_string($location) && strlen($location) > 3) { + $location = $this->fix_location($location); + $location = $this->gfObj->cleanString($location, "sql_insert"); + $sql = "SELECT location_id FROM csblog_location_table " . + "WHERE location='". $location ."'"; + $numrows = $this->run_sql($sql, false); + + + if($numrows == 0) { + $retval = false; + } + elseif($numrows == 1) { + $retval = $this->db->farray(); + $retval = $retval[0]; + } + else { + throw new exception(__METHOD__ .": failed to retrieve location (". $location ."), " . + "invalid numrows (". $numrows .")"); + } + } + else { + throw new exception(__METHOD__ .": invalid location (". $location .")"); + } + + return($retval); + }//end get_location_id() + //------------------------------------------------------------------------- + + + + //------------------------------------------------------------------------- + public function fix_location($location) { + if(strlen($location)) { + $retval = $location; + if(!preg_match("/^\//", $retval)) { + $retval = "/". $retval; + } + $retval = preg_replace("/[^A-Za-z0-9\/_-]/", "", $retval); + $retval = preg_replace("/(\/){2,}/", "/", $retval); + $retval = preg_replace("/\/$/", "", $retval); + } + else { + throw new exception(__METHOD__ .": no valid location (". $location .")"); + } + + return($retval); + }//end fix_location() + //------------------------------------------------------------------------- + + + + //------------------------------------------------------------------------- + public function get_locations() { + $sql = "SELECT location_id, location FROM csblog_location_table ORDER BY location_id"; + $numrows = $this->run_sql($sql,false); + + if($numrows > 0) { + $retval = $this->db->farray_nvp('location_id', 'location'); + } + else { + throw new exception(__METHOD__ .": no records found (". $numrows .")"); + } + + return($retval); + }//end get_locations() + //------------------------------------------------------------------------- + + +} +?> \ No newline at end of file Copied: trunk/0.1/abstract/cs_permission.class.php (from rev 8, trunk/0.1/cs_permission.class.php) =================================================================== --- trunk/0.1/abstract/cs_permission.class.php (rev 0) +++ trunk/0.1/abstract/cs_permission.class.php 2009-02-20 05:53:54 UTC (rev 10) @@ -0,0 +1,146 @@ +<?php + +require_once(dirname(__FILE__) .'/abstract/csb_dataLayer.abstract.class.php'); +require_once(dirname(__FILE__) .'/abstract/csb_blog.abstract.class.php'); + + +//TODO: this should extend csb_blogAbstract{} + +class csb_permission extends csb_dataLayerAbstract { + + //------------------------------------------------------------------------- + public function __construct(array $dbParams=null) { + parent::__construct($dbParams); + + $this->gfObj = new cs_globalFunctions(); + + }//end __construct() + //------------------------------------------------------------------------- + + + + //------------------------------------------------------------------------- + public function add_permission($blogId, $toUser) { + if(!is_numeric($toUser) && is_string($toUser) && strlen($toUser)) { + $toUser = $this->get_uid($toUser); + } + + if(is_numeric($toUser) && $toUser > 0 && is_numeric($blogId) && $blogId > 0) { + $this->db->beginTrans(); + $sql = "INSERT INTO csblog_permission_table (blog_id, uid) VALUES " . + "(". $blogId .", ". $toUser .")"; + $numrows = $this->run_sql($sql); + + if($numrows == 1) { + $this->db->commitTrans(); + $retval = $this->db->get_currval('csblog_permission_table_permission_id_seq'); + } + else { + $this->db->rollbackTrans(); + throw new exception(__METHOD__ .": invalid numrows (". $numrows .")"); + } + } + else { + throw new exception(__METHOD__ .": invalid uid (". $toUser .") or blogId (". $blogId .")"); + } + + return($retval); + }//end add_permission() + //------------------------------------------------------------------------- + + + + //------------------------------------------------------------------------- + public function can_access_blog($blogId, $uid) { + if(strlen($blogId) && (is_numeric($uid) || strlen($uid))) { + + try { + if(!is_numeric($uid)) { + $uid = $this->get_uid($uid); + } + if(!is_numeric($blogId)) { + //TODO: if this extended csb_blogAbstract{}, call get_blog_data_by_name() to make this easier. + $blogData = $this->get_blogs(array('blog_name'=>$blogId)); + if(count($blogData) == 1) { + $keys = array_keys($blogData); + $blogId = $keys[0]; + } + else { + throw new exception(__METHOD__ .": too many records found for blog name (". $blogId .")"); + } + } + //if this call doesn't cause an exception, we're good to go (add extra logic anyway) + $blogData = $this->get_blogs(array('blog_id'=>$blogId, 'uid'=>$uid)); + if(is_array($blogData) && count($blogData) == 1 && $blogData[$blogId]['uid'] == $uid) { + $retval = true; + } + else { + $retval = false; + } + } + catch(exception $e) { + //an exception means there was no record; check the permissions table. + $sql = "SELECT * FROM csblog_permission_table WHERE blog_id=". $blogId . + " AND uid=". $uid; + + $numrows = $this->run_sql($sql,false); + + $retval = false; + if($numrows == 1) { + $retval = true; + } + elseif($numrows > 1 || $numrows < 0) { + throw new exception(__METHOD__ .": invalid data returned, numrows=(". $numrows .")"); + } + } + } + else { + //they gave invalid data; default to no access. + $retval = false; + } + + return($retval); + + }//end can_access_blog() + //------------------------------------------------------------------------- + + + + //------------------------------------------------------------------------- + public function remove_permission($blogId, $fromUser) { + if(!is_numeric($fromUser) && is_string($fromUser) && strlen($fromUser)) { + $fromUser = $this->get_uid($fromUser); + } + + if(is_numeric($fromUser) && $fromUser > 0 && is_numeric($blogId) && $blogId > 0) { + $sql = "DELETE FROM csblog_permission_table WHERE blog_id=". $blogId + ." AND uid=". $fromUser; + + try { + $this->db->beginTrans(); + $numrows = $this->run_sql($sql, false); + + if($numrows == 0 || $numrows == 1) { + $this->db->commitTrans(); + $retval = $numrows; + } + else { + $this->db->rollbackTrans(); + throw new exception(__METHOD__ .": deleted too many records (". $numrows .")"); + } + } + catch(exception $e) { + throw new exception(__METHOD__ .": unable to delete permission... DETAILS::: ". $e->getMessage()); + } + } + else { + throw new exception(__METHOD__ .": invalid uid (". $fromUser .") or blogId (". $blogId .")"); + } + + return($retval); + }//end remove_permission() + //------------------------------------------------------------------------- + + +} +?> \ No newline at end of file Deleted: trunk/0.1/cs_location.class.php =================================================================== --- trunk/0.1/cs_location.class.php 2009-02-20 05:48:19 UTC (rev 9) +++ trunk/0.1/cs_location.class.php 2009-02-20 05:53:54 UTC (rev 10) @@ -1,128 +0,0 @@ -<?php - -require_once(dirname(__FILE__) .'/abstract/csb_dataLayer.abstract.class.php'); - -class csb_location extends csb_dataLayerAbstract { - - //------------------------------------------------------------------------- - public function __construct(array $dbParams=null) { - parent::__construct($dbParams); - - $this->gfObj = new cs_globalFunctions(); - - }//end __construct() - //------------------------------------------------------------------------- - - - - //------------------------------------------------------------------------- - public function add_location($location) { - if(is_string($location) && strlen($location) > 3) { - if(!preg_match('/^\//', $location)) { - $location = "/". $location; - } - $location = $this->fix_location($location); - $location = $this->gfObj->cleanString($location, "sql_insert"); - $sql = "INSERT INTO csblog_location_table (location) " . - "VALUES ('". $location ."')"; - - try { - $numrows = $this->run_sql($sql); - - - if($numrows == 1) { - //okay, retrieve the id inserted. - $retval = $this->db->get_currval('csblog_location_table_location_id_seq'); - } - else { - throw new exception(__METHOD__ .": failed to create location (". $location ."), " . - "numrows=(". $numrows .")"); - } - } - catch(exception $e) { - cs_debug_backtrace($this->gfObj->debugPrintOpt); - throw new exception(__METHOD__ .": failed to create location (". $location .")... DETAILS::: ". $e->getMessage()); - } - } - else { - throw new exception(__METHOD__ .": invalid location (". $location .")"); - } - - return($retval); - }//end add_location() - //------------------------------------------------------------------------- - - - - //------------------------------------------------------------------------- - public function get_location_id($location) { - if(is_string($location) && strlen($location) > 3) { - $location = $this->fix_location($location); - $location = $this->gfObj->cleanString($location, "sql_insert"); - $sql = "SELECT location_id FROM csblog_location_table " . - "WHERE location='". $location ."'"; - $numrows = $this->run_sql($sql, false); - - - if($numrows == 0) { - $retval = false; - } - elseif($numrows == 1) { - $retval = $this->db->farray(); - $retval = $retval[0]; - } - else { - throw new exception(__METHOD__ .": failed to retrieve location (". $location ."), " . - "invalid numrows (". $numrows .")"); - } - } - else { - throw new exception(__METHOD__ .": invalid location (". $location .")"); - } - - return($retval); - }//end get_location_id() - //------------------------------------------------------------------------- - - - - //------------------------------------------------------------------------- - public function fix_location($location) { - if(strlen($location)) { - $retval = $location; - if(!preg_match("/^\//", $retval)) { - $retval = "/". $retval; - } - $retval = preg_replace("/[^A-Za-z0-9\/_-]/", "", $retval); - $retval = preg_replace("/(\/){2,}/", "/", $retval); - $retval = preg_replace("/\/$/", "", $retval); - } - else { - throw new exception(__METHOD__ .": no valid location (". $location .")"); - } - - return($retval); - }//end fix_location() - //------------------------------------------------------------------------- - - - - //------------------------------------------------------------------------- - public function get_locations() { - $sql = "SELECT location_id, location FROM csblog_location_table ORDER BY location_id"; - $numrows = $this->run_sql($sql,false); - - if($numrows > 0) { - $retval = $this->db->farray_nvp('location_id', 'location'); - } - else { - throw new exception(__METHOD__ .": no records found (". $numrows .")"); - } - - return($retval); - }//end get_locations() - //------------------------------------------------------------------------- - - -} -?> \ No newline at end of file Deleted: trunk/0.1/cs_permission.class.php =================================================================== --- trunk/0.1/cs_permission.class.php 2009-02-20 05:48:19 UTC (rev 9) +++ trunk/0.1/cs_permission.class.php 2009-02-20 05:53:54 UTC (rev 10) @@ -1,146 +0,0 @@ -<?php - -require_once(dirname(__FILE__) .'/abstract/csb_dataLayer.abstract.class.php'); -require_once(dirname(__FILE__) .'/abstract/csb_blog.abstract.class.php'); - - -//TODO: this should extend csb_blogAbstract{} - -class csb_permission extends csb_dataLayerAbstract { - - //------------------------------------------------------------------------- - public function __construct(array $dbParams=null) { - parent::__construct($dbParams); - - $this->gfObj = new cs_globalFunctions(); - - }//end __construct() - //------------------------------------------------------------------------- - - - - //------------------------------------------------------------------------- - public function add_permission($blogId, $toUser) { - if(!is_numeric($toUser) && is_string($toUser) && strlen($toUser)) { - $toUser = $this->get_uid($toUser); - } - - if(is_numeric($toUser) && $toUser > 0 && is_numeric($blogId) && $blogId > 0) { - $this->db->beginTrans(); - $sql = "INSERT INTO csblog_permission_table (blog_id, uid) VALUES " . - "(". $blogId .", ". $toUser .")"; - $numrows = $this->run_sql($sql); - - if($numrows == 1) { - $this->db->commitTrans(); - $retval = $this->db->get_currval('csblog_permission_table_permission_id_seq'); - } - else { - $this->db->rollbackTrans(); - throw new exception(__METHOD__ .": invalid numrows (". $numrows .")"); - } - } - else { - throw new exception(__METHOD__ .": invalid uid (". $toUser .") or blogId (". $blogId .")"); - } - - return($retval); - }//end add_permission() - //------------------------------------------------------------------------- - - - - //------------------------------------------------------------------------- - public function can_access_blog($blogId, $uid) { - if(strlen($blogId) && (is_numeric($uid) || strlen($uid))) { - - try { - if(!is_numeric($uid)) { - $uid = $this->get_uid($uid); - } - if(!is_numeric($blogId)) { - //TODO: if this extended csb_blogAbstract{}, call get_blog_data_by_name() to make this easier. - $blogData = $this->get_blogs(array('blog_name'=>$blogId)); - if(count($blogData) == 1) { - $keys = array_keys($blogData); - $blogId = $keys[0]; - } - else { - throw new exception(__METHOD__ .": too many records found for blog name (". $blogId .")"); - } - } - //if this call doesn't cause an exception, we're good to go (add extra logic anyway) - $blogData = $this->get_blogs(array('blog_id'=>$blogId, 'uid'=>$uid)); - if(is_array($blogData) && count($blogData) == 1 && $blogData[$blogId]['uid'] == $uid) { - $retval = true; - } - else { - $retval = false; - } - } - catch(exception $e) { - //an exception means there was no record; check the permissions table. - $sql = "SELECT * FROM csblog_permission_table WHERE blog_id=". $blogId . - " AND uid=". $uid; - - $numrows = $this->run_sql($sql,false); - - $retval = false; - if($numrows == 1) { - $retval = true; - } - elseif($numrows > 1 || $numrows < 0) { - throw new exception(__METHOD__ .": invalid data returned, numrows=(". $numrows .")"); - } - } - } - else { - //they gave invalid data; default to no access. - $retval = false; - } - - return($retval); - - }//end can_access_blog() - //------------------------------------------------------------------------- - - - - //------------------------------------------------------------------------- - public function remove_permission($blogId, $fromUser) { - if(!is_numeric($fromUser) && is_string($fromUser) && strlen($fromUser)) { - $fromUser = $this->get_uid($fromUser); - } - - if(is_numeric($fromUser) && $fromUser > 0 && is_numeric($blogId) && $blogId > 0) { - $sql = "DELETE FROM csblog_permission_table WHERE blog_id=". $blogId - ." AND uid=". $fromUser; - - try { - $this->db->beginTrans(); - $numrows = $this->run_sql($sql, false); - - if($numrows == 0 || $numrows == 1) { - $this->db->commitTrans(); - $retval = $numrows; - } - else { - $this->db->rollbackTrans(); - throw new exception(__METHOD__ .": deleted too many records (". $numrows .")"); - } - } - catch(exception $e) { - throw new exception(__METHOD__ .": unable to delete permission... DETAILS::: ". $e->getMessage()); - } - } - else { - throw new exception(__METHOD__ .": invalid uid (". $fromUser .") or blogId (". $blogId .")"); - } - - return($retval); - }//end remove_permission() - //------------------------------------------------------------------------- - - -} -?> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |