public function render() { $m = new Mustache_Engine(array('partials_loader' => new Mustache_Loader_FilesystemLoader(implode(DIRECTORY_SEPARATOR, array(APP, 'views', 'findingaid'))))); $pieces = explode('_', $this->params['id']); $id = $pieces[0]; $component_id = $pieces[1]; $model = new ComponentModel($id, $component_id); $container_list_template = load_template('findingaid/container_list'); $component_template = load_template('findingaid/component'); $container_lists = array(); foreach ($model->container_lists() as $container_list) { $container_list_content = $m->render($container_list_template, $container_list); $container_lists[] = array('container_list' => $container_list_content); } $subcomponents = $model->subcomponents(); $subcomponent_content = array(); foreach ($model->subcomponents() as $subcomponent) { $subcomponent_content[] = array('subcomponent' => $m->render($component_template, array('label' => fa_brevity($subcomponent->title()), 'collapsible' => true, 'scopecontent' => $subcomponent->scopecontent()))); } $component_content = $m->render($component_template, array('label' => fa_brevity($model->title()), 'collapsible' => true, 'container_lists' => $container_lists, 'scopecontent' => $model->scopecontent(), 'subcomponents' => $subcomponent_content)); return array($component_content, array('level' => (string) $model->level(), 'metadata' => array('label' => fa_brevity($model->title()), 'id' => 'demo_id'))); }
/** * Because install, upgrade and remove all are actually the exact same logic for themes. * * Returns false if nothing changed, else will return an array containing all changes. * * @param int $verbosity 0 for standard output, 1 for real-time, 2 for real-time verbose output. * * @return false | array * @throws \InstallerException */ private function _performInstall($verbosity = 0) { $changed = []; $change = $this->_parseAssets(true, $verbosity); if ($change !== false) { $changed = array_merge($changed, $change); } $change = $this->_parseConfigs(true, $verbosity); if ($change !== false) { $changed = array_merge($changed, $change); } // Make sure the version is correct in the database. $c = new \ComponentModel('theme/' . $this->_name); $c->set('version', $this->_version); $c->save(); return sizeof($changed) ? $changed : false; }
public function render_component($renderer, $component_xml) { $component_content = ''; $attributes = $component_xml->attributes(); if (isset($attributes['id'])) { $heading_id = "fa-heading-{$attributes['id']}"; $body_id = "fa-body-{$attributes['id']}"; $component = new ComponentModel($this->params['id'], $attributes['id']); $subcomponent_content = array(); foreach ($component->subcomponents() as $subcomponent) { $subcomponent_details = $this->render_component($renderer, $subcomponent->xml()); $subcomponent_content[] = array('subcomponent' => $subcomponent_details[0]); } $container_lists = array(); foreach ($component->container_lists() as $container_list) { $container_list_content = $renderer->render($this->templates['container_list'], $container_list); $container_lists[] = array('container_list' => $container_list_content); } $component_content = $renderer->render($this->templates['component'], array('label' => fa_brevity($component->title()), 'collapsible' => true, 'container_lists' => $container_lists, 'scopecontent' => $component->scopecontent(), 'links' => $component->links, 'subcomponents' => $subcomponent_content, 'heading_id' => $heading_id, 'body_id' => $body_id)); } else { error_log("FA: attributes_id not set"); } return array($component_content, array('level' => (string) $component->level(), 'metadata' => array('label' => fa_brevity($component->title()), 'id' => $heading_id))); }
/** * Save this package along with all changes back down to the disk and database. * */ public function save(){ $object = $this->_getObject(); $viewdir = $object->getViewSearchDir(); $assetdir = $object->getAssetDir(); $skindir = ($this->_type == 'theme') ? $object->getSkinDir() : null; $basestrlen = strlen($this->_base->getPath()); $assetfiles = []; $viewfiles = []; $otherfiles = []; $skinfiles = []; // Only themes have skins, but this is the new unified save handler, so it needs to be present. // Save out the CHANGELOG before anything happens, that way its updated MD5 will be present in the metafile. $this->_changelog->save(); foreach($this->_iterator as $file){ /** @var FileLocal|DirectoryLocal $file */ // If this ends with a "~", skip it! // These are backup files used by gedit. if(substr($file->getFilename(), -1) == '~'){ continue; } // And then, scan this file for code, ie: classes, controllers, etc. $fname = substr($file->getFilename(), $basestrlen); /* // Skip the component.xml file itself if($fname == 'component.xml'){ continue; } // Applies to themes too if($fname == 'theme.xml'){ continue; }*/ if($viewdir && $file->inDirectory($viewdir)){ // It's a template! (view) $viewfiles[] = ['file' => $fname, 'md5' => $file->getHash()]; } elseif($assetdir && $file->inDirectory($assetdir) && $file->getExtension() == 'scss'){ // SASS/SCSS Files are NOT assets, but other files. $otherfiles[] = ['file' => $fname, 'md5' => $file->getHash()]; } elseif($assetdir && $file->inDirectory($assetdir)){ // It's an asset! $assetfiles[] = ['file' => $fname, 'md5' => $file->getHash()]; } elseif($skindir && $file->inDirectory($skindir)){ // It's a skin! $skinfiles[] = ['file' => $fname, 'md5' => $file->getHash()]; } else{ // It's a something..... it goes in the "files" array! // This will be slightly different though, as it needs to also check for classes. $filedat = [ 'file' => $fname, 'md5' => $file->getHash(), 'controllers' => [], 'classes' => [], 'interfaces' => [] ]; // PHP files get checked. if(preg_match('/\.(php|inc)$/i', $fname)){ $fconts = file_get_contents($file->getFilename()); // Trim out the comments to prevent false readings. // Will remove /* ... */ multi-line comments. $fconts = preg_replace(':/\*.*\*/:Us', '', $fconts); // Will remove // single-line comments. $fconts = preg_replace('://.*$:', '', $fconts); // If there is a namespace on this file, make sure to grab that and prefix any classes! if(preg_match('/^namespace ([a-z\\\\0-9]*);$/im', $fconts, $ret)){ $namespace = $ret[1] . '\\'; } else{ $namespace = ''; } // Well... get the classes! preg_match_all('/^\s*(abstract |final ){0,1}class [ ]*([a-z0-9_\-]*)[ ]*extends[ ]*controller_2_1/im', $fconts, $ret); foreach($ret[2] as $foundclass){ $filedat['controllers'][] = $namespace . $foundclass; } // Add any class found in this file. (skipping the ones I already found) preg_match_all('/^\s*(abstract |final ){0,1}class [ ]*([a-z0-9_\-]*)/im', $fconts, $ret); foreach($ret[2] as $foundclass){ if(in_array($foundclass, $filedat['controllers'])) continue; $filedat['classes'][] = $namespace . $foundclass; } // Allow interfaces to be associated as a provided element too. preg_match_all('/^\s*(interface)[ ]*([a-z0-9_\-]*)/im', $fconts, $ret); foreach($ret[2] as $foundclass){ $filedat['interfaces'][] = $namespace . $foundclass; } } // Empty classes? if(!sizeof($filedat['controllers'])) unset($filedat['controllers']); if(!sizeof($filedat['classes'])) unset($filedat['classes']); if(!sizeof($filedat['interfaces'])) unset($filedat['interfaces']); $otherfiles[] = $filedat; } } $object->setAuthors($this->_authors); $object->setLicenses($this->_licenses); $object->setFiles($otherfiles); $object->setViewFiles($viewfiles); $object->setAssetFiles($assetfiles); if($this->_type == 'theme'){ $object->setSkinFiles($skinfiles); } // If this is not Core, set the required version to the current Core version. if($this->_type != 'core'){ $node = $this->_xmlLoader->getElement('requires/require[@name="core"]'); $node->setAttribute('type', 'component'); $node->setAttribute('version', \Core::GetComponent('core')->getVersion()); $node->setAttribute('operation', 'ge'); } $object->save(); // Update the version installed in the database, since the codebase *was* afterall running with whatever files // were currently available, (and thus were set as the next version). if($this->_type == 'core' || $this->_type == 'component') { $name = $this->_name; } else { $name = 'Theme/' . $this->_name; } $cmodel = \ComponentModel::Construct($name); $cmodel->set('version', $this->_version); $cmodel->save(); // Reload the data from disk, // this is to ensure that subsequent operations on the component are synced up with the disk's data and not just running from memory. switch($this->_type){ case 'theme': $this->_setupTheme(); break; case 'component': $this->_setupComponent(); break; case 'core': $this->_setupCore(); break; } // Don't forget to re-parse the CHANGELOG, otherwise it's lost :/ if(!$this->_changelog->exists()){ $this->_changelog->createInitial($this->_version); } else{ $this->_changelog->parse(); } }
/** * 添加新子菜单 到选中的菜单中 */ function addin() { //父菜单ID $menu_id = $_SESSION['menuid']; //首字母大写 例:Article $type = ucfirst($_POST['type']); $id = $_POST['creat_id']; //查询数据,实例化对象 if ($type == 'Article') { $obj = new ArticleModel(); } else { if ($type == 'Category') { $obj = new CategoryModel(); } else { $obj = new SectionModel(); } } $title = $obj->field('title,description')->find($id); //重写链接 $link = $id; //得到所有父菜单,然后在模板中判断选择 $menus = new MenuModel(); $menu_list = $menus->select(); //得到该父菜单下的所有子菜单 $menu_items = new MenuItemModel(); $where = array('menuid' => $menu_id); $m_items = $menu_items->where($where)->select(); //查询组建,得到相对应组建ID $components = new ComponentModel(); $coms = $components->select(); $count = count($coms); for ($i = 0; $i < $count; $i++) { if ($coms[$i]['link'] == $type) { $componentid = $coms[$i]['id']; } } $this->assign("type_id", $id); $this->assign('menu_id', $menu_id); $this->assign('link', $link); $this->assign('title', $title); $this->assign('menu_list', $menu_list); $this->assign('m_items', $m_items); $this->assign('type', $type); $this->assign('componentid', $componentid); $this->display(); }
/** * Set this component as enabled in the database. */ public function enable(){ // If it's not installed already, it can't be disabled! if($this->isEnabled()) return false; $c = new ComponentModel($this->_name); $c->set('enabled', true); $c->save(); $this->_enabled = true; $changed = array(); $change = $this->_parseUserConfigs(); if ($change !== false) $changed = array_merge($changed, $change); $change = $this->_parsePages(); if ($change !== false) $changed = array_merge($changed, $change); // Do this when I actually have widgets to test. //$change = $this->_parseWidgets(); //if ($change !== false) $changed = array_merge($changed, $change); if(sizeof($changed)){ SystemLogModel::LogInfoEvent('/updater/component/enable', 'Component ' . $this->getName() . ' enabled successfully!', implode("\n", $changed)); } // Ensure that the core component cache is purged too! \Core\Cache::Delete('core-components'); return (sizeof($changed)) ? $changed : false; }