Explorar o código

#52 - Get rid of duplicates in code (inc -> classes).

AntonLV %!s(int64=12) %!d(string=hai) anos
pai
achega
c99ee0a650

+ 10 - 53
inc/classes/BxDolCmts.php

@@ -7,6 +7,7 @@
  * @{
  * @{
  */
  */
 
 
+bx_import('BxDolObject');
 bx_import('BxDolCmtsQuery');
 bx_import('BxDolCmtsQuery');
 
 
 define('BX_CMT_OLD_VOTES', 365*86400); ///< comment votes older than this number of seconds will be deleted automatically 
 define('BX_CMT_OLD_VOTES', 365*86400); ///< comment votes older than this number of seconds will be deleted automatically 
@@ -129,10 +130,8 @@ define('BX_CMT_RATE_VALUE_MINUS', -1);
  *      - $aExtra['rate'] - comment rate 1 or -1
  *      - $aExtra['rate'] - comment rate 1 or -1
  *
  *
  */
  */
-class BxDolCmts extends BxDol implements iBxDolReplaceable
+class BxDolCmts extends BxDolObject implements iBxDolReplaceable
 {
 {
-	protected $_oQuery = null;
-
 	protected $_sFormObject;
 	protected $_sFormObject;
 	protected $_sFormDisplayPost;
 	protected $_sFormDisplayPost;
 	protected $_sFormDisplayEdit;
 	protected $_sFormDisplayEdit;
@@ -155,10 +154,6 @@ class BxDolCmts extends BxDol implements iBxDolReplaceable
 	protected $_sBaseUrl = '';
 	protected $_sBaseUrl = '';
 	protected $_sListAnchor = '';
 	protected $_sListAnchor = '';
 
 
-	protected $_sSystem = 'profile'; ///< current comment system name
-    protected $_aSystem = array (); ///< current comments system array
-    protected $_iId = 0; ///< obect id to be commented
-
     protected $_aMarkers = array ();
     protected $_aMarkers = array ();
 
 
     protected $_sDisplayType = '';
     protected $_sDisplayType = '';
@@ -178,17 +173,12 @@ class BxDolCmts extends BxDol implements iBxDolReplaceable
      * $sSystem - comments system name
      * $sSystem - comments system name
      * $iId - obect id to be commented
      * $iId - obect id to be commented
      */
      */
-    function BxDolCmts( $sSystem, $iId, $iInit = 1)
+    function BxDolCmts($sSystem, $iId, $iInit = 1)
     {
     {
-        parent::BxDol();
-
-        $this->_aSystems = $this->getSystems();
-		if(!isset($this->_aSystems[$sSystem]))
+        parent::__construct($sSystem, $iId, $iInit);
+        if(empty($this->_sSystem))
 			return;
 			return;
 
 
-        $this->_sSystem = $sSystem;
-        $this->_aSystem = $this->_aSystems[$sSystem];
-
 		$this->_aSystem['table_images'] = 'sys_cmts_images';
 		$this->_aSystem['table_images'] = 'sys_cmts_images';
 		$this->_aSystem['table_images2entries'] = 'sys_cmts_images2entries';
 		$this->_aSystem['table_images2entries'] = 'sys_cmts_images2entries';
 
 
@@ -235,9 +225,6 @@ class BxDolCmts extends BxDol implements iBxDolReplaceable
 
 
 		$this->_sMenuObjManage = 'sys_cmts_item_manage';
 		$this->_sMenuObjManage = 'sys_cmts_item_manage';
 		$this->_sMenuObjActions = 'sys_cmts_item_actions';
 		$this->_sMenuObjActions = 'sys_cmts_item_actions';
-		
-        if ($iInit)
-            $this->init($iId);
     }
     }
 
 
 	/**
 	/**
@@ -276,6 +263,7 @@ class BxDolCmts extends BxDol implements iBxDolReplaceable
             $GLOBALS['bx_dol_cmts_systems'] = BxDolDb::getInstance()->fromCache('sys_objects_cmts', 'getAllWithKey', '
             $GLOBALS['bx_dol_cmts_systems'] = BxDolDb::getInstance()->fromCache('sys_objects_cmts', 'getAllWithKey', '
                 SELECT
                 SELECT
                     `ID` as `system_id`,
                     `ID` as `system_id`,
+                    `ID` as `id`,
                     `Name` AS `name`,
                     `Name` AS `name`,
                     `Table` AS `table`,
                     `Table` AS `table`,
                     `CharsPostMin` AS `chars_post_min`,
                     `CharsPostMin` AS `chars_post_min`,
@@ -331,38 +319,16 @@ class BxDolCmts extends BxDol implements iBxDolReplaceable
 
 
     public function init ($iId)
     public function init ($iId)
     {
     {
-        if (empty($this->iId) && $iId)
-            $this->setId($iId);
+    	$bResult = parent::init($iId);
+    	if(!$bResult)
+    		return $bResult;
 
 
 		$this->addMarkers(array(
 		$this->addMarkers(array(
 			'object_id' => $this->getId(),
 			'object_id' => $this->getId(),
 			'user_id' => $this->_getAuthorId()
 			'user_id' => $this->_getAuthorId()
 		));
 		));
-    }
-
-    public function getId ()
-    {
-        return $this->_iId;
-    }
-
-    public function isEnabled ()
-    {
-        return isset($this->_aSystem['is_on']) && $this->_aSystem['is_on'];
-    }
 
 
-	public function getSystemId()
-    {
-        return $this->_aSystem['system_id'];
-    }
-
-    public function getSystemName()
-    {
-        return $this->_sSystem;
-    }
-
-	public function getSystemInfo()
-    {
-        return $this->_aSystem;
+		return $bResult;
     }
     }
 
 
 	public function getMaxLevel()
 	public function getMaxLevel()
@@ -439,15 +405,6 @@ class BxDolCmts extends BxDol implements iBxDolReplaceable
     	return true;
     	return true;
     }
     }
 
 
-    /**
-     * set id to operate with votes
-     */
-    public function setId ($iId)
-    {
-        if ($iId == $this->getId()) return;
-        $this->_iId = $iId;
-    }
-
 	/**
 	/**
      * Add replace markers.
      * Add replace markers.
      * @param $a array of markers as key => value
      * @param $a array of markers as key => value

+ 0 - 13
inc/classes/BxDolFtp.php

@@ -71,19 +71,6 @@ class BxDolFtp extends BxDolFile {
         return $bResult;
         return $bResult;
     }
     }
 
 
-    protected function _readDirectory($sFilePath) {
-        if(!is_dir($sFilePath) || !($rSource = opendir($sFilePath))) return false;
-
-        $aResult = array();
-        while(($sFile = readdir($rSource)) !== false) {
-            if($sFile == '.' || $sFile =='..' || $sFile[0] == '.') continue;
-            $aResult[] = $sFile;
-        }
-        closedir($rSource);
-
-        return $aResult;
-    }
-
     protected function _deleteDirectory($sPath) {
     protected function _deleteDirectory($sPath) {
         if($this->_isDirectory($sPath)) {
         if($this->_isDirectory($sPath)) {
             if(substr($sPath, -1) != '/')
             if(substr($sPath, -1) != '/')

+ 87 - 0
inc/classes/BxDolObject.php

@@ -0,0 +1,87 @@
+<?php defined('BX_DOL') or defined('BX_DOL_INSTALL') or die('hack attempt');
+/**
+ * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
+ * CC-BY License - http://creativecommons.org/licenses/by/3.0/
+ *
+ * @defgroup    DolphinCore Dolphin Core
+ * @{
+ */
+
+
+/** 
+ * @page objects Objects
+ * Classes which represents high level programming constructions to generate ready functionality, like Comments, Votings, Forms. 
+ */
+
+
+/**
+ * Base class for all Dolphin Object classes
+ */
+class BxDolObject extends BxDol {
+	protected $_iId = 0;    ///< item id the action to be performed with
+    protected $_sSystem = ''; ///< current system name
+    protected $_aSystem = array(); ///< current system array
+
+    protected $_oQuery = null;
+
+    public function __construct($sSystem, $iId, $iInit = 1) {
+    	parent::BxDol();
+
+    	$this->_aSystems = $this->getSystems();
+        if(!isset($this->_aSystems[$sSystem]))
+			return;
+
+        $this->_sSystem = $sSystem;
+		$this->_aSystem = $this->_aSystems[$sSystem];
+
+		if(!$this->isEnabled()) 
+			return;
+
+		if($iInit)
+			$this->init($iId);
+    }
+
+	public function init($iId)
+    {
+    	if(!$this->isEnabled()) 
+        	return false;
+
+        if(empty($this->_iId) && $iId)
+			$this->setId($iId);
+
+		return true;
+    }
+
+	public function getSystemId()
+    {
+        return $this->_aSystem['id'];
+    }
+
+    public function getSystemName()
+    {
+        return $this->_sSystem;
+    }
+
+	public function getSystemInfo()
+    {
+        return $this->_aSystem;
+    }
+
+	public function getId()
+    {
+        return $this->_iId;
+    }
+
+	public function setId($iId)
+    {
+        if($iId == $this->getId())
+        	return;
+
+        $this->_iId = $iId;
+    }
+
+	public function isEnabled ()
+    {
+        return $this->_aSystem && (int)$this->_aSystem['is_on'] == 1;
+    }
+}

+ 5 - 63
inc/classes/BxDolView.php

@@ -7,6 +7,7 @@
  * @{
  * @{
  */
  */
 
 
+bx_import('BxDolObject');
 bx_import('BxDolViewQuery');
 bx_import('BxDolViewQuery');
 
 
 define ('BX_DOL_VIEW_OLD_VIEWS', 3 * 86400); ///< views older than this number of seconds will be deleted automatically
 define ('BX_DOL_VIEW_OLD_VIEWS', 3 * 86400); ///< views older than this number of seconds will be deleted automatically
@@ -46,35 +47,18 @@ define ('BX_DOL_VIEW_OLD_VIEWS', 3 * 86400); ///< views older than this number o
  * @endcode
  * @endcode
  *
  *
  */
  */
-class BxDolView extends BxDol
+class BxDolView extends BxDolObject
 {
 {
-    var $_iId = 0;    ///< item id to be viewed
-    var $_sSystem = ''; ///< current view system name
-    var $_aSystem = array (); ///< current view system array
-
-    var $_oQuery = null;
-
     /**
     /**
      * Constructor
      * Constructor
      */
      */
     function BxDolView($sSystem, $iId, $iInit = 1)
     function BxDolView($sSystem, $iId, $iInit = 1)
     {
     {
-    	parent::__construct();
-
-    	$this->_aSystems = $this->getSystems();
-        if(!isset($this->_aSystems[$sSystem]))
-			return;
-
-        $this->_sSystem = $sSystem;
-		$this->_aSystem = $this->_aSystems[$sSystem];
-
-		if(!$this->isEnabled()) 
+    	parent::__construct($sSystem, $iId, $iInit);
+		if(empty($this->_sSystem))
 			return;
 			return;
-
+    	
         $this->_oQuery = new BxDolViewQuery($this);
         $this->_oQuery = new BxDolViewQuery($this);
-
-        if($iInit)
-        	$this->init($iId);
     }
     }
 
 
    /**
    /**
@@ -150,48 +134,6 @@ class BxDolView extends BxDol
         return $iResult;
         return $iResult;
     }
     }
 
 
-	public function init($iId)
-    {
-    	if(!$this->isEnabled()) 
-        	return;
-
-        if(empty($this->_iId) && $iId)
-			$this->setId($iId);
-    }
-
-	public function getSystemId()
-    {
-        return $this->_aSystem['id'];
-    }
-
-    public function getSystemName()
-    {
-        return $this->_sSystem;
-    }
-
-	public function getSystemInfo()
-    {
-        return $this->_aSystem;
-    }
-
-    public function getId()
-    {
-        return $this->_iId;
-    }
-
-    public function setId($iId)
-    {
-        if($iId == $this->getId())
-        	return;
-
-        $this->_iId = $iId;
-    }
-
-    public function isEnabled ()
-    {
-        return $this->_aSystem && (int)$this->_aSystem['is_on'] == 1;
-    }
-
 	function doView()
 	function doView()
     {
     {
         if(!$this->isEnabled()) 
         if(!$this->isEnabled()) 

+ 5 - 67
inc/classes/BxDolVote.php

@@ -7,6 +7,7 @@
  * @{
  * @{
  */
  */
 
 
+bx_import('BxDolObject');
 bx_import('BxDolVoteQuery');
 bx_import('BxDolVoteQuery');
 
 
 define('BX_DOL_VOTE_OLD_VOTES', 365 * 86400); ///< votes older than this number of seconds will be deleted automatically
 define('BX_DOL_VOTE_OLD_VOTES', 365 * 86400); ///< votes older than this number of seconds will be deleted automatically
@@ -85,32 +86,15 @@ define('BX_DOL_VOTE_USAGE_DEFAULT', BX_DOL_VOTE_USAGE_BLOCK);
  *
  *
  */
  */
 
 
-class BxDolVote extends BxDol
+class BxDolVote extends BxDolObject
 {
 {
-    protected $_iId = 0;    ///< item id to be rated
-    protected $_sSystem = ''; ///< current rating system name
-    protected $_aSystem = array(); ///< current rating system array
-
-    protected $_oQuery = null;
-
-    protected function __construct($sSystem, $iId, $iInit = 1)
+    public function __construct($sSystem, $iId, $iInit = 1)
     {
     {
-        parent::__construct();
-
-        $this->_aSystems = $this->getSystems();
-        if(!isset($this->_aSystems[$sSystem]))
-			return;
-
-        $this->_sSystem = $sSystem;
-		$this->_aSystem = $this->_aSystems[$sSystem];
-
-		if(!$this->isEnabled()) 
+        parent::__construct($sSystem, $iId, $iInit);
+        if(empty($this->_sSystem))
 			return;
 			return;
 
 
         $this->_oQuery = new BxDolVoteQuery($this);
         $this->_oQuery = new BxDolVoteQuery($this);
-
-        if($iInit)
-			$this->init($iId);
     }
     }
 
 
 	/**
 	/**
@@ -191,43 +175,6 @@ class BxDolVote extends BxDol
         return $iResult;
         return $iResult;
     }
     }
 
 
-    public function init($iId)
-    {
-    	if(!$this->isEnabled()) 
-        	return;
-
-        if(empty($this->_iId) && $iId)
-			$this->setId($iId);
-    }
-
-    /**
-     * Settings functions
-     */
-	public function getSystemId()
-    {
-        return $this->_aSystem['id'];
-    }
-
-    public function getSystemName()
-    {
-        return $this->_sSystem;
-    }
-
-	public function getSystemInfo()
-    {
-        return $this->_aSystem;
-    }
-
-	public function getId()
-    {
-        return $this->_iId;
-    }
-
-    public function isEnabled()
-    {
-        return (int)$this->_aSystem['is_on'] == 1;
-    }
-
 	public function isUndo()
 	public function isUndo()
     {
     {
         return (int)$this->_aSystem['is_undo'] == 1;
         return (int)$this->_aSystem['is_undo'] == 1;
@@ -252,15 +199,6 @@ class BxDolVote extends BxDol
         return (int)$this->_aSystem['max_value'];
         return (int)$this->_aSystem['max_value'];
     }
     }
 
 
-    public function setId($iId)
-    {
-        if($iId == $this->getId())
-        	return;
-
-        $this->_iId = $iId;
-    }
-
-
 	/**
 	/**
      * Interface functions for outer usage
      * Interface functions for outer usage
      */
      */