Переглянути джерело

Ticket #270 - System and Studio queries updates.

AntonLV 10 роки тому
батько
коміт
0b39959505

+ 13 - 6
inc/classes/BxDolAccountQuery.php

@@ -209,15 +209,22 @@ class BxDolAccountQuery extends BxDolDb implements iBxDolSingleton
      */
     public function searchByTerm($sTerm, $iLimit)
     {
-        $aFieldsQuickSearch = array('name', 'email');
+    	$aBindings = array(
+    		'system' => 'system',
+    		'status' => BX_PROFILE_STATUS_ACTIVE,
+    		'limit' => (int)$iLimit
+    	);
+
         $sWhere = '';
-        foreach ($aFieldsQuickSearch as $sField)
-            $sWhere .= $this->prepare(" OR `c`.`$sField` LIKE ? ", '%' . $sTerm . '%');
+        $aFieldsQuickSearch = array('name', 'email');
+        foreach ($aFieldsQuickSearch as $sField) {
+        	$aBindings[$sField] = '%' . $sTerm . '%';
 
-        $sOrderBy = $this->prepare(" ORDER BY `added` DESC LIMIT ?", (int)$iLimit);
+            $sWhere .= " OR `c`.`$sField` LIKE :$sField ";
+        }
 
-        $sQuery = $this->prepare("SELECT `c`.`id` AS `content_id`, `p`.`account_id`, `p`.`id` AS `profile_id`, `p`.`status` AS `profile_status` FROM `sys_accounts` AS `c` INNER JOIN `sys_profiles` AS `p` ON (`p`.`content_id` = `c`.`id` AND `p`.`type` = ?) WHERE `p`.`status` = ?", 'system', BX_PROFILE_STATUS_ACTIVE);
-        return $this->getAll($sQuery . " AND (0 $sWhere) " . $sOrderBy);
+        $sQuery = "SELECT `c`.`id` AS `content_id`, `p`.`account_id`, `p`.`id` AS `profile_id`, `p`.`status` AS `profile_status` FROM `sys_accounts` AS `c` INNER JOIN `sys_profiles` AS `p` ON (`p`.`content_id` = `c`.`id` AND `p`.`type` = :system) WHERE `p`.`status` = :status AND (0 $sWhere) ORDER BY `added` DESC LIMIT :limit";
+        return $this->getAll($sQuery, $aBindings);
     }
 }
 

+ 13 - 4
inc/classes/BxDolAclQuery.php

@@ -276,12 +276,21 @@ class BxDolAclQuery extends BxDolDb implements iBxDolSingleton
 
     function updateActionTrack($iActionId, $iProfileId, $iActionsLeft, $iValidSince = 0)
     {
+    	$aBindings = array(
+    		'actions_left' => $iActionsLeft,
+    		'action_id' => $iActionId,
+    		'member_id' => $iProfileId
+    	);
+
         $sUpdateAddon = "";
-        if($iValidSince != 0)
-            $sUpdateAddon = $this->prepare(", ValidSince=FROM_UNIXTIME(?)", $iValidSince);
+        if($iValidSince != 0) {
+        	$aBindings['valid_since'] = $iValidSince;
 
-        $sQuery = $this->prepare("UPDATE `sys_acl_actions_track` SET `ActionsLeft`=?" . $sUpdateAddon . " WHERE `IDAction`=? AND `IDMember`=?", $iActionsLeft, $iActionId, $iProfileId);
-        return (int)$this->query($sQuery) > 0;
+            $sUpdateAddon = ", ValidSince=FROM_UNIXTIME(:valid_since)";
+        }
+
+        $sQuery = "UPDATE `sys_acl_actions_track` SET `ActionsLeft`=:actions_left" . $sUpdateAddon . " WHERE `IDAction`=:action_id AND `IDMember`=:member_id";
+        return (int)$this->query($sQuery, $aBindings) > 0;
     }
 
     function insertLevelByProfileId($iProfileId, $iMembershipId, $iDateStarts, $iDateExpires, $sTransactionId)

+ 70 - 40
inc/classes/BxDolCmtsQuery.php

@@ -59,9 +59,16 @@ class BxDolCmtsQuery extends BxDolDb
 
     function getCommentsCount ($iId, $iCmtVParentId = -1, $iAuthorId = 0, $sFilter = '')
     {
+    	$aBindings = array(
+    		'cmt_object_id' => $iId
+    	);
+
         $sWhereClause = '';
-        if((int)$iCmtVParentId >= 0)
-            $sWhereClause .= $this->prepare(" AND `{$this->_sTable}`.`cmt_vparent_id` = ?", $iCmtVParentId);
+        if((int)$iCmtVParentId >= 0) {
+        	$aBindings['cmt_vparent_id'] = $iCmtVParentId;
+
+            $sWhereClause .= " AND `{$this->_sTable}`.`cmt_vparent_id` = :cmt_vparent_id";
+        }
 
         $sJoinClause = '';
         switch($sFilter) {
@@ -74,21 +81,21 @@ class BxDolCmtsQuery extends BxDolDb
 	            break;
 
         	case BX_CMT_FILTER_OTHERS:
-        		$sWhereClause .= $this->prepare(" AND `{$this->_sTable}`.`cmt_author_id` <> ?", $iAuthorId);
+        		$aBindings['cmt_author_id'] = $iAuthorId;
+
+        		$sWhereClause .= " AND `{$this->_sTable}`.`cmt_author_id` <> :cmt_author_id";
         		break;
         }
 
-        $sQuery = $this->prepare("SELECT
-                COUNT(*)
-            FROM `{$this->_sTable}`
-            $sJoinClause
-            WHERE `{$this->_sTable}`.`cmt_object_id` = ?" . $sWhereClause, $iId);
-
-        return (int)$this->getOne($sQuery);
+        $sQuery = "SELECT COUNT(*) FROM `{$this->_sTable}` $sJoinClause WHERE `{$this->_sTable}`.`cmt_object_id` = :cmt_object_id" . $sWhereClause;
+        return (int)$this->getOne($sQuery, $aBindings);
     }
 
     function getComments ($iId, $iCmtVParentId = 0, $iAuthorId = 0, $sFilter = '', $aOrder = array(), $iStart = 0, $iCount = -1)
     {
+    	$aBindings = array(
+    		'cmt_object_id' => $iId
+    	);
         $sFields = $sJoin = "";
 
         $oVote = $this->_oMain->getVoteObject(0);
@@ -100,8 +107,11 @@ class BxDolCmtsQuery extends BxDolDb
         }
 
         $sWhereParent = '';
-        if((int)$iCmtVParentId >= 0)
-            $sWhereParent = $this->prepare(" AND `{$this->_sTable}`.`cmt_vparent_id` = ?", $iCmtVParentId);
+        if((int)$iCmtVParentId >= 0) {
+        	$aBindings['cmt_vparent_id'] = $iCmtVParentId;
+
+            $sWhereParent = " AND `{$this->_sTable}`.`cmt_vparent_id` = :cmt_vparent_id";
+        }
 
         if(in_array($sFilter, array(BX_CMT_FILTER_FRIENDS, BX_CMT_FILTER_SUBSCRIPTIONS))) {
             $oConnection = BxDolConnection::getObjectInstance($this->_oMain->getConnectionObject($sFilter));
@@ -125,9 +135,9 @@ class BxDolCmtsQuery extends BxDolDb
             }
         }
 
-        $sLimit = $iCount != -1 ? $this->prepare(" LIMIT ?, ?", (int)$iStart, (int)$iCount) : '';
+       	$sLimit = $iCount != -1 ? $this->prepareAsString(" LIMIT ?, ?", (int)$iStart, (int)$iCount) : '';
 
-        $sQuery = $this->prepare("SELECT
+        $sQuery = "SELECT
                 `{$this->_sTable}`.`cmt_id`,
                 `{$this->_sTable}`.`cmt_parent_id`,
                 `{$this->_sTable}`.`cmt_vparent_id`,
@@ -140,14 +150,14 @@ class BxDolCmtsQuery extends BxDolDb
                 $sFields
             FROM `{$this->_sTable}`
             $sJoin
-            WHERE `{$this->_sTable}`.`cmt_object_id` = ?" . $sWhereParent . $sOder . $sLimit, $iId);
+            WHERE `{$this->_sTable}`.`cmt_object_id` = :cmt_object_id" . $sWhereParent . $sOder . $sLimit;
 
-        return $this->getAll($sQuery);
+        return $this->getAll($sQuery, $aBindings);
     }
 
 	function getCommentsBy($aParams = array())
     {
-    	$aMethod = array('name' => 'getAll', 'params' => array(0 => 'query'));
+    	$aMethod = array('name' => 'getAll', 'params' => array(0 => 'query', 1 => array()));
         $sSelectClause = $sJoinClause = $sWhereClause = $sOrderClause = $sLimitClause = "";
 
         $sSelectClause = "
@@ -161,23 +171,32 @@ class BxDolCmtsQuery extends BxDolDb
             `{$this->_sTable}`.`cmt_replies`,
             `{$this->_sTable}`.`cmt_time`";
 
-        if(isset($aParams['object_id']))
-        	$sWhereClause .= $this->prepare(" AND `{$this->_sTable}`.`cmt_object_id` = ?" , (int)$aParams['object_id']);
+        if(isset($aParams['object_id'])) {
+        	$aMethod['params'][1]['cmt_object_id'] = (int)$aParams['object_id'];
+
+        	$sWhereClause .= " AND `{$this->_sTable}`.`cmt_object_id` = :cmt_object_id";
+        }
 
         switch($aParams['type']) {
             case 'latest':
-            	if(!empty($aParams['author']))
-            		$sWhereClause .= $this->prepare(" AND `{$this->_sTable}`.`cmt_author_id` " . (isset($aParams['others']) && (int)$aParams['others'] == 1 ? "<>" : "=") . " ?", (int)$aParams['author']);
+            	if(!empty($aParams['author'])) {
+            		$aMethod['params'][1]['cmt_author_id'] = (int)$aParams['author'];
+
+            		$sWhereClause .= " AND `{$this->_sTable}`.`cmt_author_id` " . (isset($aParams['others']) && (int)$aParams['others'] == 1 ? "<>" : "=") . " :cmt_author_id";
+            	}
 
                 $sOrderClause = "ORDER BY `{$this->_sTable}`.`cmt_time` DESC";
-                $sLimitClause = isset($aParams['per_page']) ? "LIMIT " . $aParams['start'] . ", " . $aParams['per_page'] : "";
+                $sLimitClause = "";
+                if(isset($aParams['per_page'])) {
+                	$aMethod['params'][1]['start'] = $aParams['start'];
+                	$aMethod['params'][1]['length'] = $aParams['per_page'];
+
+                	$sLimitClause = "LIMIT :start, :length";
+                }
                 break;
         }
 
-        $aMethod['params'][0] = "SELECT " . $sSelectClause . "
-            FROM `{$this->_sTable}` " . $sJoinClause . "
-            WHERE 1 " . $sWhereClause . " " . $sOrderClause . " " . $sLimitClause;
-
+        $aMethod['params'][0] = "SELECT " . $sSelectClause . " FROM `{$this->_sTable}` " . $sJoinClause . " WHERE 1 " . $sWhereClause . " " . $sOrderClause . " " . $sLimitClause;
 		return call_user_func_array(array($this, $aMethod['name']), $aMethod['params']);
     }
 
@@ -239,31 +258,43 @@ class BxDolCmtsQuery extends BxDolDb
 
     function getImages($iSystemId, $iCmtId, $iId = false)
     {
-        $sJoin = '';
-        $sWhere = $this->prepare(" AND `i`.`system_id` = ? ", $iSystemId);
+    	$aBindings = array(
+    		'system_id' => $iSystemId
+    	);
+
+        $sJoin = "";
+        $sWhere = " AND `i`.`system_id` = :system_id ";
 
         if (false !== $iCmtId) {
-            $sWhere .= $this->prepare(" AND `i`.`cmt_id` = ? ", $iCmtId);
+        	$aBindings['cmt_id'] = $iCmtId;
+
+            $sWhere .= " AND `i`.`cmt_id` = :cmt_id ";
         }
 
         if (false !== $iId) {
-            $sWhere .= $this->prepare(" AND `c`.`cmt_object_id` = ?", $iId);
+        	$aBindings['cmt_object_id'] = $iId;
+
+            $sWhere .= " AND `c`.`cmt_object_id` = :cmt_object_id";
             $sJoin .= " INNER JOIN `{$this->_sTable}` AS `c` ON (`i`.`cmt_id` = `c`.`cmt_id`) ";
         }
 
-        return $this->getAll("SELECT * FROM `{$this->_sTableImages2Entries}` AS `i` " . $sJoin . " WHERE 1 " . $sWhere);
+        return $this->getAll("SELECT * FROM `{$this->_sTableImages2Entries}` AS `i` " . $sJoin . " WHERE 1 " . $sWhere, $aBindings);
     }
 
     function deleteImages($iSystemId, $iCmtId)
     {
-        $sWhereAddon = '';
-        if (false !== $iCmtId)
-            $sWhereAddon = $this->prepare(" AND `cmt_id` = ? ", $iCmtId);
+    	$aBindings = array(
+    		'system_id' => $iSystemId
+    	);
 
-        $sQuery = $this->prepare("DELETE FROM `{$this->_sTableImages2Entries}` WHERE `system_id` = ?", $iSystemId);
-        $sQuery .= $sWhereAddon;
+        $sWhereAddon = "";
+        if ($iCmtId !== false) {
+        	$aBindings['cmt_id'] = $iCmtId;
 
-        return $this->query($sQuery);
+            $sWhereAddon = " AND `cmt_id` = :cmt_id ";
+        }
+
+        return $this->query("DELETE FROM `{$this->_sTableImages2Entries}` WHERE `system_id` = :system_id" . $sWhereAddon, $aBindings);
     }
 
     function updateRepliesCount($iCmtId, $iCount)
@@ -308,9 +339,8 @@ class BxDolCmtsQuery extends BxDolDb
         $aFiles = $this->convertImagesArray($this->getImages($aSystem['system_id'], false, $iObjectId));
 
         if ($aFiles) {
-            $sQuery = $this->prepare("DELETE FROM {$this->_sTableImages2Entries} WHERE `system_id` = ? ", $aSystem['system_id']);
-            $sQuery .= " AND `image_id` IN(" . $this->implode_escape($aFiles) . ") ";
-            $this->query ($sQuery);
+            $sQuery = $this->prepare("DELETE FROM {$this->_sTableImages2Entries} WHERE `system_id` = ? AND `image_id` IN(" . $this->implode_escape($aFiles) . ")", $aSystem['system_id']);
+            $this->query($sQuery);
         }
 
         if (null !== $aCmtIds) {

+ 4 - 7
inc/classes/BxDolConnectionQuery.php

@@ -79,7 +79,6 @@ class BxDolConnectionQuery extends BxDolDb
         $sWhere = " AND `c`.`initiator` = :initiator1";
         $sQuery = $this->_getConnectionsQuery($sWhere, $sJoin, '`c`.`content`', $isMutual, $iStart, $iLimit, $iOrder);
 
-        $sQuery = $this->prepare($sQuery);
         return $this->getColumn($sQuery, array(
     		'mutual' => $isMutual,
     		'initiator1' => $iInitiator1,
@@ -92,7 +91,6 @@ class BxDolConnectionQuery extends BxDolDb
         $sWhere = " AND `c`.`initiator` = :initiator";
         $sQuery = $this->_getConnectionsQuery($sWhere, '', '`c`.`content`', $isMutual, $iStart, $iLimit, $iOrder);
 
-        $sQuery = $this->prepare($sQuery);
         return $this->getColumn($sQuery, array(
         	'initiator' => $iInitiator
         ));
@@ -103,7 +101,6 @@ class BxDolConnectionQuery extends BxDolDb
         $sWhere = " AND `c`.`content` = :content";
         $sQuery = $this->_getConnectionsQuery($sWhere, '', '`c`.`initiator`', $isMutual, $iStart, $iLimit, $iOrder);
 
-        $sQuery = $this->prepare($sQuery);
         return $this->getColumn($sQuery, array(
         	'content' => $iContent
         ));
@@ -120,21 +117,21 @@ class BxDolConnectionQuery extends BxDolDb
 
     public function getConnectedContentCount ($iInitiator, $isMutual = false)
     {
-        $sWhere = $this->prepare(" AND `c`.`initiator` = ?", $iInitiator);
+        $sWhere = $this->prepareAsString(" AND `c`.`initiator` = ?", $iInitiator);
         $sQuery = $this->_getConnectionsQueryCount($sWhere, '', $isMutual);
         return $this->getOne($sQuery);
     }
 
     public function getConnectedInitiatorsCount ($iContent, $isMutual = false)
     {
-        $sWhere = $this->prepare(" AND `c`.`content` = ?", $iContent);
+        $sWhere = $this->prepareAsString(" AND `c`.`content` = ?", $iContent);
         $sQuery = $this->_getConnectionsQueryCount($sWhere, '', $isMutual);
         return $this->getOne($sQuery);
     }
 
     protected function _getConnectionsQueryCount ($sWhere, $sJoin = '', $isMutual = false)
     {
-        $sWhere .= (false !== $isMutual) ? $this->prepare(" AND `c`.`mutual` = ?", $isMutual) : '';
+        $sWhere .= (false !== $isMutual) ? $this->prepareAsString(" AND `c`.`mutual` = ?", $isMutual) : '';
         return "SELECT COUNT(`id`) FROM `" . $this->_sTable . "` AS `c` $sJoin WHERE 1 $sWhere";
     }
 
@@ -224,7 +221,7 @@ class BxDolConnectionQuery extends BxDolDb
 
     public function onModuleProfileDelete ($sModuleName, $sField = 'initiator')
     {
-        return $this->onModuleDeleteCustom ('sys_profiles', 'id', $sField, $this->prepare(" AND `sys_profiles`.`type` = ? ", $sModuleName));
+        return $this->onModuleDeleteCustom ('sys_profiles', 'id', $sField, $this->prepareAsString(" AND `sys_profiles`.`type` = ? ", $sModuleName));
     }
 
     protected function onModuleDeleteCustom ($sTable, $sFieldId, $sField = 'initiator', $sWhere = '')

+ 5 - 4
inc/classes/BxDolDb.php

@@ -220,7 +220,7 @@ class BxDolDb extends BxDol implements iBxDolSingleton
 		if($this->res($oStatement, $aBindings))
             $aResult = $oStatement->fetch(PDO::FETCH_NUM);
 
-        return count($aResult) ? $aResult[$iIndex] : false;
+        return is_array($aResult) && count($aResult) ? $aResult[$iIndex] : false;
     }
 
     /**
@@ -424,7 +424,6 @@ class BxDolDb extends BxDol implements iBxDolSingleton
         	$GLOBALS['bx_profiler']->beginQuery($oStatement->queryString);
 
 		$bResult = $oStatement->execute(!empty($aBindings) && is_array($aBindings) ? $aBindings : null);
-        //$bResult = !empty($aBindings) && is_array($aBindings) ? $oStatement->execute($aBindings) : $oStatement->execute();
 
         // we need to remeber last error message since mysql_ping will reset it on the next line !
         $this->_sErrorMessage = $bResult == false ? $oStatement->errorInfo() : '';
@@ -556,6 +555,8 @@ class BxDolDb extends BxDol implements iBxDolSingleton
 
     public function getParam($sKey, $bFromCache = true)
     {
+    	
+    	
         if (!$sKey)
             return false;
         if ($bFromCache && $this->isParamInCache($sKey)) {
@@ -984,8 +985,8 @@ EOJ;
                 $sQuery = str_replace($aReplace['from'], $aReplace['to'], $sQuery);
             if($sDelimiter != ';')
                 $sQuery = str_replace($sDelimiter, "", $sQuery);
-            $rResult = $this->res(trim($sQuery), false);
-            if(!$rResult) {
+
+            if($this->query(trim($sQuery)) === false) {
                 $aResult[] = array('query' => $sQuery, 'error' => $this->getErrorMessage());
                 if ($isBreakOnError)
                     break;

+ 1 - 1
inc/classes/BxDolModuleQuery.php

@@ -182,7 +182,7 @@ class BxDolModuleQuery extends BxDolDb implements iBxDolSingleton
 
     function getDependent($sUri)
     {
-        $sSql = "SELECT `id`, `title` FROM `sys_modules` WHERE `dependencies` LIKE '%" . $this->escape($sUri) . "%'";
+        $sSql = "SELECT `id`, `title` FROM `sys_modules` WHERE `dependencies` LIKE " . $this->escape('%' . $sUri . '%');
         return $this->getAll($sSql);
     }
 

+ 1 - 1
inc/classes/BxDolStorageQuery.php

@@ -146,7 +146,7 @@ class BxDolStorageQuery extends BxDolDb
             $sAdd = ", `modified` = :modified";
         }
 
-        $sQuery = $this->prepare("UPDATE " . $this->_sTableFiles . " SET `{$sField}` = :{$sField} {$sAdd} WHERE `id` = :id");
+        $sQuery = "UPDATE " . $this->_sTableFiles . " SET `{$sField}` = :{$sField} {$sAdd} WHERE `id` = :id";
         return $this->query($sQuery, $aBindings);
     }
 

+ 29 - 11
inc/classes/BxDolTranscoderQuery.php

@@ -55,14 +55,20 @@ class BxDolTranscoderQuery extends BxDolDb
 
     public function updateHandler ($iFileId, $mixedHandler)
     {
+    	$aBindings = array(
+    		'transcoder' => $this->_aObject['object'],
+    		'file_id' => $iFileId,
+    		'handler' => $mixedHandler
+    	);
+
         $sUpdateATime = '';
         if ($this->_aObject['atime_tracking']) {
-            $iTime = time();
-            $sUpdateATime = $this->prepare(", `atime` = ?", $iTime);
+        	$aBindings['atime'] = time();
+
+            $sUpdateATime = ", `atime` = :atime";
         }
-        $sQuery = $this->prepare("INSERT INTO {$this->_sTableFiles} SET `transcoder_object` = ?, `file_id` = ?, `handler` = ? $sUpdateATime
-            ON DUPLICATE KEY UPDATE `file_id` = ? $sUpdateATime", $this->_aObject['object'], $iFileId, $mixedHandler, $iFileId);
-        return $this->res($sQuery);
+
+        return $this->query("INSERT INTO {$this->_sTableFiles} SET `transcoder_object` = :transcoder, `file_id` = :file_id, `handler` = :handler $sUpdateATime ON DUPLICATE KEY UPDATE `file_id` = :file_id $sUpdateATime", $aBindings);
     }
 
     public function getFileIdByHandler ($mixedHandler)
@@ -192,12 +198,24 @@ class BxDolTranscoderQuery extends BxDolDb
         if (!$this->_sTableQueue)
             return false;
 
-        $sQueryVals = $this->prepare("`status` = ?, changed = ? WHERE `transcoder_object` = ? AND `file_id_source` = ?", $sStatus, time(), $this->_aObject['object'], $mixedId);
-        $sQueryServer = $sServer ? $this->prepare(" `server` = ?, ", $sServer) : '';
-        $sQueryLog = $sLog ? $this->prepare(" `log` = ?, ", $sLog) : '';
-        $sQueryResultFile = $mixedIdResult && $sFileUrlResult ? $this->prepare(" `file_id_result` = ?, `file_url_result` = ?, `file_ext_result` = ?, ", $mixedIdResult, $sFileUrlResult, $sFileExtResult) : '';
-        $sQueryAll = "UPDATE `" . $this->_sTableQueue . "` SET " . $sQueryServer . $sQueryLog . $sQueryResultFile . $sQueryVals;
-        return $this->query($sQueryAll);
+		$aSet = array(
+			'status' => $sStatus,
+			'changed' => time()
+		);
+
+		if($sLog)
+			$aSet['log'] = $sLog;
+        if($sServer)
+        	$aSet['server'] = $sServer;
+		if($mixedIdResult && $sFileUrlResult)
+			$aSet = array_merge($aSet, array(
+				'file_id_result' => $mixedIdResult,
+				'file_url_result' => $sFileUrlResult,
+				'file_ext_result' => $sFileExtResult
+			));
+
+        $sQuery = $this->prepare("UPDATE `" . $this->_sTableQueue . "` SET " . $this->arrayToSQL($aSet) . " WHERE `transcoder_object` = ? AND `file_id_source` = ?", $this->_aObject['object'], $mixedId);
+        return $this->query($sQuery);
     }
 
     protected function registerHandler ($sHandlerNameFunc, $sServiceFunc, $sObject, $sUnit)

+ 1 - 1
inc/classes/BxDolViewQuery.php

@@ -37,7 +37,7 @@ class BxDolViewQuery extends BxDolObjectQuery
         else {
         	$aBindings['viewer_nip'] = $iAuthorNip;
 
-            $sWhere = $this->prepare(" AND `viewer_id` = '0' AND `viewer_nip` = ? ", $iAuthorNip);
+            $sWhere = " AND `viewer_id` = '0' AND `viewer_nip` = :viewer_nip ";
         }
 
         $iDate = (int)$this->getOne("SELECT `date` FROM `{$this->_sTableTrack}` WHERE `object_id` = :object_id " . $sWhere, $aBindings);

+ 1 - 1
modules/base/notifications/classes/BxBaseModNotificationsDb.php

@@ -197,7 +197,7 @@ class BxBaseModNotificationsDb extends BxDolModuleDb
         switch($aParams['browse']) {
             case 'id':
                 $sMethod = 'getRow';
-                $sWhereClause = $this->prepare("AND `{$this->_sTable}`.`id`=? ", $aParams['value']);
+                $sWhereClause = $this->prepareAsString("AND `{$this->_sTable}`.`id`=? ", $aParams['value']);
                 $sLimitClause = "LIMIT 1";
                 break;
 

+ 54 - 16
modules/boonex/payment/classes/BxPaymentDb.php

@@ -51,7 +51,11 @@ class BxPaymentDb extends BxBaseModPaymentDb
         switch($aParams['type']) {
         	case 'by_name':
         		$aMethod['name'] = 'getRow';
-        		$sWhereClause = $this->prepare(" AND `tp`.`name`=?", $aParams['name']);
+        		$aMethod['params'][1] = array(
+                	'name' => $aParams['name']
+                );
+
+        		$sWhereClause = " AND `tp`.`name`=:name";
         		break;
 
 			case 'for_cart':
@@ -87,21 +91,28 @@ class BxPaymentDb extends BxBaseModPaymentDb
 
     public function getOptions($iUserId = BX_PAYMENT_EMPTY_ID, $iProviderId = 0)
     {
+    	$aBinding = array(
+    		'user_id' => $iUserId
+    	);
+
         if($iUserId == BX_PAYMENT_EMPTY_ID && empty($iProviderId))
            return $this->getAll("SELECT `id`, `name`, `type` FROM `" . $this->_sPrefix . "providers_options`");
 
         $sWhereAddon = "";
-        if(!empty($iProviderId))
-            $sWhereAddon = $this->prepare(" AND `tpo`.`provider_id`=?", $iProviderId);
+        if(!empty($iProviderId)) {
+        	$aBinding['provider_id'] = $iProviderId;
+
+            $sWhereAddon = " AND `tpo`.`provider_id`=:provider_id";
+        }
 
-        $sQuery = $this->prepare("SELECT
+        $sQuery = "SELECT
                `tpo`.`name` AS `name`,
                `tuv`.`value` AS `value`
             FROM `" . $this->_sPrefix . "providers_options` AS `tpo`
             LEFT JOIN `" . $this->_sPrefix . "user_values` AS `tuv` ON `tpo`.`id`=`tuv`.`option_id`
-            WHERE 1" . $sWhereAddon . " AND `tuv`.`user_id`=?", $iUserId);
+            WHERE 1" . $sWhereAddon . " AND `tuv`.`user_id`=:user_id";
 
-        return $this->getAllWithKey($sQuery, 'name');
+        return $this->getAllWithKey($sQuery, 'name', $aBinding);
     }
 
     public function updateOption($iUserId, $iOptionId, $sValue)
@@ -180,12 +191,20 @@ class BxPaymentDb extends BxBaseModPaymentDb
     	$sWhereClause = $sLimitClause = '';
         switch($aParams['type']) {
             case 'id':
-                $sWhereClause = $this->prepare(" AND `id`=?", $aParams['id']);
+            	$aMethod['params'][1] = array(
+                	'id' => $aParams['id']
+                );
+
+                $sWhereClause = " AND `id`=:id";
                 $sLimitClause = " LIMIT 1";
                 break;
 
             case 'order':
-            	$sWhereClause = $this->prepare(" AND `order`=?", $aParams['order']);
+            	$aMethod['params'][1] = array(
+                	'order' => $aParams['order']
+                );
+
+            	$sWhereClause = " AND `order`=:order";
                 $sLimitClause = " LIMIT 1";
                 break;
         }
@@ -225,7 +244,7 @@ class BxPaymentDb extends BxBaseModPaymentDb
 
         return (int)$this->query("DELETE FROM `" . $this->_sPrefix . "transactions_pending` WHERE `id` IN (" . $this->implode_escape($mixedId) . ")") > 0;
     }
-    
+
     /*
      * Processed Orders
      */
@@ -236,27 +255,46 @@ class BxPaymentDb extends BxBaseModPaymentDb
         $sWhereClause = "";
         switch($aParams['type']) {
             case 'id':
-                $sWhereClause = $this->prepare(" AND `tt`.`id`=?", $aParams['id']);
+            	$aMethod['params'][1] = array(
+                	'id' => $aParams['id']
+                );
+
+                $sWhereClause = " AND `tt`.`id`=:id";
                 break;
 
 			case 'pending_id':
-                $aMethod['name'] = 'getAll';
-                if(!empty($aParams['with_key'])) {
-					$aMethod['name'] = 'getAllWithKey';
+                if(empty($aParams['with_key'])) {
+                	$aMethod['name'] = 'getAll';
+                	$aMethod['params'][1] = array(
+						'pending_id' => $aParams['pending_id']
+					);
+                }
+                else {
+                	$aMethod['name'] = 'getAllWithKey';
 					$aMethod['params'][1] = $aParams['with_key'];
+					$aMethod['params'][2] = array(
+						'pending_id' => $aParams['pending_id']
+					);
                 }
-                $sWhereClause = $this->prepare(" AND `tt`.`pending_id`=?", $aParams['pending_id']);
+
+                $sWhereClause = " AND `tt`.`pending_id`=:pending_id";
                 break;
 
             case 'license':
                 $aMethod['name'] = 'getAll';
-                $sWhereClause = $this->prepare(" AND `tt`.`license`=?", $aParams['license']);
+                $aMethod['params'][1] = array(
+                	'license' => $aParams['license']
+                );
+
+                $sWhereClause = " AND `tt`.`license`=:license";
                 break;
 
             case 'mixed':
                 $aMethod['name'] = 'getAll';
+                $aMethod['params'][1] = $aParams['conditions'];
+
                 foreach($aParams['conditions'] as $sKey => $sValue)
-                    $sWhereClause .= $this->prepare(" AND `tt`.`" . $sKey . "`=?", $sValue);
+                    $sWhereClause .= " AND `tt`.`" . $sKey . "`=:" . $sKey;
                 break;
 
         }

+ 25 - 5
studio/classes/BxDolStudioDesignsQuery.php

@@ -25,12 +25,22 @@ class BxDolStudioDesignsQuery extends BxDolStudioPageQuery
         switch($aParams['type']) {
             case 'by_id':
                 $aMethod['name'] = 'getRow';
-                $sWhereClause .= $this->prepare(" AND `tm`.`id`=?", $aParams['value']);
+                $aMethod['params'][1] = array(
+                	'id' => $aParams['value']
+                );
+
+                $sWhereClause .= " AND `tm`.`id`=:id";
                 break;
+
             case 'by_name':
                 $aMethod['name'] = 'getRow';
-                $sWhereClause .= $this->prepare(" AND `tm`.`name`=?", $aParams['value']);
+                $aMethod['params'][1] = array(
+                	'name' => $aParams['value']
+                );
+
+                $sWhereClause .= " AND `tm`.`name`=:name";
                 break;
+
             case 'active':
                 $sWhereClause = " AND `tm`.`enabled`='1'";
                 break;
@@ -38,15 +48,25 @@ class BxDolStudioDesignsQuery extends BxDolStudioPageQuery
                 $sOrderClause = " `tm`.`uri` ASC ";
                 break;
             case 'all_by_id':
-                $sWhereClause .= $this->prepare(" AND `tm`.`id`=?", $aParams['value']);
+            	$aMethod['params'][1] = array(
+                	'id' => $aParams['value']
+                );
+
+                $sWhereClause .= " AND `tm`.`id`=:id";
                 $sOrderClause = " `tm`.`uri` ASC ";
                 break;
+
             case 'all_key_id':
                 $aMethod['name'] = 'getAllWithKey';
                 $aMethod['params'][1] = 'id';
 
-                if(isset($aParams['template']) && (int)$aParams['template'] != 0)
-                    $sWhereClause .= $this->prepare(" AND `tm`.`id`=?", $aParams['template']);
+                if(isset($aParams['template']) && (int)$aParams['template'] != 0) {
+                	$aMethod['params'][2] = array(
+	                	'id' => $aParams['template']
+	                );
+
+                    $sWhereClause .= " AND `tm`.`id`=:id";
+                }
                 break;
         }
 

+ 5 - 2
studio/classes/BxDolStudioFormsQuery.php

@@ -328,6 +328,7 @@ class BxDolStudioFormsQuery extends BxDolDb
 
     function deleteInputs($aParams)
     {
+    	$aBindings = array();
         $sWhereClause = $sLimitClause = "";
 
         switch($aParams['type']) {
@@ -337,14 +338,16 @@ class BxDolStudioFormsQuery extends BxDolDb
                     $this->query($sSql);
                 }
 
-                $sWhereClause = $this->prepare(" AND `ti`.`id`=? ", $aParams['value']);
+                $aBindings['id'] = $aParams['value'];
+
+                $sWhereClause = " AND `ti`.`id`=:id ";
                 break;
             case 'all':
                 break;
         }
 
         $sSql = "DELETE FROM `ti` USING `sys_form_inputs` AS `ti` WHERE 1 " . $sWhereClause . " " . $sLimitClause;
-        return (int)$this->query($sSql) > 0;
+        return (int)$this->query($sSql, $aBindings) > 0;
     }
 
     function checkInputsInDisplays($sObject, $sDisplayName)

+ 30 - 7
studio/classes/BxDolStudioLanguagesUtilsQuery.php

@@ -102,14 +102,20 @@ class BxDolStudioLanguagesUtilsQuery extends BxDolLanguagesQuery
 
     function deleteKeysBy($aParams = array())
     {
+    	$aBindings = array();
         $sWhereClause = "";
 
         switch($aParams['type']) {
             case 'by_key_id':
-                $sWhereClause = $this->prepare(" AND `tk`.`ID`=?", $aParams['value']);
+            	$aBindings['id'] = $aParams['value'];
+
+                $sWhereClause = " AND `tk`.`ID`=:id";
                 break;
+
             case 'by_cat_id':
-                $sWhereClause .= $this->prepare(" AND `tc`.`ID`=?", $aParams['value']);
+            	$aBindings['id'] = $aParams['value'];
+
+                $sWhereClause .= " AND `tc`.`ID`=:id";
                 break;
         }
 
@@ -119,7 +125,7 @@ class BxDolStudioLanguagesUtilsQuery extends BxDolLanguagesQuery
                     `sys_localization_keys` AS `tk`,
                     `sys_localization_strings` AS `ts`
                 WHERE `tk`.`ID`=`ts`.`IDKey` AND `tk`.`IDCategory`=`tc`.`ID`" . $sWhereClause;
-        return (int)$this->query($sSql);
+        return (int)$this->query($sSql, $aBindings);
     }
 
     function updateKeys($aParamsSet, $aParamsWhere)
@@ -157,17 +163,34 @@ class BxDolStudioLanguagesUtilsQuery extends BxDolLanguagesQuery
 
     function deleteStringsBy($aParams = array())
     {
+    	$aBindings = array();
         $sWhereClause = "";
 
         switch($aParams['type']) {
             case 'by_lang':
-                $sWhereClause .= $this->prepare(" AND `tl`.`ID`=?", $aParams['language_id']);
+            	$aBindings = array(
+            		'language_id' => $aParams['language_id']
+        		);
+
+                $sWhereClause .= " AND `tl`.`ID`=:language_id";
                 break;
+
             case 'by_cat_and_lang':
-                $sWhereClause .= $this->prepare(" AND `tc`.`ID`=? AND `tl`.`ID`=?", $aParams['category_id'], $aParams['language_id']);
+            	$aBindings = array(
+            		'category_id' => $aParams['category_id'],
+            		'language_id' => $aParams['language_id']
+            	);
+
+                $sWhereClause .= " AND `tc`.`ID`=:category_id AND `tl`.`ID`=:language_id";
                 break;
+
             case 'by_key_and_lang':
-            	$sWhereClause .= $this->prepare(" AND `tk`.`Key`=? AND `tl`.`ID`=?", $aParams['key'], $aParams['language_id']);
+            	$aBindings = array(
+            		'key' => $aParams['key'],
+            		'language_id' => $aParams['language_id']
+        		);
+
+            	$sWhereClause .= " AND `tk`.`Key`=:key AND `tl`.`ID`=:language_id";
                 break;
         }
 
@@ -177,7 +200,7 @@ class BxDolStudioLanguagesUtilsQuery extends BxDolLanguagesQuery
 				LEFT JOIN `sys_localization_strings` AS `ts` ON `tk`.`ID`=`ts`.`IDKey` 
 				LEFT JOIN `sys_localization_languages` AS `tl` ON `ts`.`IDLanguage`=`tl`.`ID`
                 WHERE 1" . $sWhereClause;
-        return (int)$this->query($sSql);
+        return (int)$this->query($sSql, $aBindings);
     }
 
     function addCategory($sName)

+ 20 - 5
studio/classes/BxDolStudioPermissionsQuery.php

@@ -34,11 +34,16 @@ class BxDolStudioPermissionsQuery extends BxDolAclQuery
 
     function deleteLevel($aParams)
     {
+    	$aBindings = array();
         $sWhereClause = $sLimitClause = "";
 
         switch($aParams['type']) {
             case 'by_id':
-                $sWhereClause .= $this->prepare("AND `tal`.`ID`=?", $aParams['value']);
+            	$aBindings = array(
+                	'level_id' => $aParams['value']
+                );
+
+                $sWhereClause .= "AND `tal`.`ID`=:level_id";
                 break;
         }
 
@@ -46,7 +51,7 @@ class BxDolStudioPermissionsQuery extends BxDolAclQuery
             USING `sys_acl_levels` AS `tal`
             LEFT JOIN `sys_acl_matrix` AS `tam` ON `tal`.`ID`=`tam`.`IDLevel`
             WHERE 1 " . $sWhereClause . " " . $sLimitClause;
-        return (int)$this->query($sSql) > 0;
+        return (int)$this->query($sSql, $aBindings) > 0;
     }
 
     function switchAction($iLevelId, $iActionId, $bEnable)
@@ -69,9 +74,14 @@ class BxDolStudioPermissionsQuery extends BxDolAclQuery
         switch($aParams['type']) {
             case 'by_level_action_ids':
                 $aMethod['name'] = 'getRow';
+                $aMethod['params'][1] = array(
+                	'level_id' => $aParams['level_id'],
+                	'action_id' => $aParams['action_id']
+                );
+
                 $sSelectClause = ", `taa`.`Title` AS `action_title`, `taa`.`Countable` AS `action_countable`";
                 $sJoinClause = "LEFT JOIN `sys_acl_actions` AS `taa` ON `tam`.`IDAction`=`taa`.`ID` ";
-                $sWhereClause = $this->prepare(" AND `tam`.`IDLevel`=? AND `tam`.`IDAction`=? ", $aParams['level_id'], $aParams['action_id']);
+                $sWhereClause = " AND `tam`.`IDLevel`=:level_id AND `tam`.`IDAction`=:action_id ";
                 break;
         }
 
@@ -102,15 +112,20 @@ class BxDolStudioPermissionsQuery extends BxDolAclQuery
 
     function deleteActions($aParams)
     {
+    	$aBindings = array();
         $sWhereClause = "";
 
         switch($aParams['type']) {
             case 'by_level_id':
-                $sWhereClause .= $this->prepare("AND `IDLevel`=?", $aParams['value']);
+            	$aBindings = array(
+            		'level_id' => $aParams['value']
+            	);
+
+                $sWhereClause .= "AND `IDLevel`=:level_id";
                 break;
         }
 
-        return (int)$this->query("DELETE FROM `sys_acl_matrix` WHERE 1 " . $sWhereClause) > 0;
+        return (int)$this->query("DELETE FROM `sys_acl_matrix` WHERE 1 " . $sWhereClause, $aBindings) > 0;
     }
 }
 

+ 6 - 1
studio/classes/BxDolStudioPolyglotQuery.php

@@ -51,8 +51,13 @@ class BxDolStudioPolyglotQuery extends BxDolStudioLanguagesUtilsQuery
         switch($aParams['type']) {
             case 'by_id':
                 $aMethod['name'] = 'getRow';
-                $sWhereClause = $this->prepare(" AND `tet`.`ID`=? ", $aParams['value']);
+                $aMethod['params'][1] = array(
+                	'id' => $aParams['value']
+                );
+
+                $sWhereClause = " AND `tet`.`ID`=:id ";
                 break;
+
             case 'counter_by_modules':
                 $aMethod['name'] = 'getPairs';
                 $aMethod['params'][1] = 'module';

+ 1 - 1
studio/classes/BxDolStudioStoreQuery.php

@@ -27,7 +27,7 @@ class BxDolStudioStoreQuery extends BxDolStudioModulesQuery
     			break;
     	}
 
-    	$sSql = $this->prepare("SELECT `id` FROM `sys_cron_jobs` WHERE name=? LIMIT 1", $sJobName);
+    	$sSql = $this->prepare("SELECT `id` FROM `sys_cron_jobs` WHERE `name`=? LIMIT 1", $sJobName);
     	return (int)$this->getOne($sSql) > 0;
     }
 }