public static function tagsExists($name) { if (empty($name)) { return; } if ($id_cms_tag = self::existsByTagName($name)) { return $id_cms_tag; } $tag = new CMSTag(); $tag->copyFromPost(); $tag->name = pSQL($name); $tag->rewrite = pSQL('post-tag-' . $name . '.html'); $tag->add(); return $tag->id; }
<?php if (Tools::P('saveCMSTag') == 'add') { $cmstag = new CMSTag(); $cmstag->copyFromPost(); $cmstag->add(); if (is_array($cmstag->_errors) && count($cmstag->_errors) > 0) { $errors = $cmstag->_errors; } else { $_GET['id'] = $cmstag->id; UIAdminAlerts::conf('CMS标签已添加'); } } if (isset($_GET['id'])) { $id = (int) $_GET['id']; $obj = new CMSTag($id); } if (Tools::P('saveCMSTag') == 'edit') { if (Validate::isLoadedObject($obj)) { $obj->copyFromPost(); $obj->update(); } if (is_array($obj->_errors) and count($obj->_errors) > 0) { $errors = $obj->_errors; } else { UIAdminAlerts::conf('CMS标签已更新'); } } $breadcrumb = new UIAdminBreadcrumb(); $breadcrumb->home(); $breadcrumb->add(array('title' => 'CMS标签', 'href' => 'index.php?rule=cms_tag'));
<?php if (Tools::G('delete') > 0) { $object = new CMSTag(Tools::G('delete')); if (Validate::isLoadedObject($object)) { $object->delete(); } if (is_array($object->_errors) and count($object->_errors) > 0) { $errors = $object->_errors; } else { UIAdminAlerts::conf('标签已删除'); } } elseif (Tools::isSubmit('subDelete')) { $select_cat = Tools::P('categoryBox'); $cmstag = new CMSTag(); if ($cmstag->deleteSelection($select_cat)) { UIAdminAlerts::conf('标签已删除'); } } if (isset($errors)) { UIAdminAlerts::MError($errors); } $table = new UIAdminTable('cms_tag', 'CMSTag', 'id_cms_tag'); $table->header = array(array('sort' => false, 'isCheckAll' => 'itemsBox[]', 'name' => 'id_cms_tag'), array('name' => 'id_cms_tag', 'title' => 'ID', 'filter' => 'string'), array('name' => 'name', 'title' => '名称', 'filter' => 'string'), array('name' => 'rewrite', 'title' => 'URL', 'filter' => 'string'), array('name' => 'add_date', 'title' => '添加时间'), array('sort' => false, 'title' => '操作', 'class' => 'text-right', 'isAction' => array('edit', 'delete'))); $filter = $table->initFilter(); $orderBy = isset($_GET['orderby']) ? Tools::G('orderby') : 'id_cms_tag'; $orderWay = isset($_GET['orderway']) ? Tools::G('orderway') : 'desc'; $limit = $cookie->getPost('pagination') ? $cookie->getPost('pagination') : '50'; $p = Tools::G('p') ? Tools::G('p') == 0 ? 1 : Tools::G('p') : 1; $result = CMSTag::loadData($p, $limit, $orderBy, $orderWay, $filter); $breadcrumb = new UIAdminBreadcrumb();
public function addToTags($tags) { if (empty($tags)) { return false; } $currenTags = $this->getTags(); $tagCats = array(); foreach ($tags as $t) { $id_cms_tag = CMSTag::tagsExists($t); if (!in_array($t, $currenTags) && $id_cms_tag) { $tagCats[] = '(' . $this->id . ', ' . $id_cms_tag . ')'; } } if (sizeof($tagCats)) { return Db::getInstance()->exec(' INSERT INTO `' . DB_PREFIX . 'cms_to_tag` (`id_cms`, `id_cms_tag`) VALUES ' . implode(',', $tagCats)); } return true; }