Example #1
0
 public static function set_by_name($strName, $strValue)
 {
     if (!preg_match("/^[a-zA-Z0-9_.]*\$/", $strName)) {
         throw new Exception(ERRORMSG_INVALID);
     }
     $arrResults = clsDB::selectQueryObjects('setting', "\n\t\t\t\t\t\t\t\tSELECT *\n\t\t\t\t\t\t\t\tFROM `<<tbl><setting>>` \n\t\t\t\t\t\t\t\tWHERE `<<setting><name>>`='{$strName}'\n\t\t\t\t\t\t\t\t\tAND `<<isdel><setting>>`='0' ");
     if (sizeof($arrResults) == 0) {
         $objSetting = new clsDB('setting');
         $objSetting->set('name', $strName);
         $objSetting->set('valud', $strValue);
         $objSetting->save();
     } else {
         $objSetting = $arrResults[0];
         $objSetting->set('value', $strValue);
         $objSetting->save();
     }
 }
Example #2
0
 public static function getNewPictures($objUser)
 {
     $arrPictures = clsDB::selectQueryObjects('picture', "\n\t\t\tSELECT `<<tbl><picture>>`.*\n\t\t\tFROM `<<tbl><picture>>` \n\t\t\t\t\tJOIN `<<tbl><album>>` ON `<<foreign><picture><album>>`=`<<album><id>>`\n\t\t\t\tWHERE `<<isdel><picture>>`='0'\n\t\t\t\t\tAND `<<picture><confirmed>>`='1'\n\t\t\t\t\tAND `<<isdel><album>>`='0'\n\t\t\t\t\tAND `<<picture><id>>` NOT IN \n\t\t\t\t\t(\n\t\t\t\t\t\tSELECT `<<foreign><userpictureview><picture>>`\n\t\t\t\t\t\t\tFROM `<<tbl><userpictureview>>`\n\t\t\t\t\t\t\tWHERE `<<foreign><userpictureview><user>>`='" . $objUser->get('id') . "'\n\t\t\t\t\t\t\t\tAND `<<isdel><userpictureview>>`='0'\n\t\t\t\t\t)\n\t\t\t\tORDER BY `<<picture><date>>` DESC\n\t\t\t\t\t");
     $arrRet = array();
     foreach ($arrPictures as $objPicture) {
         $objAlbum = new clsAlbum($objPicture->get('album_id'));
         /* TODO: Speed this up? */
         if ($objAlbum->canView($objUser)) {
             $arrRet[] = new clsPicture($objPicture->get('id'));
         }
     }
     return $arrRet;
 }
Example #3
0
 public static function getPicturesByGroup($objUser, $objGroup)
 {
     $arrPictures = clsDB::selectQueryObjects('picture', "SELECT `<<tbl><picture>>`.*\n                                        FROM `<<tbl><album>>`\n                                            LEFT JOIN `<<tbl><picture>>` ON `<<foreign><picture><album>>`=`<<album><id>>`\n                                        WHERE `<<foreign><album><group>>`='" . $objGroup->get('id') . "' \n                                            AND `<<isdel><album>>`='0'\n                                            AND `<<isdel><picture>>`='0'\n                                            AND `<<picture><confirmed>>`='1'\n                                        ORDER BY `<<picture><date>>` DESC\n                                        ");
     $arrRet = array();
     /* TODO: Might be able to make this more efficient. Make sure that canView() isn't running a query every time. */
     foreach ($arrPictures as $objPicture) {
         $objAlbum = new clsAlbum($objPicture->get('album_id'));
         if ($objAlbum->canView($objUser)) {
             $arrRet[] = new clsPicture($objPicture->get('id'));
         }
     }
     return $arrRet;
 }
Example #4
0
 public static function getUserList()
 {
     $arrUsers = clsDB::selectQueryObjects('user', "SELECT `<<user><id>>` \n\t\t\t\t\t\t\t\tFROM `<<tbl><user>>` \n\t\t\t\t\t\t\t\tWHERE `<<isdel><user>>`='0' \n\t\t\t\t\t\t\t\tORDER BY `<<user><username>>`");
     $arrRet = array();
     foreach ($arrUsers as $objUser) {
         $arrRet[] = new clsUser($objUser->get('id'));
     }
     return $arrRet;
 }
Example #5
0
 public function getLastUpdated()
 {
     $arrPictures = clsDB::selectQueryObjects('picture', "SELECT * \n\t\t\t\t\t\t\tFROM `<<tbl><picture>>`\n\t\t\t\t\t\t\tWHERE `<<foreign><picture><album>>`='" . $this->get('id') . "'\n\t\t\t\t\t\t\t\tAND `<<isdel><picture>>`='0'\n\t\t\t\t\t\t\t\tAND `<<picture><confirmed>>`='1'\n\t\t\t\t\t\t\tORDER BY `<<picture><date>>` DESC\n\t\t\t\t\t\t\tLIMIT 0, 1");
     if (sizeof($arrPictures) == 0) {
         return 'Never';
     } else {
         return time_to_text(strtotime($arrPictures[0]->get('date')));
     }
 }
Example #6
0
 /** Loads a list of objects of the type, $name.  
  * $name      The name of the database, same as it would be passed in the contructor.  The table will be called
  *            tbl_$name.  
  * $start     The number of the first object that will be loaded.  Will be sanitized, so user input is allowed. 
  * $count     The total number of objects to load (the loaded objects will be from $start to $start+$count-1).   
  *            Will be sanitized, so user input is allowed. 
  * $orderby   The order to retrieve the objects in.  By default, the 'id' is used, which probably isn't the best
  *            way of doing it.   Will be sanitized, so user input is allowed. 
  * $order     In which direction the objects are loaded.  Must be either ASC or DESC.  
  * $where     The where clause.  This will NOT be sanitized in any way, so do NOT allow user input in!  Note that 
  *            the fields in the where clause have to have the table name appended to them, like 'test_test1 = 4', 
  *            since I don't control the conditions. 
  *
  * Returns	  The array of objects. 
  * 
  */
 public static function getListStatic($name, $where = '', $orderby = 'id', $order = 'ASC', $limit = null, $start = null)
 {
     /* Sanitize the variables */
     if (!clsDB::isValidFieldName($name)) {
         throw new Exception(ERRORMSG_INVALID);
     }
     if (!clsDB::isValidFieldName($orderby)) {
         throw new Exception(ERRORMSG_INVALID);
     }
     if ($order != 'ASC' && $order != 'DESC') {
         throw new Exception(ERRORMSG_INVALID);
     }
     if ($limit !== null && !is_numeric($limit)) {
         throw new Exception(ERRORMSG_INVALID);
     }
     if ($start !== null && !is_numeric($start)) {
         throw new Exception(ERRORMSG_INVALID);
     }
     /* If no where clause is given, create ours.  Otherwise, append ours to it. */
     if ($where == '') {
         $where = "`<<isdel><{$name}>>`='0'";
     } else {
         $where .= " AND `<<isdel><{$name}>>`='0'";
     }
     /* Build the query */
     $SQL = "SELECT * FROM `<<tbl><{$name}>>` WHERE {$where} ORDER BY `<<{$name}><{$orderby}>>` {$order}";
     if ($limit !== null) {
         $SQL .= " LIMIT {$limit}";
         if ($start !== null) {
             $SQL .= ", {$start}";
         }
     }
     /* Perform the query */
     return clsDB::selectQueryObjects($name, $SQL);
 }
Example #7
0
 public static function getNewComments($objUser)
 {
     $arrPictures = clsDB::selectQueryObjects('comment', "\n\t\t\t\t\tSELECT * \n\t\t\t\t\t\t\t, `<<comment><id>>` AS COMMENTFILTER \n\t\t\t\t\t\tFROM `<<tbl><comment>>`\n\t\t\t\t\t\t\tJOIN `<<tbl><picture>>` ON `<<foreign><comment><picture>>`=`<<picture><id>>`\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t`<<isdel><comment>>`='0'\n\t\t\t\t\t\t\tAND `<<isdel><picture>>`='0'\n\t\t\t\t\t\t\tAND `<<picture><confirmed>>`='1'\n\t\t\t\t\t\t\tAND `<<foreign><picture><user>>`='" . $objUser->get('id') . "' \n\t\t\t\t\t\t\tAND `<<comment><id>>` NOT IN\n\t\t\t\t\t\t\t(\n\t\t\t\t\t\t\t\tSELECT `<<comment><id>>`\n\t\t\t\t\t\t\t\t\tFROM `<<tbl><usercommentview>>` \n\t\t\t\t\t\t\t\t\t\tJOIN `<<tbl><comment>>` ON `<<foreign><usercommentview><comment>>`=`<<comment><id>>`\n\t\t\t\t\t\t\t\t\t\tJOIN `<<tbl><picture>>` ON `<<foreign><comment><picture>>`=`<<picture><id>>`\n\t\t\t\t\t\t\t\t\tWHERE `<<isdel><comment>>`='0'\n\t\t\t\t\t\t\t\t\t\tAND `<<isdel><usercommentview>>`='0'\n\t\t\t\t\t\t\t\t\t\tAND `<<isdel><picture>>`='0'\n\t\t\t\t\t\t\t\t\t\tAND `<<picture><confirmed>>`='1'\n\t\t\t\t\t\t\t\t\t\tAND `<<foreign><usercommentview><user>>`='" . $objUser->get('id') . "'\n\t\t\t\t\t\t\t\t\t\t" . ($blnAllPictures ? "" : " AND `<<foreign><picture><user>>`='" . $objUser->get('id') . "' ") . "\n\t\t\t\t\t\t\t\t\t\tAND `<<comment><id>>`=`COMMENTFILTER`\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t");
     return $arrPictures;
 }