PageRenderTime 24ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/wcfsetup/install/files/lib/data/page/PageEditor.class.php

https://github.com/0xLeon/WCF
PHP | 88 lines | 51 code | 7 blank | 30 comment | 4 complexity | c8a57805dc2b2da7de175e5596791311 MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. namespace wcf\data\page;
  3. use wcf\data\package\PackageCache;
  4. use wcf\data\DatabaseObjectEditor;
  5. use wcf\data\IEditableCachedObject;
  6. use wcf\system\cache\builder\PageCacheBuilder;
  7. use wcf\system\cache\builder\RoutingCacheBuilder;
  8. use wcf\system\request\ControllerMap;
  9. use wcf\system\WCF;
  10. use wcf\util\FileUtil;
  11. /**
  12. * Provides functions to edit pages.
  13. *
  14. * @author Marcel Werk
  15. * @copyright 2001-2016 WoltLab GmbH
  16. * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
  17. * @package WoltLabSuite\Core\Data\Page
  18. * @since 3.0
  19. *
  20. * @method static Page create(array $parameters = [])
  21. * @method Page getDecoratedObject()
  22. * @mixin Page
  23. */
  24. class PageEditor extends DatabaseObjectEditor implements IEditableCachedObject {
  25. /**
  26. * @inheritDoc
  27. */
  28. protected static $baseClass = Page::class;
  29. /**
  30. * @inheritDoc
  31. */
  32. public static function resetCache() {
  33. RoutingCacheBuilder::getInstance()->reset();
  34. PageCacheBuilder::getInstance()->reset();
  35. }
  36. /**
  37. * Returns true if given custom url is unique.
  38. *
  39. * @param string $customURL
  40. * @param integer $packageID
  41. *
  42. * @return boolean
  43. */
  44. public static function isUniqueCustomUrl($customURL, $packageID = 1) {
  45. // check controller
  46. $package = PackageCache::getInstance()->getPackage($packageID);
  47. $packageDir = FileUtil::addTrailingSlash(FileUtil::getRealPath(WCF_DIR.$package->packageDir));
  48. $files = array_merge(glob($packageDir . 'lib/action/*.php'), glob($packageDir . 'lib/form/*.php'), glob($packageDir . 'lib/page/*.php'));
  49. foreach ($files as $file) {
  50. $filename = preg_replace('/(Action|Page|Form)(\.class)?\.php$/', '', basename($file));
  51. if ($customURL == ControllerMap::transformController($filename)) {
  52. return false;
  53. }
  54. }
  55. // check custom controller urls
  56. $sql = "SELECT COUNT(*) AS count
  57. FROM wcf".WCF_N."_page
  58. WHERE controllerCustomURL = ?
  59. AND applicationPackageID = ?";
  60. $statement = WCF::getDB()->prepareStatement($sql);
  61. $statement->execute([$customURL, $packageID]);
  62. if ($statement->fetchColumn()) {
  63. return false;
  64. }
  65. // check custom urls
  66. $sql = "SELECT COUNT(*) AS count
  67. FROM wcf".WCF_N."_page_content
  68. WHERE customURL = ?
  69. AND pageID IN (
  70. SELECT pageID
  71. FROM wcf".WCF_N."_page
  72. WHERE applicationPackageID = ?
  73. )";
  74. $statement = WCF::getDB()->prepareStatement($sql);
  75. $statement->execute([$customURL, $packageID]);
  76. if ($statement->fetchColumn()) {
  77. return false;
  78. }
  79. return true;
  80. }
  81. }