Files
grzanieplus.pl/plugins/stBlogPlugin/modules/stBlogBackend/actions/actions.class.php
2025-03-12 17:06:23 +01:00

291 lines
8.5 KiB
PHP

<?php
/**
* SOTESHOP/stBlogPlugin
*
* Ten plik należy do aplikacji stBlogPlugin opartej na licencji (Open License SOTE) Otwarta Licencja SOTE.
* Nie zmieniaj tego pliku, jeśli chcesz korzystać z automatycznych aktualizacji oprogramowania.
* Jeśli chcesz wprowadzać swoje modyfikacje do programu, zapoznaj się z dokumentacją, jak zmieniać
* oprogramowanie bez zmiany kodu bazowego http://www.sote.pl/modifications
*
* @package stBlogPlugin
* @subpackage actions
* @copyright SOTE (www.sote.pl)
* @license http://www.sote.pl/license/sote (Professional License SOTE)
* @version $Id: config.php 12100 2013-02-01 07:18:36Z pawel $
* @author Paweł Byszewski <pawel.byszewski@sote.pl>
*/
class stBlogBackendActions extends autostBlogBackendActions
{
protected function saveBlog($blog)
{
stFunctionCache::clearFrontendModule('stBlogFrontend');
stFastCacheManager::clearCache();
parent::saveBlog($blog);
$plupload = stJQueryToolsHelper::parsePluploadFromRequest($this->getRequestParameter('blog_image_main_page'));
if ($plupload['delete'])
{
foreach ($plupload['delete'] as $filename)
{
$dest = $blog->getGalleryPath($filename, true);
if (is_file($dest))
{
unlink($dest);
$gallery = $blog->getGallery();
if (isset($gallery[$filename]))
{
unset($gallery[$filename]);
}
$blog->setGallery($gallery);
}
}
}
if ($plupload['modified'])
{
$gallery = array();
foreach ($plupload['modified'] as $filename)
{
if (is_file($blog->getGalleryPath($filename, true)))
{
$gallery[$filename] = $filename;
}
else
{
$target = uniqid().'-'.$filename;
$dest = $blog->getGalleryPath($target, true);
$source = $plupload['dir'].'/'.$filename;
stJQueryToolsHelper::pluploadCopy($source, $dest);
$gallery[$target] = $target;
}
}
$blog->setGallery($gallery);
}
stJQueryToolsHelper::pluploadCleanup($plupload);
$blog->save();
$c = new Criteria();
$c -> add(BlogHasBlogCategoryPeer::BLOG_ID, $blog->getId());
BlogHasBlogCategoryPeer::doDelete($c);
$categorysBlog = $this->getRequestParameter('blog[category]');
$categoryBlogMain = $this->getRequestParameter('blog[category][main]');
foreach ($categorysBlog as $key => $value) {
$blogHasCategory = new BlogHasBlogCategory();
$blogHasCategory->setBlogId($blog->getId());
$blogHasCategory->setBlogCategoryId($key);
if ($categoryBlogMain==$key){
$blogHasCategory->setBlogCategoryMain(1);
}else{
$blogHasCategory->setBlogCategoryMain(NULL);
}
$blogHasCategory->save();
}
$isNew = $blog->isNew();
$products = stJQueryToolsHelper::parseTokensFromRequest($this->getRequestParameter('blog[products]'));
if (!$isNew)
{
$c = new Criteria();
$c->add(BlogHasProductPeer::BLOG_ID, $blog->getId());
BlogHasProductPeer::doDelete($c);
}
foreach ($products as $token)
{
$bhp = new BlogHasProduct();
$bhp->setBlog($blog);
$bhp->setProductId($token['id']);
$bhp->save();
}
}
public function executeAjaxProductsToken()
{
$query = $this->getRequestParameter('q');
$id = $this->getRequestParameter('id');
$duplicates = explode(',', $this->getRequestParameter('d'));
if ($id)
{
$duplicates[] = $id;
}
$c = new Criteria();
$criterion = $c->getNewCriterion(ProductPeer::CODE, $query);
$criterion->addOr($c->getNewCriterion(ProductPeer::OPT_NAME, '%'.$query.'%', Criteria::LIKE));
if ($duplicates)
{
$c->add(ProductPeer::ID, $duplicates, Criteria::NOT_IN);
}
$c->add($criterion);
$c->setLimit(100);
$tokens = ProductPeer::doSelectTokens($c);
return $this->renderJson($tokens);
}
public function executeViewPost()
{
if ($this->getRequest()->hasParameter('id'))
{
$id = $this->getRequestParameter('id');
$blog = BlogPeer::retrieveByPk($id);
if (is_object($blog))
{
stPluginHelper::addRouting('stBlogUrlLang', '/blog/:lang/:url', 'stBlogFrontend', 'frontendShow', 'backend', array(), array('lang' => '[a-z]{2,2}'));
stPluginHelper::addRouting('stBlogUrl', '/blog/:url', 'stBlogFrontend', 'frontendShow', 'backend');
sfLoader::loadHelpers(array('Helper','stUrl'));
$c = new Criteria();
$c->add(LanguagePeer::IS_DEFAULT, 1);
$default_lang = LanguagePeer::doSelectOne($c);
if (empty($default_lang)){
$c = new Criteria();
$c->add(LanguagePeer::ACTIVE, 1);
$default_lang = LanguagePeer::doSelectOne($c);
}
$culture = $default_lang->getLanguage();
$url = st_url_for('/blog/'.$blog->getFriendlyUrl(), true, 'frontend', null, $culture, true, null);
return $this->redirect($url, 301);
}
else
{
return $this->redirect('stBlogFrontend/list');
}
}
else
{
return $this->redirect('stBlogFrontend/list');
}
}
public function validateEdit()
{
if ($this->getRequest()->getMethod() == sfRequest::POST && !$this->getRequestParameter('id'))
{
$validator = new stAssetFileValidator();
$validator->initialize($this->getContext(), array('mime_types' => '@web_images'));
$value = $this->getRequest()->getFileValues('blog[image_main_page]');
}
return true;
}
protected function saveConfig()
{
$categorysBlog = $this->getRequestParameter('config[category_home]');
foreach ($categorysBlog as $key => $value) {
$homeCategorysBlog[] = $key;
}
$this->config->set('blog_category_home', serialize($homeCategorysBlog));
stFunctionCache::clearFrontendModule('stBlogFrontend');
stFastCacheManager::clearCache();
$this->config->save();
}
public function executePositioning()
{
$i18n = $this->getContext()->getI18N();
$this->config = stConfig::getInstance(sfContext::getInstance(), 'stBlogBackend');
$this->config->setCulture($this->getRequestParameter('culture', stLanguage::getOptLanguage()));
if ($this->getRequest()->getMethod() == sfRequest::POST){
$this->config->set('title', $this->getRequestParameter('positioning[title]'), true);
$this->config->set('description', $this->getRequestParameter('positioning[description]'), ture);
$this->config->set('keywords', $this->getRequestParameter('positioning[keywords]'), true);
$this->config->save();
$this->setFlash('notice', $i18n->__('Twoje zmiany zostały zapisane', null, 'stAdminGeneratorPlugin'));
$this->redirect('stBlogBackend/positioning?culture=' . $this->getRequestParameter('culture', stLanguage::getOptLanguage()));
}
}
public function executeAjaxBlogToken()
{
$query = $this->getRequestParameter('q');
$id = $this->getRequestParameter('id');
$duplicates = explode(',', $this->getRequestParameter('d'));
if ($id) {
$duplicates[] = $id;
}
$c = new Criteria();
$c->add(BlogPeer::OPT_NAME, '%'.$query.'%', Criteria::LIKE);
if ($duplicates) {
$c->add(BlogPeer::ID, $duplicates, Criteria::NOT_IN);
}
$c->setLimit(100);
$tokens = BlogPeer::doSelectTokens($c);
return $this->renderJson($tokens);
}
}