public function createSlug() { if ($this->slug) { return $slug; } else { $parent = Content::find($this->tmp_parent_id); if ($this->title) { $pageSlug = $this->title; } else { if ($this->name) { $pageSlug = $this->name; } else { $pageSlug = uniqid(); } } $pageSlug = str_replace(" ", "-", $pageSlug); //spaces $pageSlug = urlencode($pageSlug); //last ditch attempt to sanitise $wholeSlug = rtrim(@$parent->slug, "/") . "/{$pageSlug}"; //does it already exist? if (Content::where("slug", "=", $wholeSlug)->first()) { //it already exists.. find the highest numbered example and increment 1. $highest = Content::where('slug', 'like', "{$wholeSlug}-%")->orderBy('slug', 'desc')->first(); $num = 1; if ($highest) { $num = str_replace("{$wholeSlug}-", "", $highest->slug); $num++; } return "{$wholeSlug}-{$num}"; } else { return $wholeSlug; } } }
/** * コンテンツメタ情報を更新する * * @param string $contentCategory * @return boolean * @access public */ public function updateContentMeta(Model $model) { $db = ConnectionManager::getDataSource('baser'); $contentCategories = array(); $contentTypes = array(); if ($db->config['datasource'] == 'Database/BcCsv') { // CSVの場合GROUP BYが利用できない(baserCMS 2.0.2) $contents = $this->Content->find('all', array('conditions' => array('Content.status' => true))); foreach ($contents as $content) { if ($content['Content']['category'] && !in_array($content['Content']['category'], $contentCategories)) { $contentCategories[$content['Content']['category']] = $content['Content']['category']; } if ($content['Content']['type'] && !in_array($content['Content']['type'], $contentTypes)) { $contentTypes[$content['Content']['type']] = $content['Content']['type']; } } } else { $contents = $this->Content->find('all', array('fields' => array('Content.category'), 'group' => array('Content.category'), 'conditions' => array('Content.status' => true))); foreach ($contents as $content) { if ($content['Content']['category']) { $contentCategories[$content['Content']['category']] = $content['Content']['category']; } } $contents = $this->Content->find('all', array('fields' => array('Content.type'), 'group' => array('Content.type'), 'conditions' => array('Content.status' => true))); foreach ($contents as $content) { if ($content['Content']['type']) { $contentTypes[$content['Content']['type']] = $content['Content']['type']; } } } $siteConfigs['SiteConfig']['content_categories'] = BcUtil::serialize($contentCategories); $siteConfigs['SiteConfig']['content_types'] = BcUtil::serialize($contentTypes); $SiteConfig = ClassRegistry::init('SiteConfig'); return $SiteConfig->saveKeyValue($siteConfigs); }
public function newDownload() { $download = ''; if (Input::has('id')) { $download = Content::find(Input::get('id')); } else { $download = new Content(); } return View::make('admin/downloads/new')->withDownloads($download); }
public function editStoreContentEdit($id) { $content = Content::find($id); $t = Input::get('title'); $c = Input::get('content'); if (empty($t) or empty($c)) { return View::make('admin.contentedit.edit')->withContents($content)->withErrors(['msg' => ['Все поля должны быть заполнены!!!']]); } $content->title = $t; $content->content = $c; $content->save(); return Redirect::to('/admin/contentedit')->withErrors(['msg' => ['Контент ' . $content->title . ' changed!']]); }
/** * returns the full path to teh page */ public function realPath($pageId) { $c = new Content(); $page = $c->find($pageId)->current(); if ($page) { $parents = $c->getParents($pageId); if (is_array($parents) && count($parents) > 0) { $path = implode('/', $parents) . '/'; } $fullpath = $path . $page->title; return strtolower($fullpath); } }
public function control_panel__post_publish($publish_data) { // check that caching is turned on if (!$this->core->isEnabled()) { return; } // we only need one key from the hook's value $file = $publish_data['file']; // update the cache _Cache::update(); ContentService::loadCache(true); // grab data $triggers = $this->fetchConfig('publish_invalidation', array(), 'is_array', false, false); $content = Content::find(Path::tidy(str_replace(Config::getContentRoot(), '/', $file))); if ($triggers && $content) { foreach ($triggers as $trigger) { $folders = Parse::pipeList(array_get($trigger, 'folder', null)); $key = array_get($trigger, 'key', null); if (!$folders || !$key) { // not checking this continue; } // check $invalidate = false; foreach ($folders as $folder) { if ($folder === "*" || $folder === "/*") { // include all $invalidate = true; break; } elseif (substr($folder, -1) === "*") { // wildcard check if (strpos($content['_folder'], substr($folder, 0, -1)) === 0) { $invalidate = true; break; } } else { // plain check if ($folder == $content['_folder']) { $invalidate = true; break; } } } // invalidate if needed if ($invalidate) { $this->core->deleteByKey(Parse::pipeList($key)); } } } }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function anyDestroy($id = null) { if (!$id) { $id = \Input::all(); if (@$id['id'] == '#') { $id = ''; } else { $id = @$id['id']; } } $this->content->find($id)->delete(); if (!\Request::ajax()) { return redirect()->action('\\Bootleg\\Cms\\ContentsController@anyIndex'); } }
/** * Enter description here... * * @param string $token * @param integer $editMode * @return string */ function show($token = "", $editMode = true) { if (empty($token)) { return ''; } $out = ""; $id = ""; $ses_LNG = $this->Session->read('User.Lang'); $langId = $ses_LNG['id']; $objContent = new Content(); $content = $objContent->find('first', array('contain' => array(), 'conditions' => array('token' => $token, 'language_id' => $langId))); if (!empty($content)) { $out = $content['Content']['content']; $id = $content['Content']['id']; } else { //Get content for default Language $content = $objContent->find('first', array('contain' => array(), 'conditions' => array('token' => $token, 'language_id' => DEFAULT_LANG_ID))); if (!empty($content)) { $out = $content['Content']['content']; $id = $content['Content']['id']; } else { /*Create New content*/ $defaultContent = array('Content' => array('token' => $token, 'language_id' => DEFAULT_LANG_ID, 'title' => '', 'content' => $token)); //array $objContent->save($defaultContent); $id = $objContent->getLastInsertID(); $out = $token; } } //else if ($editMode) { $out = '<span class="token">' . '<span class="data" id="token' . $id . '" >' . $out . '</span>' . $this->Html->link($this->Html->image('editable.gif', array('alt' => 'edit')), "/contents/edittoken/{$id}?KeepThis=true&TB_iframe=true&height=500&width=680", array('class' => 'thickbox', 'title' => 'edit'), null, false) . '</span>'; } //if return $out; }
public function delete(array $input) { if (isset($input['id'])) { $id = $input['id']; /* @var $content Content */ $content = Content::find($id); $category = $content->category()->first(); if ($category != null) { $category_id = $category->id; $category = Category::find($category_id); $category->contents()->detach($content->id); } return [$content->delete()]; } else { return [false]; } }
public function content() { $mid = Q('mid', 0, 'intval'); $cid = Q('cid', 0, 'intval'); $aid = Q('aid', 0, 'intval'); if (!$mid || !$cid || !$aid) { $this->error('参数错误', __ROOT__); } $ContentModel = new Content($mid); $field = $ContentModel->find($aid); if ($field) { $field['time'] = date("Y/m/d", $field['addtime']); $field['date_before'] = date_before($field['addtime']); $field['commentnum'] = M("comment")->where("cid=" . $cid . " AND aid=" . $aid)->count(); $this->assign('hdcms', $field); $this->display($field['template']); } }
/** * コンテンツリストをツリー構造で取得する * * @param $id * @param null $level * @param array $options * @return array */ public function getTree($id = 1, $level = null, $options = []) { $options = array_merge(['type' => '', 'order' => ['Content.site_id', 'Content.lft']], $options); $conditions = array_merge($this->_Content->getConditionAllowPublish(), ['Content.id' => $id]); $content = $this->_Content->find('first', ['conditions' => $conditions, 'cache' => false]); if (!$content) { return []; } $conditions = array_merge($this->_Content->getConditionAllowPublish(), ['Content.site_root' => false, 'rght <' => $content['Content']['rght'], 'lft >' => $content['Content']['lft']]); if ($level) { $level = $level + $content['Content']['level'] + 1; $conditions['Content.level <'] = $level; } if (!empty($options['type'])) { $conditions['Content.type'] = ['ContentFolder', $options['type']]; } if (!empty($options['conditions'])) { $conditions = array_merge($conditions, $options['conditions']); } // CAUTION CakePHP2系では、fields を指定すると正常なデータが取得できない return $this->_Content->find('threaded', ['order' => $options['order'], 'conditions' => $conditions, 'recursive' => 0, 'cache' => false]); }
public function category($cid, $page = 1) { $categoryCache = cache('category'); $cat = $categoryCache[$cid]; $GLOBALS['totalPage'] = 0; if ($cat['cat_url_type'] == 2 || $cat['cattype'] == 3) { return true; } //单文章 if ($cat['cattype'] == 4) { $Model = ContentViewModel::getInstance($cat['mid']); $result = $Model->join()->where("cid={$cat['cid']}")->find(); if ($result) { $Content = new Content($cat['mid']); $data = $Content->find($result['aid']); return $this->content($data); } } else { //普通栏目与封面栏目 $htmlDir = C("HTML_PATH") ? C("HTML_PATH") . '/' : ''; $_REQUEST['page'] = $_GET['page'] = $page; $_REQUEST['mid'] = $cat['mid']; $_REQUEST['cid'] = $cat['cid']; $Model = ContentViewModel::getInstance($cat['mid']); $catid = getCategory($cat['cid']); $cat['content_num'] = $Model->join()->where("cid IN(" . implode(',', $catid) . ")")->count(); $cat['comment_num'] = intval(M('comment')->where("cid IN(" . implode(',', $catid) . ")")->count()); $htmlFile = $htmlDir . str_replace(array('{catdir}', '{cid}', '{page}'), array($cat['catdir'], $cat['cid'], $page), $cat['cat_html_url']); $info = explode('.', $htmlFile); $this->assign("hdcms", $cat); $this->createHtml(basename($info[0]), dirname($htmlFile) . '/', $cat['template']); //第1页时复制index.html if ($page == 1) { copy($htmlFile, dirname($htmlFile) . '/index.html'); } return true; } }
public function indexAction() { $page = $this->request->get('page', 'int', 0); if ($page < 1) { $page = 0; $this->view->pageType = 1; $this->view->prepage = 0; $this->view->nextpage = $this->_pageSize; } else { if ($page > $this->_allCount) { $page = $this->_allCount; $this->view->pageType = 3; $this->view->prepage = $this->_allCount - $this->_pageSize; $this->view->nextpage = $this->_pageSize; } else { $this->view->pageType = 2; $this->view->prepage = $page - $this->_pageSize; $this->view->nextpage = $page + $this->_pageSize; } } $this->view->number = $page; $this->view->data = Content::find(array('limit' => $this->_pageSize, 'offset' => $page)); }
public function content() { $mid = Q('mid', 0, 'intval'); $cid = Q('cid', 0, 'intval'); $aid = Q('aid', 0, 'intval'); if (!$mid || !$cid || !$aid) { _404(); } $ContentAccessModel = K('ContentAccess'); if (!$ContentAccessModel->isShow($cid)) { $this->error('你没有阅读权限'); } $CacheTime = C('CACHE_CONTENT') >= 1 ? C('CACHE_CONTENT') : null; if (!$this->isCache()) { $ContentModel = new Content($mid); $field = $ContentModel->find($aid); if ($field) { $this->assign('hdcms', $field); $this->display($field['template'], $CacheTime); } } else { $this->display(null, $CacheTime); } }
function index_put() { $data = $this->put(); // echo '<pre>';print_r($data);die; if ($this->put('request') == 'update') { $content = Content::find($data['content'][0]['id']); // print_r($data['content']); $content->body = $data['content'][0]['body']; $content->save(); } else { if ($this->put('request') == 'delete') { $content = Menu::find($data['id']); $content->active = 0; $content->save(); } else { if ($this->put('request') == 'enable') { $content = Menu::find($data['id']); $content->active = 1; $content->save(); } } } $this->response($content); }
App::import('Model', 'SiteConfig'); $SiteConfig = new SiteConfig(); $siteConfig = $SiteConfig->findExpanded(); $siteConfig['content_types'] = ''; if ($SiteConfig->saveKeyValue($siteConfig)) { $this->setMessage('site_configs テーブルのデータ更新に成功しました。'); } else { $this->setMessage('site_configs テーブルのデータ更新に失敗しました。', true); } /** * contents データ更新 */ $result = true; App::import('Model', 'Content'); $Content = new Content(); $contents = $Content->find('all', array('cache' => false)); if ($contents) { foreach ($contents as $content) { $content['Content']['priority'] = '0.5'; switch ($content['Content']['model']) { case 'Page': $type = 'ページ'; break; case 'BlogPost': $type = 'ブログ'; break; default: $type = ''; } $content['Content']['type'] = $type; $Content->set($content);
public function status() { $content = Content::find(Input::get('id')); $content->active = Input::get('status'); if ($content->save()) { return Redirect::back()->with('event', Input::get('status') == 0 ? '<p class="alert alert-success"><span class="glyphicon glyphicon-ok"></span> Content has been deactivated</p>' : '<p class="alert alert-success"><span class="glyphicon glyphicon-ok"></span> Content has been activated</p>'); } else { return Redirect::back()->with('event', '<p class="alert alert-danger"><span class="glyphicon glyphicon-remove"></span> Error occured. Please try after sometime</p>'); } }
public function editContent($id = false) { if ($content = Content::find($id)) { return View::make('content.edit')->withContent($content); } return Redirect::back()->withErrors('Content not found!'); }
/** * Enter description here... * * @param unknown_type $token * @return unknown */ function getcontent($token = null) { if (empty($token)) { return ''; } $langId = $this->Session->read('User.Lang.id'); $objContent = new Content(); $content = $objContent->find('first', array('contain' => array(), 'conditions' => array('token' => $token, 'language_id' => $langId))); //find if (!empty($content)) { $out = $content['Content']['content']; $id = $content['Content']['id']; } else { //is there any tokens with this name $content = $objContent->findByToken($token); if (!empty($content)) { $groupId = $content['Content']['contentgroup_id']; } else { $objGroup = new Contentgroup(); $group = $objGroup->findByName('General'); unset($objGroup); $groupId = $group['Contentgroup']['id']; } //if $defaultContent = $objContent->find(array('token' => $token, 'language_id' => $this->Session->read('DefaultLang.id'))); //find if (empty($defaultContent)) { $defaultContent = array('Content' => array('token' => $token, 'language_id' => $this->Session->read('DefaultLang.id'), 'title' => '', 'content' => '<:empty:>', 'contentgroup_id' => $groupId)); //array $objContent->save($defaultContent); $id = $objContent->getLastInsertID(); } else { $id = $defaultContent['Content']['id']; } //if $out = $defaultContent['Content']['content']; } //if return $out; }
public function BatchContent() { $this->RedirectInfo = F('RedirectInfo'); $createCategory = F('createContentFile'); if (empty($createCategory)) { if ($this->RedirectInfo) { $redirect = array_shift($this->RedirectInfo); F('RedirectInfo', $this->RedirectInfo); $this->success($redirect['title'], $redirect['url'], 0); } else { $this->success('所有文章生成完毕...', U('create_content'), 0); } } $html = new Html(); $modelCache = cache('model'); $categorycache = cache('category'); $oldCategory = $createCategory; foreach ($oldCategory as $id => $category) { $options = $category['options']; $contentModel = ContentViewModel::getInstance($category['mid']); $limit = $options['currentNum'] . ',' . $options['step_row']; $contentData = $contentModel->join('category')->where($options['where'])->limit($limit)->all(); if (empty($contentData)) { unset($createCategory[$id]); F('createContentFile', $createCategory); $this->success("[{$category['catname']}]文章生成完毕...", __METH__, 0); } $Content = new Content($category['mid']); foreach ($contentData as $content) { $html->content($Content->find($content['aid'])); } $options['currentNum'] = $options['currentNum'] + $options['step_row'] - 1; if ($options['currentNum'] >= $options['total_row']) { unset($createCategory[$id]); F('createContentFile', $createCategory); $this->success("[{$category['catname']}] 生成完毕...", __METH__, 0); } else { $createCategory[$id]['options'] = $options; F('createContentFile', $createCategory); $createCategory[$id]['options'] = $options; $message = "[{$category['catname']}]\n 已经更新{$options['currentNum']}条\n (<font color='red'>" . floor($options['currentNum'] / $options['total_row'] * 100) . "%</font>)"; $this->success($message, __METH__, 0); } } }
/** * 删除文章 */ public function del() { $aid = Q('aid', 0, 'intval'); if (!$aid) { $this->error('文章不存在'); } $ContentModel = new Content($this->_mid); $result = $ContentModel->find($aid); if ($result['uid'] != $_SESSION['uid']) { $this->error('没有删除权限'); } if ($ContentModel->del($aid)) { $this->success('删除成功'); } else { $this->error('aid参数错误'); } }
/** * コンテンツを更新する * @return bool */ protected function _updateContents() { App::uses('Content', 'Model'); $Content = new Content(); $contents = $Content->find('all', ['recursive' => -1]); $result = true; foreach ($contents as $content) { $content['Content']['created_date'] = date('Y-m-d H:i:s'); if (!$Content->save($content, ['validation' => false, 'callbacks' => false])) { $result = false; } } return $result; }
public function postDeletetestemocial() { $testimonial = Content::find(Input::get('id')); if (!$testimonial) { $output = array('result' => 0, 'error' => 'Testemonial not found'); return Response::json($output); } $testimonial->delete(); return Response::json(array('result' => 1)); }
public static function loadDefaultValues($input = '') { $parent = Content::find($input['parent_id']); if (!@$input['template_id']) { $parentTemplate = Template::find($parent->template_id); // dd($parent->template_id); if ($parentTemplate) { //since we occasionally want to process a looped back tree (which makes the whole tree //invalid, we can't use baum's built in functions to get the first child. if ($parentTemplate->loopback) { $parentTemplateChild = Template::find($parentTemplate->loopback); } else { $parentTemplateChild = @$parentTemplate->getImmediateDescendants()->first(); } $input['template_id'] = @$parentTemplateChild->id; } if (!@$input['template_id']) { //if it's still nothing we can safely set this to 0; $input['template_id'] = null; } } $template = Template::find($input['template_id']); //dd($template->name); //TODO: replace with something like this: dd($this->default_fields()->first()->id); //$contentDefaultFields = Contentdefaultfield::where('content_type_id', '=', $this->content_type_id)->get(); //plug in the fields we wanted.. if (!@$input['template_id']) { $input['template_id'] = @$template->id; } if (!@$input['name']) { $input['name'] = @$template->name; } if (!@$input['view']) { $input['view'] = @$template->view; } if (!@$input['identifier']) { $input['identifier'] = @$template->identifier; } if (!@$input['package']) { $input['package'] = @$template->package; } if (!@$input['edit_view']) { $input['edit_view'] = @$template->edit_view; } if (!@$input['edit_package']) { $input['edit_package'] = @$template->edit_package; } if (!@$input['edit_action']) { $input['edit_action'] = @$template->edit_action; } //work out the slug if not manually set if (!@$input['slug']) { $input['slug'] = Content::createSlug($input, $parent); } //and the user_id (author) $input['user_id'] = Auth::user()->id; //and the application: if (!@$input['application_id']) { $application = Application::getApplication(); $input['application_id'] = $application->id; } //set language if (!@$input['language']) { $input['language'] = App::getLocale(); } //and the package if not set if (!@$input['package']) { //set it as parent one.. $input['package'] = @$parent->package; //still nothing - set from application $application = Application::getApplication(); if ($application->package) { $input['package'] = $application->package; } //still nothing - we have to set it to default. if (!$input['package']) { //last ditch attempt to put something sensible in here $input['package'] = Content::PACKAGE; } } if (!@$input['edit_package']) { //set it as parent one.. $input['edit_package'] = @$parent->edit_package; //still nothing - we have to set it to default. if (!$input['edit_package']) { //last ditch attempt to put something sensible in here $input['edit_package'] = Content::PACKAGE; } } if (!@$input['edit_view']) { //set it as parent one.. $input['edit_view'] = @$parent->edit_view; //still nothing - we have to set it to default. if (!$input['edit_view']) { //last ditch attempt to put something sensible in here $input['edit_view'] = Content::EDIT_VIEW; } } if (!@$input['view']) { $input['view'] = Content::VIEW; } return $input; }
public function actionDelete($id) { $model = Content::find($id); $model->delete(); return $this->redirect(array('index')); }
public function savetestimonial($id) { // dd(Input::all()); $testimonial = Content::find($id); $testimonial->body = Input::get('body'); $testimonial->title = Input::get('title'); $testimonial->intro = Input::get('intro'); switch (Input::get('client_facing')) { case 'both': $testimonial->candidate_facing = 1; $testimonial->client_facing = 1; break; case 'candidate': $testimonial->candidate_facing = 1; $testimonial->client_facing = 0; break; case 'client': $testimonial->candidate_facing = 0; $testimonial->client_facing = 1; break; } $testimonial->save(); return Redirect::to('dashboard/testimonials'); }
/** * Serice page */ public function policy($id) { $banners = $this->banners; $policy = Content::find($id); return View::make('pages.policy')->with(compact('policy', 'banners')); }