protected function _toHtml() { if (!AW_Kbase_Helper_Data::getFrontendEnabled()) { return ''; } return parent::_toHtml(); }
public static function getFrontendEnabled() { if (null === self::$_frontendEnabled) { self::$_frontendEnabled = Mage::getStoreConfig('kbase/general/frontent_enabled'); } return self::$_frontendEnabled; }
protected function _prepareForm() { $form = new Varien_Data_Form(); $data = Mage::registry('kbase_article'); if (!is_array($data)) { $data = array(); } $fieldset = $form->addFieldset('general', array('legend' => $this->__('General information'), 'class' => 'fieldset-wide')); $fieldset->addField('article_date_created', 'hidden', array('name' => 'article_date_created')); $fieldset->addField('article_title', 'text', array('name' => 'article_title', 'label' => $this->__('Title'), 'required' => true)); if (AW_Kbase_Helper_Data::mageVersionIsAbove13()) { $config = Mage::getSingleton('cms/wysiwyg_config')->getConfig(); $config->setData(AW_Kbase_Helper_Data::recursiveReplace('/kbase_admin/', '/' . (string) Mage::app()->getConfig()->getNode('admin/routers/adminhtml/args/frontName') . '/', $config->getData())); } else { $config = false; } $fieldset->addField('article_text', 'editor', array('name' => 'article_text', 'label' => $this->__('Article'), 'style' => 'height:25em', 'required' => true, 'config' => $config)); $fieldset->addField('article_attachment', 'file', array('name' => 'article_attachment', 'label' => $this->__('Attachment'), 'class' => 'kbase')); $form->getElement('article_attachment')->setRenderer($this->getLayout()->createBlock('kbase/adminhtml_edit_uploader')); $fieldset->addField('article_tags', 'text', array('name' => 'article_tags', 'label' => $this->__('Tags'), 'note' => $this->__('Separate tags with commas'))); $fieldset->addField('article_url_key', 'text', array('name' => 'article_url_key', 'label' => $this->__('URL key'), 'note' => $this->__('URL key must be unique within store views'))); $fieldset->addField('article_status', 'select', array('name' => 'article_status', 'label' => $this->__('Status'), 'values' => AW_Kbase_Model_Source_Status::toOptionArray())); $fieldset->addField('article_author_id', 'select', array('name' => 'article_author_id', 'label' => $this->__('Author'), 'values' => AW_Kbase_Model_Source_User::toShortOptionArray())); $form->setValues($data); $this->setForm($form); return parent::_prepareForm(); }
public function getProccessedText($text) { $processorModelName = AW_Kbase_Helper_Data::mageVersionIsAbove13() ? 'widget/template_filter' : 'core/email_template_filter'; $processor = Mage::getModel($processorModelName); if ($processor instanceof Mage_Core_Model_Email_Template_Filter) { $text = $processor->filter($text); } return $text; }
protected function _toHtml() { if (!AW_Kbase_Helper_Data::getFrontendEnabled()) { return ''; } if (!Mage::getStoreConfig('kbase/search/enabled')) { return ''; } return parent::_toHtml(); }
protected function _toHtml() { if (!AW_Kbase_Helper_Data::getFrontendEnabled()) { return ''; } if (!Mage::getStoreConfig('kbase/category/enabled')) { return ''; } $this->setCategories(Mage::getResourceModel('kbase/article')->getCategoryWithArticleList(Mage::getStoreConfig('kbase/category/count'))); return parent::_toHtml(); }
protected function _toHtml() { $this->setRatingEnabled(Mage::getStoreConfig('kbase/general/rating_enabled')); // processing article text $processorModelName = AW_Kbase_Helper_Data::mageVersionIsAbove13() ? 'widget/template_filter' : 'core/email_template_filter'; $processor = Mage::getModel($processorModelName); if ($processor instanceof Mage_Core_Model_Email_Template_Filter) { $this->setProcessedText($processor->filter($this->getArticle()->getArticleText())); } else { $this->setProcessedText($this->getArticle()->getArticleText()); } return parent::_toHtml(); }
protected function _toHtml() { if (!AW_Kbase_Helper_Data::getFrontendEnabled()) { return ''; } $this->_readBlock('search'); $this->_readBlock('category'); $this->_readBlock('top'); $this->_readBlock('latest'); $this->_readBlock('tag'); asort($this->_blocks); return parent::_toHtml(); }
protected function _toHtml() { if (!AW_Kbase_Helper_Data::getFrontendEnabled()) { return ''; } if (!Mage::getStoreConfig('kbase/latest/enabled')) { return ''; } $collection = Mage::getResourceModel('kbase/article_collection')->addStatusFilter()->setStoreFilter()->applySorting(AW_Kbase_Model_Source_Sorting::BY_DATE, AW_Kbase_Model_Source_Sorting::SORT_DESC)->limit(Mage::getStoreConfig('kbase/latest/count')); $collection->getSelect()->distinct(); $collection->load(); $this->setArticles($collection); return parent::_toHtml(); }
protected function _toHtml() { if (!AW_Kbase_Helper_Data::getFrontendEnabled()) { return ''; } if (!Mage::getStoreConfig('kbase/tag/enabled')) { return ''; } $autoSize = Mage::getStoreConfig('kbase/tag/auto_size'); $tagMaxCount = AW_Kbase_Model_Mysql4_Article::getTagMaxCount(); if (!$tagMaxCount) { $autoSize = false; } $this->setAutoSize($autoSize); $this->setTagMaxCount($tagMaxCount); $this->setTags(AW_Kbase_Model_Mysql4_Article::getAllTags($autoSize)); return parent::_toHtml(); }
public function voteAction() { $this->_checkRegistered(); $this->_checkFrontendEnabled(); try { $session = Mage::getSingleton('core/session'); $articleId = $this->getRequest()->getParam(AW_Kbase_Helper_Url::URL_PARAM_NAME_ARTICLE_ID); if (!AW_Kbase_Helper_Data::isArticleVoteAllowed($articleId)) { if (AW_Kbase_Helper_Data::VOTINGS_PER_DAY <= (int) Mage::app()->getRequest()->getCookie(AW_Kbase_Helper_Data::COOKIE_ARTICLES_VOTED_COUNT)) { $session->addNotice($this->__('You may vote only %s times per day!', AW_Kbase_Helper_Data::VOTINGS_PER_DAY)); } else { $session->addNotice($this->__('You have already voted on this article!')); } $this->_goBack(); return; } else { $rating = $this->getRequest()->getParam('rating'); if ($rating > 5 || $rating < 1) { throw new Exception($this->__('Wrong rating')); } Mage::getModel('kbase/article')->setArticleId($articleId)->vote($rating); if ($articlesVoted = Mage::app()->getRequest()->getCookie(AW_Kbase_Helper_Data::COOKIE_ARTICLES_VOTED_IDS)) { $articlesVoted .= ',' . $articleId; } else { $articlesVoted = $articleId; } setcookie(AW_Kbase_Helper_Data::COOKIE_ARTICLES_VOTED_IDS, $articlesVoted, time() + 60 * 60 * 24 * 30, '/'); $articlesVotedCount = (int) Mage::app()->getRequest()->getCookie(AW_Kbase_Helper_Data::COOKIE_ARTICLES_VOTED_COUNT); setcookie(AW_Kbase_Helper_Data::COOKIE_ARTICLES_VOTED_COUNT, $articlesVotedCount + 1, time() + 60 * 60 * 24, '/'); } $session->addSuccess($this->__('Your voice has been accepted. Thank you!')); } catch (Exception $e) { // Mage::logException($e); $session->addError($this->__('Unable to vote. Please, try again later')); } $this->_goBack(); }
public function downloadAttachmentAction() { if (!($id = $this->getRequest()->getParam('id'))) { Mage::getSingleton('adminhtml/session')->addError($this->__('No article specified')); $this->redirectHome(); return; } $fileName = AW_Kbase_Helper_Data::getAttachmentFilename($id); AW_Kbase_Helper_Data::downloadFile($fileName); }
public static function matchUrl(Zend_Controller_Request_Http $request) { if (AW_Kbase_Helper_Data::isModuleOutputDisabled() || !AW_Kbase_Helper_Data::getFrontendEnabled()) { return false; } $urlKey = self::getModuleUrlKey(); $pathInfo = $request->getPathInfo(); $requestUri = $request->getRequestUri(); if ($request->getParam('___from_store')) { $_fromStore = Mage::app()->getSafeStore($request->getParam('___from_store')); if ($_fromStore->getData()) { $_oldUrlKey = self::getModuleUrlKeyFromConfig($_fromStore); if (strpos($pathInfo, '/' . $_oldUrlKey) === 0 && $_oldUrlKey != $urlKey) { $_newUrl = self::secureUrl(Mage::getBaseUrl() . $urlKey . '/'); $response = Mage::app()->getResponse(); $response->setRedirect($_newUrl); $response->sendHeaders(); $request->setDispatched(true); return true; } } } if (0 !== strpos($pathInfo, '/' . $urlKey . '/')) { // if path does not begin with /kbase/ return false; } $pathInfo = substr($pathInfo, strlen($urlKey) + 2); $request->setModuleName('kbase')->setControllerName('article'); if (!strlen($pathInfo)) { $request->setActionName('index'); return AW_Kbase_Helper_Data::getFrontendEnabled() && self::cacheRewrite($request->getPathInfo(), 'kbase/article/index'); } $urlKeySuffix = self::getUrlKeySuffix(); $isArticle = false; if (!$urlKeySuffix) { $_path = explode('/', $pathInfo); $_aUrl = false; if (count($_path) == 1) { $_aUrl = $_path[0]; } if (count($_path) == 2) { $_aUrl = $_path[1]; } if ($_aUrl) { $_aUrl = urldecode($_aUrl); $_aId = Mage::getModel('kbase/article')->getResource()->getIdByUrlKey($_aUrl); if (!$_aId) { $_aId = Mage::getModel('kbase/article')->getResource()->getIdByUrlKey($_aUrl, true); } if ($_aId) { $isArticle = true; } } } /** * Checking is customer comes from other store view * having various article suffix id in comparison * with current */ if ($request->getParam('___from_store') && !$isArticle) { if (!isset($_fromStore)) { $_fromStore = Mage::app()->getSafeStore($request->getParam('___from_store')); } if ($_fromStore->getData()) { $_oldUrlSuffix = self::getUrlKeySuffixFromConfig($_fromStore); if ($urlKeySuffix != $_oldUrlSuffix) { $_path = explode('/', $pathInfo); $_aUrl = false; if (count($_path) == 1) { $_aUrl = $_path[0]; } if (count($_path) == 2) { $_aUrl = $_path[1]; } if ($_aUrl) { $_articleUrlKey = substr($_aUrl, 0, strpos($_aUrl, $_oldUrlSuffix)); $_aId = Mage::getModel('kbase/article')->getResource()->getIdByUrlKey($_articleUrlKey); if (!$_aId) { $_aId = Mage::getModel('kbase/article')->getResource()->getIdByUrlKey($_articleUrlKey, true); } if ($_aId) { $_storeIds = Mage::getModel('kbase/article')->getResource()->getArticleStoreIds($_aId); if (in_array(Mage::app()->getStore()->getId(), $_storeIds)) { $_newUrl = self::secureUrl(Mage::getBaseUrl() . $urlKey . '/' . $_articleUrlKey . $urlKeySuffix); $response = Mage::app()->getResponse(); $response->setRedirect($_newUrl); $response->sendHeaders(); $request->setDispatched(true); return true; } } } } } } if ($urlKeySuffix && '/' != $urlKeySuffix && $urlKeySuffix == substr($pathInfo, -strlen($urlKeySuffix)) || $isArticle) { $pathInfo = substr($pathInfo, 0, strlen($pathInfo) - strlen($urlKeySuffix)); $path = explode('/', $pathInfo); if (count($path) == 1) { $request->setActionName('article'); self::$_queryParams[self::URL_PARAM_NAME_ARTICLE] = $path[0]; return self::cacheRewrite($request->getPathInfo(), 'kbase/article/article/' . self::URL_PARAM_NAME_ARTICLE . '/' . $path[0]); } elseif (count($path) == 2) { $request->setActionName('article'); self::$_queryParams[self::URL_PARAM_NAME_CATEGORY] = $path[0]; self::$_queryParams[self::URL_PARAM_NAME_ARTICLE] = $path[1]; return self::cacheRewrite($request->getPathInfo(), 'kbase/article/article/' . self::URL_PARAM_NAME_CATEGORY . '/' . $path[0] . '/' . self::URL_PARAM_NAME_ARTICLE . '/' . $path[1]); } return false; } // since further there will be listing pages only, we should check the condition here if (!Mage::getStoreConfig('kbase/general/frontent_enabled')) { return false; } // init parameters with optional ones self::$_queryParams = array(self::URL_PARAM_NAME_LIMIT => false, self::URL_PARAM_NAME_PAGE => false, self::URL_PARAM_NAME_SORT => false, self::URL_PARAM_NAME_SORT_DIR => false, self::URL_PARAM_NAME_QUERY => false); $pathInfo = substr($pathInfo, 0, strlen($pathInfo) - 1); $path = explode('/', $pathInfo); for ($i = count($path) - 1; $i > 0; $i -= 2) { $paramName = $path[$i - 1]; if (array_key_exists($paramName, self::$_queryParams)) { // for(; $path[$i] != $decoded = urldecode($path[$i]); $path[$i] = $decoded); // self::$_queryParams[$paramName] = $path[$i]; self::$_queryParams[$paramName] = urldecode($path[$i]); unset($path[$i]); unset($path[$i - 1]); } } foreach (self::$_queryParams as $paramName => $value) { if ($value = self::getQueryParam($requestUri, $paramName)) { self::$_queryParams[$paramName] = urldecode($value); $requestUri = self::unsetQueryParam($requestUri, $paramName); } } if (1 == count($path)) { if ('search' == $path[0]) { // if there were known parameters passed as query params if ($requestUri != $request->getRequestUri()) { foreach (self::$_queryParams as $name => $value) { if ($value) { self::$_queryParams[$name] = self::encodeSpecialChars($value); } } Mage::app()->getFrontController()->getResponse()->setRedirect(self::getUrl(self::URL_TYPE_SEARCH, self::$_queryParams))->sendResponse(); exit; } $request->setActionName('search'); return true; } $request->setActionName('category'); self::$_queryParams[self::URL_PARAM_NAME_CATEGORY] = $path[0]; return true; } elseif (2 == count($path) && 'tag' == $path[0] && $path[1]) { $request->setActionName('tag'); self::$_queryParams[self::URL_PARAM_NAME_TAG] = $path[1]; return true; } return false; }
protected function _toHtml() { if (!AW_Kbase_Helper_Data::getFrontendEnabled()) { return ''; } $this->_prepareCollection(); if ($sorter = $this->getChild('kbase_sorter')) { list($sortOrder, $sortDir) = $sorter->getCurrentSorting(); if ($sortOrder) { $this->_collection = $this->_collection->applySorting($sortOrder, $sortDir); } } if ($pager = $this->getChild('kbase_pager')) { $this->_collection = $pager->setCollection($this->_collection)->getCollection(); } return parent::_toHtml(); }
public function addSearchFilter($words) { if (!is_array($words)) { $words = AW_Kbase_Helper_Data::parseQuery($words); } foreach ($words as $word) { $arrayWhere[] = $this->getConnection()->quoteInto("(main_table.article_title LIKE ?)", '%' . $word . '%'); $arrayWhere[] = $this->getConnection()->quoteInto("(main_table.article_text LIKE ?)", '%' . $word . '%'); } if (is_array($arrayWhere) && count($arrayWhere) > 0) { $this->getSelect()->where(implode(' OR ', $arrayWhere)); } return $this; }
protected function _beforeDelete() { AW_Kbase_Helper_Data::removeDirectory(AW_Kbase_Helper_Data::attachmentDirName($this->getId())); return parent::_beforeDelete(); }
public function saveTags($articleId, $tags) { if (!is_array($tags)) { $rawTags = explode(',', strtolower($tags)); $tags = array(); foreach ($rawTags as $tag) { $tag = trim($tag); while (false !== strpos($tag, ' ')) { $tag = str_replace(' ', ' ', $tag); } if ($tag) { $tags[] = $tag; } } } $existing = $this->getTags($articleId); $common = array_intersect($existing, $tags); $deleted = array_diff($existing, $common); $new = array_diff($tags, $common); $db = $this->_getWriteAdapter(); if (!empty($deleted)) { foreach ($deleted as $tagName) { $arrayWords[] = $db->getConnection()->quote($tagName); } $db->delete($this->getTable('kbase/tag'), 'tag_article_id=' . $articleId . ' AND tag_name IN (' . implode(',', $arrayWords) . ')'); } if (!empty($new)) { $data = array(); foreach ($new as $tagName) { $data[] = array($articleId, $tagName); } AW_Kbase_Helper_Data::insertArray($this->getTable('kbase/tag'), array('tag_article_id', 'tag_name'), $data); } return $this; }
public function saveStoreIds($categoryId, $storeIds) { if (!is_array($storeIds)) { $storeIds = explode(',', $storeIds); } $existing = $this->getStoreIds($categoryId); $common = array_intersect($existing, $storeIds); $deleted = array_diff($existing, $common); $new = array_diff($storeIds, $common); $db = $this->_getWriteAdapter(); if (!empty($deleted)) { $db->delete($this->getTable('kbase/category_store'), 'category_id=' . $categoryId . ' AND store_id IN (' . implode(',', $deleted) . ')'); } if (!empty($new)) { $data = array(); foreach ($new as $storeId) { $data[] = array($categoryId, $storeId); } AW_Kbase_Helper_Data::insertArray($this->getTable('kbase/category_store'), array('category_id', 'store_id'), $data); } return $this; }