Example #1
0
 public static function load_settings()
 {
     $arrSettings = clsDB::getListStatic('setting');
     foreach ($arrSettings as $objSetting) {
         define($objSetting->get('name'), $objSetting->get('value'));
     }
 }
Example #2
0
 public static function getRating($objPicture)
 {
     $arrRatings = clsDB::getListStatic('vote', "`<<foreign><vote><picture>>`='" . $objPicture->get('id') . "'");
     if (sizeof($arrRatings) == 0) {
         return -1;
     }
     if (SETTING_WEIGHTED_AVERAGE) {
         $arrWeights = array();
         /* Generate the weight array. For a MAX_VOTE of 10, it'll be 50, 51, 52, 53, 54, 55, 54, 53, 52, 51, 50. */
         for ($i = 0; $i <= MAX_VOTE; $i++) {
             $arrWeights[$i] = MAX_VOTE / 2 - abs($i - MAX_VOTE / 2) + 5 * MAX_VOTE;
         }
         $intTotal = 0;
         $intTotalWeights = 0;
         foreach ($arrRatings as $objRating) {
             $intTotal += $objRating->get('vote') * $arrWeights[$objRating->get('vote')];
             $intTotalWeights += $arrWeights[$objRating->get('vote')];
         }
         return round($intTotal / $intTotalWeights, 2);
     } else {
         $intTotal = 0;
         foreach ($arrRatings as $objRating) {
             $intTotal += $objRating->get('vote');
         }
         return round($intTotal / sizeof($arrRatings), 2);
     }
 }
Example #3
0
 public static function getGroupList($objUser)
 {
     if ($objUser && $objUser->get('is_admin')) {
         $arrGroups = clsDB::getListStatic('group');
     } else {
         $arrGroups = clsDB::selectQueryObjects('group', "\n\t\t\t\t\tSELECT * FROM\n\t\t\t\t\t(\n\t\t\t\t\t\t\tSELECT `<<group><id>>`, `<<group><name>>`\n\t\t\t\t\t\t\t\tFROM `<<tbl><group>>`\n\t\t\t\t\t\t\t\tWHERE `<<group><is_hidden>>`='0'\n\t\t\t\t\t\t\t\t\tAND `<<isdel><group>>`='0'\n\t\t\t\t\t" . ($objUser ? "\n\t\t\t\t\t\t\tUNION\n\t\t\t\t\t\t\t\tSELECT `<<group><id>>`, `<<group><name>>`\n\t\t\t\t\t\t\t\t\tFROM `<<tbl><group>>` \n\t\t\t\t\t\t\t\t\t\tJOIN `<<tbl><usergroup>>` ON `<<group><id>>`=`<<foreign><usergroup><group>>`\n\t\t\t\t\t\t\t\t\tWHERE `<<foreign><usergroup><user>>`='" . $objUser->get('id') . "' \n\t\t\t\t\t\t\t\t\t\tAND `<<isdel><group>>`='0'\n\t\t\t\t\t\t\t\t\t\tAND `<<isdel><usergroup>>`='0'\n\t\t\t\t\t\t\tUNION\n\t\t\t\t\t\t\t\tSELECT `<<group><id>>`, `<<group><name>>`\n\t\t\t\t\t\t\t\t\tFROM `<<tbl><group>>`\n\t\t\t\t\t\t\t\t\tWHERE `<<foreign><group><user>>`='" . $objUser->get('id') . "'\n\t\t\t\t\t\t\t\t\t\tAND `<<isdel><group>>`='0'\n\t\t\t\t\t\t" : "") . "\n\t\t\t\t\t) AS i\n\t\t\t\t\tGROUP BY `<<group><id>>` \n\t\t\t\t\tORDER BY `<<group><name>>`\n\t\t\t\t");
     }
     $arrRet = array();
     foreach ($arrGroups as $objGroup) {
         $arrRet[] = new clsGroup($objGroup->get('id'));
     }
     return $arrRet;
 }
Example #4
0
 public static function getThumbnail($objUser, $picture_id, $intWidth, $intHeight, $objAlbum)
 {
     if (!is_numeric($picture_id)) {
         throw new Exception(INVALID_VALUE);
     }
     if (!is_numeric($intWidth)) {
         throw new Exception(INVALID_VALUE);
     }
     if (!is_numeric($intHeight)) {
         throw new Exception(INVALID_VALUE);
     }
     /* This prevents the thumbnails from being bigger than the original. */
     if (!$objAlbum->isNew()) {
         $intWidth = min($intWidth, $objAlbum->get('max_width'));
         $intHeight = min($intHeight, $objAlbum->get('max_height'));
     }
     $arrThumbnails = clsDB::getListStatic('thumbnail', "`<<foreign><thumbnail><picture>>`='{$picture_id}' AND `<<thumbnail><width>>`='{$intWidth}' AND `<<thumbnail><height>>`='{$intHeight}'");
     if (sizeof($arrThumbnails) == 0) {
         $objPicture = new clsPicture($picture_id);
         list($img, $intActualWidth, $intActualHeight) = $objPicture->getResized($objUser, $intWidth, $intHeight);
         if (is_string($img)) {
             return $img;
         }
         $objThumbnail = new clsThumbnail();
         $objThumbnail->set('picture_id', $picture_id);
         $objThumbnail->set('width', $intWidth);
         $objThumbnail->set('height', $intHeight);
         $objThumbnail->set('actual_width', $intActualWidth);
         $objThumbnail->set('actual_height', $intActualHeight);
         $objThumbnail->set('date', date('Y-m-d H:i:s'));
         $result = $objThumbnail->setImage($img);
         if ($result) {
             return $result;
         }
         $objThumbnail->save();
     } else {
         $objThumbnail = new clsThumbnail($arrThumbnails[0]->get('id'));
     }
     return $objThumbnail;
 }
Example #5
0
<?php

require_once 'cls/clsParameters.php';
require_once 'cls/clsTemplate.php';
$objTemplate->setText('PAGETITLE', 'News');
if ($strSubAction == '' || $strSubAction == 'archive') {
    if ($strSubAction == 'archive') {
        $arrNews = clsDB::getListStatic('news', "", 'date', 'DESC');
    } else {
        $arrNews = clsDB::getListStatic('news', "", 'date', 'DESC', 0, 5);
        $objMiniMenu->add('News Archive', 'index.php?subaction=archive');
    }
    if ($objUser && $objUser->get('is_admin')) {
        $objMiniMenu->add('Post News', 'index.php?subaction=edit');
    }
    $objMiniMenu->add('Upload Image', 'index.php?action=upload');
    $objMiniMenu->add('Pending Uploads', 'index.php?action=upload&subaction=preview');
    foreach ($arrNews as $objNews) {
        if ($objUser && $objUser->get('is_admin')) {
            $objNewsTemplate = new clsTemplate('newsitemadmin');
        } else {
            $objNewsTemplate = new clsTemplate('newsitem');
        }
        $objNewsUser = $objNews->getForeignObject('user');
        $objAlbum = $objNews->getForeignObject('album');
        $objNewsTemplate->setText('ID', $objNews->get('id'));
        $objNewsTemplate->setText('USERID', $objNewsUser->get('id'));
        $objNewsTemplate->setText('USERNAME', $objNewsUser->get('username'));
        $objNewsTemplate->setText('DATE', date('Y-m-d', strtotime($objNews->get('date'))));
        $objNewsTemplate->setText('TITLE', $objNews->get('title'));
        $objNewsTemplate->setText('TEXT', bbcode_format($objNews->get('text')));
Example #6
0
    $objGroup->getFromRequest(array('id', 'name', 'is_private', 'is_hidden'));
    if ($objGroup->isNew()) {
        $objGroup->set('user_id', $objUser->get('id'));
    }
    $objGroup->save();
    header("Location: index.php?action=groups&subaction=view&message=group_saved&" . $objGroup->getIDPair());
}
if ($strSubAction == 'invite') {
    if (!$objGroup->isMember($objUser)) {
        throw new Exception('exception_accessdenied');
    }
    if ($objMember->isNew()) {
        $objTemplate->setText('PAGETITLE', "Inviting a user");
        $objBreadcrumbs->add('Inviting', 'index.php?action=groups&subaction=invite&' . $objGroup->getIDPair());
        $objMiniMenu->add('Back', 'index.php?action=groups&subaction=view&' . $objGroup->getIDPair());
        $arrMembers = clsDB::getListStatic('user', '', 'username');
        foreach ($arrMembers as $objMember) {
            print "<ul>";
            if (!$objGroup->isMemberOrPotential($objMember)) {
                print "<li><a href='index.php?action=groups&subaction=invite&" . $objGroup->getIDPair() . "&" . $objMember->getIDPair() . "'>" . $objMember->get('username') . "</a></li>";
            }
            print "</ul>";
        }
    } else {
        $strResult = $objGroup->inviteUser($objMember, $objUser);
        header("Location: index.php?action=groups&subaction=invite&message={$strResult}&" . $objGroup->getIDPair());
    }
}
if ($strSubAction == 'join') {
    if ($objGroup->isMemberOrPotential($objUser)) {
        throw new Exception('exception_accessdenied');
Example #7
0
 public static function getByName($strName)
 {
     /* By putting the username into an object, it is sanitized. */
     $objUser = new clsUser();
     $objUser->set('username', $strName);
     $arrResults = clsDB::getListStatic('user', "`<<user><username>>`='" . $objUser->get('username') . "'");
     if (sizeof($arrResults) == 0) {
         return null;
     }
     // Username wasn't found
     if (sizeof($arrResults) > 1) {
         throw new Exception("exception_multiplenames");
     }
     /* should never happen, but who knows? */
     return new clsUser($arrResults[0]->get('id'));
 }
Example #8
0
 public static function getUserFilter($strZeroCaption)
 {
     $str = "<form method='get'>\n\t\t\t\t\t<input type='hidden' name='action' value='albums'>\n\t\t\t\t\t<input type='hidden' name='subaction' value='useralbums'>\n\t\t\t\t\t<select name='user_id'> \n\t\t\t\t\t\t<option value='0'>{$strZeroCaption}</option>\n\t\t\t\t\t";
     $arrUsers = clsDB::getListStatic('user', '', 'username');
     foreach ($arrUsers as $objUser) {
         $str .= "<option value='" . $objUser->get('id') . "'>" . $objUser->get('username') . "</option>\n";
     }
     $str .= "\n\t\t\t\t\t</select>\n\t\t\t\t\t<input type='submit' value='Filter'>\n\t\t\t\t</form>";
     return $str;
 }
Example #9
0
                        }
                        print "<br><br>";
                    }
                }
            }
        }
    }
}
if ($strSubAction == 'settings_save') {
    $objSetting = new clsDB('setting');
    $objSetting->getFromRequest(array('id', 'value'));
    $objSetting->save();
    $strSubAction = 'settings';
}
if ($strSubAction == 'settings') {
    $arrSettings = clsDB::getListStatic('setting');
    print "<table>";
    print "<tr>";
    print "<td>Name</td><td>Value</td><td>Comments</td><td>Save</td>";
    print "</tr>";
    foreach ($arrSettings as $objSetting) {
        print "<form action='index.php' method='get'>";
        print $objSetting->getHiddenField('id');
        print "<input type='hidden' name='action'    value='admin'>";
        print "<input type='hidden' name='subaction' value='settings_save'>";
        print "<tr>";
        print "<td>" . $objSetting->get('name') . "</td>";
        print "<td>" . $objSetting->getTextField('value') . "</td>";
        print "<td>" . $objSetting->get('comment') . "</td>";
        print "<td>" . $objSetting->getSubmit('Save') . "</td>";
        print "</tr>";
Example #10
0
 /** This is a quick wrapper around getOptionsFromList that pulls an entire table into a list.  
  * I found myself using, getOptionsFromList(getListStatic('table')) way too many times, so this
  * will shorten that code.  */
 public static function getOptionsFromTable($strTableName, $strValueElement = 'name', $strKeyElement = 'id', $strZeroCaption = 'Please make a selection')
 {
     return clsDB::getOptionsFromList(clsDB::getListStatic($strTableName), $strValueElement, $strKeyElement, $strZeroCaption);
 }