/web/concrete/libraries/attribute/view.php

https://github.com/shin2/concrete5 · PHP · 124 lines · 92 code · 20 blank · 12 comment · 21 complexity · a3842aaef4e67d0cd36adcfc00d0fccb MD5 · raw file

  1. <?
  2. defined('C5_EXECUTE') or die("Access Denied.");
  3. /**
  4. * An object corresponding to a particular view of an attribute.
  5. *
  6. * @author Andrew Embler <andrew@concrete5.org>
  7. * @category Concrete
  8. * @copyright Copyright (c) 2003-2008 Concrete5. (http://www.concrete5.org)
  9. * @license http://www.concrete5.org/license/ MIT License
  10. *
  11. */
  12. class AttributeTypeView extends View {
  13. protected function getValue() {return $this->attributeValue;}
  14. protected function getAttributeKey() {return $this->attributeKey;}
  15. public function action($action) {
  16. $uh = Loader::helper('concrete/urls');
  17. $a = func_get_args();
  18. $args = '';
  19. for ($i = 1; $i < count($a); $i++) {
  20. $args .= '&args[]=' . $a[$i];
  21. }
  22. $url = $uh->getToolsURL('attribute_type_actions') . '?atID=' . $this->controller->attributeType->getAttributeTypeID();
  23. if (is_object($this->attributeKey)) {
  24. $url .= '&akID=' . $this->attributeKey->getAttributeKeyID();
  25. }
  26. $url .= '&action=' . $action . $args;
  27. return $url;
  28. }
  29. public function getAttributeTypeURL($filename = false) {
  30. $atHandle = $this->attributeType->getAttributeTypeHandle();
  31. if (file_exists(DIR_MODELS . '/' . DIRNAME_ATTRIBUTES . '/' . DIRNAME_ATTRIBUTE_TYPES . '/' . $atHandle . '/' . $filename)) {
  32. $url = BASE_URL . DIR_REL . '/' . DIRNAME_MODELS . '/' . DIRNAME_ATTRIBUTES . '/' . DIRNAME_ATTRIBUTE_TYPES . '/' . $atHandle . '/' . $filename;
  33. }
  34. if (!isset($file) && $this->attributeType->getPackageID() > 0) {
  35. $pkgHandle = PackageList::getHandle($this->attributeType->getPackageID());
  36. $dirp = is_dir(DIR_PACKAGES . '/' . $pkgHandle) ? DIR_PACKAGES . '/' . $pkgHandle : DIR_PACKAGES_CORE . '/' . $pkgHandle;
  37. $rdirp = is_dir(DIR_PACKAGES . '/' . $pkgHandle) ? BASE_URL . DIR_REL . '/' . DIRNAME_PACKAGES . '/' . $pkgHandle : ASSETS_URL . '/' . DIRNAME_PACKAGES . '/' . $pkgHandle;
  38. if (file_exists($dirp . '/' . $pkgHandle . '/' . DIRNAME_MODELS . '/' . DIRNAME_ATTRIBUTES . '/' . DIRNAME_ATTRIBUTE_TYPES . '/' . $atHandle . '/' . $filename)) {
  39. $url = $rdirp . '/' . DIRNAME_MODELS . '/' . DIRNAME_ATTRIBUTES . '/' . DIRNAME_ATTRIBUTE_TYPES . '/' . $atHandle . '/' . $filename;
  40. }
  41. }
  42. if (!isset($url)) {
  43. $url = ASSETS_URL . '/' . DIRNAME_MODELS . '/' . DIRNAME_ATTRIBUTES . '/' . DIRNAME_ATTRIBUTE_TYPES . '/' . $atHandle . '/' . $filename;
  44. }
  45. return $url;
  46. }
  47. public function __construct($attributeType, $attributeKey, $attributeValue) {
  48. $this->controller = $attributeType->getController();
  49. $this->controller->setAttributeKey($attributeKey);
  50. $this->controller->setAttributeValue($attributeValue);
  51. $this->attributeValue = $attributeValue;
  52. $this->attributeKey = $attributeKey;
  53. $this->attributeType = $attributeType;
  54. }
  55. /**
  56. * Renders a particular view for an attribute
  57. */
  58. public function render($view, $return = false) {
  59. if ($return) {
  60. ob_start();
  61. }
  62. Loader::element(DIRNAME_ATTRIBUTES . '/' . $view . '_header', array('type' => $this->attributeType));
  63. $js = $this->attributeType->getAttributeTypeFileURL($view . '.js');
  64. $css = $this->attributeType->getAttributeTypeFileURL($view . '.css');
  65. $html = Loader::helper('html');
  66. if ($js != false) {
  67. $this->controller->addHeaderItem($html->javascript($js));
  68. }
  69. if ($css != false) {
  70. $this->controller->addHeaderItem($html->css($css));
  71. }
  72. $this->controller->setupAndRun($view);
  73. extract($this->controller->getSets());
  74. extract($this->controller->getHelperObjects());
  75. $atHandle = $this->attributeType->getAttributeTypeHandle();
  76. if (is_object($attributeKey)) {
  77. $this->controller->set('akID', $this->attributeKey->getAttributeKeyID());
  78. }
  79. if (file_exists(DIR_MODELS . '/' . DIRNAME_ATTRIBUTES . '/' . DIRNAME_ATTRIBUTE_TYPES . '/' . $atHandle . '/' . $view . '.php')) {
  80. $file = DIR_MODELS . '/' . DIRNAME_ATTRIBUTES . '/' . DIRNAME_ATTRIBUTE_TYPES . '/' . $atHandle . '/' . $view . '.php';
  81. }
  82. if (!isset($file) && $this->attributeType->getPackageID() > 0) {
  83. $pkgHandle = PackageList::getHandle($this->attributeType->getPackageID());
  84. $dirp = is_dir(DIR_PACKAGES . '/' . $pkgHandle) ? DIR_PACKAGES . '/' . $pkgHandle : DIR_PACKAGES_CORE . '/' . $pkgHandle;
  85. if (file_exists($dirp . '/' . DIRNAME_MODELS . '/' . DIRNAME_ATTRIBUTES . '/' . DIRNAME_ATTRIBUTE_TYPES . '/' . $atHandle . '/' . $view . '.php')) {
  86. $file = $dirp . '/' . DIRNAME_MODELS . '/' . DIRNAME_ATTRIBUTES . '/' . DIRNAME_ATTRIBUTE_TYPES . '/' . $atHandle . '/' . $view . '.php';
  87. }
  88. }
  89. if (!isset($file)) {
  90. if (file_exists(DIR_MODELS_CORE . '/' . DIRNAME_ATTRIBUTES . '/' . DIRNAME_ATTRIBUTE_TYPES . '/' . $atHandle . '/' . $view . '.php')) {
  91. $file = DIR_MODELS_CORE . '/' . DIRNAME_ATTRIBUTES . '/' . DIRNAME_ATTRIBUTE_TYPES . '/' . $atHandle . '/' . $view . '.php';
  92. }
  93. }
  94. if (isset($file)) {
  95. include($file);
  96. }
  97. Loader::element(DIRNAME_ATTRIBUTES . '/' . $view . '_footer', array('type' => $this->attributeType));
  98. if ($return) {
  99. $contents = ob_get_contents();
  100. ob_end_clean();
  101. return $contents;
  102. }
  103. }
  104. }