function Main()
{
    global $site;
    global $tmpl;
    global $date_format;
    $sRetHtml = '';
    $oBlogs = new BxDolBlogs(true);
    $oBlogs->bAdminMode = true;
    $oBlogs->sCommonCSS = <<<EOF
<link href="{$site['url']}templates/tmpl_{$tmpl}/css/blogs_common.css" rel="stylesheet" type="text/css" />
EOF;
    $sRetHtml .= $oBlogs->GenCommandForms();
    switch ($_REQUEST['action']) {
        //print functions
        case 'top_blogs':
            $sRetHtml .= $oBlogs->GenBlogLists('top');
            break;
        case 'show_member_blog':
            $sRetHtml .= $oBlogs->GenMemberBlog();
            break;
        case 'top_posts':
            $sRetHtml .= $oBlogs->GenPostLists('top');
            break;
        case 'new_post':
            $sRetHtml .= $oBlogs->AddNewPostForm();
            break;
        case 'show_member_post':
            $sRetHtml .= $oBlogs->GenPostPage();
            break;
        case 'search_by_tag':
            $sRetHtml .= $oBlogs->GenSearchResult();
            break;
            //forms of editing
        //forms of editing
        case 'add_category':
            $sRetHtml .= $oBlogs->GenEditCategoryForm();
            break;
        case 'edit_category':
            $iCategoryID = (int) $_REQUEST['categoryID'];
            $sRetHtml .= $oBlogs->GenEditCategoryForm($iCategoryID);
            break;
        case 'edit_post':
            $iPostID = (int) $_POST['EditPostID'];
            $sRetHtml .= $oBlogs->AddNewPostForm($iPostID);
            break;
            //non safe functions
        //non safe functions
        case 'create_blog':
            $sRetHtml .= $oBlogs->ActionCreateBlog();
            break;
        case 'edit_blog':
            $sRetHtml .= $oBlogs->ActionEditBlog();
            $iOwnerID = (int) $_REQUEST['EOwnerID'];
            $sRetHtml .= $oBlogs->GenMemberBlog($iOwnerID);
            break;
        case 'delete_blog':
            $sRetHtml .= $oBlogs->ActionDeleteBlogSQL();
            $sRetHtml .= $oBlogs->GenBlogLists('last');
            break;
        case 'addcategory':
            $sRetHtml .= $oBlogs->ActionUpdateCategory();
            $iOwnerID = (int) $_REQUEST['OwnerID'];
            $_REQUEST['category'] = mysql_insert_id();
            $sRetHtml .= $oBlogs->GenMemberBlog($iOwnerID);
            break;
        case 'editcategory':
            $sRetHtml .= $oBlogs->ActionUpdateCategory(TRUE);
            $iOwnerID = (int) $_REQUEST['OwnerID'];
            $_REQUEST['category'] = mysql_insert_id();
            $sRetHtml .= $oBlogs->GenMemberBlog($iOwnerID);
            break;
        case 'delete_category':
            $sRetHtml .= $oBlogs->ActionDeleteCategory();
            $iOwnerID = (int) $_REQUEST['OwnerID'];
            $sRetHtml .= $oBlogs->GenMemberBlog($iOwnerID);
            break;
        case 'del_img':
            $sRetHtml .= $oBlogs->ActionDelImg();
            $sRetHtml .= $oBlogs->GenPostPage();
            break;
        case 'add_post':
            $arrPostAdv = $oBlogs->GetPostArrByPostValues();
            $arrErr = $oBlogs->GetCheckErrors($arrPostAdv);
            if (empty($arrErr)) {
                $iLastID = -1;
                $sRetHtml .= $oBlogs->ActionAddNewPost($iLastID);
                $_REQUEST['post_id'] = $iLastID;
                $sRetHtml .= $oBlogs->GenPostPage();
            } else {
                $sRetHtml .= $oBlogs->AddNewPostForm(-1, $arrErr);
            }
            break;
        case 'post_updated':
            $iPostID = (int) $_POST['EditedPostID'];
            $arrPostAdv = $oBlogs->GetPostArrByPostValues();
            $arrErr = $oBlogs->GetCheckErrors($arrPostAdv);
            if (empty($arrErr)) {
                $sRetHtml .= $oBlogs->ActionEditPost();
                $_REQUEST['post_id'] = $iPostID;
                $sRetHtml .= $oBlogs->GenPostPage();
            } else {
                $sRetHtml .= $oBlogs->AddNewPostForm($iPostID, $arrErr);
            }
            break;
        case 'delete_post':
            $iOwnerID = (int) $_REQUEST['DOwnerID'];
            $sRetHtml .= $oBlogs->ActionDeletePost();
            $sRetHtml .= $oBlogs->GenMemberBlog($iOwnerID);
            break;
            /*case 'addcomment':
            			$sRetHtml .= $oBlogs->ActionAddBlogComment();
            			$iPostID = (int)($_POST['CommPostID']);
            			$iOwnerID = (int)($_POST['ownerID']);
            			$_REQUEST['post_id'] = $iPostID;
            			$sRetHtml .= $oBlogs->GenPostPage();
            			break;
            		case 'editcomment':
            			$sRetHtml .= $oBlogs->ActionEditComment();
            			$iPostID = (int)($_POST['EPostID']);
            			$iOwnerID = (int)($_POST['ownerID']);
            			$_REQUEST['post_id'] = $iPostID;
            			$sRetHtml .= $oBlogs->GenPostPage();
            			break;
            		case 'delete_comment':
            			$sRetHtml .= $oBlogs->ActionDeleteComment();
            			$iPostID = (int)($_POST['DPostID']);
            			$iOwnerID = (int)($_POST['ownerID']);
            			$_REQUEST['post_id'] = $iPostID;
            			$sRetHtml .= $oBlogs->GenPostPage();
            			break;*/
        /*case 'addcomment':
        			$sRetHtml .= $oBlogs->ActionAddBlogComment();
        			$iPostID = (int)($_POST['CommPostID']);
        			$iOwnerID = (int)($_POST['ownerID']);
        			$_REQUEST['post_id'] = $iPostID;
        			$sRetHtml .= $oBlogs->GenPostPage();
        			break;
        		case 'editcomment':
        			$sRetHtml .= $oBlogs->ActionEditComment();
        			$iPostID = (int)($_POST['EPostID']);
        			$iOwnerID = (int)($_POST['ownerID']);
        			$_REQUEST['post_id'] = $iPostID;
        			$sRetHtml .= $oBlogs->GenPostPage();
        			break;
        		case 'delete_comment':
        			$sRetHtml .= $oBlogs->ActionDeleteComment();
        			$iPostID = (int)($_POST['DPostID']);
        			$iOwnerID = (int)($_POST['ownerID']);
        			$_REQUEST['post_id'] = $iPostID;
        			$sRetHtml .= $oBlogs->GenPostPage();
        			break;*/
        default:
            $sRetHtml .= $oBlogs->GenBlogLists('last');
            break;
    }
    print $sRetHtml;
}
    function showBlockProfileBlog($sCaption, $bNoDB = false)
    {
        global $site;
        $ID = $this->_iProfileID;
        if ($ID > 0) {
            $sQuery = "\r\n\t\t\tSELECT DISTINCT\r\n\t\t\t\tCOUNT(`BlogPosts`.`PostID`)\r\n\t\t\tFROM `BlogCategories`\r\n\t\t\tINNER JOIN `BlogPosts` ON\r\n\t\t\t\t `BlogCategories`.`CategoryID` = `BlogPosts`.`CategoryID`\r\n\t\t\tWHERE\r\n\t\t\t\t`BlogCategories`.`OwnerID`  = {$ID} AND\r\n\t\t\t\t`BlogPosts`.`PostReadPermission` = 'public' AND\r\n\t\t\t\t`BlogPosts`.`PostStatus`         = 'approval'\r\n\t\t\t";
            $iBlogs = db_value($sQuery);
            if ($iBlogs > 0) {
                $oBlogs = new BxDolBlogs();
                $sBlocks = $oBlogs->GenAnyBlockContent('last', $ID);
                $ret = <<<EOF
<div id="container_blogs">
\t{$sBlocks}
</div>
EOF;
                $show_hide = $this->genShowHideItem('container_blogs');
                if ($bNoDB) {
                    return $ret;
                } else {
                    echo DesignBoxContent(_t($sCaption), $ret, 1, $show_hide);
                }
            } else {
                return;
            }
        } else {
            if ($bNoDB) {
                return MsgBox(_t('_im_textNoCurrUser'));
            } else {
                echo MsgBox(_t('_im_textNoCurrUser'));
            }
        }
    }
 function getBlockCode_Blogs()
 {
     global $site;
     $mode = $_REQUEST['blogs_mode'];
     if ($mode != 'rand' and $mode != 'latest' and $mode != 'top') {
         $mode = 'latest';
     }
     //generate top menu
     $aDBTopMenu = array();
     foreach (array('latest', 'top', 'rand') as $myMode) {
         switch ($myMode) {
             case 'top':
                 $OrderBy = '`num_com` DESC';
                 $sTabTitle = _t('_Top');
                 break;
             case 'latest':
                 $OrderBy = '`PostDate` DESC';
                 $sTabTitle = _t('_Latest');
                 break;
             case 'rand':
                 $OrderBy = 'RAND()';
                 $sTabTitle = _t('_Random');
                 break;
         }
         $aDBTopMenu[$sTabTitle] = array('href' => "{$_SERVER['PHP_SELF']}?blogs_mode={$myMode}", 'dynamic' => true, 'active' => $myMode == $mode);
     }
     //generate content
     $iTotalNum = db_value("SELECT COUNT(*) AS 'Cnt' FROM `BlogPosts` WHERE `PostStatus` = 'approval' AND `PostReadPermission` = 'public'");
     $oBlogs = new BxDolBlogs();
     if ($iTotalNum) {
         $iResPerPage = (int) getParam("max_blogs_on_home");
         $iTotalPages = ceil($iTotalNum / $iResPerPage);
         $page = (int) $_REQUEST['blogs_page'];
         if ($page < 1 or $mode == 'rand') {
             $page = 1;
         }
         if ($page > $iTotalPages) {
             $page = $iTotalPages;
         }
         $sqlLimitFrom = ($page - 1) * $iResPerPage;
         //$oBlogs = new BxDolBlogs();
         $sBlocks = $oBlogs->GenAnyBlockContent($mode, 0, "LIMIT {$sqlLimitFrom}, {$iResPerPage}");
         $ret = $sBlocks;
     } else {
         $ret = '<div class="no_result"><div>' . _t("_No blogs available") . '</div></div>';
     }
     //generate bottom menu
     $aDBBottomMenu = array();
     if ($iTotalPages > 1) {
         if ($page > 1) {
             $prevPage = $page - 1;
             $aDBBottomMenu[_t('_Back')] = array('href' => "{$_SERVER['PHP_SELF']}?blogs_mode={$mode}&amp;blogs_page={$prevPage}", 'dynamic' => true, 'class' => 'backMembers');
         }
         if ($page < $iTotalPages) {
             $nextPage = $page + 1;
             $aDBBottomMenu[_t('_Next')] = array('href' => "{$_SERVER['PHP_SELF']}?blogs_mode={$mode}&amp;blogs_page={$nextPage}", 'dynamic' => true, 'class' => 'moreMembers');
         }
         $sBMViewAllLink = $oBlogs->isPermalinkEnabled() ? "{$site['url']}blogs/" : "{$site['url']}blogs.php";
         $aDBBottomMenu[_t('_View All')] = array('href' => $sBMViewAllLink, 'dynamic' => false, 'class' => 'viewAllMembers');
     }
     return array($ret, $aDBTopMenu, $aDBBottomMenu);
 }
function profile_delete($ID)
{
    global $MySQL;
    global $dir;
    global $site;
    global $logged;
    $ID = (int) $ID;
    if (!$ID) {
        return false;
    }
    if (!getProfileInfo($ID)) {
        return false;
    }
    modules_del($ID);
    db_res("DELETE FROM `VKisses` WHERE `ID` = '{$ID}' OR `Member` = '{$ID}'");
    db_res("DELETE FROM `Profiles` WHERE `ID` = '{$ID}'");
    if (!mysql_affected_rows()) {
        return false;
    }
    db_res("DELETE FROM `BlockList` WHERE `ID` = '{$ID}' OR `Profile` = '{$ID}';");
    db_res("DELETE FROM `ProfilesTrack` WHERE `Member` = '{$ID}' OR `Profile` = '{$ID}'");
    db_res("DELETE FROM `Messages` WHERE Recipient = {$ID} ");
    db_res("DELETE FROM `Guestbook` WHERE Recipient = {$ID} ");
    db_res("DELETE FROM `aff_members` WHERE idProfile = {$ID}");
    db_res("DELETE FROM `HotList` WHERE ID = {$ID} OR Profile = {$ID}");
    db_res("DELETE FROM `FriendList` WHERE ID = {$ID} OR Profile = {$ID}");
    db_res("DELETE FROM `BlockList` WHERE ID = {$ID} OR Profile = {$ID}");
    db_res("DELETE FROM `BoughtContacts` WHERE `IDBuyer` = {$ID} OR `IDContact` = {$ID}");
    db_res("DELETE FROM `ProfileMemLevels` WHERE `IDMember` = {$ID}");
    db_res("DELETE FROM `ProfilesComments` WHERE `Sender` = {$ID} OR `Recipient` = {$ID}");
    db_res("DELETE FROM `ProfilesPolls` WHERE `id_profile` = {$ID}");
    db_res("DELETE FROM `Tags` WHERE `ID` = {$ID} AND `Type` = 'profile'");
    db_res("DELETE FROM `GroupsMembers` WHERE `memberID` = {$ID}");
    // delete profile votings
    require_once BX_DIRECTORY_PATH_CLASSES . 'BxDolVoting.php';
    $oVotingProfile = new BxDolVoting('profile', 0, 0);
    $oVotingProfile->deleteVotings($ID);
    // delete profile comments
    require_once BX_DIRECTORY_PATH_CLASSES . 'BxDolCmts.php';
    $oCmts = new BxDolCmts('profile', $ID);
    $oCmts->onObjectDelete();
    // delete all comments in all comments' systems, this user posted
    $oCmts->onAuthorDelete($ID);
    // Clean gallery
    $albumsRes = db_res("SELECT `ID` FROM `GalleryAlbums` WHERE `IDMember` = {$ID}");
    while ($albumArr = mysql_fetch_assoc($albumsRes)) {
        $albumID = $albumArr['ID'];
        $objectsRes = db_res("SELECT `Filename`, `ThumbFilename` FROM `GalleryObjects` WHERE `IDAlbum` = {$albumID}");
        while ($objectArr = mysql_fetch_assoc($objectsRes)) {
            @unlink("{$dir['gallery']}{$objectArr['Filename']}");
            if (strlen($objectArr['ThumbFilename']) && file_exists("{$dir['gallery']}{$objectArr['ThumbFilename']}")) {
                @unlink("{$dir['gallery']}{$objectArr['ThumbFilename']}");
            }
        }
        db_res("DELETE FROM `GalleryObjects` WHERE `IDAlbum` = {$albumID}");
    }
    db_res("DELETE FROM `GalleryAlbums` WHERE `IDMember` = {$ID}");
    // Clean customizations
    $customArr = db_arr("SELECT `BackgroundFilename` FROM `ProfilesSettings` WHERE `IDMember` = {$ID}");
    if (strlen($customArr['BackgroundFilename']) && file_exists($dir['profileImage'] . $customArr['BackgroundFilename']) && is_file($dir['profileImage'] . $customArr['BackgroundFilename'])) {
        unlink($dir['profileImage'] . $customArr['BackgroundFilename']);
    }
    db_res("DELETE FROM `ProfilesSettings` WHERE `IDMember` = {$ID}");
    // delete media
    $rMedia = db_res("SELECT `med_id`, `med_file`, `med_type` FROM `media` WHERE `med_prof_id` = {$ID}");
    $oVotingMedia = new BxDolVoting('media', 0, 0);
    while ($aMedia = mysql_fetch_assoc($rMedia)) {
        switch ($aMedia['med_type']) {
            case 'photo':
                $medDir = $dir['profileImage'] . $ID . "/";
                @unlink($medDir . 'icon_' . $aMedia['med_file']);
                @unlink($medDir . 'photo_' . $aMedia['med_file']);
                @unlink($medDir . 'thumb_' . $aMedia['med_file']);
                break;
            case 'audio':
                $medDir = $dir['profileSound'] . $ID . "/";
                @unlink($medDir . $aMedia['med_file']);
                break;
            case 'video':
                $medDir = $dir['profileVideo'] . $ID . "/";
                @unlink($medDir . $aMedia['med_file']);
                break;
        }
        // delete media voting
        $oVotingMedia->deleteVotings($aMedia['med_id']);
    }
    $aMem = array();
    $aMedia = array('photo', 'music', 'video');
    foreach ($aMedia as $sVal) {
        $oMedia = new BxDolSharedMedia($sVal, $site, $dir, $aMem);
        $oMedia->deleteUserGallery($ID, $logged);
    }
    db_res("DELETE FROM `media` WHERE `med_prof_id` = {$ID}");
    @rmdir($dir['profileImage'] . $ID);
    @rmdir($dir['profileVideo'] . $ID);
    @rmdir($dir['profileSound'] . $ID);
    //Clean blogs
    $aBlog = db_arr("SELECT `ID` FROM `Blogs` WHERE `OwnerID` = {$ID}");
    $iBlogID = $aBlog['ID'];
    if ($iBlogID > 0) {
        //Clean blogs
        $oBlogs = new BxDolBlogs(TRUE);
        $oBlogs->bAdminMode = TRUE;
        (int) ($_REQUEST['DeleteBlogID'] = $iBlogID);
        $oBlogs->ActionDeleteBlogSQL();
    }
    //delete user classifieds
    $oClassifieds = new BxDolClassifieds();
    $oClassifieds->bAdminMode = TRUE;
    $oClassifieds->DeleteProfileAdvertisement($ID);
    //delete user events
    $oEvents = new BxDolEvents();
    $oEvents->bAdminMode = TRUE;
    $oEvents->DeleteProfileEvents($ID);
    //delete cache file
    $sCacheFile = $dir['cache'] . 'user' . $ID . '.php';
    @unlink($sCacheFile);
    reparseObjTags('profile', $ID);
}
* Dolphin is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the Creative Commons Attribution 3.0 License for more details. 
* You should have received a copy of the Creative Commons Attribution 3.0 License along with Dolphin, 
* see license.txt file; if not, write to marketing@boonex.com
***************************************************************************/
require_once 'inc/header.inc.php';
require_once BX_DIRECTORY_PATH_INC . 'design.inc.php';
require_once BX_DIRECTORY_PATH_INC . 'profiles.inc.php';
require_once BX_DIRECTORY_PATH_INC . 'utils.inc.php';
require_once BX_DIRECTORY_PATH_CLASSES . 'BxDolBlogs.php';
// --------------- page variables and login
$_page['name_index'] = 49;
$_page['css_name'] = 'blogs.css';
check_logged();
$oBlogs = new BxDolBlogs(FALSE);
$_ni = $_page['name_index'];
$_page_cont[$_ni]['page_main_code'] = PageCompBlogs();
$_page['extra_js'] = $oTemplConfig->sTinyMceEditorCompactJS;
$_page['header'] = $oBlogs->GetHeaderString();
$_page['header_text'] = $oBlogs->GetHeaderString();
function PageCompBlogs()
{
    global $site;
    global $date_format;
    global $oBlogs;
    $sRetHtml = '';
    $sRetHtml .= $oBlogs->GenCommandForms();
    switch ($_REQUEST['action']) {
        //print functions
        case 'top_blogs':