function indexAction($id = null)
 {
     $p = Tools::getValue('page', 1);
     if (!empty($id)) {
         $sql = "select ID, Name, MetaKeywords, MetaRobots, Description from ArticleCategories where (ID = {$id}) and (IsDeleted = 0);";
         $category = GetMainConnection()->query($sql)->fetch();
         if (empty($category['ID'])) {
             return AddAlertMessage('danger', 'Категории статей не существует.', '/');
         }
         $CategoryName = $category['Name'];
         $sql = "SELECT count(*) as RecordCount " . "FROM Articles a " . "WHERE a.CategoryID = {$id} " . "AND a.isActive = 1 " . "AND a.IsDeleted = 0";
         $rec = GetMainConnection()->query($sql)->fetch();
         $total = ceil($rec['RecordCount'] / ARTICLES_PER_PAGE);
         $sql = "SELECT a.ID, a.CategoryID, a.Name, a.ShortDescription, a.count_likes, a.CountComments, MainImageExt " . "FROM Articles a " . "WHERE a.CategoryID = {$id} " . "AND a.isActive = 1 " . "AND a.IsDeleted = 0 " . "ORDER BY a.CreateDate DESC, a.ID DESC " . "LIMIT " . ($p > 0 ? $p - 1 : 0) * ARTICLES_PER_PAGE . ", " . ARTICLES_PER_PAGE;
         $articles = GetMainConnection()->query($sql)->fetchAll();
     } else {
         $category = null;
         $CategoryName = 'Все статьи';
         $article = new Articles($this->context);
         $total = ceil($article->getArticles($p, null, true) / ARTICLES_PER_PAGE);
         $articles = $article->getArticles($p);
     }
     $this->view->setVars(array('CategoryName' => $CategoryName, 'articles' => $articles, 'pagination' => array('total_pages' => $total, 'current' => $p)));
     $this->view->breadcrumbs = array(array('url' => '/category', 'title' => 'Все статьи'));
     if (isset($category)) {
         $this->view->breadcrumbs[] = array('url' => '/articles/c-' . $id, 'title' => $CategoryName);
         $this->view->meta = array('meta_title' => $CategoryName, 'meta_description' => $category['Description'], 'meta_keywords' => $category['MetaKeywords']);
     } else {
         $this->view->meta = array('meta_title' => $CategoryName, 'meta_description' => $CategoryName, 'meta_keywords' => $CategoryName);
     }
     $this->view->generate();
 }
 function indexAction()
 {
     $p = Tools::getValue('page', 1);
     $q = Tools::getValue('q', '');
     $AuthorID = Tools::getValue('author', null);
     $articles = new Articles($this->context);
     if ($AuthorID != null) {
         $sql = "SELECT ID, Name FROM Authors WHERE ID = {$AuthorID};";
         $author = GetMainConnection()->query($sql)->fetch();
         if (empty($author['ID'])) {
             return AddAlertMessage('danger', 'Такого автора не существует.', '/');
         }
         $AuthorName = $author['Name'];
         $total = ceil($articles->getArticles($p, 'AuthorID = ' . $AuthorID, true) / ARTICLES_PER_PAGE);
         $articles = $total > 0 ? $articles->getArticles($p, 'AuthorID = ' . $AuthorID) : null;
     } else {
         $AuthorName = '';
         $AddWhere = empty($q) ? '' : '(Name LIKE "%' . $q . '%" OR Description LIKE "%' . $q . '%")';
         $total = ceil($articles->getArticles($p, $AddWhere, true) / ARTICLES_PER_PAGE);
         $articles = $total > 0 ? $articles->getArticles($p, $AddWhere) : null;
     }
     $this->view->setVars(array('q' => $q, 'AuthorName' => $AuthorName, 'articles' => $articles, 'pagination' => array('total_pages' => $total, 'current' => $p)));
     $this->view->breadcrumbs = array(array('url' => '/search', 'title' => 'Поиск'));
     $this->view->generate();
 }
 public function indexAction($id = null)
 {
     if (empty($id)) {
         return AddAlertMessage('danger', 'Статьи не существует.', '/');
     }
     $vUserID = GetUserID();
     $UnknownUserGUID = GetUnknownUserGUID();
     $IsNotifyRecipientActive = false;
     if ($vUserID != 0) {
         $vAddWhere = "((UserID = {$vUserID}) or (UnknownUserGUID = '{$UnknownUserGUID}'))";
         $UnknownUserGUIDForViewed = "";
         $IsNotifyRecipientActive = Emails_IsNotifyRecipientActive(1, $id, $_SESSION['auth']['email']);
     } else {
         $vAddWhere = "(UnknownUserGUID = '{$UnknownUserGUID}')";
         $UnknownUserGUIDForViewed = $UnknownUserGUID;
     }
     // Регистрация просмотра статьи пользователем
     $sql = "insert into ArticleViewed(ArticleID, UnknownUserGUID, UserID, LastView) " . "values({$id}, '{$UnknownUserGUIDForViewed}', {$vUserID}, '" . GetLocalDateTimeAsSQLStr() . "') " . "on duplicate key update " . "LastView = '" . GetLocalDateTimeAsSQLStr() . "';";
     $this->db->exec($sql);
     $article = new Articles($this->context, 'ID = "' . $id . '"');
     if (!isset($article->ID) || $article->ID == null) {
         return AddAlertMessage('danger', 'Статьи не существует.', '/');
     }
     if ($article->IsActive != '1' && !Tools::getValue('preview')) {
         return AddAlertMessage('danger', 'Статья в черновике.', '/');
     }
     $article->PhotoL = URL . DIR_DBIMAGES . 'articles/' . $id . '/l_1.' . $article->MainImageExt;
     $sql = "select Name from ArticleCategories where ID = " . (int) $article->CategoryID;
     $category = GetMainConnection()->query($sql)->fetch();
     $vArticleLike = $this->db->query("select ID from ArticleLikes where (ArticleID = {$id}) and {$vAddWhere} limit 1;")->fetch();
     $vAlreadyLiked = !empty($vArticleLike['ID']);
     $sql = "select CommentDate, UserID, UserName, Comment " . "from ArticleComments " . "where (ArticleID = {$id}) " . "and (IsDeleted = 0) " . "order by CommentDate desc;";
     $ArticleComments = $this->db->query($sql)->fetchAll();
     if (!isset($article->AuthorID) || $article->AuthorID == null) {
         $ArticleAuthor['Name'] = '';
         $ArticleAuthor['ShortDescription'] = '';
         $ArticleAuthor['Photo'] = '';
     } else {
         $sql = 'SELECT Name, ShortDescription, Photo FROM Authors WHERE ID=' . (int) $article->AuthorID;
         $ArticleAuthor = $this->db->query($sql)->fetch();
     }
     $this->view->setVars(array('id' => $id, 'article' => $article, 'similar' => $article->getSimilar($id), 'discused' => $article->getMostDiscussed(), 'alreadyLiked' => $vAlreadyLiked, 'ArticleAuthor' => $ArticleAuthor, 'ArticleDocuments' => $article->getArticleDocuments($id), 'ArticleComments' => $ArticleComments, 'ArticleCategory' => $category['Name'], 'IsNotifyRecipientActive' => $IsNotifyRecipientActive));
     $this->view->breadcrumbs = array(array('url' => '/category', 'title' => 'Все статьи'), array('url' => '/articles/c-' . $article->CategoryID, 'title' => $category['Name']), array('url' => '/articles/c-' . $article->CategoryID . '/a-' . $article->ID, 'title' => $article->Name));
     $this->view->meta = array('meta_title' => $article->Name, 'meta_description' => $article->ShortDescription, 'meta_keywords' => $article->MetaKeywords);
     SetTokenForPreventDoubleSubmit();
     $this->view->generate();
 }
     } catch (Facebook\Exceptions\FacebookSDKException $e) {
         /*echo "<p>Error getting long-lived access token: " . $helper->getMessage() . "</p>\n\n";
         exit;*/
         return AddAlertMessage('danger', 'Ошибка при регистрации! (2)', '/');
     }
     /*echo '<h3>Long-lived</h3>';
       var_dump($accessToken->getValue());*/
 }
 $accessTokenStr = $accessToken->getValue();
 // Поиск пользователя в бд, и если не существует, то создание нового
 $sql = "select ID " . "from Users " . "where (UniversalID = '{$vUniversalID}');";
 $rec = GetMainConnection()->query($sql)->fetch();
 if (empty($rec['ID'])) {
     try {
         // Returns a Facebook\FacebookResponse object
         $response = $facebook->get('/me?fields=id,first_name,last_name,email', $accessTokenStr);
         $user = $response->getGraphUser();
         $userEmail = $user->getField('email');
         if (empty($userEmail)) {
             return AddAlertMessage('danger', 'Ошибка при регистрации! (Эл. почта не указана).', '/');
         }
         $sql = "select ID from Users where (Email = '{$userEmail}');";
         $checkuser = GetMainConnection()->query($sql)->fetch();
         if (!empty($checkuser['ID'])) {
             return AddAlertMessage('danger', 'Пользователь с эл. почтой: "' . $userEmail . '" уже зарегистрирован на сайте.', '/');
         }
         /*echo '<h3>User</h3>';
             var_dump($user);*/
         $sql = "insert into Users(UniversalType, UniversalID, AccessToken, UserName, Email, EmailConfirmed, RememberMe) " . "values(2, '{$vUniversalID}', '{$accessTokenStr}', '{$userEmail}', '{$userEmail}', 1, 1) " . "on duplicate key update " . "UniversalID = '{$vUniversalID}';";
         GetMainConnection()->exec($sql);
         $UserID = GetMainConnection()->lastInsertId();
        } else {
            $UserName = $_SESSION['auth']['firstname'];
        }
        unset($_POST['ajax_AddCommentBtn']);
        unset($_POST['UserNameEdt']);
        unset($_POST['CommentEdt']);
        if (isset($_SESSION['auth'])) {
            $vUserID = $_SESSION['auth']['id'];
            $vUnknownUserGUID = "";
        } else {
            $vUserID = "0";
            $vUnknownUserGUID = (string) GetUnknownUserGUID();
        }
        $sql = "select ID " . "from CatalogComments " . "where (CatalogItemID = {$id}) " . "and (UnknownUserGUID = '{$vUnknownUserGUID}') " . "and (UserID = {$vUserID}) " . "and (Text = '{$Comment}');";
        $rec = GetMainConnection()->query($sql)->fetch();
        if (empty($rec['ID'])) {
            $sql = "insert into CatalogComments(CatalogItemID, UserID, UnknownUserGUID, CreateDate, UserName, Text) " . "values({$id}, {$vUserID}, '{$vUnknownUserGUID}', '" . GetLocalDateTimeAsSQLStr() . "', '{$UserName}', '{$Comment}');";
            GetMainConnection()->exec($sql);
        } else {
            $ErrorText = 'Такой отзыв уже существует.';
        }
    }
    // Формат ответа: 1 позиция текст ошибки, 2 позиция кол-во комментов, 3-html для перезаполнения таблицы комментов
    if (empty($ErrorText)) {
        $sql = "select CreateDate, UserID, UserName, Text " . "from CatalogComments " . "where (CatalogItemID = {$id}) " . "and (IsDeleted = 0) " . "order by CreateDate desc;";
        $Comments = GetMainConnection()->query($sql)->fetchAll();
        echo '||' . count($Comments) . '||' . GetCatalogCommentsHTML($Comments);
    } else {
        echo $ErrorText . '||||';
    }
}
 public function loginAction()
 {
     if (Tools::isPost()) {
         $email = Tools::getValue('email');
         $password = Tools::getValue('password');
         $sql = "select ID, UniversalID, PasswordHash from Users where (UniversalType = 1) and (email = '{$email}');";
         $user = GetMainConnection()->query($sql)->fetch();
         if (!empty($user['ID'])) {
             if (VerifyPassword($password, $user['PasswordHash'])) {
                 unset($password);
                 $sql = "update Users " . "set RememberMe = '" . POSTBoolAsSQLStr('RememberMeEdt') . "' " . "where (ID = " . $user['ID'] . ");";
                 GetMainConnection()->exec($sql);
                 if (LoginUsingUniversalID($user['UniversalID'])) {
                     if (empty($_SESSION['login_redirect'])) {
                         return AddAlertMessage('success', 'Добро пожаловать!', '/');
                     } else {
                         $vRedirect = $_SESSION['login_redirect'];
                         unset($_SESSION['login_redirect']);
                         Redirect($vRedirect);
                     }
                 }
             } else {
                 unset($password);
                 AddAlertMessage('danger', 'Неверный e-mail или пароль.');
             }
         } else {
             unset($password);
             AddAlertMessage('danger', 'E-mail не найден.');
         }
     }
     // https://developers.facebook.com/docs/php/gettingstarted/5.0.0
     // https://developers.facebook.com/docs/php/Facebook/5.0.0
     // http://25labs.com/tutorial-integrate-facebook-connect-to-your-website-using-php-sdk-v-3-x-x-which-uses-graph-api/
     require_once PATH_SITE_ROOT . 'core/facebook-php-sdk-v4-5.0-dev/src/Facebook/autoload.php';
     $facebook = new Facebook\Facebook(['app_id' => facebook_app_id, 'app_secret' => facebook_app_secret, 'default_graph_version' => facebook_graph_version]);
     $helper = $facebook->getRedirectLoginHelper();
     $permissions = ['email'];
     // optional
     $FB_LoginUrl = $helper->getLoginUrl('http://karapuz.life/app/common/facebook_login_callback.php', $permissions);
     $VK_LoginUrl = 'https://oauth.vk.com/authorize?client_id=' . vk_app_id . '&scope=offline,email&redirect_uri=' . urlencode('http://karapuz.life/app/common/vk_login_callback.php') . '&response_type=code';
     $this->view->setVars(array('FB_LoginUrl' => $FB_LoginUrl, 'VK_LoginUrl' => $VK_LoginUrl));
     $this->view->breadcrumbs = array(array('url' => '/auth/login', 'title' => 'Вход на сайт'));
     $this->view->meta = array('meta_title' => 'Войти на сайт', 'meta_description' => 'Войти на сайт', 'meta_keywords' => '');
     $this->view->generate();
 }
            }
            $mail->MsgHTML($vBody);
            /*
                // add attachments
                if ($attach != null) {
                    foreach ($attach as $a) {
                        $mail->AddAttachment($a['path'], $a['name']);
                    }
                }*/
            //$answer = (!$mail->send()) ? $mail->ErrorInfo : true;
            SetTaskActivity($vTaskName, true);
            if ($mail->send()) {
                $sql = "insert into Emails_Sent(RecordGUID, CreateDate, SentDate, FromEmail, FromName, ToEmail, ToName, CopyToEmail, BlindCopyToEmail, Subject, Body) " . "values('" . $rec['RecordGUID'] . "', '" . $rec['CreateDate'] . "', '" . GetLocalDateTimeAsSQLStr() . "', '" . $rec['FromEmail'] . "', '" . $rec['FromName'] . "', '" . $rec['ToEmail'] . "', '" . $rec['ToName'] . "', '" . $rec['CopyToEmail'] . "', '" . $rec['BlindCopyToEmail'] . "', '" . $rec['Subject'] . "', '" . base64_encode($vBody) . "');";
                GetMainConnection()->exec($sql);
                $sql = "delete from Emails_ToSend where RecordGUID = '" . $rec['RecordGUID'] . "';";
                GetMainConnection()->exec($sql);
            } else {
                $vContinueProcessing = false;
                $sql = "update Emails_ToSend set Error = '" . ClearSQLStr($mail->ErrorInfo) . "' where RecordGUID = '" . $rec['RecordGUID'] . "';";
                GetMainConnection()->exec($sql);
            }
            $mail->ClearAddresses();
            $mail->ClearAttachments();
            //CountAttempts
        }
        usleep(50);
        // in msec
    }
} catch (Exception $exc) {
    //echo $exc->getTraceAsString();
    if (!empty($vProcessingGUID)) {
示例#8
0
 session_start();
 define('PATH_SITE_ROOT', __DIR__ . '/');
 require_once 'config.php';
 require_once 'connection.php';
 require_once 'core/global.php';
 InitDebugLog();
 GetUnknownUserGUID();
 // Создание GUID для каждого пользователя и сохранение его в cookies (для идентификации незалогинившихся пользователей)
 $context = new stdClass();
 $path = explode('/', GetURLPath());
 if (!empty($path[1]) && strtolower($path[1]) == 'index.php') {
     array_splice($path, 1, 1);
 }
 //AddDebugLog('Start block 1');
 // Основная база данных проекта
 $context->db = GetMainConnection();
 //AddDebugLog('Start block 2');
 // Register files
 require_once DIR_CORE . 'Model.php';
 require_once DIR_CORE . 'View.php';
 require_once DIR_CORE . 'Controller.php';
 require_once DIR_CORE . 'Tools.php';
 //AddDebugLog('Start block 3');
 /*if (DIR_MODELS != null && is_dir(DIR_MODELS)) {
         $dir = opendir(DIR_MODELS);
 
         while (false !== ($file = readdir($dir))) {
             if ($file !== '.' && $file != '..' && $file != '.svn') {
                 require_once DIR_MODELS.$file;
             }
         }
示例#9
0
function EchoAuthorArticleBlockHTML($AAuthorID, $AArticleID)
{
    $sql = "select ID, CategoryID, Name " . "from Articles " . "where AuthorID = {$AAuthorID} " . "and ID <> {$AArticleID} " . "and IsActive = 1 " . "and IsDeleted <> 1 " . "order by CreateDate desc " . "limit 3;";
    $records = GetMainConnection()->query($sql)->fetchAll();
    $vResult = '';
    foreach ($records as $r) {
        $vResult = $vResult . '<li><a href="/articles/c-' . $r['CategoryID'] . '/a-' . $r['ID'] . '">' . $r['Name'] . '</a></li>';
    }
    if (!empty($vResult)) {
        echo 'Другие статьи автора:<br /><ul>' . $vResult . '<li><a href="/search/?author=' . $AAuthorID . '">Все статьи автора.</a></li></ul>';
    }
}