Пример #1
0
        /// <summary>
        /// Get
        /// </summary>
        /// <returns></returns>
        public async Task <IActionResult> OnGet()
        {
            LoggedIn     = !string.IsNullOrEmpty(Request.Cookies["Token"]);
            IsPoetPage   = false;
            IsCatPage    = false;
            IsPoemPage   = false;
            IsHomePage   = Request.Path == "/";
            PinterestUrl = Request.Query["pinterest_url"];
            GoogleBreadCrumbList breadCrumbList = new GoogleBreadCrumbList();

            using (HttpClient client = new HttpClient())
            {
                if (!string.IsNullOrEmpty(Request.Query["p"]))
                {
                    var pageUrlResponse = await client.GetAsync($"{APIRoot.Url}/api/ganjoor/pageurl?id={Request.Query["p"]}");

                    pageUrlResponse.EnsureSuccessStatusCode();
                    var pageUrl = JsonConvert.DeserializeObject <string>(await pageUrlResponse.Content.ReadAsStringAsync());
                    return(Redirect(pageUrl));
                }

                var response = await client.GetAsync($"{APIRoot.Url}/api/ganjoor/poets?includeBio=false");

                response.EnsureSuccessStatusCode();

                Poets = JArray.Parse(await response.Content.ReadAsStringAsync()).ToObject <List <GanjoorPoetViewModel> >();

                if (!IsHomePage)
                {
                    var pageQuery = await client.GetAsync($"{APIRoot.Url}/api/ganjoor/page?url={Request.Path}");

                    if (pageQuery.IsSuccessStatusCode)
                    {
                        GanjoorPage          = JObject.Parse(await pageQuery.Content.ReadAsStringAsync()).ToObject <GanjoorPageCompleteViewModel>();
                        GanjoorPage.HtmlText = GanjoorPage.HtmlText.Replace("https://ganjoor.net/", "/").Replace("http://ganjoor.net/", "/");
                        switch (GanjoorPage.GanjoorPageType)
                        {
                        case GanjoorPageType.PoemPage:
                            _markMyComments();
                            _preparePoemExcerpt(GanjoorPage.Poem.Next);
                            _preparePoemExcerpt(GanjoorPage.Poem.Previous);
                            GanjoorPage.PoetOrCat = GanjoorPage.Poem.Category;
                            IsPoemPage            = true;
                            break;

                        case GanjoorPageType.PoetPage:
                            IsPoetPage = true;
                            break;

                        case GanjoorPageType.CatPage:
                            IsCatPage = true;
                            break;
                        }
                    }
                }
            }

            if (IsHomePage)
            {
                ViewData["Title"] = "گنجور";
            }
            else
            if (IsPoetPage)
            {
                ViewData["Title"] = $"گنجور &raquo; {GanjoorPage.PoetOrCat.Poet.Name}";
                breadCrumbList.AddItem(GanjoorPage.PoetOrCat.Poet.Name, GanjoorPage.PoetOrCat.Cat.FullUrl, $"/image/poets/{GanjoorPage.PoetOrCat.Poet.Id}.png");
            }
            else
            if (IsCatPage)
            {
                string title   = $"گنجور &raquo; ";
                bool   poetCat = true;
                foreach (var gran in GanjoorPage.PoetOrCat.Cat.Ancestors)
                {
                    title += $"{gran.Title} &raquo; ";
                    breadCrumbList.AddItem(gran.Title, gran.FullUrl, poetCat ? $"/image/poets/{GanjoorPage.PoetOrCat.Poet.Id}.png" : "https://i.ganjoor.net/cat.png");
                    poetCat = false;
                }
                breadCrumbList.AddItem(GanjoorPage.PoetOrCat.Cat.Title, GanjoorPage.PoetOrCat.Cat.FullUrl, "https://i.ganjoor.net/cat.png");
                title            += GanjoorPage.PoetOrCat.Cat.Title;
                ViewData["Title"] = title;
            }
            else
            if (IsPoemPage)
            {
                ViewData["Title"] = $"گنجور &raquo; {GanjoorPage.Poem.FullTitle}";
                bool poetCat = true;
                foreach (var gran in GanjoorPage.Poem.Category.Cat.Ancestors)
                {
                    breadCrumbList.AddItem(gran.Title, gran.FullUrl, poetCat ? $"/image/poets/{GanjoorPage.Poem.Category.Poet.Id}.png" : "https://i.ganjoor.net/cat.png");
                    poetCat = false;
                }
                breadCrumbList.AddItem(GanjoorPage.PoetOrCat.Cat.Title, GanjoorPage.PoetOrCat.Cat.FullUrl, "https://i.ganjoor.net/cat.png");
                breadCrumbList.AddItem(GanjoorPage.Poem.Title, GanjoorPage.Poem.FullUrl, "https://i.ganjoor.net/poem.png");
            }
            else if (GanjoorPage != null)
            {
                if (GanjoorPage.PoetOrCat != null)
                {
                    bool   poetCat   = true;
                    string fullTitle = "گنجور &raquo; ";
                    if (GanjoorPage.PoetOrCat.Cat.Ancestors.Count == 0)
                    {
                        fullTitle += $"{GanjoorPage.PoetOrCat.Poet.Name} &raquo; ";
                    }
                    else
                    {
                        foreach (var gran in GanjoorPage.PoetOrCat.Cat.Ancestors)
                        {
                            breadCrumbList.AddItem(gran.Title, gran.FullUrl, poetCat ? $"/image/poets/{GanjoorPage.Poem.Category.Poet.Id}.png" : "https://i.ganjoor.net/cat.png");
                            poetCat    = false;
                            fullTitle += $"{gran.Title} &raquo; ";
                        }
                    }
                    ViewData["Title"] = $"{fullTitle}{GanjoorPage.Title}";
                    breadCrumbList.AddItem(GanjoorPage.PoetOrCat.Poet.Name, GanjoorPage.PoetOrCat.Cat.FullUrl, $"/image/poets/{GanjoorPage.PoetOrCat.Poet.Id}.png");
                }
                else
                {
                    ViewData["Title"] = $"گنجور &raquo; {GanjoorPage.FullTitle}";

                    if (GanjoorPage.UrlSlug == "hashieha")
                    {
                        await _GenerateHashiehaHtmlText();
                    }
                }
                breadCrumbList.AddItem(GanjoorPage.Title, GanjoorPage.FullUrl, "https://i.ganjoor.net/cat.png");
            }
            else
            {
                return(RedirectToPage("404"));
            }

            ViewData["BrearCrumpList"] = breadCrumbList.ToString();

            return(Page());
        }
Пример #2
0
        /// <summary>
        /// Get
        /// </summary>
        /// <returns></returns>
        public async Task <IActionResult> OnGetAsync()
        {
            if (bool.Parse(Configuration["MaintenanceMode"]))
            {
                return(StatusCode(503));
            }
            LastError         = "";
            LoggedIn          = !string.IsNullOrEmpty(Request.Cookies["Token"]);
            CanEdit           = Request.Cookies["CanEdit"] == "True";
            KeepHistory       = Request.Cookies["KeepHistory"] == "True";
            IsPoetPage        = false;
            IsCatPage         = false;
            IsPoemPage        = false;
            IsHomePage        = Request.Path == "/";
            PinterestUrl      = Request.Query["pinterest_url"];
            ShowAllRecitaions = Request.Query["allaudio"] == "1";
            ViewData["GoogleAnalyticsCode"] = Configuration["GoogleAnalyticsCode"];

            GoogleBreadCrumbList breadCrumbList = new GoogleBreadCrumbList();

            Banner = null;

            if (!string.IsNullOrEmpty(Request.Query["p"]))
            {
                var pageUrlResponse = await _httpClient.GetAsync($"{APIRoot.Url}/api/ganjoor/pageurl?id={Request.Query["p"]}");

                if (!pageUrlResponse.IsSuccessStatusCode)
                {
                    LastError = JsonConvert.DeserializeObject <string>(await pageUrlResponse.Content.ReadAsStringAsync());
                    return(Page());
                }
                var pageUrl = JsonConvert.DeserializeObject <string>(await pageUrlResponse.Content.ReadAsStringAsync());
                return(Redirect(pageUrl));
            }

            if (Request.Path.ToString().IndexOf("index.php") != -1)
            {
                return(Redirect($"{Request.Path.ToString().Replace("index.php", "search")}{Request.QueryString}"));
            }

            await preparePoets();

            if (!IsHomePage)
            {
                var pageQuery = await _httpClient.GetAsync($"{APIRoot.Url}/api/ganjoor/page?url={Request.Path}");

                if (!pageQuery.IsSuccessStatusCode)
                {
                    if (pageQuery.StatusCode == HttpStatusCode.NotFound)
                    {
                        var redirectQuery = await _httpClient.GetAsync($"{APIRoot.Url}/api/ganjoor/redirecturl?url={Request.Path}");

                        if (redirectQuery.IsSuccessStatusCode)
                        {
                            var redirectUrl = JsonConvert.DeserializeObject <string>(await redirectQuery.Content.ReadAsStringAsync());
                            return(Redirect(redirectUrl));
                        }
                        return(NotFound());
                    }
                }
                if (!pageQuery.IsSuccessStatusCode)
                {
                    LastError = JsonConvert.DeserializeObject <string>(await pageQuery.Content.ReadAsStringAsync());
                    return(Page());
                }
                GanjoorPage          = JObject.Parse(await pageQuery.Content.ReadAsStringAsync()).ToObject <GanjoorPageCompleteViewModel>();
                GanjoorPage.HtmlText = GanjoorPage.HtmlText.Replace("https://ganjoor.net/", "/").Replace("http://ganjoor.net/", "/");
                switch (GanjoorPage.GanjoorPageType)
                {
                case GanjoorPageType.PoemPage:
                    _markMyComments();
                    _preparePoemExcerpt(GanjoorPage.Poem.Next);
                    _preparePoemExcerpt(GanjoorPage.Poem.Previous);
                    GanjoorPage.PoetOrCat = GanjoorPage.Poem.Category;
                    IsPoemPage            = true;
                    break;

                case GanjoorPageType.PoetPage:
                    IsPoetPage = true;
                    break;

                case GanjoorPageType.CatPage:
                    IsCatPage = true;
                    break;
                }

                if (IsPoemPage)
                {
                    HtmlLanguage = string.IsNullOrEmpty(GanjoorPage.Poem.Language) ? "fa-IR" : GanjoorPage.Poem.Language;
                    var bannerQuery = await _httpClient.GetAsync($"{APIRoot.Url}/api/banners/random");

                    if (!bannerQuery.IsSuccessStatusCode)
                    {
                        LastError = JsonConvert.DeserializeObject <string>(await bannerQuery.Content.ReadAsStringAsync());
                        return(Page());
                    }
                    string bannerResponse = await bannerQuery.Content.ReadAsStringAsync();

                    if (!string.IsNullOrEmpty(bannerResponse))
                    {
                        Banner = JObject.Parse(bannerResponse).ToObject <GanjoorSiteBannerViewModel>();
                    }
                }
            }

            if (IsHomePage)
            {
                ViewData["Title"] = "گنجور";
                await _PreparePoetGroups();
            }
            else
            if (IsPoetPage)
            {
                ViewData["Title"] = $"گنجور » {GanjoorPage.PoetOrCat.Poet.Name}";
                breadCrumbList.AddItem(GanjoorPage.PoetOrCat.Poet.Name, GanjoorPage.PoetOrCat.Cat.FullUrl, $"{APIRoot.InternetUrl + GanjoorPage.PoetOrCat.Poet.ImageUrl}");
            }
            else
            if (IsCatPage)
            {
                string title   = $"گنجور » ";
                bool   poetCat = true;
                foreach (var gran in GanjoorPage.PoetOrCat.Cat.Ancestors)
                {
                    title += $"{gran.Title} » ";
                    breadCrumbList.AddItem(gran.Title, gran.FullUrl, poetCat ? $"{APIRoot.InternetUrl + GanjoorPage.PoetOrCat.Poet.ImageUrl}" : "https://i.ganjoor.net/cat.png");
                    poetCat = false;
                }
                breadCrumbList.AddItem(GanjoorPage.PoetOrCat.Cat.Title, GanjoorPage.PoetOrCat.Cat.FullUrl, "https://i.ganjoor.net/cat.png");
                title            += GanjoorPage.PoetOrCat.Cat.Title;
                ViewData["Title"] = title;
            }
            else
            if (IsPoemPage)
            {
                ViewData["Title"] = $"گنجور » {GanjoorPage.Poem.FullTitle}";
                bool poetCat = true;
                foreach (var gran in GanjoorPage.Poem.Category.Cat.Ancestors)
                {
                    breadCrumbList.AddItem(gran.Title, gran.FullUrl, poetCat ? $"{APIRoot.InternetUrl + GanjoorPage.PoetOrCat.Poet.ImageUrl}" : "https://i.ganjoor.net/cat.png");
                    poetCat = false;
                }
                breadCrumbList.AddItem(GanjoorPage.PoetOrCat.Cat.Title, GanjoorPage.PoetOrCat.Cat.FullUrl, "https://i.ganjoor.net/cat.png");
                breadCrumbList.AddItem(GanjoorPage.Poem.Title, GanjoorPage.Poem.FullUrl, "https://i.ganjoor.net/poem.png");
            }
            else
            {
                if (GanjoorPage.PoetOrCat != null)
                {
                    bool   poetCat   = true;
                    string fullTitle = "گنجور » ";
                    if (GanjoorPage.PoetOrCat.Cat.Ancestors.Count == 0)
                    {
                        fullTitle += $"{GanjoorPage.PoetOrCat.Poet.Name} » ";
                    }
                    else
                    {
                        foreach (var gran in GanjoorPage.PoetOrCat.Cat.Ancestors)
                        {
                            breadCrumbList.AddItem(gran.Title, gran.FullUrl, poetCat ? $"{APIRoot.InternetUrl + GanjoorPage.PoetOrCat.Poet.ImageUrl}" : "https://i.ganjoor.net/cat.png");
                            poetCat    = false;
                            fullTitle += $"{gran.Title} » ";
                        }
                    }
                    ViewData["Title"] = $"{fullTitle}{GanjoorPage.Title}";
                    breadCrumbList.AddItem(GanjoorPage.PoetOrCat.Poet.Name, GanjoorPage.PoetOrCat.Cat.FullUrl, $"{APIRoot.InternetUrl + GanjoorPage.PoetOrCat.Poet.ImageUrl}");
                }
                else
                {
                    ViewData["Title"] = $"گنجور » {GanjoorPage.FullTitle}";


                    switch (GanjoorPage.UrlSlug)
                    {
                    case "hashieha":
                        await _GenerateHashiehaHtmlText();

                        break;

                    case "vazn":
                        await _GenerateVaznHtmlText();

                        break;

                    case "simi":
                        await _GenerateSimiHtmlText();

                        break;
                    }
                }
                breadCrumbList.AddItem(GanjoorPage.Title, GanjoorPage.FullUrl, "https://i.ganjoor.net/cat.png");
            }


            ViewData["BrearCrumpList"] = breadCrumbList.ToString();


            return(Page());
        }