/** * Set plugin name * * @param array $backtrace Output "debug_backtrace" function * * @throws CakeException */ protected static function setPluginName(array $backtrace) { $pluginPath = APP . 'Plugin'; if (!is_readable($pluginPath)) { throw new CakeException(__d('hurad', 'Plugin path is not readable')); } if (strpos($backtrace[0]['file'], $pluginPath) != 0) { throw new CakeException(__d('hurad', 'You should use meta box in plugin')); } $diffPath = Hash::diff(explode(DIRECTORY_SEPARATOR, $backtrace[0]['file']), explode(DIRECTORY_SEPARATOR, $pluginPath)); self::$pluginName = reset($diffPath); }
/** * Load meta boxes in specific position * * @param string $position Meta box position * * @return string */ public function loadMetaBoxes($position) { $metaBoxHtml = []; foreach (HuradMetaBox::getMetaBoxes() as $metaBox) { if ($metaBox['position'] != $position) { continue; } if ($this->_View->elementExists($metaBox['plugin'] . '.' . $metaBox['element'])) { $this->PluginForm->pluginName = $metaBox['plugin']; if ($this->hasFormHelper(file_get_contents(APP . 'Plugin/' . $metaBox['plugin'] . '/View/Elements/' . $metaBox['element'] . '.ctp'))) { $element = __d('hurad', 'You are not use form helper.'); } else { $element = $this->_View->element($metaBox['plugin'] . '.' . $metaBox['element'], ['prefix' => strtolower($metaBox['plugin'])]); } } else { $element = __d('hurad', 'Element not found: "%s"', "Elements/{$metaBox['element']}.ctp"); } $metaBoxHtml[] = <<<HTML <div class="panel panel-default"> <div class="panel-heading">{$metaBox['title']}</div> <div class="panel-body"> {$element} </div> </div> HTML; } $output = implode(' ', $metaBoxHtml); return $output; }