Inheritance: extends BlogAppModel
 public function approve()
 {
     $this->Moderated = true;
     $this->IsApproved = true;
     $this->write();
     $parent = $this->getParent();
     //debug::show($parent->ClassName);
     if ($parent->GuestBookID) {
         $GuestBookPage = $parent->GuestBook();
         $oBlogParent = $GuestBookPage->Level(1);
         //$GuestBookPageChildClass = $this->getGuestBookPageChildClass($GuestBook);
         $GuestBook = new BlogPost();
         $GuestBook->Title = $this->Title;
         $GuestBook->AuthorNames = $this->Author;
         $GuestBook->Content = $this->Content;
         $GuestBook->PublishDate = SS_Datetime::now()->getValue();
         $GuestBook->ParentID = $oBlogParent->ID;
         $GuestBook->FeaturedImageID = $this->ImageID;
         $GuestBook->doPublish();
         $GuestBook->write();
         $GuestBook->doRestoreToStage();
         //$GuestBook->writeToStage("Stage", "Live");
         $this->GuestBookLinkingID = $GuestBook->ID;
         $GuestBook->ShowInMenus = true;
         $GuestBook->doPublish();
         $GuestBook->write();
         $GuestBook->doRestoreToStage();
     }
     $this->write();
     return 'Submission published';
 }
Example #2
0
 function index()
 {
     global $router;
     $post = new BlogPost();
     $posts = $post->getMostRecent(5);
     $data = array();
     foreach ($posts as $post) {
         $data[] = (object) array('url' => $router->urlFor('Blog', 'readPost', array('year' => $post->created->format('Y'), 'month' => $post->created->format('m'), 'slug' => $post->slug)), 'title' => $post->title, 'numComments' => 0);
     }
     $this->render('home', array('posts' => $data));
 }
Example #3
0
 public function testClone()
 {
     $this->expectDocumentSaved(array('title' => 'Hello World', 'views' => 0, 'comments' => array()));
     $post = new BlogPost(array('title' => 'Hello World', 'views' => 0));
     $post->save();
     $this->assertEquals($post->saved(), true);
     $clone = clone $post;
     $this->assertEquals($clone->saved(), false);
     $post->_id = null;
     $this->assertEquals($clone, $post);
 }
 /**
  * Return blog posts
  *
  * @return DataList of BlogPost objects
  **/
 public function getBlogPosts()
 {
     $blogPosts = BlogPost::get()->filter("ParentID", $this->ID);
     //Allow decorators to manipulate list
     $this->extend('updateGetBlogPosts', $blogPosts);
     return $blogPosts;
 }
 public function actionAdd()
 {
     $orig_id = isset($_POST["orig_id"]) ? (int) $_POST["orig_id"] : (int) $_GET["orig_id"];
     $post_id = isset($_POST["post_id"]) ? (int) $_POST["post_id"] : (int) $_GET["post_id"];
     if ($orig_id) {
         $orig = Orig::model()->with("chap.book.membership")->findByPk($orig_id);
         if (!$orig) {
             throw new CHttpException(404, "Вы пытаетесь добавить несуществующий фрагмент оригинала в «мои обсуждения». Скорее всего, его удалили");
         } elseif (!$orig->chap->can("read")) {
             throw new CHttpException(403, "Вы не можете добавить этот фрагмент в «мои обсуждения» так как у вас больше нет доступа этот перевод.");
         } else {
             $orig->setTrack();
         }
     } elseif ($post_id) {
         $post = BlogPost::model()->with("book", "seen")->findByPk($post_id);
         if (!$post) {
             throw new CHttpException(404, "Вы пытаетесь добавить несуществующий пост в «мои обсуждения». Скорее всего, его удалили.");
         } else {
             if ($post->book_id != 0 and !$post->book->can("blog_r")) {
                 throw new CHttpException(403, "Вы не можете добавить этот пост в «мои обсуждения» так как у вас нет доступа в блог перевода.");
             } else {
                 $post->setTrack();
             }
         }
     } else {
         throw new CHttpException(500, "Неверный запрос.");
     }
     if ($_POST["ajax"]) {
         echo json_encode(array("status" => "ok", "id" => $orig_id ? $orig_id : $post_id));
         Yii::app()->end();
     } else {
         $this->redirect("/my/comments/?mode=" . ($orig_id ? "o" : "p"));
     }
 }
Example #6
0
 public function getPostByUrl($url)
 {
     $where = "Blog ='" . Database::escape($this->getId()) . "' AND Url = '" . Database::escape($url) . "'";
     $lista = BlogPost::SELECT($where);
     if (count($lista)) {
         return $lista[0];
     }
     return null;
 }
Example #7
0
 public function afterValidate()
 {
     if ($this->isNewRecord) {
         if ($this->wasToday) {
             $this->addError("body", "Нельзя анонсировать переводы чаще, чем один раз в сутки.");
         }
     }
     parent::afterValidate();
 }
Example #8
0
 public static function save_blogpost($cid, $uid, $title, $body, $track, $tags, $ccid = 0, $is_active = 1, $display_on = 0, $is_default_content = FALSE)
 {
     global $path_prefix;
     $errors = array();
     // ensure integers here
     $cid = (int) $cid;
     $uid = (int) $uid;
     $ccid = (int) $ccid;
     // if a new post, make one, otherwise load the existing one
     if ($cid) {
         $post = Content::load_content($cid, $uid);
         // ignore $ccid passed to function if the post already exists
         // - we don't allow users to move posts between
         // ContentCollections.
         $ccid = (int) $post->parent_collection_id;
     } else {
         $post = new BlogPost();
         $post->author_id = $uid;
         if ($ccid) {
             $post->parent_collection_id = $ccid;
         }
     }
     if ($ccid && $ccid != -1) {
         $g = ContentCollection::load_collection($ccid, $uid);
         $g->assert_user_access($uid);
     } else {
         $g = NULL;
     }
     $post->title = $title;
     $post->body = $body;
     $post->allow_comments = 1;
     $post->is_active = $is_active;
     $post->display_on = $display_on;
     if ($track) {
         $post->trackbacks = implode(",", $track);
     }
     //TODO; remove this
     $post->type = 1;
     $post->is_default_content = $is_default_content;
     $post->save();
     //if ($tags) {
     Tag::add_tags_to_content($post->content_id, $tags);
     //}
     if ($track) {
         foreach ($track as $t) {
             if (!$post->send_trackback($t)) {
                 $errors[] = array("code" => "trackback_failed", "msg" => "Failed to send trackback", "url" => $t);
             }
         }
     }
     if ($g && !$cid) {
         // new post - post it to the group as well
         $g->post_content($post->content_id, $uid);
     }
     return array("cid" => (int) $post->content_id, "moderation_required" => $g ? $g->is_moderated == 1 && $g->author_id != $uid : FALSE, "errors" => $errors);
 }
 /**
  * @return DataList
  */
 public function getFeaturedBlogPosts()
 {
     $controller = Controller::curr();
     $parameters = $controller->getRequest()->allParams();
     $list = BlogPost::get()->filter('ParentID', $this->owner->ID)->filter('IsFeatured', true);
     if (isset($parameters['Category'])) {
         $list = $list->filter('Categories.URLSegment', $parameters['Category']);
     }
     return $list;
 }
Example #10
0
 /**
  * {@inheritdoc}
  */
 public function updateCMSFields(FieldList $fields)
 {
     $excluded = $this->owner->getExcludedSiteTreeClassNames();
     if (!empty($excluded)) {
         $pages = BlogPost::get()->filter(array('ParentID' => $this->owner->ID, 'ClassName' => $excluded));
         $gridField = new BlogFilter_GridField('ChildPages', $this->getLumberjackTitle(), $pages, $this->getLumberjackGridFieldConfig());
         $tab = new Tab('ChildPages', $this->getLumberjackTitle(), $gridField);
         $fields->insertBefore($tab, 'Main');
     }
 }
Example #11
0
    public static function generateSitemap()
    {
        require_once _PS_MODULE_DIR_ . 'psblog/classes/BlogCategory.php';
        require_once _PS_MODULE_DIR_ . 'psblog/classes/BlogPost.php';
        $filename = _PS_MODULE_DIR_ . 'psblog/sitemap-blog.xml';
        if (!is_writable($filename)) {
            return FALSE;
        }
        $sql = 'SELECT s.id_shop, su.domain, su.domain_ssl, CONCAT(su.physical_uri, su.virtual_uri) as uri
				FROM ' . _DB_PREFIX_ . 'shop s
				INNER JOIN ' . _DB_PREFIX_ . 'shop_url su ON s.id_shop = su.id_shop AND su.main = 1
				WHERE s.active = 1 AND s.deleted = 0 AND su.active = 1';
        if (!($result = Db::getInstance()->executeS($sql))) {
            return false;
        }
        $xml = simplexml_load_file($filename);
        unset($xml->url);
        $sxe = new SimpleXMLElement($xml->asXML());
        foreach ($result as $row) {
            $shopContext = Context::getContext()->cloneContext();
            $shopContext->shop = new Shop($row['id_shop']);
            $languages = Language::getLanguages(true, $row['id_shop']);
            foreach ($languages as $l) {
                $shopContext->language->id_lang = $l['id_lang'];
                $shopContext->language->iso_code = $l['iso_code'];
                $url = $sxe->addChild('url');
                $listlink = BlogPost::linkList(null, $shopContext);
                $listlink = str_replace('&', '&', $listlink);
                $url->addChild('loc', $listlink);
                $url->addChild('priority', '0.7');
                $url->addChild('changefreq', 'weekly');
            }
            unset($shopContext->language);
            $shopPosts = BlogPost::listPosts($shopContext, true);
            foreach ($shopPosts as $post) {
                $postlink = BlogPost::linkPost($post['id_blog_post'], $post['link_rewrite'], $post['id_lang'], $shopContext);
                $postlink = str_replace('&', '&', $postlink);
                $url = $sxe->addChild('url');
                $url->addChild('loc', $postlink);
                $url->addChild('priority', '0.6');
                $url->addChild('changefreq', 'monthly');
            }
            $shopCategories = BlogCategory::listCategories($shopContext, true);
            foreach ($shopCategories as $cat) {
                $catlink = BlogCategory::linkCategory($cat['id_blog_category'], $cat['link_rewrite'], $cat['id_lang'], null, $shopContext);
                $catlink = str_replace('&', '&', $catlink);
                $url = $sxe->addChild('url');
                $url->addChild('loc', $catlink);
                $url->addChild('priority', '0.6');
                $url->addChild('changefreq', 'monthly');
            }
            $sxe->asXML($filename);
        }
    }
 public function testFilter()
 {
     $member = Member::currentUser();
     if ($member) {
         $member->logout();
     }
     $count = BlogPost::get()->count();
     $this->assertEquals(3, $count, "Filtered blog posts");
     SS_Datetime::set_mock_now("2020-01-01 00:00:00");
     $count = BlogPost::get()->count();
     $this->assertEquals(5, $count, "Unfiltered blog posts");
 }
Example #13
0
 public function initContent()
 {
     parent::initContent();
     if (!empty($this->id_post) && is_numeric($this->id_post)) {
         $this->displayPost();
     } else {
         $this->displayList();
     }
     $img_path = rtrim($this->conf['img_save_path'], '/') . '/';
     $this->context->smarty->assign(array('img_path' => _PS_BASE_URL_ . __PS_BASE_URI__ . $img_path, 'blog_conf' => $this->conf, 'logged' => $this->context->customer->isLogged(), 'customerName' => $this->context->customer->logged ? $this->context->customer->firstname : false, 'listLink' => $this->list_link, 'posts_rss_url' => BlogPost::linkRss()));
     // Assign template vars related to the category + execute hooks related to the category
     $this->assignCategory();
 }
Example #14
0
 public function getBlogSlicePosts()
 {
     if ($this->owner->FeaturedPosts && $this->getFeaturedBlogPost()) {
         $featured = $this->getFeaturedBlogPost();
         $others = BlogPost::get()->exclude('ID', $featured->ID)->limit(2)->sort('PublishDate', 'DESC');
         $posts = ArrayList::create();
         $posts->push($featured);
         foreach ($others as $item) {
             $posts->push($item);
         }
         return $posts;
     }
     return BlogPost::get()->limit(3)->sort('PublishDate', 'DESC');
 }
 public function hookLeftColumn($params)
 {
     require_once _PS_MODULE_DIR_ . "psblog/psblog.php";
     require_once _PS_MODULE_DIR_ . "psblog/classes/BlogPost.php";
     if (isset($_GET['search']) && trim($_GET['search']) != '') {
         $search = $_GET['search'];
         $search_nb = BlogPost::searchPosts($search, true, true, true);
         $this->smarty->assign('search_query', $search);
         $this->smarty->assign('search_query_nb', $search_nb);
     }
     $this->smarty->assign('ENT_QUOTES', ENT_QUOTES);
     $this->smarty->assign('linkPosts', BlogPost::linkList());
     return $this->display(__FILE__, 'blocksearch.tpl');
 }
Example #16
0
    function atomAddPost($request)
    {
        header("Content-Type: application/atomserv+xml; charset=utf-8");
        // parse submitted data
        $xml = new SimpleXMLElement($request->content);
        $author = (object) array('name' => (string) $xml->author->name, 'email' => (string) $xml->author->email, 'uri' => (string) $xml->author->uri);
        $tags = array();
        foreach ($xml->category as $category) {
            $tags[] = (string) $category['term'];
        }
        $draft = isset($xml->draft);
        // create blog post
        $filesystem = new Minim_Model_Backend_Sqlite($GLOBALS['database']['dsn']);
        $post = new BlogPost();
        $post->setBackend($filesystem);
        $post->title = (string) $xml->title;
        $post->content = (string) $xml->content;
        $post->draft = $draft;
        $post->save();
        $location = "/blog/" . date("Y/m/d", $post->created) . "/{$post->title}";
        $primaryKey = $post->getPrimaryKeyValue();
        header("Content-Location: {$location}");
        header("Location: {$location}");
        echo <<<XML
<?xml version="1.0" ?>
<entry xmlns="http://www.w3.org/2005/Atom">
  <id>{$primaryKey}</id>
  <title>{$post->title}</title>
  <link rel="edit" href="/blog/posts/{$post->id}" />
  <updated>{$post->created}</updated>
  <author><name>{$author->name}</name></author>
  <content>{$post->content}</summary>
</entry>
XML;
        exit;
    }
Example #17
0
 private function calculHookCommon($params)
 {
     $pref = array_merge(Psblog::getPreferences(), self::getPreferences());
     $img_path = rtrim($pref['img_save_path'], '/') . '/';
     $list = BlogPost::listPosts(true, true, 0, intval($pref['block_limit_items']));
     if ($list) {
         $i = 0;
         foreach ($list as $val) {
             $list[$i]['link'] = BlogPost::linkPost($val['id_blog_post'], $val['link_rewrite'], $val['id_lang']);
             $i++;
         }
     }
     $this->smarty->assign(array('last_post_list' => $list, 'blog_conf' => $pref, 'linkPosts' => BlogPost::linkList(), 'img_path' => _PS_BASE_URL_ . __PS_BASE_URI__ . $img_path, 'posts_rss_url' => BlogPost::linkRss()));
     return true;
 }
Example #18
0
 /**
  * Tworzenie struktury związku
  * @param Post $post
  * @param Category $category
  * @param array $params dodatkowe parametry
  * @return Collection
  */
 public static function getStructure(Post $post, Category $category, array $params = [])
 {
     $structure = null;
     $categories = $category->getSubcategories(false, true);
     if ($categories) {
         $structure = Category::orderByRaw('"order" asc NULLS LAST')->find($categories)->filter(function ($elem) use($post) {
             if (empty($elem->communication) === false) {
                 $post = BlogPost::where('id', $elem->communication)->first();
                 $elem->communication = $post->getPaths();
             }
             $elem->posts = BlogPost::getPosts(['categories_id' => [$elem->id], 'template_id' => 2, 'additional' => ['person_type' => 3], 'order' => "additional->>'order' NULLS LAST"]);
             return $elem->posts->count() > 0;
         });
     }
     return $structure;
 }
Example #19
0
 /**
  * Get CMS fields
  * 
  * @return FieldList
  */
 public function getCMSFields()
 {
     $fields = parent::getCMSFields();
     $fields->removeByName('Widgets');
     $fields->removeByName('RelatedPosts');
     $fields->removeByName('Authors');
     $fields->removeByName('AuthorNames');
     $fields->dataFieldByName('PublishDate')->setTitle('Deployment Date');
     $fields->insertBefore(TextField::create('WebsiteAddress', 'Website Address'), 'Categories');
     $fields->insertAfter(TextField::create('Client', 'Client'), 'WebsiteAddress');
     $fields->addFieldToTab('Root.Features', GridField::create('Features', 'Features', $this->Features(), GridFieldConfig_RecordEditor::create()->addComponent(new GridFieldSortableRows('SortOrder'))));
     $fields->addFieldToTab('Root.ActionBox', TextField::create('ActionBoxTitle', 'Title'));
     $fields->addFieldToTab('Root.ActionBox', HTMLEditorField::create('ActionBoxContent', 'Content')->setRows(20));
     $fields->addFieldToTab('Root.ActionBox', TextField::create('ActionBoxRedirectButtonText', 'Redirect button text'));
     $fields->addFieldToTab('Root.ActionBox', TreeDropdownField::create('ActionBoxRedirectPageID', 'Redirect page', 'SiteTree'));
     return $fields;
 }
Example #20
0
 public function actionIndex()
 {
     if (Yii::app()->user->isGuest) {
         if (Yii::app()->request->isPostRequest && isset($_POST["login"])) {
             $user = new User("login");
             $user->setAttributes($_POST["login"]);
             $user->remember = true;
             if ($user->login()) {
                 $this->redirect("/");
             } else {
                 Yii::app()->user->setFlash("error", $user->getError("pass"));
             }
         }
         if (p()['registerType'] == "INVITE") {
             $this->layout = "empty";
             $this->render("index_guest");
             return;
         }
     }
     $this->layout = "column1";
     $hot_key = sprintf("hot.%d.%d.%d", Yii::app()->user->ini["hot.s_lang"], Yii::app()->user->ini["hot.t_lang"], Yii::app()->user->ini["hot.img"]);
     if (!($hot = Yii::app()->cache->get($hot_key))) {
         $C = new CDbCriteria(array("condition" => "t.ac_read = 'a'", "order" => "t.last_tr DESC NULLS LAST"));
         $C->limit = Yii::app()->user->ini["hot.img"] ? 12 : 36;
         if (Yii::app()->user->ini["hot.s_lang"]) {
             $C->addCondition("t.s_lang = " . Yii::app()->user->ini["hot.s_lang"]);
         }
         if (Yii::app()->user->ini["hot.t_lang"]) {
             $C->addCondition("t.t_lang = " . Yii::app()->user->ini["hot.t_lang"]);
         }
         $hot = Book::model()->findAll($C);
         Yii::app()->cache->set($hot_key, $hot, 60);
     }
     if (!($announces = Yii::app()->cache->get("announces"))) {
         $announces = Announce::model()->with("book.cat", "book.owner", "seen")->findAll(array("condition" => "t.topics BETWEEN 80 AND 89 AND book.ac_read = 'a'", "order" => "t.cdate desc", "limit" => 5));
         Yii::app()->cache->set("announces", $announces, 90);
     }
     if (!($blog = Yii::app()->cache->get("blog"))) {
         $blog = BlogPost::model()->common()->findAll(["limit" => 10]);
         Yii::app()->cache->set("blog", $blog, 105);
     }
     $this->render('index', array("hot" => $hot, "searchTop" => $this->getSearchTop(), "announces" => $announces, "blog" => $blog));
 }
 public function doSavePost($data, $form)
 {
     $post = false;
     if (isset($data['ID']) && $data['ID']) {
         $post = BlogPost::get()->byID($data['ID']);
     }
     if (!$post) {
         $post = BlogPost::create();
     }
     $form->saveInto($post);
     $post->ParentID = $this->owner->ID;
     $this->owner->extend("onBeforeSavePost", $blogentry);
     $oldMode = Versioned::get_reading_mode();
     Versioned::reading_stage('Stage');
     $post->write();
     $post->publish("Stage", "Live");
     Versioned::set_reading_mode($oldMode);
     $this->owner->extend("onAfterSavePost", $post);
     $this->owner->redirect($this->owner->Link());
 }
Example #22
0
 public function beforeValidate()
 {
     // Alias
     if ($this->alias) {
         $this->alias = makeAlias($this->alias);
     } else {
         $this->alias = makeAlias($this->title);
     }
     if ($this->isNewRecord) {
         // Check if we already have an alias with those parameters
         if (BlogPost::model()->exists('alias=:alias', array(':alias' => $this->alias))) {
             $this->addError('alias', at('There is already a page with that alias.'));
         }
     } else {
         // Check if we already have an alias with those parameters
         if (BlogPost::model()->exists('alias=:alias AND id!=:id', array(':id' => $this->id, ':alias' => $this->alias))) {
             $this->addError('alias', at('There is already a page with that alias.'));
         }
     }
     return parent::beforeValidate();
 }
 public function run()
 {
     $this->command->info('Deleting existing BlogPost table...');
     DB::table('blogposts')->truncate();
     $count = 20;
     $lang = array('fr', 'en');
     $faker = Faker\Factory::create('fr_FR');
     $this->command->info('Inserting ' . $count . ' sample Blog Posts...');
     for ($i = 0; $i < $count; $i++) {
         $title = e(substr($faker->sentence(8), 0, -1));
         $content = '<p>' . implode('</p><p>', $faker->paragraphs(5)) . '</p>';
         $post = BlogPost::create(array('title' => $title, 'slug' => Str::slug($title), 'content' => e($content), 'draft' => rand(0, 1), 'lang' => $lang[rand(0, 1)], 'image' => null, 'user_id' => 1, 'meta_title' => e($title), 'meta_keywords' => str_replace(' ', ', ', strtolower($title)), 'meta_description' => strip_tags($content)));
         $nb_occur = rand(1, 4);
         $range = range(1, 5);
         shuffle($range);
         for ($j = 0; $j < $nb_occur; $j++) {
             echo $post->tags()->attach($range[$j]);
         }
     }
     $this->command->info('Blog Posts inserted successfully!');
 }
Example #24
0
File: blog.php Project: fg-ok/codev
 /**
  * @param BlogPost[] $postList
  * @return mixed[]
  */
 private function getBlogPosts(array $postList)
 {
     $blogPosts = array();
     foreach ($postList as $id => $bpost) {
         $srcUser = UserCache::getInstance()->getUser($bpost->src_user_id);
         $item = array();
         // TODO
         $item['category'] = Config::getVariableValueFromKey(Config::id_blogCategories, $bpost->category);
         $item['severity'] = BlogPost::getSeverityName($bpost->severity);
         $item['summary'] = $bpost->summary;
         $item['content'] = $bpost->content;
         $item['date_submitted'] = date('Y-m-d G:i', $bpost->date_submitted);
         $item['from'] = $srcUser->getRealname();
         // find receiver
         if (0 != $bpost->dest_user_id) {
             $destUser = UserCache::getInstance()->getUser($bpost->dest_user_id);
             $item['to'] = $destUser->getRealname();
         } else {
             if (0 != $bpost->dest_team_id) {
                 $team = TeamCache::getInstance()->getTeam($bpost->dest_team_id);
                 $item['to'] = $team->getName();
             } else {
                 if (0 != $bpost->dest_project_id) {
                     $destProj = ProjectCache::getInstance()->getProject($bpost->dest_project_id);
                     $item['to'] = $destProj->getName();
                 } else {
                     $item['to'] = '?';
                 }
             }
         }
         $item['activity'] = 'activities...';
         $item['buttons'] = "<input type='button' value='" . T_('Ack') . "' onclick='javascript: ackPost(" . $bpost->id . ")' />";
         $item['buttons'] .= "<input type='button' value='" . T_('Hide') . "' onclick='javascript: hidePost(" . $bpost->id . ")' />";
         // TODO only if i'm the owner
         $item['buttons'] .= "<input type='button' value='" . T_('Delete') . "' onclick='javascript: deletePost(" . $bpost->id . ")' />";
         $item['isHidden'] = '0';
         $blogPosts[$id] = $item;
     }
     return $blogPosts;
 }
Example #25
0
            $savaData['PetitBlogCustomFieldConfig']['status'] = true;
            for ($i = 1; $i < 11; $i++) {
                $savaData['PetitBlogCustomFieldConfig']['use_text_sub_' . $i] = false;
            }
            $PetitBlogCustomFieldConfigModel->create($savaData);
            $PetitBlogCustomFieldConfigModel->save($savaData, array('validate' => false, 'callbacks' => false));
        }
    }
}
/**
 * ブログ記事情報を元にデータを作成する
 *   ・データがないブログ用のデータのみ作成する
 * 
 */
App::uses('BlogPost', 'Blog.Model');
$BlogPostModel = new BlogPost();
$posts = $BlogPostModel->find('all', array('recursive' => -1));
if ($posts) {
    CakePlugin::load('PetitBlogCustomField');
    App::uses('PetitBlogCustomField', 'PetitBlogCustomField.Model');
    $PetitBlogCustomFieldModel = new PetitBlogCustomField();
    foreach ($posts as $key => $post) {
        $petitBlogCustomFieldData = $PetitBlogCustomFieldModel->findByBlogPostId($post['BlogPost']['id']);
        $savaData = array();
        if (!$petitBlogCustomFieldData) {
            $savaData['PetitBlogCustomField']['blog_post_id'] = $post['BlogPost']['id'];
            $savaData['PetitBlogCustomField']['blog_content_id'] = $post['BlogPost']['blog_content_id'];
            $PetitBlogCustomFieldModel->create($savaData);
            $PetitBlogCustomFieldModel->save($savaData, array('validate' => false, 'callbacks' => false));
        }
    }
<?php

$errors = array();
$blogPost = null;
$edit = array_key_exists('id', $_GET);
if ($edit) {
    $blogPost = Utils::getBlogPostByGetId();
    $blogRestaurantDao = new BlogRestaurantDao();
    $blogRestaurant = $blogRestaurantDao->findById($blogPost->getRestaurantId());
    $blogChipDao = new BlogChipDao();
    $blogChip = $blogChipDao->findById($blogRestaurant->getId());
    //    $blogRestaurant = Utils::getBlogRestaurantByGetId();
} else {
    // set defaults
    $blogPost = new BlogPost();
    $blogPost->setDate(new DateTime());
    $blogRestaurant = new BlogRestaurant();
    $blogChip = new BlogChip();
    //$flightBooking->setPriority(Todo::PRIORITY_MEDIUM);
    //$dueOn = new DateTime("+1 day");
    //$dueOn->setTime(0, 0, 0);
    //$flightBooking->setDueOn($dueOn);
}
if (array_key_exists('cancel', $_POST)) {
    // redirect
    Utils::redirect('home');
} elseif (array_key_exists('save', $_POST)) {
    // for security reasons, do not map the whole $_POST['todo']
    //pretending to have values in $_POST
    //$data = array('first_name' => 'Bob', 'no_of_passengers' => 2);
    //        private $id;
Example #27
0
 private function _postProcess()
 {
     if (Tools::isSubmit('submitPsblog')) {
         $pref = $_POST['pref'];
         $old_values = self::getPreferences();
         $checkboxes = array('category_active', 'product_active', 'comment_active', 'comment_moderate', 'comment_guest', 'list_display_date', 'view_display_date', 'related_active', 'view_display_popin', 'rewrite_active', 'product_page_related', 'rss_active', 'share_active');
         foreach ($checkboxes as $input) {
             if (!isset($pref[$input])) {
                 $pref[$input] = 0;
             }
         }
         $new_values = array_merge(self::$default_values, $pref);
         Configuration::updateValue('PSBLOG_CONF', base64_encode(serialize($new_values)));
         if ($new_values['product_page_related'] != $old_values['product_page_related']) {
             if ($new_values['product_page_related'] == 1) {
                 $this->registerHook('productTab');
                 $this->registerHook('productTabContent');
             } else {
                 $this->unregisterHook(Hook::getIdByName('productTab'));
                 $this->unregisterHook(Hook::getIdByName('productTabContent'));
             }
         }
         $this->_html .= '<div class="conf confirm">' . $this->l('Settings updated') . '</div>';
     } elseif (Tools::isSubmit('submitGenerateImg')) {
         include_once _PS_MODULE_DIR_ . "psblog/classes/BlogPost.php";
         $images = BlogPost::getAllImages();
         $save_path = _PS_ROOT_DIR_ . '/' . rtrim(self::$pref['img_save_path'], '/') . "/";
         foreach ($images as $img) {
             @unlink($save_path . 'thumb/' . $img['img_name']);
             @unlink($save_path . 'list/' . $img['img_name']);
             BlogPost::generateImageThumbs($img['id_blog_image']);
         }
         $this->_html .= '<div class="conf confirm">' . $this->l('Images regenerated') . '</div>';
     } elseif (Tools::isSubmit('submitGenerateSitemap')) {
         include_once _PS_MODULE_DIR_ . "psblog/classes/BlogShop.php";
         BlogShop::generateSitemap();
         $this->_html .= '<div class="conf confirm">' . $this->l('Google sitemap regenerated') . '</div>';
     }
 }
Example #28
0
 public function actionPosts($id)
 {
     $user = $this->loadUser($id);
     $posts = new CActiveDataProvider(BlogPost::model()->user($user->id)->with("book.membership", "seen"), array("criteria" => array("order" => "t.cdate desc"), "pagination" => array("pageSize" => 10)));
     $this->render("posts", array("user" => $user, "posts" => $posts));
 }
         foreach ($tags as $term) {
             $tr = trim($term);
             if ($tr) {
                 $terms[] = $tr;
             }
         }
     }
     try {
         $post_subject = "Network's owner bulletin - " . $_POST['title'];
         $post_message = $_POST['bulletin_body'];
         switch ($type) {
             case 'Suggestion':
                 $res = Suggestion::save_suggestion(0, $from, $post_subject, $post_message, '', $terms, 0, $is_active = ACTIVE, $user->email);
                 break;
             case 'BlogPost':
                 $res = BlogPost::save_blogpost(0, $from, $post_subject, $post_message, '', $terms, 0, $is_active = ACTIVE, $user->email);
                 break;
         }
     } catch (PAException $e) {
         $error_msg .= $e->message;
     }
     if (!empty($res['cid'])) {
         $content_obj = Content::load_content((int) $res['cid']);
         PANotify::send("content_posted_to_comm_blog", PA::$network_info, $user, $content_obj);
     }
 }
 if ($no_reg_user == TRUE) {
     $error_msg .= "No registered member in this network";
 } else {
     $error_msg .= " Bulletin has been sent ";
 }
Example #30
0
 public function nbPosts($checkContext = true, $publish = true)
 {
     return BlogPost::listPosts($checkContext, $publish, null, null, true, $this->id);
 }