From bf43dd620b17561ff1f4cabd0db6e3410db11e3e Mon Sep 17 00:00:00 2001 From: ommaniya70 Date: Sun, 22 Oct 2023 20:34:48 +0530 Subject: [PATCH] Initial Commit --- .gitignore | 1 + OtherPages/login.php | 60 +++++++++++++++++ OtherPages/review.php | 78 ++++++++++++++++++++++ OtherPages/signup.php | 82 +++++++++++++++++++++++ OtherPages/welcome.php | 38 +++++++++++ config.js | 42 ++++++++++++ dbconnection.php | 32 +++++++++ index.html | 49 ++++++++++++++ script.js | 146 ++++++++++++++++++++++++++++++++++++++++ style.css | 147 +++++++++++++++++++++++++++++++++++++++++ utils.css | 0 11 files changed, 675 insertions(+) create mode 100644 .gitignore create mode 100644 OtherPages/login.php create mode 100644 OtherPages/review.php create mode 100644 OtherPages/signup.php create mode 100644 OtherPages/welcome.php create mode 100644 config.js create mode 100644 dbconnection.php create mode 100644 index.html create mode 100644 script.js create mode 100644 style.css create mode 100644 utils.css diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..600d2d3 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.vscode \ No newline at end of file diff --git a/OtherPages/login.php b/OtherPages/login.php new file mode 100644 index 0000000..a189b6f --- /dev/null +++ b/OtherPages/login.php @@ -0,0 +1,60 @@ + + + + + + Login Page + + +

Login

+
+ +

+ +

+ +
+ + 0) { + // Redirect to the welcome page if a matching user is found + session_start(); + $_SESSION['email_id'] = $email_id; + closeConnection($conn); + header("Location: welcome.php"); + exit(); + } else { + // Invalid email or password + echo "Invalid Email or Password !!"; + } + } else { + // Handle query execution errors + echo "Error: " . mysqli_error($conn); + } + } + ?> + + diff --git a/OtherPages/review.php b/OtherPages/review.php new file mode 100644 index 0000000..5dda293 --- /dev/null +++ b/OtherPages/review.php @@ -0,0 +1,78 @@ + + + + + + + + Review Us + + +
+ +

+ + +

+ + +

+ + + + + +
+ + + + \ No newline at end of file diff --git a/OtherPages/signup.php b/OtherPages/signup.php new file mode 100644 index 0000000..b4b8d91 --- /dev/null +++ b/OtherPages/signup.php @@ -0,0 +1,82 @@ + + + + Sign Up Page + + +

Sign Up

+
+ +

+ + +

+ + +

+ + + Male + Female + + +

+ + +

+ + +
+ + + + \ No newline at end of file diff --git a/OtherPages/welcome.php b/OtherPages/welcome.php new file mode 100644 index 0000000..98ba979 --- /dev/null +++ b/OtherPages/welcome.php @@ -0,0 +1,38 @@ + + + + + Welcome + + + +

Welcome, User!

+ + + +
+ +
+ + + + \ No newline at end of file diff --git a/config.js b/config.js new file mode 100644 index 0000000..c9637bf --- /dev/null +++ b/config.js @@ -0,0 +1,42 @@ +const apiKeyData = [ + 'pub_31554370e11a6e70b4b2e4a91f27bad8a6828', + 'pub_31571add825b1d3e10c9f35e0079f6328d806', + 'pub_3157975aa5dfc81c57e1e121f7aaa49af4ce2', + 'pub_31580bbb6ba933bead156cf87510ee0aad428', + 'pub_31581573ab6880c5f0ae18d6222bf1d779099', + 'pub_315828bef552eff31127d1ef65ad0c1af6b61', + 'pub_31583a41e1d8b22b6a6163b17887f24f78339', + 'pub_31585e4453cb3f957356bcd3a5762886bc6d0', + 'pub_31617ef633d57ed52d4bf6e7f08e17740e1de', + 'pub_316194ef4c55a469201683e8a35ff44b9a487', + 'pub_31620dd02ae2700eb3acaa4669988d65ae000', + 'pub_31621668a5c7168c716b068fb7f3fe43a90cf', + 'pub_31622c261979ab968e1ee9e265281073322ae', + 'pub_31623a3427a984b872db8d780316935285eee', + 'pub_316240ed15a9eba2cec320215e8c72a7572bd', + 'pub_316265dee848e75eec918f4d1ca03e9916655', + 'pub_31627e33577f37445df2f37e5a8867dd94aa8', + 'pub_31628b0dc9d42dc3ef579a68c92b30b02bace', + 'pub_316294b354db64a154c4d8c70d02601fb2f13', + 'pub_31630ca4a9b58795e3c25382e81eef7d61885', + 'pub_316313df70c0362201587a55f202e52845ead', + 'pub_31632ab8c04a7d95513a74fa171c6e70334d5', + 'pub_316332a3e9288280f849b27f4b0d074e169c9', + 'pub_31634187b76f8f2892eb941c7b2606d979a1a', + 'pub_316354226103164584e4f29b1b55a78193bc7', + 'pub_3163688629520e7eed0681fe2499602349005', + 'pub_31637dc17c3297cdd806571ceb21bf7f98e49', + 'pub_316381054bd4d3f4eafe577dbfa73505f0809', + 'pub_31639d6a1f9c447aa342ab8bbafa539f18968', + 'pub_316407f568fddf00d598805f4760c749c3040', + 'pub_3164119889a214fcbce9112e0f527974d91c2', + 'pub_31643413c23c5c9cdb53a6f72f184e724583d', + 'pub_316445b45a0f2cbf58d30957d6d0c4f0998aa', + 'pub_316454f5a8ccf45f6bddcc58c05dc7f94fe87', + 'pub_316477a155b985b58907514e0c3ca1e1b4669', + 'pub_31648a61ea844598a93110a856ee4c82693cf', + 'pub_3164997c65a8eba4ef12d3b3e22c0ce80ac38', + 'pub_31650e077a52447585ece890c9324e239a391', + 'pub_31651a37d1f40e1da897fa72c86d5fc2319ca', + 'pub_31652adc57f4d29c04d572b2df28993453182' +]; \ No newline at end of file diff --git a/dbconnection.php b/dbconnection.php new file mode 100644 index 0000000..4601765 --- /dev/null +++ b/dbconnection.php @@ -0,0 +1,32 @@ +close(); + } + + function isExists($conn, $emailId, $table_name) + { + $emailId = mysqli_real_escape_string($conn, $emailId); // Sanitize input + $query = "SELECT EMAIL_ID FROM $table_name WHERE EMAIL_ID = '$emailId'"; + $result = mysqli_query($conn, $query); + + if ($result) { + return mysqli_num_rows($result) > 0; + } else { + return false; + } + } +?> \ No newline at end of file diff --git a/index.html b/index.html new file mode 100644 index 0000000..9944e58 --- /dev/null +++ b/index.html @@ -0,0 +1,49 @@ + + + + + + + + News + + + + + + + + +
+ +
+ + + \ No newline at end of file diff --git a/script.js b/script.js new file mode 100644 index 0000000..d819577 --- /dev/null +++ b/script.js @@ -0,0 +1,146 @@ +let url = 'https://newsapi.org/v2/top-headlines?'; +let API_KEY = apiKeyData[0]; +let api_key_tracker = 0; +let nextPageId = undefined; +let currentCategory = undefined; + +async function fetchNews(category,requiredArticles=5,json=[]) { + loadBtn = document.querySelector("#loadMoreBtn"); + let result = await fetch(`https://newsdata.io/api/1/news?apikey=` + API_KEY + `&country=in&language=en&category=`+category); + let data = await result.json(); + console.log("FetchNews : ",data); + console.log(data.status); + if(data.status == "success"){ + if(data.nextPage != null){ + nextPageId = data.nextPage; + loadBtn.innerHTML = "Load More"; + loadBtn.setAttribute("style", "display : block"); + } + else{ + loadBtn.setAttribute("style","display : none"); + nextPageId = undefined; + } + + data = data.results; + let noOfArticles = 0; + for(let i=0; i<10; i++){ + if (!(data[i].image_url === null || data[i].description === null || data[i].title === null || data[i].content === null)) { + noOfArticles++; + json.push(data[i]); + } + } + + if((requiredArticles - noOfArticles > 0) && nextPageId != undefined){ + fetchNews(category,requiredArticles-noOfArticles,json); + } + else{ + localStorage.clear(); + toLocalStorage(json); + fillNews(); + } + } + else{ + console.log("failure !!"); + api_key_tracker = (api_key_tracker + 1) % 42; + API_KEY = apiKeyData[api_key_tracker]; + fetchNews(category); + } +} + +function fillNews() { + let data = JSON.parse(localStorage.getItem("newsArticles")); + + document.getElementsByClassName("main")[0].innerHTML = ''; + for (let i = 0; i < data.length; i++) { + for (let j = 0; j < data[i].length; j++) { + let creatorDetails = data[i][j].creator; + + if (creatorDetails == null) + creatorDetails = `Anonymous • `+ data[i][j].pubDate.slice(0, 10); + else + creatorDetails = ``+data[i][j].creator+` • `+ data[i][j].pubDate.slice(0, 10); + + // Id for news card elements + let news_article_id = data[i][j].article_id; + + document.getElementsByClassName("main")[0].innerHTML += + `
+
+
`+creatorDetails+`
+
+

`+ data[i][j].title + `

+
+
+

`+ data[i][j].description.slice(0,200) + `...` + `

+
+
+
+ News-Image +
+
` + } + } +} + +function toLocalStorage(data) { + let storedData = localStorage.getItem("newsArticles"); + + if (storedData === null) { + // If no data exists, create a new array and store it in localStorage + localStorage.setItem("newsArticles", JSON.stringify([data])); + } else { + // If data exists, parse it, update the array, and store it back + let existingData = JSON.parse(storedData); + existingData.push(data); + localStorage.setItem("newsArticles", JSON.stringify(existingData)); + console.log(JSON.parse(localStorage.getItem("newsArticles"))) + } +} + +async function loadMoreNews(category,requiredArticles=5,json=[]) { + let loadBtn = document.querySelector("#loadMoreBtn"); + loadBtn.innerHTML = "Loading"; + + let result = await fetch(`https://newsdata.io/api/1/news?apikey=` + API_KEY + `&country=in&language=en&category=`+category+`&page=`+nextPageId); + let data = await result.json(); + + if(data.status == "success"){ + console.log("Load More data : ",data); + if(data.nextPage != null){ + nextPageId = data.nextPage; + loadBtn.setAttribute("style", "display : block"); + loadBtn.innerHTML = "Load More"; + } + else{ + nextPageId = undefined; + loadBtn.setAttribute("style","display : none"); + } + + data = data.results; + console.log("Main : ",data); + + let noOfArticles = 0; + for(let i=0; i<10; i++){ + if (!(data[i].image_url === null || data[i].description === null || data[i].title === null || data[i].content === null)) { + noOfArticles++; + json.push(data[i]); + } + } + if((requiredArticles - noOfArticles > 0) && nextPageId != undefined){ + loadMoreNews(category,requiredArticles-noOfArticles,json); + } + else{ + toLocalStorage(json); + fillNews(); + } + console.log(noOfArticles); + } + else{ + console.log("failure !!"); + api_key_tracker = (api_key_tracker + 1) % 42; + API_KEY = apiKeyData[api_key_tracker]; + loadMoreNews(category,requiredArticles,json); + } +} + +// fetchNews("Business"); \ No newline at end of file diff --git a/style.css b/style.css new file mode 100644 index 0000000..b32232f --- /dev/null +++ b/style.css @@ -0,0 +1,147 @@ +@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700;800&display=swap'); + +*{ + margin: 0; + padding: 0; + box-sizing: border-box; + font-family: 'Poppins', sans-serif; +} + +.navbar{ + height: 80px; + background-color: white; + display: flex; + justify-content: space-around; + align-items: center; + /* background: linear-gradient(to right, rgba(106, 17, 203, 0.9), rgba(37, 117, 252, 0.9)); */ + position: sticky; + top: 0; +} + +.logo{ + font-size: 30px; + font-weight: 700; + color: rgb(254,64,102); +} + +.nav-links{ + width: 40%; +} + +.nav-links > ul{ + display: flex; + justify-content: space-evenly; +} + +.nav-links > ul > li{ + list-style: none; +} + +.nav-links > ul > li > a{ + color: rgb(97,93,93); + text-decoration: none; + font-size: 17px; + font-weight: 700; + position: relative; +} + +.nav-links > ul > li > a::after{ + content: ''; + width: 100%; + height: 5px; + background-color: rgb(255, 128, 0); + position: absolute; + left: 0; + bottom: -9px; + transform: scaleX(0); + transition: transform 0.3s ease-in-out; + transform-origin: right; +} + +.nav-links > ul > li > a:hover::after{ + transform: scaleX(1); + transform-origin: left; +} + +.nav-links > ul > li > a:hover{ + color: black; +} + +.btn{ + width: 120px; + height: 43px; + font-size: 17px; + font-weight: 700; + letter-spacing: 1.2px; + border: none; + background-color: rgb(254,64,102); + color: white; + border-radius: 40px; + cursor: pointer; +} + +.btn:hover{ + background-color: rgb(212, 28, 64); +} + +.main{ + width: 80%; + margin: auto; + margin-top: 50px; + margin-bottom: 50px; +} + +.news-card{ + width: 100%; + height: 280px; + display: flex; + padding: 0px 20px; + border: 1px solid rgba(128, 128, 128, 0.397); + border-radius: 8px; + margin-bottom: 30px; +} + +.news-card-left{ + width: 75%; + margin-right: 25px; +} + +.news-provider-info{ + margin: 25px 0px 5px 15px; +} + +.news-title{ + margin-left: 15px; +} + +.news-description{ + margin: 15px 15px 0px 15px; +} + +.news-title > p{ + font-size: 23px; + font-weight: 600; +} + +.news-description > p{ + font-size: 15px; +} + +.news-card-right{ + width: 25%; + padding: 25px 0px; +} + +.news-image{ + width: 100%; + height: 100%; + border-radius: 8px; +} + +#loadMoreBtn{ + display : none; + margin: auto; + margin-bottom: 30px; + width: 170px; + height: 48px; +} \ No newline at end of file diff --git a/utils.css b/utils.css new file mode 100644 index 0000000..e69de29