public function indexAction() { // Get, check and setup the parameters if (!($widget_id = $this->getRequest()->getParam("id"))) { throw new Stuffpress_Exception("No widget id provided to the widget controller"); } // Verify if the requested widget exist and get its data $widgets = new Widgets(); if (!($widget = $widgets->getWidget($widget_id))) { throw new Stuffpress_Exception("Invalid widget id"); } // Get the widget properties $properties = new WidgetsProperties(array(Properties::KEY => $widget_id)); $title = $properties->getProperty('title'); $this->view->title = $title ? $title : "Tag cloud"; // Get the archives $db_tags = new Tags(array(Stuffpress_Db_Table::USER => $widget['user_id'])); if ($tags = $db_tags->getTopTags(20)) { $max = $tags[0]['count']; $min = $tags[count($tags) - 1]['count']; sort($tags); $this->view->tags = $tags; $this->view->max = $max; $this->view->min = $min; } }
public function updateMeta($event, Tags $tag) { $meta = $tag->getTagmetaOrNew(); if ($meta->id) { $meta->save(); } }
public function actionCreate() { $request = Yii::app()->request->getIsPostRequest(); $ajaxRequest = Yii::app()->request->getIsAjaxRequest(); if ($request) { $berita = new Berita(); $kategori = new Kategori(); $tags = new Tags(); $image = new Image(); $postBerita = !empty($_POST['Berita']) ? $_POST['Berita'] : ""; $postKategori = !empty($_POST['Kategori']) ? $_POST['Kategori'] : ""; $postTags = !empty($_POST['Tags']) ? $_POST['Tags'] : ""; if ($kategori) { $kategori->setAttributes($postKategori); } if ($tags) { $tags->setAttributes($postTags); } if ($postBerita) { $berita->setAttributes($postBerita); $berita->setCreatetime($postBerita['tgl_create']); $berita->setUpdatetime($postBerita['tgl_update']); } } $jsonData = array(); if ($ajaxRequest) { echo CJSON::encode($jsonData); Yii::app()->end(); } else { $this->render("create", array()); } }
function tagslist() { require_once _base_ . '/lib/lib.table.php'; require_once $GLOBALS['where_framework'] . '/lib/lib.tags.php'; $lang =& DoceboLanguage::createInstance('tags', 'framework'); $id_tag = Get::req('id_tag', DOTY_INT, 0); $tag_name = Get::req('tag', DOTY_STRING, ''); $filter = Get::req('filter', DOTY_STRING, ''); $nav_bar = new NavBar('ini', Get::sett('visuItem'), 0); $nav_bar->setLink('index.php?modname=tags&op=tags&id_tag=' . $id_tag); $ini = $nav_bar->getSelectedElement(); $tags = new Tags('*'); $resources = $tags->getResourceByTags($id_tag, false, false, $ini, Get::sett('visuItem')); $GLOBALS['page']->add(getTitleArea(array($lang->def('_TAGS')), 'tags') . '<div class="std_block">' . '<div class="tag_list">', 'content'); while (list(, $res) = each($resources['list'])) { $link = $res['permalink']; $delim = strpos($link, '?') === false ? '?' : '&'; if (strpos($link, '#') === false) { $link = $link . $delim . 'sop=setcourse&sop_idc=' . $res['id_course']; } else { $link = str_replace('#', $delim . 'sop=setcourse&sop_idc=' . $res['id_course'] . '#', $link); } $GLOBALS['page']->add('' . '<h2>' . '<a href="' . $link . '">' . $res['title'] . '</a>' . '</h2>' . '<p>' . $res['sample_text'] . '</p>' . '<div class="tag_cloud">' . '<span>' . $lang->def('_TAGS') . ' : </span>' . '<ul><li>' . implode('</li><li>', $res['related_tags']) . '</li></ul>' . '</div>' . '<br />', 'content'); } $GLOBALS['page']->add('</div>' . $nav_bar->getNavBar($ini, $resources['count']) . '</div>', 'content'); }
function getProductById($product_id) { $sql = "SELECT p.* FROM {$this->table_prefix}products p WHERE p.id=" . $product_id; $result = $this->dbstuff->GetRow($sql); if (empty($result) || !$result) { return false; } $result['pubdate'] = @date("Y-m-d", $result['created']); if (!empty($result['picture'])) { $result['imgsmall'] = "../" . pb_get_attachmenturl($result['picture']) . ".small.jpg"; $result['imgmiddle'] = "../" . pb_get_attachmenturl($result['picture']) . ".middle.jpg"; $result['image'] = "../" . pb_get_attachmenturl($result['picture']); $result['image_url'] = rawurlencode($result['picture']); } else { $result['image'] = pb_get_attachmenturl('', '', 'middle'); } if (!empty($result['tag_ids'])) { uses("tag"); $tag = new Tags(); $tag_res = $tag->getTagsByIds($result['tag_ids']); if (!empty($tag_res)) { $tags = null; foreach ($tag_res as $key => $val) { $tags .= '<a href="product/list.php?do=search&q=' . urlencode($val) . '" target="_blank">' . $val . '</a> '; } $result['tag'] = $tags; unset($tags, $tag_res, $tag); } } $this->info = $result; return $result; }
private static function addTags($model) { // add tags if (!empty($_POST['tags'])) { $taglist = explode(',', $_POST['tags']); if ($taglist !== false) { foreach ($taglist as &$tag) { if ($tag === '') { continue; } if (substr($tag, 0, 1) != '#') { $tag = '#' . $tag; } $tagModel = new Tags(); $tagModel->taggedBy = 'API'; $tagModel->timestamp = time(); $tagModel->type = get_class($model); $tagModel->itemId = $model->id; $tagModel->tag = $tag; $tagModel->itemName = $model->name; $tagModel->save(); X2Flow::trigger('RecordTagAddTrigger', array('model' => $model, 'tags' => $tag)); } } } }
/** * Assocciates photo with supplied tags, if tags does not exists * they will be created. * * @param Zend_Db_Row $photo * @param array $tagNames */ public function assocciatePhotoWith($photo, array $tagNames) { if ($photo instanceof Yag_Db_Table_Row) { $photoId = $photo->id; } $photoId = $photo; // Remove all references $this->deleteByPhotoId($photoId); $tags = new Tags(); $assoccTags = array(); foreach ($tagNames as $name) { $name = trim($name); // TODO: should be fixed by a filter automagic if ($name == '') { continue; // skip bogus names in array. } $tag = $tags->findByName($name); if (null == $tag) { $tag = $tags->createRow(); $tag->name = (string) $name; $tag->created_on = date('Y-m-d H:i:s'); // TODO: Should be handle behind $tag->save(); } $taggedPhotos = $this->createRow(array('tag_id' => $tag->id, 'photo_id' => $photoId)); $taggedPhotos->save(); $assoccTags[] = $tag; } return $assoccTags; }
public static function findAndAdd($title, $classify, $logid) { $title = zmf::filterInput($title, 't', 1); if (!$title) { return false; } $info = Tags::model()->find('title=:title AND classify=:classify', array(':title' => $title, ':classify' => $classify)); if (!$info) { if (Yii::app()->session['checkHasBadword'] == 'yes') { $status = Posts::STATUS_STAYCHECK; } else { $status = Posts::STATUS_PASSED; } unset(Yii::app()->session['checkHasBadword']); $_data = array('title' => $title, 'name' => tools::pinyin($title), 'classify' => $classify, 'status' => $status, 'cTime' => time(), 'length' => mb_strlen($title, 'GBK')); $modelB = new Tags(); $modelB->attributes = $_data; if ($modelB->save()) { $tagid = $modelB->id; } } else { $tagid = $info['id']; } if ($tagid && $logid) { $_info = TagRelation::model()->find('tagid=:tagid AND logid=:logid AND classify=:classify', array(':tagid' => $tagid, ':logid' => $logid, ':classify' => $classify)); if (!$_info) { $_tagre = array('tagid' => $tagid, 'logid' => $logid, 'classify' => $classify, 'cTime' => zmf::now()); $modelC = new TagRelation(); $modelC->attributes = $_tagre; $modelC->save(); } } return $tagid; }
/** * 列表页 */ public function action_list() { $this->_add_css('styles/album/my_library.css'); $this->_add_script('scripts/dtree.js'); $tag = new Tags(); $cate = new Bookcategory(); $position = trim($this->getQuery('position')); switch ($position) { case 'is_hot': $pageTitle = '热门文章'; break; case 'is_recommend': $pageTitle = '美文推荐'; break; default: $pageTitle = '最新文章'; break; } $this->template->position = $pageTitle; $select = DB::select('a.*', 'cate.cate_name', 'u.username')->from(array('articles', 'a'))->join(array('article_categories', 'cate'))->on('cate.cate_id', '=', 'a.cate_id')->join(array('users', 'u'))->on('u.uid', '=', 'a.uid')->where('a.recycle', '=', 0)->where('a.is_show', '=', 1)->order_by('a.article_id', 'DESC'); if (!empty($position) && $position != 'is_new') { $select->where('a.' . $position, '=', 1); } $this->template->cate_id = $cate_id = trim($this->getQuery('cate_id')); if ($cate_id > 0) { $select->where('a.cate_id', '=', $cate_id); } $this->template->pagination = $pagination = Pagination::factory(array('total_items' => count($select->execute()->as_array()), 'items_per_page' => 30)); $this->template->results = $select->limit($pagination->items_per_page)->offset($pagination->offset)->execute(); $this->template->tags = $tags = $tag->getHotTags('article'); if ($this->auth) { $this->template->categories = $categories = $cate->getCates($this->auth['uid']); } }
public function showTagAction(Users $user, Tags $tag, $page = 1) { $this->view->mytag = $tag; $this->view->page = $this->getPaginator($tag->getTaggedFiles($user), 25, $page); $this->view->form = myForm::buildCommentForm($tag); //这个应该去掉 $this->view->user = $user; }
/** * @covers Instaphp\Instagram\Tags::MultiSearch * @todo Implement testMultiSearch(). */ public function testMultiSearch() { $res = $this->object->multiSearch('test insta', ['count' => 10]); $this->assertNotEmpty($res); $this->assertInstanceOf('\\Instaphp\\Instagram\\Response', $res[0]); $res = $this->object->multiSearch(['test', 'insta'], ['count' => 10]); $this->assertNotEmpty($res); $this->assertInstanceOf('\\Instaphp\\Instagram\\Response', $res[0]); }
public function editAction(Tags $tag) { if ($this->request->isPost()) { $data = $this->request->getPost(); $tag->update($data); $this->redirectByRoute(['for' => 'tags.show', 'tag' => $tag->id]); } $this->view->myTag = $tag; $this->view->form = $this->buildFormFromModel($tag); }
public function getTagByName($name) { $tag = Tags::findFirst(['conditions' => 'name = :name:', 'bind' => ['name' => $name]]); if (null == $tag) { $tag = new Tags(); $tag->name = $name; $tag->save(); } return $tag; }
private function insertRel($value) { try { $this->log->addInfo("Inicia funcion MainPeople::insertRel() "); $tags = new Tags(); $rel = array(0, "lkp_persons", $value->id); $tags->insert($rel); } catch (\Excetion $e) { $this->log->addError($e->getMessage(), array(basename(__FILE__) . "::" . __LINE__)); } }
public function tagsToLinks($item) { $tags = $this->tagsModel->extractTags($item); if ($tags) { foreach ($tags[0] as $index => $tag) { $url = $this->linkFactory->link('Search:default', ['s' => 'tag:' . $tag]); $item = str_replace('[' . $tags[1][$index] . ']', "<a href=\"{$url}\"><span class=\"label label-info\">{$tag}</span></a> ", $item); } } return $item; }
function populate() { $t = new Tags(); $this->tags = $t->allTags; $this->folders[0] = new FeedFolder(null, null, $this); foreach ($this->tags as $tag => $count) { $this->tagCount++; $this->countTaggedItems += $count; $tt = new TagListItem($tag, $count, $t->makeTagLink($tag)); $this->folders[0]->feeds[] = $tt; } }
public function incTagsData($startDate, $endDate) { $INC = new Incomes(); $Tags = new Tags(); $inctags = []; $allTags = $Tags->find('all'); foreach ($allTags as $tag) { $amount = (int) $this->db->query("SELECT Sum(inc.cost ) as total FROM inc_tags as tag,incomes as inc where tag_id = ? and inc.inc_id = tag.inc_id and inc.date >= ? and inc.date <= ? ", [$tag->id, $startDate, $endDate])->first()->total; if ($amount > 0) { $inctags[$tag->name] = $amount; } } return $inctags; }
public function expTagsData($user_id, $startDate, $endDate) { $EXP = new Expenses(); $Tags = new Tags(); $exptags = []; $allTags = $Tags->find('all'); foreach ($allTags as $tag) { $amount = (int) $this->db->query("SELECT Sum(exp.cost ) as total FROM exp_tags as tag,expenses as exp where tag_id = ? and exp.exp_id = tag.exp_id and exp.date >= ? and exp.date <= ? and exp.user_id = ?", [$tag->id, $startDate, $endDate, $user_id])->first()->total; if ($amount > 0) { $exptags[$tag->name] = $amount; } } return $exptags; }
public function testAction() { $authors = new Authors(); $me = $authors->find(1)->current(); echo '<span>' . $me->name() . '</span>'; $meAgain = $authors->fetchRow('id = 3'); $pubs = $meAgain->findDependentRowset('Entry')->toArray(); //Zend_Debug::dump($pubs); // list of entries by tag "Test tag 1" $tags = new Tags(); $firstTag = $tags->fetchRow('id = 2'); $tagEntries = $firstTag->findManyToManyRowset('Entry', 'TagsLinks')->toArray(); //Zend_Debug::dump($tagEntries); }
public function test_create_post() { $tags = array('one', 'two', 'THREE'); $params = array( 'title' => 'A post title', 'content' => 'Some great content. Really.', 'user_id' => $this->user->id, 'status' => Post::status('published'), 'content_type' => Post::type('entry'), 'tags' => 'one, two, THREE', 'pubdate' => HabariDateTime::date_create( time() ), ); $post = Post::create($params); $this->assert_true( $post instanceof Post, 'Post should be created.' ); // Check the post's id is set. $this->assert_true( (int)$post->id > 0, 'The Post id should be greater than zero' ); // Check the post's tags are usable. $this->assert_equal(count($post->tags), count($tags), 'All tags should have been created.'); foreach ( $post->tags as $tag ) { $this->assert_equal($tag->tag_slug, Utils::slugify($tag->tag_text), 'Tags key should be slugified tag.'); } foreach( $post->tags as $tag ) { Tags::vocabulary()->delete_term( $tag ); } }
function getInstance() { if (!isset(self::$instance[get_class()])) { self::$instance = new Tags(); } return self::$instance; }
/** * Handles get requests for the dashboard * @todo update check should probably be cron'd and cached, not re-checked every load */ public function get_dashboard() { // Not sure how best to determine this yet, maybe set an option on install, maybe do this: $firstpostdate = DB::get_value('SELECT min(pubdate) FROM {posts} WHERE status = ?', array(Post::status('published'))); $this->theme->active_time = HabariDateTime::date_create($firstpostdate); // get the active theme, so we can check it // @todo this should be worked into the main Update::check() code for registering beacons $active_theme = Themes::get_active(); $active_theme = $active_theme->name . ':' . $active_theme->version; // check to see if we have updates to display $this->theme->updates = Options::get('updates_available', array()); // collect all the stats we display on the dashboard $this->theme->stats = array('author_count' => Users::get(array('count' => 1)), 'page_count' => Posts::get(array('count' => 1, 'content_type' => Post::type('page'), 'status' => Post::status('published'))), 'entry_count' => Posts::get(array('count' => 1, 'content_type' => Post::type('entry'), 'status' => Post::status('published'))), 'comment_count' => Comments::count_total(Comment::STATUS_APPROVED, false), 'tag_count' => Tags::vocabulary()->count_total(), 'page_draft_count' => Posts::get(array('count' => 1, 'content_type' => Post::type('page'), 'status' => Post::status('draft'), 'user_id' => User::identify()->id)), 'entry_draft_count' => Posts::get(array('count' => 1, 'content_type' => Post::type('entry'), 'status' => Post::status('draft'), 'user_id' => User::identify()->id)), 'unapproved_comment_count' => User::identify()->can('manage_all_comments') ? Comments::count_total(Comment::STATUS_UNAPPROVED, false) : Comments::count_by_author(User::identify()->id, Comment::STATUS_UNAPPROVED), 'spam_comment_count' => User::identify()->can('manage_all_comments') ? Comments::count_total(Comment::STATUS_SPAM, false) : Comments::count_by_author(User::identify()->id, Comment::STATUS_SPAM), 'user_entry_scheduled_count' => Posts::get(array('count' => 1, 'content_type' => Post::type('any'), 'status' => Post::status('scheduled'), 'user_id' => User::identify()->id))); $this->fetch_dashboard_modules(); // check for first run $u = User::identify(); if (!isset($u->info->experience_level)) { $this->theme->first_run = true; $u->info->experience_level = 'user'; $u->info->commit(); } else { $this->theme->first_run = false; } $this->display('dashboard'); }
public function action_post_update_before($post) { $aliases = self::get_aliases(); if (Options::get('tagrewriter__plurals') != NULL && Options::get('tagrewriter__plurals') == 1) { $pluralize = true; } else { $pluralize = false; } $tags = array(); foreach ($post->tags as $tag) { if (isset($aliases[$tag])) { $tags[] = $aliases[$tag]; continue; } if ($pluralize) { if (Tags::get_by_slug($tag . 's') != false) { $tags[] = $tag . 's'; continue; } elseif (Tags::get_by_slug(rtrim($tag, 's')) != false) { $tags[] = rtrim($tag, 's'); continue; } } $tags[] = $tag; } $post->tags = $tags; }
/** * Add additional template variables to the template output. * * You can assign additional output values in the template here, instead of * having the PHP execute directly in the template. The advantage is that * you would easily be able to switch between template types (RawPHP/Smarty) * without having to port code from one to the other. * * You could use this area to provide "recent comments" data to the template, * for instance. * * Note that the variables added here should possibly *always* be added, * especially 'user'. * * Also, this function gets executed *after* regular data is assigned to the * template. So the values here, unless checked, will overwrite any existing * values. */ public function add_template_vars() { if (!$this->template_engine->assigned('pages')) { $this->assign('pages', Posts::get(array('content_type' => 'page', 'status' => Post::status('published'), 'nolimit' => 1))); } if (!$this->template_engine->assigned('user')) { $this->assign('user', User::identify()); } if (!$this->template_engine->assigned('tags')) { $this->assign('tags', Tags::get()); } if (!$this->template_engine->assigned('page')) { $this->assign('page', isset($page) ? $page : 1); } if (!$this->template_engine->assigned('feed_alternate')) { $matched_rule = URL::get_matched_rule(); switch ($matched_rule->name) { case 'display_entry': case 'display_page': $feed_alternate = URL::get('atom_entry', array('slug' => Controller::get_var('slug'))); break; case 'display_entries_by_tag': $feed_alternate = URL::get('atom_feed_tag', array('tag' => Controller::get_var('tag'))); break; case 'display_home': default: $feed_alternate = URL::get('atom_feed', array('index' => '1')); } $this->assign('feed_alternate', $feed_alternate); } // Specify pages you want in your navigation here $this->assign('nav_pages', Posts::get(array('content_type' => 'page', 'status' => 'published', 'nolimit' => 1))); parent::add_template_vars(); }
/** * Get a list of tags based on current GET parameters. * * @access private * @param string $extra_where Where clause to add to lookup query; * it is caller's responsibility to * make sure this is safe!! * @return array Tag details. */ private function getTagList($extra_where = '') { $tagList = array(); $tag = new Tags(); $sql = "SELECT tags.tag, COUNT(resource_tags.id) as cnt " . "FROM tags, resource_tags " . "WHERE tags.id = resource_tags.tag_id{$extra_where} GROUP BY tags.tag"; switch ($_GET['findby']) { case 'alphabetical': $sql .= " ORDER BY tags.tag, cnt DESC"; break; case 'popularity': $sql .= " ORDER BY cnt DESC, tags.tag"; break; case 'recent': $sql .= " ORDER BY resource_tags.posted DESC, cnt DESC, tags.tag"; break; } // Limit the size of our results based on the ini browse limit setting $browseLimit = isset($configArray['Browse']['result_limit']) ? $configArray['Browse']['result_limit'] : 100; $sql .= " LIMIT " . $browseLimit; $tag->query($sql); if ($tag->N) { while ($tag->fetch()) { $tagList[] = clone $tag; } } return $tagList; }
/** * 查看相片 */ public function action_view() { $tag = new Tags(); $this->template->pid = $pid = $this->request->param('id'); $imgSelect = DB::select('i.id', 'i.cate_id', 'i.uploadtime', 'i.picname', 'i.userid', 'i.disk_id', 'i.picname', 'i.custom_name', array('i.disk_id', 'disk_domain'), 'i.click', 'i.comment_num', 'i.support', 'i.oppose', array('i.disk_name', 'img_dir'))->from(array('imgs', 'i'))->order_by('i.id', 'DESC'); $imgInfo = $imgSelect->where('i.id', '=', (int) $pid)->fetch_row(); $this->template->pageTitle = $imgInfo['custom_name']; $imgInfo['cate_name'] = DB::select('cate_name')->from('img_categories')->where('cate_id', '=', (int) $imgInfo['cate_id'])->fetch_one(); $user = ORM::factory('user', $imgInfo['userid']); $imgInfo['username'] = $user->username; $imgInfo['avatar'] = $user->avatar; $imgInfo['uid'] = $user->uid; $imgInfo['sign'] = ORM::factory('user_field', (int) $imgInfo['userid'])->sign; $this->template->imgInfo = $imgInfo; if (empty($imgInfo)) { $this->show_message('非法访问', 0, array(), true); } if ($user->status != 'approved' || $user->expire_time < time()) { $links[] = array('text' => '返回首页', 'href' => '/'); $this->show_message('该用户已经过期或者禁止,不允许访问其所属的图片', 1, $links, true, 10000); } $this->template->tags = $tags = $tag->get($pid, 'img'); $select = DB::select('c.*', 'u.username', 'u.avatar')->from(array('comments', 'c'))->where('c.item_id', '=', (int) $pid)->where('c.app', '=', 'img')->join(array('users', 'u'), 'LEFT')->on('u.uid', '=', 'c.author'); $this->template->commentList = $select->execute()->as_array(); if ($this->isPost()) { $tags = trim($this->getPost('tags')); $pid = (int) $this->getPost('pid'); $tags = explode(' ', $tags); $tag->add($pid, 'img', $tags, $imgInfo['userid']); $this->request->redirect('/' . $pid . '.html'); } // 更新访问量 DB::update('users')->set(array('visit' => DB::expr("visit + 1")))->where('uid', '=', (int) $imgInfo['userid'])->execute(); DB::update('imgs')->set(array('click' => DB::expr('click + 1')))->where('id', '=', (int) $pid)->execute(); }
public static function get_stat($type, $month = NULL) { $str = 'chicklet_stat_' . $type; if ($month != NULL) { $str .= '_' . $month; } if (Cache::has($str)) { return Cache::get($str); } switch ($type) { case 'entries': case 'posts': $params = array('content_type' => array(Post::type('entry'), Post::type('link')), 'nolimit' => TRUE); $stat = count(Posts::get($params)); break; case 'subscribers': $stat = self::fetch(); break; case 'comments': $stat = Comments::count_total(Comment::STATUS_APPROVED); break; case 'tags': $stat = count(Tags::vocabulary()->get_tree()); break; default: $stat = 0; break; } Cache::set($str, $stat); return $stat; }
/** * Respond to Javascript callbacks * The name of this method is action_ajax_ followed by what you passed to the context parameter above. */ public function action_ajax_auto_tags( $handler ) { $selected = array(); if( isset( $handler->handler_vars['selected'] ) ) { $selected = Utils::single_array( $handler->handler_vars['selected'] ); } if( isset( $handler->handler_vars['term'] ) && MultiByte::strlen( $handler->handler_vars['term'] ) ) { $search = $handler->handler_vars['term'] . '%'; $tags = new Terms( DB::get_results( "SELECT * FROM {terms} WHERE vocabulary_id = :vid and LOWER(term_display) LIKE LOWER(:crit) ORDER BY term_display ASC", array( 'vid' => Tags::vocabulary()->id, 'crit' => $search ), 'Term' ) ); } else { $tags = Tags::vocabulary()->get_tree( 'term_display ASC' ); } $resp = array(); foreach ( $tags as $tag ) { $resp[] = MultiByte::strpos( $tag->term_display, ',' ) === false ? $tag->term_display : $tag->tag_text_searchable; } if( count( $selected ) ) { $resp = array_diff($resp, $selected ); } // Send the response // $ar = new AjaxResponse(); // $ar->data = $resp; // $ar->out(); echo json_encode( $resp ); }
/** * Create a service * @link https://apidocs.serverdensity.com/?python#creating-a-service * @param array $service with all it's attributes. * @return an array that is the device. */ public function create($service, array $tagNames = array()) { if (!empty($tagNames)) { $tagEndpoint = new Tags($this->client); $tags = $tagEndpoint->findAll($tagNames); if (!empty($tags['notFound'])) { foreach ($tags['notFound'] as $name) { $tags['tags'][] = $tagEndpoint->create($name); } } $formattedTags = $tagEndpoint->format($tags['tags'], 'other'); $service['tags'] = $formattedTags['tags']; } $service = $this->makeJsonReady($service); return $this->post('inventory/services/', $service); }
/** * Retrieve a JSON object containing autocomplete suggestions for existing users. */ public function action_tag() { $string = $this->request->param('string', FALSE); $type = $this->request->param('type', 'blog'); // The user enters a comma-separated list of tags. We only autocomplete the last tag. $tags_typed = Tags::explode($string); $tag_last = UTF8::strtolower(array_pop($tags_typed)); $matches = array(); if (!empty($tag_last)) { $query = DB::select('name')->from('tags')->where('name', 'LIKE', $tag_last . '%')->where('type', '=', $type); // Do not select already entered terms. if (!empty($tags_typed)) { $query->where('name', 'NOT IN', $tags_typed); } $result = $query->limit('10')->execute(); $prefix = count($tags_typed) ? implode(', ', $tags_typed) . ', ' : ''; foreach ($result as $tag) { $n = $tag['name']; // Tag names containing commas or quotes must be wrapped in quotes. if (strpos($tag['name'], ',') !== FALSE or strpos($tag['name'], '"') !== FALSE) { $n = '"' . str_replace('"', '""', $tag['name']) . '"'; } else { $matches[$prefix . $n] = Text::plain($tag['name']); } } } $this->response->body(JSON::encode($matches)); }