358 lines
8.0 KiB
PHP
358 lines
8.0 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 libs
|
|
* @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>
|
|
*/
|
|
|
|
/**
|
|
* Klasa Blog
|
|
*
|
|
* @package stBlogPlugin
|
|
* @subpackage libs
|
|
*/
|
|
class Blog extends BaseBlog
|
|
{
|
|
|
|
public function __toString()
|
|
{
|
|
return $this->getName() ? $this->getName() : '';
|
|
}
|
|
|
|
public function setTitle(?string $title)
|
|
{
|
|
$this->setName($title);
|
|
}
|
|
|
|
public function getTitle(): ?string
|
|
{
|
|
return $this->getName();
|
|
}
|
|
|
|
public function setCtaButtonName(?string $name)
|
|
{
|
|
$this->setCtaName($name);
|
|
}
|
|
|
|
public function getCtaButtonName(): ?string
|
|
{
|
|
return $this->getCtaName();
|
|
}
|
|
|
|
public function setCtaButtonUrl(?string $name)
|
|
{
|
|
$this->setCtaUrl($name);
|
|
}
|
|
|
|
public function getCtaButtonUrl(): ?string
|
|
{
|
|
return $this->getCtaUrl();
|
|
}
|
|
|
|
public function hydrate(ResultSet $rs, $startcol = 1)
|
|
{
|
|
$this->setCulture(stLanguage::getHydrateCulture());
|
|
return parent::hydrate($rs, $startcol);
|
|
}
|
|
|
|
public function getCtaUrl()
|
|
{
|
|
return stLanguageModelI18nHelper::getI18nField($this, __METHOD__);
|
|
}
|
|
|
|
public function setCtaUrl($value)
|
|
{
|
|
stLanguageModelI18nHelper::setI18nField($this, __METHOD__, $value);
|
|
}
|
|
|
|
public function getCtaName()
|
|
{
|
|
return stLanguageModelI18nHelper::getI18nField($this, __METHOD__);
|
|
}
|
|
|
|
public function setCtaName($value)
|
|
{
|
|
stLanguageModelI18nHelper::setI18nField($this, __METHOD__, $value);
|
|
}
|
|
|
|
public function getCtaDescriptionHead()
|
|
{
|
|
return stLanguageModelI18nHelper::getI18nField($this, __METHOD__);
|
|
}
|
|
|
|
public function setCtaDescriptionHead($value)
|
|
{
|
|
stLanguageModelI18nHelper::setI18nField($this, __METHOD__, $value);
|
|
}
|
|
|
|
public function getCtaDescriptionFoot()
|
|
{
|
|
return stLanguageModelI18nHelper::getI18nField($this, __METHOD__);
|
|
}
|
|
|
|
public function setCtaDescriptionFoot($value)
|
|
{
|
|
stLanguageModelI18nHelper::setI18nField($this, __METHOD__, $value);
|
|
}
|
|
|
|
public function getName()
|
|
{
|
|
return stLanguageModelI18nHelper::getI18nField($this, __METHOD__);
|
|
}
|
|
|
|
public function setName($v)
|
|
{
|
|
stLanguageModelI18nHelper::setI18nField($this, __METHOD__, $v);
|
|
}
|
|
|
|
public function getUrl()
|
|
{
|
|
return stLanguageModelI18nHelper::getI18nField($this, __METHOD__);
|
|
}
|
|
|
|
public function setUrl($v)
|
|
{
|
|
stLanguageModelI18nHelper::setI18nField($this, __METHOD__, $v);
|
|
}
|
|
|
|
public function getLongDescription()
|
|
{
|
|
return stLanguageModelI18nHelper::getI18nField($this, __METHOD__);
|
|
}
|
|
|
|
public function setLongDescription($v)
|
|
{
|
|
stLanguageModelI18nHelper::setI18nField($this, __METHOD__, $v);
|
|
}
|
|
|
|
public function setShortDescription($v)
|
|
{
|
|
stLanguageModelI18nHelper::setI18nField($this, __METHOD__, $v);
|
|
}
|
|
|
|
public function getShortDescription()
|
|
{
|
|
return stLanguageModelI18nHelper::getI18nField($this, __METHOD__);
|
|
}
|
|
|
|
public function getShortDescriptionTrimed($length = 50)
|
|
{
|
|
$content = $this->getShortDescription();
|
|
$content = strip_tags($content);
|
|
$contentLength = strlen($content);
|
|
|
|
//sprawdzenie czy istnieje potrzeba przyciecia
|
|
if($contentLength <= $length)
|
|
{
|
|
return strip_tags($this->getShortDescription());
|
|
}
|
|
|
|
$content = trim(wordwrap($content, $length, "\n"));
|
|
$table = explode("\n", $content);
|
|
|
|
if(count($table) > 0)
|
|
{
|
|
return $table[0]."...";
|
|
}
|
|
return "";
|
|
}
|
|
|
|
public function urlFilter($friendly_url)
|
|
{
|
|
$c = new Criteria();
|
|
|
|
$c->add(BlogI18nPeer::ID, $this->getPrimaryKey(), Criteria::NOT_EQUAL);
|
|
|
|
$c->add(BlogI18nPeer::URL, $friendly_url);
|
|
|
|
if (BlogI18nPeer::doCount($c) > 0)
|
|
{
|
|
return $friendly_url.'-'.$this->getPrimaryKey();
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public function save($con = null)
|
|
{
|
|
if ($this->asfAsset || $this->getSfAssetId() && $this->isColumnModified(BlogPeer::SF_ASSET_ID))
|
|
{
|
|
$this->setOptImageMainPage($this->getsfAsset()->getRelativePath());
|
|
$this->setOptImage($this->getsfAsset()->getRelativePath());
|
|
}
|
|
|
|
if ($this->isModified())
|
|
{
|
|
BlogPeer::clearCache();
|
|
}
|
|
|
|
return parent::save($con);
|
|
}
|
|
|
|
public function delete($con = null)
|
|
{
|
|
parent::delete($con);
|
|
|
|
$this->removeImage();
|
|
|
|
BlogPeer::clearCache();
|
|
}
|
|
|
|
public function setOptImageMainPage($v)
|
|
{
|
|
$this->setImageMainPage($v);
|
|
}
|
|
|
|
public function getOptImageMainPage()
|
|
{
|
|
return $this->getImageMainPage();
|
|
}
|
|
|
|
public function getImageMainPage()
|
|
{
|
|
if (null !== $this->getGallery())
|
|
{
|
|
$gallery = $this->getGallery();
|
|
return current($gallery);
|
|
}
|
|
|
|
return parent::getImageMainPage();
|
|
}
|
|
|
|
public function setOptImage($v)
|
|
{
|
|
$this->setImage($v);
|
|
}
|
|
|
|
public function getOptImage()
|
|
{
|
|
return $this->getImage();
|
|
}
|
|
|
|
public function destroyAsset()
|
|
{
|
|
$asset = $this->getsfAsset();
|
|
|
|
if ($asset)
|
|
{
|
|
$asset->delete(null, 'blog');
|
|
|
|
$this->setImage(null);
|
|
|
|
$this->setImageMainPage(null);
|
|
|
|
$this->setsfAsset(null);
|
|
}
|
|
}
|
|
|
|
public function createAsset($filename, $source_file)
|
|
{
|
|
if (!$this->getPrimaryKey())
|
|
{
|
|
throw new sfException('Wpis musi być najpierw zapisany do bazy danych...');
|
|
}
|
|
|
|
$asset = $this->getsfAsset();
|
|
|
|
if (!$asset)
|
|
{
|
|
$asset = new sfAsset();
|
|
}
|
|
else
|
|
{
|
|
$asset->destroy();
|
|
}
|
|
|
|
$folder = sfAssetFolderPeer::retrieveByPath('media/blog');
|
|
|
|
if (!$folder)
|
|
{
|
|
$folder = sfAssetFolderPeer::createFromPath('media/blog');
|
|
}
|
|
|
|
$asset->setsfAssetFolder($folder);
|
|
|
|
$asset->setFilename($filename);
|
|
|
|
$tmp = $prev = sfConfig::get('app_sfAssetsLibrary_thumbnails');
|
|
|
|
foreach ($tmp as $type => $config)
|
|
{
|
|
$tmp[$type]['watermark'] = false;
|
|
}
|
|
|
|
sfConfig::set('app_sfAssetsLibrary_thumbnails', $tmp);
|
|
|
|
$asset->create($source_file, true, false);
|
|
|
|
$this->setsfAsset($asset);
|
|
|
|
sfConfig::set('app_sfAssetsLibrary_thumbnails', $prev);
|
|
|
|
return $asset;
|
|
}
|
|
|
|
public static function trim_post($description, $chars)
|
|
{
|
|
$max_length = $chars;
|
|
$s = strip_tags($description);
|
|
|
|
if (strlen($s) > $max_length)
|
|
{
|
|
$offset = ($max_length - 3) - strlen($s);
|
|
$s = @substr($s, 0, strrpos($s, ' ', $offset)) . '...';
|
|
}
|
|
|
|
$description = $s;
|
|
|
|
return $description;
|
|
}
|
|
|
|
|
|
public function removeImage()
|
|
{
|
|
$path = $this->getImagePath(true);
|
|
|
|
if (is_file($path))
|
|
{
|
|
unlink($path);
|
|
}
|
|
|
|
$this->setImageMainPage(null);
|
|
}
|
|
|
|
public function getImageDir($system_dir = false)
|
|
{
|
|
$dir = 'uploads/blog/main';
|
|
|
|
if ($system_dir)
|
|
{
|
|
return sfConfig::get('sf_web_dir').'/'.$dir;
|
|
}
|
|
|
|
return $dir;
|
|
}
|
|
|
|
public function getImagePath($system_dir = false)
|
|
{
|
|
return $this->getImageDir($system_dir).'/'.$this->getImageMainPage();
|
|
}
|
|
|
|
public function getGalleryPath($name, $system_dir = false)
|
|
{
|
|
return $this->getImageDir($system_dir).'/'.$name;
|
|
}
|
|
}
|
|
|
|
sfPropelBehavior::add('Blog', array('stPropelSeoUrlBehavior' => array('source_column' => 'Name', 'target_column' => 'Url', 'target_column_filter' => 'urlFilter'))); |