From aec787385242d3bd2cdd525db8316a74617b4b98 Mon Sep 17 00:00:00 2001 From: Leonardo Date: Fri, 23 Oct 2015 11:43:21 -0300 Subject: [PATCH] Deleting post --- README.md | 6 +-- src/link-preview/js/link-preview-database.js | 18 ++++++- src/link-preview/js/link-preview.js | 56 ++++++++++++++++---- src/link-preview/linkpreview.sql | 24 ++++----- src/link-preview/php/delete.php | 3 +- 5 files changed, 79 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index 99ef69b..d7599a9 100755 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -Link Preview (In Development) +Link Preview ========================== Developed by @LeonardoCardoso. @@ -110,7 +110,7 @@ Attributes -5 • Database +4 • Database To custom your database configurations, you need to change the following values in [Database.php](/src/link-preview/php/classes/Database.php) @@ -221,7 +221,7 @@ $ sudo port install php5-curl $ sudo apachectl restart ``` -Also where there is 'src/link-preview/' as part of a path of a Javascript, CSS or image file, +Also where there is 'src/link-preview/' as part of a path of a Javascript, CSS or image file, you must change to the path on your server. diff --git a/src/link-preview/js/link-preview-database.js b/src/link-preview/js/link-preview-database.js index 33db9ae..87765e9 100755 --- a/src/link-preview/js/link-preview-database.js +++ b/src/link-preview/js/link-preview-database.js @@ -27,7 +27,6 @@ app.controller('MyControllerDatabase', ['$scope', '$http', '$sce', function ($sc data[i].textHTML = $sce.trustAsHtml(data[i].text); data[i].descriptionHTML = $sce.trustAsHtml(data[i].description); data[i].videoIframeHTML = $sce.trustAsHtml(data[i].videoIframe); - console.log(data[i]); } $scope.databasePosts = data; @@ -37,7 +36,22 @@ app.controller('MyControllerDatabase', ['$scope', '$http', '$sce', function ($sc }; $scope.deletePosted = function (post, $index) { - $scope.posts.splice($index, 1); + $scope.databasePosts.splice($index, 1); + + var url = 'src/link-preview/php/delete.php'; + var jsonData = angular.toJson({ + id: post.id + }); + + $http({ + url: url, + method: "POST", + data: "data=" + jsonData, + headers: {'Content-Type': 'application/x-www-form-urlencoded'} + }).success(function (data, status, headers, config) { + + }); + }; $scope.imageAction = function (post) { diff --git a/src/link-preview/js/link-preview.js b/src/link-preview/js/link-preview.js index d8fc676..f3ccb8f 100755 --- a/src/link-preview/js/link-preview.js +++ b/src/link-preview/js/link-preview.js @@ -70,6 +70,7 @@ app.directive('linkPreview', ['$compile', '$http', '$sce', function ($compile, $ $scope.currentImageIndex = 1; $scope.preview = { + "id": -1, "text": "", "title": "", "url": "", @@ -271,6 +272,13 @@ app.directive('linkPreview', ['$compile', '$http', '$sce', function ($compile, $ post.image = ''; } + if (post.title === $scope.defaultTitle) { + post.title = ""; + } + if (post.description === $scope.defaultDescription) { + post.description = ""; + } + post.url = window.btoa(post.url); post.pageUrl = window.btoa(post.pageUrl); post.canonicalUrl = window.btoa(post.canonicalUrl); @@ -280,24 +288,36 @@ app.directive('linkPreview', ['$compile', '$http', '$sce', function ($compile, $ text: $scope.userTyping, data: post }); + // Saving in db $http({ url: url, method: "POST", data: "data=" + window.btoa(encodeURIComponent(jsonData)), headers: {'Content-Type': 'application/x-www-form-urlencoded'} - }).success(function (data, status, headers, config) { - }); + }).success(function (id, status, headers, config) { - if ($scope.noThumbnail || $scope.noImage) { - $scope.preview.image = ""; - } - $scope.textHTML = $sce.trustAsHtml(data.text); - $scope.descriptionHTML = $sce.trustAsHtml(data.description); - $scope.userTyping = ""; - $scope.posts.unshift(preview); + if (!isNaN(id)) { + post.id = id; + } + + if ($scope.noThumbnail || $scope.noImage) { + post.image = ""; + } + $scope.textHTML = $sce.trustAsHtml(data.text); + $scope.descriptionHTML = $sce.trustAsHtml(post.description); + $scope.userTyping = ""; + + post.url = preview.url; + post.pageUrl = preview.pageUrl; + post.canonicalUrl = preview.canonicalUrl; + + $scope.posts.unshift(post); + + defaultValues($scope); + + }); - defaultValues($scope); } ) ; @@ -306,6 +326,22 @@ app.directive('linkPreview', ['$compile', '$http', '$sce', function ($compile, $ $scope.deletePosted = function (post, $index) { $scope.posts.splice($index, 1); + + if (post.id != -1) { + var url = 'src/link-preview/php/delete.php'; + var jsonData = angular.toJson({ + id: post.id + }); + + $http({ + url: url, + method: "POST", + data: "data=" + jsonData, + headers: {'Content-Type': 'application/x-www-form-urlencoded'} + }).success(function (data, status, headers, config) { + + }); + } }; $scope.imageAction = function (post) { diff --git a/src/link-preview/linkpreview.sql b/src/link-preview/linkpreview.sql index 9248512..1e73f34 100644 --- a/src/link-preview/linkpreview.sql +++ b/src/link-preview/linkpreview.sql @@ -43,18 +43,18 @@ LOCK TABLES `linkpreview` WRITE; INSERT INTO `linkpreview` (`id`, `text`, `image`, `title`, `canonicalUrl`, `url`, `pageUrl`, `description`, `videoIframe`) VALUES - (90,'http://www.imdb.com/list/ls015186022/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=2248695062&pf_rd_r=03S3DKWA4WBJZY9Q8Z2X&pf_rd_s=center-1&pf_rd_t=15061&pf_rd_i=homepage&ref_=hm_osc_cr_hd&pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=2248695062&pf_rd_r=03S3DKWA4WBJZY9Q8Z2X&pf_rd_s=center-1&pf_rd_t=15061&pf_rd_i=homepage#1','http://ia.media-imdb.com/images/M/MV5BMTgyNDk2NTE0MV5BMl5BanBnXkFtZTYwMDQ1NDg0._V1._SX266_SY400_.jpg','IMDb: Six Facts You Might Not Know About Oscars Host Chris Rock - a list by IMDb-Editors','www.imdb.com','http://www.imdb.com/list/ls015186022/?pf_rd_m=A2FGELUUNOQJNL','http://www.imdb.com/list/ls015186022/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=2248695062&pf_rd_r=03S3DKWA4WBJZY9Q8Z2X&pf_rd_s=center-1&pf_rd_t=15061&pf_rd_i=homepage&ref_=hm_osc_cr_hd&pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=2248695062&pf_rd_r=03S3DKWA4WBJZY9Q8Z2X&pf_rd_s=center-1&pf_rd_t=15061&pf_rd_i=homepage','Chris Rock has been named host of the 88th Annual Academy Awards™, airing Sunday, Feb. 28, 2016. Rock is best known for his stand-up comedy and acting. He is also a writer, producer, and director — which gives him experience in numerous Academy Awards™ categories. His background as a filmmaker makes him well-qualified to host the movie industry\'s biggest night. Here are a half-dozen facts you might not know about Chris Rock\'s career. — Sara Bibel',''), - (91,'http://web.media.mit.edu/~mres/','','Mitchel Resnick','web.media.mit.edu','http://web.media.mit.edu/~mres/','http://web.media.mit.edu/~mres/','To support my work, please consider making a donation to the Code-to-Learn Foundation or the Resnick Teacher Scholarship Fund.',''), - (92,'http://25.media.tumblr.com/076d514bbf5a5387f24a5896c26805af/tumblr_mlhc0rjpIc1rp499go2_400.gif','http://25.media.tumblr.com/076d514bbf5a5387f24a5896c26805af/tumblr_mlhc0rjpIc1rp499go2_400.gif','Just a minion gif!','25.media.tumblr.com','http://25.media.tumblr.com/076d514bbf5a5387f24a5896c26805af/tumblr_mlhc0rjpIc1rp499go2_400.gif','http://25.media.tumblr.com/076d514bbf5a5387f24a5896c26805af/tumblr_mlhc0rjpIc1rp499go2_400.gif',':D',''), - (93,'http://www.nationalgallery.org.uk/','http://www.nationalgallery.org.uk/upload/img/N-6589-homepage_208x184.jpg','The National Gallery, London','www.nationalgallery.org.uk','http://www.nationalgallery.org.uk/','http://www.nationalgallery.org.uk/','The National Gallery houses one of the greatest collections of paintings in the world. Enjoy free entrance 361 days a year.',''), - (94,'','https://i.kinja-img.com/gawker-media/image/upload/s--OqAhAoNZ--/c_fill,fl_progressive,g_center,h_200,q_80,w_200/u0939doeuioaqhspkjyc.png','Lifehacker - Tips and downloads for getting things done','lifehacker.com','http://lifehacker.com/','http://lifehacker.com/','Tips and downloads for getting things done',''), - (95,'Youtube >> http://www.youtube.com/watch?v=cv2mjAgFTaI','http://i2.ytimg.com/vi/cv2mjAgFTaI/hqdefault.jpg','Mutemath - Blood Pressure [Official Music Video]','www.youtube.com','https://www.youtube.com/watch?v=cv2mjAgFTaI','https://www.youtube.com/watch?v=cv2mjAgFTaI','© 2011 Teleprompt/Warner Bros. Records Inc. \"Blood Pressure\" by Mutemath from Odd Soul, available now. Written, directed, and filmed in less than 24 hours du...','
'), - (96,'http://www.warnerchannel.com/br/series/','http://cdn.warnerestrenos.com/img/share/shared_link_series_por.jpg','Series | Warner Channel','www.warnerchannel.com','http://www.warnerchannel.com/br/series/','http://www.warnerchannel.com/br/series/','As melhores séries só pra você. Porque #WarnerEstreia',''), - (97,'My own url with no thumb! http://lab.leocardz.com/facebook-link-preview-php--jquery/','','Facebook Link Preview: PHP + jQuery • Lab • LeoCardz','lab.leocardz.com','http://lab.leocardz.com/facebook-link-preview-php--jquery/','http://lab.leocardz.com/facebook-link-preview-php--jquery/','All of us know about the big phenomenon that Facebook is. And since they have always to keep inovating, new super interesting features appear. And the liking of Facebook Link Preview is almost ...',''), - (98,'http://theverge.com/','https://cdn2.vox-cdn.com/uploads/network/placeholder_image/2/default-new.12.jpg','The Verge','www.theverge.com','http://www.theverge.com/','http://www.theverge.com/','The Verge was founded in 2011 in partnership with Vox Media, and covers the intersection of technology, science, art, and culture. Its mission is to offer in-depth reporting and long-form feature stories, breaking news coverage, product information, and community content in a unified and cohesive manner. The site is powered by Vox Media\'s Chorus platform, a modern media stack built for web-native news in the 21st century.',''), - (99,'http://mashable.com/2015/10/22/instagram-boomerang/#h27f1ql3Uaq4','http://rack.1.mshcdn.com/media/ZgkyMDE1LzEwLzIyLzA5L1NjcmVlblNob3QyLjMwNTZmLnBuZwpwCXRodW1iCTEyMDB4NjI3IwplCWpwZw/9073089e/1c1/Screen-Shot-2015-10-22-at-10.18.38-AM.jpg','Instagram launches Boomerang, an app for 1-second videos','mashable.com','http://mashable.com/2015/10/22/instagram-boomerang/','http://mashable.com/2015/10/22/instagram-boomerang/','Instagram has blessed the world with its version of short, looping videos. And it\'s serious about short.',''), - (100,'Tech news...','http://cdn1.tnwcdn.com/wp-content/blogs.dir/1/files/2015/10/Screen-Shot-2015-10-22-at-10.21.45-AM.png','The Next Web - International technology news, business and culture','thenextweb.com','http://thenextweb.com/','http://thenextweb.com/','The Next Web is one of the world’s largest online publications that delivers an international perspective on the latest news about Internet technology, business and culture.',''), - (101,'A Vimeo video: https://vimeo.com/141041381','http://i.vimeocdn.com/video/540550689_640.jpg','DARKLIGHT - 4K Full Film by Sweetgrass Productions','vimeo.com','https://vimeo.com/141041381','https://vimeo.com/141041381','Presented by Philips Ambilight TV In Association with Specialized and TomTom Bandit ActionCam Supported by Freefly Systems (MOVI), Bike Magazine, and CLIF Bar…','
'); + (NULL,'http://www.imdb.com/list/ls015186022/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=2248695062&pf_rd_r=03S3DKWA4WBJZY9Q8Z2X&pf_rd_s=center-1&pf_rd_t=15061&pf_rd_i=homepage&ref_=hm_osc_cr_hd&pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=2248695062&pf_rd_r=03S3DKWA4WBJZY9Q8Z2X&pf_rd_s=center-1&pf_rd_t=15061&pf_rd_i=homepage#1','http://ia.media-imdb.com/images/M/MV5BMTgyNDk2NTE0MV5BMl5BanBnXkFtZTYwMDQ1NDg0._V1._SX266_SY400_.jpg','IMDb: Six Facts You Might Not Know About Oscars Host Chris Rock - a list by IMDb-Editors','www.imdb.com','http://www.imdb.com/list/ls015186022/?pf_rd_m=A2FGELUUNOQJNL','http://www.imdb.com/list/ls015186022/?pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=2248695062&pf_rd_r=03S3DKWA4WBJZY9Q8Z2X&pf_rd_s=center-1&pf_rd_t=15061&pf_rd_i=homepage&ref_=hm_osc_cr_hd&pf_rd_m=A2FGELUUNOQJNL&pf_rd_p=2248695062&pf_rd_r=03S3DKWA4WBJZY9Q8Z2X&pf_rd_s=center-1&pf_rd_t=15061&pf_rd_i=homepage','Chris Rock has been named host of the 88th Annual Academy Awards™, airing Sunday, Feb. 28, 2016. Rock is best known for his stand-up comedy and acting. He is also a writer, producer, and director — which gives him experience in numerous Academy Awards™ categories. His background as a filmmaker makes him well-qualified to host the movie industry\'s biggest night. Here are a half-dozen facts you might not know about Chris Rock\'s career. — Sara Bibel',''), + (NULL,'http://web.media.mit.edu/~mres/','','Mitchel Resnick','web.media.mit.edu','http://web.media.mit.edu/~mres/','http://web.media.mit.edu/~mres/','To support my work, please consider making a donation to the Code-to-Learn Foundation or the Resnick Teacher Scholarship Fund.',''), + (NULL,'http://25.media.tumblr.com/076d514bbf5a5387f24a5896c26805af/tumblr_mlhc0rjpIc1rp499go2_400.gif','http://25.media.tumblr.com/076d514bbf5a5387f24a5896c26805af/tumblr_mlhc0rjpIc1rp499go2_400.gif','Just a minion gif!','25.media.tumblr.com','http://25.media.tumblr.com/076d514bbf5a5387f24a5896c26805af/tumblr_mlhc0rjpIc1rp499go2_400.gif','http://25.media.tumblr.com/076d514bbf5a5387f24a5896c26805af/tumblr_mlhc0rjpIc1rp499go2_400.gif',':D',''), + (NULL,'http://www.nationalgallery.org.uk/','http://www.nationalgallery.org.uk/upload/img/N-6589-homepage_208x184.jpg','The National Gallery, London','www.nationalgallery.org.uk','http://www.nationalgallery.org.uk/','http://www.nationalgallery.org.uk/','The National Gallery houses one of the greatest collections of paintings in the world. Enjoy free entrance 361 days a year.',''), + (NULL,'','https://i.kinja-img.com/gawker-media/image/upload/s--OqAhAoNZ--/c_fill,fl_progressive,g_center,h_200,q_80,w_200/u0939doeuioaqhspkjyc.png','Lifehacker - Tips and downloads for getting things done','lifehacker.com','http://lifehacker.com/','http://lifehacker.com/','Tips and downloads for getting things done',''), + (NULL,'Youtube >> http://www.youtube.com/watch?v=cv2mjAgFTaI','http://i2.ytimg.com/vi/cv2mjAgFTaI/hqdefault.jpg','Mutemath - Blood Pressure [Official Music Video]','www.youtube.com','https://www.youtube.com/watch?v=cv2mjAgFTaI','https://www.youtube.com/watch?v=cv2mjAgFTaI','© 2011 Teleprompt/Warner Bros. Records Inc. \"Blood Pressure\" by Mutemath from Odd Soul, available now. Written, directed, and filmed in less than 24 hours du...','
'), + (NULL,'http://www.warnerchannel.com/br/series/','http://cdn.warnerestrenos.com/img/share/shared_link_series_por.jpg','Series | Warner Channel','www.warnerchannel.com','http://www.warnerchannel.com/br/series/','http://www.warnerchannel.com/br/series/','As melhores séries só pra você. Porque #WarnerEstreia',''), + (NULL,'My own url with no thumb! http://lab.leocardz.com/facebook-link-preview-php--jquery/','','Facebook Link Preview: PHP + jQuery • Lab • LeoCardz','lab.leocardz.com','http://lab.leocardz.com/facebook-link-preview-php--jquery/','http://lab.leocardz.com/facebook-link-preview-php--jquery/','All of us know about the big phenomenon that Facebook is. And since they have always to keep inovating, new super interesting features appear. And the liking of Facebook Link Preview is almost ...',''), + (NULL,'http://theverge.com/','https://cdn2.vox-cdn.com/uploads/network/placeholder_image/2/default-new.12.jpg','The Verge','www.theverge.com','http://www.theverge.com/','http://www.theverge.com/','The Verge was founded in 2011 in partnership with Vox Media, and covers the intersection of technology, science, art, and culture. Its mission is to offer in-depth reporting and long-form feature stories, breaking news coverage, product information, and community content in a unified and cohesive manner. The site is powered by Vox Media\'s Chorus platform, a modern media stack built for web-native news in the 21st century.',''), + (NULL,'http://mashable.com/2015/10/22/instagram-boomerang/#h27f1ql3Uaq4','http://rack.1.mshcdn.com/media/ZgkyMDE1LzEwLzIyLzA5L1NjcmVlblNob3QyLjMwNTZmLnBuZwpwCXRodW1iCTEyMDB4NjI3IwplCWpwZw/9073089e/1c1/Screen-Shot-2015-10-22-at-10.18.38-AM.jpg','Instagram launches Boomerang, an app for 1-second videos','mashable.com','http://mashable.com/2015/10/22/instagram-boomerang/','http://mashable.com/2015/10/22/instagram-boomerang/','Instagram has blessed the world with its version of short, looping videos. And it\'s serious about short.',''), + (NULL,'Tech news...','http://cdn1.tnwcdn.com/wp-content/blogs.dir/1/files/2015/10/Screen-Shot-2015-10-22-at-10.21.45-AM.png','The Next Web - International technology news, business and culture','thenextweb.com','http://thenextweb.com/','http://thenextweb.com/','The Next Web is one of the world’s largest online publications that delivers an international perspective on the latest news about Internet technology, business and culture.',''), + (NULL,'A Vimeo video: https://vimeo.com/141041381','http://i.vimeocdn.com/video/540550689_640.jpg','DARKLIGHT - 4K Full Film by Sweetgrass Productions','vimeo.com','https://vimeo.com/141041381','https://vimeo.com/141041381','Presented by Philips Ambilight TV In Association with Specialized and TomTom Bandit ActionCam Supported by Freefly Systems (MOVI), Bike Magazine, and CLIF Bar…','
'); /*!40000 ALTER TABLE `linkpreview` ENABLE KEYS */; UNLOCK TABLES; diff --git a/src/link-preview/php/delete.php b/src/link-preview/php/delete.php index 898f552..f381cf2 100755 --- a/src/link-preview/php/delete.php +++ b/src/link-preview/php/delete.php @@ -12,8 +12,9 @@ SetUp::headers(); +$data = json_decode($_POST["data"]); $delete = array( - "id" => $_POST["id"], + "id" => $data->id, ); Database::delete($delete);