From c8022ee1be72d9980b3d3d7e191409d5aaee8fe2 Mon Sep 17 00:00:00 2001 From: Darko Date: Tue, 26 May 2015 16:05:42 +0200 Subject: [PATCH] Change site table to settings table, move files around and adjust to new settings table. patchDB needs to be fixed for the final patch is is used for. --- bin/fixreleasenames.php | 4 +- bin/groupfixrelnames.php | 4 +- bin/postprocess.php | 4 +- bin/update_groups.php | 4 +- bin/update_releases.php | 4 +- lib/DB/mysqldump_tables.php | 4 +- lib/DB/patchDB.php | 8 +- lib/copy_this/cli/update_db.php | 50 ++ lib/copy_this/cli/verify_permissions.php | 131 ++++ lib/copy_this/cli/versions.php | 52 ++ lib/copy_this/libs/Git.php/Git.php | 684 +++++++++++++++++ lib/copy_this/libs/Git.php/composer.json | 6 + lib/copy_this/libs/Git.php/license.txt | 708 ++++++++++++++++++ lib/copy_this/libs/Git.php/readme.md | 21 + .../libs/Git.php/test/test-suite.php | 170 +++++ .../misc/sphinxsearch/create_se_tables.php | 4 +- .../misc/sphinxsearch/populate_rt_indexes.php | 4 +- .../misc/sphinxsearch/toggle_search_type.php | 6 +- .../misc/testing/checkblanklinenzbs.php | 4 +- lib/copy_this/misc/testing/deletepreviews.php | 4 +- lib/copy_this/misc/testing/deletereleases.php | 4 +- lib/copy_this/misc/testing/dumpnfo.php | 2 +- lib/copy_this/misc/testing/fixTVRage.php | 2 +- lib/copy_this/misc/testing/fix_filesize.php | 4 +- lib/copy_this/misc/testing/fixreleasename.php | 2 +- lib/copy_this/misc/testing/getConsole.php | 4 +- lib/copy_this/misc/testing/getCovers.php | 4 +- lib/copy_this/misc/testing/getTVInfo.php | 4 +- lib/copy_this/misc/testing/movecat.php | 4 +- lib/copy_this/misc/testing/parread.php | 4 +- lib/copy_this/misc/testing/refreshMovie.php | 4 +- lib/copy_this/misc/testing/regexverify.php | 2 +- lib/copy_this/misc/testing/test_blacklist.php | 6 +- lib/copy_this/misc/testing/test_regex.php | 4 +- lib/copy_this/misc/testing/tidynzbfolder.php | 4 +- lib/copy_this/misc/testing/timetest.php | 4 +- .../misc/testing/transactiontest.php | 4 +- .../misc/testing/updateCategories.php | 4 +- lib/copy_this/misc/testing/updateTVRage.php | 4 +- lib/copy_this/misc/testing/updateviddef.php | 2 +- .../misc/update_scripts/backfill.php | 4 +- lib/copy_this/misc/update_scripts/import.php | 4 +- .../multiprocessing/.do_not_run/switch.php | 28 +- .../misc/update_scripts/nntpproxy.php | 4 +- .../misc/update_scripts/optimise_db.php | 4 +- .../misc/update_scripts/update_binaries.php | 4 +- .../update_database_version.php | 6 +- lib/copy_this/newznab/build/addGitHook.php | 109 +++ .../newznab/build/git-hooks/pre-commit | 52 ++ .../newznab/build/git-hooks/runHooks.php | 75 ++ lib/copy_this/newznab/build/newznab.xml | 17 + .../newznab/controllers/AdminPage.php | 4 +- lib/copy_this/newznab/controllers/AniDB.php | 9 +- .../newznab/controllers/Backfill.php | 14 +- .../newznab/controllers/BasePage.php | 20 +- .../newznab/controllers/Binaries.php | 6 +- lib/copy_this/newznab/controllers/Book.php | 10 +- lib/copy_this/newznab/controllers/Books.php | 20 +- lib/copy_this/newznab/controllers/Captcha.php | 10 +- .../newznab/controllers/Categorize.php | 6 +- .../newznab/controllers/Category.php | 30 +- .../controllers/CollectionsCleaning.php | 4 +- lib/copy_this/newznab/controllers/Console.php | 10 +- .../newznab/controllers/Contents.php | 18 +- lib/copy_this/newznab/controllers/Enzebe.php | 16 +- lib/copy_this/newznab/controllers/Episode.php | 6 +- lib/copy_this/newznab/controllers/Film.php | 20 +- lib/copy_this/newznab/controllers/Forum.php | 26 +- lib/copy_this/newznab/controllers/Games.php | 16 +- lib/copy_this/newznab/controllers/Genres.php | 6 +- lib/copy_this/newznab/controllers/Groups.php | 6 +- .../newznab/controllers/IRCScraper.php | 6 +- lib/copy_this/newznab/controllers/Info.php | 20 +- lib/copy_this/newznab/controllers/Konsole.php | 18 +- lib/copy_this/newznab/controllers/Menu.php | 14 +- .../newznab/controllers/MiscSorter.php | 12 +- lib/copy_this/newznab/controllers/Movie.php | 12 +- lib/copy_this/newznab/controllers/Music.php | 12 +- lib/copy_this/newznab/controllers/Musik.php | 18 +- lib/copy_this/newznab/controllers/NNTP.php | 10 +- lib/copy_this/newznab/controllers/NZB.php | 14 +- .../newznab/controllers/NZBContents.php | 10 +- .../newznab/controllers/NZBExport.php | 6 +- .../newznab/controllers/NZBImport.php | 10 +- .../newznab/controllers/NameFixer.php | 6 +- lib/copy_this/newznab/controllers/Nfo.php | 12 +- lib/copy_this/newznab/controllers/Page.php | 2 +- lib/copy_this/newznab/controllers/Parsing.php | 14 +- .../newznab/controllers/PostProcess.php | 102 +-- lib/copy_this/newznab/controllers/PreDB.php | 10 +- lib/copy_this/newznab/controllers/PreHash.php | 6 +- lib/copy_this/newznab/controllers/Regexes.php | 6 +- .../newznab/controllers/ReleaseCleaning.php | 6 +- .../newznab/controllers/ReleaseComments.php | 26 +- .../newznab/controllers/ReleaseExtra.php | 26 +- .../newznab/controllers/ReleaseFiles.php | 10 +- .../newznab/controllers/ReleaseImage.php | 4 +- .../newznab/controllers/ReleaseRegex.php | 8 +- .../newznab/controllers/ReleaseRemover.php | 6 +- .../newznab/controllers/ReleaseSearch.php | 10 +- .../newznab/controllers/Releases.php | 10 +- .../newznab/controllers/RequestID.php | 6 +- .../newznab/controllers/RequestIDWeb.php | 4 +- lib/copy_this/newznab/controllers/Sharing.php | 6 +- lib/copy_this/newznab/controllers/Sites.php | 10 +- lib/copy_this/newznab/controllers/Sphinx.php | 65 +- .../newznab/controllers/SphinxSearch.php | 7 +- lib/copy_this/newznab/controllers/SpotNab.php | 86 +-- lib/copy_this/newznab/controllers/TheTVDB.php | 6 +- lib/copy_this/newznab/controllers/Tmux.php | 16 +- .../newznab/controllers/TmuxOutput.php | 21 +- lib/copy_this/newznab/controllers/TmuxRun.php | 4 +- lib/copy_this/newznab/controllers/TvAnger.php | 8 +- lib/copy_this/newznab/controllers/TvRage.php | 10 +- .../newznab/controllers/UserMovies.php | 14 +- .../newznab/controllers/UserSeries.php | 16 +- lib/copy_this/newznab/controllers/Users.php | 22 +- lib/copy_this/newznab/controllers/XXX.php | 10 +- lib/copy_this/newznab/db/DbUpdate.php | 428 +++++++++++ lib/copy_this/newznab/db/Settings.php | 349 +++++++++ lib/copy_this/newznab/db/populate/AniDB.php | 14 +- lib/copy_this/newznab/libraries/Forking.php | 61 +- .../newznab/libraries/ForkingImportNZB.php | 4 +- lib/copy_this/newznab/processing/PProcess.php | 32 +- .../newznab/processing/ProcessReleases.php | 54 +- .../newznab/processing/post/AniDB.php | 8 +- .../processing/post/ProcessAdditional.php | 80 +- lib/copy_this/newznab/utility/Git.php | 124 +++ lib/copy_this/newznab/utility/Utility.php | 33 + lib/copy_this/newznab/utility/Versions.php | 299 ++++++++ .../resources}/patches/0001_tmux.sql | 0 .../resources}/patches/0002_tmux.sql | 0 .../resources}/patches/0004_tmux.sql | 0 .../resources}/patches/0005_releases.sql | 0 .../resources}/patches/0006_tmux.sql | 0 .../resources}/patches/0007_releases_tmux.sql | 0 .../resources}/patches/0008_releases.sql | 0 .../resources}/patches/0009_releases.sql | 0 .../resources}/patches/0010_releases.sql | 0 .../resources}/patches/0011_prehash.sql | 0 .../resources}/patches/0012_prehash.sql | 0 .../resources}/patches/0013_tmux.sql | 0 .../resources}/patches/0014_prehash.sql | 0 .../resources}/patches/0015_sharing.sql | 0 .../resources}/patches/0016_tmux.sql | 0 .../resources}/patches/0017_tmux.sql | 0 .../resources}/patches/0018_sharing.sql | 0 .../resources}/patches/0019_sharing.sql | 0 .../resources}/patches/0020_tmux.sql | 0 .../resources}/patches/0021_tmux.sql | 0 .../resources}/patches/0022_releases.sql | 0 .../resources}/patches/0023_tmux.sql | 0 .../resources}/patches/0024_tmux.sql | 0 .../resources}/patches/0025_tmux.sql | 0 .../resources}/patches/0026_tmux.sql | 0 .../resources}/patches/0027_prehash.sql | 0 .../resources}/patches/0028_tmux.sql | 0 .../resources}/patches/0029_releases.sql | 0 .../resources}/patches/0030_tmux.sql | 0 .../resources}/patches/0031_releases.sql | 0 .../resources}/patches/0032_releases.sql | 0 .../resources}/patches/0033_releases.sql | 0 .../resources}/patches/0034_tmux.sql | 0 .../resources}/patches/0035_prehash.sql | 0 .../resources}/patches/0036_tmux.sql | 0 .../resources}/patches/0037_tmux.sql | 0 .../resources}/patches/0038_releasesearch.sql | 0 .../resources}/patches/0039_prehash.sql | 0 .../resources}/patches/0040_tmux.sql | 0 .../resources}/patches/0041_predbhash.sql | 0 .../resources}/patches/0042_predbhash.sql | 0 .../resources}/patches/0043_prehash.sql | 0 .../patches/0044_releasecomment.sql | 0 .../resources}/patches/0045_prehash.sql | 0 .../patches/0046_releasecomment.sql | 0 .../resources}/patches/0047_users.sql | 0 .../resources}/patches/0049_site.sql | 0 .../resources}/patches/0050_category.sql | 0 .../resources}/patches/0051_tmux.sql | 0 .../resources}/patches/0052~gamesinfo.sql | 0 .../resources}/patches/0053~site.sql | 0 .../resources}/patches/0054~releases.sql | 0 .../resources}/patches/0055~users.sql | 0 .../resources}/patches/0056~menu.sql | 0 .../resources}/patches/0057~releases.sql | 0 .../resources}/patches/0058~tmux.sql | 0 .../resources}/patches/0059~users.sql | 0 .../resources}/patches/0060~xxxinfo.sql | 0 .../resources}/patches/0061~releases.sql | 0 .../resources}/patches/0062~releases.sql | 0 .../resources}/patches/0063~site.sql | 0 .../resources}/patches/0064~site.sql | 0 .../resources}/patches/0065~users.sql | 0 .../resources}/patches/0066~genres.sql | 0 .../resources}/patches/0067~gamesinfo.sql | 0 .../resources}/patches/0068~xxxinfo.sql | 0 .../resources}/patches/0069~site.sql | 0 .../resources}/patches/0070~animetitles.sql | 0 .../resources}/patches/0071~site.sql | 0 .../resources}/patches/0072~site.sql | 0 .../resources}/patches/0073~releases.sql | 0 .../resources}/patches/0074~releases.sql | 0 .../resources}/patches/0075~site.sql | 0 .../resources}/patches/0078~site.sql | 0 .../resources}/patches/0079~site.sql | 0 .../resources}/patches/0080~site.sql | 0 .../resources}/patches/0081~movieinfo.sql | 0 .../patches/0082~tvrageepisodes.sql | 0 .../resources}/patches/0083~site.sql | 0 .../resources}/patches/0084~groups.sql | 0 .../resources}/patches/0085~site.sql | 0 .../resources}/patches/0086~category.sql | 0 .../resources}/patches/0087~site.sql | 0 .../resources}/patches/0088~site.sql | 0 .../resources}/patches/0089~site.sql | 0 .../resources}/patches/0090~bookinfo.sql | 0 .../resources}/patches/0091~releasesearch.sql | 0 .../resources}/patches/0092~bookinfo.sql | 0 .../resources}/patches/0093~anidb.sql | 0 .../resources}/patches/0094~site.sql | 0 .../resources}/patches/0095~releases.sql | 0 .../resources}/patches/0096~site.sql | 0 .../resources}/patches/0097~releases.sql | 0 .../resources}/patches/0098~tmux.sql | 0 .../resources}/patches/0099~releases.sql | 0 .../resources}/patches/0100~binaries.sql | 0 .../resources}/patches/0101~tmux.sql | 0 .../resources}/patches/0102~predb.sql | 0 .../resources}/patches/0103~site.sql | 0 .../patches/0104~releasecomment.sql | 0 .../resources}/patches/0105~site.sql | 0 .../resources}/patches/0106~category.sql | 0 .../resources}/patches/0107~prehash.sql | 0 .../resources}/patches/0108~regexless.sql | 0 .../resources}/patches/0109~site.sql | 0 .../resources}/patches/0110~category.sql | 0 .../resources}/patches/0111~collections.sql | 0 .../resources}/patches/0112~category.sql | 0 .../resources}/patches/0113~releases.sql | 0 .../patches/0114~collection_regexes.sql | 0 .../resources}/patches/0115~tmux.sql | 0 .../resources}/patches/0116~tmux.sql | 0 .../resources}/patches/0117~tmux.sql | 0 .../patches/0118~release_naming_regexes.sql | 0 .../patches/0119~category_regex.sql | 0 .../patches/0120~release_naming_regexes.sql | 0 .../patches/0121~collection_regexes.sql | 0 .../resources}/patches/0122~general.sql | 0 .../patches/0123~release_naming_regexes.sql | 0 .../resources}/patches/0124~movieinfo.sql | 0 .../patches/0125~faileddownloads.sql | 0 .../resources}/patches/0127~site.sql | 0 .../patches/0128~collection_regexes.sql | 0 .../patches/0129~category_regexes.sql | 0 .../patches/0130~release_naming_regexes.sql | 0 .../resources}/patches/0131~blacklist.sql | 0 .../resources}/patches/0132~site.sql | 0 .../patches/0133~collection_regexes.sql | 0 .../patches/0134~collection_regexes.sql | 0 .../patches/0135~collection_regexes.sql | 0 .../patches/0136~release_naming_regexes.sql | 0 .../resources}/patches/0137~groups.sql | 0 .../patches/0138~collection_regexes.sql | 0 .../resources}/patches/0139~users.sql | 0 .../patches/0140~collection_regexes.sql | 0 .../patches/0141~collection_regexes.sql | 0 .../patches/0142~collection_regexes.sql | 0 .../patches/0143~collection_regexes.sql | 0 .../resources}/patches/0144~site.sql | 0 .../patches/0145~collection_regexes.sql | 0 .../patches/0146~collection_regexes.sql | 0 .../resources}/patches/0147~site.sql | 0 .../resources}/patches/0148~site.sql | 0 lib/copy_this/resources/patches/0149~site.sql | 14 + .../www/admin/ajax_sharing_settings.php | 2 +- lib/copy_this/www/admin/db-optimise.php | 4 +- lib/copy_this/www/admin/index.php | 6 +- lib/copy_this/www/admin/sharing.php | 4 +- lib/copy_this/www/admin/site-debug.php | 2 +- lib/copy_this/www/pages/api.php | 4 +- lib/copy_this/www/pages/content.php | 2 - lib/copy_this/www/pages/dlbrowse.php | 5 +- lib/copy_this/www/pages/myshows.php | 4 +- lib/copy_this/www/pages/prehashinfo.php | 10 +- .../nntmux/views/frontend/rssdesc.tpl | 2 +- lib/decrypt_hashes.php | 4 +- lib/fixReleaseNames.php | 4 +- lib/testing/DB/change_USP_provider.php | 4 +- lib/testing/DB/convert_mysql_tables.php | 4 +- lib/testing/DB/convert_to_tpg.php | 4 +- lib/testing/DB/mysqldump_tables.php | 4 +- lib/testing/DB/populate_nzb_guid.php | 4 +- lib/testing/DB/rename_to_lower.php | 2 +- lib/testing/DB/reset_postprocessing.php | 4 +- lib/testing/DB/reset_truncate.php | 4 +- lib/testing/DB/resetdb.php | 4 +- lib/testing/Dev/clean_nzbs.php | 4 +- lib/testing/Dev/renametopre.php | 4 +- lib/testing/PostProc/check_previews.php | 4 +- lib/testing/PostProc/getConsole.php | 4 +- lib/testing/PostProc/getGameCovers.php | 4 +- lib/testing/PostProc/getImdb.php | 4 +- lib/testing/PostProc/getMovieCovers.php | 4 +- lib/testing/PostProc/getXXXCovers.php | 4 +- lib/testing/PostProc/populate_tvrage.php | 4 +- lib/testing/PostProc/updateBookImages.php | 4 +- lib/testing/PostProc/updateConsoleImages.php | 4 +- lib/testing/PostProc/updateGamesImages.php | 4 +- lib/testing/PostProc/updateMovieImages.php | 4 +- lib/testing/PostProc/updateMusicImages.php | 4 +- lib/testing/PostProc/updateTvRage.php | 4 +- lib/testing/PostProc/updateXXXImages.php | 4 +- .../tpg_add_collections_column_2015-02-20.php | 4 +- lib/testing/_run_once/tpg_fixes.php | 4 +- lib/testing/populate_anidb.php | 4 +- lib/testing/predb_import_daily_batch.php | 4 +- lib/testing/recategorize.php | 4 +- monitor.php | 6 +- run.php | 51 +- scripts/reset_rar_check.php | 2 +- start.php | 4 +- 321 files changed, 4154 insertions(+), 829 deletions(-) create mode 100644 lib/copy_this/cli/update_db.php create mode 100644 lib/copy_this/cli/verify_permissions.php create mode 100644 lib/copy_this/cli/versions.php create mode 100644 lib/copy_this/libs/Git.php/Git.php create mode 100644 lib/copy_this/libs/Git.php/composer.json create mode 100644 lib/copy_this/libs/Git.php/license.txt create mode 100644 lib/copy_this/libs/Git.php/readme.md create mode 100644 lib/copy_this/libs/Git.php/test/test-suite.php create mode 100644 lib/copy_this/newznab/build/addGitHook.php create mode 100644 lib/copy_this/newznab/build/git-hooks/pre-commit create mode 100644 lib/copy_this/newznab/build/git-hooks/runHooks.php create mode 100644 lib/copy_this/newznab/build/newznab.xml create mode 100644 lib/copy_this/newznab/db/DbUpdate.php create mode 100644 lib/copy_this/newznab/db/Settings.php create mode 100644 lib/copy_this/newznab/utility/Git.php create mode 100644 lib/copy_this/newznab/utility/Versions.php rename lib/{DB => copy_this/resources}/patches/0001_tmux.sql (100%) rename lib/{DB => copy_this/resources}/patches/0002_tmux.sql (100%) rename lib/{DB => copy_this/resources}/patches/0004_tmux.sql (100%) rename lib/{DB => copy_this/resources}/patches/0005_releases.sql (100%) rename lib/{DB => copy_this/resources}/patches/0006_tmux.sql (100%) rename lib/{DB => copy_this/resources}/patches/0007_releases_tmux.sql (100%) rename lib/{DB => copy_this/resources}/patches/0008_releases.sql (100%) rename lib/{DB => copy_this/resources}/patches/0009_releases.sql (100%) rename lib/{DB => copy_this/resources}/patches/0010_releases.sql (100%) rename lib/{DB => copy_this/resources}/patches/0011_prehash.sql (100%) rename lib/{DB => copy_this/resources}/patches/0012_prehash.sql (100%) rename lib/{DB => copy_this/resources}/patches/0013_tmux.sql (100%) rename lib/{DB => copy_this/resources}/patches/0014_prehash.sql (100%) rename lib/{DB => copy_this/resources}/patches/0015_sharing.sql (100%) rename lib/{DB => copy_this/resources}/patches/0016_tmux.sql (100%) rename lib/{DB => copy_this/resources}/patches/0017_tmux.sql (100%) rename lib/{DB => copy_this/resources}/patches/0018_sharing.sql (100%) rename lib/{DB => copy_this/resources}/patches/0019_sharing.sql (100%) rename lib/{DB => copy_this/resources}/patches/0020_tmux.sql (100%) rename lib/{DB => copy_this/resources}/patches/0021_tmux.sql (100%) rename lib/{DB => copy_this/resources}/patches/0022_releases.sql (100%) rename lib/{DB => copy_this/resources}/patches/0023_tmux.sql (100%) rename lib/{DB => copy_this/resources}/patches/0024_tmux.sql (100%) rename lib/{DB => copy_this/resources}/patches/0025_tmux.sql (100%) rename lib/{DB => copy_this/resources}/patches/0026_tmux.sql (100%) rename lib/{DB => copy_this/resources}/patches/0027_prehash.sql (100%) rename lib/{DB => copy_this/resources}/patches/0028_tmux.sql (100%) rename lib/{DB => copy_this/resources}/patches/0029_releases.sql (100%) rename lib/{DB => copy_this/resources}/patches/0030_tmux.sql (100%) rename lib/{DB => copy_this/resources}/patches/0031_releases.sql (100%) rename lib/{DB => copy_this/resources}/patches/0032_releases.sql (100%) rename lib/{DB => copy_this/resources}/patches/0033_releases.sql (100%) rename lib/{DB => copy_this/resources}/patches/0034_tmux.sql (100%) rename lib/{DB => copy_this/resources}/patches/0035_prehash.sql (100%) rename lib/{DB => copy_this/resources}/patches/0036_tmux.sql (100%) rename lib/{DB => copy_this/resources}/patches/0037_tmux.sql (100%) rename lib/{DB => copy_this/resources}/patches/0038_releasesearch.sql (100%) rename lib/{DB => copy_this/resources}/patches/0039_prehash.sql (100%) rename lib/{DB => copy_this/resources}/patches/0040_tmux.sql (100%) rename lib/{DB => copy_this/resources}/patches/0041_predbhash.sql (100%) rename lib/{DB => copy_this/resources}/patches/0042_predbhash.sql (100%) rename lib/{DB => copy_this/resources}/patches/0043_prehash.sql (100%) rename lib/{DB => copy_this/resources}/patches/0044_releasecomment.sql (100%) rename lib/{DB => copy_this/resources}/patches/0045_prehash.sql (100%) rename lib/{DB => copy_this/resources}/patches/0046_releasecomment.sql (100%) rename lib/{DB => copy_this/resources}/patches/0047_users.sql (100%) rename lib/{DB => copy_this/resources}/patches/0049_site.sql (100%) rename lib/{DB => copy_this/resources}/patches/0050_category.sql (100%) rename lib/{DB => copy_this/resources}/patches/0051_tmux.sql (100%) rename lib/{DB => copy_this/resources}/patches/0052~gamesinfo.sql (100%) rename lib/{DB => copy_this/resources}/patches/0053~site.sql (100%) rename lib/{DB => copy_this/resources}/patches/0054~releases.sql (100%) rename lib/{DB => copy_this/resources}/patches/0055~users.sql (100%) rename lib/{DB => copy_this/resources}/patches/0056~menu.sql (100%) rename lib/{DB => copy_this/resources}/patches/0057~releases.sql (100%) rename lib/{DB => copy_this/resources}/patches/0058~tmux.sql (100%) rename lib/{DB => copy_this/resources}/patches/0059~users.sql (100%) rename lib/{DB => copy_this/resources}/patches/0060~xxxinfo.sql (100%) rename lib/{DB => copy_this/resources}/patches/0061~releases.sql (100%) rename lib/{DB => copy_this/resources}/patches/0062~releases.sql (100%) rename lib/{DB => copy_this/resources}/patches/0063~site.sql (100%) rename lib/{DB => copy_this/resources}/patches/0064~site.sql (100%) rename lib/{DB => copy_this/resources}/patches/0065~users.sql (100%) rename lib/{DB => copy_this/resources}/patches/0066~genres.sql (100%) rename lib/{DB => copy_this/resources}/patches/0067~gamesinfo.sql (100%) rename lib/{DB => copy_this/resources}/patches/0068~xxxinfo.sql (100%) rename lib/{DB => copy_this/resources}/patches/0069~site.sql (100%) rename lib/{DB => copy_this/resources}/patches/0070~animetitles.sql (100%) rename lib/{DB => copy_this/resources}/patches/0071~site.sql (100%) rename lib/{DB => copy_this/resources}/patches/0072~site.sql (100%) rename lib/{DB => copy_this/resources}/patches/0073~releases.sql (100%) rename lib/{DB => copy_this/resources}/patches/0074~releases.sql (100%) rename lib/{DB => copy_this/resources}/patches/0075~site.sql (100%) rename lib/{DB => copy_this/resources}/patches/0078~site.sql (100%) rename lib/{DB => copy_this/resources}/patches/0079~site.sql (100%) rename lib/{DB => copy_this/resources}/patches/0080~site.sql (100%) rename lib/{DB => copy_this/resources}/patches/0081~movieinfo.sql (100%) rename lib/{DB => copy_this/resources}/patches/0082~tvrageepisodes.sql (100%) rename lib/{DB => copy_this/resources}/patches/0083~site.sql (100%) rename lib/{DB => copy_this/resources}/patches/0084~groups.sql (100%) rename lib/{DB => copy_this/resources}/patches/0085~site.sql (100%) rename lib/{DB => copy_this/resources}/patches/0086~category.sql (100%) rename lib/{DB => copy_this/resources}/patches/0087~site.sql (100%) rename lib/{DB => copy_this/resources}/patches/0088~site.sql (100%) rename lib/{DB => copy_this/resources}/patches/0089~site.sql (100%) rename lib/{DB => copy_this/resources}/patches/0090~bookinfo.sql (100%) rename lib/{DB => copy_this/resources}/patches/0091~releasesearch.sql (100%) rename lib/{DB => copy_this/resources}/patches/0092~bookinfo.sql (100%) rename lib/{DB => copy_this/resources}/patches/0093~anidb.sql (100%) rename lib/{DB => copy_this/resources}/patches/0094~site.sql (100%) rename lib/{DB => copy_this/resources}/patches/0095~releases.sql (100%) rename lib/{DB => copy_this/resources}/patches/0096~site.sql (100%) rename lib/{DB => copy_this/resources}/patches/0097~releases.sql (100%) rename lib/{DB => copy_this/resources}/patches/0098~tmux.sql (100%) rename lib/{DB => copy_this/resources}/patches/0099~releases.sql (100%) rename lib/{DB => copy_this/resources}/patches/0100~binaries.sql (100%) rename lib/{DB => copy_this/resources}/patches/0101~tmux.sql (100%) rename lib/{DB => copy_this/resources}/patches/0102~predb.sql (100%) rename lib/{DB => copy_this/resources}/patches/0103~site.sql (100%) rename lib/{DB => copy_this/resources}/patches/0104~releasecomment.sql (100%) rename lib/{DB => copy_this/resources}/patches/0105~site.sql (100%) rename lib/{DB => copy_this/resources}/patches/0106~category.sql (100%) rename lib/{DB => copy_this/resources}/patches/0107~prehash.sql (100%) rename lib/{DB => copy_this/resources}/patches/0108~regexless.sql (100%) rename lib/{DB => copy_this/resources}/patches/0109~site.sql (100%) rename lib/{DB => copy_this/resources}/patches/0110~category.sql (100%) rename lib/{DB => copy_this/resources}/patches/0111~collections.sql (100%) rename lib/{DB => copy_this/resources}/patches/0112~category.sql (100%) rename lib/{DB => copy_this/resources}/patches/0113~releases.sql (100%) rename lib/{DB => copy_this/resources}/patches/0114~collection_regexes.sql (100%) rename lib/{DB => copy_this/resources}/patches/0115~tmux.sql (100%) rename lib/{DB => copy_this/resources}/patches/0116~tmux.sql (100%) rename lib/{DB => copy_this/resources}/patches/0117~tmux.sql (100%) rename lib/{DB => copy_this/resources}/patches/0118~release_naming_regexes.sql (100%) rename lib/{DB => copy_this/resources}/patches/0119~category_regex.sql (100%) rename lib/{DB => copy_this/resources}/patches/0120~release_naming_regexes.sql (100%) rename lib/{DB => copy_this/resources}/patches/0121~collection_regexes.sql (100%) rename lib/{DB => copy_this/resources}/patches/0122~general.sql (100%) rename lib/{DB => copy_this/resources}/patches/0123~release_naming_regexes.sql (100%) rename lib/{DB => copy_this/resources}/patches/0124~movieinfo.sql (100%) rename lib/{DB => copy_this/resources}/patches/0125~faileddownloads.sql (100%) rename lib/{DB => copy_this/resources}/patches/0127~site.sql (100%) rename lib/{DB => copy_this/resources}/patches/0128~collection_regexes.sql (100%) rename lib/{DB => copy_this/resources}/patches/0129~category_regexes.sql (100%) rename lib/{DB => copy_this/resources}/patches/0130~release_naming_regexes.sql (100%) rename lib/{DB => copy_this/resources}/patches/0131~blacklist.sql (100%) rename lib/{DB => copy_this/resources}/patches/0132~site.sql (100%) rename lib/{DB => copy_this/resources}/patches/0133~collection_regexes.sql (100%) rename lib/{DB => copy_this/resources}/patches/0134~collection_regexes.sql (100%) rename lib/{DB => copy_this/resources}/patches/0135~collection_regexes.sql (100%) rename lib/{DB => copy_this/resources}/patches/0136~release_naming_regexes.sql (100%) rename lib/{DB => copy_this/resources}/patches/0137~groups.sql (100%) rename lib/{DB => copy_this/resources}/patches/0138~collection_regexes.sql (100%) rename lib/{DB => copy_this/resources}/patches/0139~users.sql (100%) rename lib/{DB => copy_this/resources}/patches/0140~collection_regexes.sql (100%) rename lib/{DB => copy_this/resources}/patches/0141~collection_regexes.sql (100%) rename lib/{DB => copy_this/resources}/patches/0142~collection_regexes.sql (100%) rename lib/{DB => copy_this/resources}/patches/0143~collection_regexes.sql (100%) rename lib/{DB => copy_this/resources}/patches/0144~site.sql (100%) rename lib/{DB => copy_this/resources}/patches/0145~collection_regexes.sql (100%) rename lib/{DB => copy_this/resources}/patches/0146~collection_regexes.sql (100%) rename lib/{DB => copy_this/resources}/patches/0147~site.sql (100%) rename lib/{DB => copy_this/resources}/patches/0148~site.sql (100%) create mode 100644 lib/copy_this/resources/patches/0149~site.sql diff --git a/bin/fixreleasenames.php b/bin/fixreleasenames.php index f1d545f93..c3b4224ae 100644 --- a/bin/fixreleasenames.php +++ b/bin/fixreleasenames.php @@ -2,14 +2,14 @@ require_once(dirname(__FILE__)."/config.php"); -use newznab\db\DB; +use newznab\db\Settings; use newznab\processing\PProcess; $c = new ColorCLI(); if (!isset($argv[1])) { exit($c->error("This script is not intended to be run manually, it is called from fixreleasenames_threaded.py.")); } else if (isset($argv[1])) { - $db = new DB(); + $db = new Settings(); $namefixer = new \NameFixer(['Settings' => $pdo]); $pieces = explode(' ', $argv[1]); if (isset($pieces[1]) && $pieces[0] == 'nfo') { diff --git a/bin/groupfixrelnames.php b/bin/groupfixrelnames.php index becec5970..f528de858 100644 --- a/bin/groupfixrelnames.php +++ b/bin/groupfixrelnames.php @@ -1,10 +1,10 @@ get(); diff --git a/bin/postprocess.php b/bin/postprocess.php index bd997314b..b4838e23b 100644 --- a/bin/postprocess.php +++ b/bin/postprocess.php @@ -2,10 +2,10 @@ require_once(dirname(__FILE__) . '/config.php'); -use newznab\db\DB; +use newznab\db\Settings; use newznab\processing\PProcess; -$pdo = new DB(); +$pdo = new Settings(); $s = new Sites(); $site = $s->get(); /** diff --git a/bin/update_groups.php b/bin/update_groups.php index 7ed6a5fe5..8f4487af3 100644 --- a/bin/update_groups.php +++ b/bin/update_groups.php @@ -2,11 +2,11 @@ require_once(dirname(__FILE__).'/config.php'); -use newznab\db\DB; +use newznab\db\Settings; $start = TIME(); -$pdo = new DB(); +$pdo = new Settings(); $consoleTools = new \ConsoleTools(['ColorCLI' => $pdo->log]); // Create the connection here and pass diff --git a/bin/update_releases.php b/bin/update_releases.php index 7b887ca60..e281b02bf 100644 --- a/bin/update_releases.php +++ b/bin/update_releases.php @@ -1,12 +1,12 @@ get(); -$pdo = new DB(); +$pdo = new Settings(); if (isset($argv[2]) && $argv[2] === 'true') { // Create the connection here and pass diff --git a/lib/DB/mysqldump_tables.php b/lib/DB/mysqldump_tables.php index dc4067b69..7ee1db188 100644 --- a/lib/DB/mysqldump_tables.php +++ b/lib/DB/mysqldump_tables.php @@ -1,12 +1,12 @@ sqlpatch; $patched = 0; $patches = array(); - $db = new DB(); + $db = new Settings(); $backedup = false; $c = new ColorCLI(); $DIR = dirname (__FILE__); diff --git a/lib/copy_this/cli/update_db.php b/lib/copy_this/cli/update_db.php new file mode 100644 index 000000000..457897103 --- /dev/null +++ b/lib/copy_this/cli/update_db.php @@ -0,0 +1,50 @@ +. + * @author niel + * @copyright 2014 nZEDb + */ +require_once dirname(__DIR__) . DIRECTORY_SEPARATOR . 'www' . DIRECTORY_SEPARATOR . 'config.php'; + +use newznab\db\DbUpdate; +use newznab\utility\Utility; + +if (!Utility::isCLI()) { + exit; +} + +if (isset($argc) && $argc > 1 && isset($argv[1]) && $argv[1] == true) { + $backup = (isset($argv[2]) && $argv[2] == 'safe') ? true : false; + $updater = new DbUpdate(['backup' => $backup]); + echo $updater->log->header("Db updater starting ..."); + $patched = $updater->processPatches(['safe' => $backup]); + + if ($patched > 0) { + echo $updater->log->info("$patched patch(es) applied."); + + $smarty = new Smarty(); + $cleared = $smarty->clearCompiledTemplate(); + if ($cleared) { + $msg = "The smarty template cache has been cleaned for you\n"; + } else { + $msg = "You should clear your smarty template cache at: " . SMARTY_DIR . "templates_c\n"; + } + $updater->log->info($msg); + } +} else { + echo "Usage: php update_db.php true"; +} \ No newline at end of file diff --git a/lib/copy_this/cli/verify_permissions.php b/lib/copy_this/cli/verify_permissions.php new file mode 100644 index 000000000..1af67c6dd --- /dev/null +++ b/lib/copy_this/cli/verify_permissions.php @@ -0,0 +1,131 @@ + [R], + NN_LIBS . 'smarty' => [R], + NN_LIBS . 'smarty' . DS . 'templates_c' => [R, W], + NN_RES => [R, W, E], + NN_RES . 'db' => [R, E], + NN_RES . 'db' . DS . 'patches' => [R, E], + NN_RES . 'db' . DS . 'schema' => [R, E], + NN_RES . 'db' . DS . 'schema' . DS . 'data' => [R, E], + NN_RES . 'nzb' => [R], + NN_LOGS => [R, W], + NN_TMP => [R, W], + NN_TMP . DS . 'unrar' => [R, W, E], + NN_TMP . DS . 'yEnc' => [R, W, E], + NN_VERSIONS => [R], +]; + +// Add nzb folders. +foreach ([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 'a', 'b', 'c', 'd', 'e', 'f'] as $identifier) { + $nzbFolder = NN_RES . 'nzb' . DS . $identifier . DS; + $folders[$nzbFolder] = [R, W]; +} + +// Add covers paths. +foreach (['anime', 'audio', 'audiosample', 'book', 'console', 'games', 'movies', 'music', 'preview', 'sample', 'tvrage', 'video', 'xxx'] as $identifier) { + $nzbFolder = NN_RES . 'covers' . DS . $identifier . DS; + $folders[$nzbFolder] = [R, W]; +} + +// Set up covers paths. +if (defined('DB_PASSWORD') && DB_PASSWORD != '') { + $ri = new ReleaseImage(); + + $folders[$ri->audSavePath] = [R, W]; + $folders[$ri->imgSavePath] = [R, W]; + $folders[$ri->jpgSavePath] = [R, W]; + $folders[$ri->movieImgSavePath] = [R, W]; + $folders[$ri->vidSavePath] = [R, W]; +} else { + echo 'Skipping cover folders check, as you have not set up a database yet. You can rerun this script after running install.' . PHP_EOL; +} + +// Check folders. +foreach ($folders as $folder => $check) { + exists($folder); + foreach ($check as $type) { + switch ($type) { + case R: + readable($folder); + break; + case W: + writable($folder); + break; + case E: + executable($folder); + break; + } + } +} + +echo 'Your permissions seem right for this user. Note, this script does not verify all paths, only the most important ones.' . PHP_EOL; + +if (!newznab\utility\Utility::isWin()) { + $user = posix_getpwuid(posix_geteuid()); + if ($user['name'] !== 'www-data') { + echo 'If you have not already done so, please rerun this script using the www-data user: sudo -u www-data php verify_permissions.php yes' . PHP_EOL; + } +} + +function readable($folder) +{ + if (!is_readable($folder)) { + exit('Error: This path is not readable: (' . $folder . ') resolve this and rerun the script.' . PHP_EOL); + } +} + +function writable($folder) +{ + if (!is_writable($folder)) { + exit('Error: This path is not writable: (' . $folder . ') resolve this and rerun the script.' . PHP_EOL); + } +} + +function executable($folder) +{ + if (!is_executable($folder)) { + exit('Error: This path is not executable: (' . $folder . ') resolve this and rerun the script.' . PHP_EOL); + } +} + +function exists($folder) +{ + if (!file_exists($folder)) { + exit('Error: This path (' . $folder . ') does not exist or is not readable. Create it or make it readable.' . PHP_EOL); + } +} \ No newline at end of file diff --git a/lib/copy_this/cli/versions.php b/lib/copy_this/cli/versions.php new file mode 100644 index 000000000..d5d90f383 --- /dev/null +++ b/lib/copy_this/cli/versions.php @@ -0,0 +1,52 @@ +. + * @author niel + * @copyright 2014 nZEDb + */ +require_once dirname(__DIR__) . DIRECTORY_SEPARATOR . 'www' . DIRECTORY_SEPARATOR . 'config.php'; + +use newznab\utility\Utility; +use newznab\utility\Versions; + +if (!Utility::isCLI()) { + exit; +} + +$vers = new Versions(); +if (isset($argc) && $argc > 1 && isset($argv[1]) && $argv[1] == true) { + echo $vers->out->header("Checking versions..."); + + if ($vers->checkAll()) { + $vers->save(); + } else { + echo "No changes detected.\n"; + output($vers); + } +} else { + $vers->checkAll(false); + echo "Version info in file:\n"; + output($vers); +} + +function output($vers) +{ + echo " Commit: " . $vers->out->primary($vers->getCommit()); + echo "SQL DB: " . $vers->out->primary($vers->getSQLPatchFromDb()); + echo "SQL File: " . $vers->out->primary($vers->getSQLPatchFromFiles()); + echo " Tag: " . $vers->out->primary($vers->getTagVersion()); +} \ No newline at end of file diff --git a/lib/copy_this/libs/Git.php/Git.php b/lib/copy_this/libs/Git.php/Git.php new file mode 100644 index 000000000..5537b24f3 --- /dev/null +++ b/lib/copy_this/libs/Git.php/Git.php @@ -0,0 +1,684 @@ + ['pipe', 'w']], $pipes); + + $stdout = stream_get_contents($pipes[1]); + + foreach ($pipes as $pipe) { + fclose($pipe); + } + + $status = trim(proc_close($resource)); + + if (!$status) { + $binPath = trim($stdout); + } + + if (strpos($binPath, ' ') !== false) { + $binPath = newznab\utility\Utility::isWin() ? '"' . $binPath . '"' + : str_replace(' ', '\ ', $binPath); + } + + self::set_bin($binPath); + return $binPath; + } +} + +// ------------------------------------------------------------------------ + +/** + * Git Repository Interface Class + * + * This class enables the creating, reading, and manipulation + * of a git repository + * + * @class GitRepo + */ +class GitRepo { + + protected $repo_path = null; + protected $bare = false; + protected $envopts = array(); + + /** + * Create a new git repository + * + * Accepts a creation path, and, optionally, a source path + * + * @access public + * @param string repository path + * @param string directory to source + * @return GitRepo + */ + public static function &create_new($repo_path, $source = null, $remote_source = false) { + if (is_dir($repo_path) && file_exists($repo_path."/.git") && is_dir($repo_path."/.git")) { + throw new Exception('"'.$repo_path.'" is already a git repository'); + } else { + $repo = new self($repo_path, true, false); + if (is_string($source)) { + if ($remote_source) { + $repo->clone_remote($source); + } else { + $repo->clone_from($source); + } + } else { + $repo->run('init'); + } + return $repo; + } + } + + /** + * Constructor + * + * Accepts a repository path + * + * @access public + * @param string repository path + * @param bool create if not exists? + * @return void + */ + public function __construct($path = null, $create_new = false, $_init = true) { + if (is_string($path)) { + $this->set_repo_path($path, $create_new, $_init); + } + } + + /** + * Set the repository's path + * + * Accepts the repository path + * + * @access public + * @param string repository path + * @param bool create if not exists? + * @param bool initialize new Git repo if not exists? + * @return void + */ + public function set_repo_path($repo_path, $create_new = false, $_init = true) { + if (is_string($repo_path)) { + if ($new_path = realpath($repo_path)) { + $repo_path = $new_path; + if (is_dir($repo_path)) { + // Is this a work tree? + if (file_exists($repo_path."/.git") && is_dir($repo_path."/.git")) { + $this->repo_path = $repo_path; + $this->bare = false; + // Is this a bare repo? + } else if (is_file($repo_path."/config")) { + $parse_ini = parse_ini_file($repo_path."/config"); + if ($parse_ini['bare']) { + $this->repo_path = $repo_path; + $this->bare = true; + } + } else { + if ($create_new) { + $this->repo_path = $repo_path; + if ($_init) { + $this->run('init'); + } + } else { + throw new Exception('"'.$repo_path.'" is not a git repository'); + } + } + } else { + throw new Exception('"'.$repo_path.'" is not a directory'); + } + } else { + if ($create_new) { + if ($parent = realpath(dirname($repo_path))) { + mkdir($repo_path); + $this->repo_path = $repo_path; + if ($_init) $this->run('init'); + } else { + throw new Exception('cannot create repository in non-existent directory'); + } + } else { + throw new Exception('"'.$repo_path.'" does not exist'); + } + } + } + } + + /** + * Tests if git is installed + * + * @access public + * @return bool + */ + public function test_git() { + $descriptorspec = array( + 1 => array('pipe', 'w'), + 2 => array('pipe', 'w'), + ); + $pipes = array(); + $resource = proc_open(Git::get_bin(), $descriptorspec, $pipes); + + $stdout = stream_get_contents($pipes[1]); + $stderr = stream_get_contents($pipes[2]); + foreach ($pipes as $pipe) { + fclose($pipe); + } + + $status = trim(proc_close($resource)); + return ($status != 127); + } + + /** + * Run a command in the git repository + * + * Accepts a shell command to run + * + * @access protected + * @param string command to run + * @return string + */ + protected function run_command($command) { + $descriptorspec = array( + 1 => array('pipe', 'w'), + 2 => array('pipe', 'w'), + ); + $pipes = array(); + /* Depending on the value of variables_order, $_ENV may be empty. + * In that case, we have to explicitly set the new variables with + * putenv, and call proc_open with env=null to inherit the reset + * of the system. + * + * This is kind of crappy because we cannot easily restore just those + * variables afterwards. + * + * If $_ENV is not empty, then we can just copy it and be done with it. + */ + if(count($_ENV) === 0) { + $env = NULL; + foreach($this->envopts as $k => $v) { + putenv(sprintf("%s=%s",$k,$v)); + } + } else { + $env = array_merge($_ENV, $this->envopts); + } + $cwd = $this->repo_path; + $resource = proc_open($command, $descriptorspec, $pipes, $cwd, $env); + + $stdout = stream_get_contents($pipes[1]); + $stderr = stream_get_contents($pipes[2]); + foreach ($pipes as $pipe) { + fclose($pipe); + } + + $status = trim(proc_close($resource)); + if ($status) throw new Exception($stderr . PHP_EOL . $command); + + return $stdout; + } + + /** + * Run a git command in the git repository + * + * Accepts a git command to run + * + * @access public + * @param string command to run + * @return string + */ + public function run($command) { + // If git.exe is in C:/Program Files, the space between Program and Files causes an error. + return $this->run_command(Git::get_bin() . " " . $command); + } + + /** + * Runs a 'git status' call + * + * Accept a convert to HTML bool + * + * @access public + * @param bool return string with
+ * @return string + */ + public function status($html = false) { + $msg = $this->run("status"); + if ($html == true) { + $msg = str_replace("\n", "
", $msg); + } + return $msg; + } + + /** + * Runs a `git add` call + * + * Accepts a list of files to add + * + * @access public + * @param mixed files to add + * @return string + */ + public function add($files = "*") { + if (is_array($files)) { + $files = '"'.implode('" "', $files).'"'; + } + return $this->run("add $files -v"); + } + + /** + * Runs a `git rm` call + * + * Accepts a list of files to remove + * + * @access public + * @param mixed files to remove + * @param Boolean use the --cached flag? + * @return string + */ + public function rm($files = "*", $cached = false) { + if (is_array($files)) { + $files = '"'.implode('" "', $files).'"'; + } + return $this->run("rm ".($cached ? '--cached ' : '').$files); + } + + + /** + * Runs a `git commit` call + * + * Accepts a commit message string + * + * @access public + * @param string commit message + * @return string + */ + public function commit($message = "") { + return $this->run("commit -av -m ".escapeshellarg($message)); + } + + /** + * Runs a `git clone` call to clone the current repository + * into a different directory + * + * Accepts a target directory + * + * @access public + * @param string target directory + * @return string + */ + public function clone_to($target) { + return $this->run("clone --local ".$this->repo_path." $target"); + } + + /** + * Runs a `git clone` call to clone a different repository + * into the current repository + * + * Accepts a source directory + * + * @access public + * @param string source directory + * @return string + */ + public function clone_from($source) { + return $this->run("clone --local $source ".$this->repo_path); + } + + /** + * Runs a `git clone` call to clone a remote repository + * into the current repository + * + * Accepts a source url + * + * @access public + * @param string source url + * @return string + */ + public function clone_remote($source) { + return $this->run("clone $source ".$this->repo_path); + } + + /** + * Runs a `git clean` call + * + * Accepts a remove directories flag + * + * @access public + * @param bool delete directories? + * @param bool force clean? + * @return string + */ + public function clean($dirs = false, $force = false) { + return $this->run("clean".(($force) ? " -f" : "").(($dirs) ? " -d" : "")); + } + + /** + * Runs a `git branch` call + * + * Accepts a name for the branch + * + * @access public + * @param string branch name + * @return string + */ + public function create_branch($branch) { + return $this->run("branch $branch"); + } + + /** + * Runs a `git branch -[d|D]` call + * + * Accepts a name for the branch + * + * @access public + * @param string branch name + * @return string + */ + public function delete_branch($branch, $force = false) { + return $this->run("branch ".(($force) ? '-D' : '-d')." $branch"); + } + + /** + * Runs a `git branch` call + * + * @access public + * @param bool keep asterisk mark on active branch + * @return array + */ + public function list_branches($keep_asterisk = false) { + $branchArray = explode("\n", $this->run("branch")); + foreach($branchArray as $i => &$branch) { + $branch = trim($branch); + if (! $keep_asterisk) { + $branch = str_replace("* ", "", $branch); + } + if ($branch == "") { + unset($branchArray[$i]); + } + } + return $branchArray; + } + + /** + * Lists remote branches (using `git branch -r`). + * + * Also strips out the HEAD reference (e.g. "origin/HEAD -> origin/master"). + * + * @access public + * @return array + */ + public function list_remote_branches() { + $branchArray = explode("\n", $this->run("branch -r")); + foreach($branchArray as $i => &$branch) { + $branch = trim($branch); + if ($branch == "" || strpos($branch, 'HEAD -> ') !== false) { + unset($branchArray[$i]); + } + } + return $branchArray; + } + + /** + * Returns name of active branch + * + * @access public + * @param bool keep asterisk mark on branch name + * @return string + */ + public function active_branch($keep_asterisk = false) { + $branchArray = $this->list_branches(true); + $active_branch = preg_grep("/^\*/", $branchArray); + reset($active_branch); + if ($keep_asterisk) { + return current($active_branch); + } else { + return str_replace("* ", "", current($active_branch)); + } + } + + /** + * Runs a `git checkout` call + * + * Accepts a name for the branch + * + * @access public + * @param string branch name + * @return string + */ + public function checkout($branch) { + return $this->run("checkout $branch"); + } + + + /** + * Runs a `git merge` call + * + * Accepts a name for the branch to be merged + * + * @access public + * @param string $branch + * @return string + */ + public function merge($branch) { + return $this->run("merge $branch --no-ff"); + } + + + /** + * Runs a git fetch on the current branch + * + * @access public + * @return string + */ + public function fetch() { + return $this->run("fetch"); + } + + /** + * Add a new tag on the current position + * + * Accepts the name for the tag and the message + * + * @param string $tag + * @param string $message + * @return string + */ + public function add_tag($tag, $message = null) { + if ($message === null) { + $message = $tag; + } + return $this->run("tag -a $tag -m $message"); + } + + /** + * List all the available repository tags. + * + * Optionally, accept a shell wildcard pattern and return only tags matching it. + * + * @access public + * @param string $pattern Shell wildcard pattern to match tags against. + * @return array Available repository tags. + */ + public function list_tags($pattern = null) { + $tagArray = explode("\n", $this->run("tag -l $pattern")); + foreach ($tagArray as $i => &$tag) { + $tag = trim($tag); + if ($tag == '') { + unset($tagArray[$i]); + } + } + + return $tagArray; + } + + /** + * Push specific branch to a remote + * + * Accepts the name of the remote and local branch + * + * @param string $remote + * @param string $branch + * @return string + */ + public function push($remote, $branch) { + return $this->run("push --tags $remote $branch"); + } + + /** + * Pull specific branch from remote + * + * Accepts the name of the remote and local branch + * + * @param string $remote + * @param string $branch + * @return string + */ + public function pull($remote, $branch) { + return $this->run("pull $remote $branch"); + } + + /** + * Sets the project description. + * + * @param string $new + */ + public function set_description($new) { + file_put_contents($this->repo_path."/.git/description", $new); + } + + /** + * Gets the project description. + * + * @return string + */ + public function get_description() { + return file_get_contents($this->repo_path."/.git/description"); + } + + /** + * Sets custom environment options for calling Git + * + * @param string key + * @param string value + */ + public function setenv($key, $value) { + $this->envopts[$key] = $value; + } + +} + +/* End of file */ \ No newline at end of file diff --git a/lib/copy_this/libs/Git.php/composer.json b/lib/copy_this/libs/Git.php/composer.json new file mode 100644 index 000000000..fb94daed4 --- /dev/null +++ b/lib/copy_this/libs/Git.php/composer.json @@ -0,0 +1,6 @@ +{ + "name": "kbjr/Git.php", + "autoload": { + "classmap": ["Git.php"] + } +} diff --git a/lib/copy_this/libs/Git.php/license.txt b/lib/copy_this/libs/Git.php/license.txt new file mode 100644 index 000000000..1cfbdb3e8 --- /dev/null +++ b/lib/copy_this/libs/Git.php/license.txt @@ -0,0 +1,708 @@ +Copyright (c) 2010 James Brumond + +This software is dual licensed under the MIT and GNU General Public Licenses. +This means that you may use this software under either of these licenses (at +your option). + +-------------------------------------------------------------------------------- +-------------------------------------------------------------------------------- + + MIT LICENSE + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + + + +-------------------------------------------------------------------------------- +-------------------------------------------------------------------------------- + + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/lib/copy_this/libs/Git.php/readme.md b/lib/copy_this/libs/Git.php/readme.md new file mode 100644 index 000000000..b4430a9b4 --- /dev/null +++ b/lib/copy_this/libs/Git.php/readme.md @@ -0,0 +1,21 @@ +# Git.php + +## Description + +A PHP git repository control library. Allows the running of any git command from a PHP class. Runs git commands using `proc_open`, not `exec` or the type, therefore it can run in PHP safe mode. + +## Requirements + +A system with [git](http://git-scm.com/) installed + +## Basic Use + +```php +require_once('Git.php'); + +$repo = Git::open('/path/to/repo'); // -or- Git::create('/path/to/repo') + +$repo->add('.'); +$repo->commit('Some commit message'); +$repo->push('origin', 'master'); +``` diff --git a/lib/copy_this/libs/Git.php/test/test-suite.php b/lib/copy_this/libs/Git.php/test/test-suite.php new file mode 100644 index 000000000..ac42405cb --- /dev/null +++ b/lib/copy_this/libs/Git.php/test/test-suite.php @@ -0,0 +1,170 @@ + function() { + $return = null; + $repo = new GitRepo(); + $found = $repo->test_git(); + if ($found) { + $return = array(0, "Git was located and tested successfully"); + } else { + $return = array(1, "Git could not be found at the default location"); + } + return $return; + }, + + 'Git::create()' => function() { + $return = null; + $repo = Git::create(DIR."/create"); + if (! Git::is_repo($repo)) { + $return = array(2, "Git::create() failed to produce expected output."); + } else { + $return = array(0, "Git::create() executed successfully"); + } + return $return; + }, + + 'Git::create([ $source ])' => function() { + $return = null; + $repo = Git::create(DIR."/createfrom", DIR."/test.git"); + if (! Git::is_repo($repo)) { + $return = array(2, "Git::create([ \$source ]) failed to produce expected output."); + } else { + $return = array(0, "Git::create([ \$source ]) executed successfully"); + } + return $return; + }, + + 'Git::open()' => function() { + $return = null; + $repo = Git::open(DIR."/test.git"); + if (! Git::is_repo($repo)) { + $return = array(2, "Git::open() failed to produce expected output."); + } else { + $return = array(0, "Git::open() executed successfully"); + } + return $return; + } + +); + +class Git_TestSuiteControl { + + protected $warnings = 0; + protected $errors = 0; + + public static function rm($dir) { + if (! file_exists($dir)) return true; + if (! is_dir($dir)) return unlink($dir); + $items = scandir($dir); + closedir(opendir($dir)); + foreach ($items as $item) { + if ($item == '.' || $item == '..') continue; + if (! self::rm("$dir/$item")) return false; + } + return rmdir($dir); + } + + public function __construct() { + $this->output("Starting Git.php Test Suite."); + } + + public function output($msg) { + echo "$msg\n"; + } + + public function warning($msg) { + $this->warnings++; + $this->output("Warning: $msg"); + } + + public function error($msg) { + $this->errors++; + $this->output("Error: $msg"); + } + + public function finish() { + $this->cleanup(); + $this->output("\n\n".str_repeat('-', 30)); + $this->output("Tests Complete. Results:"); + $this->output("Errors: ".$this->errors." Warnings: ".$this->warnings); + } + + public function cleanup() { + self::rm(DIR."/create"); + self::rm(DIR."/createfrom"); + } + + public function run_test($name, $callback) { + $this->output("\nTesting $name."); + $this->cleanup(); + try { + $oldReport = error_reporting(0); + set_error_handler(function($n, $str) { + throw new Exception($str); + }); + $result = $callback(); + error_reporting($oldReport); + restore_error_handler(); + } catch (Exception $e) { + $this->error("Test case threw an exception:\n ".implode("\n ", explode("\n", $e->getMessage()))); + return; + } + switch ($result[0]) { + case 0: + $this->output($result[1]); + break; + case 1: + $this->warning($result[1]); + break; + case 2: + $this->error($result[1]); + break; + } + } + +} + +// define the test class +class Git_TestSuite { + + public static function run() { + + $test = new Git_TestSuiteControl(); + + foreach ($GLOBALS['Git_Tests'] as $name => $callback) { + $test->run_test($name, $callback); + } + + $test->finish(); + unset($test); + + } + +} + +if (__FILE__ == $_SERVER['SCRIPT_FILENAME']) { + header("Content-Type: text/plain"); + Git_TestSuite::run(); +} + +/* End Of File */ diff --git a/lib/copy_this/misc/sphinxsearch/create_se_tables.php b/lib/copy_this/misc/sphinxsearch/create_se_tables.php index 0a567cfd1..31d96dbb3 100644 --- a/lib/copy_this/misc/sphinxsearch/create_se_tables.php +++ b/lib/copy_this/misc/sphinxsearch/create_se_tables.php @@ -1,7 +1,7 @@ queryExec('SELECT id, guid, name, searchname, fromname FROM releases'); if ($rows !== false && $rows->rowCount()) { diff --git a/lib/copy_this/misc/sphinxsearch/toggle_search_type.php b/lib/copy_this/misc/sphinxsearch/toggle_search_type.php index e5c7168d3..99cf683d3 100644 --- a/lib/copy_this/misc/sphinxsearch/toggle_search_type.php +++ b/lib/copy_this/misc/sphinxsearch/toggle_search_type.php @@ -1,7 +1,7 @@ log->error('Error, NN_RELEASE_SEARCH_TYPE in www/settings.php must be set to SPHINX to optimize for Sphinx!' . PHP_EOL); } break; case 'standard': - revertToStandard(new DB()); + revertToStandard(new Settings()); break; } diff --git a/lib/copy_this/misc/testing/checkblanklinenzbs.php b/lib/copy_this/misc/testing/checkblanklinenzbs.php index 790cb4650..878bd2afd 100644 --- a/lib/copy_this/misc/testing/checkblanklinenzbs.php +++ b/lib/copy_this/misc/testing/checkblanklinenzbs.php @@ -1,10 +1,10 @@ get(); diff --git a/lib/copy_this/misc/testing/deletepreviews.php b/lib/copy_this/misc/testing/deletepreviews.php index 06b917ae9..354ef2660 100644 --- a/lib/copy_this/misc/testing/deletepreviews.php +++ b/lib/copy_this/misc/testing/deletepreviews.php @@ -4,10 +4,10 @@ require_once dirname(__FILE__) . '/../../www/config.php'; -use newznab\db\DB; +use newznab\db\Settings; $releases = new Releases(); -$db = new DB; +$db = new Settings; // // delete all previews over a year old diff --git a/lib/copy_this/misc/testing/deletereleases.php b/lib/copy_this/misc/testing/deletereleases.php index ab58a2191..76c44bdfd 100644 --- a/lib/copy_this/misc/testing/deletereleases.php +++ b/lib/copy_this/misc/testing/deletereleases.php @@ -5,10 +5,10 @@ require_once dirname(__FILE__) . '/../../www/config.php'; -use newznab\db\DB; +use newznab\db\Settings; $releases = new Releases(); -$db = new DB(); +$db = new Settings(); // // [1] delete all releases for a group which only has x number of files diff --git a/lib/copy_this/misc/testing/dumpnfo.php b/lib/copy_this/misc/testing/dumpnfo.php index 9d0993906..cf91eada3 100644 --- a/lib/copy_this/misc/testing/dumpnfo.php +++ b/lib/copy_this/misc/testing/dumpnfo.php @@ -1 +1 @@ -queryDirect("select releases.searchname, releases.postdate, uncompress(releasenfo.nfo) as nfo from releases inner join releasenfo on releases.ID = releasenfo.releaseID and releasenfo.nfo is not null order by postdate"); while ($row = $db->getAssocArray($res)) { $dir = date("Ymd", strtotime($row["postdate"])); if (!file_exists($dir)) mkdir($dir); $filename = $dir."/".safeFilename($row["searchname"]).".nfo"; if (!file_exists($filename)) { $fh = fopen($filename, 'w'); fwrite($fh, \newznab\utility\Utility::cp437toUTF($row["nfo"])); fclose($fh); } } \ No newline at end of file +queryDirect("select releases.searchname, releases.postdate, uncompress(releasenfo.nfo) as nfo from releases inner join releasenfo on releases.ID = releasenfo.releaseID and releasenfo.nfo is not null order by postdate"); while ($row = $db->getAssocArray($res)) { $dir = date("Ymd", strtotime($row["postdate"])); if (!file_exists($dir)) mkdir($dir); $filename = $dir."/".safeFilename($row["searchname"]).".nfo"; if (!file_exists($filename)) { $fh = fopen($filename, 'w'); fwrite($fh, \newznab\utility\Utility::cp437toUTF($row["nfo"])); fclose($fh); } } \ No newline at end of file diff --git a/lib/copy_this/misc/testing/fixTVRage.php b/lib/copy_this/misc/testing/fixTVRage.php index 0093fa6b9..35259c2f9 100644 --- a/lib/copy_this/misc/testing/fixTVRage.php +++ b/lib/copy_this/misc/testing/fixTVRage.php @@ -3,7 +3,7 @@ require_once dirname(__FILE__) . '/../../www/config.php'; -$db = new \newznab\db\DB(); +$db = new \newznab\db\Settings(); $sql = "select distinct rageid from tvrage where rageid in (select rageid from tvrage where rageid != -2 group by rageid having count(*) > 1)"; $rows = $db->query($sql); diff --git a/lib/copy_this/misc/testing/fix_filesize.php b/lib/copy_this/misc/testing/fix_filesize.php index daf011028..6d454dd4d 100644 --- a/lib/copy_this/misc/testing/fix_filesize.php +++ b/lib/copy_this/misc/testing/fix_filesize.php @@ -8,9 +8,9 @@ Author: lordgnu require_once dirname(__FILE__) . '/../../www/config.php'; -use newznab\db\DB; +use newznab\db\Settings; -$db = new DB; +$db = new Settings; $s = New Sites; $nzb = new NZB; diff --git a/lib/copy_this/misc/testing/fixreleasename.php b/lib/copy_this/misc/testing/fixreleasename.php index 5253c6f5e..6334cc985 100644 --- a/lib/copy_this/misc/testing/fixreleasename.php +++ b/lib/copy_this/misc/testing/fixreleasename.php @@ -2,7 +2,7 @@ require_once dirname(__FILE__) . '/../../www/config.php'; -$db = new \newznab\db\DB(); +$db = new \newznab\db\Settings(); //query to find rough matches $rows = $db->query("SELECT ID, searchname from releases where searchname like '%QWERTY%'"); diff --git a/lib/copy_this/misc/testing/getConsole.php b/lib/copy_this/misc/testing/getConsole.php index 7d5e9f338..ec8504313 100644 --- a/lib/copy_this/misc/testing/getConsole.php +++ b/lib/copy_this/misc/testing/getConsole.php @@ -3,11 +3,11 @@ require_once dirname(__FILE__) . '/../../www/config.php'; -use newznab\db\DB; +use newznab\db\Settings; $console = new Console(true); -$db = new DB(); +$db = new Settings(); $res = $db->queryDirect(sprintf("SELECT searchname, ID from releases where consoleinfoID IS NULL and categoryID in ( select ID from category where parentID = %d ) ORDER BY id DESC LIMIT %d", Category::CAT_PARENT_GAME, Console::NUMTOPROCESSPERTIME)); diff --git a/lib/copy_this/misc/testing/getCovers.php b/lib/copy_this/misc/testing/getCovers.php index 33a301b67..e1963d369 100644 --- a/lib/copy_this/misc/testing/getCovers.php +++ b/lib/copy_this/misc/testing/getCovers.php @@ -3,11 +3,11 @@ require_once dirname(__FILE__) . '/../../www/config.php'; -use newznab\db\DB; +use newznab\db\Settings; $movie = new Movie(true); -$db = new DB(); +$db = new Settings(); $movies = $db->query("SELECT imdbID from movieinfo where cover = 0"); diff --git a/lib/copy_this/misc/testing/getTVInfo.php b/lib/copy_this/misc/testing/getTVInfo.php index 39c82ff4c..a25268bc9 100644 --- a/lib/copy_this/misc/testing/getTVInfo.php +++ b/lib/copy_this/misc/testing/getTVInfo.php @@ -1,11 +1,11 @@ query("select name from releases where categoryID IN (select ID from category where parentID = 5000) limit 0, 50"); diff --git a/lib/copy_this/misc/testing/movecat.php b/lib/copy_this/misc/testing/movecat.php index a5ccb02f3..fe212fcf7 100644 --- a/lib/copy_this/misc/testing/movecat.php +++ b/lib/copy_this/misc/testing/movecat.php @@ -4,10 +4,10 @@ require_once dirname(__FILE__) . '/../../www/config.php'; -use newznab\db\DB; +use newznab\db\Settings; $releases = new Releases(); -$db = new DB(); +$db = new Settings(); // // [1] move mp3 files from other misc into audio mp3 diff --git a/lib/copy_this/misc/testing/parread.php b/lib/copy_this/misc/testing/parread.php index 167d60b66..7d53ad359 100644 --- a/lib/copy_this/misc/testing/parread.php +++ b/lib/copy_this/misc/testing/parread.php @@ -2,12 +2,12 @@ require_once dirname(__FILE__) . '/../../www/config.php'; -use newznab\db\DB; +use newznab\db\Settings; $s = new Sites(); $site = $s->get(); $releases = new Releases(); -$db = new DB(); +$db = new Settings(); $nzb = new NZB(); $nntp = new NNTP; diff --git a/lib/copy_this/misc/testing/refreshMovie.php b/lib/copy_this/misc/testing/refreshMovie.php index 436c19246..836f2f6c1 100644 --- a/lib/copy_this/misc/testing/refreshMovie.php +++ b/lib/copy_this/misc/testing/refreshMovie.php @@ -2,10 +2,10 @@ require_once dirname(__FILE__) . '/../../www/config.php'; -use newznab\db\DB; +use newznab\db\Settings; $movie = new Movie(true); -$db = new DB(); +$db = new Settings(); $movies = array(); $counter = 1; $sleepsecsbetweenscrape = 1; diff --git a/lib/copy_this/misc/testing/regexverify.php b/lib/copy_this/misc/testing/regexverify.php index 6e30555bf..211f96a39 100644 --- a/lib/copy_this/misc/testing/regexverify.php +++ b/lib/copy_this/misc/testing/regexverify.php @@ -26,7 +26,7 @@ $regs = array( ); $releases = new Releases(); -$db = new DB(); +$db = new Settings(); # fetch enabled regular expression $catsql = "select ID,groupname,regex from releaseregex where status = 1"; $res = $db->query($catsql); diff --git a/lib/copy_this/misc/testing/test_blacklist.php b/lib/copy_this/misc/testing/test_blacklist.php index b318d5b54..a4f95ffce 100644 --- a/lib/copy_this/misc/testing/test_blacklist.php +++ b/lib/copy_this/misc/testing/test_blacklist.php @@ -10,7 +10,7 @@ // require_once dirname(__FILE__) . '/../../www/config.php'; -use newznab\db\DB; +use newznab\db\Settings; # If satisfied with what is matched, set this to true and have @@ -200,11 +200,11 @@ function get_block($offset, $batch) $catsql = "SELECT releases.*,groups.name as groupname FROM " ."releases LEFT JOIN groups on releases.groupID = groups.ID "; - $db = new DB(); + $db = new Settings(); return $db->query($catsql.sprintf(' LIMIT %d,%d', $offset, $batch)); } -$db = new DB(); +$db = new Settings(); $errcnt=0; $total=0; diff --git a/lib/copy_this/misc/testing/test_regex.php b/lib/copy_this/misc/testing/test_regex.php index bf7f482e9..841b873c2 100644 --- a/lib/copy_this/misc/testing/test_regex.php +++ b/lib/copy_this/misc/testing/test_regex.php @@ -7,7 +7,7 @@ // require_once dirname(__FILE__) . '/../../www/config.php'; -use newznab\db\DB; +use newznab\db\Settings; function handleError($errno, $errstr, $errfile, $errline, array $errcontext) { @@ -26,7 +26,7 @@ $regs = array( "simple" => '"data.mp3', ); -$db = new DB(); +$db = new Settings(); # fetch enabled regular expression $catsql = "select ID,groupname,regex from releaseregex where status = 1"; $res = $db->query($catsql); diff --git a/lib/copy_this/misc/testing/tidynzbfolder.php b/lib/copy_this/misc/testing/tidynzbfolder.php index 49195afc6..e340690ae 100644 --- a/lib/copy_this/misc/testing/tidynzbfolder.php +++ b/lib/copy_this/misc/testing/tidynzbfolder.php @@ -1,11 +1,11 @@ get(); -$db = new DB(); +$db = new Settings(); $r = new Releases(); // diff --git a/lib/copy_this/misc/testing/timetest.php b/lib/copy_this/misc/testing/timetest.php index 6ccb07b83..5a8bcfb38 100644 --- a/lib/copy_this/misc/testing/timetest.php +++ b/lib/copy_this/misc/testing/timetest.php @@ -2,10 +2,10 @@ //This Script Verifies your System Time vs Myself Time vs PHP Time require_once dirname(__FILE__) . '/../../www/config.php'; -use newznab\db\DB; +use newznab\db\Settings; $res=""; -$db = new DB(); +$db = new Settings(); $res = $db->queryonerow( sprintf("Select now()")); foreach($res as $time){ echo "Mysql Time Is Now ".$time."\n";} diff --git a/lib/copy_this/misc/testing/transactiontest.php b/lib/copy_this/misc/testing/transactiontest.php index 7f9b0c706..d79b63191 100644 --- a/lib/copy_this/misc/testing/transactiontest.php +++ b/lib/copy_this/misc/testing/transactiontest.php @@ -3,7 +3,7 @@ try { // Create the first database class instance (which will initialize the PDO connection) - $db = new DB(); + $db = new Settings(); // For debug set the error mode $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); @@ -18,7 +18,7 @@ try { echo "--[ Insert run: {$i} ]----------------------------------------". PHP_EOL; // Create a new db class instance (multiple can exist) - $newDb = new DB(); + $newDb = new Settings(); // Check that there is a new db class instance, but no new PDO instance var_dump( $newDb, $newDb->getPDO() ); diff --git a/lib/copy_this/misc/testing/updateCategories.php b/lib/copy_this/misc/testing/updateCategories.php index f51781f4a..f10c6932e 100644 --- a/lib/copy_this/misc/testing/updateCategories.php +++ b/lib/copy_this/misc/testing/updateCategories.php @@ -2,9 +2,9 @@ //This script will rerun all releases against Category.php require_once dirname(__FILE__) . '/../../www/config.php'; -use newznab\db\DB; +use newznab\db\Settings; -$db = new DB(); +$db = new Settings(); $category = new Categorize(); $changedcount = 0; $rescount = 0; diff --git a/lib/copy_this/misc/testing/updateTVRage.php b/lib/copy_this/misc/testing/updateTVRage.php index d97d2a5c8..d7f973a18 100644 --- a/lib/copy_this/misc/testing/updateTVRage.php +++ b/lib/copy_this/misc/testing/updateTVRage.php @@ -1,9 +1,9 @@ query("select releaseID, videowidth, videoheight from releasevideo where definition is null"); foreach($rels as $rel) { $sql = sprintf("update releasevideo set definition = %d where releaseID = %d", $rv->determineVideoResolution($rel["videowidth"], $rel["videoheight"]), $rel["releaseID"]); $db->exec($sql); } ?> \ No newline at end of file +query("select releaseID, videowidth, videoheight from releasevideo where definition is null"); foreach($rels as $rel) { $sql = sprintf("update releasevideo set definition = %d where releaseID = %d", $rv->determineVideoResolution($rel["videowidth"], $rel["videoheight"]), $rel["releaseID"]); $db->exec($sql); } ?> \ No newline at end of file diff --git a/lib/copy_this/misc/update_scripts/backfill.php b/lib/copy_this/misc/update_scripts/backfill.php index 0cc514e59..41593f8ea 100644 --- a/lib/copy_this/misc/update_scripts/backfill.php +++ b/lib/copy_this/misc/update_scripts/backfill.php @@ -1,9 +1,9 @@ $pdo]); diff --git a/lib/copy_this/misc/update_scripts/import.php b/lib/copy_this/misc/update_scripts/import.php index 2d1cfdd0c..da7ab41ca 100644 --- a/lib/copy_this/misc/update_scripts/import.php +++ b/lib/copy_this/misc/update_scripts/import.php @@ -2,11 +2,11 @@ require_once dirname(__FILE__) . '/../../www/config.php'; -use newznab\db\DB; +use newznab\db\Settings; use newznab\utility\Utility; $releases = new Releases(); -$db = new newznab\db\DB(); +$db = new newznab\db\Settings(); $cat = new Category(); $releaseRegex = new ReleaseRegex(); $nzb = new NZB(); diff --git a/lib/copy_this/misc/update_scripts/nix_scripts/multiprocessing/.do_not_run/switch.php b/lib/copy_this/misc/update_scripts/nix_scripts/multiprocessing/.do_not_run/switch.php index 5922ec107..c3812ff45 100644 --- a/lib/copy_this/misc/update_scripts/nix_scripts/multiprocessing/.do_not_run/switch.php +++ b/lib/copy_this/misc/update_scripts/nix_scripts/multiprocessing/.do_not_run/switch.php @@ -6,7 +6,7 @@ if (!isset($argv[1])) { require_once dirname(__FILE__) . '/../../../../../www/config.php'; -use \newznab\db\DB; +use \newznab\db\Settings; use \newznab\processing\PProcess; use \newznab\processing\ProcessReleases; use \newznab\processing\post\ProcessAdditional; @@ -22,7 +22,7 @@ switch ($options[1]) { // $options[3] => (int) backfill type from tmux settings. 1 = Backfill interval , 2 = Bakfill all case 'backfill': if (in_array((int)$options[3], [1, 2])) { - $pdo = new DB(); + $pdo = new Settings(); $value = $pdo->queryOneRow("SELECT value FROM tmux WHERE setting = 'backfill_qty'"); if ($value !== false) { $nntp = nntp($pdo); @@ -37,7 +37,7 @@ switch ($options[1]) { * $options[3] => (int) Quantity of articles to download. */ case 'backfill_all_quantity': - $pdo = new DB(); + $pdo = new Settings(); $nntp = nntp($pdo); (new \Backfill())->backfillAllGroups($options[2], $options[3]); break; @@ -45,7 +45,7 @@ switch ($options[1]) { // BackFill a single group, 10000 parts. // $options[2] => (string)group name, Name of group to work on. case 'backfill_all_quick': - $pdo = new DB(); + $pdo = new Settings(); $nntp = nntp($pdo); (new \Backfill())->backfillAllGroups($options[2], 10000, 'normal'); break; @@ -59,7 +59,7 @@ switch ($options[1]) { * $options[6] => (int) Number of threads. */ case 'get_range': - $pdo = new DB(); + $pdo = new Settings(); $nntp = nntp($pdo); $groups = new \Groups(); $s = new Sites(); @@ -126,7 +126,7 @@ switch ($options[1]) { * $options[2] => (string) Group name. */ case 'part_repair': - $pdo = new DB(); + $pdo = new Settings(); $groups = new \Groups(['Settings' => $pdo]); $groupMySQL = $groups->getByName($options[2]); $nntp = nntp($pdo); @@ -143,7 +143,7 @@ switch ($options[1]) { // Process releases. // $options[2] => (string)groupCount, number of groups terminated by _ | (int)groupid, group to work on case 'releases': - $pdo = new DB(); + $pdo = new Settings(); $s = new Sites(); $site = $s->get(); $releases = new ProcessReleases(['Settings' => $pdo]); @@ -185,7 +185,7 @@ switch ($options[1]) { * $options[2] => (string) Group name. */ case 'update_group_headers': - $pdo = new DB(); + $pdo = new Settings(); $nntp = nntp($pdo); $groups = new \Groups(); $groupMySQL = $groups->getByName($options[2]); @@ -198,7 +198,7 @@ switch ($options[1]) { case 'update_per_group': if (is_numeric($options[2])) { - $pdo = new DB(); + $pdo = new Settings(); // Get the group info from MySQL. $groupMySQL = $pdo->queryOneRow(sprintf('SELECT * FROM groups WHERE id = %d', $options[2])); @@ -232,7 +232,7 @@ switch ($options[1]) { case 'pp_additional': case 'pp_nfo': if (charCheck($options[2])) { - $pdo = new DB(); + $pdo = new Settings(); // Create the connection here and pass, this is for post processing, so check for alternate. $nntp = nntp($pdo, true); @@ -252,7 +252,7 @@ switch ($options[1]) { */ case 'pp_movie': if (charCheck($options[2])) { - $pdo = new DB(); + $pdo = new Settings(); (new PProcess(['Settings' => $pdo]))->processMovies('', $options[2], (isset($options[3]) ? $options[3] : '')); } break; @@ -264,7 +264,7 @@ switch ($options[1]) { */ case 'pp_tv': if (charCheck($options[2])) { - $pdo = new DB(); + $pdo = new Settings(); (new PProcess(['Settings' => $pdo]))->processTv('', $options[2], (isset($options[3]) ? $options[3] : '')); } break; @@ -313,7 +313,7 @@ function charCheck($char) /** * Check if the group should be processed. * - * @param \newznab\db\DB $pdo + * @param \newznab\db\Settings $pdo * @param int $groupID */ function collectionCheck(&$pdo, $groupID) @@ -326,7 +326,7 @@ function collectionCheck(&$pdo, $groupID) /** * Connect to usenet, return NNTP object. * - * @param \newznab\db\DB $pdo + * @param \newznab\db\Settings $pdo * @param bool $alternate Use alternate NNTP provider. * * @return NNTP diff --git a/lib/copy_this/misc/update_scripts/nntpproxy.php b/lib/copy_this/misc/update_scripts/nntpproxy.php index bcc74ff1e..917abae5b 100644 --- a/lib/copy_this/misc/update_scripts/nntpproxy.php +++ b/lib/copy_this/misc/update_scripts/nntpproxy.php @@ -1,12 +1,12 @@ get(); $powerline = (isset($tmux->powerline)) ? $tmux->powerline : 0; diff --git a/lib/copy_this/misc/update_scripts/optimise_db.php b/lib/copy_this/misc/update_scripts/optimise_db.php index 3c474e17e..e61a79588 100644 --- a/lib/copy_this/misc/update_scripts/optimise_db.php +++ b/lib/copy_this/misc/update_scripts/optimise_db.php @@ -2,11 +2,11 @@ require_once("config.php"); -use newznab\db\DB; +use newznab\db\Settings; $force = ((isset($argv[1]) && ($argv[1] == "true"))); -$db = new DB; +$db = new Settings; $ret = $db->optimise($force); if (count($ret) > 0) diff --git a/lib/copy_this/misc/update_scripts/update_binaries.php b/lib/copy_this/misc/update_scripts/update_binaries.php index e210f63e8..0046e5a60 100644 --- a/lib/copy_this/misc/update_scripts/update_binaries.php +++ b/lib/copy_this/misc/update_scripts/update_binaries.php @@ -2,9 +2,9 @@ require_once("config.php"); -use newznab\db\DB; +use newznab\db\Settings; -$pdo = new DB(); +$pdo = new Settings(); // Create the connection here and pass $nntp = new \NNTP(['Settings' => $pdo]); diff --git a/lib/copy_this/misc/update_scripts/update_database_version.php b/lib/copy_this/misc/update_scripts/update_database_version.php index 33dfd1f36..0ff0ab072 100644 --- a/lib/copy_this/misc/update_scripts/update_database_version.php +++ b/lib/copy_this/misc/update_scripts/update_database_version.php @@ -2,7 +2,7 @@ require_once("config.php"); -use newznab\db\DB; +use newznab\db\Settings; $s = new Sites(); $site = $s->get(); @@ -18,8 +18,8 @@ else { echo "Patchn : Executing patch ".basename($patch)."\n"; - $db = new DB(); - $rows = $db->query("select * from site"); + $db = new Settings(); + $rows = $db->query("select * from settings"); $dbData = file_get_contents($patch); //fix to remove BOM in UTF8 files diff --git a/lib/copy_this/newznab/build/addGitHook.php b/lib/copy_this/newznab/build/addGitHook.php new file mode 100644 index 000000000..736bd9be2 --- /dev/null +++ b/lib/copy_this/newznab/build/addGitHook.php @@ -0,0 +1,109 @@ +. + * @author niel + * @copyright 2014 nZEDb + */ +require_once realpath(dirname(__DIR__) . '/../www/automated.config.php'); + +use ColorCLI; + +define('NN_GIT', NN_ROOT . '.git' . DS); +define('NN_HOOKS', NN_GIT . 'hooks' . DS); +define('PRE_COMMIT_HOOK', 'pre-commit'); +define('GIT_HOOK_VERSION', 2); +$current = 1; + +if ($argc > 1 && $argv[1]) { + define('VERBOSE', true); +} else { + define('VERBOSE', false); +} + +$changed = false; +$source = __DIR__ . DS . 'git-hooks' . DS . PRE_COMMIT_HOOK; +$target = NN_HOOKS . DS . PRE_COMMIT_HOOK; + +if (!file_exists(NN_HOOKS . PRE_COMMIT_HOOK)) { + copy($source, $target); +} + +$file = file($target, FILE_IGNORE_NEW_LINES); +if (preg_match('/^(?P#version=)(?P.*)$/', $file[1], $match)) { + $current = $match['value']; +} + +$out = new ColorCLI(); + +$versions = new \newznab\utility\Versions(); +$version = $versions->getGitHookPrecommit(); +if ($version > $current) { + copy($source, $target); + echo $out->info("Updated pre-commit hook to version $version"); + $file = file($target, FILE_IGNORE_NEW_LINES); +} +chmod($target, 0774); + +$count = count($file); +$index = 0; +while ($index < $count) { + if (preg_match('/^#newznab hook\s*-\s*(.+)$/', $file[$index], $match)) { + if (VERBOSE) { + echo $out->primary("Matched: " . $file[$index]); + } + $index++; + $file[$index] = trim($file[$index]); + switch ($match[1]) { + case 'update version info': + case 'run hooks': + $hook = '/usr/bin/php ' . NN_LIB . 'build/git-hooks/runHooks.php'; + if ($hook != $file[$index]) { + if (VERBOSE) { + echo $out->primary('Replace: "' . $file[$index] . '" with "' . $hook . '"'); + } + $file[$index] = $hook; + $changed = true; + } else { + echo $out->primary("Skipped: " . $file[$index]); + } + break; + + default: + $index--; + echo $out->error('Invalid hook placeholder!!'); + break; + } + } else if (preg_match('#^PROJECT=(?P.*)$#', $file[$index], $match)) { + if ($match['path'] != NN_ROOT) { + $file[$index] = 'PROJECT=' . NN_ROOT; + $changed = true; + } + } else { + if (VERBOSE) { + echo $out->primary("Skipped: " . $file[$index]); + } + } + $index++; +} + +if ($changed === false) { + echo $out->warning('Unable to find any hooks needing updates!'); +} else { + if (file_put_contents($target, implode("\n", $file)) === false) { + echo $out->error("Error writing file to disc!!"); + } +} \ No newline at end of file diff --git a/lib/copy_this/newznab/build/git-hooks/pre-commit b/lib/copy_this/newznab/build/git-hooks/pre-commit new file mode 100644 index 000000000..5a65d0fed --- /dev/null +++ b/lib/copy_this/newznab/build/git-hooks/pre-commit @@ -0,0 +1,52 @@ +#!/bin/sh +#version=9 +# +# The hook should +# exit with non-zero status after issuing an appropriate message if +# it wants to stop the commit. +# +# To enable this hook, rename this file to "pre-commit". + +if git rev-parse --verify HEAD >/dev/null 2>&1 +then + AGAINST=HEAD +else + # Initial commit: diff against an empty tree object + AGAINST=4b825dc642cb6eb9a060e54bf8d69288fbee4904 +fi + +##################################################################################################### + +EXIT_STATUS=0 +PROJECT=/path/to/newznab/ +HOOKS=${PROJECT}newznab/build/git-hooks +FILE_LIST=${HOOKS}/git_hook_list.txt + +if [ -e ${FILE_LIST} ] +then + rm ${FILE_LIST} +fi +touch ${FILE_LIST} + +for FILE in `git diff-index --cached --name-only --diff-filter=AM ${AGAINST}` +do + echo ${PROJECT}/${FILE} >> ${FILE_LIST} +done + +#nZEDb hook - run hooks +# placeholder for script to add command with correct path ;-) + +EXIT_STATUS=$? + +if [ -e ${FILE_LIST} ] +then + rm ${FILE_LIST} +fi + +if [ ${EXIT_STATUS} -gt 0 ] +then + exit ${EXIT_STATUS} +fi + +# If there are whitespace errors, print the offending file names and fail. +exec git diff-index --check --cached ${AGAINST} -- \ No newline at end of file diff --git a/lib/copy_this/newznab/build/git-hooks/runHooks.php b/lib/copy_this/newznab/build/git-hooks/runHooks.php new file mode 100644 index 000000000..9523da9fe --- /dev/null +++ b/lib/copy_this/newznab/build/git-hooks/runHooks.php @@ -0,0 +1,75 @@ +. + * @author niel + * @copyright 2014 nZEDb + */ +define('GIT_PRE_COMMIT', true); +require_once realpath(dirname(dirname(dirname(__DIR__))) . DIRECTORY_SEPARATOR . 'www' . + DIRECTORY_SEPARATOR . 'automated.config.php'); + +use newznab\db\DbUpdate; +use newznab\utility\Git; +use newznab\utility\Versions; + +echo "Running pre-commit hooks\n"; + +$error = false; + +// TODO Add code here to check permissions on staged files. +//$files = file(nZEDb_ROOT . 'nzedb/build/git-hooks'), FILE_IGNORE_NEW_LINES); +//foreach ($files as $file) { +// echo "Filename: $file\n"; +//} + +/** + * Add all hooks BEFORE the versions are updated so they can be skipped on any errors + */ +if ($error === false) { + $git = new Git(); + $branch = $git->active_branch(); + if (in_array($branch, $git->mainBranches())) { + // Only update versions, patches, etc. on specific branches to lessen conflicts + try { + // Run DbUpdates to make sure we're up to date. + $DbUpdater = new DbUpdate(['git' => $git]); + $DbUpdater->newPatches(['safe' => false]); + } catch (\Exception $e) { + $error = 1; + echo "Error while checking patches!\n"; + echo $e->getMessage() . "\n"; + } + + if ($error === false) { + try { + $vers = new Versions(); + $vers->checkAll(); + $vers->save(); + $git->add(NN_VERSIONS); + } catch (\Exception $e) { + $error = 1; + echo "Error while checking versions!\n"; + } + } + } else { + echo "not 'dev', 'next-master', or 'master' branch, skipping version/patch updates\n"; + } +} else { + echo "Error in pre-commit hooks!!\n"; +} + +exit($error); \ No newline at end of file diff --git a/lib/copy_this/newznab/build/newznab.xml b/lib/copy_this/newznab/build/newznab.xml new file mode 100644 index 000000000..bacd27569 --- /dev/null +++ b/lib/copy_this/newznab/build/newznab.xml @@ -0,0 +1,17 @@ + + + + + 149 + 149 + + + 0.0.0 + + + 9 + + + + + diff --git a/lib/copy_this/newznab/controllers/AdminPage.php b/lib/copy_this/newznab/controllers/AdminPage.php index 95adf4340..b739e4d7c 100644 --- a/lib/copy_this/newznab/controllers/AdminPage.php +++ b/lib/copy_this/newznab/controllers/AdminPage.php @@ -14,8 +14,8 @@ class AdminPage extends BasePage parent::__construct(); $tplpaths = []; - if ($this->site->style != "default") - $tplpaths["style_admin"] = WWW_DIR.'templates/'.$this->site->style.'/views/admin'; + if ($this->pdo->getSetting('style') != "default") + $tplpaths["style_admin"] = WWW_DIR.'templates/'.$this->pdo->getSetting('style').'/views/admin'; $tplpaths["admin"] = WWW_DIR.'templates/default/views/admin'; $tplpaths["frontend"] = WWW_DIR.'templates/default/views/frontend'; $this->smarty->setTemplateDir($tplpaths); diff --git a/lib/copy_this/newznab/controllers/AniDB.php b/lib/copy_this/newznab/controllers/AniDB.php index 24cc00879..1380fcf85 100644 --- a/lib/copy_this/newznab/controllers/AniDB.php +++ b/lib/copy_this/newznab/controllers/AniDB.php @@ -1,11 +1,11 @@ pdo = ($options['Settings'] instanceof DB ? $options['Settings'] : new DB()); + $this->pdo = ($options['Settings'] instanceof Settings ? $options['Settings'] : new Settings()); } /** @@ -28,6 +28,7 @@ class AniDB * * @param int $anidbID * @param string $type + * @param string $title * @param string $startdate * @param string $enddate * @param string $related @@ -38,7 +39,7 @@ class AniDB * @param string $categories * @param string $characters */ - public function updateTitle($anidbID, $type, $startdate, $enddate, $related, $similar, $creators, $description, $rating, $categories, $characters) + public function updateTitle($anidbID, $title, $type, $startdate, $enddate, $related, $similar, $creators, $description, $rating, $categories, $characters, $epnos, $airdates, $episodetitles) { // FIXME fix the missing variables for this query $this->pdo->queryExec( diff --git a/lib/copy_this/newznab/controllers/Backfill.php b/lib/copy_this/newznab/controllers/Backfill.php index 5da1a6920..3ba6d6656 100644 --- a/lib/copy_this/newznab/controllers/Backfill.php +++ b/lib/copy_this/newznab/controllers/Backfill.php @@ -1,13 +1,13 @@ _echoCLI = ($options['Echo'] && NN_ECHOCLI); - $this->pdo = ($options['Settings'] instanceof DB ? $options['Settings'] : new DB()); + $this->pdo = ($options['Settings'] instanceof Settings ? $options['Settings'] : new Settings()); $this->_groups = ($options['Groups'] instanceof \Groups ? $options['Groups'] : new \Groups(['Settings' => $this->pdo])); $this->_nntp = ($options['NNTP'] instanceof \NNTP ? $options['NNTP'] : new \NNTP(['Settings' => $this->pdo]) @@ -112,10 +112,10 @@ class Backfill } } - $this->_compressedHeaders = ($this->site->compressedheaders == 1 ? true : false); - $this->_safeBackFillDate = ($this->site->safebackfilldate != '') ? (string)$this->site->safebackfilldate : '2008-08-14'; - $this->_safePartRepair = ($this->site->safepartrepair == 1 ? 'update' : 'backfill'); - $this->_tablePerGroup = ($this->site->tablepergroup == 1 ? true : false); + $this->_compressedHeaders = ($this->pdo->getSetting('compressedheaders') == 1 ? true : false); + $this->_safeBackFillDate = ($this->pdo->getSetting('safebackfilldate') != '') ? (string)$this->pdo->getSetting('safebackfilldate') : '2008-08-14'; + $this->_safePartRepair = ($this->pdo->getSetting('safepartrepair') == 1 ? 'update' : 'backfill'); + $this->_tablePerGroup = ($this->pdo->getSetting('tablepergroup') == 1 ? true : false); } /** diff --git a/lib/copy_this/newznab/controllers/BasePage.php b/lib/copy_this/newznab/controllers/BasePage.php index b13a496bd..43c5e94cd 100644 --- a/lib/copy_this/newznab/controllers/BasePage.php +++ b/lib/copy_this/newznab/controllers/BasePage.php @@ -3,11 +3,12 @@ require_once SMARTY_DIR . 'Smarty.class.php'; require_once NN_LIB . 'utility' . DS . 'SmartyUtils.php'; use newznab\controllers\Captcha; +use newznab\db\Settings; class BasePage { /** - * @var \newznab\db\DB + * @var \newznab\db\Settings */ public $settings = null; @@ -60,15 +61,16 @@ class BasePage // set site variable $s = new Sites(); $this->site = $s->get(); + $this->pdo = new Settings(); // Buffer settings/DB connection. - $this->settings = new newznab\db\DB(); + $this->settings = new newznab\db\Settings(); $this->smarty = new Smarty(); $this->captcha = new Captcha(['Settings' => $this->settings]); $this->smarty->setTemplateDir( array( - 'user_frontend' => NN_WWW . 'templates/' . $this->site->style . '/views/frontend', + 'user_frontend' => NN_WWW . 'templates/' . $this->pdo->getSetting('style') . '/views/frontend', 'frontend' => NN_WWW . 'templates/default/views/frontend' ) ); @@ -78,8 +80,8 @@ class BasePage $this->smarty->error_reporting = ((NN_DEBUG ? E_ALL : E_ALL - E_NOTICE)); $this->secure_connection = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || (isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == 443)) ; - if (file_exists(WWW_DIR.'templates/'.$this->site->style.'/theme.php')) - require_once(WWW_DIR.'templates/'.$this->site->style.'/theme.php'); + if (file_exists(WWW_DIR.'templates/'.$this->pdo->getSetting('style').'/theme.php')) + require_once(WWW_DIR.'templates/'.$this->pdo->getSetting('style').'/theme.php'); $this->smarty->assign('themevars', (isset($themevars) ? $themevars : null)); $servername = null; @@ -113,7 +115,7 @@ class BasePage $this->userdata["categoryexclusions"] = $this->users->getCategoryExclusion($this->users->currentUserId()); // Change the theme to user's selected theme if they selected one, else use the admin one. - if ($this->site->userselstyle == 1) { + if ($this->pdo->getSetting('userselstyle') == 1) { if (isset($this->userdata['style']) && $this->userdata['style'] !== 'None') { $this->smarty->setTemplateDir( array( @@ -144,9 +146,9 @@ class BasePage if ($this->userdata["hideads"] == "1") { - $this->site->adheader=""; - $this->site->adbrowse=""; - $this->site->addetail=""; + $this->pdo->setSetting(['adheader', '']); + $this->pdo->setSetting(['adbrowse', '']); + $this->pdo->setSetting(['addetail', '']); } $this->floodCheck($this->userdata["role"]); diff --git a/lib/copy_this/newznab/controllers/Binaries.php b/lib/copy_this/newznab/controllers/Binaries.php index 85fd0fb6f..b4518644c 100644 --- a/lib/copy_this/newznab/controllers/Binaries.php +++ b/lib/copy_this/newznab/controllers/Binaries.php @@ -1,6 +1,6 @@ _site = $s->get(); - $this->_pdo = ($options['Settings'] instanceof DB ? $options['Settings'] : new DB()); + $this->_pdo = ($options['Settings'] instanceof Settings ? $options['Settings'] : new Settings()); $this->_groups = ($options['Groups'] instanceof \Groups ? $options['Groups'] : new \Groups(['Settings' => $this->_pdo])); $this->_colorCLI = ($options['ColorCLI'] instanceof \ColorCLI ? $options['ColorCLI'] : new \ColorCLI()); $this->_nntp = ($options['NNTP'] instanceof \NNTP ? $options['NNTP'] : new \NNTP(['Echo' => $this->_colorCLI, 'Settings' => $this->_pdo, 'ColorCLI' => $this->_colorCLI])); diff --git a/lib/copy_this/newznab/controllers/Book.php b/lib/copy_this/newznab/controllers/Book.php index a08b286cf..0de800db1 100644 --- a/lib/copy_this/newznab/controllers/Book.php +++ b/lib/copy_this/newznab/controllers/Book.php @@ -1,6 +1,6 @@ pubkey = $site->amazonpubkey; $this->privkey = $site->amazonprivkey; $this->asstag = $site->amazonassociatetag; - $this->pdo = new DB(); + $this->pdo = new Settings(); $this->imgSavePath = WWW_DIR.'covers/book/'; } @@ -92,7 +92,7 @@ class Book else $maxage = ""; - $sql = sprintf("select count(distinct r.bookinfoid) as num from releases r inner join bookinfo b on b.id = r.bookinfoid and b.title != '' where r.passwordstatus <= (select value from site where setting='showpasswordedrelease') %s %s", $browseby, $maxage); + $sql = sprintf("select count(distinct r.bookinfoid) as num from releases r inner join bookinfo b on b.id = r.bookinfoid and b.title != '' where r.passwordstatus <= (select value from settings where setting='showpasswordedrelease') %s %s", $browseby, $maxage); $res = $this->pdo->queryOneRow($sql, true); return $res["num"]; @@ -115,7 +115,7 @@ class Book $maxagesql = sprintf(" and r.postdate > now() - interval %d day ", $maxage); $order = $this->getBrowseOrder($orderby); - $sql = sprintf(" SELECT r.bookinfoid, max(postdate), b.* from releases r inner join bookinfo b on b.id = r.bookinfoid and b.title != '' where r.passwordstatus <= (select value from site where setting='showpasswordedrelease') %s %s group by r.bookinfoid order by %s %s".$limit, $browseby, $maxagesql, $order[0], $order[1]); + $sql = sprintf(" SELECT r.bookinfoid, max(postdate), b.* from releases r inner join bookinfo b on b.id = r.bookinfoid and b.title != '' where r.passwordstatus <= (select value from settings where setting='showpasswordedrelease') %s %s group by r.bookinfoid order by %s %s".$limit, $browseby, $maxagesql, $order[0], $order[1]); $rows = $this->pdo->query($sql, true); // diff --git a/lib/copy_this/newznab/controllers/Books.php b/lib/copy_this/newznab/controllers/Books.php index 3e19608f8..60c6e95ce 100644 --- a/lib/copy_this/newznab/controllers/Books.php +++ b/lib/copy_this/newznab/controllers/Books.php @@ -1,6 +1,6 @@ echooutput = ($options['Echo'] && NN_ECHOCLI); - $this->pdo = ($options['Settings'] instanceof DB ? $options['Settings'] : new DB()); + $this->pdo = ($options['Settings'] instanceof Settings ? $options['Settings'] : new Settings()); $s = new Sites(); $this->site = $s->get(); - $this->pubkey = $this->site->amazonpubkey; - $this->privkey = $this->site->amazonprivkey; - $this->asstag = $this->site->amazonassociatetag; - $this->bookqty = ($this->site->maxbooksprocessed != '') ? $this->site->maxbooksprocessed : 300; - $this->sleeptime = ($this->site->amazonsleep != '') ? $this->site->amazonsleep : 1000; + $this->pubkey = $this->pdo->getSetting('amazonpubkey'); + $this->privkey = $this->pdo->getSetting('amazonprivkey'); + $this->asstag = $this->pdo->getSetting('amazonassociatetag'); + $this->bookqty = ($this->pdo->getSetting('maxbooksprocessed') != '') ? $this->pdo->getSetting('maxbooksprocessed') : 300; + $this->sleeptime = ($this->pdo->getSetting('amazonsleep') != '') ? $this->pdo->getSetting('amazonsleep') : 1000; $this->imgSavePath = NN_COVERS . 'book' . DS; - $this->bookreqids = ($this->site->book_reqids == null || $this->site->book_reqids == "") ? 7010 : $this->site->book_reqids; + $this->bookreqids = ($this->pdo->getSetting('book_reqids') == null || $this->pdo->getSetting('book_reqids') == "") ? 7010 : $this->pdo->getSetting('book_reqids'); $this->renamed = ''; - if ($this->site->lookupbooks == 2) { + if ($this->pdo->getSetting('lookupbooks') == 2) { $this->renamed = 'AND isrenamed = 1'; } } diff --git a/lib/copy_this/newznab/controllers/Captcha.php b/lib/copy_this/newznab/controllers/Captcha.php index 422abbacb..4331d2f1c 100644 --- a/lib/copy_this/newznab/controllers/Captcha.php +++ b/lib/copy_this/newznab/controllers/Captcha.php @@ -1,13 +1,13 @@ pdo = ($options['Settings'] instanceof DB ? $options['Settings'] : new DB()); + $this->pdo = ($options['Settings'] instanceof Settings ? $options['Settings'] : new Settings()); $s = new \Sites(); $this->site = $s->get(); } @@ -194,8 +194,8 @@ class Captcha { return true; } - $this->sitekey = $this->site->recaptchapublickey; - $this->secretkey = $this->site->recaptchaprivatekey; + $this->sitekey = $this->pdo->getSetting('recaptchapublickey'); + $this->secretkey = $this->pdo->getSetting('recaptchaprivatekey'); if ($this->sitekey != false && $this->sitekey != '') { if ($this->secretkey != false && $this->secretkey != '') { diff --git a/lib/copy_this/newznab/controllers/Categorize.php b/lib/copy_this/newznab/controllers/Categorize.php index 8ca4ef8fe..ac15fef3d 100644 --- a/lib/copy_this/newznab/controllers/Categorize.php +++ b/lib/copy_this/newznab/controllers/Categorize.php @@ -50,9 +50,9 @@ class Categorize extends Category //parent::__construct($options); $s = new Sites(); $this->site = $s->get(); - $this->pdo = new newznab\db\DB(); - $this->categorizeForeign = ($this->site->categorizeforeign == "0") ? false : true; - $this->catWebDL = ($this->site->catwebdl == "0") ? false : true; + $this->pdo = new newznab\db\Settings(); + $this->categorizeForeign = ($this->pdo->getSetting('categorizeforeign') == "0") ? false : true; + $this->catWebDL = ($this->pdo->getSetting('catwebdl') == "0") ? false : true; $this->regexes = new Regexes(['Settings' => $this->pdo, 'Table_Name' => 'category_regexes']); } diff --git a/lib/copy_this/newznab/controllers/Category.php b/lib/copy_this/newznab/controllers/Category.php index 583a2b10d..379e1024d 100644 --- a/lib/copy_this/newznab/controllers/Category.php +++ b/lib/copy_this/newznab/controllers/Category.php @@ -1,6 +1,6 @@ pdo = ($options['Settings'] instanceof DB ? $options['Settings'] : new DB()); + $this->pdo = ($options['Settings'] instanceof Settings ? $options['Settings'] : new Settings()); } /** @@ -143,7 +143,7 @@ class Category */ public function isParent($cid) { - $db = new newznab\db\DB(); + $db = new newznab\db\Settings(); $ret = $db->queryOneRow(sprintf("select count(*) as count from category where id = %d and parentid is null", $cid), true); if ($ret['count']) return true; @@ -156,7 +156,7 @@ class Category */ public function getChildren($cid) { - $db = new newznab\db\DB(); + $db = new newznab\db\Settings(); return $db->query(sprintf("select c.* from category c where parentid = %d", $cid), true); } @@ -166,7 +166,7 @@ class Category */ public function getFlat($activeonly = false) { - $db = new newznab\db\DB(); + $db = new newznab\db\Settings(); $act = ""; if ($activeonly) $act = sprintf(" where c.status = %d ", Category::STATUS_ACTIVE); @@ -181,7 +181,7 @@ class Category */ public function getEnabledParentNames() { - $db = new newznab\db\DB(); + $db = new newznab\db\Settings(); return $db->query("SELECT title FROM category WHERE parentid IS NULL AND status = 1"); } @@ -193,7 +193,7 @@ class Category */ public function getDisabledIDs() { - $db = new newznab\db\DB(); + $db = new newznab\db\Settings(); return $db->query("SELECT id FROM category WHERE status = 2 OR parentid IN (SELECT id FROM category WHERE status = 2 AND parentid IS NULL)"); } @@ -202,14 +202,14 @@ class Category */ public function getById($id) { - $db = new newznab\db\DB(); + $db = new newznab\db\Settings(); return $db->queryOneRow(sprintf("SELECT c.disablepreview, c.id, c.description, c.minsizetoformrelease, c.maxsizetoformrelease, CONCAT(COALESCE(cp.title,'') , CASE WHEN cp.title IS NULL THEN '' ELSE ' > ' END , c.title) as title, c.status, c.parentid from category c left outer join category cp on cp.id = c.parentid where c.id = %d", $id)); } public function getSizeRangeById($id) { - $db = new newznab\db\DB(); + $db = new newznab\db\Settings(); $res = $db->queryOneRow(sprintf("SELECT c.minsizetoformrelease, c.maxsizetoformrelease, cp.minsizetoformrelease as p_minsizetoformrelease, cp.maxsizetoformrelease as p_maxsizetoformrelease" . " from category c left outer join category cp on cp.id = c.parentid where c.id = %d", $id ) @@ -255,14 +255,14 @@ class Category */ public function getByIds($ids) { - $db = new newznab\db\DB(); + $db = new newznab\db\Settings(); return $db->query(sprintf("SELECT concat(cp.title, ' > ',c.title) as title from category c inner join category cp on cp.id = c.parentid where c.id in (%s)", implode(',', $ids))); } public function getNameByID($ID) { - $db = new newznab\db\DB(); + $db = new newznab\db\Settings(); $parent = $db->queryOneRow(sprintf("SELECT title FROM category WHERE id = %d", substr($ID, 0, 1) . "000")); $cat = $db->queryOneRow(sprintf("SELECT title FROM category WHERE id = %d", $ID)); @@ -274,7 +274,7 @@ class Category */ public function update($id, $status, $desc, $disablepreview, $minsize, $maxsize) { - $db = new newznab\db\DB(); + $db = new newznab\db\Settings(); return $db->queryExec(sprintf("update category set disablepreview = %d, status = %d, minsizetoformrelease = %d, maxsizetoformrelease = %d, description = %s where id = %d", $disablepreview, $status, $minsize, $maxsize, $db->escapeString($desc), $id)); } @@ -284,7 +284,7 @@ class Category */ public function getForMenu($excludedcats = array()) { - $db = new newznab\db\DB(); + $db = new newznab\db\Settings(); $ret = array(); $exccatlist = ""; @@ -340,7 +340,7 @@ class Category */ public function get($activeonly = false, $excludedcats = array()) { - $db = new newznab\db\DB(); + $db = new newznab\db\Settings(); $exccatlist = ""; if (count($excludedcats) > 0) diff --git a/lib/copy_this/newznab/controllers/CollectionsCleaning.php b/lib/copy_this/newznab/controllers/CollectionsCleaning.php index ea1d2b384..944694118 100644 --- a/lib/copy_this/newznab/controllers/CollectionsCleaning.php +++ b/lib/copy_this/newznab/controllers/CollectionsCleaning.php @@ -55,7 +55,7 @@ class CollectionsCleaning public $subject = ''; /** - * @var \newznab\db\DB + * @var \newznab\db\Settings */ public $pdo; @@ -79,7 +79,7 @@ class CollectionsCleaning ]; $options += $defaults; - $this->pdo = ($options['Settings'] instanceof newznab\db\DB ? $options['Settings'] : new newznab\db\DB()); + $this->pdo = ($options['Settings'] instanceof newznab\db\Settings ? $options['Settings'] : new newznab\db\Settings()); $this->_regexes = new Regexes(['Settings' => $this->pdo, 'Table_Name' => 'collection_regexes']); } diff --git a/lib/copy_this/newznab/controllers/Console.php b/lib/copy_this/newznab/controllers/Console.php index 2d7a84987..28932ccd8 100644 --- a/lib/copy_this/newznab/controllers/Console.php +++ b/lib/copy_this/newznab/controllers/Console.php @@ -1,7 +1,7 @@ pubkey = $site->amazonpubkey; $this->privkey = $site->amazonprivkey; $this->asstag = $site->amazonassociatetag; - $this->pdo = new newznab\db\DB(); + $this->pdo = new newznab\db\Settings(); $this->imgSavePath = WWW_DIR.'covers/console/'; } @@ -122,7 +122,7 @@ class Console if (count($excludedcats) > 0) $exccatlist = " and r.categoryid not in (".implode(",", $excludedcats).")"; - $sql = sprintf("select count(r.id) as num from releases r inner join consoleinfo con on con.id = r.consoleinfoid and con.title != '' where r.passwordstatus <= (select value from site where setting='showpasswordedrelease') and %s %s %s %s", $browseby, $catsrch, $maxage, $exccatlist); + $sql = sprintf("select count(r.id) as num from releases r inner join consoleinfo con on con.id = r.consoleinfoid and con.title != '' where r.passwordstatus <= (select value from settings where setting='showpasswordedrelease') and %s %s %s %s", $browseby, $catsrch, $maxage, $exccatlist); $res = $this->pdo->queryOneRow($sql, true); return $res["num"]; } @@ -177,7 +177,7 @@ class Console $exccatlist = " and r.categoryid not in (".implode(",", $excludedcats).")"; $order = $this->getConsoleOrder($orderby); - $sql = sprintf(" SELECT r.*, r.id as releaseid, con.*, g.title as genre, groups.name as group_name, concat(cp.title, ' > ', c.title) as category_name, concat(cp.id, ',', c.id) as category_ids, rn.id as nfoid from releases r left outer join groups on groups.id = r.groupid inner join consoleinfo con on con.id = r.consoleinfoid left outer join releasenfo rn on rn.releaseid = r.id and rn.nfo is not null left outer join category c on c.id = r.categoryid left outer join category cp on cp.id = c.parentid left outer join genres g on g.id = con.genreID where r.passwordstatus <= (select value from site where setting='showpasswordedrelease') and %s %s %s %s order by %s %s".$limit, $browseby, $catsrch, $maxagesql, $exccatlist, $order[0], $order[1]); + $sql = sprintf(" SELECT r.*, r.id as releaseid, con.*, g.title as genre, groups.name as group_name, concat(cp.title, ' > ', c.title) as category_name, concat(cp.id, ',', c.id) as category_ids, rn.id as nfoid from releases r left outer join groups on groups.id = r.groupid inner join consoleinfo con on con.id = r.consoleinfoid left outer join releasenfo rn on rn.releaseid = r.id and rn.nfo is not null left outer join category c on c.id = r.categoryid left outer join category cp on cp.id = c.parentid left outer join genres g on g.id = con.genreID where r.passwordstatus <= (select value from settings where setting='showpasswordedrelease') and %s %s %s %s order by %s %s".$limit, $browseby, $catsrch, $maxagesql, $exccatlist, $order[0], $order[1]); return $this->pdo->query($sql, true); } diff --git a/lib/copy_this/newznab/controllers/Contents.php b/lib/copy_this/newznab/controllers/Contents.php index ec94db79e..400f2a992 100644 --- a/lib/copy_this/newznab/controllers/Contents.php +++ b/lib/copy_this/newznab/controllers/Contents.php @@ -1,6 +1,6 @@ queryExec(sprintf("DELETE from content where id=%d", $id)); } @@ -43,7 +43,7 @@ class Contents */ public function update($content) { - $db = new DB(); + $db = new Settings(); $content = $this->validate($content); $db->queryExec(sprintf("update content set role=%d, title = %s , url = %s , body = %s , metadescription = %s , metakeywords = %s , contenttype = %d , showinmenu = %d , status = %d , ordinal = %d where id = %d ", $content["role"], $db->escapeString($content["title"]), $db->escapeString($content["url"]), $db->escapeString($content["body"]), $db->escapeString($content["metadescription"]), $db->escapeString($content["metakeywords"]), $content["contenttype"], $content["showinmenu"], $content["status"], $content["ordinal"], $content["id"] )); } @@ -53,7 +53,7 @@ class Contents */ public function add($content) { - $db = new DB(); + $db = new Settings(); $content = $this->validate($content); @@ -65,7 +65,7 @@ class Contents */ public function get() { - $db = new DB(); + $db = new Settings(); return $db->query(sprintf("select * from content where status = 1 order by contenttype, coalesce(ordinal, 1000000)")); } @@ -74,7 +74,7 @@ class Contents */ public function getAll() { - $db = new DB(); + $db = new Settings(); return $db->query(sprintf("select * from content order by contenttype, coalesce(ordinal, 1000000)")); } @@ -83,7 +83,7 @@ class Contents */ public function getByID($id, $role) { - $db = new DB(); + $db = new Settings(); if ($role == Users::ROLE_ADMIN) $role = ""; else @@ -97,7 +97,7 @@ class Contents */ public function getIndex() { - $db = new DB(); + $db = new Settings(); return $db->queryOneRow(sprintf("select * from content where status=1 and contenttype = %d ", Contents::TYPEINDEX), true); } @@ -106,7 +106,7 @@ class Contents */ public function getForMenuByTypeAndRole($id, $role) { - $db = new DB(); + $db = new Settings(); if ($role == Users::ROLE_ADMIN) $role = ""; else diff --git a/lib/copy_this/newznab/controllers/Enzebe.php b/lib/copy_this/newznab/controllers/Enzebe.php index 69ad6bca7..97a9fb4b1 100644 --- a/lib/copy_this/newznab/controllers/Enzebe.php +++ b/lib/copy_this/newznab/controllers/Enzebe.php @@ -1,6 +1,6 @@ pdo = ($pdo instanceof DB ? $pdo : new DB()); - $s = new Sites(); - $this->site = $s->get(); + $this->pdo = ($pdo instanceof Settings ? $pdo : new Settings()); - $this->tablePerGroup = ($this->site->tablepergroup == 0 ? false : true); - $nzbSplitLevel = $this->site->nzbsplitlevel; + $this->tablePerGroup = ($this->pdo->getSetting('tablepergroup') == 0 ? false : true); + $nzbSplitLevel = $this->pdo->getSetting('nzbsplitlevel'); $this->nzbSplitLevel = (empty($nzbSplitLevel) ? 1 : $nzbSplitLevel); - $this->siteNzbPath = (string)$this->site->nzbpath; + $this->siteNzbPath = (string)$this->pdo->getSetting('nzbpath'); if (substr($this->siteNzbPath, -1) !== DS) { $this->siteNzbPath .= DS; } diff --git a/lib/copy_this/newznab/controllers/Episode.php b/lib/copy_this/newznab/controllers/Episode.php index cc8656679..233e6a37f 100644 --- a/lib/copy_this/newznab/controllers/Episode.php +++ b/lib/copy_this/newznab/controllers/Episode.php @@ -1,6 +1,6 @@ queryOneRow(sprintf('SELECT * FROM episodeinfo WHERE id = %d', $episodeinfoID)); } @@ -21,7 +21,7 @@ class Episode */ public function getEpisodeInfoByName($showtitle, $fullep, $epabsolute='0') { - $db = new DB(); + $db = new Settings(); if($epabsolute == '0') //as string - not int. if(!preg_match('/[21]\d{3}\/\d{2}\/\d{2}/', $fullep)) diff --git a/lib/copy_this/newznab/controllers/Film.php b/lib/copy_this/newznab/controllers/Film.php index 4eace77a8..14d53cad7 100644 --- a/lib/copy_this/newznab/controllers/Film.php +++ b/lib/copy_this/newznab/controllers/Film.php @@ -1,6 +1,6 @@ pdo = ($options['Settings'] instanceof DB ? $options['Settings'] : new DB()); + $this->pdo = ($options['Settings'] instanceof Settings ? $options['Settings'] : new Settings()); $s = new Sites(); $this->site = $s->get(); $this->releaseImage = ($options['ReleaseImage'] instanceof \ReleaseImage ? $options['ReleaseImage'] : new \ReleaseImage($this->pdo)); - $this->lookuplanguage = ($this->site->lookuplanguage != '') ? (string)$this->site->lookuplanguage : 'en'; + $this->lookuplanguage = ($this->pdo->getSetting('lookuplanguage') != '') ? (string)$this->pdo->getSetting('lookuplanguage') : 'en'; - $this->fanartapikey = $this->site->fanarttvkey; - $this->imdburl = ($this->site->imdburl == 0 ? false : true); - $this->movieqty = ($this->site->maximdbprocessed != '') ? $this->site->maximdbprocessed : 100; + $this->fanartapikey = $this->pdo->getSetting('fanarttvkey'); + $this->imdburl = ($this->pdo->getSetting('imdburl') == 0 ? false : true); + $this->movieqty = ($this->pdo->getSetting('maximdbprocessed') != '') ? $this->pdo->getSetting('maximdbprocessed') : 100; $this->searchEngines = true; - $this->showPasswords = ($this->site->showpasswordedrelease != '') ? $this->site->showpasswordedrelease : 0; + $this->showPasswords = ($this->pdo->getSetting('showpasswordedrelease') != '') ? $this->pdo->getSetting('showpasswordedrelease') : 0; $this->debug = NN_DEBUG; $this->echooutput = ($options['Echo'] && NN_ECHOCLI && $this->pdo->cli); @@ -719,7 +719,7 @@ class Film public function fetchTMDBProperties($imdbId, $text = false) { $lookupId = ($text === false ? 'tt' . $imdbId : $imdbId); - $tmdb = new TMDB($this->site->tmdbkey); + $tmdb = new TMDB($this->pdo->getSetting('tmdbkey')); try { $tmdbLookup = $tmdb->getMovie($lookupId); @@ -821,7 +821,7 @@ class Film $buffer = Utility::getUrl([ 'url' => 'http://' . ($this->imdburl === false ? 'www' : 'akas') . '.imdb.com/title/tt' . $imdbId . '/', - 'language' => (($this->site->lookuplanguage != '') ? $this->site->lookuplanguage : 'en'), + 'language' => (($this->pdo->getSetting('lookuplanguage') != '') ? $this->pdo->getSetting('lookuplanguage') : 'en'), 'useragent' => 'Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) ' . 'Version/4.0.4 Mobile/7B334b Safari/531.21.102011-10-16 20:23:10', 'foo=bar' ] @@ -1333,7 +1333,7 @@ class Film $this->pdo->log->doEcho($this->pdo->log->header('Updating movie schedule using rotten tomatoes.')); } - $rt = new \RottenTomato($this->site->rottentomatokey); + $rt = new \RottenTomato($this->pdo->getSetting('rottentomatokey')); if ($rt instanceof \RottenTomato) { diff --git a/lib/copy_this/newznab/controllers/Forum.php b/lib/copy_this/newznab/controllers/Forum.php index b8f48017a..366ea9c58 100644 --- a/lib/copy_this/newznab/controllers/Forum.php +++ b/lib/copy_this/newznab/controllers/Forum.php @@ -1,6 +1,6 @@ queryOneRow(sprintf(" SELECT forumpost.*, users.username from forumpost left outer join users on users.id = forumpost.userid where forumpost.id = %d ", $parent)); } @@ -44,7 +44,7 @@ class Forum */ public function getRecentPosts($limit) { - $db = new DB(); + $db = new Settings(); return $db->query(sprintf("select forumpost.*, users.username from forumpost join (select case when parentid = 0 then id else parentid end as id, max(createddate) from forumpost group by case when parentid = 0 then id else parentid end order by max(createddate) desc) x on x.id = forumpost.id inner join users on userid = users.id limit %d", $limit)); } @@ -54,7 +54,7 @@ class Forum */ public function getPosts($parent) { - $db = new DB(); + $db = new Settings(); return $db->query(sprintf(" SELECT forumpost.*, CASE WHEN role=%d THEN 1 ELSE 0 END AS 'isadmin', users.username from forumpost left outer join users on users.id = forumpost.userid where forumpost.id = %d or parentid = %d order by createddate asc limit 250", Users::ROLE_ADMIN, $parent, $parent)); } @@ -63,7 +63,7 @@ class Forum */ public function getPost($id) { - $db = new DB(); + $db = new Settings(); return $db->queryOneRow(sprintf(" SELECT * from forumpost where id = %d", $id)); } @@ -72,7 +72,7 @@ class Forum */ public function getBrowseCount() { - $db = new DB(); + $db = new Settings(); $res = $db->queryOneRow(sprintf("select count(id) as num from forumpost where parentid = 0")); return $res["num"]; } @@ -82,7 +82,7 @@ class Forum */ public function getBrowseRange($start, $num) { - $db = new DB(); + $db = new Settings(); if ($start === false) $limit = ""; @@ -97,7 +97,7 @@ class Forum */ public function deleteParent($parent) { - $db = new DB(); + $db = new Settings(); $db->queryExec(sprintf("DELETE from forumpost where id = %d or parentid = %d", $parent, $parent)); } @@ -106,7 +106,7 @@ class Forum */ public function deletePost($id) { - $db = new DB(); + $db = new Settings(); $post = $this->getPost($id); if ($post) { @@ -122,7 +122,7 @@ class Forum */ public function deleteUser($id) { - $db = new DB(); + $db = new Settings(); $db->queryExec(sprintf("DELETE from forumpost where userid = %d", $id)); } @@ -131,7 +131,7 @@ class Forum */ public function getCountForUser($uid) { - $db = new DB(); + $db = new Settings(); $res = $db->queryOneRow(sprintf("select count(id) as num from forumpost where userid = %d", $uid)); return $res["num"]; } @@ -141,7 +141,7 @@ class Forum */ public function getForUserRange($uid, $start, $num) { - $db = new DB(); + $db = new Settings(); if ($start === false) $limit = ""; diff --git a/lib/copy_this/newznab/controllers/Games.php b/lib/copy_this/newznab/controllers/Games.php index 29a233ed3..23e334b59 100644 --- a/lib/copy_this/newznab/controllers/Games.php +++ b/lib/copy_this/newznab/controllers/Games.php @@ -1,7 +1,7 @@ site = $s->get(); $this->echoOutput = ($options['Echo'] && NN_ECHOCLI); - $this->pdo = ($options['Settings'] instanceof DB ? $options['Settings'] : new DB()); + $this->pdo = ($options['Settings'] instanceof Settings ? $options['Settings'] : new Settings()); - $this->publicKey = $this->site->giantbombkey; - $this->gameQty = ($this->site->maxgamesprocessed != '') ? $this->site->maxgamesprocessed : 150; - $this->sleepTime = ($this->site->amazonsleep != '') ? $this->site->amazonsleep : 1000; + $this->publicKey = $this->pdo->getSetting('giantbombkey'); + $this->gameQty = ($this->pdo->getSetting('maxgamesprocessed') != '') ? $this->pdo->getSetting('maxgamesprocessed') : 150; + $this->sleepTime = ($this->pdo->getSetting('amazonsleep') != '') ? $this->pdo->getSetting('amazonsleep') : 1000; $this->imgSavePath = NN_COVERS . 'games' . DS; $this->renamed = ''; $this->matchPercentage = 60; $this->maxHitRequest = false; $this->cookie = NN_TMP . 'xxx.cookie'; - if ($this->site->lookupgames == 2) { + if ($this->pdo->getSetting('lookupgames') == 2) { $this->renamed = 'AND isrenamed = 1'; } - //$this->cleangames = ($this->site->('lookupgames') == 2) ? 'AND isrenamed = 1' : ''; + //$this->cleangames = ($this->pdo->getSetting('('lookupgames') == 2) ? 'AND isrenamed = 1' : ''; } public function getGamesInfo($id) diff --git a/lib/copy_this/newznab/controllers/Genres.php b/lib/copy_this/newznab/controllers/Genres.php index e5d87f0c5..4b0f45986 100644 --- a/lib/copy_this/newznab/controllers/Genres.php +++ b/lib/copy_this/newznab/controllers/Genres.php @@ -1,6 +1,6 @@ pdo = ($options['Settings'] instanceof DB ? $options['Settings'] : new DB()); + $this->pdo = ($options['Settings'] instanceof Settings ? $options['Settings'] : new Settings()); } public function getGenres($type = '', $activeonly = false) diff --git a/lib/copy_this/newznab/controllers/Groups.php b/lib/copy_this/newznab/controllers/Groups.php index 9a50b6015..1001d320a 100644 --- a/lib/copy_this/newznab/controllers/Groups.php +++ b/lib/copy_this/newznab/controllers/Groups.php @@ -1,6 +1,6 @@ pdo = ($options['Settings'] instanceof DB ? $options['Settings'] : new DB()); + $this->pdo = ($options['Settings'] instanceof Settings ? $options['Settings'] : new Settings()); } /** * Get all group rows. diff --git a/lib/copy_this/newznab/controllers/IRCScraper.php b/lib/copy_this/newznab/controllers/IRCScraper.php index 5d1cc55a6..d8526e43a 100644 --- a/lib/copy_this/newznab/controllers/IRCScraper.php +++ b/lib/copy_this/newznab/controllers/IRCScraper.php @@ -1,6 +1,6 @@ _titleIgnoreRegex = SCRAPE_IRC_TITLE_IGNORE; } - $this->_pdo = new DB(); + $this->_pdo = new Settings(); $this->_groupList = array(); $this->_silent = $silent; $this->_debug = $debug; diff --git a/lib/copy_this/newznab/controllers/Info.php b/lib/copy_this/newznab/controllers/Info.php index a4456ad08..fa5433094 100644 --- a/lib/copy_this/newznab/controllers/Info.php +++ b/lib/copy_this/newznab/controllers/Info.php @@ -1,5 +1,5 @@ site = $s->get(); $this->echo = ($options['Echo'] && NN_ECHOCLI); - $this->pdo = ($options['Settings'] instanceof DB ? $options['Settings'] : new DB()); + $this->pdo = ($options['Settings'] instanceof Settings ? $options['Settings'] : new Settings()); $s = new Sites(); $this->site = $s->get(); - $this->nzbs = ($this->site->maxnfoprocessed != '') ? (int)$this->site->maxnfoprocessed : 100; - $this->maxsize = ($this->site->maxsizetoprocessnfo != '') ? (int)$this->site->maxsizetoprocessnfo : 100; + $this->nzbs = ($this->pdo->getSetting('maxnfoprocessed') != '') ? (int)$this->pdo->getSetting('maxnfoprocessed') : 100; + $this->maxsize = ($this->pdo->getSetting('maxsizetoprocessnfo') != '') ? (int)$this->pdo->getSetting('maxsizetoprocessnfo') : 100; $this->maxsize = ($this->maxsize > 0 ? ('AND size < ' . ($this->maxsize * 1073741824)) : ''); - $this->minsize = ($this->site->minsizetoprocessnfo != '') ? (int)$this->site->minsizetoprocessnfo : 100; + $this->minsize = ($this->pdo->getSetting('minsizetoprocessnfo') != '') ? (int)$this->pdo->getSetting('minsizetoprocessnfo') : 100; $this->minsize = ($this->minsize > 0 ? ('AND size > ' . ($this->minsize * 1048576)) : ''); - $this->maxRetries = (int)($this->site->maxnforetries >= 0 ? -((int)$this->site->maxnforetries + 1) : self::NFO_UNPROC); + $this->maxRetries = (int)($this->pdo->getSetting('maxnforetries') >= 0 ? -((int)$this->pdo->getSetting('maxnforetries') + 1) : self::NFO_UNPROC); $this->maxRetries = ($this->maxRetries < -8 ? -8 : $this->maxRetries); - $this->tmpPath = (string)$this->site->tmpunrarpath; + $this->tmpPath = (string)$this->pdo->getSetting('tmpunrarpath'); if (!preg_match('/[\/\\\\]$/', $this->tmpPath)) { $this->tmpPath .= DS; } @@ -240,13 +240,13 @@ class Info * "AND r.nzbstatus = 1 AND r.nfostatus BETWEEN -8 AND -1 AND r.size < 1073741824 AND r.size > 1048576" * To use in a query. * - * @param DB $pdo + * @param Settings $pdo * * @return string * @access public * @static */ - static public function NfoQueryString(DB &$pdo) + static public function NfoQueryString(Settings &$pdo) { $s = new Sites(); $site = $s->get(); diff --git a/lib/copy_this/newznab/controllers/Konsole.php b/lib/copy_this/newznab/controllers/Konsole.php index 6d3b156f2..5f6ec20fc 100644 --- a/lib/copy_this/newznab/controllers/Konsole.php +++ b/lib/copy_this/newznab/controllers/Konsole.php @@ -1,6 +1,6 @@ echooutput = ($options['Echo'] && NN_ECHOCLI); - $this->pdo = ($options['Settings'] instanceof DB ? $options['Settings'] : new DB()); + $this->pdo = ($options['Settings'] instanceof Settings ? $options['Settings'] : new Settings()); $s = new Sites(); $this->site = $s->get(); - $this->pubkey = $this->site->amazonpubkey; - $this->privkey = $this->site->amazonprivkey; - $this->asstag = $this->site->amazonassociatetag; - $this->gameqty = ($this->site->maxgamesprocessed != '') ? $this->site->maxgamesprocessed : 150; - $this->sleeptime = ($this->site->amazonsleep != '') ? $this->site->amazonsleep : 1000; + $this->pubkey = $this->pdo->getSetting('amazonpubkey'); + $this->privkey = $this->pdo->getSetting('amazonprivkey'); + $this->asstag = $this->pdo->getSetting('amazonassociatetag'); + $this->gameqty = ($this->pdo->getSetting('maxgamesprocessed') != '') ? $this->pdo->getSetting('maxgamesprocessed') : 150; + $this->sleeptime = ($this->pdo->getSetting('amazonsleep') != '') ? $this->pdo->getSetting('amazonsleep') : 1000; $this->imgSavePath = NN_COVERS . 'console' . DS; $this->renamed = ''; - if ($this->site->lookupgames == 2) { + if ($this->pdo->getSetting('lookupgames') == 2) { $this->renamed = 'AND isrenamed = 1'; } //$this->cleanconsole = ($this->pdo->getSetting('lookupgames') == 2) ? 'AND isrenamed = 1' : ''; diff --git a/lib/copy_this/newznab/controllers/Menu.php b/lib/copy_this/newznab/controllers/Menu.php index d79a153d5..db16b9108 100644 --- a/lib/copy_this/newznab/controllers/Menu.php +++ b/lib/copy_this/newznab/controllers/Menu.php @@ -1,6 +1,6 @@ query(sprintf("select * from menu order by role, ordinal")); } @@ -55,7 +55,7 @@ class Menu */ public function getById($id) { - $db = new newznab\db\DB(); + $db = new newznab\db\Settings(); return $db->queryOneRow(sprintf("select * from menu where id = %d", $id)); } @@ -64,7 +64,7 @@ class Menu */ public function delete($id) { - $db = new newznab\db\DB(); + $db = new newznab\db\Settings(); return $db->queryExec(sprintf("DELETE from menu where id = %d", $id)); } @@ -73,7 +73,7 @@ class Menu */ public function add($menu) { - $db = new newznab\db\DB(); + $db = new newznab\db\Settings(); return $db->queryInsert(sprintf("INSERT INTO menu (href, title, tooltip, role, ordinal, menueval, newwindow ) VALUES (%s, %s, %s, %d, %d, %s, %d) ", $db->escapeString($menu["href"]), $db->escapeString($menu["title"]), $db->escapeString($menu["tooltip"]), $menu["role"] , $menu["ordinal"], $db->escapeString($menu["menueval"]), $menu["newwindow"] )); } @@ -83,7 +83,7 @@ class Menu */ public function update($menu) { - $db = new newznab\db\DB(); + $db = new newznab\db\Settings(); return $db->queryExec(sprintf("update menu set href = %s, title = %s, tooltip = %s, role = %d, ordinal = %d, menueval = %s, newwindow=%d where id = %d ", $db->escapeString($menu["href"]), $db->escapeString($menu["title"]), $db->escapeString($menu["tooltip"]), $menu["role"] , $menu["ordinal"], $db->escapeString($menu["menueval"]), $menu["newwindow"], $menu["id"] )); } } \ No newline at end of file diff --git a/lib/copy_this/newznab/controllers/MiscSorter.php b/lib/copy_this/newznab/controllers/MiscSorter.php index f262d8056..f44c7c266 100644 --- a/lib/copy_this/newznab/controllers/MiscSorter.php +++ b/lib/copy_this/newznab/controllers/MiscSorter.php @@ -1,6 +1,6 @@ qty = 100; $this->DEBUGGING = NN_DEBUG; - $this->pdo = ($pdo instanceof DB ? $pdo : new DB()); + $this->pdo = ($pdo instanceof Settings ? $pdo : new Settings()); $this->category = new Categorize(['Settings' => $this->pdo]); $this->movie = new Film(['Echo' => $this->echooutput, 'Settings' => $this->pdo]); $s = new Sites(); $this->site = $s->get(); - $this->pubkey = $this->site->amazonpubkey; - $this->privkey = $this->site->amazonprivkey; - $this->asstag = $this->site->amazonassociatetag; + $this->pubkey = $this->pdo->getSetting('amazonpubkey'); + $this->privkey = $this->pdo->getSetting('amazonprivkey'); + $this->asstag = $this->pdo->getSetting('amazonassociatetag'); } // Main function that determines which operation(s) should be run based on the releases NFO file @@ -378,7 +378,7 @@ class MiscSorter echo $e->getMessage(); } - //$amazon = new AmazonProductAPI($this->site->amazonpubkey, $this->site->amazonprivkey, $this->site->amazonassociatetag); + //$amazon = new AmazonProductAPI($this->pdo->getSetting('amazonpubkey, $this->pdo->getSetting('amazonprivkey, $this->pdo->getSetting('amazonassociatetag); $amalookup = new Lookup(); $apaiIo = new ApaiIO($conf); diff --git a/lib/copy_this/newznab/controllers/Movie.php b/lib/copy_this/newznab/controllers/Movie.php index 7d13da0d9..38417a326 100644 --- a/lib/copy_this/newznab/controllers/Movie.php +++ b/lib/copy_this/newznab/controllers/Movie.php @@ -1,7 +1,7 @@ get(); $this->apikey = $site->tmdbkey; $this->lookuplanguage = $site->lookuplanguage; - $this->pdo = new DB(); + $this->pdo = new Settings(); $this->imgSavePath = NN_COVERS . 'movies' . DS; } @@ -175,7 +175,7 @@ class Movie if (count($excludedcats) > 0) $exccatlist = " and r.categoryid not in (".implode(",", $excludedcats).")"; - $sql = sprintf("select count(distinct r.imdbid) as num from releases r inner join movieinfo m on m.imdbid = r.imdbid and m.title != '' where r.passwordstatus <= (select value from site where setting='showpasswordedrelease') and %s %s %s %s ", $browseby, $catsrch, $maxage, $exccatlist); + $sql = sprintf("select count(distinct r.imdbid) as num from releases r inner join movieinfo m on m.imdbid = r.imdbid and m.title != '' where r.passwordstatus <= (select value from settings where setting='showpasswordedrelease') and %s %s %s %s ", $browseby, $catsrch, $maxage, $exccatlist); $res = $this->pdo->queryOneRow($sql, true); return $res["num"]; } @@ -232,7 +232,7 @@ class Movie $exccatlist = " and r.categoryid not in (".implode(",", $excludedcats).")"; $order = $this->getMovieOrder($orderby); - $sql = sprintf(" SELECT r.imdbid, max(r.postdate) as postdate, m.* from releases r inner join movieinfo m on m.imdbid = r.imdbid where r.passwordstatus <= (select value from site where setting='showpasswordedrelease') and m.title != '' and r.imdbid != 0000000 and %s %s %s %s group by r.imdbid order by %s %s".$limit, $browseby, $catsrch, $maxagesql, $exccatlist, $order[0], $order[1]); + $sql = sprintf(" SELECT r.imdbid, max(r.postdate) as postdate, m.* from releases r inner join movieinfo m on m.imdbid = r.imdbid where r.passwordstatus <= (select value from settings where setting='showpasswordedrelease') and m.title != '' and r.imdbid != 0000000 and %s %s %s %s group by r.imdbid order by %s %s".$limit, $browseby, $catsrch, $maxagesql, $exccatlist, $order[0], $order[1]); $rows = $this->pdo->query($sql, true); // @@ -348,7 +348,7 @@ class Movie */ public function getBrowseBy() { - $this->pdo = new newznab\db\DB; + $this->pdo = new newznab\db\Settings; $browseby = ' '; $browsebyArr = $this->getBrowseByOptions(); diff --git a/lib/copy_this/newznab/controllers/Music.php b/lib/copy_this/newznab/controllers/Music.php index c4d36ae2f..d465762cb 100644 --- a/lib/copy_this/newznab/controllers/Music.php +++ b/lib/copy_this/newznab/controllers/Music.php @@ -1,7 +1,7 @@ pubkey = $site->amazonpubkey; $this->privkey = $site->amazonprivkey; $this->asstag = $site->amazonassociatetag; - $this->pdo = new newznab\db\DB(); + $this->pdo = new newznab\db\Settings(); $this->imgSavePath = WWW_DIR.'covers/music/'; } @@ -122,7 +122,7 @@ class Music if (count($excludedcats) > 0) $exccatlist = " and r.categoryid not in (".implode(",", $excludedcats).")"; - $sql = sprintf("select count(r.id) as num from releases r inner join musicinfo m on m.id = r.musicinfoid and m.title != '' where r.passwordstatus <= (select value from site where setting='showpasswordedrelease') and %s %s %s %s", $browseby, $catsrch, $maxage, $exccatlist); + $sql = sprintf("select count(r.id) as num from releases r inner join musicinfo m on m.id = r.musicinfoid and m.title != '' where r.passwordstatus <= (select value from settings where setting='showpasswordedrelease') and %s %s %s %s", $browseby, $catsrch, $maxage, $exccatlist); $res = $this->pdo->queryOneRow($sql, true); return $res["num"]; } @@ -178,7 +178,7 @@ class Music $order = $this->getMusicOrder($orderby); // query modified to join to musicinfo after limiting releases as performance issue prevented sane sql. - $sql = sprintf(" SELECT r.*, r.id as releaseid, m.*, g.title as genre, groups.name as group_name, concat(cp.title, ' > ', c.title) as category_name, concat(cp.id, ',', c.id) as category_ids, rn.id as nfoid from releases r left outer join groups on groups.id = r.groupid inner join musicinfo m on m.id = r.musicinfoid and m.title != '' left outer join releasenfo rn on rn.releaseid = r.id and rn.nfo is not null left outer join category c on c.id = r.categoryid left outer join category cp on cp.id = c.parentid left outer join genres g on g.id = m.genreID inner join (select r.id from releases r inner join musicinfo m ON m.id = r.musicinfoid and m.title != '' where r.musicinfoid > 0 and r.passwordstatus <= (select value from site where setting='showpasswordedrelease') and %s %s %s %s order by %s %s %s) x on x.id = r.id order by %s %s", $browseby, $catsrch, $maxagesql, $exccatlist, $order[0], $order[1], $limit, $order[0], $order[1]); + $sql = sprintf(" SELECT r.*, r.id as releaseid, m.*, g.title as genre, groups.name as group_name, concat(cp.title, ' > ', c.title) as category_name, concat(cp.id, ',', c.id) as category_ids, rn.id as nfoid from releases r left outer join groups on groups.id = r.groupid inner join musicinfo m on m.id = r.musicinfoid and m.title != '' left outer join releasenfo rn on rn.releaseid = r.id and rn.nfo is not null left outer join category c on c.id = r.categoryid left outer join category cp on cp.id = c.parentid left outer join genres g on g.id = m.genreID inner join (select r.id from releases r inner join musicinfo m ON m.id = r.musicinfoid and m.title != '' where r.musicinfoid > 0 and r.passwordstatus <= (select value from settings where setting='showpasswordedrelease') and %s %s %s %s order by %s %s %s) x on x.id = r.id order by %s %s", $browseby, $catsrch, $maxagesql, $exccatlist, $order[0], $order[1], $limit, $order[0], $order[1]); return $this->pdo->query($sql, true); } @@ -238,7 +238,7 @@ class Music */ public function getBrowseBy() { - $this->pdo = new newznab\db\DB; + $this->pdo = new newznab\db\Settings; $browseby = ' '; $browsebyArr = $this->getBrowseByOptions(); diff --git a/lib/copy_this/newznab/controllers/Musik.php b/lib/copy_this/newznab/controllers/Musik.php index 04933ff6f..822c7d66c 100644 --- a/lib/copy_this/newznab/controllers/Musik.php +++ b/lib/copy_this/newznab/controllers/Musik.php @@ -1,5 +1,5 @@ site = $s->get(); - $this->pdo = ($options['Settings'] instanceof DB ? $options['Settings'] : new DB()); - $this->pubkey = $this->site->amazonpubkey; - $this->privkey = $this->site->amazonprivkey; - $this->asstag = $this->site->amazonassociatetag; - $this->musicqty = ($this->site->maxmusicprocessed != '') ? $this->site->maxmusicprocessed : 150; - $this->sleeptime = ($this->site->amazonsleep != '') ? $this->site->amazonsleep : 1000; + $this->pdo = ($options['Settings'] instanceof Settings ? $options['Settings'] : new Settings()); + $this->pubkey = $this->pdo->getSetting('amazonpubkey'); + $this->privkey = $this->pdo->getSetting('amazonprivkey'); + $this->asstag = $this->pdo->getSetting('amazonassociatetag'); + $this->musicqty = ($this->pdo->getSetting('maxmusicprocessed') != '') ? $this->pdo->getSetting('maxmusicprocessed') : 150; + $this->sleeptime = ($this->pdo->getSetting('amazonsleep') != '') ? $this->pdo->getSetting('amazonsleep') : 1000; $this->imgSavePath = NN_COVERS . 'music' . DS; $this->renamed = ''; - if ($this->site->lookupmusic == 2) { + if ($this->pdo->getSetting('lookupmusic') == 2) { $this->renamed = 'AND isrenamed = 1'; } } diff --git a/lib/copy_this/newznab/controllers/NNTP.php b/lib/copy_this/newznab/controllers/NNTP.php index 2edc46f3a..a2f3cf342 100644 --- a/lib/copy_this/newznab/controllers/NNTP.php +++ b/lib/copy_this/newznab/controllers/NNTP.php @@ -107,7 +107,7 @@ class NNTP extends Net_NNTP_Client $this->_echo = ($options['Echo'] && NN_ECHOCLI); - $this->pdo = ($options['Settings'] instanceof \newznab\db\DB ? $options['Settings'] : new \newznab\db\DB()); + $this->pdo = ($options['Settings'] instanceof \newznab\db\Settings ? $options['Settings'] : new \newznab\db\Settings()); $s = new Sites(); $this->site = $s->get(); @@ -120,7 +120,7 @@ class NNTP extends Net_NNTP_Client } } - $this->_nntpRetries = ($this->site->nntpretries != '') ? (int)$this->site->nntpretries : 0 + 1; + $this->_nntpRetries = ($this->pdo->getSetting('nntpretries') != '') ? (int)$this->pdo->getSetting('nntpretries') : 0 + 1; $this->_initiateYEncSettings(); } @@ -274,7 +274,7 @@ class NNTP extends Net_NNTP_Client // If we are connected and authenticated, try enabling compression if we have it enabled. if ($connected === true && $authenticated === true) { // Check if we should use compression on the connection. - if ($compression === false || $this->site->compressedheaders == 0) { + if ($compression === false || $this->pdo->getSetting('compressedheaders') == 0) { $this->_compressionSupported = false; } if ($this->_debugBool) { @@ -347,7 +347,7 @@ class NNTP extends Net_NNTP_Client */ public function enableCompression() { - if (!$this->site->compressedheaders == 1) { + if (!$this->pdo->getSetting('compressedheaders') == 1) { return; } $this->_enableCompression(); @@ -1220,7 +1220,7 @@ class NNTP extends Net_NNTP_Client protected function _initiateYEncSettings() { // Check if the user wants to use yyDecode or the simple_php_yenc_decode extension. - $this->_yyDecoderPath = ($this->site->yydecoderpath != '') ? (string)$this->site->yydecoderpath : false; + $this->_yyDecoderPath = ($this->pdo->getSetting('yydecoderpath') != '') ? (string)$this->pdo->getSetting('yydecoderpath') : false; if (strpos((string)$this->_yyDecoderPath, 'simple_php_yenc_decode') !== false) { if (extension_loaded('simple_php_yenc_decode')) { $this->_yEncExtension = true; diff --git a/lib/copy_this/newznab/controllers/NZB.php b/lib/copy_this/newznab/controllers/NZB.php index fb81a30cc..a8f1b9596 100644 --- a/lib/copy_this/newznab/controllers/NZB.php +++ b/lib/copy_this/newznab/controllers/NZB.php @@ -1,6 +1,6 @@ pdo = ($pdo instanceof DB ? $pdo : new DB()); + $this->pdo = ($pdo instanceof Settings ? $pdo : new Settings()); $s = new Sites(); $this->site = $s->get(); - $this->tablePerGroup = ($this->site->tablepergroup == 0 ? false : true); - $nzbSplitLevel = $this->site->nzbsplitlevel; + $this->tablePerGroup = ($this->pdo->getSetting('tablepergroup') == 0 ? false : true); + $nzbSplitLevel = $this->pdo->getSetting('nzbsplitlevel'); $this->nzbSplitLevel = (empty($nzbSplitLevel) ? 1 : $nzbSplitLevel); - $this->siteNzbPath = (string)$this->site->nzbpath; + $this->siteNzbPath = (string)$this->pdo->getSetting('nzbpath'); if (substr($this->siteNzbPath, -1) !== DS) { $this->siteNzbPath .= DS; } diff --git a/lib/copy_this/newznab/controllers/NZBContents.php b/lib/copy_this/newznab/controllers/NZBContents.php index 3ca9ef6a6..2a2c14b8a 100644 --- a/lib/copy_this/newznab/controllers/NZBContents.php +++ b/lib/copy_this/newznab/controllers/NZBContents.php @@ -1,6 +1,6 @@ NNTP ; Class NNTP. * 'Nfo' => Nfo ; Class Info. * 'NZB' => NZB ; Class NZB. - * 'Settings' => DB ; Class newznab\db\DB. + * 'Settings' => DB ; Class newznab\db\Settings. * 'PostProcess' => PProcess ; Class PProcess. * ) * @@ -87,7 +87,7 @@ Class NZBContents $options += $defaults; $this->echooutput = ($options['Echo'] && NN_ECHOCLI); - $this->pdo = ($options['Settings'] instanceof DB ? $options['Settings'] : new DB()); + $this->pdo = ($options['Settings'] instanceof Settings ? $options['Settings'] : new Settings()); $this->nntp = ($options['NNTP'] instanceof \NNTP ? $options['NNTP'] : new \NNTP(['Echo' => $this->echooutput, 'Settings' => $this->pdo])); $this->nfo = ($options['Nfo'] instanceof \Info ? $options['Nfo'] : new \Info(['Echo' => $this->echooutput, 'Settings' => $this->pdo])); $this->pp = ( @@ -101,7 +101,7 @@ Class NZBContents $s = new Sites(); $this->site = $s->get(); $this->lookuppar2 = ($this->tmux->lookuppar2 == 1 ? true : false); - $this->alternateNNTP = ($this->site->alternate_nntp == 1 ? true : false); + $this->alternateNNTP = ($this->pdo->getSetting('alternate_nntp') == 1 ? true : false); } /** diff --git a/lib/copy_this/newznab/controllers/NZBExport.php b/lib/copy_this/newznab/controllers/NZBExport.php index 2f0517557..4fe605f1a 100644 --- a/lib/copy_this/newznab/controllers/NZBExport.php +++ b/lib/copy_this/newznab/controllers/NZBExport.php @@ -1,6 +1,6 @@ browser = $options['Browser']; $this->echoCLI = (!$this->browser && NN_ECHOCLI && $options['Echo']); - $this->pdo = ($options['Settings'] instanceof DB ? $options['Setting'] : new DB()); + $this->pdo = ($options['Settings'] instanceof Settings ? $options['Setting'] : new Settings()); $this->releases = ($options['Releases'] instanceof \Releases ? $options['Releases'] : new \Releases(['Settings' => $this->pdo])); $this->nzb = ($options['NZB'] instanceof \NZB ? $options['NZB'] : new \NZB($this->pdo)); } diff --git a/lib/copy_this/newznab/controllers/NZBImport.php b/lib/copy_this/newznab/controllers/NZBImport.php index e139e2db5..c37ab4cde 100644 --- a/lib/copy_this/newznab/controllers/NZBImport.php +++ b/lib/copy_this/newznab/controllers/NZBImport.php @@ -1,6 +1,6 @@ site = $s->get(); $this->echoCLI = (!$this->browser && NN_ECHOCLI && $options['Echo']); - $this->pdo = ($options['Settings'] instanceof DB ? $options['Settings'] : new DB()); + $this->pdo = ($options['Settings'] instanceof Settings ? $options['Settings'] : new Settings()); $this->binaries = ($options['Binaries'] instanceof \Binaries ? $options['Binaries'] : new \Binaries(['Settings' => $this->pdo, 'Echo' => $this->echoCLI])); $this->category = ($options['Categorize'] instanceof \Categorize ? $options['Categorize'] : new \Categorize(['Settings' => $this->pdo])); $this->nzb = ($options['NZB'] instanceof \NZB ? $options['NZB'] : new \NZB($this->pdo)); @@ -116,7 +116,7 @@ class NZBImport $s = new Sites(); $this->site = $s->get(); - $this->crossPostt = ($this->site->crossposttime != '') ? $this->site->crossposttime : 2; + $this->crossPostt = ($this->pdo->getSetting('crossposttime') != '') ? $this->pdo->getSetting('crossposttime') : 2; $this->browser = $options['Browser']; $this->retVal = ''; } @@ -403,7 +403,7 @@ class NZBImport 'postdate' => $this->pdo->escapeString($nzbDetails['postDate']), 'fromname' => $escapedFromName, 'reqid' => NULL, - 'passwordstatus' => ($this->site->checkpasswordedrar > 0 ? -1 : 0), + 'passwordstatus' => ($this->pdo->getSetting('checkpasswordedrar') > 0 ? -1 : 0), 'size' => $this->pdo->escapeString($nzbDetails['totalSize']), 'categoryid' => $this->category->determineCategory($nzbDetails['groupid'], $cleanName), 'isrenamed' => $renamed, diff --git a/lib/copy_this/newznab/controllers/NameFixer.php b/lib/copy_this/newznab/controllers/NameFixer.php index f43ddf826..70740d938 100644 --- a/lib/copy_this/newznab/controllers/NameFixer.php +++ b/lib/copy_this/newznab/controllers/NameFixer.php @@ -1,6 +1,6 @@ echooutput = ($options['Echo'] && NN_ECHOCLI); $this->relid = $this->fixed = $this->checked = 0; - $this->pdo = ($options['Settings'] instanceof DB ? $options['Settings'] : new DB()); + $this->pdo = ($options['Settings'] instanceof Settings ? $options['Settings'] : new Settings()); $this->timeother = ' AND rel.adddate > (NOW() - INTERVAL 0 HOUR) AND rel.categoryid IN (1090, 2020, 3050, 6050, 5050, 7050, 8010, 8020) GROUP BY rel.id ORDER BY postdate DESC'; $this->timeall = ' AND rel.adddate > (NOW() - INTERVAL 6 HOUR) GROUP BY rel.id ORDER BY postdate DESC'; $this->fullother = ' AND rel.categoryid IN (1090, 2020, 3050, 6050, 5050, 7050, 8010, 8020) GROUP BY rel.id'; diff --git a/lib/copy_this/newznab/controllers/Nfo.php b/lib/copy_this/newznab/controllers/Nfo.php index 9cf383b6f..ccb14f6bb 100644 --- a/lib/copy_this/newznab/controllers/Nfo.php +++ b/lib/copy_this/newznab/controllers/Nfo.php @@ -1,6 +1,6 @@ $blob){ $query = sprintf( "REPLACE INTO releasenfo (id, releaseid, binaryID, nfo) ". @@ -489,7 +489,7 @@ class Nfo // nzb files are further parsed for nfo segments that can // be extracted and applied to the release $nzb = new NZB(); - $db = new DB(); + $db = new Settings(); // How many releases to handle at a time $batch=Nfo::NNTP_BATCH_COUNT; @@ -587,7 +587,7 @@ class Nfo */ public function deleteReleaseNfo($relid) { - $db = new DB(); + $db = new Settings(); return $db->queryExec(sprintf("DELETE from releasenfo where releaseid = %d", $relid)); } @@ -596,7 +596,7 @@ class Nfo */ private function setNfoMissing($relid) { - $db = new DB(); + $db = new Settings(); $q = sprintf("UPDATE releases SET releasenfoid = %d ". "WHERE id = %d", Nfo::FLAG_NFO_MISSING, $relid); return $db->queryExec($q); @@ -607,7 +607,7 @@ class Nfo */ public function getNfo($relid, &$nfoout) { - $db = new DB(); + $db = new Settings(); // Has NFO Query $mnfo = "SELECT uncompress(rn.nfo) as nfo FROM releases r ". "INNER JOIN releasenfo rn ON rn.releaseid = r.id AND rn.id = r.releasenfoid ". diff --git a/lib/copy_this/newznab/controllers/Page.php b/lib/copy_this/newznab/controllers/Page.php index eae0dd439..8509e580a 100644 --- a/lib/copy_this/newznab/controllers/Page.php +++ b/lib/copy_this/newznab/controllers/Page.php @@ -23,7 +23,7 @@ class Page extends BasePage $this->smarty->assign('usefulcontentlist',$content->getForMenuByTypeAndRole(Contents::TYPEUSEFUL, $role)); $this->smarty->assign('articlecontentlist',$content->getForMenuByTypeAndRole(Contents::TYPEARTICLE, $role)); if ($this->userdata != null) - $this->smarty->assign('recentforumpostslist',$f->getRecentPosts($this->site->showrecentforumposts)); + $this->smarty->assign('recentforumpostslist',$f->getRecentPosts($this->pdo->getSetting('showrecentforumposts'))); $this->smarty->assign('main_menu',$this->smarty->fetch('mainmenu.tpl')); $this->smarty->assign('useful_menu',$this->smarty->fetch('usefullinksmenu.tpl')); diff --git a/lib/copy_this/newznab/controllers/Parsing.php b/lib/copy_this/newznab/controllers/Parsing.php index 09fd6978a..5fbc9ae54 100644 --- a/lib/copy_this/newznab/controllers/Parsing.php +++ b/lib/copy_this/newznab/controllers/Parsing.php @@ -1,6 +1,6 @@ other releases into real names. @@ -8,7 +8,7 @@ use newznab\db\DB; class Parsing { /** - * @var newznab\db\DB + * @var newznab\db\Settings */ public $pdo; @@ -35,7 +35,7 @@ class Parsing $this->cleanup = ['nuke' => [], 'misc' => []]; $s = new Sites(); $this->site = $s->get(); - $this->pdo = new newznab\db\DB(); + $this->pdo = new newznab\db\Settings(); } /** @@ -661,7 +661,7 @@ class Parsing //Lookup name via reqid (filename) if (preg_match('/\.(avi|mkv|mp4|mov|wmv|iso|img|gcm|ps3|wad|ac3|nds|bin|cue|mdf)/i', $rarFile)) { - $this->site->reqidurl; + $this->pdo->getSetting('reqidurl; $lookupUrl = 'http://allfilled/query.php?t=alt.binaries.srrdb&reqid='.urlencode(basename($rarFile)); echo '-lookup: '.$lookupUrl."\n"; $xml = Utility::getUrl(['url' => $lookupUrl]); @@ -685,7 +685,7 @@ class Parsing } // do par check if user has elected for downloading extra stuff - if ($this->site->unrarpath != '' && $foundName == "") { + if ($this->pdo->getSetting('unrarpath') != '' && $foundName == "") { $nzb = new NZB(); $nzbfile = $nzb->NZBPath($rel['guid']); $nzbInfo = new nzbInfo; @@ -1485,12 +1485,12 @@ class Parsing /** * update a release name * - * @param DB $pdo + * @param Settings $pdo * @param $id * @param $oldname * @param $newname */ - private function updateName(DB $pdo, $id, $oldname, $newname) + private function updateName(Settings $pdo, $id, $oldname, $newname) { if ($this->verbose) echo sprintf("OLD : %s\nNEW : %s\n\n", $oldname, $newname); diff --git a/lib/copy_this/newznab/controllers/PostProcess.php b/lib/copy_this/newznab/controllers/PostProcess.php index 20a2867dc..c4c0975e2 100644 --- a/lib/copy_this/newznab/controllers/PostProcess.php +++ b/lib/copy_this/newznab/controllers/PostProcess.php @@ -2,7 +2,7 @@ require_once NN_LIBS . 'rarinfo/par2info.php'; require_once NN_LIBS . 'rarinfo/archiveinfo.php'; -use newznab\db\DB; +use newznab\db\Settings; use newznab\utility\Utility; /** @@ -12,7 +12,7 @@ class PostProcess { /** - * @var newznab\db\DB + * @var newznab\db\Settings */ public $pdo; @@ -31,7 +31,7 @@ class PostProcess $this->echooutput = (NN_ECHOCLI && $echooutput);; $s = new \Sites(); $this->site = $s->get(); - $this->pdo = new DB(); + $this->pdo = new Settings(); $this->mediafileregex = 'AVI|VOB|MKV|MP4|TS|WMV|MOV|M4V|F4V|MPG|MPEG|M2TS'; $this->audiofileregex = 'MP3|AAC|OGG'; $this->mp3SavePath = WWW_DIR.'covers/audio/'; @@ -64,7 +64,7 @@ class PostProcess // // Delete any passworded releases // - if($this->site->deletepasswordedrelease == 1) + if($this->pdo->getSetting('deletepasswordedrelease') == 1) { echo "PostPrc : Removing unwanted releases\n"; $result = $this->pdo->query("select id from releases where passwordstatus > 0"); @@ -75,11 +75,11 @@ class PostProcess // // Delete any releases which are older than site's release retention days // - if($this->site->releaseretentiondays != 0) + if($this->pdo->getSetting('releaseretentiondays') != 0) { - echo "PostPrc : Deleting releases older than ".$this->site->releaseretentiondays." days\n"; + echo "PostPrc : Deleting releases older than ".$this->pdo->getSetting('releaseretentiondays')." days\n"; - $result = $this->pdo->query(sprintf("select id from releases where postdate < %s - interval %d day", $this->pdo->escapeString($currTime_ori["now"]), $this->site->releaseretentiondays)); + $result = $this->pdo->query(sprintf("select id from releases where postdate < %s - interval %d day", $this->pdo->escapeString($currTime_ori["now"]), $this->pdo->getSetting('releaseretentiondays'))); foreach ($result as $row) $r->delete($row["id"]); } @@ -87,13 +87,13 @@ class PostProcess // // Delete any audiopreviews older than site->audiopreviewprune days // - if($this->site->audiopreviewprune > 0) + if($this->pdo->getSetting('audiopreviewprune') > 0) { - $result = $this->pdo->query(sprintf("select guid from releases where categoryid in (select id from category where parentid = ".Category::CAT_PARENT_MUSIC.") and haspreview = 2 and adddate < %s - interval %d day", $this->pdo->escapeString($currTime_ori["now"]), $this->site->audiopreviewprune)); + $result = $this->pdo->query(sprintf("select guid from releases where categoryid in (select id from category where parentid = ".Category::CAT_PARENT_MUSIC.") and haspreview = 2 and adddate < %s - interval %d day", $this->pdo->escapeString($currTime_ori["now"]), $this->pdo->getSetting('audiopreviewprune'))); if (sizeof($result) > 0) { - echo "PostPrc : Deleting ".count($result)." audio previews older than ".$this->site->audiopreviewprune." days\n"; + echo "PostPrc : Deleting ".count($result)." audio previews older than ".$this->pdo->getSetting('audiopreviewprune')." days\n"; foreach ($result as $row) { $r->updateHasPreview($row["guid"], 0); @@ -105,7 +105,7 @@ class PostProcess // // Delete any releases suspected of being spam/virus // - if($this->site->removespam != 0) + if($this->pdo->getSetting('removespam') != 0) { $spamIDs = array(); @@ -119,9 +119,9 @@ class PostProcess // // all releases containing exe not in permitted categories // - if ($this->site->exepermittedcategories != '') + if ($this->pdo->getSetting('exepermittedcategories') != '') { - $sql = sprintf("select releasefiles.releaseid as id from releasefiles inner join releases on releases.id = releasefiles.releaseid left join releasenfo on releasenfo.releaseid = releases.id where releasefiles.name like '%%.exe' and releases.categoryid not in (%s) group by releasefiles.releaseid", $this->site->exepermittedcategories); + $sql = sprintf("select releasefiles.releaseid as id from releasefiles inner join releases on releases.id = releasefiles.releaseid left join releasenfo on releasenfo.releaseid = releases.id where releasefiles.name like '%%.exe' and releases.categoryid not in (%s) group by releasefiles.releaseid", $this->pdo->getSetting('exepermittedcategories')); $result = $this->pdo->query($sql); $spamIDs = array_merge($result, $spamIDs); } @@ -161,7 +161,7 @@ class PostProcess */ public function processNfos() { - if ($this->site->lookupnfo == 1) + if ($this->pdo->getSetting('lookupnfo') == 1) { $nfo = new Nfo($this->echooutput); $nfo->processNfoFiles(500); @@ -189,7 +189,7 @@ class PostProcess */ public function processMovies() { - if ($this->site->lookupimdb == 1) + if ($this->pdo->getSetting('lookupimdb') == 1) { $movie = new Movie($this->echooutput); $movie->processMovieReleases(); @@ -201,7 +201,7 @@ class PostProcess */ public function processMusic() { - if ($this->site->lookupmusic == 1) + if ($this->pdo->getSetting('lookupmusic') == 1) { $music = new Music($this->echooutput); $music->processMusicReleases(); @@ -213,7 +213,7 @@ class PostProcess */ public function processBooks() { - if ($this->site->lookupbooks == 1) + if ($this->pdo->getSetting('lookupbooks') == 1) { $book = new Book($this->echooutput); $book->processBookReleases(); @@ -225,7 +225,7 @@ class PostProcess */ public function processGames() { - if ($this->site->lookupgames == 1) + if ($this->pdo->getSetting('lookupgames') == 1) { $console = new Console($this->echooutput); $console->processConsoleReleases(); @@ -261,20 +261,20 @@ class PostProcess */ public function processTv() { - if ($this->site->lookupanidb == 1) + if ($this->pdo->getSetting('lookupanidb') == 1) { $anidb = new AniDB($this->echooutput); $anidb->animetitlesUpdate(); $anidb->processAnimeReleases(); } - if ($this->site->lookuptvrage == 1) + if ($this->pdo->getSetting('lookuptvrage') == 1) { $tvrage = new TVRage($this->echooutput); - $tvrage->processTvReleases(($this->site->lookuptvrage==1)); + $tvrage->processTvReleases(($this->pdo->getSetting('lookuptvrage') ==1)); } - if ($this->site->lookupthetvdb == 1) + if ($this->pdo->getSetting('lookupthetvdb') == 1) { $thetvdb = new TheTVDB($this->echooutput); $thetvdb->processReleases(); @@ -287,20 +287,20 @@ class PostProcess public function processOtherMiscCategory() { $p = null; - if($this->site->updatecleanup == 1) + if($this->pdo->getSetting('updatecleanup') == 1) { $p = new Parsing(false, true, false); $p->cleanup(); } - if($this->site->updateparsing == 1) + if($this->pdo->getSetting('updateparsing') == 1) { if ($p == null) $p = new Parsing(false, true, false); $p->process(); } - if($this->site->removespecial == 1) + if($this->pdo->getSetting('removespecial') == 1) { if ($p == null) $p = new Parsing(false, true, false); @@ -315,12 +315,12 @@ class PostProcess { $maxattemptstocheckpassworded = 5; - $processVideoSample = ($this->site->ffmpegpath != '') ? true : false; - $processMediainfo = ($this->site->mediainfopath != '') ? true : false; - $processPasswords = ($this->site->unrarpath != '') ? true : false; - $processAudioSample = ($this->site->saveaudiopreview == 1) ? true : false; + $processVideoSample = ($this->pdo->getSetting('ffmpegpath') != '') ? true : false; + $processMediainfo = ($this->pdo->getSetting('mediainfopath') != '') ? true : false; + $processPasswords = ($this->pdo->getSetting('unrarpath') != '') ? true : false; + $processAudioSample = ($this->pdo->getSetting('saveaudiopreview') == 1) ? true : false; - $tmpPath = $this->site->tmpunrarpath; + $tmpPath = $this->pdo->getSetting('tmpunrarpath'); if (substr($tmpPath, -strlen( '/' ) ) != '/') { $tmpPath = $tmpPath.'/'; @@ -368,7 +368,7 @@ class PostProcess // only load nzbs and check for rar files if we are doing something with them. if ($processVideoSample || $processMediainfo || $processPasswords || $processAudioSample) { - $nzbfile = $nzb->NZBPath($rel['guid'], $this->site->nzbpath); + $nzbfile = $nzb->NZBPath($rel['guid'], $this->pdo->getSetting('nzbpath')); if (!$nzbInfo->loadFromFile($nzbfile)) { continue; @@ -401,7 +401,7 @@ class PostProcess file_put_contents($samplefile, $sampleBinary); - $blnTookSample = $this->getSample($tmpPath, $this->site->ffmpegpath, $rel['guid']); + $blnTookSample = $this->getSample($tmpPath, $this->pdo->getSetting('ffmpegpath'), $rel['guid']); if ($blnTookSample) $this->updateReleaseHasPreview($rel['guid']); @@ -432,13 +432,13 @@ class PostProcess if ($processVideoSample && $blnTookSample === false) { - $blnTookSample = $this->getSample($tmpPath, $this->site->ffmpegpath, $rel['guid']); + $blnTookSample = $this->getSample($tmpPath, $this->pdo->getSetting('ffmpegpath'), $rel['guid']); if ($blnTookSample) $this->updateReleaseHasPreview($rel['guid']); } if ($processMediainfo) - $blnTookMediainfo = $this->getMediainfo($tmpPath, $this->site->mediainfopath, $rel['id']); + $blnTookMediainfo = $this->getMediainfo($tmpPath, $this->pdo->getSetting('mediainfopath'), $rel['id']); unlink($mediafile); } @@ -470,23 +470,23 @@ class PostProcess $this->updateReleaseHasPreview($rel['guid'], 2); if ($processMediainfo) - $blnTookMediainfo = $this->getMediainfo($tmpPath, $this->site->mediainfopath, $rel['id']); + $blnTookMediainfo = $this->getMediainfo($tmpPath, $this->pdo->getSetting('mediainfopath'), $rel['id']); - if ($this->site->lamepath != "") - $this->lameAudioSample($this->site->lamepath, $rel['guid']); + if ($this->pdo->getSetting('lamepath') != "") + $this->lameAudioSample($this->pdo->getSetting('lamepath'), $rel['guid']); unlink($audiofile); } unset($audioBinary); } - if (!empty($nzbInfo->rarfiles) && ($this->site->checkpasswordedrar > 0 || (($processVideoSample || $processAudioSample) && $blnTookSample === false) || $processMediainfo)) + if (!empty($nzbInfo->rarfiles) && ($this->pdo->getSetting('checkpasswordedrar') > 0 || (($processVideoSample || $processAudioSample) && $blnTookSample === false) || $processMediainfo)) { $mysqlkeepalive = 0; foreach($nzbInfo->rarfiles as $rarFile) { //dont process any more rars if a passworded rar has been detected and the site is set to automatically delete them - if ($this->site->deletepasswordedrelease == 1 && max($passStatus) == Releases::PASSWD_RAR) + if ($this->pdo->getSetting('deletepasswordedrelease') == 1 && max($passStatus) == Releases::PASSWD_RAR) { echo "-Skipping processing of rar {$rarFile['subject']} as this release has already been marked as passworded.\n"; continue; @@ -510,24 +510,24 @@ class PostProcess { $relFiles = $this->processReleaseFiles($fetchedBinary, $rel['id']); - if ($this->site->checkpasswordedrar > 0 && $processPasswords) + if ($this->pdo->getSetting('checkpasswordedrar') > 0 && $processPasswords) { - $passStatus[] = $this->processReleasePasswords($fetchedBinary, $tmpPath, $this->site->unrarpath, $this->site->checkpasswordedrar); + $passStatus[] = $this->processReleasePasswords($fetchedBinary, $tmpPath, $this->pdo->getSetting('unrarpath'), $this->pdo->getSetting('checkpasswordedrar')); } // we need to unrar the fetched binary if checkpasswordedrar wasnt 2 - if ($this->site->checkpasswordedrar < 2 && $processPasswords) + if ($this->pdo->getSetting('checkpasswordedrar') < 2 && $processPasswords) { $rarfile = $tmpPath.'rarfile.rar'; file_put_contents($rarfile, $fetchedBinary); - $execstring = '"'.$this->site->unrarpath.'" e -ai -ep -c- -id -r -kb -p- -y -inul "'.$rarfile.'" "'.$tmpPath.'"'; + $execstring = '"'.$this->pdo->getSetting('unrarpath').'" e -ai -ep -c- -id -r -kb -p- -y -inul "'.$rarfile.'" "'.$tmpPath.'"'; $output = Utility::runCmd($execstring, false, true); unlink($rarfile); } if ($processVideoSample && $blnTookSample === false) { - $blnTookSample = $this->getSample($tmpPath, $this->site->ffmpegpath, $rel['guid']); + $blnTookSample = $this->getSample($tmpPath, $this->pdo->getSetting('ffmpegpath'), $rel['guid']); if ($blnTookSample) $this->updateReleaseHasPreview($rel['guid']); } @@ -545,14 +545,14 @@ class PostProcess if ($processMediainfo && $blnTookMediainfo === false) { - $blnTookMediainfo = $this->getMediainfo($tmpPath, $this->site->mediainfopath, $rel['id']); + $blnTookMediainfo = $this->getMediainfo($tmpPath, $this->pdo->getSetting('mediainfopath'), $rel['id']); } // // Has to be done after mediainfo // - if ($blnTookAudioSample && $this->site->lamepath != "") - $this->lameAudioSample($this->site->lamepath, $rel['guid']); + if ($blnTookAudioSample && $this->pdo->getSetting('lamepath') != "") + $this->lameAudioSample($this->pdo->getSetting('lamepath'), $rel['guid']); if ($mysqlkeepalive % 25 == 0) $this->pdo->query("select 1"); @@ -886,7 +886,7 @@ class PostProcess $minacceptableencodefilesize = 10000; $samplefile = $this->mp3SavePath.$releaseguid.'.mp3'; $samplefileogg = $this->mp3SavePath.$releaseguid.'.ogg'; - $ffmpeginfo = $this->site->ffmpegpath; + $ffmpeginfo = $this->pdo->getSetting('ffmpegpath'); if (file_exists($samplefile)) { @@ -987,9 +987,9 @@ class PostProcess */ public function processMusicFromMediaInfo() { - $processMediainfo = ($this->site->mediainfopath != '') ? true : false; - $processAudioSample = ($this->site->saveaudiopreview == 1) ? true : false; - $processMusic = ($this->site->lookupmusic == 1) ? true : false; + $processMediainfo = ($this->pdo->getSetting('mediainfopath') != '') ? true : false; + $processAudioSample = ($this->pdo->getSetting('saveaudiopreview') == 1) ? true : false; + $processMusic = ($this->pdo->getSetting('lookupmusic') == 1) ? true : false; if ($processMusic && $processMediainfo && $processAudioSample) { diff --git a/lib/copy_this/newznab/controllers/PreDB.php b/lib/copy_this/newznab/controllers/PreDB.php index 99b461fe7..19d146a00 100644 --- a/lib/copy_this/newznab/controllers/PreDB.php +++ b/lib/copy_this/newznab/controllers/PreDB.php @@ -1,6 +1,6 @@ echooutput = (NN_ECHOCLI && $echooutput); - $this->pdo = new DB(); + $this->pdo = new Settings(); } /** @@ -138,11 +138,11 @@ class PreDB /** * Add/Update predb row. * - * @param newznab\db\DB $pdo + * @param newznab\db\Settings $pdo * @param $preArray * @return bool */ - public function updatePreDB(DB $pdo, $preArray) + public function updatePreDB(Settings $pdo, $preArray) { if(!preg_match('/^(UN)?((MOD)?NUKED?|DELPRE)$/', $preArray['category'])) { diff --git a/lib/copy_this/newznab/controllers/PreHash.php b/lib/copy_this/newznab/controllers/PreHash.php index 8eeb00ae2..3f3992221 100644 --- a/lib/copy_this/newznab/controllers/PreHash.php +++ b/lib/copy_this/newznab/controllers/PreHash.php @@ -1,7 +1,7 @@ echooutput = ($options['Echo'] && NN_ECHOCLI); - $this->pdo = ($options['Settings'] instanceof DB ? $options['Settings'] : new DB()); + $this->pdo = ($options['Settings'] instanceof Settings ? $options['Settings'] : new Settings()); } /** diff --git a/lib/copy_this/newznab/controllers/Regexes.php b/lib/copy_this/newznab/controllers/Regexes.php index a0af440c2..2a7fe614a 100644 --- a/lib/copy_this/newznab/controllers/Regexes.php +++ b/lib/copy_this/newznab/controllers/Regexes.php @@ -1,11 +1,11 @@ pdo = ($options['Settings'] instanceof DB ? $options['Settings'] : new DB()); + $this->pdo = ($options['Settings'] instanceof Settings ? $options['Settings'] : new Settings()); $this->tableName = $options['Table_Name']; } diff --git a/lib/copy_this/newznab/controllers/ReleaseCleaning.php b/lib/copy_this/newznab/controllers/ReleaseCleaning.php index 9f04ae05c..922b49773 100644 --- a/lib/copy_this/newznab/controllers/ReleaseCleaning.php +++ b/lib/copy_this/newznab/controllers/ReleaseCleaning.php @@ -1,6 +1,6 @@ e1 = \CollectionsCleaning::REGEX_FILE_EXTENSIONS . \CollectionsCleaning::REGEX_END; $this->e2 = \CollectionsCleaning::REGEX_FILE_EXTENSIONS . \CollectionsCleaning::REGEX_SUBJECT_SIZE . \CollectionsCleaning::REGEX_END; - $this->pdo = ($settings instanceof newznab\db\DB ? $settings : new newznab\db\DB()); + $this->pdo = ($settings instanceof newznab\db\Settings ? $settings : new newznab\db\Settings()); $this->_regexes = new Regexes(['Settings' => $this->pdo, 'Table_Name' => 'release_naming_regexes']); } diff --git a/lib/copy_this/newznab/controllers/ReleaseComments.php b/lib/copy_this/newznab/controllers/ReleaseComments.php index 3dde85184..75601837f 100644 --- a/lib/copy_this/newznab/controllers/ReleaseComments.php +++ b/lib/copy_this/newznab/controllers/ReleaseComments.php @@ -1,6 +1,6 @@ queryOneRow(sprintf("SELECT * FROM releasecomment WHERE id = %d", $id)); } @@ -22,7 +22,7 @@ class ReleaseComments */ public function getCommentsByGid($gid) { - $db = new DB(); + $db = new Settings(); return $db->query(sprintf("SELECT rc.id, text, createddate, sourceid, CASE WHEN sourceid = 0 THEN (SELECT username FROM users WHERE id = userid) ELSE username END AS username, CASE WHEN sourceid = 0 THEN (SELECT role FROM users WHERE id = userid) ELSE '-1' END AS role, CASE WHEN sourceid =0 THEN (SELECT r.name AS rolename FROM users AS u LEFT JOIN userroles AS r ON r.id = u.role WHERE u.id = userid) ELSE (SELECT description AS rolename FROM spotnabsources WHERE id = sourceid) END AS rolename FROM releasecomment rc WHERE isvisible = 1 AND gid = %s AND (userid IN (SELECT id FROM users) OR rc.username IS NOT NULL) ORDER BY createddate DESC LIMIT 100", $db->escapeString($gid))); } @@ -31,7 +31,7 @@ class ReleaseComments */ public function getCommentsByGuid($guid) { - $db = new DB(); + $db = new Settings(); return $db->query(sprintf("SELECT rc.id, text, createddate, sourceid, CASE WHEN sourceid = 0 THEN (SELECT username FROM users WHERE id = userid) ELSE username END AS username FROM releasecomment rc LEFT JOIN releases r ON r.gid = rc.gid WHERE isvisible = 1 AND guid = %s AND (userid IN (SELECT id FROM users) OR rc.username IS NOT NULL) ORDER BY createddate DESC LIMIT 100", $db->escapeString($guid))); } @@ -40,7 +40,7 @@ class ReleaseComments */ public function getCommentCount($refdate=Null, $localOnly=Null) { - $db = new DB(); + $db = new Settings(); if($refdate !== Null){ if(is_string($refdate)){ // ensure we're in the right format @@ -80,7 +80,7 @@ class ReleaseComments */ public function deleteComment($id) { - $db = new DB(); + $db = new Settings(); $res = $this->getCommentById($id); if ($res) { @@ -94,7 +94,7 @@ class ReleaseComments */ public function deleteCommentsForRelease($id) { - $db = new DB(); + $db = new Settings(); $res = $this->getCommentById($id); if ($res) { @@ -108,7 +108,7 @@ class ReleaseComments */ public function deleteCommentsForUser($id) { - $db = new DB(); + $db = new Settings(); $numcomments = $this->getCommentCountForUser($id); if ($numcomments > 0) @@ -130,7 +130,7 @@ class ReleaseComments if(strlen(trim($text)) == 0) return false; - $db = new DB(); + $db = new Settings(); $site = new Sites(); $s = $site->get(); @@ -147,7 +147,7 @@ class ReleaseComments */ public function getCommentsRange($start, $num) { - $db = new DB(); + $db = new Settings(); if ($start === false) $limit = ""; @@ -163,7 +163,7 @@ class ReleaseComments */ public function updateReleaseCommentCount($gid) { - $db = new DB(); + $db = new Settings(); $db->queryExec(sprintf("update releases SET comments = (SELECT count(id) FROM releasecomment WHERE releasecomment.gid = releases.gid AND isvisible = 1) WHERE releases.gid = %s", $db->escapeString($gid) )); @@ -174,7 +174,7 @@ class ReleaseComments */ public function getCommentCountForUser($uid) { - $db = new DB(); + $db = new Settings(); $res = $db->queryOneRow(sprintf("SELECT count(id) AS num FROM releasecomment WHERE userid = %d AND isvisible = 1", $uid)); return $res["num"]; } @@ -184,7 +184,7 @@ class ReleaseComments */ public function getCommentsForUserRange($uid, $start, $num) { - $db = new DB(); + $db = new Settings(); if ($start === false) $limit = ""; diff --git a/lib/copy_this/newznab/controllers/ReleaseExtra.php b/lib/copy_this/newznab/controllers/ReleaseExtra.php index f43253444..f218c99d8 100644 --- a/lib/copy_this/newznab/controllers/ReleaseExtra.php +++ b/lib/copy_this/newznab/controllers/ReleaseExtra.php @@ -1,6 +1,6 @@ query(sprintf("select * from releaseaudio where releaseid = %d order by audioID ASC", $id)); } public function getBriefByGuid($guid) { - $db = new DB(); + $db = new Settings(); return $db->queryOneRow(sprintf("select containerformat,videocodec,videoduration,videoaspect, concat(releasevideo.videowidth,'x',releasevideo.videoheight,' @',format(videoframerate,0),'fps') as size, group_concat(distinct releaseaudio.audiolanguage SEPARATOR ', ') as audio, group_concat(distinct releaseaudio.audiobitrate SEPARATOR ', ') as audiobitrate, group_concat(distinct releaseaudio.audioformat SEPARATOR ', ') as audioformat, group_concat(distinct releaseaudio.audiomode SEPARATOR ', ') as audiomode, group_concat(distinct releaseaudio.audiobitratemode SEPARATOR ', ') as audiobitratemode, group_concat(distinct releasesubs.subslanguage SEPARATOR ', ') as subs from releaseaudio left outer join releasesubs on releaseaudio.releaseid = releasesubs.releaseid left outer join releasevideo on releasevideo.releaseid = releaseaudio.releaseid inner join releases r on r.id = releaseaudio.releaseid where r.guid = %s group by r.id", $db->escapeString($guid))); } public function delete($id) { - $db = new DB(); + $db = new Settings(); $db->queryExec(sprintf("DELETE from releaseaudio where releaseid = %d", $id)); $db->queryExec(sprintf("DELETE from releasesubs where releaseid = %d", $id)); $db->queryExec(sprintf("DELETE from releaseextrafull where releaseid = %d", $id)); @@ -165,7 +165,7 @@ class ReleaseExtra */ public function addVideo($releaseID, $containerformat, $overallbitrate, $videoduration, $videoformat, $videocodec, $videowidth, $videoheight, $videoaspect, $videoframerate, $videolibrary) { - $db = new DB(); + $db = new Settings(); $row = $this->getVideo($releaseID); if ($row) @@ -191,7 +191,7 @@ class ReleaseExtra public function getVideo($id) { - $db = new DB(); + $db = new Settings(); return $db->queryOneRow(sprintf("select * from releasevideo where releaseid = %d", $id)); } @@ -239,7 +239,7 @@ class ReleaseExtra */ public function addAudio($releaseID, $audioID, $audioformat, $audiomode, $audiobitratemode, $audiobitrate, $audiochannels, $audiosamplerate, $audiolibrary, $audiolanguage, $audiotitle) { - $db = new DB(); + $db = new Settings(); $row = $this->getAudioAndChannel($releaseID, $audioID); if ($row) @@ -259,14 +259,14 @@ class ReleaseExtra public function getAudioAndChannel($rid, $aid) { - $db = new DB(); + $db = new Settings(); return $db->queryOneRow(sprintf("select * from releaseaudio where releaseid = %d and audioID = %d", $rid, $aid)); } public function addSubs($releaseID, $subsID, $subslanguage) { - $db = new DB(); + $db = new Settings(); $row = $this->getSubs($releaseID); if ($row) return -1; @@ -278,21 +278,21 @@ class ReleaseExtra public function getSubs($id) { - $db = new DB(); + $db = new Settings(); return $db->queryOneRow(sprintf("SELECT group_concat(subslanguage SEPARATOR ', ') as subs FROM `releasesubs` WHERE `releaseid` = %d ORDER BY `subsID` ASC", $id)); } public function deleteFull($id) { - $db = new DB(); + $db = new Settings(); return $db->queryExec(sprintf("DELETE from releaseextrafull where releaseid = %d", $id)); } public function addFull($id, $xml) { - $db = new DB(); + $db = new Settings(); $row = $this->getFull($id); if ($row) return -1; @@ -302,7 +302,7 @@ class ReleaseExtra public function getFull($id) { - $db = new DB(); + $db = new Settings(); return $db->queryOneRow(sprintf("select * from releaseextrafull where releaseid = %d", $id)); } diff --git a/lib/copy_this/newznab/controllers/ReleaseFiles.php b/lib/copy_this/newznab/controllers/ReleaseFiles.php index 0bd9b9321..1e750edba 100644 --- a/lib/copy_this/newznab/controllers/ReleaseFiles.php +++ b/lib/copy_this/newznab/controllers/ReleaseFiles.php @@ -1,6 +1,6 @@ query(sprintf("select * from releasefiles where releaseid = %d order by releasefiles.name ", $id)); } @@ -21,7 +21,7 @@ class ReleaseFiles */ public function getByGuid($guid) { - $db = new DB(); + $db = new Settings(); return $db->query(sprintf("select releasefiles.* from releasefiles inner join releases r on r.id = releasefiles.releaseid where r.guid = %s order by releasefiles.name ", $db->escapeString($guid))); } @@ -30,7 +30,7 @@ class ReleaseFiles */ public function delete($id) { - $db = new DB(); + $db = new Settings(); return $db->queryExec(sprintf("DELETE from releasefiles where releaseid = %d", $id)); } @@ -39,7 +39,7 @@ class ReleaseFiles */ public function add($id, $name, $size, $createddate, $passworded) { - $db = new DB(); + $db = new Settings(); $sql = sprintf("INSERT INTO releasefiles (releaseid, name, size, createddate, passworded) VALUES (%d, %s, %s, from_unixtime(%d), %d)", $id, $db->escapeString($name), $db->escapeString($size), $createddate, $passworded ); return $db->queryInsert($sql); } diff --git a/lib/copy_this/newznab/controllers/ReleaseImage.php b/lib/copy_this/newznab/controllers/ReleaseImage.php index 4ae6e0e5d..23e7c3353 100644 --- a/lib/copy_this/newznab/controllers/ReleaseImage.php +++ b/lib/copy_this/newznab/controllers/ReleaseImage.php @@ -1,6 +1,6 @@ audSavePath = NN_COVERS . 'audiosample' . DS; // releases guid diff --git a/lib/copy_this/newznab/controllers/ReleaseRegex.php b/lib/copy_this/newznab/controllers/ReleaseRegex.php index 88b27b360..4cee3e6b4 100644 --- a/lib/copy_this/newznab/controllers/ReleaseRegex.php +++ b/lib/copy_this/newznab/controllers/ReleaseRegex.php @@ -1,6 +1,6 @@ regexes = []; - $this->pdo = new DB(); + $this->pdo = new Settings(); $s = new Sites(); $this->site = $s->get(); - $this->tablePerGroup = $this->site->tablepergroup; + $this->tablePerGroup = $this->pdo->getSetting('tablepergroup'); } /** diff --git a/lib/copy_this/newznab/controllers/ReleaseRemover.php b/lib/copy_this/newznab/controllers/ReleaseRemover.php index 53d311222..9c7de6873 100644 --- a/lib/copy_this/newznab/controllers/ReleaseRemover.php +++ b/lib/copy_this/newznab/controllers/ReleaseRemover.php @@ -1,6 +1,6 @@ pdo = ($options['Settings'] instanceof DB ? $options['Settings'] : new DB()); + $this->pdo = ($options['Settings'] instanceof Settings ? $options['Settings'] : new Settings()); $this->consoleTools = ($options['ConsoleTools'] instanceof \ConsoleTools ? $options['ConsoleTools'] : new \ConsoleTools(['ColorCLI' => $this->pdo->log])); $this->releases = ($options['Releases'] instanceof \Releases ? $options['Releases'] : new \Releases(['Settings' => $this->pdo])); $this->nzb = ($options['NZB'] instanceof \NZB ? $options['NZB'] : new \NZB($this->pdo)); diff --git a/lib/copy_this/newznab/controllers/ReleaseSearch.php b/lib/copy_this/newznab/controllers/ReleaseSearch.php index 681819e16..1bab6b9a6 100644 --- a/lib/copy_this/newznab/controllers/ReleaseSearch.php +++ b/lib/copy_this/newznab/controllers/ReleaseSearch.php @@ -1,6 +1,6 @@ pdo = ($settings instanceof newznab\db\DB ? $settings : new newznab\db\DB()); + $this->pdo = ($settings instanceof newznab\db\Settings ? $settings : new newznab\db\Settings()); } /** diff --git a/lib/copy_this/newznab/controllers/Releases.php b/lib/copy_this/newznab/controllers/Releases.php index 13e5a68f9..9cfc1418b 100644 --- a/lib/copy_this/newznab/controllers/Releases.php +++ b/lib/copy_this/newznab/controllers/Releases.php @@ -1,6 +1,6 @@ site = $s->get(); - $this->pdo = ($options['Settings'] instanceof DB ? $options['Settings'] : new DB()); + $this->pdo = ($options['Settings'] instanceof Settings ? $options['Settings'] : new Settings()); $this->groups = ($options['Groups'] instanceof \Groups ? $options['Groups'] : new \Groups(['Settings' => $this->pdo])); - $this->updategrabs = ($this->site->grabstatus == '0' ? false : true); - $this->passwordStatus = ($this->site->checkpasswordedrar == 1 ? -1 : 0); + $this->updategrabs = ($this->pdo->getSetting('grabstatus') == '0' ? false : true); + $this->passwordStatus = ($this->pdo->getSetting('checkpasswordedrar') == 1 ? -1 : 0); $this->sphinxSearch = new \SphinxSearch(); $this->releaseSearch = new \ReleaseSearch($this->pdo, $this->sphinxSearch); } diff --git a/lib/copy_this/newznab/controllers/RequestID.php b/lib/copy_this/newznab/controllers/RequestID.php index 7e3e5602c..a28b91d3e 100644 --- a/lib/copy_this/newznab/controllers/RequestID.php +++ b/lib/copy_this/newznab/controllers/RequestID.php @@ -1,6 +1,6 @@ echoOutput = ($options['Echo'] && NN_ECHOCLI); - $this->pdo = ($options['Settings'] instanceof DB ? $options['Settings'] : new DB()); + $this->pdo = ($options['Settings'] instanceof Settings ? $options['Settings'] : new Settings()); $this->category = ($options['Categorize'] instanceof \Categorize ? $options['Categorize'] : new \Categorize(['Settings' => $this->pdo])); $this->groups = ($options['Groups'] instanceof \Groups ? $options['Groups'] : new \Groups(['Settings' => $this->pdo])); $this->consoleTools = ($options['ConsoleTools'] instanceof \ConsoleTools ? $options['ConsoleTools'] : new \ConsoleTools(['ColorCLI' => $this->pdo->log])); @@ -156,7 +156,7 @@ abstract class RequestID protected $category; /** - * @var newznab\db\DB + * @var newznab\db\Settings */ protected $pdo; diff --git a/lib/copy_this/newznab/controllers/RequestIDWeb.php b/lib/copy_this/newznab/controllers/RequestIDWeb.php index 78487f5ee..9d03f9a97 100644 --- a/lib/copy_this/newznab/controllers/RequestIDWeb.php +++ b/lib/copy_this/newznab/controllers/RequestIDWeb.php @@ -33,7 +33,7 @@ class RequestIDWeb extends RequestID parent::__construct($options); $s = new Sites(); $this->site = $s->get(); - $this->_request_hours = ($this->site->request_hours != '') ? (int)$this->site->request_hours : 1; + $this->_request_hours = ($this->pdo->getSetting('request_hours') != '') ? (int)$this->pdo->getSetting('request_hours') : 1; } /** @@ -152,7 +152,7 @@ class RequestIDWeb extends RequestID // Do a web lookup. $returnXml = Utility::getUrl([ - 'url' => $this->site->request_url, + 'url' => $this->pdo->getSetting('request_url'), 'method' => 'post', 'postdata' => 'data=' . serialize($requestArray), 'verifycert' => false, diff --git a/lib/copy_this/newznab/controllers/Sharing.php b/lib/copy_this/newznab/controllers/Sharing.php index a63dc460a..da71a788f 100644 --- a/lib/copy_this/newznab/controllers/Sharing.php +++ b/lib/copy_this/newznab/controllers/Sharing.php @@ -1,6 +1,6 @@ pdo = ($options['Settings'] instanceof DB ? $options['Settings'] : new DB()); + $this->pdo = ($options['Settings'] instanceof Settings ? $options['Settings'] : new Settings()); // Get all sharing info from DB. $check = $this->pdo->queryOneRow('SELECT * FROM sharing'); diff --git a/lib/copy_this/newznab/controllers/Sites.php b/lib/copy_this/newznab/controllers/Sites.php index 4e60516c4..f6940858b 100644 --- a/lib/copy_this/newznab/controllers/Sites.php +++ b/lib/copy_this/newznab/controllers/Sites.php @@ -1,6 +1,6 @@ row2Object($form); if (substr($site->nzbpath, strlen($site->nzbpath) - 1) != '/') @@ -72,14 +72,14 @@ class Sites public function get($refresh = false) { - $sql = "select * from site"; + $sql = "select * from settings"; if ($refresh) { $cache = new Cache(); $cache->delete($sql); } - $db = new DB(); + $db = new Settings(); $rows = $db->query($sql, true, NN_CACHE_EXPIRY_MEDIUM); if ($rows === false) @@ -131,7 +131,7 @@ class Sites public function updateItem($setting, $value) { - $db = new DB(); + $db = new Settings(); $sql = sprintf("update site set value = %s where setting = %s", $db->escapeString($value), $db->escapeString($setting)); return $db->exec($sql); diff --git a/lib/copy_this/newznab/controllers/Sphinx.php b/lib/copy_this/newznab/controllers/Sphinx.php index 91b781838..4b35ad554 100644 --- a/lib/copy_this/newznab/controllers/Sphinx.php +++ b/lib/copy_this/newznab/controllers/Sphinx.php @@ -10,6 +10,7 @@ if (!defined("FS_ROOT")) { define('FS_ROOT', realpath(dirname(__FILE__))); } use newznab\libraries\Cache; +use newznab\db\Settings; // Every day define("INDEX_MERGE_FREQ", 1440); @@ -30,9 +31,7 @@ class Sphinx */ function __construct() { - $s = new Sites; - - $this->site = $s->get(); + $this->pdo = new Settings(); $this->nzb = new NZB; $this->indexes = array("releases", "releasefiles", "releasenfo", "nzbs", "predb"); @@ -72,7 +71,7 @@ class Sphinx */ public function getNextMergeDate() { - return strtotime("tomorrow ".$this->site->sphinxmergefreq); + return strtotime("tomorrow ".$this->pdo->getSetting('sphinxmergefreq')); } /** @@ -81,8 +80,8 @@ class Sphinx */ public function getNextRebuildDate() { - $rebuildStr = $this->site->sphinxrebuildfreq_day." " - . $this->site->sphinxrebuildfreq; + $rebuildStr = $this->pdo->getSetting('sphinxrebuildfreq_day')." " + . $this->pdo->getSetting('sphinxrebuildfreq'); $rebuildDate = strtotime($rebuildStr); if ($rebuildDate < time(true)) { // Date is in the past, pick the next one @@ -107,7 +106,7 @@ class Sphinx return false; } - $db = new newznab\db\DB(); + $db = new newznab\db\Settings(); if ($lastRebuildDate == 0) { $lastRebuildDate = "NOW()"; @@ -145,7 +144,7 @@ class Sphinx return false; } - $db = new newznab\db\DB(); + $db = new newznab\db\Settings(); if ($lastMergedDate == 0) { $lastMergedDate = "NOW()"; @@ -253,7 +252,7 @@ class Sphinx $index .= "_delta"; } - $handle = fopen($this->site->sphinxconfpath, 'r'); + $handle = fopen($this->pdo->getSetting('sphinxconfpath'), 'r'); if ($handle) { $indexPath = ""; while ($line = fgets($handle)) { @@ -305,9 +304,9 @@ class Sphinx */ public function update() { - $db = new newznab\db\DB(); + $db = new newznab\db\Settings(); - if (!$this->site->sphinxenabled) { + if (!$this->pdo->getSetting('sphinxenabled')) { // Sphinx is disabled, so we don't do anything. return; } @@ -325,10 +324,10 @@ class Sphinx $indexDetails = $this->indexDetails($index); $isMergeDueDate = (strtotime($row['nextmergedate']) <= time(true)); $isMergeDueSize = (intval($indexDetails["total-documents"]) >= - intval($this->site->sphinxmergefreq_count)); + intval($this->pdo->getSetting('sphinxmergefreq_count'))); if (strtotime($row['nextrebuilddate']) <= time(true) && - $this->site->sphinxrebuildfreq_day != "") + $this->pdo->getSetting('sphinxrebuildfreq_day') != "") { // Rebuild required printf("Index '%s' is going to be rebuilt.\n", $index); @@ -376,8 +375,8 @@ class Sphinx */ public function getSphinxBinPath($bin) { - $path = rtrim($this->site->sphinxbinpath, DIRECTORY_SEPARATOR); - $conf = $this->site->sphinxconfpath; + $path = rtrim($this->pdo->getSetting('sphinxbinpath'), DIRECTORY_SEPARATOR); + $conf = $this->pdo->getSetting('sphinxconfpath'); if ($path) { // $path is a path to a directory. @@ -399,7 +398,7 @@ class Sphinx public function isIndexEnabled($index) { // Is Sphinx enabled? - if (!$this->site->sphinxenabled) { + if (!$this->pdo->getSetting('sphinxenabled')) { return false; } @@ -410,13 +409,13 @@ class Sphinx case "releases": return true; // Always enabled, as long as Sphinx is case "releasenfo": - return (bool)$this->site->sphinxindexnfos; + return (bool)$this->pdo->getSetting('sphinxindexnfos'); case "releasefiles": - return (bool)$this->site->sphinxindexreleasefiles; + return (bool)$this->pdo->getSetting('sphinxindexreleasefiles'); case "nzbs": - return (bool)$this->site->sphinxindexnzbs; + return (bool)$this->pdo->getSetting('sphinxindexnzbs'); case "predb": - return (bool)$this->site->sphinxindexpredb; + return (bool)$this->pdo->getSetting('sphinxindexpredb'); default: return false; } @@ -533,7 +532,7 @@ class Sphinx // Get connection to Sphinx's MySQL interface. // Connect to Sphinx - $hostport = explode (":", $this->site->sphinxserverhost); + $hostport = explode (":", $this->pdo->getSetting('sphinxserverhost')); $sdb = mysqli_connect($hostport[0], "root", "", "", $hostport[1]); if (!$sdb) { // Couldn't connect to Sphinx. @@ -541,7 +540,7 @@ class Sphinx } // Get connection to Newznab's MySQL database - $ndb = new newznab\db\DB; + $ndb = new newznab\db\Settings; // Determine which release to start with if ($startingID < 0) { @@ -570,7 +569,7 @@ class Sphinx while ($row = $ndb->getAssocArray($result)) { $fileNames = ""; $fileCount = 0; - $nzbpath = $this->nzb->NZBPath($row['guid'], $this->site->nzbpath); + $nzbpath = $this->nzb->NZBPath($row['guid'], $this->pdo->getSetting('nzbpath')); if (file_exists($nzbpath)) { $nzbfile = file_get_contents('compress.zlib://'.$nzbpath); $files = $this->nzb->nzbFileList($nzbfile); @@ -630,7 +629,7 @@ class Sphinx } // Connect to Sphinx - $hostport = explode (":", $this->site->sphinxserverhost); + $hostport = explode (":", $this->pdo->getSetting('sphinxserverhost')); $sdb = mysqli_connect($hostport[0], "root", "", "", $hostport[1]); if (!$sdb) { // Couldn't connect to Sphinx. @@ -675,7 +674,7 @@ class Sphinx } if ($lookupQuery && count($results) > 0) { - $ndb = new newznab\db\DB; + $ndb = new newznab\db\Settings; $sql = sprintf($lookupQuery, implode(",", $results)); $result = $ndb->queryDirect($sql); if ($result) @@ -721,7 +720,7 @@ class Sphinx $indexes=array(), $lookup=true, $where=array(), &$lookupQuery="") { - $ndb = new newznab\db\DB; + $ndb = new newznab\db\Settings; $offset = intval($offset); $limit = intval($limit); @@ -767,7 +766,7 @@ class Sphinx // No field specifiers were found, so use the site-defaults. This // turns the query for "ubuntu" into something like: // "@(name,searchname) ubuntu" - $fields = str_replace(" ", "", $this->site->sphinxsearchfields); + $fields = str_replace(" ", "", $this->pdo->getSetting('sphinxsearchfields')); // Remove single "-" so that Sphinx doesn't use it as an // exclusion modifier @@ -970,7 +969,7 @@ class Sphinx $limit=100, $name="", $cat=array(-1), $maxage=-1, $indexes=array(), $lookup=true) { - $db = new newznab\db\DB(); + $db = new newznab\db\Settings(); $order = array("postdate", "desc"); $search = array($name); if ($series != "") { @@ -1036,7 +1035,7 @@ class Sphinx $cat=array(-1), $genre="", $maxage=-1, $indexes=array(), $lookup=true) { - $db = new newznab\db\DB(); + $db = new newznab\db\Settings(); $search = array(); $order = array("postdate", "desc"); $where = array(); @@ -1103,7 +1102,7 @@ class Sphinx $cat=array(-1), $maxage=-1, $indexes=array(), $lookup=true) { - $db = new newznab\db\DB(); + $db = new newznab\db\Settings(); $search = array(); $where = array(); $order = array("postdate", "desc"); @@ -1179,7 +1178,7 @@ class Sphinx public function searchBook($author, $title, $offset=0, $limit=100, $maxage=-1, $indexes=array(), $lookup=true) { - $db = new newznab\db\DB(); + $db = new newznab\db\Settings(); $order = array("postdate", "desc"); $search = array(); if ($author != "") { @@ -1242,7 +1241,7 @@ class Sphinx $name='', $maxage=-1, $indexes=array(), $lookup=true) { - $db = new newznab\db\DB(); + $db = new newznab\db\Settings(); $where = array(); $search = array(); $order = array("postdate", "desc"); @@ -1291,7 +1290,7 @@ class Sphinx */ public function getPreRange($start=0, $num, $dirname='', $category='') { - $db = new newznab\db\DB(); + $db = new newznab\db\Settings(); $dirname = empty($category) ? $dirname : $dirname." @category =".$category; $sphinxQuery = sprintf("SELECT id " ."FROM predb, predb_delta " diff --git a/lib/copy_this/newznab/controllers/SphinxSearch.php b/lib/copy_this/newznab/controllers/SphinxSearch.php index 4a47e628d..dca42f2b8 100644 --- a/lib/copy_this/newznab/controllers/SphinxSearch.php +++ b/lib/copy_this/newznab/controllers/SphinxSearch.php @@ -1,4 +1,5 @@ sphinxQL = new newznab\db\DB( + $this->sphinxQL = new DB( [ 'dbname' => '', 'dbport' => NN_SPHINXQL_PORT, @@ -58,9 +59,9 @@ class SphinxSearch /** * Delete release from Sphinx RT table. * @param array $identifiers ['g' => Release GUID(mandatory), 'id => ReleaseID(optional, pass false)] - * @param DB $pdo + * @param Settings $pdo */ - public function deleteRelease($identifiers, DB $pdo) + public function deleteRelease($identifiers, Settings $pdo) { if (!is_null($this->sphinxQL)) { if ($identifiers['i'] === false) { diff --git a/lib/copy_this/newznab/controllers/SpotNab.php b/lib/copy_this/newznab/controllers/SpotNab.php index ecd862414..821a3405b 100644 --- a/lib/copy_this/newznab/controllers/SpotNab.php +++ b/lib/copy_this/newznab/controllers/SpotNab.php @@ -1,6 +1,6 @@ _pdo = new DB(); + $this->_pdo = new Settings(); $this->_nntp = new NNTP(['Settings' => $this->_pdo]); $this->releaseImage = new \ReleaseImage($this->_pdo); $this->nzb = new \NZB($this->_pdo); @@ -189,30 +189,30 @@ class SpotNab { } // Public Key - $this->_ssl_pubkey = trim($this->_globals->spotnabsitepubkey)? - $this->_globals->spotnabsitepubkey:false; + $this->_ssl_pubkey = trim($this->_pdo->getSetting('spotnabsitepubkey'))? + $this->_pdo->getSetting('spotnabsitepubkey') : false; if($this->_ssl_pubkey) $this->_ssl_pubkey = $this->decompstr($this->_ssl_pubkey); // Private Key - $this->_ssl_prvkey = trim($this->_globals->spotnabsiteprvkey)? - $this->_globals->spotnabsiteprvkey:false; + $this->_ssl_prvkey = trim($this->_pdo->getSetting('spotnabsiteprivkey'))? + $this->_pdo->getSetting('spotnabsiteprivkey') : false; if($this->_ssl_prvkey) $this->_ssl_prvkey = $this->decompstr($this->_ssl_prvkey); // Track Discovery Article - $this->_discovery_lastarticle = intval($this->_globals->spotnablastarticle); + $this->_discovery_lastarticle = intval($this->_pdo->getSetting('spotnablastarticle')); // Posting Flag - $this->_can_post = (trim($this->_globals->spotnabpost) == 1)? + $this->_can_post = (trim($this->_pdo->getSetting('spotnabpost')) == 1)? true:false; // Auto Enable Flag - $this->_auto_enable = (trim($this->_globals->spotnabautoenable) == 1)? + $this->_auto_enable = (trim($this->_pdo->getSetting('spotnabautoenable')) == 1)? true:false; // Spotnab Privacy Posting - $this->_post_privacy = (trim($this->_globals->spotnabprivacy) == 1)? + $this->_post_privacy = (trim($this->_pdo->getSetting('spotnabsiteprivacy')) == 1)? true:false; // Auto-Discovery Private Key (used for Posting) @@ -264,7 +264,7 @@ class SpotNab { // *********************************************************************** public function auto_clean($max_days=90){ - $db = new DB(); + $db = new Settings(); // automatically sweep old sources lingering that have not shown any // sort of life what-so-ever for more then 90 days $sql = "DELETE FROM spotnabsources WHERE " @@ -288,7 +288,7 @@ class SpotNab { $sql_rel = "SELECT gid FROM releases WHERE gid IN ('%s') "; $sql_del = "DELETE FROM releasecomment WHERE gid IN ('%s')"; $total_delcnt = 0; - $db = new DB(); + $db = new Settings(); while(1) { $res = $db->query(sprintf($sql, $offset, $batch)); @@ -333,17 +333,17 @@ class SpotNab { // using existing sources // - it has never posted discovery information // - it has never scanned for existing discoveries - $db = new DB(); + $db = new Settings(); // resets sources so they need to query again $sources = "UPDATE spotnabsources SET " ."lastupdate = NULL," ."lastbroadcast = NULL," ."lastarticle = 0"; - $discovery_a = "UPDATE site SET " + $discovery_a = "UPDATE settings SET " ."value = '0' " ."WHERE setting = 'spotnablastarticle'"; - $broadcast = "UPDATE site SET " + $broadcast = "UPDATE settings SET " ."updateddate = '1980-01-01 00:00:00' " ."WHERE setting = 'spotnabbroadcast'"; @@ -351,11 +351,11 @@ class SpotNab { // by the maximum age a broadcast can be. $reftime = date("Y-m-d H:i:s", time()-(SpotNab::POST_BROADCAST_INTERVAL)); - $discovery_b = "UPDATE site SET " + $discovery_b = "Update settings SET " ."updateddate = '1980-01-01 00:00:00' " ."WHERE setting = 'spotnabdiscover'"; - $post = "UPDATE site SET " + $post = "Update settings SET " ."updateddate = '$reftime' " ."WHERE setting = 'spotnabpost'"; $db->queryExec($sources); @@ -367,7 +367,7 @@ class SpotNab { // *********************************************************************** public function fetch_discovery($reftime=Null, $retries=3){ - $db = new DB(); + $db = new Settings(); $last = $first = Null; // Return Value; Initialize it to Okay @@ -384,7 +384,7 @@ class SpotNab { } if($reftime === Null){ - $q = "SELECT updateddate FROM site WHERE " + $q = "SELECT updateddate FROM settings WHERE " ."setting = 'spotnabdiscover'"; $res = $db->queryOneRow($q); if($res){ @@ -512,13 +512,13 @@ class SpotNab { continue; } } - $sql = sprintf("UPDATE site SET value = '%d' " + $sql = sprintf("Update settings SET value = '%d' " ."WHERE setting = 'spotnablastarticle'", $last); $db->queryExec($sql); printf("%d new and %d updated source(s).\n", $inserted, $updated); // Update reference point - $q = "UPDATE site SET updateddate = NOW() WHERE " + $q = "Update settings SET updateddate = NOW() WHERE " ."setting = 'spotnabdiscover'"; $db->queryExec($q); @@ -529,9 +529,9 @@ class SpotNab { // *********************************************************************** public function auto_post_discovery($repost_sec=SpotNab::POST_BROADCAST_INTERVAL){ - $db = new DB(); + $db = new Settings(); // performs a post discovery once the time in seconds has elapsed - $q = "SELECT updateddate FROM site WHERE " + $q = "SELECT updateddate FROM settings WHERE " ."setting = 'spotnabbroadcast'"; $res = $db->queryOneRow($q); $then = strtotime($res['updateddate']); @@ -541,7 +541,7 @@ class SpotNab { if($this->post_discovery()) { // Update post time - $q = "UPDATE site SET updateddate = NOW() WHERE " + $q = "Update settings SET updateddate = NOW() WHERE " ."setting = 'spotnabbroadcast'"; $res = $db->queryExec($q); } @@ -652,7 +652,7 @@ class SpotNab { * The specified $reftime is presumed to be local *not utc* */ - $db = new DB(); + $db = new Settings(); $last = $first = Null; // Return Value; Initialize it to Okay @@ -905,7 +905,7 @@ class SpotNab { public function processGID($limit=500, $batch=5000, $delete_broken_releases=false){ // Process until someone presses cntrl-c - $db = new DB(); + $db = new Settings(); $nzb = new NZB(); $processed = 0; @@ -1007,7 +1007,7 @@ class SpotNab { public function keygen($print=true, $force_regen=false){ // Simply generate a Public/Private Key pair if they don't already // exist - $db = new DB(); + $db = new Settings(); // A small boolean we safely toggle after performing // a few checks first to make sure it's safe to do so @@ -1037,12 +1037,12 @@ class SpotNab { $keys = $this->_keygen(); if(is_array($keys)){ // Force New Username - $sql = sprintf("UPDATE site SET value = %s " + $sql = sprintf("Update settings SET value = %s " ."WHERE setting = 'spotnabuser'", $db->escapeString(sprintf("nntp-%s",substr(md5($keys['pubkey']), 0, 4)))); $db->queryExec($sql); // Force New Email - $sql = sprintf("UPDATE site SET value = %s " + $sql = sprintf("Update settings SET value = %s " ."WHERE setting = 'spotnabemail'", $db->escapeString(sprintf("nntp-%s@%s.com", substr(md5($keys['pubkey']), 4, 8), @@ -1050,18 +1050,18 @@ class SpotNab { ))); $db->queryExec($sql); // Save Keys - $sql = sprintf("UPDATE site SET value = %s ". + $sql = sprintf("Update settings SET value = %s ". "WHERE setting = 'spotnabsitepubkey'", $db->escapeString($keys['pubkey'])); $db->queryExec($sql); //echo $keys['pubkey']."\n"; - $sql = sprintf("UPDATE site SET value = %s ". + $sql = sprintf("Update settings SET value = %s ". "WHERE setting = 'spotnabsiteprvkey'", $db->escapeString($keys['prvkey'])); $db->queryExec($sql); - // Update Site Information + // Update settings Information $this->_globals = $this->_site; $this->_post_user = trim($this->_globals->spotnabuser); $this->_post_email = trim($this->_globals->spotnabemail); @@ -1330,7 +1330,7 @@ class SpotNab { // Prepare some general SQL Commands for saving later if all goes well // - $db = new DB(); + $db = new Settings(); $rc = new ReleaseComments(); // Comments @@ -1553,7 +1553,7 @@ class SpotNab { // Prepare some general SQL Commands for saving later if all goes well // - $db = new DB(); + $db = new Settings(); // Auto Enable Flag (used for inserts only) $auto_enable = ($this->_auto_enable)?"1":"0"; @@ -1891,7 +1891,7 @@ class SpotNab { { $message['comments'] = $data['comments']; - $db = new DB(); + $db = new Settings(); $sql = sprintf("UPDATE releasecomment " ."SET issynced = 1 WHERE id IN (%s)", implode(",", $data['ids'])); @@ -2245,7 +2245,7 @@ class SpotNab { * but otherwise it's expected format is string "Y-m-d H:i:s" */ - $db = new DB(); + $db = new Settings(); // Now we fetch for any new posts since reference point $sql = sprintf("SELECT r.gid, rc.id, rc.text, u.username, " @@ -2488,7 +2488,7 @@ class SpotNab { public function getSources() { - $db = new DB(); + $db = new Settings(); return $db->query("SELECT id, lastupdate,lastbroadcast, active, description, " ."(SELECT count(id) from releasecomment where sourceid = s.id)" ." AS comments FROM spotnabsources s"); @@ -2496,14 +2496,14 @@ class SpotNab { public function getSourceById($id) { - $db = new DB(); + $db = new Settings(); $sql = sprintf("SELECT * FROM spotnabsources WHERE id = %d", $id); return $db->queryOneRow($sql); } public function addSource($description,$username,$usermail,$usenetgroup,$publickey) { - $db = new DB(); + $db = new Settings(); $sql = sprintf("INSERT INTO spotnabsources " ."(description, username, useremail," ." usenetgroup, publickey, active) " @@ -2516,7 +2516,7 @@ class SpotNab { public function updateSource($id, $description,$username,$usermail,$usenetgroup,$publickey) { - $db = new DB(); + $db = new Settings(); return $db->queryExec( sprintf("UPDATE spotnabsources SET " ."description = %s, username = %s, useremail = %s," @@ -2528,19 +2528,19 @@ class SpotNab { public function deleteSource($id) { - $db = new DB(); + $db = new Settings(); return $db->queryExec(sprintf("DELETE FROM spotnabsources WHERE id = %d", $id)); } public function toggleSource($id, $active) { - $db = new DB(); + $db = new Settings(); return $db->queryExec(sprintf("update spotnabsources SET active = %d WHERE id = %d", $active, $id)); } public function getDefaultValue($table,$field) { - $db = new DB(); + $db = new Settings(); return $db->query(sprintf("SHOW COLUMNS FROM %s WHERE field = %s", $table, $db->escapeString($field))); } } \ No newline at end of file diff --git a/lib/copy_this/newznab/controllers/TheTVDB.php b/lib/copy_this/newznab/controllers/TheTVDB.php index 68803d167..24ec1c7a0 100644 --- a/lib/copy_this/newznab/controllers/TheTVDB.php +++ b/lib/copy_this/newznab/controllers/TheTVDB.php @@ -1,6 +1,6 @@ echooutput = (NN_ECHOCLI && $echooutput); $this->MIRROR = 'http://www.thetvdb.com'; - $this->pdo = new DB(); + $this->pdo = new Settings(); $this->echooutput = $echooutput; } diff --git a/lib/copy_this/newznab/controllers/Tmux.php b/lib/copy_this/newznab/controllers/Tmux.php index 76224ff6a..e9e2dcd38 100644 --- a/lib/copy_this/newznab/controllers/Tmux.php +++ b/lib/copy_this/newznab/controllers/Tmux.php @@ -1,27 +1,27 @@ pdo = (empty($pdo) ? new newznab\db\DB() : $pdo); + $this->pdo = (empty($pdo) ? new Settings() : $pdo); $s = new Sites; $this->site = $s->get(); } public function version() { - return $this->site->dbversion; + return $this->pdo->getSetting('dbversion'); } public function update($form) @@ -175,7 +175,7 @@ class Tmux public function getConstantSettings() { $tmuxstr = 'SELECT value FROM tmux WHERE setting ='; - $settstr = 'SELECT value FROM site WHERE setting ='; + $settstr = 'SELECT value FROM settings WHERE setting ='; $sql = sprintf( "SELECT @@ -196,7 +196,7 @@ class Tmux public function getMonitorSettings() { $tmuxstr = 'SELECT value FROM tmux WHERE setting ='; - $settstr = 'SELECT value FROM site WHERE setting ='; + $settstr = 'SELECT value FROM settings WHERE setting ='; $sql = sprintf( "SELECT @@ -430,7 +430,7 @@ class Tmux AND (now() - INTERVAL backfill_target DAY) < first_record_postdate ) AS backfill_groups_days, (SELECT COUNT(*) FROM groups WHERE first_record IS NOT NULL AND backfill = 1 AND (now() - INTERVAL datediff(curdate(), - (SELECT VALUE FROM site WHERE setting = 'safebackfilldate')) DAY) < first_record_postdate) AS backfill_groups_date", + (SELECT VALUE FROM settings WHERE setting = 'safebackfilldate')) DAY) < first_record_postdate) AS backfill_groups_date", $this->pdo->escapeString($db_name) ); case 6: diff --git a/lib/copy_this/newznab/controllers/TmuxOutput.php b/lib/copy_this/newznab/controllers/TmuxOutput.php index d1c9ac68d..8ff81b4b6 100644 --- a/lib/copy_this/newznab/controllers/TmuxOutput.php +++ b/lib/copy_this/newznab/controllers/TmuxOutput.php @@ -1,4 +1,7 @@ get(); $t = new Tmux(); $tmux = $t->get(); - $this->_vers = $site->dbversion; + $this->_git = new \newznab\utility\Git(); // Do not remove the full namespace/ PHP gets confused for some reason without it. + $this->_vers = Utility::getValidVersionsFile(); $this->_tvers = $tmux->sqlpatch; @@ -112,11 +120,12 @@ class TmuxOutput extends Tmux $buffer = ''; $state = ($this->runVar['settings']['is_running'] == 1) ? 'Running' : 'Disabled'; //$version = $this->_tvers . 'r' . $this->_vers; + $version = $this->_vers->versions->git->tag . 'r' . $this->_git->commits(); $tversion = '0.6r0255'; $buffer .= sprintf($this->tmpMasks[2], - "Monitor $state v$tversion @ $this->_tvers [" . $this->_vers ."]: ", - $this->relativeTime($this->runVar['timers']['timer1']) + "Monitor $state v$version [" . $this->runVar['constants']['sqlpatch'] . "]: ", + $this->relativeTime($this->runVar['timers']['timer1']) ); $buffer .= sprintf($this->tmpMasks[1], diff --git a/lib/copy_this/newznab/controllers/TmuxRun.php b/lib/copy_this/newznab/controllers/TmuxRun.php index 7cf03f004..8a5dcd273 100644 --- a/lib/copy_this/newznab/controllers/TmuxRun.php +++ b/lib/copy_this/newznab/controllers/TmuxRun.php @@ -9,9 +9,9 @@ class TmuxRun extends Tmux protected $_dateFormat; /** - * @param newznab\db\DB $pdo + * @param newznab\db\Settings $pdo */ - public function __construct(newznab\db\DB $pdo = null) + public function __construct(newznab\db\Settings $pdo = null) { parent::__construct($pdo); $this->_dateFormat = '%Y-%m-%d %T'; diff --git a/lib/copy_this/newznab/controllers/TvAnger.php b/lib/copy_this/newznab/controllers/TvAnger.php index b80719518..1a71bbc00 100644 --- a/lib/copy_this/newznab/controllers/TvAnger.php +++ b/lib/copy_this/newznab/controllers/TvAnger.php @@ -1,6 +1,6 @@ site = $s->get(); - $this->pdo = ($options['Settings'] instanceof DB ? $options['Settings'] : new DB()); - $this->rageqty = ($this->site->maxrageprocessed != '') ? $this->site->maxrageprocessed : 75; + $this->pdo = ($options['Settings'] instanceof Settings ? $options['Settings'] : new Settings()); + $this->rageqty = ($this->pdo->getSetting('maxrageprocessed') != '') ? $this->pdo->getSetting('maxrageprocessed') : 75; $this->echooutput = ($options['Echo'] && NN_ECHOCLI); $this->xmlEpisodeInfoUrl = diff --git a/lib/copy_this/newznab/controllers/TvRage.php b/lib/copy_this/newznab/controllers/TvRage.php index 4a520a6e7..4f81abf9f 100644 --- a/lib/copy_this/newznab/controllers/TvRage.php +++ b/lib/copy_this/newznab/controllers/TvRage.php @@ -1,6 +1,6 @@ echooutput = (NN_ECHOCLI && $echooutput); - $this->pdo = new DB(); + $this->pdo = new Settings(); $this->xmlFullSearchUrl = "http://services.tvrage.com/feeds/full_search.php?show="; $this->xmlFullShowInfoUrl = "http://services.tvrage.com/feeds/full_show_info.php?sid="; @@ -389,7 +389,7 @@ class TvRage public function updateEpInfo($show, $relid) { - $this->pdo = new newznab\db\DB; + $this->pdo = new newznab\db\Settings; if (empty($show['airdate']) || !strtotime($show['airdate'])) { $tvairdate = "null"; @@ -429,7 +429,7 @@ class TvRage public function updateRageInfo($rageid, $show, $tvrShow, $relid) { - $this->pdo = new newznab\db\DB; + $this->pdo = new newznab\db\Settings; $idCheck = $this->getByRageID($rageid); diff --git a/lib/copy_this/newznab/controllers/UserMovies.php b/lib/copy_this/newznab/controllers/UserMovies.php index 7e4d29607..3fb96a997 100644 --- a/lib/copy_this/newznab/controllers/UserMovies.php +++ b/lib/copy_this/newznab/controllers/UserMovies.php @@ -1,12 +1,12 @@ escapeString(implode('|', $catid)) : "null"; @@ -16,33 +16,33 @@ class UserMovies public function getMovies($uid) { - $db = new DB(); + $db = new Settings(); $sql = sprintf("select usermovies.*, movieinfo.year, movieinfo.plot, movieinfo.cover, movieinfo.title from usermovies left outer join movieinfo on movieinfo.imdbid = usermovies.imdbid where userid = %d order by movieinfo.title asc", $uid); return $db->query($sql); } public function delMovie($uid, $imdbid) { - $db = new DB(); + $db = new Settings(); $db->queryExec(sprintf("DELETE from usermovies where userid = %d and imdbid = %d ", $uid, $imdbid)); } public function getMovie($uid, $imdbid) { - $db = new DB(); + $db = new Settings(); $sql = sprintf("select usermovies.*, movieinfo.title from usermovies left outer join movieinfo on movieinfo.imdbid = usermovies.imdbid where usermovies.userid = %d and usermovies.imdbid = %d ", $uid, $imdbid); return $db->queryOneRow($sql); } public function delMovieForUser($uid) { - $db = new DB(); + $db = new Settings(); $db->queryExec(sprintf("DELETE from usermovies where userid = %d", $uid)); } public function updateMovie($uid, $imdbid, $catid=array()) { - $db = new DB(); + $db = new Settings(); $catid = (!empty($catid)) ? $db->escapeString(implode('|', $catid)) : "null"; diff --git a/lib/copy_this/newznab/controllers/UserSeries.php b/lib/copy_this/newznab/controllers/UserSeries.php index 012745505..5c934e7cd 100644 --- a/lib/copy_this/newznab/controllers/UserSeries.php +++ b/lib/copy_this/newznab/controllers/UserSeries.php @@ -1,12 +1,12 @@ escapeString(implode('|', $catid)) : "null"; @@ -16,39 +16,39 @@ class UserSeries public function getShows($uid) { - $db = new DB(); + $db = new Settings(); $sql = sprintf("select userseries.*, tvrage.releasetitle from userseries inner join (SELECT id, releasetitle, rageid FROM tvrage GROUP BY rageid) tvrage on tvrage.rageid = userseries.rageid where userid = %d order by tvrage.releasetitle asc", $uid); return $db->query($sql); } public function delShow($uid, $rageid) { - $db = new DB(); + $db = new Settings(); $db->queryExec(sprintf("DELETE from userseries where userid = %d and rageid = %d ", $uid, $rageid)); } public function getShow($uid, $rageid) { - $db = new DB(); + $db = new Settings(); $sql = sprintf("select userseries.*, tvrage.releasetitle from userseries left outer join (SELECT id, releasetitle, rageid FROM tvrage GROUP BY rageid) tvrage on tvrage.rageid = userseries.rageid where userseries.userid = %d and userseries.rageid = %d ", $uid, $rageid); return $db->queryOneRow($sql); } public function delShowForUser($uid) { - $db = new DB(); + $db = new Settings(); $db->queryExec(sprintf("DELETE from userseries where userid = %d", $uid)); } public function delShowForSeries($sid) { - $db = new DB(); + $db = new Settings(); $db->queryExec(sprintf("DELETE from userseries where rageid = %d", $sid)); } public function updateShow($uid, $rageid, $catid=array()) { - $db = new DB(); + $db = new Settings(); $catid = (!empty($catid)) ? $db->escapeString(implode('|', $catid)) : "null"; diff --git a/lib/copy_this/newznab/controllers/Users.php b/lib/copy_this/newznab/controllers/Users.php index d9bd7019a..cbfe4a4d6 100644 --- a/lib/copy_this/newznab/controllers/Users.php +++ b/lib/copy_this/newznab/controllers/Users.php @@ -1,6 +1,6 @@ null, ]; $options += $defaults; - $this->site= new Sites(); - $this->site = $this->site->get(); - $this->pdo = ($options['Settings'] instanceof DB ? $options['Settings'] : new DB()); + $this->pdo = ($options['Settings'] instanceof Settings ? $options['Settings'] : new Settings()); $this->password_hash_cost = (defined('NN_PASSWORD_HASH_COST') ? NN_PASSWORD_HASH_COST : 11); } @@ -344,7 +342,7 @@ class Users { $data = $this->pdo->query(sprintf("select id,email from users WHERE role = %d and rolechangedate < now()", $uprole)); foreach ($data as $u) { - Utility::sendEmail($u["email"], $msgsubject, $msgbody, $this->site->email); + Utility::sendEmail($u["email"], $msgsubject, $msgbody, $this->pdo->getSetting('email')); $this->pdo->queryExec(sprintf("update users SET role = %d, rolechangedate=null WHERE id = %d", $downrole, $u["id"])); } @@ -500,7 +498,7 @@ class Users // the invite would still have been used up // $invitedby = 0; - if (($this->site->registerstatus == Sites::REGISTER_STATUS_INVITE) && !$forceinvitemode) { + if (($this->pdo->getSetting('registerstatus') == Settings::REGISTER_STATUS_INVITE) && !$forceinvitemode) { if ($invitecode == '') return Users::ERR_SIGNUP_BADINVITECODE; @@ -559,7 +557,7 @@ class Users $site = new Sites(); $this->site = $site->get(); - if ($this->site->storeuserips != "1") + if ($this->pdo->getSetting('storeuserips') != "1") $host = ""; if ($invitedby == 0) @@ -594,7 +592,7 @@ class Users $site = new Sites(); $this->site = $site->get(); - if ($this->site->storeuserips != "1") + if ($this->pdo->getSetting('storeuserips') != "1") $host = ''; $this->updateSiteAccessed($uid, $host); @@ -793,11 +791,11 @@ class Users { $ipsql = "('-1')"; - if ($this->site->userhostexclusion != '') { + if ($this->pdo->getSetting('userhostexclusion') != '') { $ipsql = ""; - $ips = explode(",", $this->site->userhostexclusion); + $ips = explode(",", $this->pdo->getSetting('userhostexclusion')); foreach ($ips as $ip) { - $ipsql .= $this->pdo->escapeString($this->getHostHash($ip, $this->site->siteseed)) . ","; + $ipsql .= $this->pdo->escapeString($this->getHostHash($ip, $this->pdo->getSetting('siteseed'))) . ","; } $ipsql = "(" . $ipsql . " '-1')"; } @@ -821,7 +819,7 @@ class Users public function getHostHash($host, $siteseed = "") { if ($siteseed == "") { - $siteseed = $this->site->siteseed; + $siteseed = $this->pdo->getSetting('siteseed'); } return self::hashSHA1($siteseed . $host . $siteseed); diff --git a/lib/copy_this/newznab/controllers/XXX.php b/lib/copy_this/newznab/controllers/XXX.php index 62080aa7a..b32967192 100644 --- a/lib/copy_this/newznab/controllers/XXX.php +++ b/lib/copy_this/newznab/controllers/XXX.php @@ -1,6 +1,6 @@ site = $s->get(); - $this->pdo = ($options['Settings'] instanceof DB ? $options['Settings'] : new DB()); + $this->pdo = ($options['Settings'] instanceof Settings ? $options['Settings'] : new Settings()); $this->releaseImage = ($options['ReleaseImage'] instanceof \ReleaseImage ? $options['ReleaseImage'] : new \ReleaseImage($this->pdo)); - $this->movieqty = ($this->site->maxxxxprocessed != '') ? $this->site->maxxxxprocessed : 100; - $this->showPasswords = ($this->site->showpasswordedrelease != '') ? $this->site->showpasswordedrelease : 0; + $this->movieqty = ($this->pdo->getSetting('maxxxxprocessed') != '') ? $this->pdo->getSetting('maxxxxprocessed') : 100; + $this->showPasswords = ($this->pdo->getSetting('showpasswordedrelease') != '') ? $this->pdo->getSetting('showpasswordedrelease') : 0; $this->debug = NN_DEBUG; $this->echooutput = ($options['Echo'] && NN_ECHOCLI); $this->imgSavePath = NN_COVERS . 'xxx' . DS; diff --git a/lib/copy_this/newznab/db/DbUpdate.php b/lib/copy_this/newznab/db/DbUpdate.php new file mode 100644 index 000000000..c7e51a0ad --- /dev/null +++ b/lib/copy_this/newznab/db/DbUpdate.php @@ -0,0 +1,428 @@ +. + * @author niel + * @copyright 2014 nZEDb + */ +namespace newznab\db; + +use newznab\utility\Git; +use newznab\utility\Utility; +use ColorCLI; + + +class DbUpdate +{ + /** + * @var \newznab\db\Settings Instance variable for DB object. + */ + public $pdo; + + /** + * @var \newznab\utility\Git instance + */ + public $git; + + /** + * @var object Instance variable for logging object. Currently only ColorCLI supported, + * but expanding for full logging with agnostic API planned. + */ + public $log; + + /** + * @var object Instance object for sites/settings class. + */ + public $settings; + + protected $_DbSystem; + + /** + * @var bool Has the Db been backed up? + */ + private $backedUp = false; + + /** + * @var bool Should we perform a backup? + */ + private $backup = false; + + public function __construct(array $options = []) + { + $defaults = [ + 'backup' => true, + 'db' => null, + 'git' => new Git(), + 'logger' => new ColorCLI(), + ]; + $options += $defaults; + unset($defaults); + + $this->backup = $options['backup']; + $this->pdo = (($options['db'] instanceof Settings) ? $options['db'] : new Settings()); + $this->git = $options['git']; + $this->log = $options['logger']; + + // If $pdo is an instance of Settings, reuse it to save resources. + // This is for unconverted scripts that still use $db->settings instead of the $db->pdo property. + $this->settings =& $this->pdo; + + $this->_DbSystem = strtolower($this->pdo->dbSystem()); + } + + public function loadTables(array $options = []) + { + $defaults = [ + 'ext' => 'tsv', + 'files' => [], + 'path' => NN_RES . 'db' . DS . 'schema' . DS . 'data', + 'regex' => '#^' . Utility::PATH_REGEX . '(?P\d+)-(?P\w+)\.tsv$#', + ]; + $options += $defaults; + + $files = empty($options['files']) ? Utility::getDirFiles($options) : $options['files']; + natsort($files); + $local = $this->pdo->isLocalDb() ? '' : 'LOCAL '; + $sql = 'LOAD DATA ' . $local . 'INFILE "%s" IGNORE INTO TABLE `%s` FIELDS TERMINATED BY "\t" OPTIONALLY ENCLOSED BY "\"" IGNORE 1 LINES (%s)'; + foreach ($files as $file) { + echo "File: $file\n"; + + if (is_readable($file)) { + if (preg_match($options['regex'], $file, $matches)) { + $table = $matches['table']; + // Get the first line of the file which holds the columns used. + $handle = @fopen($file, "r"); + if (is_resource($handle)) { + $line = fgets($handle); + fclose($handle); + if ($line === false) { + echo "FAILED reading first line of '$file'\n"; + continue; + } + $fields = trim($line); + + echo "Inserting data into table: '$table'\n"; + if (Utility::isWin()) { + $file = str_replace("\\", '\/', $file); + } + $this->pdo->exec(sprintf($sql, $file, $table, $fields)); + } else { + exit("Failed to open file: '$file'\n"); + } + } else { + echo "Incorrectly formatted filename '$file' (should match " . + str_replace('#', '', $options['regex']) . "\n"; + } + } else { + echo $this->log->error(" Unable to read file: '$file'"); + } + } + } + + /** + * Takes new files in the correct format from the patches directory and turns them into proper patches. + * + * The files should be name as '+x~
.sql' where x is a number starting at 1 for your first + * patch.
should be the name of the primary table affected. If you have to modify more + * than one table, consider splitting into multiple patches using different patch modifier + * numbers to order them. i.e. +1~settings.sql, +2~predb.sql, etc. + * + * @param array $options + */ + public function newPatches(array $options = []) + { + $defaults = [ + 'data' => NN_RES . 'db' . DS . 'schema' . DS . 'data' . DS, + 'ext' => 'sql', + 'path' => NN_RES . 'db' . DS . 'patches' . DS, + 'regex' => '#^' . Utility::PATH_REGEX . '\+(?P\d+)~(?P
\w+)\.sql$#', + 'safe' => true, + ]; + $options += $defaults; + + $this->processPatches(['safe' => $options['safe']]); // Make sure we are completely up to date! + + echo $this->log->primaryOver('Looking for new patches...'); + $files = Utility::getDirFiles($options); + + $count = count($files); + echo $this->log->header(" $count found"); + if ($count > 0) { + echo $this->log->header('Processing...'); + natsort($files); + $local = $this->pdo->isLocalDb() ? '' : 'LOCAL '; + + foreach ($files as $file) { + if (!preg_match($options['regex'], $file, $matches)) { + $this->log->error("$file does not match the pattern {$options['regex']}\nPlease fix this before continuing"); + } else { + echo $this->log->header('Processing patch file: ' . $file); + $this->splitSQL($file, ['local' => $local, 'data' => $options['data']]); + $current = (integer)$this->settings->getSetting('sqlpatch'); + $current++; + $this->pdo->queryExec("UPDATE settings SET value = '$current' WHERE setting = 'sqlpatch';"); + $newName = $matches['drive'] . $matches['path'] . + str_pad($current, 4, '0', STR_PAD_LEFT) . '~' . + $matches['table'] . '.sql'; + rename($matches[0], $newName); + $this->git->add($newName); + if ($this->git->isCommited($this->git->getBranch() . ':' . $matches[0])) { + $this->git->rm("{$matches[0]}"); // remove old filename from the index. + } + } + } + } + } + + public function processPatches(array $options = []) + { + $patched = 0; + $defaults = [ + 'data' => NN_RES . 'db' . DS . 'schema' . DS . 'data' . DS, + 'ext' => 'sql', + 'path' => NN_RES . 'db' . DS . 'patches' . DS, + 'regex' => '#^' . Utility::PATH_REGEX . '(?P\d{4})~(?P
\w+)\.sql$#', + 'safe' => true, + ]; + $options += $defaults; + + $currentVersion = $this->settings->getSetting(['setting' => 'sqlpatch']); + if (!is_numeric($currentVersion)) { + exit("Bad sqlpatch value: '$currentVersion'\n"); + } + + $files = empty($options['files']) ? Utility::getDirFiles($options) : $options['files']; + + if (count($files)) { + natsort($files); + $local = $this->pdo->isLocalDb() ? '' : 'LOCAL '; + $data = $options['data']; + echo $this->log->primary('Looking for unprocessed patches...'); + foreach ($files as $file) { + $setPatch = false; + $fp = fopen($file, 'r'); + $patch = fread($fp, filesize($file)); + + if (preg_match($options['regex'], str_replace('\\', '/', $file), $matches)) { + $patch = (integer)$matches['patch']; + $setPatch = true; + } else if (preg_match('/UPDATE `?site`? SET `?value`? = \'?(?P\d+)\'? WHERE `?setting`? = \'sqlpatch\'/i', + $patch, + $matches) + ) { + $patch = (integer)$matches['patch']; + } else { + throw new \RuntimeException("No patch information available, stopping!!"); + } + + if ($patch > $currentVersion) { + echo $this->log->header('Processing patch file: ' . $file); + if ($options['safe'] && !$this->backedUp) { + $this->_backupDb(); + } + $this->splitSQL($file, ['local' => $local, 'data' => $data]); + if ($setPatch) { + $this->pdo->queryExec("UPDATE settings SET value = '$patch' WHERE setting = 'sqlpatch';"); + } + $patched++; + } + } + } else { + exit($this->log->error("\nHave you changed the path to the patches folder, or do you have the right permissions?\n")); + } + + if ($patched === 0) { + echo $this->log->info("Nothing to patch, you are already on version $currentVersion"); + } + return $patched; + } + + public function processSQLFile(array $options = []) + { + $defaults = [ + 'filepath' => NN_RES . 'db' . DS . 'schema' . DS . $this->_DbSystem . '-ddl.sql', + ]; + $options += $defaults; + + $sql = file_get_contents($options['filepath']); + $sql = str_replace(['DELIMITER $$', 'DELIMITER ;', '$$'], '', $sql); + $this->pdo->exec($sql); + } + + public function splitSQL($file, array $options = []) + { + $defaults = [ + 'data' => null, + 'delimiter' => ';', + 'local' => null, + ]; + $options += $defaults; + + if (!empty($options['vars'])) { + extract($options['vars']); + } + + set_time_limit(0); + + if (is_file($file)) { + $file = fopen($file, 'r'); + + if (is_resource($file)) { + $query = []; + + $oldDelimiter = ''; + while (!feof($file)) { + $line = fgets($file); + $query[] = $line; + + if (preg_match('~' . preg_quote($options['delimiter'], '~') . '\s*$~iS', + end($query)) == 1 + ) { + $query = trim(implode('', $query)); + if ($options['local'] !== null) { + $query = str_replace('{:local:}', $options['local'], $query); + } + if (!empty($options['data'])) { + $query = str_replace('{:data:}', $options['data'], $query); + } + + try { + $qry = $this->pdo->prepare($query); + $qry->execute(); + echo $this->log->alternateOver('SUCCESS: ') . + $this->log->primary($query); + } catch (\PDOException $e) { + // Log the problem and the query. + file_put_contents( + NN_LOGS . 'patcherrors.log', + '[' . date('r') . '] [ERROR] [' . + trim(preg_replace('/\s+/', ' ', $e->getMessage())) . ']' . PHP_EOL . + '[' . date('r') . '] [QUERY] [' . + trim(preg_replace('/\s+/', ' ', $query)) . ']' . PHP_EOL, + FILE_APPEND + ); + + if ( + in_array($e->errorInfo[1], [1091, 1060, 1061, 1071, 1146]) || + in_array($e->errorInfo[0], + [23505, 42701, 42703, '42P07', '42P16']) + ) { + if ($e->errorInfo[1] == 1060) { + echo $this->log->warning( + "$query The column already exists - No need to worry \{" . + $e->errorInfo[1] . "}.\n"); + } else { + echo $this->log->warning( + "$query Skipped - No need to worry \{" . + $e->errorInfo[1] . "}.\n"); + } + } else { + if (preg_match('/ALTER IGNORE/i', $query)) { + $this->pdo->queryExec("SET SESSION old_alter_table = 1"); + try { + $this->pdo->exec($query); + echo $this->log->alternateOver('SUCCESS: ') . + $this->log->primary($query); + } catch (\PDOException $e) { + exit($this->log->error("$query Failed \{" . $e->errorInfo[1] . "}\n\t" . $e->errorInfo[2])); + } + } else { + exit($this->log->error("$query Failed \{" . $e->errorInfo[1] . "}\n\t" . $e->errorInfo[2])); + } + } + } + + while (ob_get_level() > 0) { + ob_end_flush(); + } + flush(); + if ($oldDelimiter != '') { + $options['delimiter'] = $oldDelimiter; + $oldDelimiter = ''; + } + } + if (preg_match('#^\s*DELIMITER\s+(?P.+)$#i', $line, $matches)) { + $oldDelimiter = $options['delimiter']; + $options['delimiter'] = $matches['delimiter']; + } + + if (is_string($query) === true) { + $query = []; + } + } + } + } + } + + public function updateSchemaData(array $options = []) + { + $changed = false; + $default = [ + 'file' => '10-settings.tsv', + 'path' => 'resources' . DS . 'db' . DS . 'schema' . DS . 'data' . DS, + 'regex' => '#^(?P
.*)\t(?P.*)\t(?P.*)\t(?P.*)\t(?P.*)\t(?P.*)$#', + 'value' => function(array $matches) { + return "{$matches['section']}\t{$matches['subsection']}\t{$matches['name']}\t{$matches['value']}\t{$matches['hint']}\t{$matches['setting']}"; + } // WARNING: leaving this empty will blank not remove lines. + ]; + $options += $default; + + $file = []; + $filespec = Utility::trailingSlash($options['path']) . $options['path']; + if (file_exists($filespec) && ($file = file($filespec, FILE_IGNORE_NEW_LINES))) { + $count = count($file); + $index = 0; + while ($index < $count) { + if (preg_match($options['regex'], $file[$index], $matches)) { + if (VERBOSE) { + echo $this->log->primary("Matched: " . $file[$index]); + } + $index++; + + if (is_callable($options['value'])) { + $file[$index] = $options['value']($matches); + } else { + $file[$index] = $options['value']; + } + $changed = true; + } + } + } + + if ($changed) { + if (file_put_contents($filespec, implode("\n", $file)) === false) { + echo $this->log->error("Error writing file to disc!!"); + } + } + } + + public $backedup; + + protected function _backupDb() + { + if (Utility::hasCommand("php5")) { + $PHP = "php5"; + } else { + $PHP = "php"; + } + + system("$PHP " . NN_MISC . 'testing' . DS . 'DB' . DS . $this->_DbSystem . + 'dump_tables.php db dump'); + $this->backedup = true; + } +} + +?> diff --git a/lib/copy_this/newznab/db/Settings.php b/lib/copy_this/newznab/db/Settings.php new file mode 100644 index 000000000..7b69fc436 --- /dev/null +++ b/lib/copy_this/newznab/db/Settings.php @@ -0,0 +1,349 @@ +. + * @author niel + * @copyright 2014 nZEDb + */ +namespace newznab\db; + +if (!defined('NN_INSTALLER')) { + require_once dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR . 'www' . DIRECTORY_SEPARATOR . 'config.php'; +} + +use newznab\utility\Utility; +use newznab\utility\Versions; + +class Settings extends DB +{ + const REGISTER_STATUS_OPEN = 0; + const REGISTER_STATUS_INVITE = 1; + const REGISTER_STATUS_CLOSED = 2; + const REGISTER_STATUS_API_ONLY = 3; + const ERR_BADUNRARPATH = -1; + const ERR_BADFFMPEGPATH = -2; + const ERR_BADMEDIAINFOPATH = -3; + const ERR_BADNZBPATH = -4; + const ERR_DEEPNOUNRAR = -5; + const ERR_BADTMPUNRARPATH = -6; + const ERR_BADNZBPATH_UNREADABLE = -7; + const ERR_BADNZBPATH_UNSET = -8; + const ERR_BAD_COVERS_PATH = -9; + const ERR_BAD_YYDECODER_PATH = -10; + + private $settings; + + public function __construct(array $options = []) + { + parent::__construct($options); + $result = parent::exec("describe site", true); + $this->table = ($result === false) ? 'settings' : 'site'; + $this->setCovers(); + + return $this->pdo; + } + + /** + * Non-existent variables are assumed to be simple Settings. + * + * @param $name + * + * @return string + */ + public function __get($name) + { + return $this->getSetting($name); + } + + /** + * Retrieve one or all settings from the Db as a string or an array; + * + * @param array|string $options Name of setting to retrieve (null for all settings) + * or array of 'feature', 'section', 'name' of setting{s} to retrieve + * + * @return string|array|bool + */ + public function getSetting($options = []) + { + // todo: think about making this static so it can be accessed without instantiating. + if (!is_array($options)) { + $options = $this->_dottedToArray($options); + if (isset($options['setting']) && isset($this->settings[$options['setting']])) { + return $this->settings[$options['setting']]; + } + } + + $defaults = [ + 'section' => '', + 'subsection' => '', + 'name' => null, + ]; + $options += $defaults; + + if ($this->table == 'settings') { + $result = $this->_getFromSettings($options); + } else { + $result = $this->_getFromSites($options); + } + return $result; + } + + public function getSettingsAsTree($excludeUnsectioned = true) + { + $where = $excludeUnsectioned ? "WHERE section != ''" : ''; + + $sql = sprintf("SELECT section, subsection, name, value, hint FROM settings %s ORDER BY section, subsection, name", $where); + $results = $this->queryArray($sql); + + $tree = []; + if (is_array($results)) { + foreach ($results as $result) { + if (!empty($result['section']) || !$excludeUnsectioned) { + $tree[$result['section']][$result['subsection']][$result['name']] = + ['value' => $result['value'], 'hint' => $result['hint']]; + } + } + } else { + echo "NO results!!\n"; + } + + return $tree; + } + + public function rowToArray(array $row) + { + $this->settings[$row['setting']] = $row['value']; + } + + public function rowsToArray(array $rows) + { + foreach ($rows as $row) { + if (is_array($row)) { + $this->rowToArray($row); + } + } + return $this->settings; + } + + public function setCovers() + { + $path = $this->getSetting([ + 'section' => 'site', + 'subsection' => 'main', + 'name' => 'coverspath', + 'setting' => 'coverspath', + ]); + Utility::setCoversConstant($path); + } + + /** + * Set a setting in the database. + * + * @param array $options Array containing the mandatory keys of 'section', 'subsection', and 'value' + * + * @return boolean true or false indicating success/failure. + */ + public function setSetting(array $options) + { + if (count($options) == 1) { + foreach ($options as $key => $value) { + $options = $this->_dottedToArray($key); + $options['value'] = $value; + } + } + + $result = false; + $defaults = [ + 'section' => null, + 'subsection' => null, + 'name' => '', + 'value' => null, + 'setting' => null, + ]; + $options += $defaults; + + $temp1 = $options['section'] . $options['subsection'] . $options['name']; + $temp2 = $options['section'] . $options['subsection'] . $options['setting']; + if (!empty($temp1) || !empty($temp2)) { + if (empty($temp1)) { + if (isset($this->settings[$options['setting']])) { + $this->settings[$options['setting']] = $options['value']; + } + $result = $this->update($options); + } else if (!empty($options['name'])) { + $where = sprintf("name = '%s'", $options['name']); + $where .= ($options['section'] === null) ? '' : sprintf(" AND section = '%s'", $options['section']); + $where .= ($options['subsection'] === null) ? '' : sprintf(" AND subsection = '%s'", $options['subsection']); + + $sql = sprintf("UPDATE settings SET value = '%s' WHERE %s", + $options['value'], + $where); + $result = $this->pdo->query($sql); + } + } + + return ($result === false) ? false : true; + } + + public function table() + { + return $this->table; + } + + public function update($form) + { + $error = $this->_validate($form); + + if ($error === null) { + $sql = $sqlKeys = []; + foreach ($form as $settingK => $settingV) { + $sql[] = sprintf("WHEN %s THEN %s", + $this->escapeString($settingK), + $this->escapeString($settingV)); + $sqlKeys[] = $this->escapeString($settingK); + } + + $table = $this->table(); + $this->queryExec( + sprintf("UPDATE $table SET value = CASE setting %s END WHERE setting IN (%s)", + implode(' ', $sql), + implode(', ', $sqlKeys) + ) + ); + } else { + $form = $error; + } + return $form; + } + + public function version() + { + try { + $ver = (new Versions())->getTagVersion(); + } catch (\Exception $e) { + $ver = '0.0.0'; + } + return $ver; + } + + protected function _dottedToArray($setting) + { + $result = []; + if (is_string($setting)) { + $parts = explode('.', $setting); + switch (count($parts)) { + case 3: + list( + $result['section'], + $result['subsection'], + $result['name'], + ) = $parts; + break; + case 2: + list( + $result['subsection'], + $result['name'], + ) = $parts; + break; + case 1: + list( + $result['setting'], + ) = $parts; + break; + } + } else { + $result = false; + } + return $result; + } + + protected function _getFromSettings($options) + { + $sql = 'SELECT value FROM settings '; + $where = $options['section'] . $options['subsection'] . $options['name']; // Can't use expression in empty() < PHP 5.5 + if (!empty($where)) { + $sql .= "WHERE section = '{$options['section']}' AND subsection = '{$options['subsection']}'"; + $sql .= empty($options['name']) ? '' : " AND name = '{$options['name']}'"; + } else { + $sql .= "WHERE setting = '{$options['setting']}'"; + } + $sql .= ' ORDER BY section, subsection, name'; + $result = $this->queryOneRow($sql); + + return isset($result['value']) ? $result['value'] : null; + } + + protected function _getFromSites($options) + { + $setting = empty($options['setting']) ? $options['name'] : $options['setting']; + $sql = 'SELECT value FROM site '; + if (!empty($setting)) { + $sql .= "WHERE setting = '$setting'"; + } + + $result = $this->queryOneRow($sql); + + return $result['value']; + } + + protected function _validate(array $fields) + { + ksort($fields); + // Validate settings + $fields['nzbpath'] = Utility::trailingSlash($fields['nzbpath']); + $error = null; + switch (true) { + case ($fields['mediainfopath'] != "" && !is_file($fields['mediainfopath'])): + $error = Settings::ERR_BADMEDIAINFOPATH; + break; + case ($fields['ffmpegpath'] != "" && !is_file($fields['ffmpegpath'])): + $error = Settings::ERR_BADFFMPEGPATH; + break; + case ($fields['unrarpath'] != "" && !is_file($fields['unrarpath'])): + $error = Settings::ERR_BADUNRARPATH; + break; + case (empty($fields['nzbpath'])): + $error = Settings::ERR_BADNZBPATH_UNSET; + break; + case (!file_exists($fields['nzbpath']) || !is_dir($fields['nzbpath'])): + $error = Settings::ERR_BADNZBPATH; + break; + case (!is_readable($fields['nzbpath'])): + $error = Settings::ERR_BADNZBPATH_UNREADABLE; + break; + case ($fields['checkpasswordedrar'] == 1 && !is_file($fields['unrarpath'])): + $error = Settings::ERR_DEEPNOUNRAR; + break; + case ($fields['tmpunrarpath'] != "" && !file_exists($fields['tmpunrarpath'])): + $error = Settings::ERR_BADTMPUNRARPATH; + break; + case ($fields['yydecoderpath'] != "" && + $fields['yydecoderpath'] !== 'simple_php_yenc_decode' && + !file_exists($fields['yydecoderpath'])): + $error = Settings::ERR_BAD_YYDECODER_PATH; + } + + return $error; + } +} + +/* + * Putting procedural stuff inside class scripts like this is BAD. Do not use this as an excuse to do more. + * This is a temporary measure until a proper frontend for cli stuff can be implemented with li3. + */ +if (Utility::isCLI() && isset($argv[1])) { + echo (new Settings())->getSetting($argv[1]); +} \ No newline at end of file diff --git a/lib/copy_this/newznab/db/populate/AniDB.php b/lib/copy_this/newznab/db/populate/AniDB.php index 85122cf8c..5a55132f8 100644 --- a/lib/copy_this/newznab/db/populate/AniDB.php +++ b/lib/copy_this/newznab/db/populate/AniDB.php @@ -3,7 +3,7 @@ namespace newznab\db\populate; require_once NN_LIBS . 'simple_html_dom.php'; -use newznab\db\DB; +use newznab\db\Settings; class AniDB @@ -23,7 +23,7 @@ class AniDB public $imgSavePath; /** - * @var \newznab\db\DB + * @var \newznab\db\Settings */ public $pdo; @@ -69,16 +69,16 @@ class AniDB $options += $defaults; $this->echooutput = ($options['Echo'] && NN_ECHOCLI); - $this->pdo = ($options['Settings'] instanceof DB ? $options['Settings'] : new DB()); + $this->pdo = ($options['Settings'] instanceof Settings ? $options['Settings'] : new Settings()); $s = new \Sites(); $this->site = $s->get(); // $maxanidbprocessed = $this->pdo->getSetting('maxanidbprocessed'); - $anidbupdint = $this->site->intanidbupdate; - $lastupdated = $this->site->lastanidbupdate; + $anidbupdint = $this->pdo->getSetting('intanidbupdate'); + $lastupdated = $this->pdo->getSetting('lastanidbupdate'); $this->imgSavePath = NN_COVERS . 'anime' . DS; - $this->apiKey = $this->site->anidbkey; + $this->apiKey = $this->pdo->getSetting('anidbkey'); $this->updateInterval = (isset($anidbupdint) ? $anidbupdint : '7'); $this->lastUpdate = (isset($lastupdated) ? $lastupdated : '0'); @@ -143,7 +143,7 @@ class AniDB */ private function getAniDbAPI() { - $timestamp = $this->site->banned + 90000; + $timestamp = $this->pdo->getSetting('banned') + 90000; if ($timestamp > time()) { echo "Banned from AniDB lookups until " . date('Y-m-d H:i:s', $timestamp) . "\n"; return false; diff --git a/lib/copy_this/newznab/libraries/Forking.php b/lib/copy_this/newznab/libraries/Forking.php index a986bc76d..955a370be 100644 --- a/lib/copy_this/newznab/libraries/Forking.php +++ b/lib/copy_this/newznab/libraries/Forking.php @@ -1,7 +1,7 @@ _colorCLI = new \ColorCLI(); - $s = new \Sites(); - $this->site = $s->get(); + $this->pdo = new Settings(); $this->register_logging( [0 => $this, 1 => 'logger'], @@ -92,7 +91,7 @@ class Forking extends \fork_daemon $this->work = []; // Init Settings here, as forking causes errors when it's destroyed. - $this->pdo = new DB(); + $this->pdo = new Settings(); // Process extra work that should not be forked and done before forking. $this->processStartWork(); @@ -287,7 +286,7 @@ class Forking extends \fork_daemon ($this->workTypeOptions[0] === false ? '' : (', ' . $this->workTypeOptions[0] . ' AS max')) ) ); - return $this->site->backfillthreads; + return $this->pdo->getSetting('backfillthreads'); } public function backFillChildWorker($groups, $identifier = '') @@ -308,7 +307,7 @@ class Forking extends \fork_daemon $this->register_child_run([0 => $this, 1 => 'safeBackfillChildWorker']); $run = $this->pdo->query("SELECT (SELECT value FROM tmux WHERE setting = 'backfill_qty') AS qty, (SELECT value FROM tmux WHERE setting = 'backfill') AS backfill, (SELECT value FROM tmux WHERE setting = 'backfill_order') AS orderby, (SELECT value FROM tmux WHERE setting = 'backfill_days') AS days, (SELECT value FROM site WHERE setting = 'maxmssgs') AS maxmsgs"); - $threads = $this->site->backfillthreads; + $threads = $this->pdo->getSetting('backfillthreads'); $orderby = "ORDER BY a.last_record ASC"; switch ((int)$run[0]['orderby']) { @@ -337,7 +336,7 @@ class Forking extends \fork_daemon if ($run[0]['days'] == 1) { $backfilldays = "backfill_target"; } elseif ($run[0]['days'] == 2) { - $backfilldays = round(abs(strtotime(date("Y-m-d")) - strtotime($this->site->safebackfilldate)) / 86400);; + $backfilldays = round(abs(strtotime(date("Y-m-d")) - strtotime($this->pdo->getSetting('safebackfilldate'))) / 86400);; } $data = $this->pdo->queryOneRow( @@ -406,7 +405,7 @@ class Forking extends \fork_daemon $this->workTypeOptions[0] ) ); - return $this->site->binarythreads; + return $this->pdo->getSetting('binarythreads'); } public function binariesChildWorker($groups, $identifier = '') @@ -425,8 +424,8 @@ class Forking extends \fork_daemon { $this->register_child_run([0 => $this, 1 => 'safeBinariesChildWorker']); - $maxmssgs = $this->site->maxmssgs; - $threads = $this->site->binarythreads; + $maxmssgs = $this->pdo->getSetting('maxmssgs'); + $threads = $this->pdo->getSetting('binarythreads'); $groups = $this->pdo->query("SELECT g.name AS groupname, g.last_record AS our_last, a.last_record AS their_last FROM groups g INNER JOIN shortgroups a ON g.active = 1 AND g.name = a.name ORDER BY a.last_record DESC"); @@ -494,8 +493,8 @@ class Forking extends \fork_daemon $select = "DISTINCT LEFT(r.guid, 1) AS guidchar, COUNT(*) AS count"; - $threads = $this->site->fixnamethreads; - $maxperrun = $this->site->fixnamesperrun; + $threads = $this->pdo->getSetting('fixnamethreads'); + $maxperrun = $this->pdo->getSetting('fixnamesperrun'); if ($threads > 16) { $threads = 16; @@ -572,7 +571,7 @@ class Forking extends \fork_daemon { $this->register_child_run([0 => $this, 1 => 'releasesChildWorker']); - $this->tablePerGroup = ($this->site->tablepergroup == 1 ? true : false); + $this->tablePerGroup = ($this->pdo->getSetting('tablepergroup') == 1 ? true : false); if ($this->tablePerGroup === true) { $groups = $this->pdo->queryDirect('SELECT id FROM groups WHERE (active = 1 OR backfill = 1)'); @@ -588,7 +587,7 @@ class Forking extends \fork_daemon $this->work = $this->pdo->query('SELECT name FROM groups WHERE (active = 1 OR backfill = 1)'); } - return $this->site->releasethreads; + return $this->pdo->getSetting('releasethreads'); } public function releasesChildWorker($groups, $identifier = '') @@ -648,10 +647,10 @@ class Forking extends \fork_daemon private function checkProcessAdditional() { $this->ppAddMinSize = - ($this->site->minsizetopostprocess != '') ? (int)$this->site->minsizetopostprocess : 1; + ($this->pdo->getSetting('minsizetopostprocess') != '') ? (int)$this->pdo->getSetting('minsizetopostprocess') : 1; $this->ppAddMinSize = ($this->ppAddMinSize > 0 ? ('AND r.size > ' . ($this->ppAddMinSize * 1048576)) : ''); $this->ppAddMaxSize = - ($this->site->maxsizetopostprocess != '') ? (int)$this->site->maxsizetopostprocess : 100; + ($this->pdo->getSetting('maxsizetopostprocess') != '') ? (int)$this->pdo->getSetting('maxsizetopostprocess') : 100; $this->ppAddMaxSize = ($this->ppAddMaxSize > 0 ? ('AND r.size < ' . ($this->ppAddMaxSize * 1073741824)) : ''); return ( $this->pdo->queryOneRow( @@ -696,7 +695,7 @@ class Forking extends \fork_daemon $this->ppAddMinSize ) ); - $maxProcesses = $this->site->postthreads; + $maxProcesses = $this->pdo->getSetting('postthreads'); } return $maxProcesses; } @@ -709,7 +708,7 @@ class Forking extends \fork_daemon */ private function checkProcessNfo() { - if ($this->site->lookupnfo == 1) { + if ($this->pdo->getSetting('lookupnfo') == 1) { $this->nfoQueryString = \Info::NfoQueryString($this->pdo); return ( $this->pdo->queryOneRow( @@ -739,7 +738,7 @@ class Forking extends \fork_daemon $this->nfoQueryString ) ); - $maxProcesses = $this->site->nfothreads; + $maxProcesses = $this->pdo->getSetting('nfothreads'); } return $maxProcesses; } @@ -750,7 +749,7 @@ class Forking extends \fork_daemon */ private function checkProcessMovies() { - if ($this->site->lookupimdb > 0) { + if ($this->pdo->getSetting('lookupimdb') > 0) { return ( $this->pdo->queryOneRow( sprintf(' @@ -762,7 +761,7 @@ class Forking extends \fork_daemon %s %s LIMIT 1', \NZB::NZB_ADDED, - ($this->site->lookupimdb == 2 ? 'AND isrenamed = 1' : ''), + ($this->pdo->getSetting('lookupimdb') == 2 ? 'AND isrenamed = 1' : ''), ($this->ppRenamedOnly ? 'AND isrenamed = 1' : '') ) ) === false ? false : true @@ -789,11 +788,11 @@ class Forking extends \fork_daemon LIMIT 16', ($this->ppRenamedOnly ? 2 : 1), \NZB::NZB_ADDED, - ($this->site->lookupimdb == 2 ? 'AND isrenamed = 1' : ''), + ($this->pdo->getSetting('lookupimdb') == 2 ? 'AND isrenamed = 1' : ''), ($this->ppRenamedOnly ? 'AND isrenamed = 1' : '') ) ); - $maxProcesses = $this->site->postthreadsnon; + $maxProcesses = $this->pdo->getSetting('postthreadsnon'); } return $maxProcesses; } @@ -804,7 +803,7 @@ class Forking extends \fork_daemon */ private function checkProcessTV() { - if ($this->site->lookuptvrage > 0) { + if ($this->pdo->getSetting('lookuptvrage') > 0) { return ( $this->pdo->queryOneRow( sprintf(' @@ -817,7 +816,7 @@ class Forking extends \fork_daemon %s %s LIMIT 1', \NZB::NZB_ADDED, - ($this->site->lookuptvrage == 2 ? 'AND isrenamed = 1' : ''), + ($this->pdo->getSetting('lookuptvrage') == 2 ? 'AND isrenamed = 1' : ''), ($this->ppRenamedOnly ? 'AND isrenamed = 1' : '') ) ) === false ? false : true @@ -845,11 +844,11 @@ class Forking extends \fork_daemon LIMIT 16', ($this->ppRenamedOnly ? 2 : 1), \NZB::NZB_ADDED, - ($this->site->lookuptvrage == 2 ? 'AND isrenamed = 1' : ''), + ($this->pdo->getSetting('lookuptvrage') == 2 ? 'AND isrenamed = 1' : ''), ($this->ppRenamedOnly ? 'AND isrenamed = 1' : '') ) ); - $maxProcesses = $this->site->postthreadsnon; + $maxProcesses = $this->pdo->getSetting('postthreadsnon'); } return $maxProcesses; } @@ -864,7 +863,7 @@ class Forking extends \fork_daemon $sharing = $this->pdo->queryOneRow('SELECT enabled FROM sharing'); if ($sharing !== false && $sharing['enabled'] == 1) { $nntp = new \NNTP(['Settings' => $this->pdo]); - if (($this->site->alternate_nntp == 1 ? $nntp->doConnect(true, true) : $nntp->doConnect()) === true) { + if (($this->pdo->getSetting('alternate_nntp') == 1 ? $nntp->doConnect(true, true) : $nntp->doConnect()) === true) { (new PProcess(['Settings' => $this->pdo, 'ColorCLI' => $this->_colorCLI]))->processSharing($nntp); } return true; @@ -907,7 +906,7 @@ class Forking extends \fork_daemon \RequestID::REQID_UPROC ) ); - return $this->site->reqidthreads; + return $this->pdo->getSetting('reqidthreads'); } public function requestIDChildWorker($groups, $identifier = '') @@ -927,7 +926,7 @@ class Forking extends \fork_daemon { $this->register_child_run([0 => $this, 1 => 'updatePerGroupChildWorker']); $this->work = $this->pdo->query('SELECT id FROM groups WHERE (active = 1 OR backfill = 1)'); - return $this->site->releasethreads; + return $this->pdo->getSetting('releasethreads'); } public function updatePerGroupChildWorker($groups, $identifier = '') @@ -1083,7 +1082,7 @@ class Forking extends \fork_daemon private $safeBackfillGroup = ''; /** - * @var \newznab\db\DB + * @var \newznab\db\Settings */ public $pdo; diff --git a/lib/copy_this/newznab/libraries/ForkingImportNZB.php b/lib/copy_this/newznab/libraries/ForkingImportNZB.php index 96ba8eb04..cd714f36e 100644 --- a/lib/copy_this/newznab/libraries/ForkingImportNZB.php +++ b/lib/copy_this/newznab/libraries/ForkingImportNZB.php @@ -1,7 +1,7 @@ new DB(), + 'settings' => new Settings(), ]; $options += $defaults; diff --git a/lib/copy_this/newznab/processing/PProcess.php b/lib/copy_this/newznab/processing/PProcess.php index 559aeda6b..4490ceafd 100644 --- a/lib/copy_this/newznab/processing/PProcess.php +++ b/lib/copy_this/newznab/processing/PProcess.php @@ -1,7 +1,7 @@ site = $s->get(); //\\ Class instances. - $this->pdo = (($options['Settings'] instanceof DB) ? $options['Settings'] : new DB()); + $this->pdo = (($options['Settings'] instanceof Settings) ? $options['Settings'] : new Settings()); $this->groups = (($options['Groups'] instanceof \Groups) ? $options['Groups'] : new \Groups()); $this->_par2Info = new \Par2Info(); $this->debugging = ($options['Logger'] instanceof \Logger ? $options['Logger'] : new \Logger(['ColorCLI' => $this->pdo->log])); @@ -99,8 +99,8 @@ class PProcess //\\ //\\ Site settings. - $this->addpar2 = ($this->site->addpar2 == 0) ? false : true; - $this->alternateNNTP = ($this->site->alternate_nntp == 1 ? true : false); + $this->addpar2 = ($this->pdo->getSetting('addpar2') == 0) ? false : true; + $this->alternateNNTP = ($this->pdo->getSetting('alternate_nntp') == 1 ? true : false); //\\ } @@ -135,7 +135,7 @@ class PProcess */ public function processAnime() { - if ($this->site->lookupanidb != 0) { + if ($this->pdo->getSetting('lookupanidb') != 0) { (new AniDB(['Echo' => $this->echooutput, 'Settings' => $this->pdo]))->processAnimeReleases(); } } @@ -147,7 +147,7 @@ class PProcess */ public function processBooks() { - if ($this->site->lookupbooks != 0) { + if ($this->pdo->getSetting('lookupbooks') != 0) { (new \Books(['Echo' => $this->echooutput, 'Settings' => $this->pdo, ]))->processBookReleases(); } } @@ -159,7 +159,7 @@ class PProcess */ public function processConsoles() { - if ($this->site->lookupgames != 0) { + if ($this->pdo->getSetting('lookupgames') != 0) { (new \Konsole(['Settings' => $this->pdo, 'Echo' => $this->echooutput]))->processConsoleReleases(); } } @@ -171,7 +171,7 @@ class PProcess */ public function processGames() { - if ($this->site->lookupgames != 0) { + if ($this->pdo->getSetting('lookupgames') != 0) { (new \Games(['Echo' => $this->echooutput, 'Settings' => $this->pdo]))->processGamesReleases(); } } @@ -188,7 +188,7 @@ class PProcess */ public function processMovies($groupID = '', $guidChar = '', $processMovies = '') { - $processMovies = (is_numeric($processMovies) ? $processMovies : $this->site->lookupimdb); + $processMovies = (is_numeric($processMovies) ? $processMovies : $this->pdo->getSetting('lookupimdb')); if ($processMovies > 0) { (new \Film(['Echo' => $this->echooutput, 'Settings' => $this->pdo]))->processMovieReleases($groupID, $guidChar, $processMovies); } @@ -201,7 +201,7 @@ class PProcess */ public function processMusic() { - if ($this->site->lookupmusic != 0) { + if ($this->pdo->getSetting('lookupmusic') != 0) { (new \Musik(['Echo' => $this->echooutput, 'Settings' => $this->pdo]))->processMusicReleases(); } } @@ -217,8 +217,8 @@ class PProcess */ public function processNfos(&$nntp, $groupID = '', $guidChar = '') { - if ($this->site->lookupnfo == 1) { - $this->Nfo->processNfoFiles($nntp, $groupID, $guidChar, (int)$this->site->lookupimdb, (int)$this->site->lookuptvrage); + if ($this->pdo->getSetting('lookupnfo') == 1) { + $this->Nfo->processNfoFiles($nntp, $groupID, $guidChar, (int)$this->pdo->getSetting('lookupimdb'), (int)$this->pdo->getSetting('lookuptvrage')); } } @@ -265,7 +265,7 @@ class PProcess */ public function processTv($groupID = '', $guidChar = '', $processTV = '') { - $processTV = (is_numeric($processTV) ? $processTV : $this->site->lookuptvrage); + $processTV = (is_numeric($processTV) ? $processTV : $this->pdo->getSetting('lookuptvrage')); if ($processTV > 0) { (new \TvAnger(['Echo' => $this->echooutput, 'Settings' => $this->pdo]))->processTvReleases($groupID, $guidChar, $processTV); } @@ -273,7 +273,7 @@ class PProcess public function processTvDB() { - if ($this->site->lookupthetvdb == 1) + if ($this->pdo->getSetting('lookupthetvdb') == 1) { $thetvdb = new \TheTVDB($this->echooutput); $thetvdb->processReleases(); @@ -285,7 +285,7 @@ class PProcess */ public function processXXX() { - if ($this->site->lookupxxx == 1) { + if ($this->pdo->getSetting('lookupxxx') == 1) { (new \XXX(['Echo' => $this->echooutput, 'Settings' => $this->pdo]))->processXXXReleases(); } } diff --git a/lib/copy_this/newznab/processing/ProcessReleases.php b/lib/copy_this/newznab/processing/ProcessReleases.php index 93840e46d..05923710a 100644 --- a/lib/copy_this/newznab/processing/ProcessReleases.php +++ b/lib/copy_this/newznab/processing/ProcessReleases.php @@ -1,7 +1,7 @@ echoCLI = ($options['Echo'] && NN_ECHOCLI); - $this->pdo = ($options['Settings'] instanceof DB ? $options['Settings'] : new DB()); + $this->pdo = ($options['Settings'] instanceof Settings ? $options['Settings'] : new Settings()); $this->consoleTools = ($options['ConsoleTools'] instanceof \ConsoleTools ? $options['ConsoleTools'] : new \ConsoleTools(['ColorCLI' => $this->pdo->log])); $this->groups = ($options['Groups'] instanceof \Groups ? $options['Groups'] : new \Groups(['Settings' => $this->pdo])); $this->nzb = ($options['NZB'] instanceof \NZB ? $options['NZB'] : new \NZB($this->pdo)); @@ -116,12 +116,12 @@ class ProcessReleases $s = new \Sites(); $this->site = $s ->get(); - $this->tablePerGroup = ($this->site->tablepergroup == 0 ? false : true); - $this->collectionDelayTime = ($this->site->delaytime!= '' ? (int)$this->site->delaytime : 2); - $this->crossPostTime = ($this->site->crossposttime!= '' ? (int)$this->site->crossposttime : 2); - $this->releaseCreationLimit = ($this->site->maxnzbsprocessed != '' ? (int)$this->site->maxnzbsprocessed : 1000); - $this->completion = ($this->site->completionpercent != '' ? (int)$this->site->completionpercent : 0); - $this->processRequestIDs = (int)$this->site->lookup_reqids; + $this->tablePerGroup = ($this->pdo->getSetting('tablepergroup') == 0 ? false : true); + $this->collectionDelayTime = ($this->pdo->getSetting('delaytime') != '' ? (int)$this->pdo->getSetting('delaytime') : 2); + $this->crossPostTime = ($this->pdo->getSetting('crossposttime') != '' ? (int)$this->pdo->getSetting('crossposttime') : 2); + $this->releaseCreationLimit = ($this->pdo->getSetting('maxnzbsprocessed') != '' ? (int)$this->pdo->getSetting('maxnzbsprocessed') : 1000); + $this->completion = ($this->pdo->getSetting('completionpercent') != '' ? (int)$this->pdo->getSetting('completionpercent') : 0); + $this->processRequestIDs = (int)$this->pdo->getSetting('lookup_reqids'); if ($this->completion > 100) { $this->completion = 100; echo $this->pdo->log->error(PHP_EOL . 'You have an invalid setting for completion. It must be lower than 100.'); @@ -154,9 +154,9 @@ class ProcessReleases $this->pdo->log->doEcho($this->pdo->log->header("Starting release update process (" . date('Y-m-d H:i:s') . ")"), true); } - if (!file_exists($this->site->nzbpath)) { + if (!file_exists($this->pdo->getSetting('nzbpath'))) { if ($this->echoCLI) { - $this->pdo->log->doEcho($this->pdo->log->error('Bad or missing nzb directory - ' . $this->site->nzbpath), true); + $this->pdo->log->doEcho($this->pdo->log->error('Bad or missing nzb directory - ' . $this->pdo->getSetting('nzbpath')), true); } return 0; @@ -393,9 +393,9 @@ class ProcessReleases $minSizeDeleted = $maxSizeDeleted = $minFilesDeleted = 0; - $maxSizeSetting = $this->site->maxsizetoformrelease; - $minSizeSetting = $this->site->minsizetoformrelease; - $minFilesSetting = $this->site->minfilestoformrelease; + $maxSizeSetting = $this->pdo->getSetting('maxsizetoformrelease'); + $minSizeSetting = $this->pdo->getSetting('minsizetoformrelease'); + $minFilesSetting = $this->pdo->getSetting('minfilestoformrelease'); foreach ($groupIDs as $groupID) { if ($this->pdo->queryOneRow( @@ -721,7 +721,7 @@ class ProcessReleases */ public function processRequestIDs($groupID = '', $limit = 5000, $local = true) { - if ($local === false && $this->site->lookup_reqids == 0) { + if ($local === false && $this->pdo->getSetting('lookup_reqids') == 0) { return; } @@ -852,7 +852,7 @@ class ProcessReleases sprintf( 'DELETE FROM %s WHERE dateadded < (NOW() - INTERVAL %d HOUR) %s', $group['cname'], - $this->site->rawretentiondays, + $this->pdo->getSetting('rawretentiondays'), (!empty($groupID) && $this->tablePerGroup === false ? ' AND group_id = ' . $groupID : '') ) ); @@ -1028,9 +1028,9 @@ class ProcessReleases $groupIDs = [['id' => $groupID]]; } - $maxSizeSetting = $this->site->maxsizetoformrelease; - $minSizeSetting = $this->site->minsizetoformrelease; - $minFilesSetting = $this->site->minfilestoformrelease; + $maxSizeSetting = $this->pdo->getSetting('maxsizetoformrelease'); + $minSizeSetting = $this->pdo->getSetting('minsizetoformrelease'); + $minFilesSetting = $this->pdo->getSetting('minfilestoformrelease'); foreach ($groupIDs as $groupID) { $releases = $this->pdo->queryDirect( @@ -1127,11 +1127,11 @@ class ProcessReleases } // Releases past retention. - if ($this->site->releaseretentiondays != 0) { + if ($this->pdo->getSetting('releaseretentiondays') != 0) { $releases = $this->pdo->queryDirect( sprintf( 'SELECT id, guid FROM releases WHERE postdate < (NOW() - INTERVAL %d DAY)', - $this->site->releaseretentiondays + $this->pdo->getSetting('releaseretentiondays') ) ); if ($releases instanceof \Traversable) { @@ -1143,7 +1143,7 @@ class ProcessReleases } // Passworded releases. - if ($this->site->deletepasswordedrelease == 1) { + if ($this->pdo->getSetting('deletepasswordedrelease') == 1) { $releases = $this->pdo->queryDirect( sprintf( 'SELECT id, guid FROM releases WHERE passwordstatus = %d', @@ -1159,7 +1159,7 @@ class ProcessReleases } // Possibly passworded releases. - if ($this->site->deletepossiblerelease == 1) { + if ($this->pdo->getSetting('deletepossiblerelease') == 1) { $releases = $this->pdo->queryDirect( sprintf( 'SELECT id, guid FROM releases WHERE passwordstatus = %d', @@ -1277,7 +1277,7 @@ class ProcessReleases } // Misc other. - if ($this->site->miscotherretentionhours > 0) { + if ($this->pdo->getSetting('miscotherretentionhours') > 0) { $releases = $this->pdo->queryDirect( sprintf(' SELECT id, guid @@ -1285,7 +1285,7 @@ class ProcessReleases WHERE categoryid = %d AND adddate <= NOW() - INTERVAL %d HOUR', \Category::CAT_MISC_OTHER, - $this->site->miscotherretentionhours + $this->pdo->getSetting('miscotherretentionhours') ) ); if ($releases instanceof \Traversable) { @@ -1297,7 +1297,7 @@ class ProcessReleases } // Misc hashed. - if ($this->site->mischashedretentionhours > 0) { + if ($this->pdo->getSetting('mischashedretentionhours') > 0) { $releases = $this->pdo->queryDirect( sprintf(' SELECT id, guid @@ -1305,7 +1305,7 @@ class ProcessReleases WHERE categoryid = %d AND adddate <= NOW() - INTERVAL %d HOUR', \Category::CAT_MISC_HASHED, - $this->site->mischashedretentionhours + $this->pdo->getSetting('mischashedretentionhours') ) ); if ($releases instanceof \Traversable) { diff --git a/lib/copy_this/newznab/processing/post/AniDB.php b/lib/copy_this/newznab/processing/post/AniDB.php index 3dd00be40..a2faa6c05 100644 --- a/lib/copy_this/newznab/processing/post/AniDB.php +++ b/lib/copy_this/newznab/processing/post/AniDB.php @@ -1,7 +1,7 @@ echooutput = ($options['Echo'] && NN_ECHOCLI); - $this->pdo = ($options['Settings'] instanceof DB ? $options['Settings'] : new DB()); + $this->pdo = ($options['Settings'] instanceof Settings ? $options['Settings'] : new Settings()); $s = new \Sites(); $this->site = $s->get(); - $qty = $this->site->maxanidbprocessed; + $qty = $this->pdo->getSetting('maxanidbprocessed'); $this->aniqty = !empty($qty) ? $qty : 100; $this->status = 'NULL'; diff --git a/lib/copy_this/newznab/processing/post/ProcessAdditional.php b/lib/copy_this/newznab/processing/post/ProcessAdditional.php index 47a8f9811..e22c3e445 100644 --- a/lib/copy_this/newznab/processing/post/ProcessAdditional.php +++ b/lib/copy_this/newznab/processing/post/ProcessAdditional.php @@ -4,7 +4,7 @@ namespace newznab\processing\post; require_once NN_LIBS . 'rarinfo/archiveinfo.php'; require_once NN_LIBS . 'rarinfo/par2info.php'; -use newznab\db\DB; +use newznab\db\Settings; use newznab\utility\Utility; class ProcessAdditional @@ -17,7 +17,7 @@ class ProcessAdditional const maxCompressedFilesToCheck = 20; /** - * @var \newznab\db\DB + * @var \newznab\db\Settings */ public $pdo; @@ -284,7 +284,7 @@ class ProcessAdditional $this->_echoCLI = ($options['Echo'] && NN_ECHOCLI && (strtolower(PHP_SAPI) === 'cli')); $this->_echoDebug = NN_DEBUG; - $this->pdo = ($options['Settings'] instanceof DB ? $options['Settings'] : new DB()); + $this->pdo = ($options['Settings'] instanceof Settings ? $options['Settings'] : new Settings()); $this->_nntp = ($options['NNTP'] instanceof \NNTP ? $options['NNTP'] : new \NNTP(['Echo' => $this->_echoCLI, 'Settings' => $this->pdo])); $this->_nzb = ($options['NZB'] instanceof \NZB ? $options['NZB'] : new \NZB($this->pdo)); @@ -301,33 +301,33 @@ class ProcessAdditional $s = new \Sites(); $this->site = $s->get(); - $this->_innerFileBlacklist = ($this->site->innerfileblacklist == '' ? false : $this->site->innerfileblacklist); - $this->_maxNestedLevels = ($this->site->maxnestedlevels == 0 ? 3 : $this->site->maxnestedlevels); - $this->_extractUsingRarInfo = ($this->site->extractusingrarinfo == 0 ? false : true); + $this->_innerFileBlacklist = ($this->pdo->getSetting('innerfileblacklist') == '' ? false : $this->pdo->getSetting('innerfileblacklist')); + $this->_maxNestedLevels = ($this->pdo->getSetting('maxnestedlevels') == 0 ? 3 : $this->pdo->getSetting('maxnestedlevels')); + $this->_extractUsingRarInfo = ($this->pdo->getSetting('extractusingrarinfo') == 0 ? false : true); $this->_7zipPath = false; $this->_unrarPath = false; // Pass the binary extractors to ArchiveInfo. $clients = array(); - if ($this->site->unrarpath != '') { - $clients += array(\ArchiveInfo::TYPE_RAR => $this->site->unrarpath); - $this->_unrarPath = $this->site->unrarpath; + if ($this->pdo->getSetting('unrarpath') != '') { + $clients += array(\ArchiveInfo::TYPE_RAR => $this->pdo->getSetting('unrarpath')); + $this->_unrarPath = $this->pdo->getSetting('unrarpath'); } - if ($this->site->zippath != '') { - $clients += array(\ArchiveInfo::TYPE_ZIP => $this->site->zippath); - $this->_7zipPath = $this->site->zippath; + if ($this->pdo->getSetting('zippath') != '') { + $clients += array(\ArchiveInfo::TYPE_ZIP => $this->pdo->getSetting('zippath')); + $this->_7zipPath = $this->pdo->getSetting('zippath'); } $this->_archiveInfo->setExternalClients($clients); $this->_hasGNUFile = (Utility::hasCommand('file') === true ? true : false); $this->_killString = '"'; - if ($this->site->timeoutpath != '' && $this->site->timeoutseconds > 0) { + if ($this->pdo->getSetting('timeoutpath') != '' && $this->pdo->getSetting('timeoutseconds') > 0) { $this->_killString = ( - '"' . $this->site->timeoutpath . + '"' . $this->pdo->getSetting('timeoutpath') . '" --foreground --signal=KILL ' . - $this->site->timeoutseconds . ' "' + $this->pdo->getSetting('timeoutseconds') . ' "' ); } @@ -335,52 +335,52 @@ class ProcessAdditional // Maximum amount of releases to fetch per run. $this->_queryLimit = - ($this->site->maxaddprocessed != '') ? (int)$this->site->maxaddprocessed : 25; + ($this->pdo->getSetting('maxaddprocessed') != '') ? (int)$this->pdo->getSetting('maxaddprocessed') : 25; // Maximum message id's to download per file type in the NZB (video, jpg, etc). $this->_segmentsToDownload = - ($this->site->segmentstodownload != '') ? (int)$this->site->segmentstodownload : 2; + ($this->pdo->getSetting('segmentstodownload') != '') ? (int)$this->pdo->getSetting('segmentstodownload') : 2; // Maximum message id's to download for a RAR file. $this->_maximumRarSegments = - ($this->site->maxpartsprocessed != '') ? (int)$this->site->maxpartsprocessed : 3; + ($this->pdo->getSetting('maxpartsprocessed') != '') ? (int)$this->pdo->getSetting('maxpartsprocessed') : 3; // Maximum RAR files to check for a password before stopping. $this->_maximumRarPasswordChecks = - ($this->site->passchkattempts != '') ? (int)$this->site->passchkattempts : 1; + ($this->pdo->getSetting('passchkattempts') != '') ? (int)$this->pdo->getSetting('passchkattempts') : 1; $this->_maximumRarPasswordChecks = ($this->_maximumRarPasswordChecks < 1 ? 1 : $this->_maximumRarPasswordChecks); // Maximum size of releases in GB. $this->_maxSize = - ($this->site->maxsizetopostprocess != '') ? (int)$this->site->maxsizetopostprocess : 100; + ($this->pdo->getSetting('maxsizetopostprocess') != '') ? (int)$this->pdo->getSetting('maxsizetopostprocess') : 100; $this->_maxSize = ($this->_maxSize > 0 ? ('AND r.size < ' . ($this->_maxSize * 1073741824)) : ''); // Minimum size of releases in MB. $this->_minSize = - ($this->site->minsizetopostprocess != '') ? (int)$this->site->minsizetopostprocess : 100; + ($this->pdo->getSetting('minsizetopostprocess') != '') ? (int)$this->pdo->getSetting('minsizetopostprocess') : 100; $this->_minSize = ($this->_minSize > 0 ? ('AND r.size > ' . ($this->_minSize * 1048576)) : ''); // Use the alternate NNTP provider for downloading Message-ID's ? - $this->_alternateNNTP = ($this->site->alternate_nntp == 1 ? true : false); + $this->_alternateNNTP = ($this->pdo->getSetting('alternate_nntp') == 1 ? true : false); - $this->_ffMPEGDuration = ($this->site->ffmpeg_duration != '') ? (int)$this->site->ffmpeg_duration : 5; + $this->_ffMPEGDuration = ($this->pdo->getSetting('ffmpeg_duration') != '') ? (int)$this->pdo->getSetting('ffmpeg_duration') : 5; - $this->_addPAR2Files = ($this->site->addpar2 === '0') ? false : true; + $this->_addPAR2Files = ($this->pdo->getSetting('addpar2') === '0') ? false : true; - if (!$this->site->ffmpegpath) { + if (!$this->pdo->getSetting('ffmpegpath')) { $this->_processAudioSample = $this->_processThumbnails = $this->_processVideo = false; } else { - $this->_processAudioSample = ($this->site->processaudiosample == 0) ? false : true; - $this->_processThumbnails = ($this->site->processthumbnails == 0 ? false : true); - $this->_processVideo = ($this->site->processvideos == 0) ? false : true; + $this->_processAudioSample = ($this->pdo->getSetting('processaudiosample') == 0) ? false : true; + $this->_processThumbnails = ($this->pdo->getSetting('processthumbnails') == 0 ? false : true); + $this->_processVideo = ($this->pdo->getSetting('processvideos') == 0) ? false : true; } - $this->_processJPGSample = ($this->site->processjpg == 0) ? false : true; - $this->_processMediaInfo = ($this->site->mediainfopath == '') ? false : true; + $this->_processJPGSample = ($this->pdo->getSetting('processjpg') == 0) ? false : true; + $this->_processMediaInfo = ($this->pdo->getSetting('mediainfopath') == '') ? false : true; $this->_processAudioInfo = $this->_processMediaInfo; $this->_processPasswords = ( - ((($this->site->checkpasswordedrar == 0) ? false : true)) && - (($this->site->unrarpath == '') ? false : true) + ((($this->pdo->getSetting('checkpasswordedrar') == 0) ? false : true)) && + (($this->pdo->getSetting('unrarpath') == '') ? false : true) ); $this->_audioSavePath = NN_COVERS . 'audiosample' . DS; @@ -444,7 +444,7 @@ class ProcessAdditional protected function _setMainTempPath(&$groupID = '', &$guidChar) { // Set up the temporary files folder location. - $this->_mainTmpPath = (string)$this->site->tmpunrarpath; + $this->_mainTmpPath = (string)$this->pdo->getSetting('tmpunrarpath'); // Check if it ends with a dir separator. if (!preg_match('/[\/\\\\]$/', $this->_mainTmpPath)) { @@ -1633,7 +1633,7 @@ class ProcessAdditional // Get the media info for the file. $xmlArray = Utility::runCmd( - $this->_killString . $this->site->mediainfopath . '" --Output=XML "' . $fileLocation . '"' + $this->_killString . $this->pdo->getSetting('mediainfopath') . '" --Output=XML "' . $fileLocation . '"' ); if (is_array($xmlArray)) { @@ -1721,7 +1721,7 @@ class ProcessAdditional // Create an audio sample. Utility::runCmd( $this->_killString . - $this->site->ffmpegpath . + $this->pdo->getSetting('ffmpegpath') . '" -t 30 -i "' . $fileLocation . '" -acodec libvorbis -loglevel quiet -y "' . @@ -1824,7 +1824,7 @@ class ProcessAdditional // Get the real duration of the file. $time = Utility::runCmd( $this->_killString . - $this->site->ffmpegpath . + $this->pdo->getSetting('ffmpegpath') . '" -i "' . $videoLocation . '" -vcodec copy -y 2>&1 "' . $tmpVideo . '"', @@ -1870,7 +1870,7 @@ class ProcessAdditional // Create the image. Utility::runCmd( $this->_killString . - $this->site->ffmpegpath . + $this->pdo->getSetting('ffmpegpath') . '" -i "' . $fileLocation . '" -ss ' . ($time === '' ? '00:00:03.00' : $time) . @@ -1961,7 +1961,7 @@ class ProcessAdditional // Try to get the sample (from the end instead of the start). Utility::runCmd( $this->_killString . - $this->site->ffmpegpath . + $this->pdo->getSetting('ffmpegpath') . '" -i "' . $fileLocation . '" -ss ' . $lowestLength . @@ -1978,7 +1978,7 @@ class ProcessAdditional // If longer than 60 or we could not get the video length, run the old way. Utility::runCmd( $this->_killString . - $this->site->ffmpegpath . + $this->pdo->getSetting('ffmpegpath') . '" -i "' . $fileLocation . '" -vcodec libtheora -filter:v scale=320:-1 -t ' . @@ -2052,7 +2052,7 @@ class ProcessAdditional // Run media info on it. $xmlArray = Utility::runCmd( - $this->_killString . $this->site->mediainfopath . '" --Output=XML "' . $fileLocation . '"' + $this->_killString . $this->pdo->getSetting('mediainfopath') . '" --Output=XML "' . $fileLocation . '"' ); // Check if we got it. diff --git a/lib/copy_this/newznab/utility/Git.php b/lib/copy_this/newznab/utility/Git.php new file mode 100644 index 000000000..8fa1b61be --- /dev/null +++ b/lib/copy_this/newznab/utility/Git.php @@ -0,0 +1,124 @@ +. + * @author niel + * @copyright 2014 nZEDb + */ +namespace newznab\utility; + +require_once NN_LIBS . 'Git.php' . DS . 'Git.php'; + +/** + * Class Git - Wrapper for various git operations. + * @package newznab\utility + */ +class Git extends \GitRepo +{ + private $branch; + private $mainBranches = ['dev', 'dev-regexless', 'master']; + + public function __construct(array $options = []) + { + $defaults = [ + 'create' => false, + 'initialise' => false, + 'filepath' => NN_ROOT, + ]; + $options += $defaults; + + parent::__construct($options['filepath'], $options['create'], $options['initialise']); + $this->branch = parent::active_branch(); + } + + /** + * Return the number of commits made to repo + */ + public function commits() + { + $count = 0; + $log = explode("\n", $this->log()); + foreach ($log as $line) { + if (preg_match('#^commit#', $line)) { + ++$count; + } + } + return $count; + } + + /** + * @param string $options + * + * @return string + */ + public function describe($options = null) + { + return $this->run("describe $options"); + } + + public function getBranch() + { + return $this->branch; + } + + /** + * @param $gitObject + * + * @return bool + * @throws \Exception + */ + public function isCommited($gitObject) + { + $cmd = "cat-file -e $gitObject"; + + try { + $result = $this->run($cmd); + } catch (\Exception $e) { + $message = explode("\n", $e->getMessage()); + if ($message[0] === "fatal: Not a valid object name $gitObject") { + $result = false; + } else { + throw new \Exception($message); + } + } + return ($result === ''); + } + + public function log($options = null) + { + return $this->run("log $options"); + } + + public function mainBranches() + { + return $this->mainBranches; + } + + /** + * @param string $options + * + * @return string + */ + public function tag($options = null) + { + return $this->run("tag $options"); + } + + public function tagLatest() + { + return $this->describe("--tags --abbrev=0 HEAD"); + } +} \ No newline at end of file diff --git a/lib/copy_this/newznab/utility/Utility.php b/lib/copy_this/newznab/utility/Utility.php index 7387af954..d53a94866 100644 --- a/lib/copy_this/newznab/utility/Utility.php +++ b/lib/copy_this/newznab/utility/Utility.php @@ -1,6 +1,9 @@ getValidVersionsFile(); + } + /** * Detect if the command is accessible on the system. * @@ -192,6 +202,29 @@ class Utility return ($gzipped); } + public static function isPatched(Settings $pdo = null) + { + $versions = self::getValidVersionsFile(); + + if (!($pdo instanceof Settings)) { + $pdo = new Settings(); + } + $patch = $pdo->getSetting(['section' => '', 'subsection' => '', 'name' => 'sqlpatch']); + $ver = $versions->versions->sql->file; + + // Check database patch version + if ($patch < $ver) { + $message = "\nYour database is not up to date. Reported patch levels\n Db: $patch\nfile: $ver\nPlease update.\n php " . + NN_ROOT . "cli/update_db.php true\n"; + if (self::isCLI()) { + echo (new ColorCLI())->error($message); + } + throw new \RuntimeException($message); + } + + return true; + } + static public function isWin() { return (strtolower(substr(PHP_OS, 0, 3)) === 'win'); diff --git a/lib/copy_this/newznab/utility/Versions.php b/lib/copy_this/newznab/utility/Versions.php new file mode 100644 index 000000000..8a18eff66 --- /dev/null +++ b/lib/copy_this/newznab/utility/Versions.php @@ -0,0 +1,299 @@ +versions node to make method work shorter. + * @var object SimpleXMLElement + */ + protected $_vers; + + /** + * @var object simpleXMLElement + */ + protected $_xml; + + /** + * Class constructor initialises the SimpleXML object and sets a few properties. + * @param string $filepath Optional filespec for the XML file to use. Will use default otherwise. + * + * @throws \Exception If the XML is invalid. + * @throws \RuntimeException If version file does not exist. + */ + public function __construct($filepath = null) + { + if (empty($filepath)) { + if (defined('NN_VERSIONS')) { + $filepath = NN_VERSIONS; + } + } + + if (!file_exists($filepath)) { + throw new \RuntimeException("Versions file '$filepath' does not exist!'"); + } + $this->_filespec = $filepath; + + $this->out = new ColorCLI(); + $this->git = new Git(); + + $this->getValidVersionsFile(); + } + + public function changes() + { + return $this->_changes; + } + + /** + * Run all checks + * @param boolean $update Whether the XML should be updated by the check. + * @return boolean True if any of the checks actually caused an update (not if it indicated one was needed), flase otherwise + */ + public function checkAll($update = true) + { + $this->checkGitTag($update); + //$this->checkSQLFileLatest($update); + $this->checkSQLDb($update); + $this->checkGitCommit($update); + return $this->hasChanged(); + } + + /** + * Checks the git commit number against the XML's stored value. + * @param boolean $update Whether the XML should be updated by the check. + * @return integer|boolean The new git commit number, or false. + */ + public function checkGitCommit($update = true) + { + // Since Dec 2014 we no longer maintain the git commit count in the XML file, as it is no + // longer used in the code base. + if ((int)$this->_vers->sql->db >= 307) { + return 0; + } + + $count = $this->git->commits(); + if ($this->_vers->git->commit->__toString() < $count || GIT_PRE_COMMIT === true) { + // Allow pre-commit to override the commit number (often branch number is higher than dev's) + if ($update) { + if (GIT_PRE_COMMIT === true) { + // only the pre-commit script is allowed to set the NEXT commit number + $count += 1; + } + if ($count != $this->_vers->git->commit) { + echo $this->out->primary("Updating commit number to {$count}"); + $this->_vers->git->commit = $count; + $this->_changes |= self::UPDATED_GIT_COMMIT; + } + } + return $this->_vers->git->commit; + } + return false; + } + + /** + * Checks the git's latest version tag against the XML's stored value. Version should be + * Major.Minor.Revision (Note commit number is NOT revision) + * @param boolean $update Whether the XML should be updated by the check. + * @return boolean The new git's latest version tag, or false. + */ + public function checkGitTag($update = true) + { + $latest = $this->git->tagLatest(); + $ver = preg_match('#v(\d+\.\d+\.\d+).*#', $latest, $matches) ? $matches[1] : $latest; + + if ($this->git->getBranch() === 'dev') { + if (version_compare($this->_vers->git->tag, '0.0.0', '!=')) { + $this->_vers->git->tag = '0.0.0'; + $this->_changes |= self::UPDATED_GIT_TAG; + } + return $this->_vers->git->tag; + } + + // Check if version file's entry is the same as current branch's tag + if (version_compare($this->_vers->git->tag, $latest, '!=')) { + if ($update) { + echo $this->out->primaryOver("Updating tag version to ") . $this->out->headerOver($latest); + $this->_vers->git->tag = $ver; + $this->_changes |= self::UPDATED_GIT_TAG; + } else { + echo $this->out->primaryOver("Leaving tag version at ") . + $this->out->headerOver($this->_vers->git->tag); + } + return $this->_vers->git->tag; + } else { + echo $this->out->primaryOver("Tag version is ") . $this->out->header($latest); + } + return false; + } + + /** + * Checks the database sqlpatch setting against the XML's stored value. + * + * @param boolean $update Whether the XML should be updated by the check. + * + * @return boolean The new database sqlpatch version, or false. + */ + public function checkSQLDb($update = false) + { + $this->checkSQLFileLatest($update); + + //$settings = new Settings(); + //$setting = $settings->getSetting('sqlpatch'); + + if ($this->_vers->sql->db->__toString() != $this->_vers->sql->file->__toString()) { + if ($update) { + echo $this->out->primaryOver("Updating Db revision to " . $this->_vers->sql->file); + $this->_vers->sql->db = $this->_vers->sql->file->__toString(); + $this->_changes |= self::UPDATED_SQL_DB_PATCH; + } + return $this->_vers->patch->db; + } + return false; + } + + /** + * Checks the numeric value from the last SQL patch file, updating the versions file if desired. + * + * @param bool $update Whether to update the versions file. + * + * @return bool|int False if there is a problem, otherwise the number from the last patch file. + */ + public function checkSQLFileLatest($update = true) + { + $options = [ + 'data' => NN_RES . 'db' . DS . 'schema' . DS . 'data' . DS, + 'ext' => 'sql', + 'path' => NN_RES . 'db' . DS . 'patches' . DS . 'mysql', + 'regex' => + '#^' . Utility::PATH_REGEX . '(?P\d{4})~(?P
\w+)\.sql$#', + 'safe' => true, + ]; + $files = Utility::getDirFiles($options); + natsort($files); + + $last = (preg_match($options['regex'], end($files), $matches)) ? (int)$matches['patch'] : false; + + if ($update) { + if ($last !== false && $this->_vers->sql->file->__toString() != $last) { + echo $this->out->primary("Updating latest patch file to " . $last); + $this->_vers->sql->file = $last; + $this->_changes |= self::UPDATED_SQL_FILE_LAST; + } + + if ($this->_vers->sql->file->__toString() != $last) { + $this->_vers->sql->file = $last; + $this->_changes |= self::UPDATED_SQL_DB_PATCH; + } + } + return $last; + } + + public function getCommit() + { + return $this->_vers->git->commit->__toString(); + } + + public function getGitHookPrecommit() + { + return $this->_vers->git->hooks->precommit->__toString(); + } + + public function getSQLPatchFromDb() + { + return $this->_vers->sql->db->__toString(); + } + + public function getSQLPatchFromFiles() + { + return $this->_vers->sql->file->__toString(); + } + + public function getTagVersion() + { + return $this->_vers->git->tag->__toString(); + } + + public function getValidVersionsFile($filepath = null) + { + $filepath = empty($filepath) ? $this->_filespec : $filepath; + + $temp = libxml_use_internal_errors(true); + $this->_xml = simplexml_load_file($filepath); + libxml_use_internal_errors($temp); + + if ($this->_xml === false) { + if (Utility::isCLI()) { + $this->out->error("Your versions XML file ($filepath) is broken, try updating from git."); + } + throw new \Exception("Failed to open versions XML file '$filepath'"); + } + + if ($this->_xml->count() > 0) { + $vers = $this->_xml->xpath('/newznab/versions'); + + if ($vers[0]->count() == 0) { + $this->out->error("Your versions XML file ({NN_VERSIONS}) does not contain version info, try updating from git."); + throw new \Exception("Failed to find versions node in XML file '$filepath'"); + } else { + $this->out->primary("Your versions XML file ({NN_VERSIONS}) looks okay, continuing."); + $this->_vers = &$this->_xml->versions; + } + } else { + throw new \RuntimeException("No elements in file!\n"); + } + + return $this->_xml; + } + + /** + * Check whether the XML has been changed by one of the methods here. + * @return boolean True if the XML has been changed. + */ + public function hasChanged() + { + return $this->_changes != 0; + } + + public function save() + { + if ($this->hasChanged()) { + $this->_xml->asXML($this->_filespec); + $this->_changes = 0; + } + } +} \ No newline at end of file diff --git a/lib/DB/patches/0001_tmux.sql b/lib/copy_this/resources/patches/0001_tmux.sql similarity index 100% rename from lib/DB/patches/0001_tmux.sql rename to lib/copy_this/resources/patches/0001_tmux.sql diff --git a/lib/DB/patches/0002_tmux.sql b/lib/copy_this/resources/patches/0002_tmux.sql similarity index 100% rename from lib/DB/patches/0002_tmux.sql rename to lib/copy_this/resources/patches/0002_tmux.sql diff --git a/lib/DB/patches/0004_tmux.sql b/lib/copy_this/resources/patches/0004_tmux.sql similarity index 100% rename from lib/DB/patches/0004_tmux.sql rename to lib/copy_this/resources/patches/0004_tmux.sql diff --git a/lib/DB/patches/0005_releases.sql b/lib/copy_this/resources/patches/0005_releases.sql similarity index 100% rename from lib/DB/patches/0005_releases.sql rename to lib/copy_this/resources/patches/0005_releases.sql diff --git a/lib/DB/patches/0006_tmux.sql b/lib/copy_this/resources/patches/0006_tmux.sql similarity index 100% rename from lib/DB/patches/0006_tmux.sql rename to lib/copy_this/resources/patches/0006_tmux.sql diff --git a/lib/DB/patches/0007_releases_tmux.sql b/lib/copy_this/resources/patches/0007_releases_tmux.sql similarity index 100% rename from lib/DB/patches/0007_releases_tmux.sql rename to lib/copy_this/resources/patches/0007_releases_tmux.sql diff --git a/lib/DB/patches/0008_releases.sql b/lib/copy_this/resources/patches/0008_releases.sql similarity index 100% rename from lib/DB/patches/0008_releases.sql rename to lib/copy_this/resources/patches/0008_releases.sql diff --git a/lib/DB/patches/0009_releases.sql b/lib/copy_this/resources/patches/0009_releases.sql similarity index 100% rename from lib/DB/patches/0009_releases.sql rename to lib/copy_this/resources/patches/0009_releases.sql diff --git a/lib/DB/patches/0010_releases.sql b/lib/copy_this/resources/patches/0010_releases.sql similarity index 100% rename from lib/DB/patches/0010_releases.sql rename to lib/copy_this/resources/patches/0010_releases.sql diff --git a/lib/DB/patches/0011_prehash.sql b/lib/copy_this/resources/patches/0011_prehash.sql similarity index 100% rename from lib/DB/patches/0011_prehash.sql rename to lib/copy_this/resources/patches/0011_prehash.sql diff --git a/lib/DB/patches/0012_prehash.sql b/lib/copy_this/resources/patches/0012_prehash.sql similarity index 100% rename from lib/DB/patches/0012_prehash.sql rename to lib/copy_this/resources/patches/0012_prehash.sql diff --git a/lib/DB/patches/0013_tmux.sql b/lib/copy_this/resources/patches/0013_tmux.sql similarity index 100% rename from lib/DB/patches/0013_tmux.sql rename to lib/copy_this/resources/patches/0013_tmux.sql diff --git a/lib/DB/patches/0014_prehash.sql b/lib/copy_this/resources/patches/0014_prehash.sql similarity index 100% rename from lib/DB/patches/0014_prehash.sql rename to lib/copy_this/resources/patches/0014_prehash.sql diff --git a/lib/DB/patches/0015_sharing.sql b/lib/copy_this/resources/patches/0015_sharing.sql similarity index 100% rename from lib/DB/patches/0015_sharing.sql rename to lib/copy_this/resources/patches/0015_sharing.sql diff --git a/lib/DB/patches/0016_tmux.sql b/lib/copy_this/resources/patches/0016_tmux.sql similarity index 100% rename from lib/DB/patches/0016_tmux.sql rename to lib/copy_this/resources/patches/0016_tmux.sql diff --git a/lib/DB/patches/0017_tmux.sql b/lib/copy_this/resources/patches/0017_tmux.sql similarity index 100% rename from lib/DB/patches/0017_tmux.sql rename to lib/copy_this/resources/patches/0017_tmux.sql diff --git a/lib/DB/patches/0018_sharing.sql b/lib/copy_this/resources/patches/0018_sharing.sql similarity index 100% rename from lib/DB/patches/0018_sharing.sql rename to lib/copy_this/resources/patches/0018_sharing.sql diff --git a/lib/DB/patches/0019_sharing.sql b/lib/copy_this/resources/patches/0019_sharing.sql similarity index 100% rename from lib/DB/patches/0019_sharing.sql rename to lib/copy_this/resources/patches/0019_sharing.sql diff --git a/lib/DB/patches/0020_tmux.sql b/lib/copy_this/resources/patches/0020_tmux.sql similarity index 100% rename from lib/DB/patches/0020_tmux.sql rename to lib/copy_this/resources/patches/0020_tmux.sql diff --git a/lib/DB/patches/0021_tmux.sql b/lib/copy_this/resources/patches/0021_tmux.sql similarity index 100% rename from lib/DB/patches/0021_tmux.sql rename to lib/copy_this/resources/patches/0021_tmux.sql diff --git a/lib/DB/patches/0022_releases.sql b/lib/copy_this/resources/patches/0022_releases.sql similarity index 100% rename from lib/DB/patches/0022_releases.sql rename to lib/copy_this/resources/patches/0022_releases.sql diff --git a/lib/DB/patches/0023_tmux.sql b/lib/copy_this/resources/patches/0023_tmux.sql similarity index 100% rename from lib/DB/patches/0023_tmux.sql rename to lib/copy_this/resources/patches/0023_tmux.sql diff --git a/lib/DB/patches/0024_tmux.sql b/lib/copy_this/resources/patches/0024_tmux.sql similarity index 100% rename from lib/DB/patches/0024_tmux.sql rename to lib/copy_this/resources/patches/0024_tmux.sql diff --git a/lib/DB/patches/0025_tmux.sql b/lib/copy_this/resources/patches/0025_tmux.sql similarity index 100% rename from lib/DB/patches/0025_tmux.sql rename to lib/copy_this/resources/patches/0025_tmux.sql diff --git a/lib/DB/patches/0026_tmux.sql b/lib/copy_this/resources/patches/0026_tmux.sql similarity index 100% rename from lib/DB/patches/0026_tmux.sql rename to lib/copy_this/resources/patches/0026_tmux.sql diff --git a/lib/DB/patches/0027_prehash.sql b/lib/copy_this/resources/patches/0027_prehash.sql similarity index 100% rename from lib/DB/patches/0027_prehash.sql rename to lib/copy_this/resources/patches/0027_prehash.sql diff --git a/lib/DB/patches/0028_tmux.sql b/lib/copy_this/resources/patches/0028_tmux.sql similarity index 100% rename from lib/DB/patches/0028_tmux.sql rename to lib/copy_this/resources/patches/0028_tmux.sql diff --git a/lib/DB/patches/0029_releases.sql b/lib/copy_this/resources/patches/0029_releases.sql similarity index 100% rename from lib/DB/patches/0029_releases.sql rename to lib/copy_this/resources/patches/0029_releases.sql diff --git a/lib/DB/patches/0030_tmux.sql b/lib/copy_this/resources/patches/0030_tmux.sql similarity index 100% rename from lib/DB/patches/0030_tmux.sql rename to lib/copy_this/resources/patches/0030_tmux.sql diff --git a/lib/DB/patches/0031_releases.sql b/lib/copy_this/resources/patches/0031_releases.sql similarity index 100% rename from lib/DB/patches/0031_releases.sql rename to lib/copy_this/resources/patches/0031_releases.sql diff --git a/lib/DB/patches/0032_releases.sql b/lib/copy_this/resources/patches/0032_releases.sql similarity index 100% rename from lib/DB/patches/0032_releases.sql rename to lib/copy_this/resources/patches/0032_releases.sql diff --git a/lib/DB/patches/0033_releases.sql b/lib/copy_this/resources/patches/0033_releases.sql similarity index 100% rename from lib/DB/patches/0033_releases.sql rename to lib/copy_this/resources/patches/0033_releases.sql diff --git a/lib/DB/patches/0034_tmux.sql b/lib/copy_this/resources/patches/0034_tmux.sql similarity index 100% rename from lib/DB/patches/0034_tmux.sql rename to lib/copy_this/resources/patches/0034_tmux.sql diff --git a/lib/DB/patches/0035_prehash.sql b/lib/copy_this/resources/patches/0035_prehash.sql similarity index 100% rename from lib/DB/patches/0035_prehash.sql rename to lib/copy_this/resources/patches/0035_prehash.sql diff --git a/lib/DB/patches/0036_tmux.sql b/lib/copy_this/resources/patches/0036_tmux.sql similarity index 100% rename from lib/DB/patches/0036_tmux.sql rename to lib/copy_this/resources/patches/0036_tmux.sql diff --git a/lib/DB/patches/0037_tmux.sql b/lib/copy_this/resources/patches/0037_tmux.sql similarity index 100% rename from lib/DB/patches/0037_tmux.sql rename to lib/copy_this/resources/patches/0037_tmux.sql diff --git a/lib/DB/patches/0038_releasesearch.sql b/lib/copy_this/resources/patches/0038_releasesearch.sql similarity index 100% rename from lib/DB/patches/0038_releasesearch.sql rename to lib/copy_this/resources/patches/0038_releasesearch.sql diff --git a/lib/DB/patches/0039_prehash.sql b/lib/copy_this/resources/patches/0039_prehash.sql similarity index 100% rename from lib/DB/patches/0039_prehash.sql rename to lib/copy_this/resources/patches/0039_prehash.sql diff --git a/lib/DB/patches/0040_tmux.sql b/lib/copy_this/resources/patches/0040_tmux.sql similarity index 100% rename from lib/DB/patches/0040_tmux.sql rename to lib/copy_this/resources/patches/0040_tmux.sql diff --git a/lib/DB/patches/0041_predbhash.sql b/lib/copy_this/resources/patches/0041_predbhash.sql similarity index 100% rename from lib/DB/patches/0041_predbhash.sql rename to lib/copy_this/resources/patches/0041_predbhash.sql diff --git a/lib/DB/patches/0042_predbhash.sql b/lib/copy_this/resources/patches/0042_predbhash.sql similarity index 100% rename from lib/DB/patches/0042_predbhash.sql rename to lib/copy_this/resources/patches/0042_predbhash.sql diff --git a/lib/DB/patches/0043_prehash.sql b/lib/copy_this/resources/patches/0043_prehash.sql similarity index 100% rename from lib/DB/patches/0043_prehash.sql rename to lib/copy_this/resources/patches/0043_prehash.sql diff --git a/lib/DB/patches/0044_releasecomment.sql b/lib/copy_this/resources/patches/0044_releasecomment.sql similarity index 100% rename from lib/DB/patches/0044_releasecomment.sql rename to lib/copy_this/resources/patches/0044_releasecomment.sql diff --git a/lib/DB/patches/0045_prehash.sql b/lib/copy_this/resources/patches/0045_prehash.sql similarity index 100% rename from lib/DB/patches/0045_prehash.sql rename to lib/copy_this/resources/patches/0045_prehash.sql diff --git a/lib/DB/patches/0046_releasecomment.sql b/lib/copy_this/resources/patches/0046_releasecomment.sql similarity index 100% rename from lib/DB/patches/0046_releasecomment.sql rename to lib/copy_this/resources/patches/0046_releasecomment.sql diff --git a/lib/DB/patches/0047_users.sql b/lib/copy_this/resources/patches/0047_users.sql similarity index 100% rename from lib/DB/patches/0047_users.sql rename to lib/copy_this/resources/patches/0047_users.sql diff --git a/lib/DB/patches/0049_site.sql b/lib/copy_this/resources/patches/0049_site.sql similarity index 100% rename from lib/DB/patches/0049_site.sql rename to lib/copy_this/resources/patches/0049_site.sql diff --git a/lib/DB/patches/0050_category.sql b/lib/copy_this/resources/patches/0050_category.sql similarity index 100% rename from lib/DB/patches/0050_category.sql rename to lib/copy_this/resources/patches/0050_category.sql diff --git a/lib/DB/patches/0051_tmux.sql b/lib/copy_this/resources/patches/0051_tmux.sql similarity index 100% rename from lib/DB/patches/0051_tmux.sql rename to lib/copy_this/resources/patches/0051_tmux.sql diff --git a/lib/DB/patches/0052~gamesinfo.sql b/lib/copy_this/resources/patches/0052~gamesinfo.sql similarity index 100% rename from lib/DB/patches/0052~gamesinfo.sql rename to lib/copy_this/resources/patches/0052~gamesinfo.sql diff --git a/lib/DB/patches/0053~site.sql b/lib/copy_this/resources/patches/0053~site.sql similarity index 100% rename from lib/DB/patches/0053~site.sql rename to lib/copy_this/resources/patches/0053~site.sql diff --git a/lib/DB/patches/0054~releases.sql b/lib/copy_this/resources/patches/0054~releases.sql similarity index 100% rename from lib/DB/patches/0054~releases.sql rename to lib/copy_this/resources/patches/0054~releases.sql diff --git a/lib/DB/patches/0055~users.sql b/lib/copy_this/resources/patches/0055~users.sql similarity index 100% rename from lib/DB/patches/0055~users.sql rename to lib/copy_this/resources/patches/0055~users.sql diff --git a/lib/DB/patches/0056~menu.sql b/lib/copy_this/resources/patches/0056~menu.sql similarity index 100% rename from lib/DB/patches/0056~menu.sql rename to lib/copy_this/resources/patches/0056~menu.sql diff --git a/lib/DB/patches/0057~releases.sql b/lib/copy_this/resources/patches/0057~releases.sql similarity index 100% rename from lib/DB/patches/0057~releases.sql rename to lib/copy_this/resources/patches/0057~releases.sql diff --git a/lib/DB/patches/0058~tmux.sql b/lib/copy_this/resources/patches/0058~tmux.sql similarity index 100% rename from lib/DB/patches/0058~tmux.sql rename to lib/copy_this/resources/patches/0058~tmux.sql diff --git a/lib/DB/patches/0059~users.sql b/lib/copy_this/resources/patches/0059~users.sql similarity index 100% rename from lib/DB/patches/0059~users.sql rename to lib/copy_this/resources/patches/0059~users.sql diff --git a/lib/DB/patches/0060~xxxinfo.sql b/lib/copy_this/resources/patches/0060~xxxinfo.sql similarity index 100% rename from lib/DB/patches/0060~xxxinfo.sql rename to lib/copy_this/resources/patches/0060~xxxinfo.sql diff --git a/lib/DB/patches/0061~releases.sql b/lib/copy_this/resources/patches/0061~releases.sql similarity index 100% rename from lib/DB/patches/0061~releases.sql rename to lib/copy_this/resources/patches/0061~releases.sql diff --git a/lib/DB/patches/0062~releases.sql b/lib/copy_this/resources/patches/0062~releases.sql similarity index 100% rename from lib/DB/patches/0062~releases.sql rename to lib/copy_this/resources/patches/0062~releases.sql diff --git a/lib/DB/patches/0063~site.sql b/lib/copy_this/resources/patches/0063~site.sql similarity index 100% rename from lib/DB/patches/0063~site.sql rename to lib/copy_this/resources/patches/0063~site.sql diff --git a/lib/DB/patches/0064~site.sql b/lib/copy_this/resources/patches/0064~site.sql similarity index 100% rename from lib/DB/patches/0064~site.sql rename to lib/copy_this/resources/patches/0064~site.sql diff --git a/lib/DB/patches/0065~users.sql b/lib/copy_this/resources/patches/0065~users.sql similarity index 100% rename from lib/DB/patches/0065~users.sql rename to lib/copy_this/resources/patches/0065~users.sql diff --git a/lib/DB/patches/0066~genres.sql b/lib/copy_this/resources/patches/0066~genres.sql similarity index 100% rename from lib/DB/patches/0066~genres.sql rename to lib/copy_this/resources/patches/0066~genres.sql diff --git a/lib/DB/patches/0067~gamesinfo.sql b/lib/copy_this/resources/patches/0067~gamesinfo.sql similarity index 100% rename from lib/DB/patches/0067~gamesinfo.sql rename to lib/copy_this/resources/patches/0067~gamesinfo.sql diff --git a/lib/DB/patches/0068~xxxinfo.sql b/lib/copy_this/resources/patches/0068~xxxinfo.sql similarity index 100% rename from lib/DB/patches/0068~xxxinfo.sql rename to lib/copy_this/resources/patches/0068~xxxinfo.sql diff --git a/lib/DB/patches/0069~site.sql b/lib/copy_this/resources/patches/0069~site.sql similarity index 100% rename from lib/DB/patches/0069~site.sql rename to lib/copy_this/resources/patches/0069~site.sql diff --git a/lib/DB/patches/0070~animetitles.sql b/lib/copy_this/resources/patches/0070~animetitles.sql similarity index 100% rename from lib/DB/patches/0070~animetitles.sql rename to lib/copy_this/resources/patches/0070~animetitles.sql diff --git a/lib/DB/patches/0071~site.sql b/lib/copy_this/resources/patches/0071~site.sql similarity index 100% rename from lib/DB/patches/0071~site.sql rename to lib/copy_this/resources/patches/0071~site.sql diff --git a/lib/DB/patches/0072~site.sql b/lib/copy_this/resources/patches/0072~site.sql similarity index 100% rename from lib/DB/patches/0072~site.sql rename to lib/copy_this/resources/patches/0072~site.sql diff --git a/lib/DB/patches/0073~releases.sql b/lib/copy_this/resources/patches/0073~releases.sql similarity index 100% rename from lib/DB/patches/0073~releases.sql rename to lib/copy_this/resources/patches/0073~releases.sql diff --git a/lib/DB/patches/0074~releases.sql b/lib/copy_this/resources/patches/0074~releases.sql similarity index 100% rename from lib/DB/patches/0074~releases.sql rename to lib/copy_this/resources/patches/0074~releases.sql diff --git a/lib/DB/patches/0075~site.sql b/lib/copy_this/resources/patches/0075~site.sql similarity index 100% rename from lib/DB/patches/0075~site.sql rename to lib/copy_this/resources/patches/0075~site.sql diff --git a/lib/DB/patches/0078~site.sql b/lib/copy_this/resources/patches/0078~site.sql similarity index 100% rename from lib/DB/patches/0078~site.sql rename to lib/copy_this/resources/patches/0078~site.sql diff --git a/lib/DB/patches/0079~site.sql b/lib/copy_this/resources/patches/0079~site.sql similarity index 100% rename from lib/DB/patches/0079~site.sql rename to lib/copy_this/resources/patches/0079~site.sql diff --git a/lib/DB/patches/0080~site.sql b/lib/copy_this/resources/patches/0080~site.sql similarity index 100% rename from lib/DB/patches/0080~site.sql rename to lib/copy_this/resources/patches/0080~site.sql diff --git a/lib/DB/patches/0081~movieinfo.sql b/lib/copy_this/resources/patches/0081~movieinfo.sql similarity index 100% rename from lib/DB/patches/0081~movieinfo.sql rename to lib/copy_this/resources/patches/0081~movieinfo.sql diff --git a/lib/DB/patches/0082~tvrageepisodes.sql b/lib/copy_this/resources/patches/0082~tvrageepisodes.sql similarity index 100% rename from lib/DB/patches/0082~tvrageepisodes.sql rename to lib/copy_this/resources/patches/0082~tvrageepisodes.sql diff --git a/lib/DB/patches/0083~site.sql b/lib/copy_this/resources/patches/0083~site.sql similarity index 100% rename from lib/DB/patches/0083~site.sql rename to lib/copy_this/resources/patches/0083~site.sql diff --git a/lib/DB/patches/0084~groups.sql b/lib/copy_this/resources/patches/0084~groups.sql similarity index 100% rename from lib/DB/patches/0084~groups.sql rename to lib/copy_this/resources/patches/0084~groups.sql diff --git a/lib/DB/patches/0085~site.sql b/lib/copy_this/resources/patches/0085~site.sql similarity index 100% rename from lib/DB/patches/0085~site.sql rename to lib/copy_this/resources/patches/0085~site.sql diff --git a/lib/DB/patches/0086~category.sql b/lib/copy_this/resources/patches/0086~category.sql similarity index 100% rename from lib/DB/patches/0086~category.sql rename to lib/copy_this/resources/patches/0086~category.sql diff --git a/lib/DB/patches/0087~site.sql b/lib/copy_this/resources/patches/0087~site.sql similarity index 100% rename from lib/DB/patches/0087~site.sql rename to lib/copy_this/resources/patches/0087~site.sql diff --git a/lib/DB/patches/0088~site.sql b/lib/copy_this/resources/patches/0088~site.sql similarity index 100% rename from lib/DB/patches/0088~site.sql rename to lib/copy_this/resources/patches/0088~site.sql diff --git a/lib/DB/patches/0089~site.sql b/lib/copy_this/resources/patches/0089~site.sql similarity index 100% rename from lib/DB/patches/0089~site.sql rename to lib/copy_this/resources/patches/0089~site.sql diff --git a/lib/DB/patches/0090~bookinfo.sql b/lib/copy_this/resources/patches/0090~bookinfo.sql similarity index 100% rename from lib/DB/patches/0090~bookinfo.sql rename to lib/copy_this/resources/patches/0090~bookinfo.sql diff --git a/lib/DB/patches/0091~releasesearch.sql b/lib/copy_this/resources/patches/0091~releasesearch.sql similarity index 100% rename from lib/DB/patches/0091~releasesearch.sql rename to lib/copy_this/resources/patches/0091~releasesearch.sql diff --git a/lib/DB/patches/0092~bookinfo.sql b/lib/copy_this/resources/patches/0092~bookinfo.sql similarity index 100% rename from lib/DB/patches/0092~bookinfo.sql rename to lib/copy_this/resources/patches/0092~bookinfo.sql diff --git a/lib/DB/patches/0093~anidb.sql b/lib/copy_this/resources/patches/0093~anidb.sql similarity index 100% rename from lib/DB/patches/0093~anidb.sql rename to lib/copy_this/resources/patches/0093~anidb.sql diff --git a/lib/DB/patches/0094~site.sql b/lib/copy_this/resources/patches/0094~site.sql similarity index 100% rename from lib/DB/patches/0094~site.sql rename to lib/copy_this/resources/patches/0094~site.sql diff --git a/lib/DB/patches/0095~releases.sql b/lib/copy_this/resources/patches/0095~releases.sql similarity index 100% rename from lib/DB/patches/0095~releases.sql rename to lib/copy_this/resources/patches/0095~releases.sql diff --git a/lib/DB/patches/0096~site.sql b/lib/copy_this/resources/patches/0096~site.sql similarity index 100% rename from lib/DB/patches/0096~site.sql rename to lib/copy_this/resources/patches/0096~site.sql diff --git a/lib/DB/patches/0097~releases.sql b/lib/copy_this/resources/patches/0097~releases.sql similarity index 100% rename from lib/DB/patches/0097~releases.sql rename to lib/copy_this/resources/patches/0097~releases.sql diff --git a/lib/DB/patches/0098~tmux.sql b/lib/copy_this/resources/patches/0098~tmux.sql similarity index 100% rename from lib/DB/patches/0098~tmux.sql rename to lib/copy_this/resources/patches/0098~tmux.sql diff --git a/lib/DB/patches/0099~releases.sql b/lib/copy_this/resources/patches/0099~releases.sql similarity index 100% rename from lib/DB/patches/0099~releases.sql rename to lib/copy_this/resources/patches/0099~releases.sql diff --git a/lib/DB/patches/0100~binaries.sql b/lib/copy_this/resources/patches/0100~binaries.sql similarity index 100% rename from lib/DB/patches/0100~binaries.sql rename to lib/copy_this/resources/patches/0100~binaries.sql diff --git a/lib/DB/patches/0101~tmux.sql b/lib/copy_this/resources/patches/0101~tmux.sql similarity index 100% rename from lib/DB/patches/0101~tmux.sql rename to lib/copy_this/resources/patches/0101~tmux.sql diff --git a/lib/DB/patches/0102~predb.sql b/lib/copy_this/resources/patches/0102~predb.sql similarity index 100% rename from lib/DB/patches/0102~predb.sql rename to lib/copy_this/resources/patches/0102~predb.sql diff --git a/lib/DB/patches/0103~site.sql b/lib/copy_this/resources/patches/0103~site.sql similarity index 100% rename from lib/DB/patches/0103~site.sql rename to lib/copy_this/resources/patches/0103~site.sql diff --git a/lib/DB/patches/0104~releasecomment.sql b/lib/copy_this/resources/patches/0104~releasecomment.sql similarity index 100% rename from lib/DB/patches/0104~releasecomment.sql rename to lib/copy_this/resources/patches/0104~releasecomment.sql diff --git a/lib/DB/patches/0105~site.sql b/lib/copy_this/resources/patches/0105~site.sql similarity index 100% rename from lib/DB/patches/0105~site.sql rename to lib/copy_this/resources/patches/0105~site.sql diff --git a/lib/DB/patches/0106~category.sql b/lib/copy_this/resources/patches/0106~category.sql similarity index 100% rename from lib/DB/patches/0106~category.sql rename to lib/copy_this/resources/patches/0106~category.sql diff --git a/lib/DB/patches/0107~prehash.sql b/lib/copy_this/resources/patches/0107~prehash.sql similarity index 100% rename from lib/DB/patches/0107~prehash.sql rename to lib/copy_this/resources/patches/0107~prehash.sql diff --git a/lib/DB/patches/0108~regexless.sql b/lib/copy_this/resources/patches/0108~regexless.sql similarity index 100% rename from lib/DB/patches/0108~regexless.sql rename to lib/copy_this/resources/patches/0108~regexless.sql diff --git a/lib/DB/patches/0109~site.sql b/lib/copy_this/resources/patches/0109~site.sql similarity index 100% rename from lib/DB/patches/0109~site.sql rename to lib/copy_this/resources/patches/0109~site.sql diff --git a/lib/DB/patches/0110~category.sql b/lib/copy_this/resources/patches/0110~category.sql similarity index 100% rename from lib/DB/patches/0110~category.sql rename to lib/copy_this/resources/patches/0110~category.sql diff --git a/lib/DB/patches/0111~collections.sql b/lib/copy_this/resources/patches/0111~collections.sql similarity index 100% rename from lib/DB/patches/0111~collections.sql rename to lib/copy_this/resources/patches/0111~collections.sql diff --git a/lib/DB/patches/0112~category.sql b/lib/copy_this/resources/patches/0112~category.sql similarity index 100% rename from lib/DB/patches/0112~category.sql rename to lib/copy_this/resources/patches/0112~category.sql diff --git a/lib/DB/patches/0113~releases.sql b/lib/copy_this/resources/patches/0113~releases.sql similarity index 100% rename from lib/DB/patches/0113~releases.sql rename to lib/copy_this/resources/patches/0113~releases.sql diff --git a/lib/DB/patches/0114~collection_regexes.sql b/lib/copy_this/resources/patches/0114~collection_regexes.sql similarity index 100% rename from lib/DB/patches/0114~collection_regexes.sql rename to lib/copy_this/resources/patches/0114~collection_regexes.sql diff --git a/lib/DB/patches/0115~tmux.sql b/lib/copy_this/resources/patches/0115~tmux.sql similarity index 100% rename from lib/DB/patches/0115~tmux.sql rename to lib/copy_this/resources/patches/0115~tmux.sql diff --git a/lib/DB/patches/0116~tmux.sql b/lib/copy_this/resources/patches/0116~tmux.sql similarity index 100% rename from lib/DB/patches/0116~tmux.sql rename to lib/copy_this/resources/patches/0116~tmux.sql diff --git a/lib/DB/patches/0117~tmux.sql b/lib/copy_this/resources/patches/0117~tmux.sql similarity index 100% rename from lib/DB/patches/0117~tmux.sql rename to lib/copy_this/resources/patches/0117~tmux.sql diff --git a/lib/DB/patches/0118~release_naming_regexes.sql b/lib/copy_this/resources/patches/0118~release_naming_regexes.sql similarity index 100% rename from lib/DB/patches/0118~release_naming_regexes.sql rename to lib/copy_this/resources/patches/0118~release_naming_regexes.sql diff --git a/lib/DB/patches/0119~category_regex.sql b/lib/copy_this/resources/patches/0119~category_regex.sql similarity index 100% rename from lib/DB/patches/0119~category_regex.sql rename to lib/copy_this/resources/patches/0119~category_regex.sql diff --git a/lib/DB/patches/0120~release_naming_regexes.sql b/lib/copy_this/resources/patches/0120~release_naming_regexes.sql similarity index 100% rename from lib/DB/patches/0120~release_naming_regexes.sql rename to lib/copy_this/resources/patches/0120~release_naming_regexes.sql diff --git a/lib/DB/patches/0121~collection_regexes.sql b/lib/copy_this/resources/patches/0121~collection_regexes.sql similarity index 100% rename from lib/DB/patches/0121~collection_regexes.sql rename to lib/copy_this/resources/patches/0121~collection_regexes.sql diff --git a/lib/DB/patches/0122~general.sql b/lib/copy_this/resources/patches/0122~general.sql similarity index 100% rename from lib/DB/patches/0122~general.sql rename to lib/copy_this/resources/patches/0122~general.sql diff --git a/lib/DB/patches/0123~release_naming_regexes.sql b/lib/copy_this/resources/patches/0123~release_naming_regexes.sql similarity index 100% rename from lib/DB/patches/0123~release_naming_regexes.sql rename to lib/copy_this/resources/patches/0123~release_naming_regexes.sql diff --git a/lib/DB/patches/0124~movieinfo.sql b/lib/copy_this/resources/patches/0124~movieinfo.sql similarity index 100% rename from lib/DB/patches/0124~movieinfo.sql rename to lib/copy_this/resources/patches/0124~movieinfo.sql diff --git a/lib/DB/patches/0125~faileddownloads.sql b/lib/copy_this/resources/patches/0125~faileddownloads.sql similarity index 100% rename from lib/DB/patches/0125~faileddownloads.sql rename to lib/copy_this/resources/patches/0125~faileddownloads.sql diff --git a/lib/DB/patches/0127~site.sql b/lib/copy_this/resources/patches/0127~site.sql similarity index 100% rename from lib/DB/patches/0127~site.sql rename to lib/copy_this/resources/patches/0127~site.sql diff --git a/lib/DB/patches/0128~collection_regexes.sql b/lib/copy_this/resources/patches/0128~collection_regexes.sql similarity index 100% rename from lib/DB/patches/0128~collection_regexes.sql rename to lib/copy_this/resources/patches/0128~collection_regexes.sql diff --git a/lib/DB/patches/0129~category_regexes.sql b/lib/copy_this/resources/patches/0129~category_regexes.sql similarity index 100% rename from lib/DB/patches/0129~category_regexes.sql rename to lib/copy_this/resources/patches/0129~category_regexes.sql diff --git a/lib/DB/patches/0130~release_naming_regexes.sql b/lib/copy_this/resources/patches/0130~release_naming_regexes.sql similarity index 100% rename from lib/DB/patches/0130~release_naming_regexes.sql rename to lib/copy_this/resources/patches/0130~release_naming_regexes.sql diff --git a/lib/DB/patches/0131~blacklist.sql b/lib/copy_this/resources/patches/0131~blacklist.sql similarity index 100% rename from lib/DB/patches/0131~blacklist.sql rename to lib/copy_this/resources/patches/0131~blacklist.sql diff --git a/lib/DB/patches/0132~site.sql b/lib/copy_this/resources/patches/0132~site.sql similarity index 100% rename from lib/DB/patches/0132~site.sql rename to lib/copy_this/resources/patches/0132~site.sql diff --git a/lib/DB/patches/0133~collection_regexes.sql b/lib/copy_this/resources/patches/0133~collection_regexes.sql similarity index 100% rename from lib/DB/patches/0133~collection_regexes.sql rename to lib/copy_this/resources/patches/0133~collection_regexes.sql diff --git a/lib/DB/patches/0134~collection_regexes.sql b/lib/copy_this/resources/patches/0134~collection_regexes.sql similarity index 100% rename from lib/DB/patches/0134~collection_regexes.sql rename to lib/copy_this/resources/patches/0134~collection_regexes.sql diff --git a/lib/DB/patches/0135~collection_regexes.sql b/lib/copy_this/resources/patches/0135~collection_regexes.sql similarity index 100% rename from lib/DB/patches/0135~collection_regexes.sql rename to lib/copy_this/resources/patches/0135~collection_regexes.sql diff --git a/lib/DB/patches/0136~release_naming_regexes.sql b/lib/copy_this/resources/patches/0136~release_naming_regexes.sql similarity index 100% rename from lib/DB/patches/0136~release_naming_regexes.sql rename to lib/copy_this/resources/patches/0136~release_naming_regexes.sql diff --git a/lib/DB/patches/0137~groups.sql b/lib/copy_this/resources/patches/0137~groups.sql similarity index 100% rename from lib/DB/patches/0137~groups.sql rename to lib/copy_this/resources/patches/0137~groups.sql diff --git a/lib/DB/patches/0138~collection_regexes.sql b/lib/copy_this/resources/patches/0138~collection_regexes.sql similarity index 100% rename from lib/DB/patches/0138~collection_regexes.sql rename to lib/copy_this/resources/patches/0138~collection_regexes.sql diff --git a/lib/DB/patches/0139~users.sql b/lib/copy_this/resources/patches/0139~users.sql similarity index 100% rename from lib/DB/patches/0139~users.sql rename to lib/copy_this/resources/patches/0139~users.sql diff --git a/lib/DB/patches/0140~collection_regexes.sql b/lib/copy_this/resources/patches/0140~collection_regexes.sql similarity index 100% rename from lib/DB/patches/0140~collection_regexes.sql rename to lib/copy_this/resources/patches/0140~collection_regexes.sql diff --git a/lib/DB/patches/0141~collection_regexes.sql b/lib/copy_this/resources/patches/0141~collection_regexes.sql similarity index 100% rename from lib/DB/patches/0141~collection_regexes.sql rename to lib/copy_this/resources/patches/0141~collection_regexes.sql diff --git a/lib/DB/patches/0142~collection_regexes.sql b/lib/copy_this/resources/patches/0142~collection_regexes.sql similarity index 100% rename from lib/DB/patches/0142~collection_regexes.sql rename to lib/copy_this/resources/patches/0142~collection_regexes.sql diff --git a/lib/DB/patches/0143~collection_regexes.sql b/lib/copy_this/resources/patches/0143~collection_regexes.sql similarity index 100% rename from lib/DB/patches/0143~collection_regexes.sql rename to lib/copy_this/resources/patches/0143~collection_regexes.sql diff --git a/lib/DB/patches/0144~site.sql b/lib/copy_this/resources/patches/0144~site.sql similarity index 100% rename from lib/DB/patches/0144~site.sql rename to lib/copy_this/resources/patches/0144~site.sql diff --git a/lib/DB/patches/0145~collection_regexes.sql b/lib/copy_this/resources/patches/0145~collection_regexes.sql similarity index 100% rename from lib/DB/patches/0145~collection_regexes.sql rename to lib/copy_this/resources/patches/0145~collection_regexes.sql diff --git a/lib/DB/patches/0146~collection_regexes.sql b/lib/copy_this/resources/patches/0146~collection_regexes.sql similarity index 100% rename from lib/DB/patches/0146~collection_regexes.sql rename to lib/copy_this/resources/patches/0146~collection_regexes.sql diff --git a/lib/DB/patches/0147~site.sql b/lib/copy_this/resources/patches/0147~site.sql similarity index 100% rename from lib/DB/patches/0147~site.sql rename to lib/copy_this/resources/patches/0147~site.sql diff --git a/lib/DB/patches/0148~site.sql b/lib/copy_this/resources/patches/0148~site.sql similarity index 100% rename from lib/DB/patches/0148~site.sql rename to lib/copy_this/resources/patches/0148~site.sql diff --git a/lib/copy_this/resources/patches/0149~site.sql b/lib/copy_this/resources/patches/0149~site.sql new file mode 100644 index 000000000..86c6b14b1 --- /dev/null +++ b/lib/copy_this/resources/patches/0149~site.sql @@ -0,0 +1,14 @@ +ALTER TABLE site +ADD section VARCHAR(25) NOT NULL DEFAULT '', +ADD subsection VARCHAR(25) NOT NULL DEFAULT '', +ADD name VARCHAR(25) NOT NULL DEFAULT '', +ADD hint TEXT NOT NULL; +ALTER TABLE site DROP COLUMN id; +ALTER TABLE site DROP INDEX setting; +UPDATE site SET name = setting; +ALTER TABLE site +ADD PRIMARY KEY (section, subsection, name), +ADD UNIQUE INDEX ui_settings_setting (setting); +RENAME TABLE site TO settings; +INSERT IGNORE INTO settings (name, setting, value) VALUES('sqlpatch', 'sqlpatch', 149); + diff --git a/lib/copy_this/www/admin/ajax_sharing_settings.php b/lib/copy_this/www/admin/ajax_sharing_settings.php index d57e713a7..fec342120 100644 --- a/lib/copy_this/www/admin/ajax_sharing_settings.php +++ b/lib/copy_this/www/admin/ajax_sharing_settings.php @@ -4,7 +4,7 @@ require_once './config.php'; // Login check. $admin = new AdminPage; -$db = new newznab\db\DB(); +$db = new newznab\db\Settings(); if (isset($_GET['site_ID']) && isset($_GET['site_status'])) { $db->queryExec(sprintf('UPDATE sharing_sites SET enabled = %d WHERE id = %d', $_GET['site_status'], $_GET['site_ID'])); diff --git a/lib/copy_this/www/admin/db-optimise.php b/lib/copy_this/www/admin/db-optimise.php index 978d04a28..58c24141b 100644 --- a/lib/copy_this/www/admin/db-optimise.php +++ b/lib/copy_this/www/admin/db-optimise.php @@ -2,10 +2,10 @@ require_once './config.php'; -use newznab\db\DB; +use newznab\db\Settings; $page = new AdminPage(); -$db = new DB; +$db = new Settings; $tablelist = $db->optimise(); $page->title = "DB Table Optimise"; diff --git a/lib/copy_this/www/admin/index.php b/lib/copy_this/www/admin/index.php index d65829ff8..09633e91a 100644 --- a/lib/copy_this/www/admin/index.php +++ b/lib/copy_this/www/admin/index.php @@ -2,7 +2,7 @@ require_once './config.php'; -use newznab\db\DB; +use newznab\db\Settings; $page = new AdminPage(); @@ -18,7 +18,7 @@ $statusmsgs = array(); // // mysql config settings // -$db = new DB(); +$db = new Settings(); $result = $db->queryDirect("SELECT @@group_concat_max_len, @@max_allowed_packet"); $data = $db->getAssocArray($result); @@ -42,7 +42,7 @@ if ($page->site->rawretentiondays > 10) $s = new Sites(); if (!property_exists($page->site, "dbversion")) { - $db = new DB(); + $db = new Settings(); $db->queryInsert('INSERT INTO site (setting, value, updateddate ) VALUES (\'dbversion\', \'$Rev: 2248 $\', now())'); $page->site = $s->get(); } diff --git a/lib/copy_this/www/admin/sharing.php b/lib/copy_this/www/admin/sharing.php index 62dd0d4c2..1d480f371 100644 --- a/lib/copy_this/www/admin/sharing.php +++ b/lib/copy_this/www/admin/sharing.php @@ -1,12 +1,12 @@ title = 'Sharing Settings'; -$db = new DB(); +$db = new Settings(); $offset = (isset($_GET['offset']) ? $_GET['offset'] : 0); diff --git a/lib/copy_this/www/admin/site-debug.php b/lib/copy_this/www/admin/site-debug.php index 9830b7f42..d4af956d7 100644 --- a/lib/copy_this/www/admin/site-debug.php +++ b/lib/copy_this/www/admin/site-debug.php @@ -18,7 +18,7 @@ unset($s->sabapikey); unset($s->sabcompletedir); unset($s->sabvdir); -$db = new newznab\db\DB; +$db = new newznab\db\Settings; $totalsize = 0; $alltables = $db->query("show table status"); foreach ($alltables as $tablename) diff --git a/lib/copy_this/www/pages/api.php b/lib/copy_this/www/pages/api.php index cb12d5f4e..e12ecc4ee 100644 --- a/lib/copy_this/www/pages/api.php +++ b/lib/copy_this/www/pages/api.php @@ -656,10 +656,10 @@ function addCoverURL(&$releases, callable $getCoverURL) /** * Add language from media info XML to release search names. * @param array $releases - * @param \newznab\db\DB $settings + * @param \newznab\db\Settings $settings * @return array */ -function addLanguage(&$releases, \newznab\db\DB $settings) +function addLanguage(&$releases, \newznab\db\Settings $settings) { if ($releases && count($releases)) { foreach ($releases as $key => $release) { diff --git a/lib/copy_this/www/pages/content.php b/lib/copy_this/www/pages/content.php index e280f0ccd..ad2836f5f 100644 --- a/lib/copy_this/www/pages/content.php +++ b/lib/copy_this/www/pages/content.php @@ -1,6 +1,4 @@ isLoggedIn()) @@ -11,7 +10,7 @@ $r = new Releases(); $s = new Sites(); $site = $s->get(); -$db = new DB(); +$db = new Settings(); if ($site->sabvdir == "" || $site->sabcompletedir == "" || !file_exists($site->sabcompletedir)) $page->show404(); diff --git a/lib/copy_this/www/pages/myshows.php b/lib/copy_this/www/pages/myshows.php index a68178e87..1f31004c5 100644 --- a/lib/copy_this/www/pages/myshows.php +++ b/lib/copy_this/www/pages/myshows.php @@ -1,6 +1,6 @@ isLoggedIn()) $page->show403(); @@ -34,7 +34,7 @@ switch($action) { } else { - $db = new DB(); + $db = new Settings(); $show = $db->queryOneRow(sprintf("select releasetitle from tvrage where rageID = %d", $rid)); if (!$show) $page->show404('Seriously?'); diff --git a/lib/copy_this/www/pages/prehashinfo.php b/lib/copy_this/www/pages/prehashinfo.php index 8971c5943..699281a5f 100644 --- a/lib/copy_this/www/pages/prehashinfo.php +++ b/lib/copy_this/www/pages/prehashinfo.php @@ -149,7 +149,7 @@ if (isset($_GET['type'])) { case 'r': case 'requestid': if (isset($_GET['reqid']) && is_numeric($_GET['reqid']) && isset($_GET['group']) && is_string($_GET['group'])) { - $db = new newznab\db\DB(); + $db = new newznab\db\Settings(); $preData = $db->query( sprintf(' SELECT p.* @@ -175,7 +175,7 @@ if (isset($_GET['type'])) { case 't': case 'title': if (isset($_GET['title'])) { - $db = new newznab\db\DB(); + $db = new newznab\db\Settings(); $preData = $db->query( sprintf('SELECT * FROM prehash p WHERE p.title %s %s %s LIKE %s LIMIT %d OFFSET %d', $newer, @@ -193,7 +193,7 @@ if (isset($_GET['type'])) { case 'm': case 'md5': if (isset($_GET['md5']) && strlen($_GET['title']) === 32) { - $db = new newznab\db\DB(); + $db = new newznab\db\Settings(); $preData = $db->query( sprintf('SELECT * FROM prehash p INNER JOIN predbhash ph ON ph.pre_id = p.id WHERE MATCH(hashes) AGAINST (%s) %s %s %s LIMIT %d OFFSET %d', $db->escapeString($_GET['md5']), @@ -210,7 +210,7 @@ if (isset($_GET['type'])) { case 's': case 'sha1': if (isset($_GET['sha1']) && strlen($_GET['sha1']) === 40) { - $db = new newznab\db\DB(); + $db = new newznab\db\Settings(); $preData = $db->query( sprintf('SELECT * FROM prehash p INNER JOIN predbhash ph ON ph.pre_id = p.id WHERE MATCH(hashes) AGAINST (%s) %s %s %s LIMIT %d OFFSET %d', $db->escapeString($_GET['sha1']), @@ -226,7 +226,7 @@ if (isset($_GET['type'])) { case 'a': case 'all': - $db = new newznab\db\DB(); + $db = new newznab\db\Settings(); $preData = $db->query( sprintf('SELECT * FROM prehash p WHERE 1=1 %s %s %s ORDER BY p.predate DESC LIMIT %d OFFSET %d', $newer, diff --git a/lib/copy_this/www/templates/nntmux/views/frontend/rssdesc.tpl b/lib/copy_this/www/templates/nntmux/views/frontend/rssdesc.tpl index 91913e941..c9a509bd0 100644 --- a/lib/copy_this/www/templates/nntmux/views/frontend/rssdesc.tpl +++ b/lib/copy_this/www/templates/nntmux/views/frontend/rssdesc.tpl @@ -2,7 +2,7 @@

{$page->title}

- Here you can choose rss feeds from site categories. The feeds will present either decriptions or + Here you can choose rss feeds from settings categories. The feeds will present either decriptions or downloads of Nzb files.

diff --git a/lib/decrypt_hashes.php b/lib/decrypt_hashes.php index 620f631ce..63737f134 100644 --- a/lib/decrypt_hashes.php +++ b/lib/decrypt_hashes.php @@ -1,9 +1,9 @@ log->error( diff --git a/lib/fixReleaseNames.php b/lib/fixReleaseNames.php index 3d92696c0..1ff47f5bc 100644 --- a/lib/fixReleaseNames.php +++ b/lib/fixReleaseNames.php @@ -9,11 +9,11 @@ */ require_once(dirname(__FILE__)."/../bin/config.php"); -use newznab\db\DB; +use newznab\db\Settings; $n = "\n"; -$pdo = new DB(); +$pdo = new Settings(); $namefixer = new \NameFixer(['Settings' => $pdo]); $predb = new \PreHash(['Echo' => true, 'Settings' => $pdo]); $s = new Sites(); diff --git a/lib/testing/DB/change_USP_provider.php b/lib/testing/DB/change_USP_provider.php index c27e63aff..36bc2bca9 100644 --- a/lib/testing/DB/change_USP_provider.php +++ b/lib/testing/DB/change_USP_provider.php @@ -1,7 +1,7 @@ log->setColor('Yellow') . "This script is used when you have switched UseNet Providers(USP) so you can pickup where you left off, rather than resetting all the groups.\nOnly use this script after you have updated your config.php file with your new USP info!!\nMake sure you " . $pdo->log->setColor('Red', 'Bold') . "DO NOT" . $pdo->log->setcolor('Yellow') . " have any update or postprocess scripts running when running this script!\n\n" . $pdo->log->setColor('Cyan') . "Usage: php change_USP_provider true\n"); diff --git a/lib/testing/DB/convert_mysql_tables.php b/lib/testing/DB/convert_mysql_tables.php index 16823b728..7ca35e77b 100644 --- a/lib/testing/DB/convert_mysql_tables.php +++ b/lib/testing/DB/convert_mysql_tables.php @@ -1,11 +1,11 @@ true]); +$pdo = new Settings(['checkVersion' => true]); $ftinnodb = $pdo->isDbVersionAtLeast('5.6'); if (isset($argv[1]) && isset($argv[2]) && $argv[2] == "fmyisam") { diff --git a/lib/testing/DB/convert_to_tpg.php b/lib/testing/DB/convert_to_tpg.php index b96b559d8..ddb4faaee 100644 --- a/lib/testing/DB/convert_to_tpg.php +++ b/lib/testing/DB/convert_to_tpg.php @@ -1,11 +1,11 @@ $pdo]); $consoletools = new \ConsoleTools(['ColorCLI' => $pdo->log]); $s = new Sites(); diff --git a/lib/testing/DB/mysqldump_tables.php b/lib/testing/DB/mysqldump_tables.php index 4301cc468..919e77db3 100644 --- a/lib/testing/DB/mysqldump_tables.php +++ b/lib/testing/DB/mysqldump_tables.php @@ -1,13 +1,13 @@ $pdo->log]); $timestart = TIME(); $relcount = $deleted = $total = 0; diff --git a/lib/testing/DB/rename_to_lower.php b/lib/testing/DB/rename_to_lower.php index d842d60fb..9e4d151c4 100644 --- a/lib/testing/DB/rename_to_lower.php +++ b/lib/testing/DB/rename_to_lower.php @@ -4,7 +4,7 @@ require_once(dirname(__FILE__) . "/../../../bin/config.php"); passthru('clear'); -$pdo = new newznab\db\DB(); +$pdo = new newznab\db\Settings(); if (!isset($argv[1]) || (isset($argv[1]) && $argv[1] !== 'true')) { exit($pdo->log->error("\nThis script renames all table columns to lowercase, it can be dangerous. Please BACKUP your database before running this script.\n" diff --git a/lib/testing/DB/reset_postprocessing.php b/lib/testing/DB/reset_postprocessing.php index 3353da3d3..dfc018f01 100644 --- a/lib/testing/DB/reset_postprocessing.php +++ b/lib/testing/DB/reset_postprocessing.php @@ -1,9 +1,9 @@ $pdo->log]); $ran = false; diff --git a/lib/testing/DB/reset_truncate.php b/lib/testing/DB/reset_truncate.php index b95c026e4..727ad3994 100644 --- a/lib/testing/DB/reset_truncate.php +++ b/lib/testing/DB/reset_truncate.php @@ -1,9 +1,9 @@ get(); diff --git a/lib/testing/DB/resetdb.php b/lib/testing/DB/resetdb.php index 4913b3537..fcf43a7fa 100644 --- a/lib/testing/DB/resetdb.php +++ b/lib/testing/DB/resetdb.php @@ -1,11 +1,11 @@ log->error("\nThis script removes all releases and release related files. To run:\nphp resetdb.php true\n")); diff --git a/lib/testing/Dev/clean_nzbs.php b/lib/testing/Dev/clean_nzbs.php index 98dc1f9c2..a3c1c7e23 100644 --- a/lib/testing/Dev/clean_nzbs.php +++ b/lib/testing/Dev/clean_nzbs.php @@ -1,10 +1,10 @@ get(); diff --git a/lib/testing/Dev/renametopre.php b/lib/testing/Dev/renametopre.php index 3a5d99678..465bc60fa 100644 --- a/lib/testing/Dev/renametopre.php +++ b/lib/testing/Dev/renametopre.php @@ -1,7 +1,7 @@ log->error( diff --git a/lib/testing/PostProc/check_previews.php b/lib/testing/PostProc/check_previews.php index a27df6249..28188ae70 100644 --- a/lib/testing/PostProc/check_previews.php +++ b/lib/testing/PostProc/check_previews.php @@ -4,10 +4,10 @@ // -------------------------------------------------------------- require_once(dirname(__FILE__) . "/../../../bin/config.php"); -use newznab\db\DB; +use newznab\db\Settings; use newznab\utility\Utility; -$pdo = new DB(); +$pdo = new Settings(); $row = $pdo->queryOneRow("SELECT value FROM site WHERE setting = 'coverspath'"); if ($row !== false) { diff --git a/lib/testing/PostProc/getConsole.php b/lib/testing/PostProc/getConsole.php index 8bbe4b107..89d385ded 100644 --- a/lib/testing/PostProc/getConsole.php +++ b/lib/testing/PostProc/getConsole.php @@ -3,11 +3,11 @@ require_once(dirname(__FILE__) . "/../../../bin/config.php"); -use newznab\db\DB; +use newznab\db\Settings; -$pdo = new DB(); +$pdo = new Settings(); $console = new \Konsole(['Echo' => true, 'Settings' => $pdo]); $res = $pdo->queryDirect(sprintf("SELECT searchname, id FROM releases WHERE consoleinfoid IS NULL AND categoryid BETWEEN 1000 AND 1999 ORDER BY id DESC" )); diff --git a/lib/testing/PostProc/getGameCovers.php b/lib/testing/PostProc/getGameCovers.php index 3a17debd8..901eb2dc6 100644 --- a/lib/testing/PostProc/getGameCovers.php +++ b/lib/testing/PostProc/getGameCovers.php @@ -3,10 +3,10 @@ require_once(dirname(__FILE__) . "/../../../bin/config.php"); -use newznab\db\DB; +use newznab\db\Settings; -$pdo = new DB(); +$pdo = new Settings(); $game = new \Games(['Echo' => true, 'Settings' => $pdo]); $res = $pdo->query( diff --git a/lib/testing/PostProc/getImdb.php b/lib/testing/PostProc/getImdb.php index d10bba52a..97a714e50 100644 --- a/lib/testing/PostProc/getImdb.php +++ b/lib/testing/PostProc/getImdb.php @@ -2,9 +2,9 @@ //This script will update all records in the movieinfo table require_once(dirname(__FILE__) . "/../../../bin/config.php"); -use newznab\db\DB; +use newznab\db\Settings; -$pdo = new DB(); +$pdo = new Settings(); $c = new \ColorCLI(); $movie = new \Film(['Echo' => true, 'Settings' => $pdo]); diff --git a/lib/testing/PostProc/getMovieCovers.php b/lib/testing/PostProc/getMovieCovers.php index 637d0849c..3302bcd83 100644 --- a/lib/testing/PostProc/getMovieCovers.php +++ b/lib/testing/PostProc/getMovieCovers.php @@ -2,9 +2,9 @@ //This script will update all records in the movieinfo table where there is no cover require_once(dirname(__FILE__) . "/../../../bin/config.php"); -use newznab\db\DB; +use newznab\db\Settings; -$pdo = new DB(); +$pdo = new Settings(); $movie = new \Film(array('Echo' => true, 'Settings' => $pdo)); diff --git a/lib/testing/PostProc/getXXXCovers.php b/lib/testing/PostProc/getXXXCovers.php index 6991235e2..94b2d3289 100644 --- a/lib/testing/PostProc/getXXXCovers.php +++ b/lib/testing/PostProc/getXXXCovers.php @@ -2,10 +2,10 @@ //This script will update all records in the xxxinfo table where there is no cover require_once(dirname(__FILE__) . "/../../../bin/config.php"); -use newznab\db\DB; +use newznab\db\Settings; -$pdo = new DB(); +$pdo = new Settings(); $movie = new XXX(); $c = new ColorCLI(); diff --git a/lib/testing/PostProc/populate_tvrage.php b/lib/testing/PostProc/populate_tvrage.php index 2ab7ff847..f91e46ccd 100644 --- a/lib/testing/PostProc/populate_tvrage.php +++ b/lib/testing/PostProc/populate_tvrage.php @@ -1,10 +1,10 @@ log->error("\nThis script will download all tvrage shows and insert into the db.\n\n" diff --git a/lib/testing/PostProc/updateBookImages.php b/lib/testing/PostProc/updateBookImages.php index 2ae28a851..8fdc013de 100644 --- a/lib/testing/PostProc/updateBookImages.php +++ b/lib/testing/PostProc/updateBookImages.php @@ -1,10 +1,10 @@ $pdo, 'Echo' => true]); $shows = $pdo->queryDirect("SELECT rageid FROM tvrage WHERE imgdata IS NULL ORDER BY rageid DESC LIMIT 2000"); diff --git a/lib/testing/PostProc/updateXXXImages.php b/lib/testing/PostProc/updateXXXImages.php index b333ced02..5e4c1bf24 100644 --- a/lib/testing/PostProc/updateXXXImages.php +++ b/lib/testing/PostProc/updateXXXImages.php @@ -1,10 +1,10 @@ get(); diff --git a/lib/testing/_run_once/tpg_fixes.php b/lib/testing/_run_once/tpg_fixes.php index 1ea2ea8fe..57fd322bb 100644 --- a/lib/testing/_run_once/tpg_fixes.php +++ b/lib/testing/_run_once/tpg_fixes.php @@ -28,9 +28,9 @@ if (!isset($argv[1]) || !in_array($argv[1], ['1'])) { require_once(dirname(__FILE__) . "/../../../bin/config.php"); -use newznab\db\DB; +use newznab\db\Settings; -$pdo = new DB(); +$pdo = new Settings(); $s = new Sites(); $site = $s->get(); diff --git a/lib/testing/populate_anidb.php b/lib/testing/populate_anidb.php index 308d701a6..26ddd0a42 100644 --- a/lib/testing/populate_anidb.php +++ b/lib/testing/populate_anidb.php @@ -4,9 +4,9 @@ */ require_once(dirname(__FILE__) . "/../../bin/config.php"); -use newznab\db\DB; +use newznab\db\Settings; -$pdo = new DB(); +$pdo = new Settings(); if ($argc > 1 && $argv[1] == true) { (new \PopulateAniDB(['Settings' => $pdo, 'Echo' => true]))->populateTable('full'); diff --git a/lib/testing/predb_import_daily_batch.php b/lib/testing/predb_import_daily_batch.php index aee44ad98..90abb542f 100644 --- a/lib/testing/predb_import_daily_batch.php +++ b/lib/testing/predb_import_daily_batch.php @@ -4,7 +4,7 @@ pre-fetching groupid and other data for faster inclusion in the main query. */ -use newznab\db\DB; +use newznab\db\Settings; use newznab\utility\Utility; $config = dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR . 'bin' . DIRECTORY_SEPARATOR . @@ -72,7 +72,7 @@ if ($result) { exec('clear'); $all_matches = array_unique($all_matches[1]); $total = count($all_matches); - $pdo = new DB(); + $pdo = new Settings(); if ($argv[1] != 'progress') { $progress['last'] = !is_numeric($argv[1]) ? time() : $argv[1]; diff --git a/lib/testing/recategorize.php b/lib/testing/recategorize.php index c995c343d..d7cd563f0 100644 --- a/lib/testing/recategorize.php +++ b/lib/testing/recategorize.php @@ -1,7 +1,7 @@ 0) { //check the db connection if ($pdo->ping(true) == false) { unset($pdo); - $pdo = new DB(); + $pdo = new Settings(); } $timer01 = time(); diff --git a/run.php b/run.php index e624b6962..963d8b21f 100644 --- a/run.php +++ b/run.php @@ -1,14 +1,12 @@ get(); $t = new Tmux(); $tmux = $t->get(); $patch = (isset($tmux->sqlpatch)) ? $tmux->sqlpatch : 0; @@ -17,12 +15,13 @@ $tmux_session = (isset($tmux->tmux_session)) ? $tmux->tmux_session : 0; $seq = (isset($tmux->sequential)) ? $tmux->sequential : 0; $powerline = (isset($tmux->powerline)) ? $tmux->powerline : 0; $colors = (isset($tmux->colors)) ? $tmux->colors : 0; -$nntpproxy = $site->nntpproxy; -$tablepergroup = $site->tablepergroup; +$nntpproxy = $pdo->getSetting('nntpproxy'); +$tablepergroup = $pdo->getSetting('tablepergroup'); $tablepergroup = ($tablepergroup != '') ? $tablepergroup : 0; -$delaytimet = $site->delaytime; +$delaytimet = $pdo->getSetting('delaytime'); $delaytimet = ($delaytimet) ? (int)$delaytimet : 2; +Utility::isPatched(); Utility::clearScreen(); echo "Starting Tmux...\n"; @@ -38,9 +37,9 @@ if (count($nntpkill) !== 0) { } // Check database patch version -if ($patch < 148) { +/*if ($patch < 149) { exit($c->error("\nYour database is not up to date. Please update.\nphp /var/www/newznab/misc/update_scripts/nix_scripts/tmux/lib/DB/patchDB.php\n")); -} +}*/ //check if session exists $session = shell_exec("tmux list-session | grep $tmux_session"); @@ -50,7 +49,7 @@ if (count($session) !== 0) { exit($pdo->log->error("tmux session: '" . $tmux_session . "' is already running, aborting.\n")); } -$nntpproxy = $site->nntpproxy; +$nntpproxy = $pdo->getSetting('nntpproxy'); if ($nntpproxy == '1') { $modules = ["nntp", "socketpool"]; foreach ($modules as &$value) { @@ -62,16 +61,16 @@ if ($nntpproxy == '1') { } //reset collections dateadded to now if dateadded > delay time check -echo $db->log->header("Resetting expired collections dateadded to now. This could take a minute or two. Really."); +echo $pdo->log->header("Resetting expired collections dateadded to now. This could take a minute or two. Really."); if ($tablepergroup == 1) { $sql = "SHOW table status"; - $tables = $db->queryDirect($sql); + $tables = $pdo->queryDirect($sql); $ran = 0; foreach ($tables as $row) { $tbl = $row['name']; if (preg_match('/collections_\d+/', $tbl)) { - $run = $db->queryExec('UPDATE ' . $tbl . + $run = $pdo->queryExec('UPDATE ' . $tbl . ' SET dateadded = now() WHERE dateadded < now() - INTERVAL ' . $delaytimet . ' HOUR'); if ($run !== false) { @@ -79,15 +78,15 @@ if ($tablepergroup == 1) { } } } - echo $db->log->primary(number_format($ran) . " collections reset."); + echo $pdo->log->primary(number_format($ran) . " collections reset."); } else { $ran = 0; - $run = $db->queryExec('update collections set dateadded = now() WHERE dateadded < now() - INTERVAL ' . + $run = $pdo->queryExec('update collections set dateadded = now() WHERE dateadded < now() - INTERVAL ' . $delaytimet . ' HOUR'); if ($run !== false) { $ran += $run->rowCount(); } - echo $db->log->primary(number_format($ran) . " collections reset."); + echo $pdo->log->primary(number_format($ran) . " collections reset."); } sleep(2); @@ -105,13 +104,13 @@ function writelog($pane) } //remove folders from tmpunrar -if (isset($site->tmpunrarpath)) { - $tmpunrar = $site->tmpunrarpath; +/*if (isset($pdo->getSetting('tmpunrarpath'))) { + $tmpunrar = $pdo->getSetting('tmpunrarpath'); if ((count(glob("$tmpunrar/*", GLOB_ONLYDIR))) > 0) { echo $c->info("Removing dead folders from " . $tmpunrar); exec("rm -r " . $tmpunrar . "/*"); } -} +}*/ function command_exist($cmd) { @@ -134,12 +133,12 @@ function python_module_exist($module) return ($returnCode == 0 ? true : false); } -$nntpproxy = $site->nntpproxy; +$nntpproxy = $pdo->getSetting('nntpproxy'); if ($nntpproxy == '1') { $modules = array("nntp", "socketpool"); foreach ($modules as &$value) { if (!python_module_exist($value)) { - exit($db->log->error("\nNNTP Proxy requires " . $value . " python module but it's not installed. Aborting.\n")); + exit($pdo->log->error("\nNNTP Proxy requires " . $value . " python module but it's not installed. Aborting.\n")); } } } @@ -196,8 +195,8 @@ function start_apps($tmux_session) function window_proxy($tmux_session, $window) { - global $site; - $nntpproxy = $site->nntpproxy; + global $pdo; + $nntpproxy = $pdo->getSetting('nntpproxy'); if ($nntpproxy === '1') { $DIR = NN_MISC; $nntpproxypy = $DIR . "update_scripts/nix_scripts/tmux/python/nntpproxy.py"; @@ -207,7 +206,7 @@ function window_proxy($tmux_session, $window) } } - if ($nntpproxy === '1' && ($site->alternate_nntp == '1')) { + if ($nntpproxy === '1' && ($pdo->getSetting('alternate_nntp') == '1')) { $DIR = NN_TMUX; $nntpproxypy = $DIR . "python/nntpproxy.py"; if (file_exists($DIR . "python/lib/nntpproxy_a.conf")) { @@ -251,8 +250,8 @@ function window_optimize($tmux_session) function window_sharing($tmux_session) { - $db = new newznab\db\DB(); - $sharing = $db->queryOneRow('SELECT enabled, posting, fetching FROM sharing'); + $pdo = new newznab\db\Settings(); + $sharing = $pdo->queryOneRow('SELECT enabled, posting, fetching FROM sharing'); $t = new \Tmux(); $tmux = $t->get(); $tmux_share = (isset($tmux->run_sharing)) ? $tmux->run_sharing : 0; diff --git a/scripts/reset_rar_check.php b/scripts/reset_rar_check.php index f1d4c1cc3..302e284f9 100755 --- a/scripts/reset_rar_check.php +++ b/scripts/reset_rar_check.php @@ -1,6 +1,6 @@ query("update releases set passwordstatus = -1 where rarinnerfilecount = 0"); diff --git a/start.php b/start.php index 5b573e8f8..3c15bdbfd 100644 --- a/start.php +++ b/start.php @@ -8,9 +8,9 @@ */ require_once realpath(__DIR__ . '/../../../../www/config.php'); -use newznab\db\DB; +use newznab\db\Settings; -$pdo = new DB(); +$pdo = new Settings(); $tmux = new \Tmux(); $tmux_settings = $tmux->get();