diff --git a/assets/css/dark.css b/assets/css/dark.css index 5c3112c..e8a4674 100644 --- a/assets/css/dark.css +++ b/assets/css/dark.css @@ -2,15 +2,16 @@ /* Main colors */ --color-accent: #1fa4d1; /* Blue */ --background: #232323; /* Almost black */ - --background-alt: #1f242b; /* Almost black */ - --text: #eff1f7; /* Almost white */ - --text-alt: #eff1f7; /* Almost white */ + --background-alt: #1f242b; /* Blueish black */ + --background-popup: #1f242b; /* Blueish black */ + --text: #d6dbdf; /* Almost white */ + --text-alt: #eaecee; /* Almost white */ --border: #5f6368; /* Grey */ --border-alt: #466f82; /* Dark blue */ --button-bg: #1fa4d1; /* Blue */ --button-text: #f0f6fc; /* Almost white */ --button-hover: #466f82; /* Dark blue */ - --link: #2f8ad0; /* Blue */ + --link: #3498db; /* Blue */ --link-visited: #6d59a3; /* Purple */ --link-source: #eff1f7; /* Almost white */ --meta: #999; /* Grey */ @@ -19,6 +20,7 @@ /* Front page (Also used on oAUTH page) */ --startpage-border: #545a5f; /* Grey */ --startpage-border-alt: #6c747a; /* Lighter grey */ + --startpage-button-text: #f0f6fc; /* Almost white */ --startpage-button-bg: #2b323b; /* Blueish grey */ --startpage-button-bg-alt: #363e4a; /* Lighter blueish grey */ diff --git a/assets/css/default.css b/assets/css/default.css index d03ce50..aa44dd0 100644 --- a/assets/css/default.css +++ b/assets/css/default.css @@ -3,6 +3,7 @@ --color-accent: #1fa4d1; /* Blue */ --background: #fff; /* White */ --background-alt: #1f242b; /* Almost black */ + --background-popup: #ebf5fb; /* Blueish white */ --text: #494949; /* Dark grey */ --text-alt: #f0f6fc; /* Almost white */ --border: #5f6368; /* Grey */ @@ -19,6 +20,7 @@ /* Front page (Also used on oAUTH page) */ --startpage-border: #545a5f; /* Grey */ --startpage-border-alt: #6c747a; /* Lighter grey */ + --startpage-button-text: #f0f6fc; /* Almost white */ --startpage-button-bg: #2b323b; /* Blueish grey */ --startpage-button-bg-alt: #363e4a; /* Lighter blueish grey */ diff --git a/assets/css/light.css b/assets/css/light.css index a46dbf8..3fc7174 100644 --- a/assets/css/light.css +++ b/assets/css/light.css @@ -2,10 +2,11 @@ /* Main colors */ --color-accent: #1fa4d1; /* Blue */ --background: #fff; /* White */ - --background-alt: #ebf3fa; /* Light blue */ + --background-alt: #d6eaf8; /* Light blue */ + --background-popup: #ebf5fb; /* Blueish white */ --text: #494949; /* Dark grey */ --text-alt: #494949; /* Dark grey */ - --border: #5f6368; /* Grey */ + --border: #808b96; /* Grey */ --border-alt: #466f82; /* Dark blue */ --button-bg: #1fa4d1; /* Blue */ --button-text: #f0f6fc; /* Almost white */ @@ -17,10 +18,11 @@ --result-special-background: #ebf3fa; /* Light blue */ /* Front page (Also used on oAUTH page) */ - --startpage-border: #545a5f; /* Grey */ - --startpage-border-alt: #6c747a; /* Lighter grey */ - --startpage-button-bg: #2b323b; /* Blueish grey */ - --startpage-button-bg-alt: #363e4a; /* Lighter blueish grey */ + --startpage-border: #808b96; /* Grey */ + --startpage-border-alt: #808b96; /* Lighter grey */ + --startpage-button-text: #f0f6fc; /* Almost white */ + --startpage-button-bg: #2980B9; /* Blueish grey */ + --startpage-button-bg-alt: #7FB3D5; /* Lighter blueish grey */ /* Misc */ --green: #518257; /* Green */ diff --git a/assets/css/styles.css b/assets/css/styles.css index 654f077..dc71787 100644 --- a/assets/css/styles.css +++ b/assets/css/styles.css @@ -7,37 +7,29 @@ * COPYRIGHT NOTICES AND ALL THE COMMENTS SHOULD REMAIN INTACT. * By using this code you agree to indemnify Arnan de Gans from any * liability that might arise from its use. +--------------------------------------------------------------------------------------- +* All icons are borrowed from IconFinder (https://www.iconfinder.com/search/icons?family=unicons-line) ------------------------------------------------------------------------------------ */ -body { margin:0; padding:0; line-height:1.2; font-family:Arial, Helvetica, sans-serif; font-weight:400; font-size:1rem; background-color:var(--background); color:var(--text); } +body { min-height:100vh; display:flex; flex-direction:column; margin:0; padding:0; line-height:1.2; font-family:Arial, Helvetica, sans-serif; font-weight:400; font-size:1rem; background-color:var(--background); color:var(--text); } div { margin:0; padding:0; border:0; vertical-align:baseline; } -h2, h3, h4, h5, h6 { margin:0; padding-top:.1em; padding-bottom:.3em; font-weight:400; } +h2, h3, h4, h5, h6 { margin:0; padding-top:.1em; padding-bottom:.3em; font-weight:500; } h1 { font-size:4em; } h2 { font-size:2em; } h3 { font-size:1.5em; } -h4, h5, h6 { font-size:1em; } -p, ul, ol { margin:0; padding-top:.2em; padding-bottom:.5em; } +h4, h5, h6 { font-size:1.2em; } +p { margin:0; padding-top:.2em; padding-bottom:.5em; } ul, ul > li { margin:0; padding:0; list-style:none; } input, button { outline:none; } button { cursor:pointer; } a { text-decoration:none; color:var(--link); } a:hover { text-decoration:underline; } -small { padding:5px 0; color:var(--meta); font-size:.8rem; } +small { color:var(--meta); font-size:.8rem; } input[type="text"]:invalid ~ input[type="submit"] { opacity:0.5; pointer-events:none; } input[type="search"]::-webkit-search-cancel-button { -webkit-appearance:none; -webkit-mask-image:url("data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/Pjxzdmcgdmlld0JveD0iMCAwIDI0IDI0IiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjxwYXRoIGQ9Ik0xMy40MSwxMmw0LjMtNC4yOWExLDEsMCwxLDAtMS40Mi0xLjQyTDEyLDEwLjU5LDcuNzEsNi4yOUExLDEsMCwwLDAsNi4yOSw3LjcxTDEwLjU5LDEybC00LjMsNC4yOWExLDEsMCwwLDAsMCwxLjQyLDEsMSwwLDAsMCwxLjQyLDBMMTIsMTMuNDFsNC4yOSw0LjNhMSwxLDAsMCwwLDEuNDIsMCwxLDEsMCwwLDAsMC0xLjQyWiIgZmlsbD0iIzY1NjNmZiIvPjwvc3ZnPg=="); } -/* Page structure */ -body { min-height:100vh; display:flex; flex-direction:column; } -.header { padding:0; width:100%; } -.header form { margin:35px 0; } -.content { margin:15px 158px; padding:0; } -.footer { box-sizing:border-box; bottom:0; margin-top:auto; padding:10px 5px; width:100%; } -/* Flex grid (Box office, footer) */ -.grid-container { display:flex; flex-direction:row; } -.list-grid, .footer-grid { flex:1; width:50%; } -.list-grid:first-child, .footer-grid:first-child { margin-right:20px; } -.footer-grid:nth-child(2) { text-align:right; } +.content { margin:25px 158px; padding:0; } /* Start page */ .startpage { background-color:var(--background-alt); color:var(--text-alt); } @@ -45,7 +37,7 @@ body { min-height:100vh; display:flex; flex-direction:column; } .startpage .search-field, .password-generator .password { padding:10px 20px; width:600px; color:var(--text-alt); background-color:var(--background-alt); font-size:2rem; border:1px solid var(--startpage-border); border-radius:10px; } .startpage .search-field:focus, .password-generator .password:focus { border:1px solid var(--startpage-border-alt); } .startpage .search-field[type="search"]::-webkit-search-cancel-button { background-size:28px 28px; height:28px; width:28px; background:var(--text-alt); } -.startpage .web-search, .startpage .image-search, .startpage .magnet-search, .startpage .box-office { display:inline-block; box-sizing:border-box; margin:30px 20px 10px 20px; padding:13px 10px; min-width:130px; min-height:48px; vertical-align:middle; text-align:center; font-size:1rem; font-weight:400; background-color:var(--startpage-button-bg); color:var(--text-alt); border:1px solid var(--startpage-border); border-radius:6px; } +.startpage .web-search, .startpage .image-search, .startpage .magnet-search, .startpage .box-office { display:inline-block; box-sizing:border-box; margin:30px 20px 10px 20px; padding:13px 10px; min-width:130px; min-height:48px; vertical-align:middle; text-align:center; font-size:1rem; font-weight:400; background-color:var(--startpage-button-bg); color:var(--startpage-button-text); border:1px solid var(--startpage-border); border-radius:6px; } .startpage .magnet-search { margin-right:0; border-radius:6px 0 0 6px; } .startpage .box-office { margin-left:0; border-left:1px solid var(--startpage-button-bg); border-radius:0 6px 6px 0; } .startpage .web-search:hover, .startpage .image-search:hover, .startpage .magnet-search:hover, .startpage .box-office:hover { border:1px solid var(--startpage-border-alt); background-color:var(--startpage-button-bg-alt); text-decoration:none; } @@ -54,7 +46,8 @@ body { min-height:100vh; display:flex; flex-direction:column; } .password-generator .password { margin:10px auto; width:300px; text-align:center; font-size:.8rem; } /* Page header (Search results, Help, Box office) */ -.header { background-color:var(--background-alt); color:var(--text-alt); border-bottom:3px solid var(--color-accent); } +.header { padding:0; width:100%; background-color:var(--background-alt); color:var(--text-alt); border-bottom:3px solid var(--color-accent); } +.header form { margin:35px 0; } .header .logo { position:absolute; margin:0 18px; font-size:2rem; } .header .logo a, .header .logo a:hover { text-decoration:none; color:var(--text-alt); cursor:pointer; } .header .search-field, .header .button { display:inline-block; box-sizing:border-box; vertical-align:middle; height:40px; font-size:1.2rem } @@ -62,47 +55,52 @@ body { min-height:100vh; display:flex; flex-direction:column; } .header .search-field[type="search"]::-webkit-search-cancel-button { background-size:20px 20px; height:20px; width:20px; background-color:var(--text-alt); } .header .button { margin:0 10px 0 0; padding:5px 20px 5px 15px; color:var(--button-text); background-color:var(--button-bg); border:none; border-radius:0 10px 10px 0; } -.header .navigation { margin-left:158px; margin-bottom:8px; } /* Margin-bottom must match with padding-bottom on line 79 */ -.header .navigation img { margin-right:5px; height:16px; vertical-align:middle; } -.header .navigation a { margin-right:20px; border:none; cursor:pointer; text-decoration:none; } -.header .navigation a:visited { color:var(--link); } -.header .navigation a:hover { color:var(--text-alt); } -.header .navigation .active { padding-bottom:8px; border-bottom:4px solid var(--color-accent); } +.navigation { margin-left:158px; margin-bottom:8px; } /* Margin-bottom must match with padding-bottom on line 79 */ +.navigation a { margin-right:20px; border:none; cursor:pointer; text-decoration:none; } +.navigation a:visited { color:var(--link); } +.navigation a:hover { color:var(--text-alt); } +.navigation .active { padding-bottom:8px; border-bottom:4px solid var(--color-accent); } -/* Navigation icons (https://www.iconfinder.com/search/icons?family=unicons-line) */ -.navigation a.tab-search::before { content:""; display:inline-block; width:20px; height:20px; background:var(--color-accent); vertical-align:middle; mask-image:url('data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/Pjxzdmcgdmlld0JveD0iMCAwIDI0IDI0IiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjxwYXRoIGQ9Ik0xMiwyMEg1YTEsMSwwLDAsMS0xLTFWNUExLDEsMCwwLDEsNSw0aDVWN2EzLDMsMCwwLDAsMywzaDN2MWExLDEsMCwwLDAsMiwwVjlzMCwwLDAtLjA2YTEuMzEsMS4zMSwwLDAsMC0uMDYtLjI3bDAtLjA5YTEuMDcsMS4wNywwLDAsMC0uMTktLjI4aDBsLTYtNmgwYTEuMDcsMS4wNywwLDAsMC0uMjgtLjE5LjMyLjMyLDAsMCwwLS4wOSwwQS44OC44OCwwLDAsMCwxMS4wNSwySDVBMywzLDAsMCwwLDIsNVYxOWEzLDMsMCwwLDAsMywzaDdhMSwxLDAsMCwwLDAtMlpNMTIsNS40MSwxNC41OSw4SDEzYTEsMSwwLDAsMS0xLTFaTTcsOGExLDEsMCwwLDAsMCwySDhBMSwxLDAsMCwwLDgsOFpNMjEuNzEsMjAuMjlsLTEuMTctMS4xNkEzLjQ0LDMuNDQsMCwwLDAsMjAsMTVoMEEzLjQ5LDMuNDksMCwwLDAsMTQsMTcuNDlhMy40NiwzLjQ2LDAsMCwwLDUuMTMsMy4wNWwxLjE2LDEuMTdhMSwxLDAsMCwwLDEuNDIsMEExLDEsMCwwLDAsMjEuNzEsMjAuMjlabS0zLjE3LTEuNzVhMS41NCwxLjU0LDAsMCwxLTIuMTEsMEExLjUsMS41LDAsMCwxLDE2LDE3LjQ5YTEuNDYsMS40NiwwLDAsMSwuNDQtMS4wNiwxLjQ4LDEuNDgsMCwwLDEsMS0uNDNBMS40NywxLjQ3LDAsMCwxLDE5LDE3LjQ5LDEuNSwxLjUsMCwwLDEsMTguNTQsMTguNTRaTTEzLDEySDdhMSwxLDAsMCwwLDAsMmg2YTEsMSwwLDAsMCwwLTJabS0yLDZhMSwxLDAsMCwwLDAtMkg3YTEsMSwwLDAsMCwwLDJaIiBmaWxsPSIjNjU2M2ZmIi8+PC9zdmc+'); } -.navigation a.tab-image::before { content:""; display:inline-block; width:20px; height:20px; background:var(--color-accent); vertical-align:middle; mask-image:url('data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/Pjxzdmcgdmlld0JveD0iMCAwIDI0IDI0IiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjxwYXRoIGQ9Ik0xOSwxM2ExLDEsMCwwLDAtMSwxdi4zOWwtMS40OC0xLjQ4YTIuNzksMi43OSwwLDAsMC0zLjkzLDBsLS43LjdMOS40MSwxMS4xMmEyLjg3LDIuODcsMCwwLDAtMy45MywwTDQsMTIuNjFWN0ExLDEsMCwwLDEsNSw2SDlBMSwxLDAsMCwwLDksNEg1QTMsMywwLDAsMCwyLDdWMTlhMywzLDAsMCwwLDMsM0gxN2EzLDMsMCwwLDAsMy0zVjE0QTEsMSwwLDAsMCwxOSwxM1pNNSwyMGExLDEsMCwwLDEtMS0xVjE1LjQzbDIuOS0yLjg5YS43OS43OSwwLDAsMSwxLjA5LDBsMy4xNywzLjE3LDAsMEwxNS40NSwyMFptMTMtMWExLDEsMCwwLDEtLjE4LjU0TDEzLjMxLDE1bC43LS42OWEuNzcuNzcsMCwwLDEsMS4xLDBMMTgsMTcuMjJabTMuNzEtOC43MUwyMCw4LjU3YTQuMzEsNC4zMSwwLDEsMC02LjcyLjc5LDQuMjcsNC4yNywwLDAsMCwzLDEuMjZBNC4zNCw0LjM0LDAsMCwwLDE4LjU3LDEwbDEuNzIsMS43M2ExLDEsMCwwLDAsMS40MiwwQTEsMSwwLDAsMCwyMS43MSwxMC4yOVpNMTgsOGEyLjMyLDIuMzIsMCwxLDEsMC0zLjI3QTIuMzIsMi4zMiwwLDAsMSwxOCw4WiIgZmlsbD0iIzY1NjNmZiIvPjwvc3ZnPg=='); } -.navigation a.tab-news::before { content:""; display:inline-block; width:20px; height:20px; background:var(--color-accent); vertical-align:middle; mask-image:url('data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/Pjxzdmcgdmlld0JveD0iMCAwIDI0IDI0IiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjxwYXRoIGQ9Ik0xNywxMUgxNmExLDEsMCwwLDAsMCwyaDFhMSwxLDAsMCwwLDAtMlptMCw0SDE2YTEsMSwwLDAsMCwwLDJoMWExLDEsMCwwLDAsMC0yWk0xMSw5aDZhMSwxLDAsMCwwLDAtMkgxMWExLDEsMCwwLDAsMCwyWk0yMSwzSDdBMSwxLDAsMCwwLDYsNFY3SDNBMSwxLDAsMCwwLDIsOFYxOGEzLDMsMCwwLDAsMywzSDE4YTQsNCwwLDAsMCw0LTRWNEExLDEsMCwwLDAsMjEsM1pNNiwxOGExLDEsMCwwLDEtMiwwVjlINlptMTQtMWEyLDIsMCwwLDEtMiwySDcuODJBMywzLDAsMCwwLDgsMThWNUgyMFptLTktNGgxYTEsMSwwLDAsMCwwLTJIMTFhMSwxLDAsMCwwLDAsMlptMCw0aDFhMSwxLDAsMCwwLDAtMkgxMWExLDEsMCwwLDAsMCwyWiIgZmlsbD0iIzY1NjNmZiIvPjwvc3ZnPg=='); } -.navigation a.tab-magnet::before { content:""; display:inline-block; width:20px; height:20px; background:var(--color-accent); vertical-align:middle; mask-image:url('data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/Pjxzdmcgdmlld0JveD0iMCAwIDI0IDI0IiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjxwYXRoIGQ9Ik0yMCw4Ljk0YTEuMzEsMS4zMSwwLDAsMC0uMDYtLjI3bDAtLjA5YTEuMDcsMS4wNywwLDAsMC0uMTktLjI4aDBsLTYtNmgwYTEuMDcsMS4wNywwLDAsMC0uMjgtLjE5bC0uMSwwQTEuMSwxLjEsMCwwLDAsMTMuMDYsMkg3QTMsMywwLDAsMCw0LDVWMTlhMywzLDAsMCwwLDMsM0gxN2EzLDMsMCwwLDAsMy0zVjlTMjAsOSwyMCw4Ljk0Wk0xNCw1LjQxLDE2LjU5LDhIMTVhMSwxLDAsMCwxLTEtMVpNMTgsMTlhMSwxLDAsMCwxLTEsMUg3YTEsMSwwLDAsMS0xLTFWNUExLDEsMCwwLDEsNyw0aDVWN2EzLDMsMCwwLDAsMywzaDNabS00LjcxLTQuNzEtLjI5LjNWMTJhMSwxLDAsMCwwLTIsMHYyLjU5bC0uMjktLjNhMSwxLDAsMCwwLTEuNDIsMS40MmwyLDJhMSwxLDAsMCwwLC4zMy4yMS45NC45NCwwLDAsMCwuNzYsMCwxLDEsMCwwLDAsLjMzLS4yMWwyLTJhMSwxLDAsMCwwLTEuNDItMS40MloiIGZpbGw9IiM2NTYzZmYiLz48L3N2Zz4='); } +/* Navigation icons */ +.navigation a.tab-search::before { content:""; display:inline-block; width:1.1em; height:1.1em; background:var(--color-accent); vertical-align:text-bottom; mask-image:url('data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/Pjxzdmcgdmlld0JveD0iMCAwIDI0IDI0IiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjxwYXRoIGQ9Ik0xMiwyMEg1YTEsMSwwLDAsMS0xLTFWNUExLDEsMCwwLDEsNSw0aDVWN2EzLDMsMCwwLDAsMywzaDN2MWExLDEsMCwwLDAsMiwwVjlzMCwwLDAtLjA2YTEuMzEsMS4zMSwwLDAsMC0uMDYtLjI3bDAtLjA5YTEuMDcsMS4wNywwLDAsMC0uMTktLjI4aDBsLTYtNmgwYTEuMDcsMS4wNywwLDAsMC0uMjgtLjE5LjMyLjMyLDAsMCwwLS4wOSwwQS44OC44OCwwLDAsMCwxMS4wNSwySDVBMywzLDAsMCwwLDIsNVYxOWEzLDMsMCwwLDAsMywzaDdhMSwxLDAsMCwwLDAtMlpNMTIsNS40MSwxNC41OSw4SDEzYTEsMSwwLDAsMS0xLTFaTTcsOGExLDEsMCwwLDAsMCwySDhBMSwxLDAsMCwwLDgsOFpNMjEuNzEsMjAuMjlsLTEuMTctMS4xNkEzLjQ0LDMuNDQsMCwwLDAsMjAsMTVoMEEzLjQ5LDMuNDksMCwwLDAsMTQsMTcuNDlhMy40NiwzLjQ2LDAsMCwwLDUuMTMsMy4wNWwxLjE2LDEuMTdhMSwxLDAsMCwwLDEuNDIsMEExLDEsMCwwLDAsMjEuNzEsMjAuMjlabS0zLjE3LTEuNzVhMS41NCwxLjU0LDAsMCwxLTIuMTEsMEExLjUsMS41LDAsMCwxLDE2LDE3LjQ5YTEuNDYsMS40NiwwLDAsMSwuNDQtMS4wNiwxLjQ4LDEuNDgsMCwwLDEsMS0uNDNBMS40NywxLjQ3LDAsMCwxLDE5LDE3LjQ5LDEuNSwxLjUsMCwwLDEsMTguNTQsMTguNTRaTTEzLDEySDdhMSwxLDAsMCwwLDAsMmg2YTEsMSwwLDAsMCwwLTJabS0yLDZhMSwxLDAsMCwwLDAtMkg3YTEsMSwwLDAsMCwwLDJaIiBmaWxsPSIjNjU2M2ZmIi8+PC9zdmc+'); } +.navigation a.tab-image::before { content:""; display:inline-block; width:1.1em; height:1.1em; background:var(--color-accent); vertical-align:text-bottom; mask-image:url('data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/Pjxzdmcgdmlld0JveD0iMCAwIDI0IDI0IiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjxwYXRoIGQ9Ik0xOSwxM2ExLDEsMCwwLDAtMSwxdi4zOWwtMS40OC0xLjQ4YTIuNzksMi43OSwwLDAsMC0zLjkzLDBsLS43LjdMOS40MSwxMS4xMmEyLjg3LDIuODcsMCwwLDAtMy45MywwTDQsMTIuNjFWN0ExLDEsMCwwLDEsNSw2SDlBMSwxLDAsMCwwLDksNEg1QTMsMywwLDAsMCwyLDdWMTlhMywzLDAsMCwwLDMsM0gxN2EzLDMsMCwwLDAsMy0zVjE0QTEsMSwwLDAsMCwxOSwxM1pNNSwyMGExLDEsMCwwLDEtMS0xVjE1LjQzbDIuOS0yLjg5YS43OS43OSwwLDAsMSwxLjA5LDBsMy4xNywzLjE3LDAsMEwxNS40NSwyMFptMTMtMWExLDEsMCwwLDEtLjE4LjU0TDEzLjMxLDE1bC43LS42OWEuNzcuNzcsMCwwLDEsMS4xLDBMMTgsMTcuMjJabTMuNzEtOC43MUwyMCw4LjU3YTQuMzEsNC4zMSwwLDEsMC02LjcyLjc5LDQuMjcsNC4yNywwLDAsMCwzLDEuMjZBNC4zNCw0LjM0LDAsMCwwLDE4LjU3LDEwbDEuNzIsMS43M2ExLDEsMCwwLDAsMS40MiwwQTEsMSwwLDAsMCwyMS43MSwxMC4yOVpNMTgsOGEyLjMyLDIuMzIsMCwxLDEsMC0zLjI3QTIuMzIsMi4zMiwwLDAsMSwxOCw4WiIgZmlsbD0iIzY1NjNmZiIvPjwvc3ZnPg=='); } +.navigation a.tab-news::before { content:""; display:inline-block; width:1.1em; height:1.1em; background:var(--color-accent); vertical-align:text-bottom; mask-image:url('data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/Pjxzdmcgdmlld0JveD0iMCAwIDI0IDI0IiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjxwYXRoIGQ9Ik0xNywxMUgxNmExLDEsMCwwLDAsMCwyaDFhMSwxLDAsMCwwLDAtMlptMCw0SDE2YTEsMSwwLDAsMCwwLDJoMWExLDEsMCwwLDAsMC0yWk0xMSw5aDZhMSwxLDAsMCwwLDAtMkgxMWExLDEsMCwwLDAsMCwyWk0yMSwzSDdBMSwxLDAsMCwwLDYsNFY3SDNBMSwxLDAsMCwwLDIsOFYxOGEzLDMsMCwwLDAsMywzSDE4YTQsNCwwLDAsMCw0LTRWNEExLDEsMCwwLDAsMjEsM1pNNiwxOGExLDEsMCwwLDEtMiwwVjlINlptMTQtMWEyLDIsMCwwLDEtMiwySDcuODJBMywzLDAsMCwwLDgsMThWNUgyMFptLTktNGgxYTEsMSwwLDAsMCwwLTJIMTFhMSwxLDAsMCwwLDAsMlptMCw0aDFhMSwxLDAsMCwwLDAtMkgxMWExLDEsMCwwLDAsMCwyWiIgZmlsbD0iIzY1NjNmZiIvPjwvc3ZnPg=='); } +.navigation a.tab-magnet::before { content:""; display:inline-block; width:1.1em; height:1.1em; background:var(--color-accent); vertical-align:text-bottom; mask-image:url('data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/Pjxzdmcgdmlld0JveD0iMCAwIDI0IDI0IiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjxwYXRoIGQ9Ik0yMCw4Ljk0YTEuMzEsMS4zMSwwLDAsMC0uMDYtLjI3bDAtLjA5YTEuMDcsMS4wNywwLDAsMC0uMTktLjI4aDBsLTYtNmgwYTEuMDcsMS4wNywwLDAsMC0uMjgtLjE5bC0uMSwwQTEuMSwxLjEsMCwwLDAsMTMuMDYsMkg3QTMsMywwLDAsMCw0LDVWMTlhMywzLDAsMCwwLDMsM0gxN2EzLDMsMCwwLDAsMy0zVjlTMjAsOSwyMCw4Ljk0Wk0xNCw1LjQxLDE2LjU5LDhIMTVhMSwxLDAsMCwxLTEtMVpNMTgsMTlhMSwxLDAsMCwxLTEsMUg3YTEsMSwwLDAsMS0xLTFWNUExLDEsMCwwLDEsNyw0aDVWN2EzLDMsMCwwLDAsMywzaDNabS00LjcxLTQuNzEtLjI5LjNWMTJhMSwxLDAsMCwwLTIsMHYyLjU5bC0uMjktLjNhMSwxLDAsMCwwLTEuNDIsMS40MmwyLDJhMSwxLDAsMCwwLC4zMy4yMS45NC45NCwwLDAsMCwuNzYsMCwxLDEsMCwwLDAsLjMzLS4yMWwyLTJhMSwxLDAsMCwwLTEuNDItMS40MloiIGZpbGw9IiM2NTYzZmYiLz48L3N2Zz4='); } /* Search results (web, image, magnet, box office) */ -.resultspage .timer { margin:10px 0 0 0; } -.resultspage .sources { font-size:.8rem; color:var(--meta); } -.resultspage .result, .boxofficepage .result, .resultspage .result-special, .resultspage .result.shared, .resultspage .sources, .resultspage .suggestion { margin:0 0 25px 0; } -.resultspage .result-grid .result, .resultspage .result.image { margin:0; } +.resultspage .meta { margin:0 0 15px 0; } +.resultspage .timer, .resultspage .didyoumean { margin:0; padding:0; } +.resultspage .sources, .resultspage .suggestion { padding:0; font-size:.8rem; color:var(--meta); } +.resultspage .result, .resultspage .result-special, .resultspage .result.shared, .boxofficepage .result { margin:0 0 25px 0; } .resultspage .result-special, .resultspage .result.shared { padding:10px; } /* Results formatting */ -div.title, div.description, div.text, div.url, div.source { word-wrap:break-word; } +.resultspage .title, .resultspage .description, .resultspage .text, .resultspage .url, .resultspage .source, .resultspage .note { word-wrap:break-word; } -.result div.url, .result-special div.source { line-height:1.6; letter-spacing:.2px; } -.result div.url a, .result-special div.source a { cursor:pointer; text-decoration:none; color:var(--link-source); } +.resultspage .result .url, .resultspage .result-special .source { letter-spacing:.2px; } +.resultspage .result .url a, .resultspage .result-special .source a { cursor:pointer; text-decoration:none; color:var(--link-source); } -.result div.title h2 { position:relative; letter-spacing:-.01px; font-size:1.5rem; } -.result div.title h2:hover { text-decoration:underline; } -.result div.title a { display:block; cursor:pointer; } -.result div.title a:visited { color:var(--link-visited); } -.result div.description { line-height:1.4; } -.result div.description p { padding-top:0; padding-bottom:0; } -.result div.meta { padding:5px 0; font-size:.8rem; color:var(--meta); } -.result div.engines { padding:2px 0; font-size:.8rem; color:var(--meta); } +.resultspage .result .title h2 { position:relative; letter-spacing:-.01px; font-size:1.5rem; } +.resultspage .result .title h2:hover { text-decoration:underline; } +.resultspage .result .title a { display:block; cursor:pointer; } +.resultspage .result .title a:visited { color:var(--link-visited); } -.result.news h2 { padding-top:0; padding-bottom:0; } -.result.news { clear:both; overflow:auto; } +.resultspage .result .description p, .resultspage .result .meta p { padding-top:0; padding-bottom:0; } +.resultspage .result .meta { padding:0; font-size:.8rem; color:var(--meta); text-align:center; } +.resultspage .result.image .meta { margin:5px 0 0 0; } +.resultspage .result .engines { padding:2px 0; font-size:.8rem; color:var(--meta); } + +.resultspage .result.news { display:flex; flex-direction:row; column-gap:1rem; width:100%; } +.resultspage .result.news .title h2, .resultspage .result.magnet .title h2 { padding-top:0; padding-bottom:.2em; } +.resultspage .result.news .image { position:relative; overflow:hidden; width:140px; min-width:140px; height: 100px; border-radius:10px; } +.resultspage .result.news .image::before { content:""; position:absolute; height:100%; width:100%; background-color:var(--color-accent); background-image:url('/assets/images/goosle-nobg.webp'); background-position:center; background-repeat:no-repeat; border-radius:10px; z-index:-1; } +.resultspage .result.news .image img { object-fit:cover; object-position:center; width:100%; height:100%; border-radius:10px; } + +.resultspage .result-special .note { text-align:right; } /* Special results and shared magnet result */ -.result.shared, .result-special { overflow:hidden; background-color:var(--result-special-background); border:1px solid var(--border-alt); border-radius:10px; } -.result.shared div.title h2, .result-special div.title h2 { padding-top:0; text-decoration:none; } +.resultspage .result.shared, .resultspage .result-special { overflow:hidden; background-color:var(--result-special-background); border:1px solid var(--border-alt); border-radius:10px; } +.resultspage .result.shared div.title h2, .resultspage .result-special div.title h2 { padding-top:0; text-decoration:none; } .boxofficepage .result { border:1px solid var(--result-border); border-radius:8px; } .boxofficepage .result div.title h2 { font-size:1.2rem; } @@ -112,26 +110,27 @@ div.title, div.description, div.text, div.url, div.source { word-wrap:break-word /* Grids (image and magnet highlights) */ @supports (display:grid) { - .result-grid ul { display:grid; grid-template-columns:repeat(auto-fill, minmax(8rem, 1fr)); grid-gap:1rem; } + .result-grid { display:grid; grid-template-columns:repeat(auto-fill, minmax(8rem, 1fr)); row-gap:2rem; column-gap:1rem; } } @supports not (display:grid) { - .result-grid ul > * { max-width:8rem; margin-left:auto; margin-right:auto; } - .result-grid ul .result { display:inline-block; margin:.75rem; width:12.5%; } - .result-grid ul > * + * { margin-top:1rem; } + .result-grid > * { max-width:8rem; margin-left:auto; margin-right:auto; } + .result-grid .result { display:inline-block; margin:.75rem; width:12.5%; } + .result-grid > * + * { margin-top:1rem; } } /* Grid results */ -.result-grid { width:100%; margin:0 0 25px 0; } -.result-grid ul .result .result-box { position:relative; } -.result-grid ul .result.image .result-box::after, .result-grid ul .result.eztv .result-box::after { display:block; padding-bottom:100%; content:""; } -.result-grid ul .result.image .result-box img, .result-grid ul .result.eztv .result-box img { position:absolute; object-fit:cover; width:100%; height:100%; border-radius:10px; } -.result-grid ul .result.yts .result-box img { width:100%; height:100%; border-radius:10px; } -.result-grid ul .result .result-box img:hover { outline:none; border-color:var(--border); border-radius:10px; box-shadow:0 0 10px var(--border); } +.result-grid { margin:0 0 25px 0; } +.result-grid .result.image .thumb, .result-grid .result.highlight .thumb { position:relative; overflow:hidden; height: 140px; border-radius:10px; } +.result-grid .result.yts .thumb { height: 210px;; } +.result-grid .result.image .thumb::before, .result-grid .result.highlight .thumb::before { position:absolute; height:100%; width:100%; background-color:var(--color-accent); background-image:url('/assets/images/goosle-nobg.webp'); background-position:center; background-repeat:no-repeat; border-radius:10px; content:""; z-index:-1; } +.result-grid .result.image .thumb img, .result-grid .result.highlight .thumb img { object-fit:cover; object-position:center; width:100%; height:100%; border-radius:10px; } +.result-grid .result.image .thumb:hover, .result-grid .result.highlight .thumb:hover { outline:none; border-color:var(--border); border-radius:10px; box-shadow:0 0 10px var(--border); } +.result-grid .result, .result-grid .meta { margin:0; padding:0; } /* Magnet highlight/Share/Boxoffice popup */ .goosebox { display:none; position:fixed; inset:0; z-index:10000; overflow:auto; background-color:rgb(0, 0, 0, .75); } .goosebox.open { display:block; } -.goosebox-body { margin:50px auto; padding:20px; width:50%; background:var(--background); border:1px solid var(--border); border-radius:10px; } +.goosebox-body { margin:50px auto; padding:20px; width:50%; background:var(--background-popup); border:1px solid var(--border); border-radius:10px; } .goosebox-body h2 { padding:0 0 .3em 0; } .goosebox-body h3 { font-size:1.2rem; } .goosebox-body p { padding-top:.1em; padding-bottom:.2em; } @@ -144,6 +143,11 @@ div.title, div.description, div.text, div.url, div.source { word-wrap:break-word .goosebox-body .share-button { margin:0 auto 10px auto; border-radius:0 0 10px 10px; } .goosebox-body .success, .goosebox-body .fail { font-weight:600; } +/* Stats display (stats page) */ +.statspage h1 { margin-bottom:10px; padding:0; text-align:center; font-size:2.5em; font-weight:400; } +.statspage h2 { margin-bottom:10px; padding:0; text-align:center; font-size:1.5em; } +.statspage p { font-family:'american typewriter'; } + /* oAUTH page */ .oauthpage { background-color:var(--background-alt); color:var(--text-alt); } .oauthpage .oauth-form { text-align:center; margin-top:20px; } @@ -152,10 +156,37 @@ div.title, div.description, div.text, div.url, div.source { word-wrap:break-word .oauthpage .oauth-buttons button { margin:30px 20px 10px 20px; padding:13px 10px; min-width:130px; color:var(--text-alt); background-color:var(--startpage-button-bg); border:1px solid var(--startpage-border); font-size:1.2rem; border-radius:6px; } .oauthpage .oauth-buttons button:hover { border:1px solid var(--startpage-border-alt); background-color:var(--startpage-button-bg-alt); text-decoration:none; } +/* Pagination */ +.pagination { text-align:center; } +.pagination a { font-size:1.2em; } +.pagination a.current { font-size:1.4em; font-weight:400; text-decoration:underline; } +.arrow-left::before { content:""; display:inline-block; width:1.2em; height:1.2em; background:var(--link); vertical-align:text-top; mask-image:url('data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/PjxzdmcgZGF0YS1uYW1lPSJMYXllciAxIiB2aWV3Qm94PSIwIDAgMjQgMjQiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PHBhdGggZD0iTTE3LDExSDkuNDFsMy4zLTMuMjlhMSwxLDAsMSwwLTEuNDItMS40MmwtNSw1YTEsMSwwLDAsMC0uMjEuMzMsMSwxLDAsMCwwLDAsLjc2LDEsMSwwLDAsMCwuMjEuMzNsNSw1YTEsMSwwLDAsMCwxLjQyLDAsMSwxLDAsMCwwLDAtMS40Mkw5LjQxLDEzSDE3YTEsMSwwLDAsMCwwLTJaIiBmaWxsPSIjNjU2M2ZmIi8+PC9zdmc+'); } +.arrow-right::before { content:""; display:inline-block; width:1.2em; height:1.2em; background:var(--link); vertical-align:text-top; mask-image:url('data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/PjxzdmcgZGF0YS1uYW1lPSJMYXllciAxIiB2aWV3Qm94PSIwIDAgMjQgMjQiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PHBhdGggZD0iTTE3LjkyLDExLjYyYTEsMSwwLDAsMC0uMjEtLjMzbC01LTVhMSwxLDAsMCwwLTEuNDIsMS40MkwxNC41OSwxMUg3YTEsMSwwLDAsMCwwLDJoNy41OWwtMy4zLDMuMjlhMSwxLDAsMCwwLDAsMS40MiwxLDEsMCwwLDAsMS40MiwwbDUtNWExLDEsMCwwLDAsLjIxLS4zM0ExLDEsMCwwLDAsMTcuOTIsMTEuNjJaIiBmaWxsPSIjNjU2M2ZmIi8+PC9zdmc+'); } + +/* Flex grid (footer) */ +.footer { display:flex; flex-direction:row; } +.footer-grid { flex:1; width:50%; } +.footer-grid:first-child { margin-right:20px; } +.footer-grid:nth-child(2) { text-align:right; } + /* Footer */ -.footer { background-color:var(--background-alt); color:var(--text-alt); border-top:2px solid var(--color-accent); font-size:.9rem; } +.footer { box-sizing:border-box; bottom:0; margin-top:auto; padding:10px 5px; width:100%; background-color:var(--background-alt); color:var(--text-alt); border-top:2px solid var(--color-accent); font-size:.9rem; } .footer a { color:var(--text-alt); } +/* MPA rating colors */ +.mpa-g { color:#518257; } +.mpa-pg { color:#EB984E; } +.mpa-pg13 { color:#8E44AD; } +.mpa-r { color:#C0392B; } +.mpa-nc17 { color:#1A5276; } + +/* Tooltips */ +.tooltip { position:relative; display:inline-block; } +.tooltip-question::before { content:""; display:inline-block; width:1.1em; height:1.1em; background:var(--link); vertical-align:text-bottom; mask-image:url('data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/Pjxzdmcgdmlld0JveD0iMCAwIDI0IDI0IiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjxwYXRoIGQ9Ik0xMS4yOSwxNS4yOWExLjU4LDEuNTgsMCwwLDAtLjEyLjE1Ljc2Ljc2LDAsMCwwLS4wOS4xOC42NC42NCwwLDAsMC0uMDYuMTgsMS4zNiwxLjM2LDAsMCwwLDAsLjIuODQuODQsMCwwLDAsLjA4LjM4LjkuOSwwLDAsMCwuNTQuNTQuOTQuOTQsMCwwLDAsLjc2LDAsLjkuOSwwLDAsMCwuNTQtLjU0QTEsMSwwLDAsMCwxMywxNmExLDEsMCwwLDAtLjI5LS43MUExLDEsMCwwLDAsMTEuMjksMTUuMjlaTTEyLDJBMTAsMTAsMCwxLDAsMjIsMTIsMTAsMTAsMCwwLDAsMTIsMlptMCwxOGE4LDgsMCwxLDEsOC04QTgsOCwwLDAsMSwxMiwyMFpNMTIsN0EzLDMsMCwwLDAsOS40LDguNWExLDEsMCwxLDAsMS43MywxQTEsMSwwLDAsMSwxMiw5YTEsMSwwLDAsMSwwLDIsMSwxLDAsMCwwLTEsMXYxYTEsMSwwLDAsMCwyLDB2LS4xOEEzLDMsMCwwLDAsMTIsN1oiIGZpbGw9IiM2NTYzZmYiLz48L3N2Zz4='); } +.tooltip-alert::before { content:""; display:inline-block; width:1.1em; height:1.1em; background:var(--link); vertical-align:text-bottom; mask-image:url('data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/Pjxzdmcgdmlld0JveD0iMCAwIDI0IDI0IiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjxwYXRoIGQ9Ik0xMiwxNmExLDEsMCwxLDAsMSwxQTEsMSwwLDAsMCwxMiwxNlptMTAuNjcsMS40Ny04LjA1LTE0YTMsMywwLDAsMC01LjI0LDBsLTgsMTRBMywzLDAsMCwwLDMuOTQsMjJIMjAuMDZhMywzLDAsMCwwLDIuNjEtNC41M1ptLTEuNzMsMmExLDEsMCwwLDEtLjg4LjUxSDMuOTRhMSwxLDAsMCwxLS44OC0uNTEsMSwxLDAsMCwxLDAtMWw4LTE0YTEsMSwwLDAsMSwxLjc4LDBsOC4wNSwxNEExLDEsMCwwLDEsMjAuOTQsMTkuNDlaTTEyLDhhMSwxLDAsMCwwLTEsMXY0YTEsMSwwLDAsMCwyLDBWOUExLDEsMCwwLDAsMTIsOFoiIGZpbGw9IiM2NTYzZmYiLz48L3N2Zz4='); } +.tooltip .tooltiptext { visibility:hidden; position:absolute; padding:10px 15px; width:350px; background:var(--background-popup); border:1px solid var(--border); border-radius:10px; z-index: 10000; } +.tooltip:hover .tooltiptext { visibility:visible; } + /* Misc */ .goosle-g { color:var(--color-accent); } .green { color:var(--green); } @@ -163,6 +194,9 @@ div.title, div.description, div.text, div.url, div.source { word-wrap:break-word .yellow { color:var(--yellow); } .star { font-weight:800; } img.help { padding:0 .5rem .5rem 0; float:left; border-radius:20px; } +.text-xxl { font-size:8em; } +.text-xl { font-size:3em; } +.text-center { text-align:center; } .warning { position:relative; overflow:hidden; margin:20px 0; padding:10px; color:var(--warning); background-color:var(--warning-background); border:1px solid var(--warning); border-radius:10px; } .error { position:relative; overflow:hidden; margin:20px 0; padding:10px; color:var(--error); background-color:var(--error-background); border:1px solid var(--error); border-radius:10px; } .auth-success { margin-top:15%; text-align:center; color:var(--text-alt); } @@ -170,10 +204,7 @@ img.help { padding:0 .5rem .5rem 0; float:left; border-radius:20px; } a.update { color:var(--red); font-weight:600; } @media only screen and (max-width:960px) { /* Tablet, landscape iPad, lo-res/smaller laptops */ - /* Page structure */ - .header form { margin:15px 0 0 0; } .content { position:relative; margin:15px 48px; } - .footer-left, .footer-right { display:block; text-align:center; } /* Start page */ .startpage .content { margin-top:0; } @@ -183,6 +214,7 @@ a.update { color:var(--red); font-weight:600; } /* Page header (Search results, Help, Box office) */ .header { margin-left:auto; margin-right:auto; text-align:center; } + .header form { margin:15px 0 0 0; } .header .logo { position:relative; display:block; margin:10px auto; float:none; font-size:1.8rem; } .header .search-field { margin:10px 0 28px 48px; width:400px; } .header .search-field, .header .button { margin:10px 0 28px 0; } @@ -192,26 +224,26 @@ a.update { color:var(--red); font-weight:600; } /* Magnet highlight info popup */ .goosebox-body { margin:25px auto; width:75%; } - /* Box Office */ - .grid-container { flex-direction:column; } - .list-grid:first-child, .footer-grid:first-child { margin-right:0; } - .list-grid { width:100%; } + /* Footer */ + .footer { flex-direction:column; } + .footer-left, .footer-right { display:block; text-align:center; } .footer-grid, .footer-grid:nth-child(2) { width:100%; text-align:center; } } @media only screen and (max-width:640px) { /* Portrait tablets, portrait iPad, landscape e-readers, landscape 800x480 or 854x480 phones */ - /* Page structure */ - .header form { margin:15px 0 10px 0; } .content { position:relative; margin:10px 10px; } /* Page header (Search results, Help, Box office) */ + .header form { margin:15px 0 10px 0; } .header .search-field, .header .button { margin:0 0 10px 0; width:80%; border-radius:25px; } /* Grids (image and magnet highlights) */ @supports (display:grid) { - .result-grid ul { grid-gap:0.75rem; } + .result-grid { grid-template-columns:repeat(auto-fill, minmax(8rem, 1fr)); row-gap:.5rem; column-gap:.5rem; } } + .result-grid .result.image .thumb, .result-grid .result.highlight .thumb { width:120px; height: 120px; } + /* Magnet highlight info popup */ .goosebox-body { margin:15px auto; width:90%; } diff --git a/assets/images/goosle-nobg.webp b/assets/images/goosle-nobg.webp new file mode 100644 index 0000000..b56be16 Binary files /dev/null and b/assets/images/goosle-nobg.webp differ diff --git a/box-office.php b/box-office.php index f5a74ec..9a2b500 100644 --- a/box-office.php +++ b/box-office.php @@ -1,20 +1,4 @@ user_auth; /* ------------------------------------------------------------------------------------ * Goosle - The fast, privacy oriented search tool that just works. * @@ -25,6 +9,17 @@ $auth = (isset($_GET['a'])) ? sanitize($_GET['a']) : $opts->user_auth; * By using this code you agree to indemnify Arnan de Gans from any * liability that might arise from its use. ------------------------------------------------------------------------------------ */ + +if(!defined('ABSPATH')) define('ABSPATH', $_SERVER['DOCUMENT_ROOT'] . '/'); +date_default_timezone_set('UTC'); + +require ABSPATH.'functions/tools.php'; +require ABSPATH.'functions/tools-magnet.php'; +require ABSPATH.'engines/boxoffice/yts.php'; +require ABSPATH.'engines/boxoffice/eztv.php'; + +$opts = load_opts(); +$search = load_search(); ?> @@ -37,7 +32,7 @@ $auth = (isset($_GET['a'])) ? sanitize($_GET['a']) : $opts->user_auth; - + @@ -55,30 +50,30 @@ $auth = (isset($_GET['a'])) ? sanitize($_GET['a']) : $opts->user_auth; hash_auth, $opts->hash, $auth)) { +if(verify_hash($opts->hash_auth, $opts->hash, $opts->user_auth)) { ?>
-

Goosle

- " name="q" /> +

Goosle

+ " name="q" /> - - + +
@@ -86,156 +81,76 @@ if(verify_hash($opts->hash_auth, $opts->hash, $auth)) {

The Box Office

-
-

Click on any movie poster for more information and available download links. All other results are direct download links.

+

Click on any movie poster for more information and available download links.

-

Recently added movies on YTS

+

Recently added movies on YTS

+ + - echo ""; - - unset($highlight, $thumb, $magnet); - } - unset($highlights); - ?> - -
- -
- -
-

Newest downloads on ThePirateBay

-
    - "; - echo ""; - echo "
    Seeds: ".$highlight['seeders']." - Peers: ".$highlight['leechers']." - Size: ".human_filesize($highlight['filesize'])."
    Category: ".$highlight['category']."
    "; - echo ""; - - unset($highlight); - } - ?> -
-
- -
-

Newest downloads on Nyaa

-
    - "; - echo ""; - echo "
    Seeds: ".$highlight['seeders']." - Peers: ".$highlight['leechers']." - Size: ".human_filesize($highlight['filesize'])."
    Category: ".$highlight['category']."
    "; - echo ""; - - unset($highlight); - } - ?> -
-
- -
- -
Goosle does not index, offer or distribute torrent files.
+

Goosle does not index, offer or distribute torrent files.

-Goosle"; -} -?> + +
Redirecting
+ + + \ No newline at end of file diff --git a/config.default.php b/config.default.php index cd41f21..db67e11 100644 --- a/config.default.php +++ b/config.default.php @@ -23,86 +23,87 @@ COLORSCHEME: 'auto' Let the browser decide what to use, uses dark.css for Darkmode. default.css for regular viewing. For advanced users: You can create your own colorschemes this way too. - Name the file something like 'mycolorscheme.css', place it in /assets/css/ and use the keyword 'mycolorscheme' in this setting for it to work. + Duplicate the file /assets/css/default.css and name it something like 'mycolorscheme.css'. + Edit the color variables to your liking. + To use the colorscheme, use the filename without extension in this setting. HASH: - A simple lowercase passphrase, something simple like: j9fg-i2du-er6m or 1846. - Used for caching results and optionally for accessing Goosle (See HASH_AUTH option). + A simple lowercase passphrase, something simple like: goose1234 or 1846. + Used for caching search results and optionally for accessing Goosle (See HASH_AUTH option). HASH_AUTH: - Use the above hash as a simple passphrase. + Use the HASH option as a simple passphrase. Using a passphrase lets you host Goosle on a public facing server without providing a public service. This is useful for if just you and some friends or family should be able to use Goosle from anywhere. 'off' Don't use the hash as a password. 'on' Use the hash as a password. - Usage: https://example.com/?a=j9fg-i2du-er6m + Usage: https://example.com/?a=goose1234 Disclaimer: This is not meant to 'hack proof' or truly secure the setup. Just a simple token to keep surface level prying eyes out. CACHE_TYPE: It is highly recommended to enable caching as it will speed up repeat searches by a lot. The cache is NOT unique per user but shared between all users. Different users searching for the exact same thing get the same results. + Results loaded from the cache are much much faster to load. Caching can be done in memory with APCu or as temporary files in the /cache/ folder. + Enabling caching also enables pagination for search results. 'off' No caching. 'file' Store results in text files (Default). - 'apcu' Faster, utilizes memory. + 'apcu' Faster, requires more memory. CACHE_TIME: - APCu stores in memory, using a longer cache time takes up more of it. It is recommended to not exceed a few hours for APCu. + APCu stores in memory, using a longer cache time takes up more of it. It is recommended to not exceed a few (1 or 2?) hours for APCu. The file cache is only limited by your hosting storage space and can safely be much much longer if you want. To not show outdated results the 'limit' is 48 hours. Ignored if above 'CACHE_TYPE' option is set to off. /* ------------------------------------------------------------------------------------ LANGUAGE: To not fit the USA mold, Goosle defaults to the United Kingdom for english results. - DuckDuckGo and Google are mostly language agnostic. - Invalid values either cause the search to fail or will default to English depending on how wrong the value is. + DuckDuckGo and Google are language agnostic. + Invalid values either cause the search engine to fail or will default to English depending on how wrong the value is. Google has no language setting because as soon as you specify it all 'anonymous' settings stop working. - DuckDuckGo uses language regions and defaults to the United Kingdom. To change it see if your region is available - https://duckduckgo.com/duckduckgo-help-pages/settings/params/. - Wikipedia needs to be told which language you want. This changes the search url. Use any of their supported languages (en, es, fr, nl, etc.) Qwant uses a locale similar to DuckDuckGo and defaults to the United Kingdom as well. Available locales are: bg_bg, br_fr, ca_ad, ca_es, ca_fr, co_fr, cs_cz, cy_gb, da_dk, de_at, de_ch, de_de, ec_ca, el_gr, en_au, en_ca, en_gb, en_ie, en_my, en_nz, en_us, es_ad, es_ar, es_cl, es_co, es_es, es_mx, es_pe, et_ee, eu_es, eu_fr, fc_ca, fi_fi, fr_ad, fr_be, fr_ca, fr_ch, fr_fr, gd_gb, he_il, hu_hu, it_ch, it_it, ko_kr, nb_no, nl_be, nl_nl, pl_pl, pt_ad, pt_pt, ro_ro, sv_se, th_th, zh_cn, zh_hk. SOCIAL MEDIA RELEVANCE: - Show social media results lower in the combined results if you don't value such results. - Downranked results include websites like Facebook, Instagram, Twitter, Snapchat, TikTok, LinkedIn and Reddit. + Show social media results lower in results if you don't value such results. + This includes websites like Facebook, Instagram, Twitter/X, Snapchat, TikTok, LinkedIn and Reddit. !! CAREFUL !! This is a blanket setting, if what (or who) you're searching for primarily has social media links then less relevant results may show first. Accepts a numeric value between 1 and 10. With 10 having *NO* effect on the rank, and 0 not ranking the link at all (shows very very low in the results). /* ------------------------------------------------------------------------------------ USER AGENTS: Add more or less user agents to the list but keep at least one! - On every search Goosle picks one at random to identify as. + On every search Goosle picks a user agent at random to identify as. Keep them generic to prevent profiling, but also so that the request comes off as a generic boring browser and not as a server/crawler. Safari, Firefox and Internet Explorer (Yes that's old!) should be safe to use. Chrome may attract attention because of the lack of Chrome information (tracking) aside from the user agent. The search engine may know something is 'weird'. Opera/Edge/Brave and many others use Chrome under the hood and are not a good pick for that reason. - Mobile user agents may work, but some services like Wikipedia are a bit picky when it comes to answering API calls. - Mobile users generally do not use APIs, so they may block your search or show a trimmed version of results. + + Do not use user agents for mobile devices. Where possible Goosle explicitly tells the service it's a desktop computer to get a certain format for results. + Contradicting the request with a mobile user agent may get your banned. MAGNET TRACKERS: + Add more or less magnet trackers to the list but keep at least five or so! These are added to the magnet links Goosle creates by itself. Generally you do not need to change these. - Currently only The Pirate Bay, LimeTorrents and YTS use generated magnet links. - - You can add more or replace the existing ones if you know what you're doing. But keep at least one, preferably 3-5+. ------------------------------------------------------------------------------------ */ return (object) array( - 'siteurl' => 'example.com', // Make sure this is accurate + 'siteurl' => 'example.com', // Make sure this is accurate (ex. example.com, goosle.example.com, example.com/goosle/) 'colorscheme' => 'default', // Default colorscheme to use - 'hash' => 'j9fg-i2du-er6m', // Some kind of alphanumeric password-like string, used for caching and optionally for access to Goosle + 'hash' => '123456', // Some kind of alphanumeric password-like string, used for caching and optionally for access to Goosle 'hash_auth' => 'off', // Default: off 'cache_type' => 'file', // Default: file - 'cache_time' => 8, // Default: 8 (Hours) - 'timezone' => 'UTC', // Default: 'UTC (London. Enter UTC+1, UTC-6 etc. for your timezone) + 'cache_time' => 8, // Default: 8 (Hours), see the recommendations above. + 'timezone' => 'UTC', // Default: UTC (Enter UTC+1, UTC-6 etc. for your timezone - Find yours https://time.is/UTC) 'enable_duckduckgo' => 'on', // Default: on 'enable_google' => 'on', // Default: on @@ -110,7 +111,7 @@ return (object) array( 'enable_brave' => 'on', // Default: on 'enable_wikipedia' => 'on', // Default: on - 'enable_news_search' => 'on', // Default: on (Disables all news search regardless of settings for individual engines, results are mixed in with regular search) + 'enable_news_search' => 'on', // Default: on (Disables all news search regardless of settings for individual engines) 'enable_qwantnews' => 'on', // Default: on 'enable_yahoonews' => 'on', // Default: on 'enable_bravenews' => 'on', // Default: on @@ -118,7 +119,7 @@ return (object) array( 'enable_image_search' => 'on', // Default: on (Disables all image search regardless of settings for individual engines) 'enable_yahooimages' => 'on', // Default: on - 'enable_openverse' => 'off', // Default: off (Requires API token, see readme for details) + 'enable_openverse' => 'off', // Default: off (Requires API token, see readme.md for details) 'enable_qwantimages' => 'on', // Default: on 'enable_magnet_search' => 'on', // Default: on (Disables all magnet search regardless of settings for individual engines as well as the box office page) @@ -133,25 +134,29 @@ return (object) array( 'wikipedia_language' => 'en', // Default: en (English) 'qwant_language' => 'en_gb', // Default: en_gb (United Kingdom) + 'search_results_per_page' => 24, // Default: 24 (Any number between 8 and 160, preferably a multiple of 8. Ignored if caching is off) 'social_media_relevance' => 8, // Default: 8 'show_search_source' => 'on', // Default: on - 'show_search_rank' => 'off', // Default: off - 'imdb_id_search' => 'off', // Default: off, Requires Magnet search to also be on + 'show_search_rank' => 'off', // Default: off (Mostly for debugging) + 'imdb_id_search' => 'off', // Default: off, (Requires enable_magnet_search to also be on) 'password_generator' => 'on', // Default: on 'special' => array( 'currency' => 'on', // Default: on, Currency converter 'definition' => 'on', // Default: on, Word dictionary 'ipaddress' => 'on', // Default: on, Look up your IP Address - 'phpnet' => 'on', // Default: on, PHP-dot-net highlight + 'phpnet' => 'on', // Default: on, PHP-dot-net functions highlight + 'wordpress' => 'off' // Default: off, Wordpress functions highlight ), + 'show_nsfw_magnets' => 'off', // Default: off (Set to 'off' to try and hide adult content. Override with 'safe:off', 'xxx' or 'porn') 'show_zero_seeders' => 'off', // Default: off 'show_yts_highlight' => 'on', // Default: off (Show latest YTS movies above Magnet search results) 'show_share_option' => 'on', // Default: on (Show a share option for Magnet results) 'piratebay_categories_blocked' => array(206, 210), // Default: 206, 210 (Comma separated numbers, see /engines/magnet/thepiratebay.php for all categories) - 'yts_categories_blocked' => array('horror'), // Default: 'horror' (Comma separated keywords; 'action', 'drama', 'sci-fi' etc.. There is no defined list, so block keywords that you see and don't like) + 'yts_categories_blocked' => array('horror'), // Default: 'horror' (Comma separated keywords; array('action', 'drama', 'sci-fi') etc.. There is no defined list, so block keywords that you see on results and don't like) + // Keep at-least 1 'user_agents' => array( 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15) Gecko/20100101 Firefox/119.0', // macOS 10.15, Firefox 119 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) Gecko/20100101 Firefox/116.0', // Windows 10, Firefox 116 @@ -159,7 +164,15 @@ return (object) array( 'Mozilla/5.0 (X11; Linux i686) Gecko/20100101 Firefox/119.0', // Linux Generic, Firefox 119 ), + // Keep at-least 5 'magnet_trackers' => array( + 'udp://tracker.coppersurfer.tk:6969', + 'udp://tracker.leechers-paradise.org:6969', + 'udp://p4p.arenabg.ch:1337', + 'udp://tracker.internetwarriors.net:1337', + 'udp://glotorrents.pw:6969/announce', + 'udp://torrent.gresille.org:80/announce', + 'udp://tracker.openbittorrent.com:80', 'http://nyaa.tracker.wf:7777/announce', 'udp://tracker.opentrackr.org:1337/announce', 'udp://exodus.desync.com:6969/announce', diff --git a/engines/boxoffice/eztv.php b/engines/boxoffice/eztv.php index 605b9b1..0bf9532 100644 --- a/engines/boxoffice/eztv.php +++ b/engines/boxoffice/eztv.php @@ -33,28 +33,30 @@ function eztv_boxoffice($opts) { if($json_response['torrents_count'] == 0) return $results; foreach($json_response['torrents'] as $result) { - $name = sanitize($result['title']); - $hash = strtolower(sanitize($result['hash'])); - $thumbnail = sanitize($result['small_screenshot']); - $magnet_link = sanitize($result['magnet_url']); - $filesize = sanitize($result['size_bytes']); + $title = (!empty($result['title'])) ? sanitize($result['title']) : null; + $year = (!empty($result['date_released_unix'])) ? gmdate('Y', sanitize($result['date_released_unix'])) : null; + $hash = (!empty($result['hash'])) ? strtolower(sanitize($result['hash'])) : null; + $thumbnail = (!empty($result['small_screenshot'])) ? sanitize($result['small_screenshot']) : null; + $magnet_link = (!empty($result['magnet_url'])) ? sanitize($result['magnet_url']) : null; + $filesize = (!empty($result['size_bytes'])) ? sanitize($result['size_bytes']) : null; // Get extra data - $quality = find_video_quality($name); - $codec = find_video_codec($name); + $quality = find_video_quality($title); + $codec = find_video_codec($title); + $audio = find_audio_codec($title); // Add codec to quality if(!empty($codec)) $quality = $quality.' '.$codec; // Clean up show name - $name = (preg_match('/.+?(?=[0-9]{3,4}p|xvid|divx|(x|h)26(4|5))/i', $name, $clean_name)) ? $clean_name[0] : $name; // Break off show name before video resolution - $name = trim(str_replace(array('S0E0', 'S00E00'), '', $name)); // Strip spaces and empty season/episode indicator from name + $title = (preg_match('/.+?(?=[0-9]{3,4}p|xvid|divx|(x|h)26(4|5))/i', $title, $clean_name)) ? $clean_name[0] : $title; // Break off show name before video resolution + $title = trim(str_replace(array('S0E0', 'S00E00'), '', $title)); // Strip spaces and empty season/episode indicator from name // Group the same episodes in one result if(count($results) > 0) { // Do a match - $result_urls = array_column($results, 'name', 'id'); - $found_id = array_search($name, $result_urls); // Return the result ID + $result_urls = array_column($results, 'title', 'id'); + $found_id = array_search($title, $result_urls); // Return the result ID } else { $found_id = false; } @@ -65,25 +67,28 @@ function eztv_boxoffice($opts) { 'hash' => $hash, 'magnet' => $magnet_link, 'filesize' => $filesize, - 'quality' => $quality + 'quality' => $quality, + 'audio' => $audio ); } else { - $result_id = md5($name); // Predictable/repeatable 'unique' string + $result_id = md5($title); // Predictable/repeatable 'unique' string, can't be md5($hash) other nothing will match/merge! // First/new result $results[$result_id] = array ( 'id' => $result_id, // string - 'name' => $name, // string + 'title' => $title, // string + 'year' => $year, // int(4) 'thumbnail' => $thumbnail, // string - 'magnet_links' => array(array( // Yes, two array... + 'magnet_links' => array(array( // Yes, two array (For merging results)... 'hash' => $hash, // string 'magnet' => $magnet_link, // string 'filesize' => $filesize, // int 'quality' => $quality, // string + 'audio' => $audio // string )) ); } - unset($result, $result_urls, $found_id, $result_id, $name, $hash, $thumbnail, $magnet_link, $quality, $codec); + unset($result, $result_urls, $found_id, $result_id, $title, $hash, $thumbnail, $magnet_link, $quality, $codec); } unset($response, $json_response); diff --git a/engines/boxoffice/nyaa.php b/engines/boxoffice/nyaa.php deleted file mode 100644 index 17b9987..0000000 --- a/engines/boxoffice/nyaa.php +++ /dev/null @@ -1,83 +0,0 @@ -cache_type !== 'off' && has_cached_results($opts->cache_type, $opts->hash, $api_url, $opts->cache_time)) { - return fetch_cached_results($opts->cache_type, $opts->hash, $api_url); - } - - $response = do_curl_request( - $api_url, // (string) Where? - array('Accept: text/html, application/xhtml+xml, application/xml;q=0.8, */*;q=0.7', 'User-Agent: '.$opts->user_agents[0].';'), // (array) User agent + Headers - 'get', // (string) post/get - null // (assoc array|null) Post body - ); - $xpath = get_xpath($response); - $results = array(); - - // No response - if(!$xpath) return $results; - - // Scrape the results - $limit = $amount + 16; - $scrape = $xpath->query("//tbody/tr[position() <= $limit]"); - - // No results - if(count($scrape) == 0) return $results; - - foreach($scrape as $result) { - $meta = $xpath->evaluate(".//td[@class='text-center']", $result); - - $name = $xpath->evaluate(".//td[@colspan='2']//a[not(contains(@class, 'comments'))]/@title", $result); - if($name->length == 0) continue; - - $magnet = $xpath->evaluate(".//a[2]/@href", $meta[0]); - if($magnet->length == 0) $magnet = $xpath->evaluate(".//a/@href", $meta[0]); - if($magnet->length == 0) continue; - - $name = sanitize($name[0]->textContent); - $magnet = sanitize($magnet[0]->textContent); - parse_str(parse_url($magnet, PHP_URL_QUERY), $hash_parameters); - $hash = strtolower(str_replace('urn:btih:', '', $hash_parameters['xt'])); - $seeders = sanitize($meta[3]->textContent); - $leechers = sanitize($meta[4]->textContent); - $filesize = filesize_to_bytes(str_replace('TiB', 'TB', str_replace('GiB', 'GB', str_replace('MiB', 'MB', str_replace('KiB', 'KB', sanitize($meta[1]->textContent)))))); - $category = sanitize($xpath->evaluate(".//td[1]//a/@title", $result)[0]->textContent); - $category = str_replace(' - ', '/', $category); - - $results[] = array ( - 'id' => uniqid(rand(0, 9999)), // Semi random string to separate results on the results page - 'name' => $name, // string - 'magnet' => $magnet, // string - 'seeders' => $seeders, // int - 'leechers' => $leechers, // int - 'filesize' => $filesize, // int - 'category' => $category, // string - ); - - unset($result, $meta, $name, $magnet, $seeders, $leechers, $filesize, $category); - } - unset($response, $xpath, $scrape, $limit); - - $results = array_slice($results, 0, $amount); - - // Cache last request if there is something to cache - if($opts->cache_type !== 'off') { - if(count($results) > 0) store_cached_results($opts->cache_type, $opts->hash, $api_url, $results, $opts->cache_time); - } - - return $results; -} -?> \ No newline at end of file diff --git a/engines/boxoffice/thepiratebay.php b/engines/boxoffice/thepiratebay.php deleted file mode 100644 index 8c91814..0000000 --- a/engines/boxoffice/thepiratebay.php +++ /dev/null @@ -1,134 +0,0 @@ -cache_type !== 'off' && has_cached_results($opts->cache_type, $opts->hash, $api_url, $opts->cache_time)) { - return fetch_cached_results($opts->cache_type, $opts->hash, $api_url); - } - - $response = do_curl_request( - $api_url, // (string) Where? - array('Accept: application/json, */*;q=0.7', 'User-Agent: '.$opts->user_agents[0].';'), // (array) User agent + Headers - 'get', // (string) post/get - null // (assoc array|null) Post body - ); - $json_response = json_decode($response, true); - $results = array(); - - // No response - if(empty($json_response)) return $results; - - // No results - if($json_response[0]['name'] == 'No results returned') return $results; - - $categories = array( - 100 => 'Audio', - 101 => 'Music', - 102 => 'Audio Book', - 103 => 'Sound Clips', - 104 => 'Audio FLAC', - 199 => 'Audio Other', - - 200 => 'Video', - 201 => 'Movie', - 202 => 'Movie DVDr', - 203 => 'Music Video', - 204 => 'Movie Clip', - 205 => 'TV Show', - 206 => 'Handheld', - 207 => 'HD Movie', - 208 => 'HD TV Show', - 209 => '3D Movie', - 210 => 'CAM/TS', - 211 => 'UHD/4K Movie', - 212 => 'UHD/4K TV Show', - 299 => 'Video Other', - - 300 => 'Applications', - 301 => 'Apps Windows', - 302 => 'Apps Apple', - 303 => 'Apps Unix', - 304 => 'Apps Handheld', - 305 => 'Apps iOS', - 306 => 'Apps Android', - 399 => 'Apps Other OS', - - 400 => 'Games', - 401 => 'Games PC', - 402 => 'Games Apple', - 403 => 'Games PSx', - 404 => 'Games XBOX360', - 405 => 'Games Wii', - 406 => 'Games Handheld', - 407 => 'Games iOS', - 408 => 'Games Android', - 499 => 'Games Other OS', - - 500 => 'Porn', - 501 => 'Porn Movie', - 502 => 'Porn Movie DVDr', - 503 => 'Porn Pictures', - 504 => 'Porn Games', - 505 => 'Porn HD Movie', - 506 => 'Porn Movie Clip', - 507 => 'Porn UHD/4K Movie', - 599 => 'Porn Other', - - 600 => 'Other', - 601 => 'Other E-Book', - 602 => 'Other Comic', - 603 => 'Other Pictures', - 604 => 'Other Covers', - 605 => 'Other Physibles', - 699 => 'Other Other' - ); - - foreach($json_response as $result) { - $name = sanitize($result['name']); - $hash = strtolower(sanitize($result['info_hash'])); - $magnet = 'magnet:?xt=urn:btih:'.$hash.'&dn='.urlencode($name).'&tr='.implode('&tr=', $opts->magnet_trackers); - $seeders = sanitize($result['seeders']); - $leechers = sanitize($result['leechers']); - $filesize = sanitize($result['size']); - $category = sanitize($result['category']); - - // Block these categories - if(in_array($category, $opts->piratebay_categories_blocked)) continue; - // Set actual category - $category = $categories[$category]; - - $results[] = array( - 'id' => uniqid(rand(0, 9999)), // Semi random string to separate results on the results page - 'name' => $name, // string - 'magnet' => $magnet, // string - 'seeders' => $seeders, // int - 'leechers' => $leechers, // int - 'filesize' => $filesize, // int - 'category' => $category // string - ); - - unset($result, $name, $magnet, $seeders, $leechers, $filesize, $category); - } - unset($response, $json_response, $categories); - - $results = array_slice($results, 0, $amount); - - // Cache last request if there is something to cache - if($opts->cache_type !== 'off') { - if(count($results) > 0) store_cached_results($opts->cache_type, $opts->hash, $api_url, $results, $opts->cache_time); - } - - return $results; -} -?> \ No newline at end of file diff --git a/engines/boxoffice/yts.php b/engines/boxoffice/yts.php index 70d9b47..c3b5f30 100644 --- a/engines/boxoffice/yts.php +++ b/engines/boxoffice/yts.php @@ -33,53 +33,69 @@ function yts_boxoffice($opts, $what) { if($json_response['data']['movie_count'] == 0) return $results; foreach($json_response['data']['movies'] as $result) { - $name = sanitize($result['title']); + $title = sanitize($result['title']); - $year = (array_key_exists('year', $result)) ? sanitize($result['year']) : 0; - $category = (array_key_exists('genres', $result)) ? $result['genres'] : array(); - $rating = (array_key_exists('rating', $result)) ? sanitize($result['rating']) : 0; - $summary = (array_key_exists('summary', $result)) ? sanitize($result['summary']) : "No summary provided"; - $thumbnail = (array_key_exists('medium_cover_image', $result)) ? sanitize($result['medium_cover_image']) : ""; + $year = (!empty($result['year'])) ? sanitize($result['year']) : 0; + $category = (!empty($result['genres'])) ? $result['genres'] : null; + $language = (!empty($result['language'])) ? sanitize($result['language']) : null; + $rating = (!empty($result['rating'])) ? sanitize($result['rating']) : null; + $mpa_rating = (!empty($result['mpa_rating'])) ? sanitize($result['mpa_rating']) : null; + $summary = (!empty($result['summary'])) ? sanitize($result['summary']) : null; + if(is_null($summary)) $summary = (!empty($result['synopsis'])) ? sanitize($result['synopsis']) : "No summary provided"; + $thumbnail = (!empty($result['medium_cover_image'])) ? sanitize($result['medium_cover_image']) : null; + if(is_null($thumbnail)) $thumbnail = (!empty($result['small_cover_image'])) ? sanitize($result['small_cover_image']) : ""; - // Block these categories - if(count(array_uintersect($category, $opts->yts_categories_blocked, 'strcasecmp')) > 0) continue; - // Set actual category - $category = sanitize(implode(', ', $category)); + // Process extra data + if(is_array($category)) { + // Block these categories + if(count(array_uintersect($category, $opts->yts_categories_blocked, 'strcasecmp')) > 0) continue; + + // Set actual category + $category = sanitize(implode(', ', $category)); + } foreach($result['torrents'] as $download) { $hash = strtolower(sanitize($download['hash'])); - $magnet = 'magnet:?xt=urn:btih:'.$hash.'&dn='.urlencode($name).'&tr='.implode('&tr=', $opts->magnet_trackers); + $magnet = 'magnet:?xt=urn:btih:'.$hash.'&dn='.urlencode($title).'&tr='.implode('&tr=', $opts->magnet_trackers); $filesize = filesize_to_bytes(sanitize($download['size'])); - $type = (array_key_exists('type', $download)) ? sanitize(strtolower($download['type'])) : null; - $quality = (array_key_exists('quality', $download)) ? sanitize($download['quality']) : null; - $codec = (array_key_exists('video_codec', $download)) ? sanitize($download['video_codec']) : null; + $type = (!empty($download['type'])) ? sanitize(strtolower($download['type'])) : null; + $quality = (!empty($download['quality'])) ? sanitize($download['quality']) : null; + $codec = (!empty($download['video_codec'])) ? sanitize($download['video_codec']) : null; + $bitrate = (!empty($download['bit_depth'])) ? sanitize($download['bit_depth']) : null; + $audio = (!empty($download['audio_channels'])) ? sanitize('AAC '.$download['audio_channels']) : null; - // Add codec to quality + // Add codec and bitrate to quality if(!empty($codec)) $quality = $quality.' '.$codec; - + if(!empty($bitrate)) $quality = $quality.' '.$bitrate.'bit'; + $downloads[] = array ( 'hash' => $hash, 'magnet' => $magnet, 'filesize' => $filesize, 'type' => $type, - 'quality' => $quality + 'quality' => $quality, + 'audio' => $audio ); - unset($download, $hash, $magnet, $filesize, $type, $quality, $codec); + unset($download, $hash, $magnet, $filesize, $type, $quality, $codec, $bitrate, $audio); } - $results[] = array ( - 'id' => uniqid(rand(0, 9999)), // Semi random string to separate results on the results page - 'name' => $name, // string + $result_id = md5($title); + + $results[$result_id] = array ( + 'id' => $result_id, // Semi random string to separate results + 'title' => $title, // string 'year' => $year, // int(4) - 'category' => $category, // string - 'rating' => $rating, // float|int + 'category' => $category, // string|null + 'language' => $language, // string|null + 'rating' => $rating, // float|null + 'mpa_rating' => $mpa_rating, // string|null 'summary' => $summary, // string 'thumbnail' => $thumbnail, // string|empty 'magnet_links' => $downloads // array ); - unset($result, $name, $thumbnail, $year, $category, $rating, $url, $summary, $downloads); + unset($result, $title, $thumbnail, $year, $category, $language, $rating, $url, $summary, $downloads); } unset($response, $json_response); diff --git a/engines/image/openverse.php b/engines/image/openverse.php index 5385143..3ea8bbd 100644 --- a/engines/image/openverse.php +++ b/engines/image/openverse.php @@ -11,28 +11,21 @@ ------------------------------------------------------------------------------------ */ class OpenverseRequest extends EngineRequest { public function get_request_url() { - $query = str_replace('%22', '\"', $this->query); - // Safe search override - $safe = '0'; // No mature results - if(preg_match('/(safe:)(on|off)/i', $query, $matches)) { - if($matches[2] == 'on') $safe = '0'; - if($matches[2] == 'off') $safe = '1'; - $query = str_replace($matches[0], '', $query); + if($this->search->safe == 0) { + $safe = '1'; + } else { + $safe = '0'; } - unset($matches); - - // Is there no query left? Bail! - if(empty($query)) return false; $url = 'https://api.openverse.org/v1/images/?'.http_build_query(array( - 'q' => $query, // Search query + 'q' => $this->search->query, // Search query 'format' => 'json', // Response format - 'mature' => $safe, // Safe search (1 = ON, 0 = OFF) - 'page_size' => 50 // How many results to get + 'page_size' => 50, // How many results to get + 'mature' => $safe // Safe search (1 = ON, 0 = OFF) )); - unset($query, $safe); + unset($safe); return $url; } @@ -108,10 +101,8 @@ class OpenverseRequest extends EngineRequest { } // Base info - $number_of_results = count($engine_temp); - if($number_of_results > 0) { + if(!empty($engine_temp)) { $engine_result['source'] = 'Openverse'; - $engine_result['amount'] = $number_of_results; $engine_result['search'] = $engine_temp; } diff --git a/engines/image/qwant-images.php b/engines/image/qwant-images.php index 79a571e..9910353 100644 --- a/engines/image/qwant-images.php +++ b/engines/image/qwant-images.php @@ -11,22 +11,13 @@ ------------------------------------------------------------------------------------ */ class QwantImageRequest extends EngineRequest { public function get_request_url() { - $query = str_replace('%22', '\"', $this->query); - - // Safe search override - $safe = '1'; // Moderate results - if(preg_match('/(safe:)(on|off)/i', $query, $matches)) { - if($matches[2] == 'on') $safe = '2'; - if($matches[2] == 'off') $safe = '0'; - $query = str_replace($matches[0], '', $query); - } - unset($matches); + $query = $this->search->query; // Size override $size = 'all'; // All sizes - if(preg_match('/(size:)(small|medium|large|xlarge)/i', $query, $matches)) { + if(preg_match('/(size:)(small|medium|large|xlarge)/i', $this->search->query_terms[0], $matches)) { $size = $matches[1]; - $query = str_replace($matches[0], '', $query); + $query = str_replace($this->search->query_terms[0], '', $query); // Engine specific if($size == 'xlarge') $size = 'large'; @@ -36,9 +27,7 @@ class QwantImageRequest extends EngineRequest { // Set locale $language = (strlen($this->opts->qwant_language) > 0 && strlen($this->opts->qwant_language < 6)) ? $this->opts->qwant_language : 'en_gb'; - // Is there no query left? Bail! - if(empty($query)) return false; - + // Based on https://github.com/locness3/qwant-api-docs and variables from qwant website $url = 'https://api.qwant.com/v3/search/images?'.http_build_query(array( 'q' => $query, // Search query 't' => 'images', // Type of search, Images @@ -46,10 +35,10 @@ class QwantImageRequest extends EngineRequest { 'size' => $size, // General image size 'locale' => $language, // In which language should the search be done 'device' => 'desktop', // What kind of device are we searching from? - 'safesearch' => $safe // Safe search filter (0 = off, 1 = normal, 2 = strict) + 'safesearch' => $this->search->safe // Safe search filter (0 = off, 1 = normal, 2 = strict) )); - unset($query, $safe, $size, $language); + unset($query, $size, $language); return $url; } @@ -117,10 +106,8 @@ class QwantImageRequest extends EngineRequest { } // Base info - $number_of_results = count($engine_temp); - if($number_of_results > 0) { + if(!empty($engine_temp)) { $engine_result['source'] = 'Qwant'; - $engine_result['amount'] = $number_of_results; $engine_result['search'] = $engine_temp; } diff --git a/engines/image/yahoo-images.php b/engines/image/yahoo-images.php index d5fc274..110b96b 100644 --- a/engines/image/yahoo-images.php +++ b/engines/image/yahoo-images.php @@ -11,31 +11,26 @@ ------------------------------------------------------------------------------------ */ class YahooImageRequest extends EngineRequest { public function get_request_url() { - $query = str_replace('%22', '\"', $this->query); + $query = $this->search->query; // Safe search override - $safe = ''; // No mature results - if(preg_match('/(safe:)(on|off)/i', $query, $matches)) { - if($matches[2] == 'on') $safe = ''; - if($matches[2] == 'off') $safe = '0'; - $query = str_replace($matches[0], '', $query); + if($this->search->safe == 0) { + $safe = '0'; + } else { + $safe = ''; } - unset($matches); // Size override $size = ''; // All sizes - if(preg_match('/(size:)(small|medium|large|xlarge)/i', $query, $matches)) { + if(preg_match('/(size:)(small|medium|large|xlarge)/i', $this->search->query_terms[0], $matches)) { $size = $matches[1]; - $query = str_replace($matches[0], '', $query); + $query = str_replace($this->search->query_terms[0], '', $query); // Engine specific if($size == 'xlarge') $size = 'wallpaper'; } unset($matches); - // Is there no query left? Bail! - if(empty($query)) return false; - $url = 'https://images.search.yahoo.com/search/images?'.http_build_query(array( 'p' => $query, // Search query 'imgsz' => $size, // Image size (small|medium|large|wallpaper) @@ -154,10 +149,8 @@ class YahooImageRequest extends EngineRequest { } // Base info - $number_of_results = count($engine_temp); - if($number_of_results > 0) { + if(!empty($engine_temp)) { $engine_result['source'] = 'Yahoo! Images'; - $engine_result['amount'] = $number_of_results; $engine_result['search'] = $engine_temp; } diff --git a/engines/magnet/eztv.php b/engines/magnet/eztv.php index 914907e..963e9a5 100644 --- a/engines/magnet/eztv.php +++ b/engines/magnet/eztv.php @@ -11,10 +11,7 @@ ------------------------------------------------------------------------------------ */ class EZTVRequest extends EngineRequest { public function get_request_url() { - $query = preg_replace('/[^0-9]+/', '', $this->query); - - // Is there no query left? Bail! - if(empty($query)) return false; + $query = preg_replace('/[^0-9]+/', '', $this->search->query); // Is eztvx.to blocked for you? Use one of these urls as an alternative // Try: eztv1.xyz, eztv.wf, eztv.tf, eztv.yt @@ -47,7 +44,7 @@ class EZTVRequest extends EngineRequest { if($json_response['torrents_count'] == 0) return $engine_temp; foreach($json_response['torrents'] as $result) { - $name = sanitize($result['title']); + $title = sanitize($result['title']); $hash = strtolower(sanitize($result['hash'])); $magnet = sanitize($result['magnet_url']); $seeders = sanitize($result['seeds']); @@ -64,48 +61,49 @@ class EZTVRequest extends EngineRequest { if($episode < 10) $episode = '0'.$episode; // Throw out mismatched episodes - if(!is_season_or_episode($this->query, 'S'.$season.'E'.$episode)) continue; + if(!is_season_or_episode($this->search->query, 'S'.$season.'E'.$episode)) continue; // Get extra data - $date_added = (array_key_exists('date_released_unix', $result)) ? timezone_offset($result['date_released_unix'], $this->opts->timezone) : null; - $quality = find_video_quality($name); - $codec = find_video_codec($name); - $audio = find_audio_codec($name); + $timestamp = (isset($result['date_released_unix'])) ? sanitize($result['date_released_unix']) : null; + $quality = find_video_quality($title); + $codec = find_video_codec($title); + $audio = find_audio_codec($title); // Add codec to quality if(!empty($codec)) $quality = $quality.' '.$codec; // Clean up show name - $name = (preg_match('/.+?(?=[0-9]{3,4}p)|xvid|divx|(x|h)26(4|5)/i', $name, $clean_name)) ? $clean_name[0] : $name; // Break off show name before video resolution - $name = str_replace(array('S0E0', 'S00E00'), '', $name); // Strip empty season/episode indicator from name + $title = (preg_match('/.+?(?=[0-9]{3,4}p)|xvid|divx|(x|h)26(4|5)/i', $title, $clean_name)) ? $clean_name[0] : $title; // Break off show name before video resolution + $title = str_replace(array('S0E0', 'S00E00'), '', $title); // Strip empty season/episode indicator from name $engine_temp[] = array ( // Required 'hash' => $hash, // string - 'name' => $name, // string + 'title' => $title, // string 'magnet' => $magnet, // string 'seeders' => $seeders, // int 'leechers' => $leechers, // int 'filesize' => $filesize, // int // Optional + 'nsfw' => false, // bool 'quality' => $quality, // string|null 'type' => null, // string|null 'audio' => $audio, // string|null 'runtime' => null, // int(timestamp)|null 'year' => null, // int(4)|null - 'date_added' => $date_added, // int(timestamp)|null + 'timestamp' => $timestamp, // int(timestamp)|null 'category' => null, // string|null + 'mpa_rating' => null, // string|null + 'language' => null, // string|null 'url' => null // string|null ); - unset($result, $season, $episode, $name, $hash, $magnet, $seeders, $leechers, $filesize, $quality, $codec, $date_added); + unset($result, $season, $episode, $title, $hash, $magnet, $seeders, $leechers, $filesize, $quality, $codec, $date_added); } // Base info - $number_of_results = count($engine_temp); - if($number_of_results > 0) { + if(!empty($engine_temp)) { $engine_result['source'] = 'EZTV'; - $engine_result['amount'] = $number_of_results; $engine_result['search'] = $engine_temp; } diff --git a/engines/magnet/lime.php b/engines/magnet/lime.php index c2830fb..31b7caa 100644 --- a/engines/magnet/lime.php +++ b/engines/magnet/lime.php @@ -11,13 +11,9 @@ ------------------------------------------------------------------------------------ */ class LimeRequest extends EngineRequest { public function get_request_url() { - $query = str_replace('%22', '\"', $this->query); - $query = preg_replace('/[^a-z0-9- ]+/', '', $query); + $query = preg_replace('/[^a-z0-9- ]+/', '', $this->search->query); $query = strtolower(str_replace(' ', '-', $query)); - // Is there no query left? Bail! - if(empty($query)) return false; - $url = 'https://www.limetorrents.lol/search/all/'.$query.'/'; unset($query); @@ -46,22 +42,22 @@ class LimeRequest extends EngineRequest { foreach($scrape as $result) { // Find data - $name = $xpath->evaluate(".//td[@class='tdleft']//a[2]", $result); + $title = $xpath->evaluate(".//td[@class='tdleft']//a[2]", $result); $hash = $xpath->evaluate(".//td[@class='tdleft']//a[1]/@href", $result); $seeders = $xpath->evaluate(".//td[@class='tdseed']", $result); $leechers = $xpath->evaluate(".//td[@class='tdleech']", $result); $filesize = $xpath->evaluate(".//td[@class='tdnormal'][2]", $result); // Skip broken results - if($name->length == 0) continue; + if($title->length == 0) continue; if($hash->length == 0) continue; // Process data - $name = sanitize($name[0]->textContent); + $title = sanitize($title[0]->textContent); $hash = sanitize($hash[0]->textContent); $hash = explode('/', substr($hash, 0, strpos($hash, '.torrent?'))); $hash = strtolower($hash[array_key_last($hash)]); - $magnet = 'magnet:?xt=urn:btih:'.$hash.'&dn='.urlencode($name).'&tr='.implode('&tr=', $this->opts->magnet_trackers); + $magnet = 'magnet:?xt=urn:btih:'.$hash.'&dn='.urlencode($title).'&tr='.implode('&tr=', $this->opts->magnet_trackers); $seeders = ($seeders->length > 0) ? sanitize($seeders[0]->textContent) : 0; $leechers = ($leechers->length > 0) ? sanitize($leechers[0]->textContent) : 0; $filesize = ($filesize->length > 0) ? human_filesize(filesize_to_bytes(sanitize($filesize[0]->textContent))) : 0; @@ -70,7 +66,7 @@ class LimeRequest extends EngineRequest { if($this->opts->show_zero_seeders == 'off' AND $seeders == 0) continue; // Throw out mismatched tv-show episodes when searching for tv shows - if(!is_season_or_episode($this->query, $name)) continue; + if(!is_season_or_episode($this->search->query, $title)) continue; // Find extra data $category = $xpath->evaluate(".//td[@class='tdnormal'][1]", $result); @@ -86,46 +82,48 @@ class LimeRequest extends EngineRequest { } $url = ($url->length > 0) ? 'https://www.limetorrents.lol'.sanitize($url[0]->textContent) : null; + // Find meta data for certain categories + $nsfw = (detect_nsfw($title)) ? true : false; $quality = $codec = $audio = null; if(in_array(strtolower($category), array('movies', 'tv shows', 'anime'))) { - $quality = find_video_quality($name); - $codec = find_video_codec($name); + $quality = find_video_quality($title); + $codec = find_video_codec($title); + $audio = find_audio_codec($title); // Add codec to quality if(!empty($codec)) $quality = $quality.' '.$codec; - } - - if(in_array(strtolower($category), array('music', 'movies', 'tv shows', 'anime'))) { - $audio = find_audio_codec($name); + } else if(in_array(strtolower($category), array('music'))) { + $audio = find_audio_codec($title); } $engine_temp[] = array ( // Required 'hash' => $hash, // string - 'name' => $name, // string + 'title' => $title, // string 'magnet' => $magnet, // string 'seeders' => $seeders, // int 'leechers' => $leechers, // int 'filesize' => $filesize, // int // Optional + 'nsfw' => $nsfw, // bool 'quality' => $quality, // string|null 'type' => null, // string|null 'audio' => $audio, // string|null 'runtime' => null, // int(timestamp)|null 'year' => null, // int(4)|null - 'date_added' => null, // int(timestamp)|null + 'timestamp' => null, // int(timestamp)|null 'category' => $category, // string|null + 'mpa_rating' => null, // string|null + 'language' => null, // string|null 'url' => $url // string|null ); - unset($result, $name, $hash, $magnet, $seeders, $leechers, $filesize, $quality, $codec, $audio, $category, $url); + unset($result, $title, $hash, $magnet, $seeders, $leechers, $filesize, $quality, $codec, $audio, $category, $url); } // Base info - $number_of_results = count($engine_temp); - if($number_of_results > 0) { + if(!empty($engine_temp)) { $engine_result['source'] = 'limetorrents.lol'; - $engine_result['amount'] = $number_of_results; $engine_result['search'] = $engine_temp; } diff --git a/engines/magnet/nyaa.php b/engines/magnet/nyaa.php index 43e0bf7..f2d2fab 100644 --- a/engines/magnet/nyaa.php +++ b/engines/magnet/nyaa.php @@ -11,14 +11,7 @@ ------------------------------------------------------------------------------------ */ class NyaaRequest extends EngineRequest { public function get_request_url() { - $query = str_replace('%22', '\"', $this->query); - - // Is there no query left? Bail! - if(empty($query)) return false; - - $url = 'https://nyaa.si/?q='.urlencode($query); - - unset($query); + $url = 'https://nyaa.si/?q='.urlencode($this->search->query); return $url; } @@ -45,16 +38,16 @@ class NyaaRequest extends EngineRequest { foreach($scrape as $result) { // Find data $meta = $xpath->evaluate(".//td[@class='text-center']", $result); - $name = $xpath->evaluate(".//td[@colspan='2']//a[not(contains(@class, 'comments'))]/@title", $result); + $title = $xpath->evaluate(".//td[@colspan='2']//a[not(contains(@class, 'comments'))]/@title", $result); $magnet = $xpath->evaluate(".//a[2]/@href", $meta[0]); // Skip broken results - if($name->length == 0) continue; - if($magnet->length == 0) $magnet = $xpath->evaluate(".//a/@href", $meta[0]); // This matches if no torrent file is provided on the page + if($title->length == 0) continue; + if($magnet->length == 0) $magnet = $xpath->evaluate(".//a/@href", $meta[0]); // This matches if no torrent file is provided if($magnet->length == 0) continue; // Process data - $name = sanitize($name[0]->textContent); + $title = sanitize($title[0]->textContent); $magnet = sanitize($magnet[0]->textContent); parse_str(parse_url($magnet, PHP_URL_QUERY), $hash_parameters); $hash = strtolower(str_replace('urn:btih:', '', $hash_parameters['xt'])); @@ -66,58 +59,60 @@ class NyaaRequest extends EngineRequest { if($this->opts->show_zero_seeders == 'off' AND $seeders == 0) continue; // Throw out mismatched tv-show episodes when searching for tv shows - if(!is_season_or_episode($this->query, $name)) continue; + if(!is_season_or_episode($this->search->query, $title)) continue; // Find extra data $category = $xpath->evaluate(".//td[1]//a/@title", $result); $url = $xpath->evaluate(".//td[@colspan='2']//a[not(contains(@class, 'comments'))]/@href", $result); + $date_added = $xpath->evaluate(".//td[@class='text-center']/@data-timestamp", $result); // Process extra data $category = ($category->length > 0) ? str_replace(' - ', '/', sanitize($category[0]->textContent)) : null; $url = ($url->length > 0) ? 'https://nyaa.si'.sanitize($url[0]->textContent) : null; - $date_added = explode('-', substr(sanitize($meta[2]->textContent), 0, 10)); - $date_added = timezone_offset(gmmktime(0, 0, 0, intval($date_added[1]), intval($date_added[2]), intval($date_added[0])), $this->opts->timezone); + $timestamp = sanitize($date_added[0]->textContent); + // Find meta data for certain categories + $nsfw = (detect_nsfw($title)) ? true : false; $quality = $codec = $audio = null; if(in_array(strtolower($category), array('anime/anime music video', 'anime/non-english-translated', 'anime/english-translated', 'anime/raw', 'live action/english-translated', 'live action/non-english-translated', 'live action/idol/promotional video', 'live action/raw'))) { - $quality = find_video_quality($name); - $codec = find_video_codec($name); + $quality = find_video_quality($title); + $codec = find_video_codec($title); + $audio = find_audio_codec($title); // Add codec to quality if(!empty($codec)) $quality = $quality.' '.$codec; - } - - if(in_array(strtolower($category), array('audio/lossless', 'audio/lossy', 'anime/anime music video', 'anime/non-english-translated', 'anime/english-translated', 'anime/raw', 'live action/english-translated', 'live action/non-english-translated', 'live action/idol/promotional video', 'live action/raw'))) { - $audio = find_audio_codec($name); + } else if(in_array(strtolower($category), array('audio/lossless', 'audio/lossy'))) { + $audio = find_audio_codec($title); } $engine_temp[] = array ( // Required 'hash' => $hash, // string - 'name' => $name, // string + 'title' => $title, // string 'magnet' => $magnet, // string 'seeders' => $seeders, // int 'leechers' => $leechers, // int 'filesize' => $filesize, // int // Optional + 'nsfw' => $nsfw, // bool 'quality' => $quality, // string|null 'type' => null, // string|null 'audio' => $audio, // string|null 'runtime' => null, // int(timestamp)|null 'year' => null, // int(4)|null - 'date_added' => $date_added, // int(timestamp)|null + 'timestamp' => $timestamp, // int(timestamp)|null 'category' => $category, // string|null + 'mpa_rating' => null, // string|null + 'language' => null, // string|null 'url' => $url // string|null ); - unset($result, $name, $hash, $magnet, $seeders, $leechers, $filesize, $quality, $codec, $audio, $category, $url, $date_added); + unset($result, $title, $hash, $magnet, $seeders, $leechers, $filesize, $quality, $codec, $audio, $category, $url, $date_added); } // Base info - $number_of_results = count($engine_temp); - if($number_of_results > 0) { + if(!empty($engine_temp)) { $engine_result['source'] = 'nyaa.si'; - $engine_result['amount'] = $number_of_results; $engine_result['search'] = $engine_temp; } diff --git a/engines/magnet/sukebei.php b/engines/magnet/sukebei.php index edb3057..e475591 100644 --- a/engines/magnet/sukebei.php +++ b/engines/magnet/sukebei.php @@ -11,14 +11,7 @@ ------------------------------------------------------------------------------------ */ class SukebeiRequest extends EngineRequest { public function get_request_url() { - $query = str_replace('%22', '\"', $this->query); - - // Is there no query left? Bail! - if(empty($query)) return false; - - $url = 'https://sukebei.nyaa.si/?q='.urlencode($query); - - unset($query); + $url = 'https://sukebei.nyaa.si/?q='.urlencode($this->search->query); return $url; } @@ -45,16 +38,16 @@ class SukebeiRequest extends EngineRequest { foreach($scrape as $result) { // Find data $meta = $xpath->evaluate(".//td[@class='text-center']", $result); - $name = $xpath->evaluate(".//td[@colspan='2']//a[not(contains(@class, 'comments'))]/@title", $result); + $title = $xpath->evaluate(".//td[@colspan='2']//a[not(contains(@class, 'comments'))]/@title", $result); $magnet = $xpath->evaluate(".//a[2]/@href", $meta[0]); // Skip broken results - if($name->length == 0) continue; - if($magnet->length == 0) $magnet = $xpath->evaluate(".//a/@href", $meta[0]); // This matches if no torrent file is provided on the page + if($title->length == 0) continue; + if($magnet->length == 0) $magnet = $xpath->evaluate(".//a/@href", $meta[0]); // This matches if no torrent file is provided if($magnet->length == 0) continue; // Process data - $name = sanitize($name[0]->textContent); + $title = sanitize($title[0]->textContent); $magnet = sanitize($magnet[0]->textContent); parse_str(parse_url($magnet, PHP_URL_QUERY), $hash_parameters); $hash = strtolower(str_replace('urn:btih:', '', $hash_parameters['xt'])); @@ -66,23 +59,24 @@ class SukebeiRequest extends EngineRequest { if($this->opts->show_zero_seeders == 'off' AND $seeders == 0) continue; // Throw out mismatched tv-show episodes when searching for tv shows - if(!is_season_or_episode($this->query, $name)) continue; + if(!is_season_or_episode($this->search->query, $title)) continue; // Find extra data $category = $xpath->evaluate(".//td[1]//a/@title", $result); $url = $xpath->evaluate(".//td[@colspan='2']//a[not(contains(@class, 'comments'))]/@href", $result); + $date_added = $xpath->evaluate(".//td[@class='text-center']/@data-timestamp", $result); // Process extra data $category = ($category->length > 0) ? str_replace(' - ', '/', sanitize($category[0]->textContent)) : null; $url = ($url->length > 0) ? 'https://sukebei.nyaa.si'.sanitize($url[0]->textContent) : null; - $date_added = explode('-', substr(sanitize($meta[2]->textContent), 0, 10)); - $date_added = timezone_offset(gmmktime(0, 0, 0, intval($date_added[1]), intval($date_added[2]), intval($date_added[0])), $this->opts->timezone); + $timestamp = sanitize($date_added[0]->textContent); + // Find meta data for certain categories $quality = $codec = $audio = null; if(in_array(strtolower($category), array('art/anime', 'real life/videos'))) { - $quality = find_video_quality($name); - $codec = find_video_codec($name); - $audio = find_audio_codec($name); + $quality = find_video_quality($title); + $codec = find_video_codec($title); + $audio = find_audio_codec($title); // Add codec to quality if(!empty($codec)) $quality = $quality.' '.$codec; @@ -91,30 +85,31 @@ class SukebeiRequest extends EngineRequest { $engine_temp[] = array ( // Required 'hash' => $hash, // string - 'name' => $name, // string + 'title' => $title, // string 'magnet' => $magnet, // string 'seeders' => $seeders, // int 'leechers' => $leechers, // int 'filesize' => $filesize, // int // Optional + 'nsfw' => true, // bool 'quality' => $quality, // string|null 'type' => null, // string|null 'audio' => $audio, // string|null 'runtime' => null, // int(timestamp)|null 'year' => null, // int(4)|null - 'date_added' => $date_added, // int(timestamp)|null + 'timestamp' => $timestamp, // int(timestamp)|null 'category' => $category, // string|null + 'mpa_rating' => null, // string|null + 'language' => null, // string|null 'url' => $url // string|null ); - unset($result, $name, $hash, $magnet, $seeders, $leechers, $filesize, $quality, $codec, $audio, $category, $url, $date_added); + unset($result, $title, $hash, $magnet, $seeders, $leechers, $filesize, $quality, $codec, $audio, $category, $url, $date_added); } // Base info - $number_of_results = count($engine_temp); - if($number_of_results > 0) { + if(!empty($engine_temp)) { $engine_result['source'] = 'sukebei.nyaa.si'; - $engine_result['amount'] = $number_of_results; $engine_result['search'] = $engine_temp; } diff --git a/engines/magnet/thepiratebay.php b/engines/magnet/thepiratebay.php index 8db6b4a..5dae20c 100644 --- a/engines/magnet/thepiratebay.php +++ b/engines/magnet/thepiratebay.php @@ -11,14 +11,7 @@ ------------------------------------------------------------------------------------ */ class PirateBayRequest extends EngineRequest { public function get_request_url() { - $query = str_replace('%22', '\"', $this->query); - - // Is there no query left? Bail! - if(empty($query)) return false; - - $url = 'https://apibay.org/q.php?q='.urlencode($query); - - unset($query); + $url = 'https://apibay.org/q.php?q='.urlencode($this->search->query); return $url; } @@ -108,9 +101,9 @@ class PirateBayRequest extends EngineRequest { foreach($json_response as $result) { // Find and process data - $name = sanitize($result['name']); + $title = sanitize($result['name']); $hash = strtolower(sanitize($result['info_hash'])); - $magnet = 'magnet:?xt=urn:btih:'.$hash.'&dn='.urlencode($name).'&tr='.implode('&tr=', $this->opts->magnet_trackers); + $magnet = 'magnet:?xt=urn:btih:'.$hash.'&dn='.urlencode($title).'&tr='.implode('&tr=', $this->opts->magnet_trackers); $seeders = sanitize($result['seeders']); $leechers = sanitize($result['leechers']); $filesize = human_filesize(sanitize($result['size'])); @@ -119,30 +112,30 @@ class PirateBayRequest extends EngineRequest { if($this->opts->show_zero_seeders == 'off' AND $seeders == 0) continue; // Throw out mismatched tv-show episodes when searching for tv shows - if(!is_season_or_episode($this->query, $name)) continue; + if(!is_season_or_episode($this->search->query, $title)) continue; // Find extra data $category = (array_key_exists('category', $result)) ? sanitize($result['category']) : null; $url = (array_key_exists('id', $result)) ? 'https://thepiratebay.org/description.php?id='.sanitize($result['id']) : null; - $date_added = (array_key_exists('added', $result)) ? timezone_offset(sanitize($result['added']), $this->opts->timezone) : null; + $timestamp = (isset($result['added'])) ? sanitize($result['added']) : null; // Process extra data if(!is_null($category)) { // Block these categories if(in_array($category, $this->opts->piratebay_categories_blocked)) continue; - // Detect technical data + // Find meta data for certain categories + $nsfw = ($category >= 500 && $category <= 599) ? true : false; $quality = $codec = $audio = null; - if(($category >= 200 && $category < 300) || ($category >= 500 && $category < 600)) { - $quality = find_video_quality($name); - $codec = find_video_codec($name); + if(($category >= 200 && $category <= 299) || ($category >= 500 && $category <= 599)) { + $quality = find_video_quality($title); + $codec = find_video_codec($title); + $audio = find_audio_codec($title); // Add codec to quality if(!empty($codec)) $quality = $quality.' '.$codec; - } - - if(($category >= 100 && $category < 200) || ($category >= 200 && $category < 300) || ($category >= 500 && $category < 600)) { - $audio = find_audio_codec($name); + } else if($category >= 100 && $category <= 199) { + $audio = find_audio_codec($title); } // Set actual category @@ -152,30 +145,31 @@ class PirateBayRequest extends EngineRequest { $engine_temp[] = array( // Required 'hash' => $hash, // string - 'name' => $name, // string + 'title' => $title, // string 'magnet' => $magnet, // string 'seeders' => $seeders, // int 'leechers' => $leechers, // int 'filesize' => $filesize, // int // Optional + 'nsfw' => $nsfw, // bool 'quality' => $quality, // string|null 'type' => null, // string|null 'audio' => $audio, // string|null 'runtime' => null, // int(timestamp)|null 'year' => null, // int(4)|null - 'date_added' => $date_added, // int(timestamp)|null + 'timestamp' => $timestamp, // int(timestamp)|null 'category' => $category, // string|null + 'language' => null, // string|null + 'mpa_rating' => null, // string|null 'url' => $url // string|null ); - unset($result, $name, $hash, $magnet, $seeders, $leechers, $filesize, $quality, $codec, $audio, $category, $url, $date_added); + unset($result, $title, $hash, $magnet, $seeders, $leechers, $filesize, $quality, $codec, $audio, $category, $url, $date_added); } // Base info - $number_of_results = count($engine_temp); - if($number_of_results > 0) { + if(!empty($engine_temp)) { $engine_result['source'] = 'thepiratebay.org'; - $engine_result['amount'] = $number_of_results; $engine_result['search'] = $engine_temp; } diff --git a/engines/magnet/yts.php b/engines/magnet/yts.php index f2cd482..92e8897 100644 --- a/engines/magnet/yts.php +++ b/engines/magnet/yts.php @@ -11,14 +11,7 @@ ------------------------------------------------------------------------------------ */ class YTSRequest extends EngineRequest { public function get_request_url() { - $query = str_replace('%22', '\"', $this->query); - - // Is there no query left? Bail! - if(empty($query)) return false; - - $url = 'https://yts.mx/api/v2/list_movies.json?query_term='.urlencode($query); - - unset($query); + $url = 'https://yts.mx/api/v2/list_movies.json?query_term='.urlencode($this->search->query); return $url; } @@ -46,17 +39,19 @@ class YTSRequest extends EngineRequest { foreach($json_response['data']['movies'] as $result) { // Find and process data - $name = sanitize($result['title']); + $title = sanitize($result['title']); // Find extra data - $year = (array_key_exists('year', $result)) ? sanitize($result['year']) : null; - $category = (array_key_exists('genres', $result)) ? $result['genres'] : null; // Sanitized later - $runtime = (array_key_exists('runtime', $result)) ? date('H:i', mktime(0, sanitize($result['runtime']))) : null; - $url = (array_key_exists('url', $result)) ? sanitize($result['url']) : null; - $date_added = (array_key_exists('date_uploaded_unix', $result)) ? timezone_offset(sanitize($result['date_uploaded_unix']), $this->opts->timezone) : null; + $runtime = (!empty($result['runtime'])) ? date('H:i', mktime(0, sanitize($result['runtime']))) : null; + $year = (!empty($result['year'])) ? sanitize($result['year']) : 0; + $category = (!empty($result['genres'])) ? $result['genres'] : null; + $mpa_rating = (!empty($result['mpa_rating'])) ? sanitize($result['mpa_rating']) : null; + $timestamp = (!empty($result['date_uploaded_unix'])) ? sanitize($result['date_uploaded_unix']) : null; + $language = (!empty($result['language'])) ? sanitize($result['language']) : null; + $url = (!empty($result['url'])) ? sanitize($result['url']) : null; // Process extra data - if(!is_null($category)) { + if(is_array($category)) { // Block these categories if(count(array_uintersect($category, $this->opts->yts_categories_blocked, 'strcasecmp')) > 0) continue; @@ -67,7 +62,7 @@ class YTSRequest extends EngineRequest { foreach ($result['torrents'] as $download) { // Find and process data $hash = strtolower(sanitize($download['hash'])); - $magnet = 'magnet:?xt=urn:btih:'.$hash.'&dn='.urlencode($name).'&tr='.implode('&tr=', $this->opts->magnet_trackers); + $magnet = 'magnet:?xt=urn:btih:'.$hash.'&dn='.urlencode($title).'&tr='.implode('&tr=', $this->opts->magnet_trackers); $seeders = sanitize($download['seeds']); $leechers = sanitize($download['peers']); $filesize = human_filesize(filesize_to_bytes(sanitize($download['size']))); @@ -76,42 +71,45 @@ class YTSRequest extends EngineRequest { if($this->opts->show_zero_seeders == 'off' AND $seeders == 0) continue; // Find extra data - $quality = (array_key_exists('quality', $download)) ? sanitize(strtolower($download['quality'])) : null; - $codec = (array_key_exists('video_codec', $download)) ? sanitize(strtolower($download['video_codec'])) : null; - $type = (array_key_exists('type', $download)) ? ucfirst(sanitize(strtolower($download['type']))) : null; - $audio = (array_key_exists('audio_channels', $download)) ? sanitize('AAC '.$download['audio_channels']) : null; + $quality = (!empty($download['quality'])) ? sanitize(strtolower($download['quality'])) : null; + $codec = (!empty($download['video_codec'])) ? sanitize(strtolower($download['video_codec'])) : null; + $bitrate = (!empty($download['bit_depth'])) ? sanitize($download['bit_depth']) : null; + $type = (!empty($download['type'])) ? ucfirst(sanitize(strtolower($download['type']))) : null; + $audio = (!empty($download['audio_channels'])) ? sanitize('AAC '.$download['audio_channels']) : null; // Process extra data if(!empty($codec)) $quality = $quality.' '.$codec; + if(!empty($bitrate)) $quality = $quality.' '.$bitrate.'bit'; $engine_temp[] = array ( // Required 'hash' => $hash, // string - 'name' => $name, // string + 'title' => $title, // string 'magnet' => $magnet, // string 'seeders' => $seeders, // int 'leechers' => $leechers, // int 'filesize' => $filesize, // int // Optional + 'nsfw' => false, // bool 'quality' => $quality, // string|null 'type' => $type, // string|null 'audio' => $audio, // string|null - 'year' => $year, // int(4)|null - 'category' => $category, // string|null 'runtime' => $runtime, // int(timestamp)|null - 'url' => $url, // string|null - 'date_added' => $date_added // int(timestamp)|null + 'year' => $year, // int(4)|null + 'timestamp' => $timestamp, // int(timestamp)|null + 'category' => $category, // string|null + 'mpa_rating' => $mpa_rating, // string|null + 'language' => $language, // string|null + 'url' => $url // string|null ); - unset($download, $hash, $magnet, $seeders, $leechers, $filesize, $quality, $codec, $type, $audio); + unset($download, $hash, $magnet, $seeders, $leechers, $filesize, $quality, $codec, $bitrate, $type, $audio); } - unset($result, $name, $year, $category, $runtime, $url, $date_added); + unset($result, $title, $year, $category, $language, $runtime, $url, $date_added); } // Base info - $number_of_results = count($engine_temp); - if($number_of_results > 0) { + if(!empty($engine_temp)) { $engine_result['source'] = 'yts.mx'; - $engine_result['amount'] = $number_of_results; $engine_result['search'] = $engine_temp; } diff --git a/engines/news/brave-news.php b/engines/news/brave-news.php index 5db157e..69ce2d3 100644 --- a/engines/news/brave-news.php +++ b/engines/news/brave-news.php @@ -11,48 +11,13 @@ ------------------------------------------------------------------------------------ */ class BraveNewsRequest extends EngineRequest { public function get_request_url() { - $query = str_replace('%22', '\"', $this->query); - - $query_terms = explode(' ', $query); - $query_terms[0] = strtolower($query_terms[0]); - - // Safe search ignore (not supported) - if($query_terms[0] == 'safe:on' || $query_terms[0] == 'safe:off') { - $query = trim(str_replace($query_terms[0], '', $query)); - } - - // Search range - $today = time() - 86400; - if($query_terms[0] == 'now' || $query_terms[0] == 'today' || $query_terms[0] == 'yesterday') { - // Last 24 hours - $this->opts->result_range = $today; - $age = 'pd'; - } else if($query_terms[0] == 'week' || ($query_terms[0] == 'this' && $query_terms[1] == 'week') || $query_terms[0] == 'recent') { - // Last 7 days - $this->opts->result_range = $today - (6 * 86400); - $age = 'pw'; - } else if($query_terms[0] == 'year' || ($query_terms[0] == 'this' && $query_terms[1] == 'year')) { - // This year - $this->opts->result_range = timezone_offset(gmmktime(0, 0, 0, 1, 1, gmdate('Y')), $this->opts->timezone); - $age = 'py'; - } else { - // This month (default) - $this->opts->result_range = timezone_offset(gmmktime(0, 0, 0, gmdate('m'), 1, gmdate('Y')), $this->opts->timezone); - $age = 'pm'; - } - - // Is there no query left? Bail! - if(empty($query)) return false; - $url = 'https://search.brave.com/news?'.http_build_query(array( - 'q' => $query, // Search query + 'q' => $this->search->query, // Search query 'offset' => 0, // Start on 'page' 1 of results (0 = 1) 'spellcheck' => 0, // No spellcheck on your query 'source' => 'web', // Where are you searching from? (Web) - 'tf' => $age // How old may the article be? + 'tf' => 'pm' // How old may the article be? )); - - unset($query, $query_terms, $today, $age); return $url; } @@ -84,6 +49,7 @@ class BraveNewsRequest extends EngineRequest { $title = $xpath->evaluate(".//a[contains(@class, 'result-header')]//span[contains(@class, 'snippet-title')]", $result); $url = $xpath->evaluate(".//a[contains(@class, 'result-header')]/@href", $result); $description = $xpath->evaluate(".//p[contains(@class, 'snippet-description')]", $result); + $image = $xpath->evaluate(".//div[contains(@class, 'image-wrapper')]/img/@src", $result); $date_added = $xpath->evaluate(".//cite[contains(@class, 'snippet-url')]/span[2]", $result); // Skip broken results @@ -95,35 +61,30 @@ class BraveNewsRequest extends EngineRequest { $url = sanitize($url[0]->textContent); // $url = (strpos($url, "/a/redirect?click_url=", 0) !== false) ? "https://search.brave.com".$url : $url; $description = ($description->length == 0) ? "No description was provided for this site." : limit_string_length(strip_newlines(sanitize($description[0]->textContent))); + $image = ($image->length == 0) ? null : sanitize($image[0]->textContent); $source = str_replace('www.', '', strtolower(parse_url($url, PHP_URL_HOST))); - $date_added = ($date_added->length == 0) ? null : timezone_offset(strtotime(sanitize($date_added[0]->textContent)), $this->opts->timezone); + $timestamp = ($date_added->length == 0) ? null : strtotime(sanitize($date_added[0]->textContent)); // filter duplicate urls/results if(!empty($engine_temp)) { if(in_array($url, array_column($engine_temp, 'url'))) continue; } - // Ignore results that are too old - if(isset($this->opts->result_range) && !is_null($date_added)) { - if($date_added < $this->opts->result_range) continue; - } - $engine_temp[] = array( 'title' => $title, // string 'url' => $url, // string 'description' => $description, // string + 'image' => $image, // string|null 'source' => $source, // string - 'date_added' => $date_added, // int (timestamp) + 'timestamp' => $timestamp, // int|null 'engine_rank' => $rank // int ); $rank -= 1; } // Base info - $number_of_results = count($engine_temp); - if($number_of_results > 0) { + if(!empty($engine_temp)) { $engine_result['source'] = 'Brave News'; - $engine_result['amount'] = $number_of_results; $engine_result['search'] = $engine_temp; } diff --git a/engines/news/hackernews.php b/engines/news/hackernews.php index 5dd34d1..d9975ca 100644 --- a/engines/news/hackernews.php +++ b/engines/news/hackernews.php @@ -11,50 +11,18 @@ ------------------------------------------------------------------------------------ */ class HackernewsRequest extends EngineRequest { public function get_request_url() { - $query = str_replace('%22', '\"', $this->query); - - $query_terms = explode(' ', $query); - $query_terms[0] = strtolower($query_terms[0]); - - // Safe search ignore (not supported) - if($query_terms[0] == 'safe:on' || $query_terms[0] == 'safe:off') { - $query = trim(str_replace($query_terms[0], '', $query)); - } - - // Search range - $today = time() - 86400; - if($query_terms[0] == 'now' || $query_terms[0] == 'today' || $query_terms[0] == 'yesterday') { - // Last 24 hours - $this->opts->result_range = $today; - $age = 'created_at_i>'.$this->opts->result_range.',created_at_i<'.$today; // Yesterday - } else if($query_terms[0] == 'week' || ($query_terms[0] == 'this' && $query_terms[1] == 'week') || $query_terms[0] == 'recent') { - // Last 7 days - $this->opts->result_range = $today - (6 * 86400); - $age = 'created_at_i>'.$this->opts->result_range; // This week - } else if($query_terms[0] == 'year' || ($query_terms[0] == 'this' && $query_terms[1] == 'year')) { - // This year - $this->opts->result_range = timezone_offset(gmmktime(0, 0, 0, 1, 1, gmdate('Y')), $this->opts->timezone); - $age = 'created_at_i>'.$this->opts->result_range; - } else { - // This month (default) - $this->opts->result_range = timezone_offset(gmmktime(0, 0, 0, gmdate('m'), 1, gmdate('Y')), $this->opts->timezone); - $age = 'created_at_i>'.$this->opts->result_range; - } - - // Is there no query left? Bail! - if(empty($query)) return false; + // Search range (must be in GMT) + $article_date = time() - (30 * 86400); // More info on https://hn.algolia.com/api - $url = 'http://hn.algolia.com/api/v1/search_by_date?'.http_build_query(array( - 'query' => $query, // Search query + $url = 'https://hn.algolia.com/api/v1/search_by_date?'.http_build_query(array( + 'query' => $this->search->query, // Search query 'tags' => 'story', // What type of results to show? (story = News stories) 'hitsPerPage' => 30, // How many results to return? - 'restrictSearchableAttributes' => 'title,url', // Only match on URLs - 'attributesToRetrieve' => '_tags,title,url,author,created_at_i', // Data to retrieve - 'numericFilters' => $age // How old may the article be? + 'numericFilters' => 'created_at_i>'.$article_date // How old may the article be? )); - unset($query, $query_terms, $today, $age); + unset($article_date); return $url; } @@ -93,34 +61,28 @@ class HackernewsRequest extends EngineRequest { $url = sanitize($result['url']); $description = (array_key_exists('story_text', $result)) ? limit_string_length(strip_newlines(sanitize($result['story_text']))) : $title; $source = str_replace('www.', '', strtolower(parse_url($url, PHP_URL_HOST))); - $date_added = timezone_offset(sanitize($result['created_at_i']), $this->opts->timezone); + $timestamp = sanitize($result['created_at_i']); // Skip duplicate urls/results if(!empty($engine_temp)) { if(in_array($url, array_column($engine_temp, 'url'))) continue; } - // Ignore results that are too old - if(isset($this->opts->result_range)) { - if($date_added < $this->opts->result_range) continue; - } - $engine_temp[] = array ( 'title' => $title, // string 'url' => $url, // string 'description' => $description, // string + 'image' => null, // string|null 'source' => $source, // string - 'date_added' => $date_added, // int (timestamp) + 'timestamp' => $timestamp, // int|null 'engine_rank' => $rank // int ); $rank -= 1; } // Base info - $number_of_results = count($engine_temp); - if($number_of_results > 0) { + if(!empty($engine_temp)) { $engine_result['source'] = 'Hackernews'; - $engine_result['amount'] = $number_of_results; $engine_result['search'] = $engine_temp; } diff --git a/engines/news/qwant-news.php b/engines/news/qwant-news.php index 1f63400..b981321 100644 --- a/engines/news/qwant-news.php +++ b/engines/news/qwant-news.php @@ -11,60 +11,23 @@ ------------------------------------------------------------------------------------ */ class QwantNewsRequest extends EngineRequest { public function get_request_url() { - $query = str_replace('%22', '\"', $this->query); - - // Safe search override - $safe = '1'; // Moderate results - if(preg_match('/(safe:)(on|off)/i', $query, $matches)) { - if($matches[2] == 'on') $safe = '2'; - if($matches[2] == 'off') $safe = '0'; - $query = trim(str_replace($matches[0], '', $query)); - } - unset($matches); - // Set locale $language = (preg_match('/[a-z]{2}_[a-z]{2}/i', $this->opts->qwant_language) && strlen($this->opts->qwant_language) == 5) ? strtolower($this->opts->qwant_language) : 'en_gb'; - $query_terms = explode(' ', $query); - $query_terms[0] = strtolower($query_terms[0]); - - // Search range - $today = time() - 86400; - if($query_terms[0] == 'now' || $query_terms[0] == 'today' || $query_terms[0] == 'yesterday') { - // Last 24 hours - $this->opts->result_range = $today; - $age = 'day'; - } else if($query_terms[0] == 'week' || ($query_terms[0] == 'this' && $query_terms[1] == 'week') || $query_terms[0] == 'recent') { - // Last 7 days - $this->opts->result_range = $today - (6 * 86400); - $age = 'week'; - } else if($query_terms[0] == 'year' || ($query_terms[0] == 'this' && $query_terms[1] == 'year')) { - // This year - $this->opts->result_range = timezone_offset(gmmktime(0, 0, 0, 1, 1, gmdate('Y')), $this->opts->timezone); - $age = 'all'; - } else { - // This month - $this->opts->result_range = timezone_offset(gmmktime(0, 0, 0, gmdate('m'), 1, gmdate('Y')), $this->opts->timezone); - $age = 'month'; - } - - // Is there no query left? Bail! - if(empty($query)) return false; - // Based on https://github.com/locness3/qwant-api-docs and variables from qwant website $url = 'https://api.qwant.com/v3/search/news?'.http_build_query(array( - 'q' => $query, // Search query + 'q' => $this->search->query, // Search query 't' => 'news', // News search - 'safesearch' => $safe, // Safe search filter (0 = off, 1 = normal, 2 = strict) + 'safesearch' => $this->search->safe, // Safe search filter (0 = off, 1 = normal, 2 = strict) 'locale' => $language, // Language region 'count' => 30, // How many results? (Maximum 50) 'device' => 'desktop', // Where are you searching from 'source' => 'all', // Where to get the news from (All) - 'freshness' => $age, // How old may the article be? + 'freshness' => 'month', // How old may the article be? 'order' => 'date' // Sort by date )); - unset($query, $query_terms, $safe, $language, $age); + unset($language); return $url; } @@ -98,30 +61,28 @@ class QwantNewsRequest extends EngineRequest { $title = sanitize($result['title']); $url = strip_newlines(sanitize($result['url'])); $description = limit_string_length(strip_newlines(sanitize($result['desc']))); + $image = sanitize($result['media'][0]['pict']['url']); $source = str_replace('www.', '', strtolower(parse_url($url, PHP_URL_HOST))); - $date_added = timezone_offset(sanitize($result['date']), $this->opts->timezone); + $timestamp = sanitize($result['date']); - // Ignore results that are too old - if(isset($this->opts->result_range)) { - if($date_added < $this->opts->result_range) continue; - } + // Fix up the image + if($image == 'NULL') $image = null; $engine_temp[] = array( 'title' => $title, // string - 'url' => $url, // sting + 'url' => $url, // string 'description' => $description, // string + 'image' => $image, // string|null 'source' => $source, // string - 'date_added' => $date_added, // int (timestamp) + 'timestamp' => $timestamp, // int|null 'engine_rank' => $rank // int ); $rank -= 1; } // Base info - $number_of_results = count($engine_temp); - if($number_of_results > 0) { + if(!empty($engine_temp)) { $engine_result['source'] = 'Qwant News'; - $engine_result['amount'] = $number_of_results; $engine_result['search'] = $engine_temp; } diff --git a/engines/news/yahoo-news.php b/engines/news/yahoo-news.php index cca4d8d..fc62f1b 100644 --- a/engines/news/yahoo-news.php +++ b/engines/news/yahoo-news.php @@ -11,45 +11,19 @@ ------------------------------------------------------------------------------------ */ class YahooNewsRequest extends EngineRequest { public function get_request_url() { - $query = str_replace('%22', '\"', $this->query); - // Safe search override - $safe = ''; // No mature results - if(preg_match('/(safe:)(on|off)/i', $query, $matches)) { - if($matches[2] == 'on') $safe = ''; - if($matches[2] == 'off') $safe = '0'; - $query = str_replace($matches[0], '', $query); - } - unset($matches); - - $query_terms = explode(' ', $query); - $query_terms[0] = strtolower($query_terms[0]); - - // Search range - $today = time() - 86400; - if($query_terms[0] == 'now' || $query_terms[0] == 'today' || $query_terms[0] == 'yesterday') { - // Last 24 hours - $this->opts->result_range = $today; - } else if($query_terms[0] == 'week' || ($query_terms[0] == 'this' && $query_terms[1] == 'week') || $query_terms[0] == 'recent') { - // Last 7 days - $this->opts->result_range = $today - (6 * 86400); - } else if($query_terms[0] == 'year' || ($query_terms[0] == 'this' && $query_terms[1] == 'year')) { - // This year - $this->opts->result_range = timezone_offset(gmmktime(0, 0, 0, 1, 1, gmdate('Y')), $this->opts->timezone); + if($this->search->safe == 0) { + $safe = '0'; } else { - // This month - $this->opts->result_range = timezone_offset(gmmktime(0, 0, 0, gmdate('m'), 1, gmdate('Y')), $this->opts->timezone); + $safe = ''; } - - // Is there no query left? Bail! - if(empty($query)) return false; - + $url = 'https://news.search.yahoo.com/search?'.http_build_query(array( - 'p' => $query, // Search query + 'p' => $this->search->query, // Search query 'safe' => $safe // Safe search filter (0 = off, "" = on) )); - unset($query, $query_terms, $safe, $today); + unset($safe); return $url; } @@ -81,6 +55,7 @@ class YahooNewsRequest extends EngineRequest { $title = $xpath->evaluate("./div/ul/li/a[contains(@class, 'thmb')]/@title", $result); $url = $xpath->evaluate("./div/ul/li/h4[contains(@class, 's-title')]/a/@href", $result); $description = $xpath->evaluate("./div/ul/li/p[contains(@class, 's-desc')]", $result); + $image = $xpath->evaluate("./div/ul/li/a/img[@class='s-img']/@src", $result); $date_added = $xpath->evaluate("./div/ul/li/span[contains(@class, 's-time')]", $result); // Skip broken results @@ -93,35 +68,37 @@ class YahooNewsRequest extends EngineRequest { $url = (preg_match('/\??&?(utm_).+?(&|$)$/i', $url, $found_url)) ? urldecode($found_url[1]) : $url; $url = sanitize(str_replace('?fr=sycsrp_catchall', '', $url)); $description = ($description->length == 0) ? "No description was provided for this site." : limit_string_length(strip_newlines(sanitize($description[0]->textContent))); + $image = ($image->length == 0) ? null : sanitize($image[0]->textContent); $source = str_replace('www.', '', strtolower(parse_url($url, PHP_URL_HOST))); - $date_added = ($date_added->length == 0) ? null : timezone_offset(strtotime(sanitize(preg_replace('/[^a-z0-9 ]+/i', '', $date_added[0]->textContent))), $this->opts->timezone); + $timestamp = ($date_added->length == 0) ? null : strtotime(sanitize(preg_replace('/[^a-z0-9 ]+/i', '', $date_added[0]->textContent))); // filter duplicate urls/results if(!empty($engine_temp)) { if(in_array($url, array_column($engine_temp, 'url'))) continue; } - // Ignore results that are too old - if(isset($this->opts->result_range) && !is_null($date_added)) { - if($date_added < $this->opts->result_range) continue; + // Fix up the image + if(!is_null($image)) { + $image = explode('/http', $image); + $image = parse_url('http'.$image[1]); + $image = $image['scheme'].'://'.$image['host'].$image['path']; } $engine_temp[] = array( 'title' => $title, // string 'url' => $url, // string 'description' => $description, // string + 'image' => $image, // string|null 'source' => $source, // string - 'date_added' => $date_added, // int (timestamp) + 'timestamp' => $timestamp, // int|null 'engine_rank' => $rank // int ); $rank -= 1; } // Base info - $number_of_results = count($engine_temp); - if($number_of_results > 0) { + if(!empty($engine_temp)) { $engine_result['source'] = 'Yahoo News'; - $engine_result['amount'] = $number_of_results; $engine_result['search'] = $engine_temp; } diff --git a/engines/search-image.php b/engines/search-image.php index bcaa682..06752d0 100644 --- a/engines/search-image.php +++ b/engines/search-image.php @@ -12,27 +12,29 @@ class ImageSearch extends EngineRequest { protected $requests; - public function __construct($opts, $mh) { + public function __construct($search, $opts, $mh) { $this->requests = array(); - if($opts->enable_yahooimages == 'on') { - require ABSPATH.'engines/image/yahoo-images.php'; - $this->requests[] = new YahooImageRequest($opts, $mh); - } - - if($opts->enable_openverse == 'on') { - require ABSPATH.'engines/image/openverse.php'; - $this->requests[] = new OpenverseRequest($opts, $mh); - } - - if($opts->enable_qwantimages == 'on') { - require ABSPATH.'engines/image/qwant-images.php'; - $this->requests[] = new QwantImageRequest($opts, $mh); + if($opts->enable_image_search == 'on') { + if($opts->enable_yahooimages == 'on') { + require ABSPATH.'engines/image/yahoo-images.php'; + $this->requests[] = new YahooImageRequest($search, $opts, $mh); + } + + if($opts->enable_openverse == 'on') { + require ABSPATH.'engines/image/openverse.php'; + $this->requests[] = new OpenverseRequest($search, $opts, $mh); + } + + if($opts->enable_qwantimages == 'on') { + require ABSPATH.'engines/image/qwant-images.php'; + $this->requests[] = new QwantImageRequest($search, $opts, $mh); + } } } public function parse_results($response) { - $results = array(); + $goosle_results = array(); if(count($this->requests) !== 0) { foreach($this->requests as $request) { @@ -40,47 +42,54 @@ class ImageSearch extends EngineRequest { $engine_result = $request->get_results(); if(!empty($engine_result)) { - if(array_key_exists('did_you_mean', $engine_result)) { - $results['did_you_mean'] = $engine_result['did_you_mean']; + if(isset($engine_result['did_you_mean'])) { + $goosle_results['did_you_mean'] = $engine_result['did_you_mean']; } - if(array_key_exists('search_specific', $engine_result)) { - $results['search_specific'][] = $engine_result['search_specific']; + if(isset($engine_result['search_specific'])) { + $goosle_results['search_specific'][] = $engine_result['search_specific']; } - if(array_key_exists('search', $engine_result)) { - // Count results per source - $results['sources'][$engine_result['source']] = $engine_result['amount']; - + if(isset($engine_result['search'])) { + $how_many_results = 0; + // Merge duplicates and apply relevance scoring foreach($engine_result['search'] as $result) { - if(array_key_exists('search', $results)) { - $result_urls = array_column($results['search'], 'image_full', 'id'); + if(isset($goosle_results['search'])) { + $result_urls = array_column($goosle_results['search'], 'image_full', 'id'); $found_id = array_search($result['image_full'], $result_urls); // Return the result ID, or false if not found } else { $found_id = false; } + + $how_many_results++; + $social_media_multiplier = (is_social_media($result['url'])) ? ($request->opts->social_media_relevance / 10) : 1; + $goosle_rank = floor($result['engine_rank'] * floatval($social_media_multiplier)); if($found_id !== false) { // Duplicate result from another engine - $results['search'][$found_id]['goosle_rank'] += $result['engine_rank']; - $results['search'][$found_id]['combo_source'][] = $engine_result['source']; + $goosle_results['search'][$found_id]['goosle_rank'] += $result['engine_rank']; + $goosle_results['search'][$found_id]['combo_source'][] = $engine_result['source']; } else { // First find, rank and add to results - // Replace anything but alphanumeric with a space - $query_terms = explode(' ', preg_replace('/\s{2,}|[^a-z0-9]+/', ' ', strtolower($request->query))); - $match_rank = match_count($result['url'], $query_terms); - $match_rank += match_count($result['alt'], $query_terms); + $match_rank = match_count($result['url'], $request->search->query_terms); + $match_rank += match_count($result['alt'], $request->search->query_terms); - $result['goosle_rank'] = $result['engine_rank'] + $match_rank; + $result['goosle_rank'] = $goosle_rank + $match_rank; $result['combo_source'][] = $engine_result['source']; $result['id'] = md5($result['image_full']); - $results['search'][$result['id']] = $result; + // Add result to final results + $goosle_results['search'][$result['id']] = $result; } unset($result, $result_urls, $found_id, $social_media_multiplier, $goosle_rank, $match_rank, $query_terms); } + + // Count results per source + $goosle_results['sources'][$engine_result['source']] = $how_many_results; + + unset($how_many_results); } } } else { @@ -88,95 +97,117 @@ class ImageSearch extends EngineRequest { $http_code_info = ($request_result['http_code'] > 200 && $request_result['http_code'] < 600) ? " - What's this?" : ''; $github_issue_url = "https://github.com/adegans/Goosle/discussions/new?category=general&".http_build_query(array('title' => get_class($request)." failed with error ".$request_result['http_code'], 'body' => "```\nEngine: ".get_class($request)."\nError Code: ".$request_result['http_code']."\nRequest url: ".$request_result['url']."\n```", 'labels' => 'request-error')); - $results['error'][] = array( + $goosle_results['error'][] = array( 'message' => "Ohno! A search query ran into some trouble. Usually you can try again in a few seconds to get a result!
Engine: ".get_class($request)."
Error code: ".$request_result['http_code'].$http_code_info."
Request url: ".$request_result['url']."
Need help? Find similar issues, or ask your own question." ); } unset($request); } + + if(array_key_exists('search', $goosle_results)) { + // Re-order results based on rank + $keys = array_column($goosle_results['search'], 'goosle_rank'); + array_multisort($keys, SORT_DESC, $goosle_results['search']); + + // Count all results + $goosle_results['number_of_results'] = count($goosle_results['search']); + + unset($keys); + } else { + // Add error if there are no search results + $goosle_results['error'][] = array( + "message" => "No results found. Please try with more specific or different keywords!" + ); + } } else { - $results['error'][] = array( - 'message' => "Configuration issue! It appears that all Image Search engines are disabled. Please enable at least one in your config.php file.
Need help? Find similar issues." + $goosle_results['error'][] = array( + 'message' => "It appears that all Image Search engines are disabled or that searching for images is disabled." ); } - if(array_key_exists('search', $results)) { - // Re-order results based on rank - $keys = array_column($results['search'], 'goosle_rank'); - array_multisort($keys, SORT_DESC, $results['search']); - - unset($keys); - } else { - // Add error if there are no search results - $results['error'][] = array( - "message" => "No results found. Please try with more specific or different keywords!" - ); - } - - return $results; + return $goosle_results; } - public static function print_results($results, $opts) { + public static function print_results($goosle_results, $search, $opts) { /* // Uncomment for debugging echo '
Settings: ';
 print_r($opts);
 echo '
'; +echo "
Search data: ";
+print_r($search);
+echo "
"; echo '
Search results: ';
-print_r($results);
+print_r($goosle_results);
 echo '
'; */ - if(array_key_exists('search', $results)) { + if(array_key_exists('search', $goosle_results)) { + // Pagination offset + if($opts->cache_type !== 'off') { + $offset = ((($search->page - 1) * $opts->search_results_per_page) + 1); + $goosle_results['search'] = array_slice($goosle_results['search'], $offset, $opts->search_results_per_page); + } + echo ""; // Search results - echo "
"; - echo "
"; - echo "
Goosle does not store or distribute image files.
"; + + // Pagination navigation + if($opts->cache_type !== 'off' && $goosle_results['number_of_results'] > $opts->search_results_per_page) { + echo "

".search_pagination($search, $opts, $goosle_results['number_of_results'])."

"; + } + + echo "

Goosle does not store or distribute image files.

"; } // No results found - if(array_key_exists("error", $results)) { - foreach($results['error'] as $error) { + if(array_key_exists("error", $goosle_results)) { + foreach($goosle_results['error'] as $error) { echo "
".$error['message']."
"; } } - unset($results); + unset($goosle_results); } } ?> \ No newline at end of file diff --git a/engines/search-magnet.php b/engines/search-magnet.php index bf0a37a..86d99e2 100644 --- a/engines/search-magnet.php +++ b/engines/search-magnet.php @@ -10,86 +10,96 @@ * liability that might arise from its use. ------------------------------------------------------------------------------------ */ class MagnetSearch extends EngineRequest { - protected $requests, $boxoffice; + protected $requests; - public function __construct($opts, $mh) { + public function __construct($search, $opts, $mh) { $this->requests = array(); - // Extra functions to process magnet results - require ABSPATH.'functions/tools-magnet.php'; - - if($opts->enable_limetorrents == 'on') { - require ABSPATH.'engines/magnet/lime.php'; - $this->requests[] = new LimeRequest($opts, $mh); - } - - if($opts->enable_piratebay == 'on') { - require ABSPATH.'engines/magnet/thepiratebay.php'; - $this->requests[] = new PirateBayRequest($opts, $mh); - } - - if($opts->enable_yts == 'on') { - require ABSPATH.'engines/magnet/yts.php'; - $this->requests[] = new YTSRequest($opts, $mh); - } - - if($opts->enable_nyaa == 'on') { - require ABSPATH.'engines/magnet/nyaa.php'; - $this->requests[] = new NyaaRequest($opts, $mh); - } - - if($opts->enable_sukebei == 'on') { - require ABSPATH.'engines/magnet/sukebei.php'; - $this->requests[] = new SukebeiRequest($opts, $mh); - } - - if($opts->enable_eztv == 'on') { - if(substr(strtolower($opts->query), 0, 2) == 'tt') { - require ABSPATH.'engines/magnet/eztv.php'; - $this->requests[] = new EZTVRequest($opts, $mh); + if($opts->enable_magnet_search == 'on') { + // Extra functions to process magnet results + require ABSPATH.'functions/tools-magnet.php'; + + if($opts->enable_limetorrents == 'on') { + require ABSPATH.'engines/magnet/lime.php'; + $this->requests[] = new LimeRequest($search, $opts, $mh); + } + + if($opts->enable_piratebay == 'on') { + require ABSPATH.'engines/magnet/thepiratebay.php'; + $this->requests[] = new PirateBayRequest($search, $opts, $mh); + } + + if($opts->enable_yts == 'on') { + if($search->safe !== 0) { + require ABSPATH.'engines/magnet/yts.php'; + $this->requests[] = new YTSRequest($search, $opts, $mh); + } + } + + if($opts->enable_nyaa == 'on') { + require ABSPATH.'engines/magnet/nyaa.php'; + $this->requests[] = new NyaaRequest($search, $opts, $mh); + } + + if($opts->enable_sukebei == 'on') { + if($opts->show_nsfw_magnets == 'on' || ($opts->show_nsfw_magnets == 'off' && $search->safe === 0)) { + require ABSPATH.'engines/magnet/sukebei.php'; + $this->requests[] = new SukebeiRequest($search, $opts, $mh); + } + } + + if($opts->enable_eztv == 'on') { + if(substr(strtolower($search->query), 0, 2) == 'tt') { + require ABSPATH.'engines/magnet/eztv.php'; + $this->requests[] = new EZTVRequest($search, $opts, $mh); + } } } } public function parse_results($response) { - $results = array(); + $goosle_results = array(); - if(count($this->requests) !== 0) { + if(count($this->requests) !== 0) { foreach($this->requests as $request) { if($request->request_successful()) { $engine_result = $request->get_results(); if(!empty($engine_result)) { - if(array_key_exists('search', $engine_result)) { - // Count results per source - $results['sources'][$engine_result['source']] = $engine_result['amount']; - + if(isset($engine_result['search'])) { + $how_many_results = 0; + // Merge duplicates and apply relevance scoring foreach($engine_result['search'] as $result) { - if(array_key_exists('search', $results)) { - $result_urls = array_column($results['search'], 'hash', 'id'); + // Safe search, skip nsfw? + if($request->opts->show_nsfw_magnets == 'off' && $request->search->safe !== 0 && $result['nsfw']) continue; + + if(isset($goosle_results['search'])) { + $result_urls = array_column($goosle_results['search'], 'hash', 'id'); $found_id = array_search($result['hash'], $result_urls); // Return the result ID, or false if not found } else { $found_id = false; } + $how_many_results++; + if($found_id !== false) { // Duplicate result from another engine // If seeders or leechers mismatch, assume they're different peers - if($results['search'][$found_id]['seeders'] != $result['seeders']) $results['search'][$found_id]['combo_seeders'] += intval($result['seeders']); - if($results['search'][$found_id]['leechers'] != $result['leechers']) $results['search'][$found_id]['combo_leechers'] += intval($result['leechers']); + if($goosle_results['search'][$found_id]['seeders'] != $result['seeders']) $goosle_results['search'][$found_id]['combo_seeders'] += intval($result['seeders']); + if($goosle_results['search'][$found_id]['leechers'] != $result['leechers']) $goosle_results['search'][$found_id]['combo_leechers'] += intval($result['leechers']); - $results['search'][$found_id]['combo_source'][] = $engine_result['source']; + $goosle_results['search'][$found_id]['combo_source'][] = $engine_result['source']; // If duplicate result has more info, add it - if(is_null($results['search'][$found_id]['year']) && !is_null($result['year'])) $results['search'][$found_id]['year'] = $result['year']; - if(is_null($results['search'][$found_id]['category']) && !is_null($result['category'])) $results['search'][$found_id]['category'] = $result['category']; - if(is_null($results['search'][$found_id]['runtime']) && !is_null($result['runtime'])) $results['search'][$found_id]['runtime'] = $result['runtime']; - if(is_null($results['search'][$found_id]['url']) && !is_null($result['url'])) $results['search'][$found_id]['url'] = $result['url']; - if(is_null($results['search'][$found_id]['date_added']) && !is_null($result['date_added'])) $results['search'][$found_id]['date_added'] = $result['date_added']; - if(is_null($results['search'][$found_id]['quality']) && !is_null($result['quality'])) $results['search'][$found_id]['quality'] = $result['quality']; - if(is_null($results['search'][$found_id]['type']) && !is_null($result['type'])) $results['search'][$found_id]['type'] = $result['type']; - if(is_null($results['search'][$found_id]['audio']) && !is_null($result['audio'])) $results['search'][$found_id]['audio'] = $result['audio']; + if(is_null($goosle_results['search'][$found_id]['year']) && !is_null($result['year'])) $goosle_results['search'][$found_id]['year'] = $result['year']; + if(is_null($goosle_results['search'][$found_id]['category']) && !is_null($result['category'])) $goosle_results['search'][$found_id]['category'] = $result['category']; + if(is_null($goosle_results['search'][$found_id]['runtime']) && !is_null($result['runtime'])) $goosle_results['search'][$found_id]['runtime'] = $result['runtime']; + if(is_null($goosle_results['search'][$found_id]['url']) && !is_null($result['url'])) $goosle_results['search'][$found_id]['url'] = $result['url']; + if(is_null($goosle_results['search'][$found_id]['timestamp']) && !is_null($result['timestamp'])) $goosle_results['search'][$found_id]['timestamp'] = $result['timestamp']; + if(is_null($goosle_results['search'][$found_id]['quality']) && !is_null($result['quality'])) $goosle_results['search'][$found_id]['quality'] = $result['quality']; + if(is_null($goosle_results['search'][$found_id]['type']) && !is_null($result['type'])) $goosle_results['search'][$found_id]['type'] = $result['type']; + if(is_null($goosle_results['search'][$found_id]['audio']) && !is_null($result['audio'])) $goosle_results['search'][$found_id]['audio'] = $result['audio']; } else { // First find, rank and add to results // Ranks by combo_seeders instead of regular ranking @@ -98,11 +108,17 @@ class MagnetSearch extends EngineRequest { $result['combo_source'][] = $engine_result['source']; $result['id'] = md5($result['hash']); // Predictable/repeatable 'unique' string - $results['search'][$result['id']] = $result; + // Add result to final results + $goosle_results['search'][$result['id']] = $result; } unset($result, $result_urls, $found_id, $social_media_multiplier, $goosle_rank, $match_rank); } + + // Count results per source + $goosle_results['sources'][$engine_result['source']] = $how_many_results; + + unset($how_many_results); } } } else { @@ -110,46 +126,49 @@ class MagnetSearch extends EngineRequest { $http_code_info = ($request_result['http_code'] > 200 && $request_result['http_code'] < 600) ? " - What's this?" : ""; $github_issue_url = "https://github.com/adegans/Goosle/discussions/new?category=general&".http_build_query(array('title' => get_class($request)." failed with error ".$request_result['http_code'], 'body' => "```\nEngine: ".get_class($request)."\nError Code: ".$request_result['http_code']."\nRequest url: ".$request_result['url']."\n```", 'labels' => 'request-error')); - $results['error'][] = array( + $goosle_results['error'][] = array( 'message' => "Ohno! A search query ran into some trouble. Usually you can try again in a few seconds to get a result!
Engine: ".get_class($request)."
Error code: ".$request_result['http_code'].$http_code_info."
Request url: ".$request_result['url']."
Need help? Find similar issues, or ask your own question." ); } unset($request); } + + if(array_key_exists('search', $goosle_results)) { + // Re-order results based on seeders + $keys = array_column($goosle_results['search'], 'combo_seeders'); + array_multisort($keys, SORT_DESC, $goosle_results['search']); + + // Count all results + $goosle_results['number_of_results'] = count($goosle_results['search']); + + unset($keys); + } else { + // Add error if there are no search results + $goosle_results['error'][] = array( + 'message' => "No results found. Please try with more specific or different keywords!" + ); + } } else { - $results['error'][] = array( - 'message' => "Configuration issue! It appears that all Magnet Search engines are disabled. Please enable at least one in your config.php file.
Need help? Find similar issues." + $goosle_results['error'][] = array( + 'message' => "It appears that all Magnet Search engines are disabled or that searching for magnet links is disabled." ); } - if(array_key_exists('search', $results)) { - // Re-order results based on seeders - $keys = array_column($results['search'], 'combo_seeders'); - array_multisort($keys, SORT_DESC, $results['search']); - - // Cap results - $results['search'] = array_slice($results['search'], 0, 200); - - unset($keys); - } else { - // Add error if there are no search results - $results['error'][] = array( - 'message' => "No results found. Please try with more specific or different keywords!" - ); - } - - return $results; + return $goosle_results; } - public static function print_results($results, $opts) { + public static function print_results($goosle_results, $search, $opts) { /* // Uncomment for debugging echo '
Settings: ';
 print_r($opts);
 echo '
'; +echo "
Search data: ";
+print_r($search);
+echo "
"; echo '
Search results: ';
-print_r($results);
+print_r($goosle_results);
 echo '
'; */ @@ -157,87 +176,73 @@ echo ''; if($opts->show_yts_highlight == 'on') { require ABSPATH.'engines/boxoffice/yts.php'; - echo "
"; echo "

Latest releases from YTS

"; - echo "

View these and more new releases on the query."&t=9&a=".$opts->hash."\">box office page!

"; - echo "
"; } // Main content - if(array_key_exists('search', $results)) { + if(array_key_exists('search', $goosle_results)) { // Is this a shared search? Move shared result to position 1 - if($opts->show_share_option == 'on' && !empty($opts->share)) { - $keys = array_keys($results['search']); - $found_id = array_search(md5($opts->share), $keys); // Return the shared key ID - $found_id = $keys[$found_id]; // Get the shared ID + if($opts->show_share_option == 'on' && !empty($search->share)) { + $keys = array_keys($goosle_results['search']); + $found_id = array_search(md5($search->share), $keys); // Return the shared key ID + $found_id = $keys[$found_id]; // Get the actual shared ID - $first = array($found_id => $results['search'][$found_id]); - unset($results['search'][$found_id], $keys, $found_id); + // Get the result + $first = array($found_id => $goosle_results['search'][$found_id]); + // Delete the result wherever it is + unset($goosle_results['search'][$found_id], $keys, $found_id); + // Add the result as the first item + $goosle_results['search'] = array_merge($first, $goosle_results['search']); + } - $results['search'] = array_merge($first, $results['search']); + // Pagination offset + if($opts->cache_type !== 'off') { + $offset = ((($search->page - 1) * $opts->search_results_per_page) + 1); + $goosle_results['search'] = array_slice($goosle_results['search'], $offset, $opts->search_results_per_page); } echo ""; - echo "
Goosle does not index, offer or distribute torrent files.
"; + + // Pagination navigation + if($opts->cache_type !== 'off' && $goosle_results['number_of_results'] > $opts->search_results_per_page) { + echo "

".search_pagination($search, $opts, $goosle_results['number_of_results'])."

"; + } + + echo "

Goosle does not index, offer or distribute torrent files.

"; } // No results found - if(array_key_exists('error', $results)) { - foreach($results['error'] as $error) { + if(array_key_exists('error', $goosle_results)) { + foreach($goosle_results['error'] as $error) { echo "
".$error['message']."
"; } } diff --git a/engines/search-news.php b/engines/search-news.php index c8d9a84..b3167ec 100644 --- a/engines/search-news.php +++ b/engines/search-news.php @@ -12,32 +12,34 @@ class NewsSearch extends EngineRequest { protected $requests, $special_request; - public function __construct($opts, $mh) { + public function __construct($search, $opts, $mh) { $this->requests = array(); - if($opts->enable_qwantnews == 'on') { - require ABSPATH.'engines/news/qwant-news.php'; - $this->requests[] = new QwantNewsRequest($opts, $mh); - } - - if($opts->enable_yahoonews == 'on') { - require ABSPATH.'engines/news/yahoo-news.php'; - $this->requests[] = new YahooNewsRequest($opts, $mh); - } - - if($opts->enable_bravenews == 'on') { - require ABSPATH.'engines/news/brave-news.php'; - $this->requests[] = new BraveNewsRequest($opts, $mh); - } - - if($opts->enable_hackernews == 'on') { - require ABSPATH.'engines/news/hackernews.php'; - $this->requests[] = new HackernewsRequest($opts, $mh); + if($opts->enable_news_search == 'on') { + if($opts->enable_qwantnews == 'on') { + require ABSPATH.'engines/news/qwant-news.php'; + $this->requests[] = new QwantNewsRequest($search, $opts, $mh); + } + + if($opts->enable_yahoonews == 'on') { + require ABSPATH.'engines/news/yahoo-news.php'; + $this->requests[] = new YahooNewsRequest($search, $opts, $mh); + } + + if($opts->enable_bravenews == 'on') { + require ABSPATH.'engines/news/brave-news.php'; + $this->requests[] = new BraveNewsRequest($search, $opts, $mh); + } + + if($opts->enable_hackernews == 'on') { + require ABSPATH.'engines/news/hackernews.php'; + $this->requests[] = new HackernewsRequest($search, $opts, $mh); + } } } public function parse_results($response) { - $results = array(); + $goosle_results = array(); if(count($this->requests) !== 0) { foreach($this->requests as $request) { @@ -45,72 +47,63 @@ class NewsSearch extends EngineRequest { $engine_result = $request->get_results(); if(!empty($engine_result)) { - if(array_key_exists('did_you_mean', $engine_result)) { - $results['did_you_mean'] = $engine_result['did_you_mean']; - } - - if(array_key_exists('search_specific', $engine_result)) { - $results['search_specific'][] = $engine_result['search_specific']; - } - - if(array_key_exists('search', $engine_result)) { - // Count results per source - $results['sources'][$engine_result['source']] = $engine_result['amount']; - + if(isset($engine_result['search'])) { + $how_many_results = 0; + $time = time(); + // Merge duplicates and apply relevance scoring foreach($engine_result['search'] as $result) { - if(array_key_exists('search', $results)) { - $result_urls = array_column($results['search'], 'url', 'id'); + if(isset($goosle_results['search'])) { + $result_urls = array_column($goosle_results['search'], 'url', 'id'); $found_id = array_search($result['url'], $result_urls); // Return the result ID, or false if not found } else { $found_id = false; } + $how_many_results++; $social_media_multiplier = (is_social_media($result['url'])) ? ($request->opts->social_media_relevance / 10) : 1; $goosle_rank = floor($result['engine_rank'] * floatval($social_media_multiplier)); if($found_id !== false) { // Duplicate result from another engine - $results['search'][$found_id]['goosle_rank'] += $goosle_rank; - $results['search'][$found_id]['combo_source'][] = $engine_result['source']; + $goosle_results['search'][$found_id]['goosle_rank'] += $goosle_rank; + $goosle_results['search'][$found_id]['combo_source'][] = $engine_result['source']; } else { // First find, rank and add to results - // Replace anything but alphanumeric with a space - $query_terms = explode(' ', preg_replace('/\s{2,}|[^a-z0-9]+/', ' ', strtolower($request->query))); - $match_rank = match_count($result['title'], $query_terms); - $match_rank += match_count($result['description'], $query_terms); - $match_rank += match_count($result['url'], $query_terms); + $match_rank = match_count($result['title'], $request->search->query_terms); + $match_rank += match_count($result['description'], $request->search->query_terms); + $match_rank += match_count($result['url'], $request->search->query_terms); - if($result['date_added'] > $request->opts->result_range) { - $time_rank = time() - $result['date_added']; - if($time_rank > 7776001) { // More than 3 months old - $match_rank += 1; - } elseif($time_rank > 3888001 && $time_rank < 7776000) { - $match_rank += 2; - } elseif($time_rank > 1209600 && $time_rank < 3888000) { - $match_rank += 4; - } elseif($time_rank > 604801 && $time_rank < 1209600) { - $match_rank += 6; - } elseif($time_rank > 86401 && $time_rank < 604800) { - $match_rank += 8; - } elseif($time_rank > 43201 && $time_rank < 86400) { - $match_rank += 10; - } elseif($time_rank > 32601 && $time_rank < 43200) { - $match_rank += 12; - } else { // Less than 6 hours old - $match_rank += 14; - } + $time_rank = $time - $result['timestamp']; + if($time_rank > 21600) { // Less than 6 hours old + $match_rank += 8; + } elseif($time_rank > 86400 && $time_rank < 21600) { // About a day old + $match_rank += 6; + } elseif($time_rank > 604800 && $time_rank < 86400) { // Less than a week old, but more than a day + $match_rank += 4; + } elseif($time_rank > 2592000 && $time_rank < 604800) { // Less than a month old, but more than a week + $match_rank += 4; + } elseif($time_rank > 31536000 && $time_rank < 2592000) { // Less than a year old, but more than a month + $match_rank += 2; + } else { // More than a year old + $match_rank += 1; } $result['goosle_rank'] = $goosle_rank + $match_rank; $result['combo_source'][] = $engine_result['source']; $result['id'] = md5($result['url']); - $results['search'][$result['id']] = $result; + // Add result to final results + $goosle_results['search'][$result['id']] = $result; } unset($result, $result_urls, $found_id, $social_media_multiplier, $goosle_rank, $match_rank, $time_rank, $query_terms); } + + // Count results per source + $goosle_results['sources'][$engine_result['source']] = $how_many_results; + + unset($how_many_results, $time); } } } else { @@ -118,84 +111,109 @@ class NewsSearch extends EngineRequest { $http_code_info = ($request_result['http_code'] > 200 && $request_result['http_code'] < 600) ? " - What's this?" : ''; $github_issue_url = "https://github.com/adegans/Goosle/discussions/new?category=general&".http_build_query(array('title' => get_class($request)." failed with error ".$request_result['http_code'], 'body' => "```\nEngine: ".get_class($request)."\nError Code: ".$request_result['http_code']."\nRequest url: ".$request_result['url']."\n```", 'labels' => 'request-error')); - $results['error'][] = array( + $goosle_results['error'][] = array( 'message' => "Ohno! A search query ran into some trouble. Usually you can try again in a few seconds to get a result!
Engine: ".get_class($request)."
Error code: ".$request_result['http_code'].$http_code_info."
Request url: ".$request_result['url']."
Need help? Find similar issues, or ask your own question." ); } unset($request); } + + if(array_key_exists('search', $goosle_results)) { + // Re-order results based on rank + $keys = array_column($goosle_results['search'], 'goosle_rank'); + array_multisort($keys, SORT_DESC, $goosle_results['search']); + + // Count all results + $goosle_results['number_of_results'] = count($goosle_results['search']); + + unset($keys); + } else { + // Add error if there are no search results + $goosle_results['error'][] = array( + 'message' => "No results found. Please try with more specific or different keywords!" + ); + } } else { - $results['error'][] = array( - 'message' => "Configuration issue! It appears that all Web Search engines are disabled. Please enable at least one in your config.php file.
Need help? Find similar issues." + $goosle_results['error'][] = array( + 'message' => "It appears that all News Search engines are disabled or that searching for news is disabled." ); } - if(array_key_exists('search', $results)) { - // Re-order results based on rank - $keys = array_column($results['search'], 'goosle_rank'); - array_multisort($keys, SORT_DESC, $results['search']); - - unset($keys); - } else { - // Add error if there are no search results - $results['error'][] = array( - 'message' => "No results found. Please try with more specific or different keywords!" - ); - } - - return $results; + return $goosle_results; } - public static function print_results($results, $opts) { + public static function print_results($goosle_results, $search, $opts) { /* // Uncomment for debugging echo '
Settings: ';
 print_r($opts);
 echo '
'; +echo "
Search data: ";
+print_r($search);
+echo "
"; echo '
Search results: ';
-print_r($results);
+print_r($goosle_results);
 echo '
'; */ - if(array_key_exists('search', $results)) { + if(array_key_exists('search', $goosle_results)) { + // Pagination offset + if($opts->cache_type !== 'off') { + $offset = ((($search->page - 1) * $opts->search_results_per_page) + 1); + $goosle_results['search'] = array_slice($goosle_results['search'], $offset, $opts->search_results_per_page); + } + echo ""; + + // Pagination navigation + if($opts->cache_type !== 'off' && $goosle_results['number_of_results'] > $opts->search_results_per_page) { + echo "

".search_pagination($search, $opts, $goosle_results['number_of_results'])."

"; + } } // Some error occured - if(array_key_exists('error', $results)) { - foreach($results['error'] as $error) { + if(array_key_exists('error', $goosle_results)) { + foreach($goosle_results['error'] as $error) { echo "
".$error['message']."
"; } } - unset($results); + unset($goosle_results); } } ?> \ No newline at end of file diff --git a/engines/search.php b/engines/search.php index 2773c9b..ec03210 100644 --- a/engines/search.php +++ b/engines/search.php @@ -12,67 +12,79 @@ class Search extends EngineRequest { protected $requests, $special_request; - public function __construct($opts, $mh) { + public function __construct($search, $opts, $mh) { $this->requests = array(); if($opts->enable_duckduckgo == 'on') { require ABSPATH.'engines/search/duckduckgo.php'; - $this->requests[] = new DuckDuckGoRequest($opts, $mh); + $this->requests[] = new DuckDuckGoRequest($search, $opts, $mh); } if($opts->enable_google == 'on') { require ABSPATH.'engines/search/google.php'; - $this->requests[] = new GoogleRequest($opts, $mh); + $this->requests[] = new GoogleRequest($search, $opts, $mh); } if($opts->enable_qwant == 'on') { require ABSPATH.'engines/search/qwant.php'; - $this->requests[] = new QwantRequest($opts, $mh); + $this->requests[] = new QwantRequest($search, $opts, $mh); } if($opts->enable_brave == 'on') { require ABSPATH.'engines/search/brave.php'; - $this->requests[] = new BraveRequest($opts, $mh); + $this->requests[] = new BraveRequest($search, $opts, $mh); } if($opts->enable_wikipedia == 'on') { require ABSPATH.'engines/search/wikipedia.php'; - $this->requests[] = new WikiRequest($opts, $mh); + $this->requests[] = new WikiRequest($search, $opts, $mh); } - // Special searches - $query_terms = explode(' ', $opts->query); - $query_terms[0] = strtolower($query_terms[0]); - + /* --- SPECIAL SEARCHES --- */ + // Currency converter - if($opts->special['currency'] == 'on' && count($query_terms) == 4 && (is_numeric($query_terms[0]) && ($query_terms[2] == 'to' || $query_terms[2] == 'in'))) { - require ABSPATH.'engines/special/currency.php'; - $this->special_request = new CurrencyRequest($opts, null); + if($opts->special['currency'] == 'on') { + if($search->count_terms == 4 && (is_numeric($search->query_terms[0]) && ($search->query_terms[2] == 'to' || $search->query_terms[2] == 'in'))) { + require ABSPATH.'engines/special/currency.php'; + $this->special_request = new CurrencyRequest($search, $opts, $mh); + } } // Dictionary - if($opts->special['definition'] == 'on' && count($query_terms) == 2 && ($query_terms[0] == 'define' || $query_terms[0] == 'd' || $query_terms[0] == 'mean' || $query_terms[0] == 'meaning')) { - require ABSPATH.'engines/special/definition.php'; - $this->special_request = new DefinitionRequest($opts, null); + if($opts->special['definition'] == 'on') { + if($search->count_terms == 2 && ($search->query_terms[0] == 'define' || $search->query_terms[0] == 'meaning')) { + require ABSPATH.'engines/special/definition.php'; + $this->special_request = new DefinitionRequest($search, $opts, $mh); + } } // IP Lookup - if($opts->special['ipaddress'] == 'on' && ($query_terms[0] == 'ip' || $query_terms[0] == 'myip' || $query_terms[0] == 'ipaddress')) { - require ABSPATH.'engines/special/ipify.php'; - $this->special_request = new ipRequest($opts, null); + if($opts->special['ipaddress'] == 'on') { + if($search->count_terms == 1 && ($search->query_terms[0] == 'ip' || $search->query_terms[0] == 'myip' || $search->query_terms[0] == 'ipaddress')) { + require ABSPATH.'engines/special/ipify.php'; + $this->special_request = new ipRequest($search, $opts, $mh); + } } // php.net search - if($opts->special['phpnet'] == 'on' && count($query_terms) == 2 && $query_terms[0] == 'php') { - require ABSPATH.'engines/special/php.php'; - $this->special_request = new PHPnetRequest($opts, null); + if($opts->special['phpnet'] == 'on') { + if($search->count_terms == 2 && $search->query_terms[0] == 'php') { + require ABSPATH.'engines/special/php.php'; + $this->special_request = new PHPnetRequest($search, $opts, $mh); + } } - unset($query_terms); + // wordpress.org search + if($opts->special['wordpress'] == 'on') { + if(($search->count_terms == 2 && ($search->query_terms[0] == 'wordpress' || $search->query_terms[0] == 'wp')) || ($search->count_terms == 3 && ($search->query_terms[0] == 'wordpress' || $search->query_terms[0] == 'wp') && $search->query_terms[1] == 'hook')) { + require ABSPATH.'engines/special/wordpress.php'; + $this->special_request = new WordPressRequest($search, $opts, $mh); + } + } } public function parse_results($response) { - $results = array(); + $goosle_results = array(); if(count($this->requests) !== 0) { foreach($this->requests as $request) { @@ -80,51 +92,55 @@ class Search extends EngineRequest { $engine_result = $request->get_results(); if(!empty($engine_result)) { - if(array_key_exists('did_you_mean', $engine_result)) { - $results['did_you_mean'] = $engine_result['did_you_mean']; + if(isset($engine_result['did_you_mean'])) { + $goosle_results['did_you_mean'] = $engine_result['did_you_mean']; } - if(array_key_exists('search_specific', $engine_result)) { - $results['search_specific'][] = $engine_result['search_specific']; + if(isset($engine_result['search_specific'])) { + $goosle_results['search_specific'][] = $engine_result['search_specific']; } - if(array_key_exists('search', $engine_result)) { - // Count results per source - $results['sources'][$engine_result['source']] = $engine_result['amount']; - + if(isset($engine_result['search'])) { + $how_many_results = 0; + // Merge duplicates and apply relevance scoring foreach($engine_result['search'] as $result) { - if(array_key_exists('search', $results)) { - $result_urls = array_column($results['search'], 'url', 'id'); + if(isset($goosle_results['search'])) { + $result_urls = array_column($goosle_results['search'], 'url', 'id'); $found_id = array_search($result['url'], $result_urls); // Return the result ID, or false if not found } else { $found_id = false; } + $how_many_results++; $social_media_multiplier = (is_social_media($result['url'])) ? ($request->opts->social_media_relevance / 10) : 1; $goosle_rank = floor($result['engine_rank'] * floatval($social_media_multiplier)); if($found_id !== false) { // Duplicate result from another engine - $results['search'][$found_id]['goosle_rank'] += $goosle_rank; - $results['search'][$found_id]['combo_source'][] = $engine_result['source']; + $goosle_results['search'][$found_id]['goosle_rank'] += $goosle_rank; + $goosle_results['search'][$found_id]['combo_source'][] = $engine_result['source']; } else { // First find, rank and add to results - // Replace anything but alphanumeric with a space - $query_terms = explode(' ', preg_replace('/\s{2,}|[^a-z0-9]+/', ' ', strtolower($request->query))); - $match_rank = match_count($result['title'], $query_terms); - $match_rank += match_count($result['description'], $query_terms); - $match_rank += match_count($result['url'], $query_terms); - + $match_rank = match_count($result['title'], $request->search->query_terms); + $match_rank += match_count($result['description'], $request->search->query_terms); + $match_rank += match_count($result['url'], $request->search->query_terms); + $result['goosle_rank'] = $goosle_rank + $match_rank; $result['combo_source'][] = $engine_result['source']; $result['id'] = md5($result['url']); - $results['search'][$result['id']] = $result; + // Add result to final results + $goosle_results['search'][$result['id']] = $result; } unset($result, $result_urls, $found_id, $social_media_multiplier, $goosle_rank, $match_rank, $query_terms); } + + // Count results per source + $goosle_results['sources'][$engine_result['source']] = $how_many_results; + + unset($how_many_results); } } } else { @@ -132,120 +148,141 @@ class Search extends EngineRequest { $http_code_info = ($request_result['http_code'] > 200 && $request_result['http_code'] < 600) ? " - What's this?" : ''; $github_issue_url = "https://github.com/adegans/Goosle/discussions/new?category=general&".http_build_query(array('title' => get_class($request).' failed with error '.$request_result['http_code'], 'body' => "```\nEngine: ".get_class($request)."\nError Code: ".$request_result['http_code']."\nRequest url: ".$request_result['url']."\n```", 'labels' => 'request-error')); - $results['error'][] = array( + $goosle_results['error'][] = array( 'message' => "Ohno! A search query ran into some trouble. Usually you can try again in a few seconds to get a result!
Engine: ".get_class($request)."
Error code: ".$request_result['http_code'].$http_code_info."
Request url: ".$request_result['url']."
Need help? Find similar issues, or ask your own question." ); } unset($request); } + + // Check for Special result + if($this->special_request) { + $special_result = $this->special_request->get_results(); + + if($special_result) { + $goosle_results['special'] = $special_result; + } + + unset($special_result); + } + + if(array_key_exists('search', $goosle_results)) { + // Re-order results based on rank + $keys = array_column($goosle_results['search'], 'goosle_rank'); + array_multisort($keys, SORT_DESC, $goosle_results['search']); + + // Count all results + $goosle_results['number_of_results'] = count($goosle_results['search']); + + unset($keys); + } else { + // Add error if there are no search results + $goosle_results['error'][] = array( + 'message' => "No results found. Please try with more specific or different keywords!" + ); + } } else { - $results['error'][] = array( - 'message' => "Configuration issue! It appears that all Web Search engines are disabled. Please enable at least one in your config.php file.
Need help? Find similar issues." + $goosle_results['error'][] = array( + 'message' => "It appears that all Web Search engines are disabled. Please enable at least one in your config.php file." ); } - // Check for Special result - if($this->special_request) { - $special_result = $this->special_request->get_results(); - - if($special_result) { - $results['special'] = $special_result; - } - - unset($special_result); - } - - if(array_key_exists('search', $results)) { - // Re-order results based on rank - $keys = array_column($results['search'], 'goosle_rank'); - array_multisort($keys, SORT_DESC, $results['search']); - - unset($keys); - } else { - // Add error if there are no search results - $results['error'][] = array( - 'message' => "No results found. Please try with more specific or different keywords!" - ); - } - - return $results; + return $goosle_results; } - public static function print_results($results, $opts) { -/* + public static function print_results($goosle_results, $search, $opts) { // Uncomment for debugging +/* echo "
Settings: ";
 print_r($opts);
 echo "
"; +echo "
Search data: ";
+print_r($search);
+echo "
"; echo "
Search results: ";
-print_r($results);
+print_r($goosle_results);
 echo "
"; */ - if(array_key_exists('search', $results)) { + if(array_key_exists('search', $goosle_results)) { + // Pagination offset + if($opts->cache_type !== 'off') { + $offset = ((($search->page - 1) * $opts->search_results_per_page) + 1); + $goosle_results['search'] = array_slice($goosle_results['search'], $offset, $opts->search_results_per_page); + } + echo ""; + + // Pagination navigation + if($opts->cache_type !== 'off' && $goosle_results['number_of_results'] > $opts->search_results_per_page) { + echo "

".search_pagination($search, $opts, $goosle_results['number_of_results'])."

"; + } } // Some error occured - if(array_key_exists('error', $results)) { - foreach($results['error'] as $error) { + if(array_key_exists('error', $goosle_results)) { + foreach($goosle_results['error'] as $error) { echo "
".$error['message']."
"; } } - unset($results); + unset($goosle_results); } } ?> \ No newline at end of file diff --git a/engines/search/brave.php b/engines/search/brave.php index a3ec2cb..9c46959 100644 --- a/engines/search/brave.php +++ b/engines/search/brave.php @@ -11,27 +11,14 @@ ------------------------------------------------------------------------------------ */ class BraveRequest extends EngineRequest { public function get_request_url() { - $query = str_replace('%22', '\"', $this->query); - - // Safe search ignore (not supported) - if(preg_match('/(safe:)(on|off)/i', $query, $matches)) { - $query = trim(str_replace($matches[0], '', $query)); - } - unset($matches); - - // Is there no query left? Bail! - if(empty($query)) return false; - $url = 'https://search.brave.com/search?'.http_build_query(array( - 'q' => $query, // Search query + 'q' => $this->search->query, // Search query 'offset' => 0, // Start on 'page' 1 of results (0 = 1) 'show_local' => 0, // Localize results (0 = no localization) 'spellcheck' => 0, // No spellcheck on your query 'source' => 'web' // Where are you searching from? (Web) )); - unset($query); - return $url; } @@ -88,10 +75,8 @@ class BraveRequest extends EngineRequest { } // Base info - $number_of_results = count($engine_temp); - if($number_of_results > 0) { + if(!empty($engine_temp)) { $engine_result['source'] = 'Brave'; - $engine_result['amount'] = $number_of_results; $engine_result['search'] = $engine_temp; } diff --git a/engines/search/duckduckgo.php b/engines/search/duckduckgo.php index 18ee530..cc5e48d 100644 --- a/engines/search/duckduckgo.php +++ b/engines/search/duckduckgo.php @@ -11,29 +11,21 @@ ------------------------------------------------------------------------------------ */ class DuckDuckGoRequest extends EngineRequest { public function get_request_url() { - $query = str_replace('%22', '\"', $this->query); - // Safe search override - $safe = '-1'; - if(preg_match('/(safe:)(on|off)/i', $query, $matches)) { - if($matches[2] == 'on') $safe = '1'; - if($matches[2] == 'off') $safe = '-2'; - $query = trim(str_replace($matches[0], '', $query)); + if($this->search->safe == 0) { + $safe = '-2'; + } else if($this->search->safe == 2) { + $safe = '1'; + } else { + $safe = '-1'; } - unset($matches); - - // Is there no query left? Bail! - if(empty($query)) return false; // Set locale $language = (preg_match('/[a-z]{2}-[a-z]{2}/i', $this->opts->duckduckgo_language) && strlen($this->opts->duckduckgo_language) == 5) ? strtolower($this->opts->duckduckgo_language) : 'en_gb'; - // Is there no query left? Bail! - if(empty($query)) return false; - // All parameters and values: https://duckduckgo.com/duckduckgo-help-pages/settings/params/ $url = 'https://html.duckduckgo.com/html/?'.http_build_query(array( - 'q' => $query, // Search query + 'q' => $this->search->query, // Search query 'kp' => $safe, // Safe search (1 = on, -1 = moderate, -2 = off 'kl' => $language, // Language region 'kz' => '-1', // Instant answers (1 = on, -1 = off) @@ -48,7 +40,7 @@ class DuckDuckGoRequest extends EngineRequest { 'k1' => '-1' // Ads (1 = on, -1 = off) )); - unset($query, $safe, $language); + unset($safe, $language); return $url; } @@ -115,10 +107,8 @@ class DuckDuckGoRequest extends EngineRequest { } // Base info - $number_of_results = count($engine_temp); - if($number_of_results > 0) { + if(!empty($engine_temp)) { $engine_result['source'] = 'DuckDuckGo'; - $engine_result['amount'] = $number_of_results; $engine_result['search'] = $engine_temp; } diff --git a/engines/search/google.php b/engines/search/google.php index c759105..0c196aa 100644 --- a/engines/search/google.php +++ b/engines/search/google.php @@ -11,24 +11,10 @@ ------------------------------------------------------------------------------------ */ class GoogleRequest extends EngineRequest { public function get_request_url() { - $query = str_replace('%22', '\"', $this->query); - - // Safe search override - $safe = '1'; - if(preg_match('/(safe:)(on|off)/i', $query, $matches)) { - if($matches[2] == 'on') $safe = '2'; - if($matches[2] == 'off') $safe = '0'; - $query = trim(str_replace($matches[0], '', $query)); - } - unset($matches); - - // Is there no query left? Bail! - if(empty($query)) return false; - // Including the preferred language variable breaks the page result, and with that the crawler! $url = 'https://www.google.com/search?'.http_build_query(array( - 'q' => $query, // Search query - 'safe' => $safe, // Safe search (0 = off, 1 = moderate, 2 = on/strict) + 'q' => $this->search->query, // Search query + 'safe' => $this->search->safe, // Safe search (0 = off, 1 = moderate, 2 = on/strict) 'num' => 30, // Number of results per page 'pws' => 0, // Personalized search results (0 = off) 'udm' => 14, // A view for simpler/non-ai results @@ -37,8 +23,6 @@ class GoogleRequest extends EngineRequest { 'sclient' => 'web' // Where are you searching from )); - unset($query, $safe); - return $url; } @@ -105,10 +89,8 @@ class GoogleRequest extends EngineRequest { } // Base info - $number_of_results = count($engine_temp); - if($number_of_results > 0) { + if(!empty($engine_temp)) { $engine_result['source'] = 'Google'; - $engine_result['amount'] = $number_of_results; $engine_result['search'] = $engine_temp; } diff --git a/engines/search/qwant.php b/engines/search/qwant.php index c49f3ce..c80091c 100644 --- a/engines/search/qwant.php +++ b/engines/search/qwant.php @@ -11,34 +11,20 @@ ------------------------------------------------------------------------------------ */ class QwantRequest extends EngineRequest { public function get_request_url() { - $query = str_replace('%22', '\"', $this->query); - - // Safe search override - $safe = '1'; // Moderate results - if(preg_match('/(safe:)(on|off)/i', $query, $matches)) { - if($matches[2] == 'on') $safe = '2'; - if($matches[2] == 'off') $safe = '0'; - $query = trim(str_replace($matches[0], '', $query)); - } - unset($matches); - // Set locale $language = (preg_match('/[a-z]{2}_[a-z]{2}/i', $this->opts->qwant_language) && strlen($this->opts->qwant_language) == 5) ? strtolower($this->opts->qwant_language) : 'en_gb'; - // Is there no query left? Bail! - if(empty($query)) return false; - // Based on https://github.com/locness3/qwant-api-docs and variables from qwant website $url = 'https://api.qwant.com/v3/search/web?'.http_build_query(array( - 'q' => $query, // Search query + 'q' => $this->search->query, // Search query 't' => 'web', // Type of search, web search - 'safesearch' => $safe, // Safe search filter (0 = off, 1 = normal, 2 = strict) + 'safesearch' => $this->search->safe, // Safe search filter (0 = off, 1 = normal, 2 = strict) 'locale' => $language, // In which language should the search be done 'count' => 10, // How many results? (Maximum 10) 'device' => 'desktop' // What kind of device are we searching from? )); - unset($query, $safe, $language); + unset($query, $language); return $url; } @@ -89,10 +75,8 @@ class QwantRequest extends EngineRequest { } // Base info - $number_of_results = count($engine_temp); - if($number_of_results > 0) { + if(!empty($engine_temp)) { $engine_result['source'] = 'Qwant'; - $engine_result['amount'] = $number_of_results; $engine_result['search'] = $engine_temp; } diff --git a/engines/search/wikipedia.php b/engines/search/wikipedia.php index 95fc92d..04e86e5 100644 --- a/engines/search/wikipedia.php +++ b/engines/search/wikipedia.php @@ -11,30 +11,19 @@ ------------------------------------------------------------------------------------ */ class WikiRequest extends EngineRequest { public function get_request_url() { - $query = str_replace('%22', '\"', $this->query); - - // Safe search ignore - if(preg_match('/(safe:)(on|off)/i', $query, $matches)) { - $query = trim(str_replace($matches[0], '', $query)); - } - unset($matches); - // Set locale $language = (strlen($this->opts->wikipedia_language) == 2) ? strtolower($this->opts->wikipedia_language) : 'en'; - // Is there no query left? Bail! - if(empty($query)) return false; - // Variables based on https://www.mediawiki.org/wiki/API:Search $url = 'https://'.$language.'.wikipedia.org/w/api.php?'.http_build_query(array( - 'srsearch' => $query, // Search query + 'srsearch' => $this->search->query, // Search query 'action' => 'query', // Search type (via a query?) 'list' => 'search', // Full text search 'format' => 'json', // Return format (Must be json) 'srlimit' => 10 // How many search results to get, ideally as few as possible since it's just static wiki pages (max 500) )); - unset($query, $language); + unset($language); return $url; } @@ -79,10 +68,8 @@ class WikiRequest extends EngineRequest { } // Base info - $number_of_results = count($engine_temp); - if($number_of_results > 0) { + if(!empty($engine_temp)) { $engine_result['source'] = 'Wikipedia'; - $engine_result['amount'] = $number_of_results; $engine_result['search'] = $engine_temp; } diff --git a/engines/special/currency.php b/engines/special/currency.php index 122a337..2994325 100644 --- a/engines/special/currency.php +++ b/engines/special/currency.php @@ -43,11 +43,10 @@ class CurrencyRequest extends EngineRequest { // [2] = (to|in) // [3] = TO CURRENCY - $query_terms = explode(' ', $this->query); - $amount = floatval($query_terms[0]); - $amount_currency = strtoupper($query_terms[1]); - $conversion_currency = strtoupper($query_terms[3]); - $last_update = date('M d, Y H:i:s', timezone_offset(strtotime(sanitize($json_response['lastupdate'])), $this->opts->timezone)); + $amount = floatval($this->search->query_terms[0]); + $amount_currency = strtoupper($this->search->query_terms[1]); + $conversion_currency = strtoupper($this->search->query_terms[3]); + $last_update = the_date('M d, Y H:i', strtotime(sanitize($json_response['lastupdate']))); // Unknown/misspelled currencies if(!array_key_exists($amount_currency, $json_response['rates']) || !array_key_exists($conversion_currency, $json_response['rates'])) { @@ -58,13 +57,14 @@ class CurrencyRequest extends EngineRequest { $conversion = round(($json_response['rates'][$conversion_currency] / $json_response['rates'][$amount_currency]) * $amount, 2); $one_to_n = round(($json_response['rates'][$conversion_currency] / $json_response['rates'][$amount_currency]) * 1, 2); + // Return result $engine_result = array( 'title' => "Currency conversion: ".$amount." ".$amount_currency." = ".$conversion." ".$conversion_currency, - 'text' => "

1 $amount_currency = $one_to_n $conversion_currency

Updated: $last_update (GMT/UTC+0)

", + 'text' => "

1 ".$amount_currency." = ".$one_to_n." ".$conversion_currency."

Updated: ".$last_update."

", 'source' => "https://moneyconvert.net/" ); - unset($response, $json_response, $query_terms, $amount, $amount_currency, $conversion, $one_to_n, $conversion_currency, $last_update); + unset($response, $json_response, $amount, $amount_currency, $conversion, $one_to_n, $conversion_currency, $last_update); return $engine_result; } diff --git a/engines/special/definition.php b/engines/special/definition.php index d16ac84..717991a 100644 --- a/engines/special/definition.php +++ b/engines/special/definition.php @@ -11,18 +11,9 @@ ------------------------------------------------------------------------------------ */ class DefinitionRequest extends EngineRequest { public function get_request_url() { - $query = str_replace('%22', '\"', $this->query); - $query_terms = explode(' ', $query); - - // [0] = (define|d|mean|meaning) + // [0] = (define|meaning) // [1] = WORD - - // Is there no query left? Bail! - if(empty($query)) return false; - - $url = 'https://api.dictionaryapi.dev/api/v2/entries/en/'.$query_terms[1]; - - unset($query, $query_terms); + $url = 'https://api.dictionaryapi.dev/api/v2/entries/en/'.$this->search->query_terms[1]; return $url; } @@ -46,10 +37,12 @@ class DefinitionRequest extends EngineRequest { if(empty($json_response)) return $engine_result; // No results - if(!array_key_exists('title', $json_response)) return $engine_result; + if(isset($json_response['title']) && $json_response['title'] == 'No Definitions Found') return $engine_result; - // Grab first result if there are multiple - $result = $json_response[0]; + $result = $json_response[0]; // Always grab the first result + + // Incomplete listing? Bail! + if(!array_key_exists('word', $result)) return $engine_result; // Find a phonetic spelling if(isset($result['phonetic'])) { @@ -81,6 +74,7 @@ class DefinitionRequest extends EngineRequest { unset($meaning); } + // Return result $engine_result = array( 'title' => "Definition for: ".sanitize($result['word'])." [".sanitize($phonetic)."]", 'text' => $formatted_response, diff --git a/engines/special/ipify.php b/engines/special/ipify.php index 964db75..95fac79 100644 --- a/engines/special/ipify.php +++ b/engines/special/ipify.php @@ -34,10 +34,12 @@ class ipRequest extends EngineRequest { // No response if(empty($json_response)) return $engine_result; + // Return result $engine_result = array( 'title' => "Your IP Address: ".$_SERVER["REMOTE_ADDR"], - 'text' => "

All requests via Goosle use this as your IP Address: ".sanitize($json_response['ip'])."
Goosle is not a proxy server. This test does NOT guarantee any degree of privacy. Any site that you visit through Goosle Search Results will see your actual IP Address.

", - 'source' => "https://www.ipify.org/" + 'text' => "

All requests via Goosle use this as your IP Address: ".sanitize($json_response['ip'])."

", + 'source' => "https://www.ipify.org/", + 'note' => "Goosle is not a proxy server. Any website that you visit through Goosle Search Results will see your actual IP Address." ); unset($response, $json_response); diff --git a/engines/special/php.php b/engines/special/php.php index d6723c7..00087cb 100644 --- a/engines/special/php.php +++ b/engines/special/php.php @@ -11,14 +11,8 @@ ------------------------------------------------------------------------------------ */ class PHPnetRequest extends EngineRequest { public function get_request_url() { - $query = str_replace('%22', '\"', $this->query); - // Format query/url for php.net - $query = str_replace('php ', '', $query); - $query = str_replace('_', '-', $query); - - // Is there no query left? Bail! - if(empty($query)) return false; + $query = str_replace('_', '-', $this->search->query_terms[1]); $url = 'https://www.php.net/manual/function.'.urlencode($query).'.php'; @@ -41,31 +35,39 @@ class PHPnetRequest extends EngineRequest { if(!$xpath) return $engine_result; // Scrape the results - $scrape = $xpath->query("//div/section/div[@class='refentry']"); + $scrape = $xpath->query("//div[@class='refentry']"); // No results if(count($scrape) == 0) return $engine_result; - $query = str_replace('%22', '', $this->query); - $query = str_replace('php ', '', $query); - $query = str_replace('_', '-', $query); + $query = str_replace('_', '-', $this->search->query_terms[1]); - foreach($scrape as $result) { - $title = $xpath->query(".//div/h1[@class='refname']")[0]->textContent; - if(is_null($title)) return $engine_result; + // Process scrape + $title = $xpath->evaluate(".//div/h1[@class='refname']", $scrape[0]); + if($title->length == 0) return $engine_result; - $php_versions = $xpath->query(".//div/p[@class='verinfo']")[0]->textContent; - $purpose = $xpath->query(".//div/p[@class='refpurpose']")[0]->textContent; - $usage = $xpath->query(".//div[@class='refsect1 description']/div[@class='methodsynopsis dc-description']")[0]->textContent; - $summary = $xpath->query(".//div[@class='refsect1 description']/p[@class='para rdfs-comment']")[0]->textContent; + $php_versions = $xpath->evaluate(".//div/p[@class='verinfo']", $scrape[0]); + $purpose = $xpath->evaluate(".//div/p[@class='refpurpose']", $scrape[0]); + $usage = $xpath->evaluate(".//div[@class='refsect1 description']/div[@class='methodsynopsis dc-description']", $scrape[0]); + $summary = $xpath->evaluate(".//div[@class='refsect1 description']/p[@class='para rdfs-comment']", $scrape[0]); - $engine_result = array ( - // Required - 'title' => "Function: ".sanitize($title), - 'text' => "

".sanitize($php_versions)."

".sanitize($purpose)."

".highlight_string("", 1)."

".$summary."

", - 'source' => "https://www.php.net/manual/function.".urlencode($query).".php" - ); - } + $title = sanitize($title[0]->textContent); + $php_versions = ($php_versions->length > 0) ? sanitize($php_versions[0]->textContent) : ""; + $purpose = ($purpose->length > 0) ? sanitize($purpose[0]->textContent) : ""; + $usage = ($usage->length > 0) ? sanitize($usage[0]->textContent) : ""; + $summary = ($summary->length > 0) ? sanitize($summary[0]->textContent) : ""; + + // Clean up string + $usage = preg_replace(array('/\s{2,}/', '/[\t\n]/'), ' ', $usage); + + // Return result + $engine_result = array ( + // Required + 'title' => "Function: ".$title, + 'text' => "

".$php_versions."

".$purpose."

".highlight_string("", 1)."

".$summary."

", + 'source' => "https://www.php.net/manual/function.".urlencode($query).".php", + 'note' => "Description may be incomplete. Always check the documentation page for more information." + ); unset($response, $xpath, $scrape); return $engine_result; diff --git a/engines/special/wordpress.php b/engines/special/wordpress.php new file mode 100644 index 0000000..521dba7 --- /dev/null +++ b/engines/special/wordpress.php @@ -0,0 +1,92 @@ +search->query_terms[1] == 'hook') { + // https://developer.wordpress.org/reference/hooks/HOOK_OR_FILTER_NAME/ + $type = 'hooks'; + $query = $this->search->query_terms[2]; + } else { + // https://developer.wordpress.org/reference/functions/FUNCTION_NAME/ + $type = 'functions'; + $query = $this->search->query_terms[1]; + } + + + + $url = 'https://developer.wordpress.org/reference/'.$type.'/.'.urlencode($query).'/'; + + unset($query, $type); + + return $url; + } + + public function get_request_headers() { + return array( + 'Accept' => 'text/html, application/xhtml+xml, application/xml;q=0.8, */*;q=0.7' + ); + } + + public function parse_results($response) { + $engine_result = array(); + $xpath = get_xpath($response); + + // No response + if(!$xpath) return $engine_result; + + // Scrape the results + $scrape = $xpath->query("//div/main/article"); + + // No results + if(count($scrape) == 0) return $engine_result; + + if($this->search->query_terms[1] == 'hook') { + $type = 'hooks'; + $query = $this->search->query_terms[2]; + } else { + $type = 'functions'; + $query = $this->search->query_terms[1]; + } + + // Process scrape + $usage = $xpath->evaluate(".//h1[@class='wp-block-wporg-code-reference-title']", $scrape[0]); + if($usage->length == 0) return $engine_result; + + $purpose = $xpath->evaluate(".//section[@class='wp-block-wporg-code-reference-summary']", $scrape[0]); + $description = $xpath->evaluate(".//section[contains(@class, 'wp-block-wporg-code-reference-explanation')]/p[1]", $scrape[0]); + if($description->length == 0) $description = $xpath->evaluate(".//section[contains(@class, 'wp-block-wporg-code-reference-description')]/p[1]", $scrape[0]); + $introduced = $xpath->evaluate(".//section[@class='wp-block-wporg-code-reference-changelog']//tbody", $scrape[0]); + + $title = sanitize($query); + $purpose = ($purpose->length > 0) ? sanitize($purpose[0]->textContent) : ""; + $description = ($description->length > 0) ? sanitize($description[0]->textContent) : ""; + $usage = ($usage->length > 0) ? sanitize($usage[0]->textContent) : ""; + $introduced = ($introduced->length > 0) ? sanitize($introduced[0]->lastChild->firstElementChild->textContent) : "(Unknown)"; + + // Clean up string + $usage = preg_replace(array('/\s{2,}/', '/[\t\n]/'), ' ', $usage); + + // Return result + $engine_result = array ( + // Required + 'title' => ucfirst($type).": ".$title, + 'text' => "

Since WordPress ".$introduced."

".$purpose."

".highlight_string("", 1)."

".$description."

", + 'source' => "https://developer.wordpress.org/reference/".$type."/".urlencode($query)."/", + 'note' => "Description may be incomplete. Always check the documentation page for more information." + ); + unset($response, $xpath, $scrape); + + return $engine_result; + } +} +?> diff --git a/error.php b/error.php new file mode 100644 index 0000000..18c7224 --- /dev/null +++ b/error.php @@ -0,0 +1,50 @@ + + + + + Goosle Search + + + + + + + + + + + + + + + + + + + + + + +
+

You can't use Goosle without an authorization key!

+

Contact the website administrator for more information.

+
+ + \ No newline at end of file diff --git a/functions/oauth.php b/functions/oauth.php index 89d5f82..9953a3c 100644 --- a/functions/oauth.php +++ b/functions/oauth.php @@ -123,10 +123,10 @@ if(verify_hash($opts->hash_auth, $opts->hash, $auth)) { -Goosle"; -} -?> + +
Redirecting
+ + + \ No newline at end of file diff --git a/functions/search_engine.php b/functions/search_engine.php index ccef0f0..69cd575 100644 --- a/functions/search_engine.php +++ b/functions/search_engine.php @@ -10,12 +10,11 @@ * liability that might arise from its use. ------------------------------------------------------------------------------------ */ abstract class EngineRequest { - protected $query, $ch, $mh, $opts, $url, $headers; + protected $ch, $mh, $search, $opts, $url, $headers; - function __construct($opts, $mh) { - $this->query = $opts->query; + function __construct($search, $opts, $mh) { $this->mh = $mh; - // Must be in this order :-/ + $this->search = $search; $this->opts = $opts; $this->url = $this->get_request_url(); @@ -126,6 +125,6 @@ abstract class EngineRequest { return $results; } - public static function print_results($results, $opts) {} + public static function print_results($results, $search, $opts) {} } ?> \ No newline at end of file diff --git a/functions/tools-magnet.php b/functions/tools-magnet.php index 6362fac..dda754a 100644 --- a/functions/tools-magnet.php +++ b/functions/tools-magnet.php @@ -10,6 +10,103 @@ * liability that might arise from its use. ------------------------------------------------------------------------------------ */ +/*-------------------------------------- +// Magnet popup for movies and tv-shows +--------------------------------------*/ +function highlight_popup($opts_hash, $highlight) { + $meta = $magnet_meta = array(); + + $search_query = urlencode($highlight['title']." ".$highlight['year']); + + if(isset($highlight['category'])) $meta[] = "Genre: ".$highlight['category']; + if(isset($highlight['language'])) $meta[] = "Language: ".get_language($highlight['language']); + if(isset($highlight['year'])) $meta[] = "Released: ".$highlight['year']; + if(isset($highlight['rating'])) $meta[] = "Rating: ".movie_star_rating($highlight['rating'])." (".$highlight['rating']." / 10)"; + if(isset($highlight['mpa_rating'])) $meta[] = "MPA Rating: ".movie_mpa_rating($highlight['mpa_rating']); + + $output = "
"; + $output .= "
"; + $output .= "

".$highlight['title']."

"; + if(isset($highlight['summary'])) { + $output .= "

".$highlight['summary']."

"; + } + $output .= "

Search on GoosleFind more Magnet links

"; + if(!empty($meta)) { + $output .= "

".implode('
', $meta)."

"; + } + unset($meta); + + // List downloads + $output .= "

Downloads:

"; + $output .= "

"; + foreach($highlight['magnet_links'] as $magnet) { + if(isset($magnet['quality'])) $magnet_meta[] = $magnet['quality']; + if(isset($magnet['audio'])) $magnet_meta[] = $magnet['audio']; + if(isset($magnet['type'])) $magnet_meta[] = $magnet['type']; + $magnet_meta[] = human_filesize($magnet['filesize']); + + $output .= ""; + unset($magnet_meta); + } + $output .= "

"; + + $output .= "

Close

"; + $output .= "
"; + $output .= "
"; + + unset($highlight, $magnet, $magnet_meta); + + return $output; +} + +/*-------------------------------------- +// Detect NSFW results by keywords in the title +// True = nsfw, false = not nsfw +--------------------------------------*/ +function detect_nsfw($string) { + // Forbidden terms + //Basic pattern: ^cum[-_\s]?play(ing|ed|s)? + $nsfw_keywords = array( + '/(deepthroat|gangbang|cowgirl|dildo|fuck|cuckold|anal|humpfinger|kiss|pegg|fist|ballbust|twerk|dogg|squirt)(ing|ed|s)?/', + '/(yaoi|porn|gonzo|erotica|blowbang|bukkake|gokkun|onlyfans|fansly|manyvids|softcore|hardcore|latex|lingerie|interracial|bdsm|chastity|hogtied|kinky|bondage|shibari|hitachi|upskirt)/', + '/(cock|creampie|cameltoe|enema|nipple|sybian|vibrator|cougar|threesome|foursome|pornstar|escort)(s)?/', + '/(cmnf|cfnm|pov|cbt|bbw|pawg|ssbbw|joi|cei)/', + '/(blow|rim|foot|hand)job(s)?/', + '/(org|puss)(y|ies)\s?/', + '/hentai(ed)?/', + '/jerk(ing)?[-_\s]?off/', + '/tw(i|u)nk(s)?/', + '/cum(bot|ming|s)?/', + '/porn(hub)?/', + '/(m|g)ilf(s)?/', + '/clit(oris|s)?/', + '/tit(ties|s)/', + '/strap[-_\s]?on(ed|s)?/', + '/webcam(ming|s)?/', + '/doggy(style)?/', + '/(masturbat|penetrat)(e|ion|ing|ed)/', + '/face(fuck|sit)?(ing|ting|ed|s)?/', + '/gap(e|ing|ed)?/', + '/scissor(ing|ed)?/', + '/(fetish|penis|ass)(es)?/', + '/(fem|lez|male)dom/', + '/futa(nari)?/', + '/orgasm(ing|ed|s)?/', + '/(slave|pet)[-_\s]?play(ing|ed|s)?/', + '/submissive(d|s)?/', + '/tied[-_\s]?(up)?/', + '/glory[-_\s]?hole(d|s)?/', + '/swing(er|ers|ing)?/', + ); + + // Replace everything but letters with a space + $string = preg_replace('/\s{2,}|[^a-z0-9]+/', ' ', strtolower($string)); + + preg_replace($nsfw_keywords, '*', $string, -1 , $count); + + return ($count > 0) ? true : false; +} + /*-------------------------------------- // Depect video quality (720p/1080i etc.) // Try to standardize terms @@ -73,7 +170,9 @@ function find_video_codec($string) { $return[] = trim(strtoupper($hdr)); } - return implode(' ', $return); + if(count($return) > 0) return implode(' ', $return); + + return null; } /*-------------------------------------- @@ -123,7 +222,9 @@ function find_audio_codec($string) { $return[] = ucfirst(trim(strtolower($codec2))); } - return implode(' ', $return); + if(count($return) > 0) return implode(' ', $return); + + return null; } /*-------------------------------------- @@ -140,6 +241,37 @@ function movie_star_rating($rating) { return $star_rating; } +/*-------------------------------------- +// Create visual MPA rating for some magnet results +--------------------------------------*/ +function movie_mpa_rating($rating) { + // As described here: https://en.wikipedia.org/wiki/Motion_Picture_Association_film_rating_system + if($rating == "G") { + $rating = "G - General AudiencesSuitable for all ages."; + } else if("PG") { + $rating = "PG - Parental Guidance SuggestedMay not be suitable for children."; + } else if("PG-13") { + $rating = "PG-13 - Parents Strongly CautionedMay be inappropriate for children under 13."; + } else if("R") { + $rating = "R - RestrictedPersons under 17 require accompanying adult."; + } else if("NC-17") { + $rating = "NC-17 - Adults OnlyNot suitable for persons under 17."; + } else { + $rating = "".$rating.""; + } + + return $rating; +} + +/*-------------------------------------- +// Return the language based on the ISO name +--------------------------------------*/ +function get_language($string) { + $languages = array("ab" => "Abkhaz", "aa" => "Afar", "af" => "Afrikaans", "ak" => "Akan", "sq" => "Albanian", "am" => "Amharic", "ar" => "Arabic", "an" => "Aragonese", "hy" => "Armenian", "as" => "Assamese", "av" => "Avaric", "ae" => "Avestan", "ay" => "Aymara", "az" => "Azerbaijani", "bm" => "Bambara", "ba" => "Bashkir", "eu" => "Basque", "be" => "Belarusian", "bn" => "Bengali", "bh" => "Bihari", "bi" => "Bislama", "bs" => "Bosnian", "br" => "Breton", "bg" => "Bulgarian", "my" => "Burmese", "ca" => "Catalan", "ch" => "Chamorro", "ce" => "Chechen", "ny" => "Nyanja", "zh" => "Chinese", "cn" => "Chinese", "cv" => "Chuvash", "kw" => "Cornish", "co" => "Corsican", "cr" => "Cree", "hr" => "Croatian", "cs" => "Czech", "da" => "Danish", "dv" => "Maldivian;", "nl" => "Dutch", "en" => "English", "eo" => "Esperanto", "et" => "Estonian", "ee" => "Ewe", "fo" => "Faroese", "fj" => "Fijian", "fi" => "Finnish", "fr" => "French", "ff" => "Fulah", "gl" => "Galician", "ka" => "Georgian", "de" => "German", "el" => "Greek, Modern", "gn" => "Guaraní", "gu" => "Gujarati", "ht" => "Haitian Creole", "ha" => "Hausa", "he" => "Hebrew (modern)", "hz" => "Herero", "hi" => "Hindi", "ho" => "Hiri Motu", "hu" => "Hungarian", "ia" => "Interlingua", "id" => "Indonesian", "ie" => "Interlingue", "ga" => "Irish", "ig" => "Igbo", "ik" => "Inupiaq", "io" => "Ido", "is" => "Icelandic", "it" => "Italian", "iu" => "Inuktitut", "ja" => "Japanese", "jv" => "Javanese", "kl" => "Kalaallisut", "kn" => "Kannada", "kr" => "Kanuri", "ks" => "Kashmiri", "kk" => "Kazakh", "km" => "Khmer", "ki" => "Kikuyu", "rw" => "Kinyarwanda", "ky" => "Kirghiz, Kyrgyz", "kv" => "Komi", "kg" => "Kongo", "ko" => "Korean", "ku" => "Kurdish", "kj" => "Kwanyama", "la" => "Latin", "lb" => "Luxembourgish", "lg" => "Luganda", "li" => "Limburgish, Limburgan, Limburger", "ln" => "Lingala", "lo" => "Lao", "lt" => "Lithuanian", "lu" => "Luba-Katanga", "lv" => "Latvian", "gv" => "Manx", "mk" => "Macedonian", "mg" => "Malagasy", "ms" => "Malay", "ml" => "Malayalam", "mt" => "Maltese", "mi" => "Māori", "mr" => "Marathi", "mh" => "Marshallese", "mn" => "Mongolian", "na" => "Nauru", "nv" => "Navajo, Navaho", "nb" => "Norwegian Bokmål", "nd" => "North Ndebele", "ne" => "Nepali", "ng" => "Ndonga", "nn" => "Norwegian Nynorsk", "no" => "Norwegian", "ii" => "Nuosu", "nr" => "South Ndebele", "oc" => "Occitan", "oj" => "Ojibwe, Ojibwa", "cu" => "Old Slavonic", "om" => "Oromo", "or" => "Oriya", "os" => "Ossetian", "pa" => "Punjabi", "pi" => "Pāli", "fa" => "Persian", "pl" => "Polish", "ps" => "Pashto, Pushto", "pt" => "Portuguese", "qu" => "Quechua", "rm" => "Romansh", "rn" => "Kirundi", "ro" => "Romanian", "ru" => "Russian", "sa" => "Sanskrit", "sc" => "Sardinian", "sd" => "Sindhi", "se" => "Northern Sami", "sm" => "Samoan", "sg" => "Sango", "sr" => "Serbian", "gd" => "Gaelic", "sn" => "Shona", "si" => "Sinhala", "sk" => "Slovak", "sl" => "Slovene", "so" => "Somali", "st" => "Southern Sotho", "es" => "Spanish", "su" => "Sundanese", "sw" => "Swahili", "ss" => "Swati", "sv" => "Swedish", "ta" => "Tamil", "te" => "Telugu", "tg" => "Tajik", "th" => "Thai", "ti" => "Tigrinya", "bo" => "Tibetan Standard, Tibetan, Central", "tk" => "Turkmen", "tl" => "Tagalog", "tn" => "Tswana", "to" => "Tonga", "tr" => "Turkish", "ts" => "Tsonga", "tt" => "Tatar", "tw" => "Twi", "ty" => "Tahitian", "ug" => "Uighur, Uyghur", "uk" => "Ukrainian", "ur" => "Urdu", "uz" => "Uzbek", "ve" => "Venda", "vi" => "Vietnamese", "vo" => "Volapük", "wa" => "Walloon", "cy" => "Welsh", "wo" => "Wolof", "fy" => "Western Frisian", "xh" => "Xhosa", "yi" => "Yiddish", "yo" => "Yoruba", "za" => "Zhuang, Chuang"); + + return $languages[$string]; +} + /*-------------------------------------- // Detect TV show Seasons and Episodes in results --------------------------------------*/ @@ -154,5 +286,4 @@ function is_season_or_episode($search_query, $result_query) { return true; } - ?> \ No newline at end of file diff --git a/functions/tools-update.php b/functions/tools-update.php deleted file mode 100644 index 78684fb..0000000 --- a/functions/tools-update.php +++ /dev/null @@ -1,80 +0,0 @@ - $current_version, 'latest' => '0.0', 'checked' => 0, 'url' => ''); - file_put_contents($cache_file, serialize($version)); - } else { - // Get update information - $version = unserialize(file_get_contents($cache_file)); - } - - // TODO: Remove in a future version - if(!isset($version['current'])) $version['current'] = "1.5.1"; - - // Update check, every week - if($version['checked'] < time() - 604800) { - $response = do_curl_request( - 'https://api.github.com/repos/adegans/goosle/releases/latest', // (string) Where? - array('Accept: application/json, */*;q=0.7', 'User-Agent: goosle/'.$version['current'].';'), // (array) User agent + Headers - 'get', // (string) post/get - null // (assoc array|null) Post body - ); - $json_response = json_decode($response, true); - - // Got a response? Store it! - if(!empty($json_response)) { - // Update version info - $version = array('current' => $version['current'], 'latest' => $json_response['tag_name'], 'checked' => time(), 'url' => $json_response['html_url']); - file_put_contents($cache_file, serialize($version)); - } - } -} - -/*-------------------------------------- -// Show version in footer ---------------------------------------*/ -function show_version() { - $cache_file = ABSPATH.'cache/version.data'; - - if(is_file($cache_file)) { - // Get update information - $version = unserialize(file_get_contents($cache_file)); - - // TODO: Remove in a future version - if(!isset($version['current'])) $version['current'] = "1.5.1"; - - // Format current version for footer - $show_version = "Goosle ".$version['current']."."; - - // Check if a newer version is available and add it to the version display - if(version_compare($version['current'], $version['latest'], '<')) { - $show_version .= " Version ".$version['latest']." is available!"; - } - } else { - // If the update cache doesn't exist... - $show_version = "Goosle."; - } - - return $show_version; -} -?> \ No newline at end of file diff --git a/functions/tools.php b/functions/tools.php index 6a1072f..cf14418 100644 --- a/functions/tools.php +++ b/functions/tools.php @@ -13,8 +13,8 @@ /*-------------------------------------- // Verify the hash, or not, and let people in, or not --------------------------------------*/ -function verify_hash($use_hash, $hash, $auth) { - if(($use_hash == 'on' && strtolower($hash) === strtolower($auth)) || $use_hash == 'off') return true; +function verify_hash($use_hash, $hash, $auth, $is_shared = null) { + if(($use_hash == 'on' && strtolower($hash) === strtolower($auth)) || $use_hash == 'off' || !empty($is_shared)) return true; return false; } @@ -35,38 +35,143 @@ function load_opts() { $opts = require $config_file; // From the url/request - if(!isset($_REQUEST['s'])) { - $opts->query = (isset($_REQUEST['q'])) ? trim($_REQUEST['q']) : ''; - $opts->type = (isset($_REQUEST['t'])) ? sanitize($_REQUEST['t']) : 0; - $opts->user_auth = (isset($_REQUEST['a'])) ? sanitize($_REQUEST['a']) : ''; - $opts->share = ''; - } else { - $share_string = explode('||', base64_url_decode(sanitize($_REQUEST['s']))); - if(is_array($share_string) && count($share_string) === 4) { - $opts->query = trim($share_string[2]); - $opts->type = sanitize($share_string[0]); - $opts->user_auth = sanitize($share_string[1]); - $opts->share = sanitize($share_string[3]); - } - unset($share_string); - } - + $opts->user_auth = (isset($_REQUEST['a'])) ? sanitize($_REQUEST['a']) : ''; + $opts->pixel = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII='; + // Force a few defaults and safeguards if(empty($opts->colorscheme)) $opts->colorscheme = 'default'; if($opts->cache_type == 'file' && !is_dir(ABSPATH.'cache/')) $opts->cache_type = 'off'; if($opts->cache_type == 'apcu' && !function_exists('apcu_exists')) $opts->cache_type = 'off'; - if($opts->enable_image_search == 'off' && $opts->type == 1) $opts->type = 0; - if($opts->enable_magnet_search == 'off' && $opts->type == 9) $opts->type = 0; if($opts->cache_time < 1 || ($opts->cache_type == 'apcu' && $opts->cache_time > 8) || ($opts->cache_type == 'file' && $opts->cache_time > 48)) $opts->cache_time = 8; + if(!is_numeric($opts->search_results_per_page) || ($opts->search_results_per_page < 8 || $opts->search_results_per_page > 160)) $opts->social_media_relevance = 24; if(!is_numeric($opts->social_media_relevance) || ($opts->social_media_relevance > 10 || $opts->social_media_relevance < 0)) $opts->social_media_relevance = 8; - // Remove ! at the start of queries to prevent DDG Bangs (!g, !c and crap like that) - if(substr($opts->query, 0, 1) == '!') $opts->query = substr($opts->query, 1); - return $opts; } } +/*-------------------------------------- +// Process search query +--------------------------------------*/ +function load_search() { + global $opts; + + $search = new stdClass(); + + // From the url/request + if(!isset($_REQUEST['s'])) { + // Regular search + $search->query = (isset($_REQUEST['q'])) ? trim($_REQUEST['q']) : ''; + $search->type = (isset($_REQUEST['t'])) ? sanitize($_REQUEST['t']) : 0; + $search->share = null; + } else { + // Shared result + $share_string = explode('||', base64_url_decode(sanitize($_REQUEST['s']))); + if(is_array($share_string) && count($share_string) === 3) { + $search->query = sanitize($share_string[0]); + $search->type = sanitize($share_string[1]); + $search->share = sanitize($share_string[2]); + } else { + $search->query = ''; + $search->type = 0; + $search->share = null; + } + unset($share_string); + } + + // Set pagination page + $search->page = (isset($_REQUEST['p'])) ? sanitize($_REQUEST['p']) : 1; + + // Remove ! at the start of queries to prevent DDG Bangs (!g, !c and crap like that) + if(substr($search->query, 0, 1) == '!') $search->query = substr($search->query, 1); + + // Preserve quotes + $search->query = str_replace('%22', '\"', $search->query); + + // Special searches and filters + $search->query_terms = explode(' ', strtolower($search->query)); // Break up query + $search->count_terms = count($search->query_terms); // How many keywords? + + // Safe search override + // 0 = off, 1 = normal (default), 2 = on/strict + $search->safe = 1; + if($search->query_terms[0] == 'safe:on') { + $search->safe = 2; + $search->query = trim(str_replace($search->query_terms[0], '', $search->query)); + } + + if($search->query_terms[0] == 'safe:off' || $search->query_terms[0] == 'xxx' || $search->query_terms[0] == 'porn') { + $search->safe = 0; + $search->query = trim(str_replace($search->query_terms[0], '', $search->query)); + } + + // Maybe count stats? + if(!empty($search->query)) count_stats(); + + return $search; +} + +/*-------------------------------------- +// Do some stats +--------------------------------------*/ +function load_stats() { + $stats_file = ABSPATH.'cache/stats.data'; + + if(!is_file($stats_file)) { + // Create stats file if it doesn't exist + $stats = array('started' => mktime(0, 0, 0, date('m'), date('d'), date('Y')), 'days_active' => 0, 'all_queries' => 0, 'avg_per_day' => 0); + file_put_contents($stats_file, serialize($stats)); + } else { + // Get stats + $stats = unserialize(file_get_contents($stats_file)); + } + + return $stats; +} + +function count_stats() { + $stats = load_stats(); + + // Calculate average searches per day + $new_day = (mktime(0, 0, 0, date('m'), date('d'), date('Y')) - $stats['started']) / 86400; + if($new_day > $stats['days_active']) { + $stats['days_active'] = $stats['days_active'] + 1; + $stats['avg_per_day'] = $stats['all_queries'] / $stats['days_active']; + } + + // Count query + $stats['all_queries'] = $stats['all_queries'] + 1; + + // Save stats + $stats_file = ABSPATH.'cache/stats.data'; + file_put_contents($stats_file, serialize($stats)); +} + +/*-------------------------------------- +// Show version in footer +--------------------------------------*/ +function show_version() { + $version_file = ABSPATH.'cache/version.data'; + + if(is_file($version_file)) { + // Get version information + $version = unserialize(file_get_contents($version_file)); + + // Format current version for footer + $show_version = "Goosle ".$version['current']."."; + + // Check if a newer version is available and add it to the version display + if(version_compare($version['current'], $version['latest'], '<')) { + $show_version .= " Version ".$version['latest']." is available!"; + } + } else { + // If the update cache doesn't exist... + $show_version = "Goosle."; + } + + return $show_version; +} + /*-------------------------------------- // Standardized cURL requests that support both POST and GET // For Box Office, Update checks and oAUTH @@ -100,6 +205,7 @@ function do_curl_request($url, $headers, $method, $post_fields) { return $response; } + /*-------------------------------------- // Load pages into a DOM --------------------------------------*/ @@ -113,20 +219,6 @@ function get_xpath($response) { return $xpath; } -/*-------------------------------------- -// Format search result urls ---------------------------------------*/ -function get_formatted_url($url) { - $url = parse_url($url); - - $formatted_url = $url['scheme'] . '://' . $url['host']; - if(array_key_exists('path', $url)) { - $formatted_url .= str_replace('/', ' › ', urldecode(str_replace('%20', ' ', rtrim($url['path'], '/')))); - } - - return $formatted_url; -} - /*-------------------------------------- // Get Goosle's base url --------------------------------------*/ @@ -138,7 +230,7 @@ function get_base_url($siteurl) { } /*-------------------------------------- -// URL Safe base64 encoding +// URL Safe base64 encoding and decoding --------------------------------------*/ function base64_url_encode($input) { return strtr(base64_encode($input), '+/=', '-_.'); @@ -148,10 +240,6 @@ function base64_url_decode($input) { return base64_decode(strtr($input, '-_.', '+/=')); } -function share_encode($opts, $magnet_hash) { - return get_base_url($opts->siteurl).'/results.php?s='.base64_url_encode($opts->type.'||'.$opts->hash.'||'.$opts->query.'||'.$magnet_hash); -} - /*-------------------------------------- // Result Caching --------------------------------------*/ @@ -266,7 +354,7 @@ function strip_newlines($string) { return preg_replace('/
|\n/', '', $string); } -function limit_string_length($string, $length = 100, $append = '…') { +function limit_string_length($string, $length = 200, $append = '…') { $string = trim($string); if(str_word_count($string, 0) > $length) { @@ -317,9 +405,9 @@ function is_social_media($string) { || preg_match('/(?:https?:)?\/\/(?:[\w]+\.)?linkedin\.com\/(?P(company)|(school))\/(?P[A-z0-9-À-ÿ\.]+)\/?/', $string) || preg_match('/(?:https?:)?\/\/(?:[\w]+\.)?linkedin\.com\/feed\/update\/urn:li:activity:(?P[0-9]+)\/?/', $string) || preg_match('/(?:https?:)?\/\/(?:[\w]+\.)?linkedin\.com\/in\/(?P[\w\-\_À-ÿ%]+)\/?/', $string) -// || preg_match('/(?:https?:)?\/\/(?:[A-z]+\.)?youtube.com\/(?:c(?:hannel)?)\/(?P[A-z0-9-\_]+)\/?/', $string) + || preg_match('/(?:https?:)?\/\/(?:[A-z]+\.)?youtube.com\/(?:c(?:hannel)?)\/(?P[A-z0-9-\_]+)\/?/', $string) || preg_match('/(?:https?:)?\/\/(?:[A-z]+\.)?youtube.com\/(?:u(?:ser)?)\/(?P[A-z0-9]+)\/?/', $string) -// || preg_match('/(?:https?:)?\/\/(?:(?:www\.)?youtube\.com\/(?:watch\?v=|embed\/)|youtu\.be\/)(?P[A-z0-9\-\_]+)/', $string) + || preg_match('/(?:https?:)?\/\/(?:(?:www\.)?youtube\.com\/(?:watch\?v=|embed\/)|youtu\.be\/)(?P[A-z0-9\-\_]+)/', $string) ) return true; return false; @@ -328,23 +416,21 @@ function is_social_media($string) { /*-------------------------------------- // Search suggestions --------------------------------------*/ -function search_suggestion($opts, $results) { +function search_suggestion($search, $opts, $results) { $specific_result = $specific_result2 = ''; - if(array_key_exists('search_specific', $results)) { - if($opts->type == 3 && count($results['search_specific']) > 1) { - // Format query url - $search_specific_url2 = './results.php?q='.urlencode($results['search_specific'][1]).'&t='.$opts->type.'&a='.$opts->hash; - $specific_result2 = ' or '.$results['search_specific'][1].''; - } - - // Format query url - $search_specific_url = './results.php?q='.urlencode($results['search_specific'][0]).'&t='.$opts->type.'&a='.$opts->hash; - $specific_result = '
Or instead search for '.$results['search_specific'][0].''.$specific_result2.'.'; - - unset($search_specific_url, $search_specific_url2, $specific_result2); + if(($search->type == 0 || $search->type == 1) && count($results['search_specific']) > 1) { + // Format query url + $search_specific_url2 = "./results.php?q=".urlencode($results['search_specific'][1])."&t=".$search->type."&a=".$opts->hash; + $specific_result2 = " or ".$results['search_specific'][1].""; } + // Format query url + $search_specific_url = "./results.php?q=".urlencode($results['search_specific'][0])."&t=".$search->type."&a=".$opts->hash; + $specific_result = "Or instead search for ".$results['search_specific'][0]."".$specific_result2."."; + + unset($search_specific_url, $search_specific_url2, $specific_result2); + return $specific_result; } @@ -364,6 +450,46 @@ function search_sources($results) { return $sources; } +/*-------------------------------------- +// Format search result urls +--------------------------------------*/ +function search_formatted_url($url) { + $url = parse_url($url); + + $formatted_url = $url['scheme'] . '://' . $url['host']; + if(array_key_exists('path', $url)) { + $formatted_url .= str_replace('/', ' › ', urldecode(str_replace('%20', ' ', rtrim($url['path'], '/')))); + } + + return $formatted_url; +} + +/*-------------------------------------- +// Results pagination +--------------------------------------*/ +function search_pagination($search, $opts, $number_of_results) { + $number_of_pages = ceil($number_of_results / $opts->search_results_per_page); + + $pagination = ""; + + if($search->page > 1) { + $prev = $search->page - 1; + $pagination .= "siteurl)."/results.php?q=".urlencode($search->query)."&t=".$search->type."&a=".$opts->hash."&p=".$prev."\" title=\"Previous page\"> "; + } + + for($page = 1; $page <= $number_of_pages; $page++) { + $class = ($search->page == $page) ? "current" : ""; + $pagination .= "siteurl)."/results.php?q=".urlencode($search->query)."&t=".$search->type."&a=".$opts->hash."&p=".$page."\" class=\"".$class."\" title=\"To page ".$page."\">".$page." "; + } + + if($search->page < $number_of_pages) { + $next = $search->page + 1; + $pagination .= "siteurl)."/results.php?q=".urlencode($search->query)."&t=".$search->type."&a=".$opts->hash."&p=".$next."\" title=\"Next page\"> "; + } + + return $pagination; +} + /*-------------------------------------- // Find and replace the last comma in a string --------------------------------------*/ @@ -386,20 +512,29 @@ function human_filesize($bytes, $dec = 2) { return sprintf("%.{$dec}f ", $bytes / pow(1024, $factor)) . @$size[$factor]; } + /*-------------------------------------- -// Apply timezone setting +// Output and format dates in local time --------------------------------------*/ -function timezone_offset($timestamp, $timezone_offset) { - if(strpos($timezone_offset, 'UTC') === false) return $timestamp; - if($timezone_offset == 'UTC') return $timestamp; +function the_date($format, $timestamp = null) { + global $opts; + + $offset = preg_replace('/UTC\+?/i', '', $opts->timezone); + if(empty($offset)) $offset = 0; + + if(is_null($timestamp) || !is_numeric($timestamp)) $timestamp = time(); + + $hours = (int) $offset; + $minutes = ($offset - $hours); + + $sign = ($offset < 0) ? '-' : '+'; + $abs_hour = abs($hours); + $abs_mins = abs($minutes * 60); + + $datetime = date_create('@'.$timestamp); + $datetime->setTimezone(new DateTimeZone(sprintf('%s%02d:%02d', $sign, $abs_hour, $abs_mins))); - $timezone_offset = intval(substr($timezone_offset, 3)); - if($timezone_offset > 0) { - return abs($timestamp + (intval(substr($timezone_offset, 1)) * 3600)); - } - if($timezone_offset < 0) { - return abs($timestamp - (intval(substr($timezone_offset, 1)) * 3600)); - } + return $datetime->format($format); } /*-------------------------------------- diff --git a/goosle-cron.php b/goosle-cron.php index 0000dcb..5bf2417 100644 --- a/goosle-cron.php +++ b/goosle-cron.php @@ -3,10 +3,8 @@ if(!defined('ABSPATH')) define('ABSPATH', $_SERVER['DOCUMENT_ROOT'] . '/'); date_default_timezone_set('UTC'); require ABSPATH.'functions/tools.php'; -require ABSPATH.'functions/tools-update.php'; $opts = load_opts(); -$auth = (isset($_GET['a'])) ? sanitize($_GET['a']) : $opts->user_auth; /* ------------------------------------------------------------------------------------ * Goosle - The fast, privacy oriented search tool that just works. * @@ -18,24 +16,61 @@ $auth = (isset($_GET['a'])) ? sanitize($_GET['a']) : $opts->user_auth; * liability that might arise from its use. --------------------------------------------------------------------------------------- * Includes: -* - Checking for updates. -* - Clearing out old cached results when using the file cache. -* - Renewing access token for Openverse (Expires every 12 hours) +* - Check for updates. +* - Clear out old cached results when using the file cache. +* - Renew access token for Openverse (Expires every 12 hours) ------------------------------------------------------------------------------------ */ -if(verify_hash($opts->hash_auth, $opts->hash, $auth)) { - // Check for updates - check_update(); - echo "Update cache updated!
"; +if(verify_hash('on', $opts->hash, $opts->user_auth)) { + /*-------------------------------------- + // Do update check + --------------------------------------*/ + $version_file = ABSPATH.'cache/version.data'; + + // Currently installed version + $current_version = "1.6"; + if(!is_file($version_file)) { + // Create update cache file if it doesn't exist + $version = array('current' => $current_version, 'latest' => '0.0', 'checked' => 0, 'url' => ''); + file_put_contents($version_file, serialize($version)); + } else { + // Get update information + $version = unserialize(file_get_contents($version_file)); + } + + // Update check, every week + if($version['checked'] < time() - 604800) { + $response = do_curl_request( + 'https://api.github.com/repos/adegans/goosle/releases/latest', // (string) Where? + array('Accept: application/json, */*;q=0.7', 'User-Agent: goosle/'.$version['current'].';'), // (array) User agent + Headers + 'get', // (string) post/get + null // (assoc array|null) Post body + ); + $json_response = json_decode($response, true); + + // Got a response? Store it! + if(!empty($json_response)) { + // Update version info + $version = array('current' => $version['current'], 'latest' => $json_response['tag_name'], 'checked' => time(), 'url' => $json_response['html_url']); + file_put_contents($version_file, serialize($version)); + + echo "

- Checked for updates and update cache updated!

"; + } + } + + /*-------------------------------------- // Clear out old cached files? + --------------------------------------*/ if($opts->cache_type == 'file') { delete_cached_results($opts->cache_time); - echo "Expired file cache results deleted!
"; + echo "

- Expired file cache results deleted!

"; } - // Possibly renew the Openverse access token + /*-------------------------------------- + // Renew the Openverse access token + --------------------------------------*/ if($opts->enable_image_search == 'on' && $opts->enable_openverse == 'on') { $token_file = ABSPATH.'cache/token.data'; @@ -62,16 +97,16 @@ if(verify_hash($opts->hash_auth, $opts->hash, $auth)) { oauth_store_token($token_file, 'openverse', array('client_id' => $registration['client_id'], 'client_secret' => $registration['client_secret'], 'access_token' => $json_response['access_token'], 'expires' => $json_response['expires_in'])); - echo "New Openverse token stored!
"; + echo "

- New Openverse token stored!

"; } } unset($response, $json_response); } } } - echo "No errors on this page? We're done!
"; + echo "

Are there no errors on this page? We're done, you can close the tab/browser.

"; } else { - echo "Unauthorized!"; + echo "

!! Unauthorized !!

"; } exit; diff --git a/help.php b/help.php index 0078711..e278234 100644 --- a/help.php +++ b/help.php @@ -1,12 +1,4 @@ user_auth; /* ------------------------------------------------------------------------------------ * Goosle - The fast, privacy oriented search tool that just works. * @@ -17,6 +9,14 @@ $auth = (isset($_GET['a'])) ? sanitize($_GET['a']) : $opts->user_auth; * By using this code you agree to indemnify Arnan de Gans from any * liability that might arise from its use. ------------------------------------------------------------------------------------ */ + +if(!defined('ABSPATH')) define('ABSPATH', $_SERVER['DOCUMENT_ROOT'] . '/'); +date_default_timezone_set('UTC'); + +require ABSPATH.'functions/tools.php'; + +$opts = load_opts(); +$search = load_search(); ?> @@ -29,7 +29,7 @@ $auth = (isset($_GET['a'])) ? sanitize($_GET['a']) : $opts->user_auth; - + @@ -45,30 +45,30 @@ $auth = (isset($_GET['a'])) ? sanitize($_GET['a']) : $opts->user_auth; hash_auth, $opts->hash, $auth)) { +if(verify_hash($opts->hash_auth, $opts->hash, $opts->user_auth)) { ?>

Goosle

- " name="q" /> + " name="q" /> - - + +
@@ -85,8 +85,15 @@ if(verify_hash($opts->hash_auth, $opts->hash, $auth)) {

To try and provide the best results first. Goosle has a simple algorithm to rank results for Web and Image search. It works a little like a scoring system. A result with more points gets a higher ranking.

If a website or image is found through multiple search engines it will score higher. Also the amount of matching words in the title and SEO description and a few other bits and bops from the results are considered.

+

Safe search

+

Search defaults to Moderate Safe mode. To override the safe mode, prefix your search with safe:on or safe:off (example: safe:off geese gone wild).
On will use 'Strict' mode, while off will disable safe searching, this may yield results that are unsuitable for workspaces or minors.

+ + show_nsfw_magnets == 'off') { ?> +

The Not Suitable For Work (NSFW) filter for Magnet results is enabled. This is an attempt to hide adult content from results. Some search engines have categories that can be filtered out. Others rely on keyword matches. Goosle has an extensive list of 'dirty' keywords to try and find adult content and then ignore it. To override the setting use the safe:off, xxx or porn prefix.
+ For example: Search for xxx goose on goose action or safe:off dirty geese to include adult content in the results.

+ +

Web search

-

Search defaults to Moderate Safe mode. To override the safe mode, prefix your search with safe:on or safe:off (example: safe:on white goose).
On will use 'Strict' mode, while off will disable safe searching, this may yield results that are unsuitable for workspaces or minors.

Special Searches

special['currency'] == 'on') { ?> @@ -97,7 +104,7 @@ if(verify_hash($opts->hash_auth, $opts->hash, $auth)) { special['definition'] == 'on') { ?>

Word Definition

-

Look up the meaning of single words. Prefix the word you want to look up with any of the following keywords; d, define, mean or meaning.
+

Look up the meaning of single words. Prefix the word you want to look up with any of the following keywords; define, meaning.
For example: Searching for define goose will do a web search for 'goose' but will also show a dictionary definition highlighted above the search results.

@@ -113,6 +120,12 @@ if(verify_hash($opts->hash_auth, $opts->hash, $auth)) { For example: Searching for php in_array or php trim will show you a brief description, compatible PHP versions and the basic syntax for that function.

+ special['wordpress'] == 'on') { ?> +

WordPress documentation Search

+

Prefix your search with wordpress or wp to search on wordpress.org for a WordPress function. You can also search for hooks or filters by adding 'hook' as the 2nd keyword.
+ For example: Searching for wordpress the_content or wp hook admin_init will show you a brief description and the basic syntax for that function or hook/filter.

+ +

Note: Special Searches do not work for image, news and magnet search.

enable_image_search == 'on') { ?> @@ -120,15 +133,12 @@ if(verify_hash($opts->hash_auth, $opts->hash, $auth)) {

The number of results is not limited but typically yields about 60-100 images. If you've enabled Openverse and Qwant this number in creases a lot, optimally up-to about 150 images.

Goosle Image Search links directly to the web page where the image is displayed, but also tries to link to the actual image itself.

You can search for images in a general size by adding size:small, size:medium, size:large or size:xlarge to the beginning of your search query (example: size:small huge goose).

-

Image search defaults to Moderate Safe mode. To override the safe mode, prefix your search with safe:on or safe:off (example: safe:off geese gone wild).
On will use 'Strict' mode, while off will disable safe searching, this may yield results that are unsuitable for workspaces or minors.

The result counts for may seem off, for example you get 50 results with 20 from Qwant Images and 60 from Yahoo! Images. Logically this should mean you should see 80 results. However, this simply means that 30 results were found on both search engines and were merged, resulting in 50 results.

enable_news_search == 'on') { ?>

News search

-

Look for current and revent news through News Search. Search for any topic and you'll find news from the last month.

-

For current news prefix your search with today, now or yesterday or simply search for those single words if you want 'global' news for today. For example today where is the goose. You can also use recent, week, month, this month, year or this year. For example: recent geese migration.

-

Keep in mind: Using these limiting prefixes Goosle will filter out any results that are outside of your search which may result in less or no results at all.

+

Look for current and recent news through News Search. Search for any topic and you'll find news from the last 30 days. Search is loosely ranked by post date. Newer news ranks higher.

enable_magnet_search == 'on') { ?> @@ -138,17 +148,22 @@ if(verify_hash($opts->hash_auth, $opts->hash, $auth)) {

Goosle will try to provide useful information about the download, which includea; Seeders/Leechers, A link to the torrent page, Download Category, Release year. But may also include the Movie quality (720p, 4K etc.), Movie Runtime and the Download Size along with some other bits and bops if available. Not every website makes this available and all results take a best effort approach.

+

Searching for TV Shows

+

To do a specific search on The Pirate Bay and EZTV you search for IMDb Title IDs. These are numeric IDs prefixed with tt. This kind of search is useful when you're looking for a tv show that doesn't have a unique name, or simply if you want to use a specialized tracker for tv shows.

+

If you know the IMDb Title ID you can search for it through the Magnet search.

imdb_id_search == 'on') { ?> -

Searching for TV Shows

-

To do a specific search on The Pirate Bay and EZTV you search for IMDb Title IDs. These are numeric IDs prefixed with tt. This kind of search is useful when you're looking for a tv show that doesn't have a unique name, or simply if you want to use a specialized tracker for tv shows.

-

If you already know the Title ID you can search for it through the Magnet search.
- If you don't know the Title ID you can do a regular search for imdb [tv show name], for example imdb Duck and Goose.
+

If you don't know the Title ID you can do a regular search for imdb [tv show name], for example imdb Duck and Goose.
Goosle will detect the IMDb ID from the search results and highlight it in the result as a link. This link offers you to search for downloads through a Magnet Search.

show_share_option == 'on') { ?>

Sharing results

-

You can share a specific Magnet result by clicking on the share link that's behind the result information. In the little popup that opens you can copy the result and share or store it anywhere you can paste text - For example in a messenger. This special link will perform the same search as you did yourself and highlight the result that you want to share. Keep in mind that if you run a private installation of Goosle you might be giving uninvited guests access to it, so be mindful of where you post the link.

+

You can share a specific Magnet result by clicking on the share link that's behind the result information. In the popup that opens you can copy the link and share or store it anywhere you can paste text - For example in a messenger or note. This special link will perform the same search as you did yourself and highlight the result that you want to share.

+ hash_auth == 'off') { ?> +

The links can be shared with anyone since you do not run a private Goosle. Anyone who has the shared link can see the results.

+ +

The links can be shared with anyone but keep in mind that since you run a private installation you might be giving uninvited guests access to it. To prevent this from happening the share link does NOT include the passphrase hash. This means that any guests can see your shared results but searching for new things will not work for them.

+

Finding specific TV Show episodes and seasons

@@ -160,14 +175,14 @@ if(verify_hash($opts->hash_auth, $opts->hash, $auth)) {

The box office

Along with Magnet search a Box Office page also appears. This is an overview page of the latest movies and other new downloads available on a few supported torrent sites. The shown results are cached just like regular search results.

-

Note: The things you find through magnet search are not always legal to download due to copyright or local restrictions. If possible, always try to get a legal copy if you found a use for what you downloaded!

+

Note: The things you find through magnet search are not always legal to download due to copyright or local restrictions. If possible, try to get a legal copy if you found a use for what you downloaded!

Default search engine

-

In some browsers you can add a custom search engine. To do so use the following link: https://example.com/results.php?q=%s.

-

Or if you use the Auth Hash as a password add the a argument, like so: https://example.com/results.php?a=YOUR_HASH&q=%s.

+

In some browsers you can add a custom search engine. To do so follow the browsers instruction and use the following link: https://example.com/results.php?q=%s.

+

Or if you use the Auth Hash as a password add the a argument, like so: https://example.com/results.php?a=YOUR_HASH&q=%s. Obviously replace example.com with your actual goosle addesss.

-

Most browsers ask that you add %s for the search query as shown in the examples. If your browser has a different value for this simply replace %s with what your browser requires. +

Most browsers will instruct you to add %s for the search query as shown in the examples. If your browser has a different value for this simply replace %s with what your browser requires.

Colorschemes

Goose comes with several colorschemes, configurable through the config.php file.

@@ -177,7 +192,7 @@ if(verify_hash($opts->hash_auth, $opts->hash, $auth)) {
  • "default" A dark headers and main backgrounds with light search results.
  • "light" More light elements.
  • "dark" More dark elements, some apps would call this dark mode.
  • -
  • "auto" Let the browser decide what to use. This is typically linked to your device its darkmode setting.
  • +
  • "auto" Let the browser decide what to use. This is typically linked to the darkmode setting of your device.
  • Acknowledgements:
    Goosle started as a fork of LibreY, and takes some design cues from DuckDuckGo.com. Goosle is created by Arnan de Gans with the intent to make search more productive and fun.

    @@ -185,17 +200,17 @@ if(verify_hash($opts->hash_auth, $opts->hash, $auth)) { -Goosle"; -} -?> + +
    Redirecting
    + + + \ No newline at end of file diff --git a/index.php b/index.php index 5caf19e..d97ae34 100644 --- a/index.php +++ b/index.php @@ -1,10 +1,4 @@ user_auth; /* ------------------------------------------------------------------------------------ * Goosle - The fast, privacy oriented search tool that just works. * @@ -15,6 +9,12 @@ $auth = (isset($_GET['a'])) ? sanitize($_GET['a']) : $opts->user_auth; * By using this code you agree to indemnify Arnan de Gans from any * liability that might arise from its use. ------------------------------------------------------------------------------------ */ + +if(!defined('ABSPATH')) define('ABSPATH', $_SERVER['DOCUMENT_ROOT'] . '/'); + +require ABSPATH.'functions/tools.php'; + +$opts = load_opts(); ?> @@ -43,7 +43,7 @@ $auth = (isset($_GET['a'])) ? sanitize($_GET['a']) : $opts->user_auth; hash_auth, $opts->hash, $auth)) { +if(verify_hash($opts->hash_auth, $opts->hash, $opts->user_auth)) { ?>
    @@ -75,10 +75,10 @@ if(verify_hash($opts->hash_auth, $opts->hash, $auth)) {
    -Goosle"; -} -?> + +
    Redirecting
    + + + \ No newline at end of file diff --git a/readme.md b/readme.md index 60ffed6..2465947 100644 --- a/readme.md +++ b/readme.md @@ -1,10 +1,10 @@ -

    Goosle

    -

    The best Meta Search Engine to find everything

    +

    Goosle

    +

    The best Meta Search Engine to find everything

    Goosle is a fast, privacy oriented search tool that just works. \ It's kept simple so everyone can use it and to make sure it works on most webservers. -If you're tired of traditional results from one site like Google search or DuckDuckGo and want to see more at once, Goosle has your back! Goosle searches on several search engine at the same time and shows you the most relevant results through a neat, clean interface. Goosle has **no** distractions, **no** trackers, **no** cookies and **no** bloated libraries, frameworks, dependencies or other things that slow you down. +If you're tired of traditional results from one site like Google search or DuckDuckGo and want to see more at once, Goosle has your back! Goosle searches on several search engine at the same time and shows you the most relevant results through a neat, clean interface. Goosle has **no** distractions, **no** trackers, **no** cookies and **no** bloated libraries, frameworks, dependencies or other things that slow you down. Goosle does Image search which shows results from Yahoo! Images and Openverse. @@ -76,11 +76,12 @@ Execute this cronjob a couple of times per day, recommended is every 8 hours. Without it, Openverse access will expire and you have to generate a new key every few hours. For low traffic setups or if you do not use Openverse a longer interval of once a day is fine. -If you've enabled the access hash as a password, don't forget to include ?a=YOUR_HASH to the url. -Cron jobs are usually set up from your hosting dashboard, or through something like DirectAdmin, cPanel or WHM. +The access hash is always required as an access token, don't forget to include ?a=YOUR_HASH to the url. +Cron jobs are commonly set up from your hosting dashboard, or through something like DirectAdmin, cPanel or WHM. Ask your hosting provider where to find the Cron job scheduler or have them set it up for you if you don't see it. You can also use something like [cron-job.org](https://cron-job.org/) to trigger the background task remotely. +To test, you can also load the url in your browser and trigger the script that way. Look for the onscreen prompts to see what routines are executed. ### Usage examples Example for 10 minutes past every 3 hours \ @@ -92,7 +93,7 @@ Example for 5 minutes past every 8 hours (I use this on my Goosle) \ Example for every midnight \ `0 0 * * * wget -qO - https://example.com/goosle-cron.php?a=YOUR_HASH` -Why a few minutes past the hour? Because commonly people run stuff exactly on the hour or some other predictable interval like 15 or 30 minutes. Running things a few minutes later spreads server load. +Why a few minutes past the hour? Because most people run stuff exactly on the hour or some other predictable interval like 15 or 30 minutes. Running things a few minutes later spreads server load. ## Authorizing access to the Openverse search API This is required to use Openverse Image Search. @@ -121,9 +122,39 @@ You can post your questions on Github Discussions or say hi on [Mastodon](https: ### Known "issues" - Duckduckgo sometimes returns a 202 header and no results. I'm not sure what causes that but suspect it's something to do with quotas or a service limitation on their end. - Some crawlers for Magnet searches may return empty results. These are likely quota limits on their end. -- Sometimes TV Show episodes on the box office are not properly merged despite all required data matching. ## Changelog +1.6 - July 15, 2024 +- NOTICE: config.default.php has changed, update your config.php!! +- [change] Moved magnet popups into combined function +- [change] Better handling of EZTV TV Show data +- [change] Better handling of YTS movie data +- [change] Added 6 new public trackers for Magnets +- [change] Removed regularly unresponsive trackers for Magnets +- [change] Search query string processed before search so all engines don't have to do it individually +- [change] Updated help page +- [new] Special searches can have a note/disclaimer in the lower right corner +- [new] Results pagination for all search tabs (Requires caching to be enabled) +- [new] WordPress function, hook and filter lookup as a special search (See help page) +- [new] Language meta data for some Magnet results +- [new] Try to detect audio codec for EZTV results +- [new] Show MPA Rating for some movie results +- [new] Filter to include NSFW Magnet results or not +- [new] Override NSFW filter with prefix keywords (see config.php) +- [new] Simple search stat counter (Link in footer) +- [tweak] Muted the blue and white text in dark theme a tiny bit +- [tweak] Better light blue header in light theme +- [tweak] Added title and alt attributes to relevant links/images +- [tweak] Removed Magnet search limit of 200 results +- [fix] HTML rendering issues for `
    ` tags in paragraphs +- [fix] Start page buttons in light theme now use the right css variables +- [fix] Properly decode quotes in code snippers for PHP special search +- [fix] Image, News and Magnet search no longer work if they're disabled in config.php +- [fix] 2nd search suggestion not showing if it's available +- [fix] Removed non-functional checking if query is empty in every engine +- [fix] Correctly uses user provided auth hash to keep searching +- [fix] Correctly 'expire' share links for guests so they can not use Goosle beyond seeing the shared results + 1.5.1 - June 22, 2024 - [fix] Updated help.php, removed incorrect colorscheme information - [fix] Typo in text output for goosle-cron.php @@ -305,4 +336,4 @@ Goosle started as a fork of LibreY, and ended up as a rewrite and something diff Search results take design cues from DuckDuckGo and the magnet search has been modified to show more useful information where possible. \ Goosle does not index, store or distribute torrent files. If you like, or found a use for, what you downloaded, you should probably buy a legal copy of it. -The name Goosle comes from my last name with an L added in. Translate it from Dutch. \ No newline at end of file +The name Goosle comes from my last name with an L added in. Translate it from Dutch. diff --git a/results.php b/results.php index 9459c6a..235a678 100644 --- a/results.php +++ b/results.php @@ -1,17 +1,4 @@ user_auth; -$start_time = microtime(true); /* ------------------------------------------------------------------------------------ * Goosle - The fast, privacy oriented search tool that just works. * @@ -22,6 +9,16 @@ $start_time = microtime(true); * By using this code you agree to indemnify Arnan de Gans from any * liability that might arise from its use. ------------------------------------------------------------------------------------ */ + +if(!defined('ABSPATH')) define('ABSPATH', $_SERVER['DOCUMENT_ROOT'] . '/'); +date_default_timezone_set('UTC'); + +require ABSPATH.'functions/tools.php'; +require ABSPATH.'functions/search_engine.php'; + +$opts = load_opts(); +$search = load_search(); +$start_time = microtime(true); ?> @@ -34,7 +31,7 @@ $start_time = microtime(true); - + @@ -48,7 +45,7 @@ $start_time = microtime(true); type == "9") { + if($search->type == "9") { echo " "; } ?> @@ -56,53 +53,53 @@ $start_time = microtime(true); hash_auth, $opts->hash, $auth)) { +if(verify_hash($opts->hash_auth, $opts->hash, $opts->user_auth, $search->share)) { ?>

    Goosle

    - " name="q" /> + " name="q" /> - - + +
    query)) { +if(!empty($search->query)) { // Curl $mh = curl_multi_init(); // Load search script - if($opts->type == 0) { + if($search->type == 0) { require ABSPATH.'engines/search.php'; - $search = new Search($opts, $mh); - } else if($opts->type == 1) { + $search_results = new Search($search, $opts, $mh); + } else if($search->type == 1) { require ABSPATH.'engines/search-image.php'; - $search = new ImageSearch($opts, $mh); - } else if($opts->type == 2) { + $search_results = new ImageSearch($search, $opts, $mh); + } else if($search->type == 2) { require ABSPATH.'engines/search-news.php'; - $search = new NewsSearch($opts, $mh); - } else if($opts->type == 9) { + $search_results = new NewsSearch($search, $opts, $mh); + } else if($search->type == 9) { require ABSPATH.'engines/search-magnet.php'; - $search = new MagnetSearch($opts, $mh); + $search_results = new MagnetSearch($search, $opts, $mh); } $running = null; @@ -114,7 +111,7 @@ if(!empty($opts->query)) { } } while ($running && $status == CURLM_OK); - $results = $search->get_results(); + $results = $search_results->get_results(); curl_multi_close($mh); @@ -122,11 +119,11 @@ if(!empty($opts->query)) { $results['time'] = number_format(microtime(true) - $start_time, 5, '.', ''); // Echoes results and special searches - $search->print_results($results, $opts); + $search_results->print_results($results, $search, $opts); } else { echo "
    "; echo "

    Search query can not be empty!

    "; - echo "

    Not sure what went wrong? Learn more about hash."\" title=\"how to use Goosle!\">how to use Goosle.

    "; + echo "

    Not sure what went wrong? Learn more about user_auth."\" title=\"how to use Goosle!\">how to use Goosle.

    "; echo "
    "; } ?> @@ -134,17 +131,17 @@ if(!empty($opts->query)) { -Goosle
    "; -} -?> + +
    Redirecting
    + + + \ No newline at end of file diff --git a/stats.php b/stats.php new file mode 100644 index 0000000..ce0ce3e --- /dev/null +++ b/stats.php @@ -0,0 +1,99 @@ + + + + + Goosle Search Usage Stats + + + + + + + + + + + + + + + + + + + + + + +hash_auth, $opts->hash, $opts->user_auth)) { +?> +
    +
    +

    Goosle

    + " name="q" /> + + + +
    + + +
    + +
    +

    Searches

    +

    +

    Average per day

    +

    +
    + + + + +
    Redirecting
    + + + + + \ No newline at end of file