lavi_news - Version 1.0.1

Version Notes

news for your website.

Download this release

Release Info

Developer Navneet
Extension lavi_news
Version 1.0.1
Comparing to
See all releases


Version 1.0.1

Files changed (32) hide show
  1. app/code/community/Lavi/News/Block/Adminhtml/News.php +53 -0
  2. app/code/community/Lavi/News/Block/Adminhtml/News/Edit.php +87 -0
  3. app/code/community/Lavi/News/Block/Adminhtml/News/Edit/Form.php +46 -0
  4. app/code/community/Lavi/News/Block/Adminhtml/News/Edit/Form/Element/Image.php +41 -0
  5. app/code/community/Lavi/News/Block/Adminhtml/News/Edit/Tab/Content.php +133 -0
  6. app/code/community/Lavi/News/Block/Adminhtml/News/Edit/Tab/Image.php +126 -0
  7. app/code/community/Lavi/News/Block/Adminhtml/News/Edit/Tab/Main.php +134 -0
  8. app/code/community/Lavi/News/Block/Adminhtml/News/Edit/Tabs.php +39 -0
  9. app/code/community/Lavi/News/Block/Adminhtml/News/Grid.php +132 -0
  10. app/code/community/Lavi/News/Block/Item.php +64 -0
  11. app/code/community/Lavi/News/Block/List.php +114 -0
  12. app/code/community/Lavi/News/Block/Sidebar.php +82 -0
  13. app/code/community/Lavi/News/Helper/Admin.php +38 -0
  14. app/code/community/Lavi/News/Helper/Data.php +140 -0
  15. app/code/community/Lavi/News/Helper/Image.php +217 -0
  16. app/code/community/Lavi/News/Model/News.php +49 -0
  17. app/code/community/Lavi/News/Model/Observer.php +44 -0
  18. app/code/community/Lavi/News/Model/Resource/News.php +35 -0
  19. app/code/community/Lavi/News/Model/Resource/News/Collection.php +48 -0
  20. app/code/community/Lavi/News/controllers/Adminhtml/NewsController.php +289 -0
  21. app/code/community/Lavi/News/controllers/IndexController.php +96 -0
  22. app/code/community/Lavi/News/etc/adminhtml.xml +81 -0
  23. app/code/community/Lavi/News/etc/config.xml +124 -0
  24. app/code/community/Lavi/News/etc/system.xml +114 -0
  25. app/code/community/Lavi/News/sql/lavi_news_setup/install-1.0.0.0.1.php +72 -0
  26. app/design/adminhtml/default/default/layout/lavi_news.xml +58 -0
  27. app/design/frontend/base/default/layout/lavi_news.xml +81 -0
  28. app/design/frontend/base/default/template/lavi/news/item.phtml +50 -0
  29. app/design/frontend/base/default/template/lavi/news/list.phtml +52 -0
  30. app/design/frontend/base/default/template/lavi/news/sidebar.phtml +52 -0
  31. app/etc/modules/Lavi_News.xml +19 -0
  32. package.xml +46 -0
app/code/community/Lavi/News/Block/Adminhtml/News.php ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * SAGIPL
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ *
12
+ * @category SAGIPL
13
+ * @package Lavi_News
14
+ * @copyright Copyright (c) 2014 SAGIPL. (http://www.sagipl.com/)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * Free Shipping Offer Message
20
+ *
21
+ * @category SAGIPL
22
+ * @package Lavi_News
23
+ * @author Navneet <navneet.kshk@gmail.com>
24
+ */
25
+
26
+ class Lavi_News_Block_Adminhtml_News extends Mage_Adminhtml_Block_Widget_Grid_Container
27
+ {
28
+ /**
29
+ * Block constructor
30
+ */
31
+ public function __construct()
32
+ {
33
+ $this->_blockGroup = 'lavi_news';
34
+ $this->_controller = 'adminhtml_news';
35
+ $this->_headerText = Mage::helper('lavi_news')->__('Manage News');
36
+
37
+ parent::__construct();
38
+
39
+ if (Mage::helper('lavi_news/admin')->isActionAllowed('save')) {
40
+ $this->_updateButton('add', 'label', Mage::helper('lavi_news')->__('Add New News'));
41
+ } else {
42
+ $this->_removeButton('add');
43
+ }
44
+ $this->addButton(
45
+ 'news_flush_images_cache',
46
+ array(
47
+ 'label' => Mage::helper('lavi_news')->__('Flush Images Cache'),
48
+ 'onclick' => 'setLocation(\'' . $this->getUrl('*/*/flush') . '\')',
49
+ )
50
+ );
51
+
52
+ }
53
+ }
app/code/community/Lavi/News/Block/Adminhtml/News/Edit.php ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * SAGIPL
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ *
12
+ * @category SAGIPL
13
+ * @package Lavi_News
14
+ * @copyright Copyright (c) 2014 SAGIPL. (http://www.sagipl.com/)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * Free Shipping Offer Message
20
+ *
21
+ * @category SAGIPL
22
+ * @package Lavi_News
23
+ * @author Navneet <navneet.kshk@gmail.com>
24
+ */
25
+
26
+ class Lavi_News_Block_Adminhtml_News_Edit extends Mage_Adminhtml_Block_Widget_Form_Container
27
+ {
28
+ /**
29
+ * Initialize edit form container
30
+ *
31
+ */
32
+ public function __construct()
33
+ {
34
+ $this->_objectId = 'id';
35
+ $this->_blockGroup = 'lavi_news';
36
+ $this->_controller = 'adminhtml_news';
37
+
38
+ parent::__construct();
39
+
40
+ if (Mage::helper('lavi_news/admin')->isActionAllowed('save')) {
41
+ $this->_updateButton('save', 'label', Mage::helper('lavi_news')->__('Save News Item'));
42
+ $this->_addButton('saveandcontinue', array(
43
+ 'label' => Mage::helper('adminhtml')->__('Save and Continue Edit'),
44
+ 'onclick' => 'saveAndContinueEdit()',
45
+ 'class' => 'save',
46
+ ), -100);
47
+ } else {
48
+ $this->_removeButton('save');
49
+ }
50
+
51
+ if (Mage::helper('lavi_news/admin')->isActionAllowed('delete')) {
52
+ $this->_updateButton('delete', 'label', Mage::helper('lavi_news')->__('Delete News Item'));
53
+ } else {
54
+ $this->_removeButton('delete');
55
+ }
56
+
57
+ $this->_formScripts[] = "
58
+ function toggleEditor() {
59
+ if (tinyMCE.getInstanceById('page_content') == null) {
60
+ tinyMCE.execCommand('mceAddControl', false, 'page_content');
61
+ } else {
62
+ tinyMCE.execCommand('mceRemoveControl', false, 'page_content');
63
+ }
64
+ }
65
+
66
+ function saveAndContinueEdit(){
67
+ editForm.submit($('edit_form').action+'back/edit/');
68
+ }
69
+ ";
70
+ }
71
+
72
+ /**
73
+ * Retrieve text for header element depending on loaded page
74
+ *
75
+ * @return string
76
+ */
77
+ public function getHeaderText()
78
+ {
79
+ $model = Mage::helper('lavi_news')->getNewsItemInstance();
80
+ if ($model->getId()) {
81
+ return Mage::helper('lavi_news')->__("Edit News Item '%s'",
82
+ $this->escapeHtml($model->getTitle()));
83
+ } else {
84
+ return Mage::helper('lavi_news')->__('New News Item');
85
+ }
86
+ }
87
+ }
app/code/community/Lavi/News/Block/Adminhtml/News/Edit/Form.php ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * SAGIPL
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ *
12
+ * @category SAGIPL
13
+ * @package Lavi_News
14
+ * @copyright Copyright (c) 2014 SAGIPL. (http://www.sagipl.com/)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * Free Shipping Offer Message
20
+ *
21
+ * @category SAGIPL
22
+ * @package Lavi_News
23
+ * @author Navneet <navneet.kshk@gmail.com>
24
+ */
25
+
26
+ class Lavi_News_Block_Adminhtml_News_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
27
+ {
28
+ /**
29
+ * Prepare form action
30
+ *
31
+ * @return Magentostudy_News_Block_Adminhtml_News_Edit_Form
32
+ */
33
+ protected function _prepareForm()
34
+ {
35
+ $form = new Varien_Data_Form(array(
36
+ 'id' => 'edit_form',
37
+ 'action' => $this->getUrl('*/*/save'),
38
+ 'method' => 'post',
39
+ 'enctype' => 'multipart/form-data'
40
+ ));
41
+
42
+ $form->setUseContainer(true);
43
+ $this->setForm($form);
44
+ return parent::_prepareForm();
45
+ }
46
+ }
app/code/community/Lavi/News/Block/Adminhtml/News/Edit/Form/Element/Image.php ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * SAGIPL
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ *
12
+ * @category SAGIPL
13
+ * @package Lavi_News
14
+ * @copyright Copyright (c) 2014 SAGIPL. (http://www.sagipl.com/)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * Free Shipping Offer Message
20
+ *
21
+ * @category SAGIPL
22
+ * @package Lavi_News
23
+ * @author Navneet <navneet.kshk@gmail.com>
24
+ */
25
+
26
+ class Lavi_News_Block_Adminhtml_News_Edit_Form_Element_Image extends Varien_Data_Form_Element_Image
27
+ {
28
+ /**
29
+ * Get image preview url
30
+ *
31
+ * @return string
32
+ */
33
+ protected function _getUrl()
34
+ {
35
+ $url = false;
36
+ if ($this->getValue()) {
37
+ $url = Mage::helper('lavi_news/image')->getBaseUrl() . '/' . $this->getValue();
38
+ }
39
+ return $url;
40
+ }
41
+ }
app/code/community/Lavi/News/Block/Adminhtml/News/Edit/Tab/Content.php ADDED
@@ -0,0 +1,133 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * SAGIPL
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ *
12
+ * @category SAGIPL
13
+ * @package Lavi_News
14
+ * @copyright Copyright (c) 2014 SAGIPL. (http://www.sagipl.com/)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * Free Shipping Offer Message
20
+ *
21
+ * @category SAGIPL
22
+ * @package Lavi_News
23
+ * @author Navneet <navneet.kshk@gmail.com>
24
+ */
25
+
26
+ class Lavi_News_Block_Adminhtml_News_Edit_Tab_Content
27
+ extends Mage_Adminhtml_Block_Widget_Form
28
+ implements Mage_Adminhtml_Block_Widget_Tab_Interface
29
+ {
30
+ /**
31
+ * Load WYSIWYG on demand and prepare layout
32
+ */
33
+ protected function _prepareLayout()
34
+ {
35
+ parent::_prepareLayout();
36
+ if (Mage::getSingleton('cms/wysiwyg_config')->isEnabled()) {
37
+ $this->getLayout()->getBlock('head')->setCanLoadTinyMce(true);
38
+ }
39
+ return $this;
40
+ }
41
+
42
+ /**
43
+ * Prepares tab form
44
+ *
45
+ * @return Mage_Adminhtml_Block_Widget_Form
46
+ */
47
+ protected function _prepareForm()
48
+ {
49
+ $model = Mage::helper('lavi_news')->getNewsItemInstance();
50
+
51
+ /**
52
+ * Checking if user have permissions to save information
53
+ */
54
+ if (Mage::helper('lavi_news/admin')->isActionAllowed('save')) {
55
+ $isElementDisabled = false;
56
+ } else {
57
+ $isElementDisabled = true;
58
+ }
59
+
60
+ $form = new Varien_Data_Form();
61
+
62
+ $form->setHtmlIdPrefix('news_content_');
63
+
64
+ $fieldset = $form->addFieldset('content_fieldset', array(
65
+ 'legend' => Mage::helper('lavi_news')->__('Content'),
66
+ 'class' => 'fieldset-wide'
67
+ ));
68
+
69
+ $wysiwygConfig = Mage::getSingleton('cms/wysiwyg_config')->getConfig(array(
70
+ 'tab_id' => $this->getTabId()
71
+ ));
72
+
73
+ $contentField = $fieldset->addField('content', 'editor', array(
74
+ 'name' => 'content',
75
+ 'style' => 'height:36em;',
76
+ 'required' => true,
77
+ 'disabled' => $isElementDisabled,
78
+ 'config' => $wysiwygConfig
79
+ ));
80
+
81
+ // Setting custom renderer for content field to remove label column
82
+ $renderer = $this->getLayout()->createBlock('adminhtml/widget_form_renderer_fieldset_element')
83
+ ->setTemplate('cms/page/edit/form/renderer/content.phtml');
84
+ $contentField->setRenderer($renderer);
85
+
86
+ $form->setValues($model->getData());
87
+ $this->setForm($form);
88
+
89
+ Mage::dispatchEvent('adminhtml_news_edit_tab_content_prepare_form', array('form' => $form));
90
+
91
+ return parent::_prepareForm();
92
+ }
93
+
94
+ /**
95
+ * Prepare label for tab
96
+ *
97
+ * @return string
98
+ */
99
+ public function getTabLabel()
100
+ {
101
+ return Mage::helper('lavi_news')->__('Content');
102
+ }
103
+
104
+ /**
105
+ * Prepare title for tab
106
+ *
107
+ * @return string
108
+ */
109
+ public function getTabTitle()
110
+ {
111
+ return Mage::helper('lavi_news')->__('Content');
112
+ }
113
+
114
+ /**
115
+ * Returns status flag about this tab can be shown or not
116
+ *
117
+ * @return true
118
+ */
119
+ public function canShowTab()
120
+ {
121
+ return true;
122
+ }
123
+
124
+ /**
125
+ * Returns status flag about this tab hidden or not
126
+ *
127
+ * @return true
128
+ */
129
+ public function isHidden()
130
+ {
131
+ return false;
132
+ }
133
+ }
app/code/community/Lavi/News/Block/Adminhtml/News/Edit/Tab/Image.php ADDED
@@ -0,0 +1,126 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * SAGIPL
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ *
12
+ * @category SAGIPL
13
+ * @package Lavi_News
14
+ * @copyright Copyright (c) 2014 SAGIPL. (http://www.sagipl.com/)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * Free Shipping Offer Message
20
+ *
21
+ * @category SAGIPL
22
+ * @package Lavi_News
23
+ * @author Navneet <navneet.kshk@gmail.com>
24
+ */
25
+
26
+ class Lavi_News_Block_Adminhtml_News_Edit_Tab_Image
27
+ extends Mage_Adminhtml_Block_Widget_Form
28
+ implements Mage_Adminhtml_Block_Widget_Tab_Interface
29
+ {
30
+ /**
31
+ * Prepare form elements
32
+ *
33
+ * @return Mage_Adminhtml_Block_Widget_Form
34
+ */
35
+ protected function _prepareForm()
36
+ {
37
+ /**
38
+ * Checking if user have permissions to save information
39
+ */
40
+ if (Mage::helper('lavi_news/admin')->isActionAllowed('save')) {
41
+ $isElementDisabled = false;
42
+ } else {
43
+ $isElementDisabled = true;
44
+ }
45
+
46
+ $form = new Varien_Data_Form();
47
+
48
+ $form->setHtmlIdPrefix('news_image_');
49
+
50
+ $model = Mage::helper('lavi_news')->getNewsItemInstance();
51
+
52
+
53
+ $fieldset = $form->addFieldset('image_fieldset', array(
54
+ 'legend' => Mage::helper('lavi_news')->__('Image Thumbnail'), 'class' => 'fieldset-wide'
55
+ ));
56
+
57
+ $this->_addElementTypes($fieldset);
58
+
59
+ $fieldset->addField('image', 'image', array(
60
+ 'name' => 'image',
61
+ 'label' => Mage::helper('lavi_news')->__('Image'),
62
+ 'title' => Mage::helper('lavi_news')->__('Image'),
63
+ 'required' => false,
64
+ 'disabled' => $isElementDisabled
65
+ ));
66
+
67
+ Mage::dispatchEvent('adminhtml_news_edit_tab_image_prepare_form', array('form' => $form));
68
+
69
+ $form->setValues($model->getData());
70
+ $this->setForm($form);
71
+
72
+ return parent::_prepareForm();
73
+ }
74
+
75
+ /**
76
+ * Prepare label for tab
77
+ *
78
+ * @return string
79
+ */
80
+ public function getTabLabel()
81
+ {
82
+ return Mage::helper('lavi_news')->__('Image Thumbnail');
83
+ }
84
+
85
+ /**
86
+ * Prepare title for tab
87
+ *
88
+ * @return string
89
+ */
90
+ public function getTabTitle()
91
+ {
92
+ return Mage::helper('lavi_news')->__('Image Thumbnail');
93
+ }
94
+
95
+ /**
96
+ * Returns status flag about this tab can be showen or not
97
+ *
98
+ * @return true
99
+ */
100
+ public function canShowTab()
101
+ {
102
+ return true;
103
+ }
104
+
105
+ /**
106
+ * Returns status flag about this tab hidden or not
107
+ *
108
+ * @return true
109
+ */
110
+ public function isHidden()
111
+ {
112
+ return false;
113
+ }
114
+
115
+ /**
116
+ * Retrieve predefined additional element types
117
+ *
118
+ * @return array
119
+ */
120
+ protected function _getAdditionalElementTypes()
121
+ {
122
+ return array(
123
+ 'image' => Mage::getConfig()->getBlockClassName('lavi_news/adminhtml_news_edit_form_element_image')
124
+ );
125
+ }
126
+ }
app/code/community/Lavi/News/Block/Adminhtml/News/Edit/Tab/Main.php ADDED
@@ -0,0 +1,134 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * SAGIPL
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ *
12
+ * @category SAGIPL
13
+ * @package Lavi_News
14
+ * @copyright Copyright (c) 2014 SAGIPL. (http://www.sagipl.com/)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * Free Shipping Offer Message
20
+ *
21
+ * @category SAGIPL
22
+ * @package Lavi_News
23
+ * @author Navneet <navneet.kshk@gmail.com>
24
+ */
25
+
26
+ class Lavi_News_Block_Adminhtml_News_Edit_Tab_Main
27
+ extends Mage_Adminhtml_Block_Widget_Form
28
+ implements Mage_Adminhtml_Block_Widget_Tab_Interface
29
+ {
30
+ /**
31
+ * Prepare form elements for tab
32
+ *
33
+ * @return Mage_Adminhtml_Block_Widget_Form
34
+ */
35
+ protected function _prepareForm()
36
+ {
37
+ $model = Mage::helper('lavi_news')->getNewsItemInstance();
38
+
39
+ /**
40
+ * Checking if user have permissions to save information
41
+ */
42
+ if (Mage::helper('lavi_news/admin')->isActionAllowed('save')) {
43
+ $isElementDisabled = false;
44
+ } else {
45
+ $isElementDisabled = true;
46
+ }
47
+
48
+ $form = new Varien_Data_Form();
49
+
50
+ $form->setHtmlIdPrefix('news_main_');
51
+
52
+ $fieldset = $form->addFieldset('base_fieldset', array(
53
+ 'legend' => Mage::helper('lavi_news')->__('News Item Info')
54
+ ));
55
+
56
+ if ($model->getId()) {
57
+ $fieldset->addField('news_id', 'hidden', array(
58
+ 'name' => 'news_id',
59
+ ));
60
+ }
61
+
62
+ $fieldset->addField('title', 'text', array(
63
+ 'name' => 'title',
64
+ 'label' => Mage::helper('lavi_news')->__('News Title'),
65
+ 'title' => Mage::helper('lavi_news')->__('News Title'),
66
+ 'required' => true,
67
+ 'disabled' => $isElementDisabled
68
+ ));
69
+
70
+ $fieldset->addField('author', 'text', array(
71
+ 'name' => 'author',
72
+ 'label' => Mage::helper('lavi_news')->__('Author'),
73
+ 'title' => Mage::helper('lavi_news')->__('Author'),
74
+ 'required' => true,
75
+ 'disabled' => $isElementDisabled
76
+ ));
77
+
78
+ $fieldset->addField('published_at', 'date', array(
79
+ 'name' => 'published_at',
80
+ 'format' => Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT),
81
+ 'image' => $this->getSkinUrl('images/grid-cal.gif'),
82
+ 'label' => Mage::helper('lavi_news')->__('Publishing Date'),
83
+ 'title' => Mage::helper('lavi_news')->__('Publishing Date'),
84
+ 'required' => true
85
+ ));
86
+
87
+ Mage::dispatchEvent('adminhtml_news_edit_tab_main_prepare_form', array('form' => $form));
88
+
89
+ $form->setValues($model->getData());
90
+ $this->setForm($form);
91
+
92
+ return parent::_prepareForm();
93
+ }
94
+
95
+ /**
96
+ * Prepare label for tab
97
+ *
98
+ * @return string
99
+ */
100
+ public function getTabLabel()
101
+ {
102
+ return Mage::helper('lavi_news')->__('News Info');
103
+ }
104
+
105
+ /**
106
+ * Prepare title for tab
107
+ *
108
+ * @return string
109
+ */
110
+ public function getTabTitle()
111
+ {
112
+ return Mage::helper('lavi_news')->__('News Info');
113
+ }
114
+
115
+ /**
116
+ * Returns status flag about this tab can be shown or not
117
+ *
118
+ * @return true
119
+ */
120
+ public function canShowTab()
121
+ {
122
+ return true;
123
+ }
124
+
125
+ /**
126
+ * Returns status flag about this tab hidden or not
127
+ *
128
+ * @return true
129
+ */
130
+ public function isHidden()
131
+ {
132
+ return false;
133
+ }
134
+ }
app/code/community/Lavi/News/Block/Adminhtml/News/Edit/Tabs.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * SAGIPL
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ *
12
+ * @category SAGIPL
13
+ * @package Lavi_News
14
+ * @copyright Copyright (c) 2014 SAGIPL. (http://www.sagipl.com/)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * Free Shipping Offer Message
20
+ *
21
+ * @category SAGIPL
22
+ * @package Lavi_News
23
+ * @author Navneet <navneet.kshk@gmail.com>
24
+ */
25
+
26
+ class Lavi_News_Block_Adminhtml_News_Edit_Tabs extends Mage_Adminhtml_Block_Widget_Tabs
27
+ {
28
+ /**
29
+ * Initialize tabs and define tabs block settings
30
+ *
31
+ */
32
+ public function __construct()
33
+ {
34
+ parent::__construct();
35
+ $this->setId('page_tabs');
36
+ $this->setDestElementId('edit_form');
37
+ $this->setTitle(Mage::helper('lavi_news')->__('News Item Info'));
38
+ }
39
+ }
app/code/community/Lavi/News/Block/Adminhtml/News/Grid.php ADDED
@@ -0,0 +1,132 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * SAGIPL
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ *
12
+ * @category SAGIPL
13
+ * @package Lavi_News
14
+ * @copyright Copyright (c) 2014 SAGIPL. (http://www.sagipl.com/)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * Free Shipping Offer Message
20
+ *
21
+ * @category SAGIPL
22
+ * @package Lavi_News
23
+ * @author Navneet <navneet.kshk@gmail.com>
24
+ */
25
+
26
+ class Lavi_News_Block_Adminhtml_News_Grid extends Mage_Adminhtml_Block_Widget_Grid
27
+ {
28
+ /**
29
+ * Init Grid default properties
30
+ *
31
+ */
32
+ public function __construct()
33
+ {
34
+ parent::__construct();
35
+ $this->setId('news_list_grid');
36
+ $this->setDefaultSort('created_at');
37
+ $this->setDefaultDir('DESC');
38
+ $this->setSaveParametersInSession(true);
39
+ $this->setUseAjax(true);
40
+ }
41
+
42
+ /**
43
+ * Prepare collection for Grid
44
+ *
45
+ * @return Lavi_News_Block_Adminhtml_Grid
46
+ */
47
+ protected function _prepareCollection()
48
+ {
49
+ $collection = Mage::getModel('lavi_news/news')->getResourceCollection();
50
+
51
+ $this->setCollection($collection);
52
+ return parent::_prepareCollection();
53
+ }
54
+
55
+ /**
56
+ * Prepare Grid columns
57
+ *
58
+ * @return Mage_Adminhtml_Block_Catalog_Search_Grid
59
+ */
60
+ protected function _prepareColumns()
61
+ {
62
+ $this->addColumn('news_id', array(
63
+ 'header' => Mage::helper('lavi_news')->__('ID'),
64
+ 'width' => '50px',
65
+ 'index' => 'news_id',
66
+ ));
67
+
68
+ $this->addColumn('title', array(
69
+ 'header' => Mage::helper('lavi_news')->__('News Title'),
70
+ 'index' => 'title',
71
+ ));
72
+
73
+ $this->addColumn('author', array(
74
+ 'header' => Mage::helper('lavi_news')->__('Author'),
75
+ 'index' => 'author',
76
+ ));
77
+
78
+ $this->addColumn('published_at', array(
79
+ 'header' => Mage::helper('lavi_news')->__('Published On'),
80
+ 'sortable' => true,
81
+ 'width' => '170px',
82
+ 'index' => 'published_at',
83
+ 'type' => 'date',
84
+ ));
85
+
86
+ $this->addColumn('created_at', array(
87
+ 'header' => Mage::helper('lavi_news')->__('Created'),
88
+ 'sortable' => true,
89
+ 'width' => '170px',
90
+ 'index' => 'created_at',
91
+ 'type' => 'datetime',
92
+ ));
93
+
94
+ $this->addColumn('action',
95
+ array(
96
+ 'header' => Mage::helper('lavi_news')->__('Action'),
97
+ 'width' => '100px',
98
+ 'type' => 'action',
99
+ 'getter' => 'getId',
100
+ 'actions' => array(array(
101
+ 'caption' => Mage::helper('lavi_news')->__('Edit'),
102
+ 'url' => array('base' => '*/*/edit'),
103
+ 'field' => 'id'
104
+ )),
105
+ 'filter' => false,
106
+ 'sortable' => false,
107
+ 'index' => 'news',
108
+ ));
109
+
110
+ return parent::_prepareColumns();
111
+ }
112
+
113
+ /**
114
+ * Return row URL for js event handlers
115
+ *
116
+ * @return string
117
+ */
118
+ public function getRowUrl($row)
119
+ {
120
+ return $this->getUrl('*/*/edit', array('id' => $row->getId()));
121
+ }
122
+
123
+ /**
124
+ * Grid url getter
125
+ *
126
+ * @return string current grid url
127
+ */
128
+ public function getGridUrl()
129
+ {
130
+ return $this->getUrl('*/*/grid', array('_current' => true));
131
+ }
132
+ }
app/code/community/Lavi/News/Block/Item.php ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * SAGIPL
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ *
12
+ * @category SAGIPL
13
+ * @package Lavi_News
14
+ * @copyright Copyright (c) 2014 SAGIPL. (http://www.sagipl.com/)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * Free Shipping Offer Message
20
+ *
21
+ * @category SAGIPL
22
+ * @package Lavi_News
23
+ * @author Navneet <navneet.kshk@gmail.com>
24
+ */
25
+
26
+ class Lavi_News_Block_Item extends Mage_Core_Block_Template
27
+ {
28
+ /**
29
+ * Current news item instance
30
+ */
31
+ protected $_item;
32
+
33
+ /**
34
+ * Return parameters for back url
35
+ *
36
+ * @param array $additionalParams
37
+ * @return array
38
+ */
39
+ protected function _getBackUrlQueryParams($additionalParams = array())
40
+ {
41
+ return array_merge(array('p' => $this->getPage()), $additionalParams);
42
+ }
43
+
44
+ /**
45
+ * Return URL to the news list page
46
+ *
47
+ * @return string
48
+ */
49
+ public function getBackUrl()
50
+ {
51
+ return $this->getUrl('*/', array('_query' => $this->_getBackUrlQueryParams()));
52
+ }
53
+
54
+ /**
55
+ * Return URL for resized News Item image
56
+ *
57
+ * @param integer $width
58
+ * @return string|false
59
+ */
60
+ public function getImageUrl($item, $width)
61
+ {
62
+ return Mage::helper('lavi_news/image')->resize($item, $width);
63
+ }
64
+ }
app/code/community/Lavi/News/Block/List.php ADDED
@@ -0,0 +1,114 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * SAGIPL
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ *
12
+ * @category SAGIPL
13
+ * @package Lavi_News
14
+ * @copyright Copyright (c) 2014 SAGIPL. (http://www.sagipl.com/)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * Free Shipping Offer Message
20
+ *
21
+ * @category SAGIPL
22
+ * @package Lavi_News
23
+ * @author Navneet <navneet.kshk@gmail.com>
24
+ */
25
+
26
+ class Lavi_News_Block_List extends Mage_Core_Block_Template
27
+ {
28
+ /**
29
+ * News collection
30
+ *
31
+ * @var Lavi_News_Model_Resource_News_Collection
32
+ */
33
+ protected $_newsCollection = null;
34
+
35
+ /**
36
+ * Retrieve news collection
37
+ *
38
+ * @return Lavi_News_Model_Resource_News_Collection
39
+ */
40
+ protected function _getCollection()
41
+ {
42
+ return Mage::getResourceModel('lavi_news/news_collection');
43
+ }
44
+
45
+ /**
46
+ * Retrieve prepared news collection
47
+ *
48
+ * @return Lavi_News_Model_Resource_News_Collection
49
+ */
50
+ public function getCollection()
51
+ {
52
+ if (is_null($this->_newsCollection)) {
53
+ $this->_newsCollection = $this->_getCollection();
54
+ $this->_newsCollection->prepareForList($this->getCurrentPage());
55
+ }
56
+
57
+ return $this->_newsCollection;
58
+ }
59
+
60
+ /**
61
+ * Return URL to item's view page
62
+ *
63
+ * @param Lavi_News_Model_News $newsItem
64
+ * @return string
65
+ */
66
+ public function getItemUrl($newsItem)
67
+ {
68
+ return $this->getUrl('*/*/view', array('id' => $newsItem->getId()));
69
+ }
70
+
71
+ /**
72
+ * Fetch the current page for the news list
73
+ *
74
+ * @return int
75
+ */
76
+ public function getCurrentPage()
77
+ {
78
+ return $this->getData('current_page') ? $this->getData('current_page') : 1;
79
+ }
80
+
81
+ /**
82
+ * Get a pager
83
+ *
84
+ * @return string|null
85
+ */
86
+ public function getPager()
87
+ {
88
+ $pager = $this->getChild('news_list_pager');
89
+ if ($pager) {
90
+ $newsPerPage = Mage::helper('lavi_news')->getNewsPerPage();
91
+
92
+ $pager->setAvailableLimit(array($newsPerPage => $newsPerPage));
93
+ $pager->setTotalNum($this->getCollection()->getSize());
94
+ $pager->setCollection($this->getCollection());
95
+ $pager->setShowPerPage(true);
96
+
97
+ return $pager->toHtml();
98
+ }
99
+
100
+ return null;
101
+ }
102
+
103
+ /**
104
+ * Return URL for resized News Item image
105
+ *
106
+ * @param Lavi_News_Model_News $item
107
+ * @param integer $width
108
+ * @return string|false
109
+ */
110
+ public function getImageUrl($item, $width)
111
+ {
112
+ return Mage::helper('lavi_news/image')->resize($item, $width);
113
+ }
114
+ }
app/code/community/Lavi/News/Block/Sidebar.php ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * SAGIPL
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ *
12
+ * @category SAGIPL
13
+ * @package Lavi_News
14
+ * @copyright Copyright (c) 2014 SAGIPL. (http://www.sagipl.com/)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * Free Shipping Offer Message
20
+ *
21
+ * @category SAGIPL
22
+ * @package Lavi_News
23
+ * @author Navneet <navneet.kshk@gmail.com>
24
+ */
25
+
26
+ class Lavi_News_Block_Sidebar extends Mage_Core_Block_Template
27
+ {
28
+ /**
29
+ * News collection
30
+ *
31
+ * @var Lavi_News_Model_Resource_News_Collection
32
+ */
33
+ protected $_newsCollection = null;
34
+
35
+ /**
36
+ * Retrieve news collection
37
+ *
38
+ * @return Lavi_News_Model_Resource_News_Collection
39
+ */
40
+ protected function _getCollection()
41
+ {
42
+ return Mage::getResourceModel('lavi_news/news_collection');
43
+ }
44
+
45
+ /**
46
+ * Retrieve prepared news collection
47
+ *
48
+ * @return Lavi_News_Model_Resource_News_Collection
49
+ */
50
+ public function getCollection()
51
+ {
52
+ if (is_null($this->_newsCollection)) {
53
+ $this->_newsCollection = $this->_getCollection()->setCurPage(1)->setPageSize(2);
54
+ //$this->_newsCollection->prepareForList($this->getCurrentPage());
55
+ }
56
+
57
+ return $this->_newsCollection;
58
+ }
59
+
60
+ /**
61
+ * Return URL to item's view page
62
+ *
63
+ * @param Lavi_News_Model_News $newsItem
64
+ * @return string
65
+ */
66
+ public function getItemUrl($newsItem)
67
+ {
68
+ return $this->getUrl('*/*/view', array('id' => $newsItem->getId()));
69
+ }
70
+
71
+ /**
72
+ * Return URL for resized News Item image
73
+ *
74
+ * @param Lavi_News_Model_News $item
75
+ * @param integer $width
76
+ * @return string|false
77
+ */
78
+ public function getImageUrl($item, $width)
79
+ {
80
+ return Mage::helper('lavi_news/image')->resize($item, $width);
81
+ }
82
+ }
app/code/community/Lavi/News/Helper/Admin.php ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * SAGIPL
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ *
12
+ * @category SAGIPL
13
+ * @package Lavi_News
14
+ * @copyright Copyright (c) 2014 SAGIPL. (http://www.sagipl.com/)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * Free Shipping Offer Message
20
+ *
21
+ * @category SAGIPL
22
+ * @package Lavi_News
23
+ * @author Navneet <navneet.kshk@gmail.com>
24
+ */
25
+
26
+ class Lavi_News_Helper_Admin extends Mage_Core_Helper_Abstract
27
+ {
28
+ /**
29
+ * Check permission for passed action
30
+ *
31
+ * @param string $action
32
+ * @return bool
33
+ */
34
+ public function isActionAllowed($action)
35
+ {
36
+ return Mage::getSingleton('admin/session')->isAllowed('news/manage/' . $action);
37
+ }
38
+ }
app/code/community/Lavi/News/Helper/Data.php ADDED
@@ -0,0 +1,140 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * SAGIPL
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ *
12
+ * @category SAGIPL
13
+ * @package Lavi_News
14
+ * @copyright Copyright (c) 2014 SAGIPL. (http://www.sagipl.com/)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * Free Shipping Offer Message
20
+ *
21
+ * @category SAGIPL
22
+ * @package Lavi_News
23
+ * @author Navneet <navneet.kshk@gmail.com>
24
+ */
25
+
26
+
27
+ class Lavi_News_Helper_Data extends Mage_Core_Helper_Data
28
+ {
29
+ /**
30
+ * Path to store config if front-end output is enabled
31
+ *
32
+ * @var string
33
+ */
34
+ const XML_PATH_ENABLED = 'news/view/enabled';
35
+
36
+ /**
37
+ * Path to store config where count of news posts per page is stored
38
+ *
39
+ * @var string
40
+ */
41
+ const XML_PATH_ITEMS_PER_PAGE = 'news/view/items_per_page';
42
+
43
+ /**
44
+ * Path to store config where count of days while news is still recently added is stored
45
+ *
46
+ * @var string
47
+ */
48
+ const XML_PATH_DAYS_DIFFERENCE = 'news/view/days_difference';
49
+
50
+ /**
51
+ * News Item instance for lazy loading
52
+ *
53
+ * @var Lavi_News_Model_News
54
+ */
55
+ protected $_newsItemInstance;
56
+
57
+ /**
58
+ * Checks whether news can be displayed in the frontend
59
+ *
60
+ * @param integer|string|Mage_Core_Model_Store $store
61
+ * @return boolean
62
+ */
63
+ public function isEnabled($store = null)
64
+ {
65
+ return Mage::getStoreConfigFlag(self::XML_PATH_ENABLED, $store);
66
+ }
67
+
68
+ /**
69
+ * Return the number of items per page
70
+ *
71
+ * @param integer|string|Mage_Core_Model_Store $store
72
+ * @return int
73
+ */
74
+ public function getNewsPerPage($store = null)
75
+ {
76
+ return abs((int)Mage::getStoreConfig(self::XML_PATH_ITEMS_PER_PAGE, $store));
77
+ }
78
+
79
+ /**
80
+ * Return difference in days while news is recently added
81
+ *
82
+ * @param integer|string|Mage_Core_Model_Store $store
83
+ * @return int
84
+ */
85
+ public function getDaysDifference($store = null)
86
+ {
87
+ return abs((int)Mage::getStoreConfig(self::XML_PATH_DAYS_DIFFERENCE, $store));
88
+ }
89
+
90
+ /**
91
+ * Return yes/no for left side position
92
+ *
93
+ * @param integer|string|Mage_Core_Model_Store $store
94
+ * @return boolean
95
+ */
96
+ public function getShowinleft($store = null)
97
+ {
98
+ return abs((int)Mage::getStoreConfig(self::XML_PATH_SHOWINLEFT, $store));
99
+ }
100
+
101
+ /**
102
+ * Return yes/no for right side position
103
+ *
104
+ * @param integer|string|Mage_Core_Model_Store $store
105
+ * @return boolean
106
+ */
107
+ public function getDaysShowinright($store = null)
108
+ {
109
+ return abs((int)Mage::getStoreConfig(self::XML_PATH_SHOWINRIGHT, $store));
110
+ }
111
+
112
+ /**
113
+ * Return number of news which are show in left/right
114
+ *
115
+ * @param integer|string|Mage_Core_Model_Store $store
116
+ * @return int
117
+ */
118
+ public function getNumberofnews($store = null)
119
+ {
120
+ return abs((int)Mage::getStoreConfig(self::XML_PATH_NUMBEROFNEWS, $store));
121
+ }
122
+
123
+ /**
124
+ * Return current news item instance from the Registry
125
+ *
126
+ * @return Lavi_News_Model_News
127
+ */
128
+ public function getNewsItemInstance()
129
+ {
130
+ if (!$this->_newsItemInstance) {
131
+ $this->_newsItemInstance = Mage::registry('news_item');
132
+
133
+ if (!$this->_newsItemInstance) {
134
+ Mage::throwException($this->__('News item instance does not exist in Registry'));
135
+ }
136
+ }
137
+
138
+ return $this->_newsItemInstance;
139
+ }
140
+ }
app/code/community/Lavi/News/Helper/Image.php ADDED
@@ -0,0 +1,217 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * SAGIPL
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ *
12
+ * @category SAGIPL
13
+ * @package Lavi_News
14
+ * @copyright Copyright (c) 2014 SAGIPL. (http://www.sagipl.com/)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * Free Shipping Offer Message
20
+ *
21
+ * @category SAGIPL
22
+ * @package Lavi_News
23
+ * @author Navneet <navneet.kshk@gmail.com>
24
+ */
25
+
26
+ class Lavi_News_Helper_Image extends Mage_Core_Helper_Abstract
27
+ {
28
+ /**
29
+ * Media path to extension imahes
30
+ *
31
+ * @var string
32
+ */
33
+ const MEDIA_PATH = 'news';
34
+
35
+ /**
36
+ * Maximum size for image in bytes
37
+ * Default value is 1M
38
+ *
39
+ * @var int
40
+ */
41
+ const MAX_FILE_SIZE = 1048576;
42
+
43
+ /**
44
+ * Manimum image height in pixels
45
+ *
46
+ * @var int
47
+ */
48
+ const MIN_HEIGHT = 50;
49
+
50
+ /**
51
+ * Maximum image height in pixels
52
+ *
53
+ * @var int
54
+ */
55
+ const MAX_HEIGHT = 800;
56
+
57
+ /**
58
+ * Manimum image width in pixels
59
+ *
60
+ * @var int
61
+ */
62
+ const MIN_WIDTH = 50;
63
+
64
+ /**
65
+ * Maximum image width in pixels
66
+ *
67
+ * @var int
68
+ */
69
+ const MAX_WIDTH = 800;
70
+
71
+ /**
72
+ * Array of image size limitation
73
+ *
74
+ * @var array
75
+ */
76
+ protected $_imageSize = array(
77
+ 'minheight' => self::MIN_HEIGHT,
78
+ 'minwidth' => self::MIN_WIDTH,
79
+ 'maxheight' => self::MAX_HEIGHT,
80
+ 'maxwidth' => self::MAX_WIDTH,
81
+ );
82
+
83
+ /**
84
+ * Array of allowed file extensions
85
+ *
86
+ * @var array
87
+ */
88
+ protected $_allowedExtensions = array('jpg', 'gif', 'png');
89
+
90
+ /**
91
+ * Return the base media directory for News Item images
92
+ *
93
+ * @return string
94
+ */
95
+ public function getBaseDir()
96
+ {
97
+ return Mage::getBaseDir('media') . DS . self::MEDIA_PATH;
98
+ }
99
+
100
+ /**
101
+ * Return the Base URL for News Item images
102
+ *
103
+ * @return string
104
+ */
105
+ public function getBaseUrl()
106
+ {
107
+ return Mage::getBaseUrl('media') . '/' . self::MEDIA_PATH;
108
+ }
109
+
110
+ /**
111
+ * Remove news item image by image filename
112
+ *
113
+ * @param string $imageFile
114
+ * @return bool
115
+ */
116
+ public function removeImage($imageFile)
117
+ {
118
+ $io = new Varien_Io_File();
119
+ $io->open(array('path' => $this->getBaseDir()));
120
+ if ($io->fileExists($imageFile)) {
121
+ return $io->rm($imageFile);
122
+ }
123
+ return false;
124
+ }
125
+
126
+ /**
127
+ * Upload image and return uploaded image file name or false
128
+ *
129
+ * @throws Mage_Core_Exception
130
+ * @param string $scope the request key for file
131
+ * @return bool|string
132
+ */
133
+ public function uploadImage($scope)
134
+ {
135
+ $adapter = new Zend_File_Transfer_Adapter_Http();
136
+ $adapter->addValidator('ImageSize', true, $this->_imageSize);
137
+ $adapter->addValidator('Size', true, self::MAX_FILE_SIZE);
138
+ if ($adapter->isUploaded($scope)) {
139
+ // validate image
140
+ if (!$adapter->isValid($scope)) {
141
+ Mage::throwException(Mage::helper('lavi_news')->__('Uploaded image is not valid'));
142
+ }
143
+ $upload = new Varien_File_Uploader($scope);
144
+ $upload->setAllowCreateFolders(true);
145
+ $upload->setAllowedExtensions($this->_allowedExtensions);
146
+ $upload->setAllowRenameFiles(true);
147
+ $upload->setFilesDispersion(false);
148
+ if ($upload->save($this->getBaseDir())) {
149
+ return $upload->getUploadedFileName();
150
+ }
151
+ }
152
+ return false;
153
+ }
154
+
155
+ /**
156
+ * Return URL for resized News Item Image
157
+ *
158
+ * @param Lavi_News_Model_Item $item
159
+ * @param integer $width
160
+ * @param integer $height
161
+ * @return bool|string
162
+ */
163
+ public function resize(Lavi_News_Model_News $item, $width, $height = null)
164
+ {
165
+ if (!$item->getImage()) {
166
+ return false;
167
+ }
168
+
169
+ if ($width < self::MIN_WIDTH || $width > self::MAX_WIDTH) {
170
+ return false;
171
+ }
172
+ $width = (int)$width;
173
+
174
+ if (!is_null($height)) {
175
+ if ($height < self::MIN_HEIGHT || $height > self::MAX_HEIGHT) {
176
+ return false;
177
+ }
178
+ $height = (int)$height;
179
+ }
180
+
181
+ $imageFile = $item->getImage();
182
+ $cacheDir = $this->getBaseDir() . DS . 'cache' . DS . $width;
183
+ $cacheUrl = $this->getBaseUrl() . '/' . 'cache' . '/' . $width . '/';
184
+
185
+ $io = new Varien_Io_File();
186
+ $io->checkAndCreateFolder($cacheDir);
187
+ $io->open(array('path' => $cacheDir));
188
+ if ($io->fileExists($imageFile)) {
189
+ return $cacheUrl . $imageFile;
190
+ }
191
+
192
+ try {
193
+ $image = new Varien_Image($this->getBaseDir() . DS . $imageFile);
194
+ $image->resize($width, $height);
195
+ $image->save($cacheDir . DS . $imageFile);
196
+ return $cacheUrl . $imageFile;
197
+ } catch (Exception $e) {
198
+ Mage::logException($e);
199
+ return false;
200
+ }
201
+ }
202
+
203
+ /**
204
+ * Removes folder with cached images
205
+ *
206
+ * @return boolean
207
+ */
208
+ public function flushImagesCache()
209
+ {
210
+ $cacheDir = $this->getBaseDir() . DS . 'cache' . DS ;
211
+ $io = new Varien_Io_File();
212
+ if ($io->fileExists($cacheDir, false) ) {
213
+ return $io->rmdir($cacheDir, true);
214
+ }
215
+ return true;
216
+ }
217
+ }
app/code/community/Lavi/News/Model/News.php ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * SAGIPL
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ *
12
+ * @category SAGIPL
13
+ * @package Lavi_News
14
+ * @copyright Copyright (c) 2014 SAGIPL. (http://www.sagipl.com/)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * Free Shipping Offer Message
20
+ *
21
+ * @category SAGIPL
22
+ * @package Lavi_News
23
+ * @author Navneet <navneet.kshk@gmail.com>
24
+ */
25
+
26
+ class Lavi_News_Model_News extends Mage_Core_Model_Abstract
27
+ {
28
+ /**
29
+ * Define resource model
30
+ */
31
+ protected function _construct()
32
+ {
33
+ $this->_init('lavi_news/news');
34
+ }
35
+
36
+ /**
37
+ * If object is new adds creation date
38
+ *
39
+ * @return Lavi_News_Model_News
40
+ */
41
+ protected function _beforeSave()
42
+ {
43
+ parent::_beforeSave();
44
+ if ($this->isObjectNew()) {
45
+ $this->setData('created_at', Varien_Date::now());
46
+ }
47
+ return $this;
48
+ }
49
+ }
app/code/community/Lavi/News/Model/Observer.php ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * SAGIPL
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ *
12
+ * @category SAGIPL
13
+ * @package Lavi_News
14
+ * @copyright Copyright (c) 2014 SAGIPL. (http://www.sagipl.com/)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * Free Shipping Offer Message
20
+ *
21
+ * @category SAGIPL
22
+ * @package Lavi_News
23
+ * @author Navneet <navneet.kshk@gmail.com>
24
+ */
25
+
26
+ class Lavi_News_Model_Observer
27
+ {
28
+ /**
29
+ * Event before show news item on frontend
30
+ * If specified new post was added recently (term is defined in config) we'll see message about this on front-end.
31
+ *
32
+ * @param Varien_Event_Observer $observer
33
+ */
34
+ public function beforeNewsDisplayed(Varien_Event_Observer $observer)
35
+ {
36
+ $newsItem = $observer->getEvent()->getNewsItem();
37
+ $currentDate = Mage::app()->getLocale()->date();
38
+ $newsCreatedAt = Mage::app()->getLocale()->date(strtotime($newsItem->getCreatedAt()));
39
+ $daysDifference = $currentDate->sub($newsCreatedAt)->getTimestamp() / (60 * 60 * 24);
40
+ if ($daysDifference < Mage::helper('lavi_news')->getDaysDifference()) {
41
+ Mage::getSingleton('core/session')->addSuccess(Mage::helper('lavi_news')->__('Recently added'));
42
+ }
43
+ }
44
+ }
app/code/community/Lavi/News/Model/Resource/News.php ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * SAGIPL
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ *
12
+ * @category SAGIPL
13
+ * @package Lavi_News
14
+ * @copyright Copyright (c) 2014 SAGIPL. (http://www.sagipl.com/)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * Free Shipping Offer Message
20
+ *
21
+ * @category SAGIPL
22
+ * @package Lavi_News
23
+ * @author Navneet <navneet.kshk@gmail.com>
24
+ */
25
+
26
+ class Lavi_News_Model_Resource_News extends Mage_Core_Model_Resource_Db_Abstract
27
+ {
28
+ /**
29
+ * Initialize connection and define main table and primary key
30
+ */
31
+ protected function _construct()
32
+ {
33
+ $this->_init('lavi_news/news', 'news_id');
34
+ }
35
+ }
app/code/community/Lavi/News/Model/Resource/News/Collection.php ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * SAGIPL
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ *
12
+ * @category SAGIPL
13
+ * @package Lavi_News
14
+ * @copyright Copyright (c) 2014 SAGIPL. (http://www.sagipl.com/)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * Free Shipping Offer Message
20
+ *
21
+ * @category SAGIPL
22
+ * @package Lavi_News
23
+ * @author Navneet <navneet.kshk@gmail.com>
24
+ */
25
+
26
+ class Lavi_News_Model_Resource_News_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
27
+ {
28
+ /**
29
+ * Define collection model
30
+ */
31
+ protected function _construct()
32
+ {
33
+ $this->_init('lavi_news/news');
34
+ }
35
+
36
+ /**
37
+ * Prepare for displaying in list
38
+ *
39
+ * @param integer $page
40
+ * @return Lavi_News_Model_Resource_News_Collection
41
+ */
42
+ public function prepareForList($page)
43
+ {
44
+ $this->setPageSize(Mage::helper('lavi_news')->getNewsPerPage());
45
+ $this->setCurPage($page)->setOrder('published_at', Varien_Data_Collection::SORT_ORDER_DESC);
46
+ return $this;
47
+ }
48
+ }
app/code/community/Lavi/News/controllers/Adminhtml/NewsController.php ADDED
@@ -0,0 +1,289 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * SAGIPL
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ *
12
+ * @category SAGIPL
13
+ * @package Lavi_News
14
+ * @copyright Copyright (c) 2014 SAGIPL. (http://www.sagipl.com/)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * Free Shipping Offer Message
20
+ *
21
+ * @category SAGIPL
22
+ * @package Lavi_News
23
+ * @author Navneet <navneet.kshk@gmail.com>
24
+ */
25
+
26
+ class Lavi_News_Adminhtml_NewsController extends Mage_Adminhtml_Controller_Action
27
+ {
28
+ /**
29
+ * Init actions
30
+ *
31
+ * @return Lavi_News_Adminhtml_NewsController
32
+ */
33
+ protected function _initAction()
34
+ {
35
+ // load layout, set active menu and breadcrumbs
36
+ $this->loadLayout()
37
+ ->_setActiveMenu('news/manage')
38
+ ->_addBreadcrumb(
39
+ Mage::helper('lavi_news')->__('News'),
40
+ Mage::helper('lavi_news')->__('News')
41
+ )
42
+ ->_addBreadcrumb(
43
+ Mage::helper('lavi_news')->__('Manage News'),
44
+ Mage::helper('lavi_news')->__('Manage News')
45
+ )
46
+ ;
47
+ return $this;
48
+ }
49
+
50
+ /**
51
+ * Index action
52
+ */
53
+ public function indexAction()
54
+ {
55
+ $this->_title($this->__('News'))
56
+ ->_title($this->__('Manage News'));
57
+
58
+ $this->_initAction();
59
+ $this->renderLayout();
60
+ }
61
+
62
+ /**
63
+ * Create new News item
64
+ */
65
+ public function newAction()
66
+ {
67
+ // the same form is used to create and edit
68
+ $this->_forward('edit');
69
+ }
70
+
71
+ /**
72
+ * Edit News item
73
+ */
74
+ public function editAction()
75
+ {
76
+ $this->_title($this->__('News'))
77
+ ->_title($this->__('Manage News'));
78
+
79
+ // 1. instance news model
80
+ /* @var $model Lavi_News_Model_Item */
81
+ $model = Mage::getModel('lavi_news/news');
82
+
83
+ // 2. if exists id, check it and load data
84
+ $newsId = $this->getRequest()->getParam('id');
85
+ if ($newsId) {
86
+ $model->load($newsId);
87
+
88
+ if (!$model->getId()) {
89
+ $this->_getSession()->addError(
90
+ Mage::helper('lavi_news')->__('News item does not exist.')
91
+ );
92
+ return $this->_redirect('*/*/');
93
+ }
94
+ // prepare title
95
+ $this->_title($model->getTitle());
96
+ $breadCrumb = Mage::helper('lavi_news')->__('Edit Item');
97
+ } else {
98
+ $this->_title(Mage::helper('lavi_news')->__('New Item'));
99
+ $breadCrumb = Mage::helper('lavi_news')->__('New Item');
100
+ }
101
+
102
+ // Init breadcrumbs
103
+ $this->_initAction()->_addBreadcrumb($breadCrumb, $breadCrumb);
104
+
105
+ // 3. Set entered data if was error when we do save
106
+ $data = Mage::getSingleton('adminhtml/session')->getFormData(true);
107
+ if (!empty($data)) {
108
+ $model->addData($data);
109
+ }
110
+
111
+ // 4. Register model to use later in blocks
112
+ Mage::register('news_item', $model);
113
+
114
+ // 5. render layout
115
+ $this->renderLayout();
116
+ }
117
+
118
+ /**
119
+ * Save action
120
+ */
121
+ public function saveAction()
122
+ {
123
+ $redirectPath = '*/*';
124
+ $redirectParams = array();
125
+
126
+ // check if data sent
127
+ $data = $this->getRequest()->getPost();
128
+ if ($data) {
129
+ $data = $this->_filterPostData($data);
130
+ // init model and set data
131
+ /* @var $model Lavi_News_Model_Item */
132
+ $model = Mage::getModel('lavi_news/news');
133
+
134
+ // if news item exists, try to load it
135
+ $newsId = $this->getRequest()->getParam('news_id');
136
+ if ($newsId) {
137
+ $model->load($newsId);
138
+ }
139
+ // save image data and remove from data array
140
+ if (isset($data['image'])) {
141
+ $imageData = $data['image'];
142
+ unset($data['image']);
143
+ } else {
144
+ $imageData = array();
145
+ }
146
+ $model->addData($data);
147
+
148
+ try {
149
+ $hasError = false;
150
+ /* @var $imageHelper Lavi_News_Helper_Image */
151
+ $imageHelper = Mage::helper('lavi_news/image');
152
+ // remove image
153
+
154
+ if (isset($imageData['delete']) && $model->getImage()) {
155
+ $imageHelper->removeImage($model->getImage());
156
+ $model->setImage(null);
157
+ }
158
+
159
+ // upload new image
160
+ $imageFile = $imageHelper->uploadImage('image');
161
+ if ($imageFile) {
162
+ if ($model->getImage()) {
163
+ $imageHelper->removeImage($model->getImage());
164
+ }
165
+ $model->setImage($imageFile);
166
+ }
167
+ // save the data
168
+ $model->save();
169
+
170
+ // display success message
171
+ $this->_getSession()->addSuccess(
172
+ Mage::helper('lavi_news')->__('The news item has been saved.')
173
+ );
174
+
175
+ // check if 'Save and Continue'
176
+ if ($this->getRequest()->getParam('back')) {
177
+ $redirectPath = '*/*/edit';
178
+ $redirectParams = array('id' => $model->getId());
179
+ }
180
+ } catch (Mage_Core_Exception $e) {
181
+ $hasError = true;
182
+ $this->_getSession()->addError($e->getMessage());
183
+ } catch (Exception $e) {
184
+ $hasError = true;
185
+ $this->_getSession()->addException($e,
186
+ Mage::helper('lavi_news')->__('An error occurred while saving the news item.')
187
+ );
188
+ }
189
+
190
+ if ($hasError) {
191
+ $this->_getSession()->setFormData($data);
192
+ $redirectPath = '*/*/edit';
193
+ $redirectParams = array('id' => $this->getRequest()->getParam('id'));
194
+ }
195
+ }
196
+
197
+ $this->_redirect($redirectPath, $redirectParams);
198
+ }
199
+
200
+ /**
201
+ * Delete action
202
+ */
203
+ public function deleteAction()
204
+ {
205
+ // check if we know what should be deleted
206
+ $itemId = $this->getRequest()->getParam('id');
207
+ if ($itemId) {
208
+ try {
209
+ // init model and delete
210
+ /** @var $model Lavi_News_Model_Item */
211
+ $model = Mage::getModel('lavi_news/news');
212
+ $model->load($itemId);
213
+ if (!$model->getId()) {
214
+ Mage::throwException(Mage::helper('lavi_news')->__('Unable to find a news item.'));
215
+ }
216
+ $model->delete();
217
+
218
+ // display success message
219
+ $this->_getSession()->addSuccess(
220
+ Mage::helper('lavi_news')->__('The news item has been deleted.')
221
+ );
222
+ } catch (Mage_Core_Exception $e) {
223
+ $this->_getSession()->addError($e->getMessage());
224
+ } catch (Exception $e) {
225
+ $this->_getSession()->addException($e,
226
+ Mage::helper('lavi_news')->__('An error occurred while deleting the news item.')
227
+ );
228
+ }
229
+ }
230
+
231
+ // go to grid
232
+ $this->_redirect('*/*/');
233
+ }
234
+
235
+ /**
236
+ * Check the permission to run it
237
+ *
238
+ * @return boolean
239
+ */
240
+ protected function _isAllowed()
241
+ {
242
+ switch ($this->getRequest()->getActionName()) {
243
+ case 'new':
244
+ case 'save':
245
+ return Mage::getSingleton('admin/session')->isAllowed('news/manage/save');
246
+ break;
247
+ case 'delete':
248
+ return Mage::getSingleton('admin/session')->isAllowed('news/manage/delete');
249
+ break;
250
+ default:
251
+ return Mage::getSingleton('admin/session')->isAllowed('news/manage');
252
+ break;
253
+ }
254
+ }
255
+
256
+ /**
257
+ * Filtering posted data. Converting localized data if needed
258
+ *
259
+ * @param array
260
+ * @return array
261
+ */
262
+ protected function _filterPostData($data)
263
+ {
264
+ $data = $this->_filterDates($data, array('time_published'));
265
+ return $data;
266
+ }
267
+
268
+ /**
269
+ * Grid ajax action
270
+ */
271
+ public function gridAction()
272
+ {
273
+ $this->loadLayout();
274
+ $this->renderLayout();
275
+ }
276
+
277
+ /**
278
+ * Flush News Posts Images Cache action
279
+ */
280
+ public function flushAction()
281
+ {
282
+ if (Mage::helper('lavi_news/image')->flushImagesCache()) {
283
+ $this->_getSession()->addSuccess('Cache successfully flushed');
284
+ } else {
285
+ $this->_getSession()->addError('There was error during flushing cache');
286
+ }
287
+ $this->_forward('index');
288
+ }
289
+ }
app/code/community/Lavi/News/controllers/IndexController.php ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * SAGIPL
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ *
12
+ * @category SAGIPL
13
+ * @package Lavi_News
14
+ * @copyright Copyright (c) 2014 SAGIPL. (http://www.sagipl.com/)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * Free Shipping Offer Message
20
+ *
21
+ * @category SAGIPL
22
+ * @package Lavi_News
23
+ * @author Navneet <navneet.kshk@gmail.com>
24
+ */
25
+
26
+ class Lavi_News_IndexController extends Mage_Core_Controller_Front_Action
27
+ {
28
+ /**
29
+ * Pre dispatch action that allows to redirect to no route page in case of disabled extension through admin panel
30
+ */
31
+ public function preDispatch()
32
+ {
33
+ parent::preDispatch();
34
+
35
+ if (!Mage::helper('lavi_news')->isEnabled()) {
36
+ $this->setFlag('', 'no-dispatch', true);
37
+ $this->_redirect('noRoute');
38
+ }
39
+ }
40
+
41
+ /**
42
+ * Index action
43
+ */
44
+ public function indexAction()
45
+ {
46
+ $this->loadLayout();
47
+
48
+ $listBlock = $this->getLayout()->getBlock('news.list');
49
+
50
+ if ($listBlock) {
51
+ $currentPage = abs(intval($this->getRequest()->getParam('p')));
52
+ if ($currentPage < 1) {
53
+ $currentPage = 1;
54
+ }
55
+ $listBlock->setCurrentPage($currentPage);
56
+ }
57
+
58
+ $this->renderLayout();
59
+ }
60
+
61
+ /**
62
+ * News view action
63
+ */
64
+ public function viewAction()
65
+ {
66
+ $newsId = $this->getRequest()->getParam('id');
67
+ if (!$newsId) {
68
+ return $this->_forward('noRoute');
69
+ }
70
+
71
+ /** @var $model Lavi_News_Model_News */
72
+ $model = Mage::getModel('lavi_news/news');
73
+ $model->load($newsId);
74
+
75
+ if (!$model->getId()) {
76
+ return $this->_forward('noRoute');
77
+ }
78
+
79
+ Mage::register('news_item', $model);
80
+
81
+ Mage::dispatchEvent('before_news_item_display', array('news_item' => $model));
82
+
83
+ $this->loadLayout();
84
+ $itemBlock = $this->getLayout()->getBlock('news.item');
85
+ if ($itemBlock) {
86
+ $listBlock = $this->getLayout()->getBlock('news.list');
87
+ if ($listBlock) {
88
+ $page = (int)$listBlock->getCurrentPage() ? (int)$listBlock->getCurrentPage() : 1;
89
+ } else {
90
+ $page = 1;
91
+ }
92
+ $itemBlock->setPage($page);
93
+ }
94
+ $this->renderLayout();
95
+ }
96
+ }
app/code/community/Lavi/News/etc/adminhtml.xml ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * SAGIPL
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ *
13
+ * @category SAGIPL
14
+ * @package Lavi_News
15
+ * @copyright Copyright (c) 2014 SAGIPL. (http://www.sagipl.com/)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * Free Shipping Offer Message
21
+ *
22
+ * @category SAGIPL
23
+ * @package Lavi_News
24
+ * @author Navneet <navneet.kshk@gmail.com>
25
+ */
26
+ -->
27
+ <config>
28
+ <menu>
29
+ <news translate="title" module="lavi_news">
30
+ <title>News</title>
31
+ <sort_order>99</sort_order>
32
+ <children>
33
+ <manage translate="title" module="lavi_news">
34
+ <title>Manage News</title>
35
+ <action>adminhtml/news</action>
36
+ <sort_order>50</sort_order>
37
+ </manage>
38
+ </children>
39
+ </news>
40
+ </menu>
41
+
42
+ <acl>
43
+ <resources>
44
+ <admin>
45
+ <children>
46
+ <news translate="title" module="lavi_news">
47
+ <title>News</title>
48
+ <sort_order>65</sort_order>
49
+ <children>
50
+ <manage translate="title">
51
+ <title>Manage News</title>
52
+ <sort_order>0</sort_order>
53
+ <children>
54
+ <save translate="title">
55
+ <title>Save News</title>
56
+ <sort_order>0</sort_order>
57
+ </save>
58
+ <delete translate="title">
59
+ <title>Delete News</title>
60
+ <sort_order>10</sort_order>
61
+ </delete>
62
+ </children>
63
+ </manage>
64
+ </children>
65
+ </news>
66
+ <system>
67
+ <children>
68
+ <config>
69
+ <children>
70
+ <news translate="title" module="lavi_news">
71
+ <title>News Management</title>
72
+ </news>
73
+ </children>
74
+ </config>
75
+ </children>
76
+ </system>
77
+ </children>
78
+ </admin>
79
+ </resources>
80
+ </acl>
81
+ </config>
app/code/community/Lavi/News/etc/config.xml ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * SAGIPL
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ *
13
+ * @category SAGIPL
14
+ * @package Lavi_News
15
+ * @copyright Copyright (c) 2014 SAGIPL. (http://www.sagipl.com/)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * Free Shipping Offer Message
21
+ *
22
+ * @category SAGIPL
23
+ * @package Lavi_News
24
+ * @author Navneet <navneet.kshk@gmail.com>
25
+ */
26
+ -->
27
+ <config>
28
+ <modules>
29
+ <Lavi_News>
30
+ <version>1.0.0</version>
31
+ </Lavi_News>
32
+ </modules>
33
+ <global>
34
+ <models>
35
+ <lavi_news>
36
+ <class>Lavi_News_Model</class>
37
+ <resourceModel>news_resource</resourceModel>
38
+ </lavi_news>
39
+ <news_resource>
40
+ <class>Lavi_News_Model_Resource</class>
41
+ <entities>
42
+ <news>
43
+ <table>lavi_news</table>
44
+ </news>
45
+ </entities>
46
+ </news_resource>
47
+ </models>
48
+ <helpers>
49
+ <lavi_news>
50
+ <class>Lavi_News_Helper</class>
51
+ </lavi_news>
52
+ </helpers>
53
+ <blocks>
54
+ <lavi_news>
55
+ <class>Lavi_News_Block</class>
56
+ </lavi_news>
57
+ </blocks>
58
+ <resources>
59
+ <lavi_news_setup>
60
+ <setup>
61
+ <module>Lavi_News</module>
62
+ <class>Mage_Core_Model_Resource_Setup</class>
63
+ </setup>
64
+ </lavi_news_setup>
65
+ </resources>
66
+ <events>
67
+ <before_news_item_display>
68
+ <observers>
69
+ <lavi_news>
70
+ <class>lavi_news/observer</class>
71
+ <method>beforeNewsDisplayed</method>
72
+ </lavi_news>
73
+ </observers>
74
+ </before_news_item_display>
75
+ </events>
76
+ </global>
77
+ <frontend>
78
+ <routers>
79
+ <lavi_news>
80
+ <use>standard</use>
81
+ <args>
82
+ <module>Lavi_News</module>
83
+ <frontName>news</frontName>
84
+ </args>
85
+ </lavi_news>
86
+ </routers>
87
+ <layout>
88
+ <updates>
89
+ <lavi_news>
90
+ <file>lavi_news.xml</file>
91
+ </lavi_news>
92
+ </updates>
93
+ </layout>
94
+ </frontend>
95
+ <admin>
96
+ <routers>
97
+ <adminhtml>
98
+ <args>
99
+ <modules>
100
+ <Lavi_News before="Mage_Adminhtml">Lavi_News_Adminhtml</Lavi_News>
101
+ </modules>
102
+ </args>
103
+ </adminhtml>
104
+ </routers>
105
+ </admin>
106
+ <adminhtml>
107
+ <layout>
108
+ <updates>
109
+ <lavi_news>
110
+ <file>lavi_news.xml</file>
111
+ </lavi_news>
112
+ </updates>
113
+ </layout>
114
+ </adminhtml>
115
+ <default>
116
+ <news>
117
+ <view>
118
+ <enabled>1</enabled>
119
+ <items_per_page>20</items_per_page>
120
+ <days_difference>3</days_difference>
121
+ </view>
122
+ </news>
123
+ </default>
124
+ </config>
app/code/community/Lavi/News/etc/system.xml ADDED
@@ -0,0 +1,114 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * SAGIPL
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ *
13
+ * @category SAGIPL
14
+ * @package Lavi_News
15
+ * @copyright Copyright (c) 2014 SAGIPL. (http://www.sagipl.com/)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * Free Shipping Offer Message
21
+ *
22
+ * @category SAGIPL
23
+ * @package Lavi_News
24
+ * @author Navneet <navneet.kshk@gmail.com>
25
+ */
26
+ -->
27
+ <config>
28
+ <tabs>
29
+ <news translate="label" module="lavi_news">
30
+ <label>Lavi News</label>
31
+ <sort_order>100</sort_order>
32
+ </news>
33
+ </tabs>
34
+ <sections>
35
+ <news>
36
+ <label>Options</label>
37
+ <tab>news</tab>
38
+ <frontend_type>text</frontend_type>
39
+ <sort_order>1</sort_order>
40
+ <show_in_default>1</show_in_default>
41
+ <show_in_website>1</show_in_website>
42
+ <show_in_store>1</show_in_store>
43
+
44
+ <groups>
45
+ <view translate="label">
46
+ <label>News View Settings</label>
47
+ <frontend_type>text</frontend_type>
48
+ <sort_order>10</sort_order>
49
+ <show_in_default>1</show_in_default>
50
+ <show_in_website>1</show_in_website>
51
+ <show_in_store>1</show_in_store>
52
+ <fields>
53
+ <enabled translate="label">
54
+ <label>Enable News On Frontend</label>
55
+ <frontend_type>select</frontend_type>
56
+ <source_model>adminhtml/system_config_source_yesno</source_model>
57
+ <sort_order>1</sort_order>
58
+ <show_in_default>1</show_in_default>
59
+ <show_in_website>1</show_in_website>
60
+ <show_in_store>1</show_in_store>
61
+ </enabled>
62
+ <items_per_page translate="label">
63
+ <label>News Per Page</label>
64
+ <comment>Empty value is the same as default 20.</comment>
65
+ <sort_order>2</sort_order>
66
+ <depends><enabled>1</enabled></depends>
67
+ <show_in_default>1</show_in_default>
68
+ <show_in_website>1</show_in_website>
69
+ <show_in_store>1</show_in_store>
70
+ </items_per_page>
71
+ <days_difference translate="label">
72
+ <label>Number of days since a post has been marked as recently added</label>
73
+ <comment>Empty value is the same as default 3.</comment>
74
+ <sort_order>3</sort_order>
75
+ <depends><enabled>1</enabled></depends>
76
+ <show_in_default>1</show_in_default>
77
+ <show_in_website>1</show_in_website>
78
+ <show_in_store>1</show_in_store>
79
+ </days_difference>
80
+ <showinleft translate="label">
81
+ <label>Show in Left: </label>
82
+ <comment>Show in left enabled Yes/No</comment>
83
+ <frontend_type>select</frontend_type>
84
+ <sort_order>4</sort_order>
85
+ <show_in_default>1</show_in_default>
86
+ <show_in_website>1</show_in_website>
87
+ <show_in_store>1</show_in_store>
88
+ <source_model>adminhtml/system_config_source_yesno</source_model>
89
+ </showinleft>
90
+ <showinright translate="label">
91
+ <label>Show in Right: </label>
92
+ <comment>Show in right enabled Yes/No</comment>
93
+ <frontend_type>select</frontend_type>
94
+ <sort_order>5</sort_order>
95
+ <show_in_default>1</show_in_default>
96
+ <show_in_website>1</show_in_website>
97
+ <show_in_store>1</show_in_store>
98
+ <source_model>adminhtml/system_config_source_yesno</source_model>
99
+ </showinright>
100
+ <numberofnews translate="label">
101
+ <label>Number of news which show in left/right</label>
102
+ <comment>Empty value is the same as default 5.</comment>
103
+ <sort_order>6</sort_order>
104
+ <depends><enabled>1</enabled></depends>
105
+ <show_in_default>1</show_in_default>
106
+ <show_in_website>1</show_in_website>
107
+ <show_in_store>1</show_in_store>
108
+ </numberofnews>
109
+ </fields>
110
+ </view>
111
+ </groups>
112
+ </news>
113
+ </sections>
114
+ </config>
app/code/community/Lavi/News/sql/lavi_news_setup/install-1.0.0.0.1.php ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * SAGIPL
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ *
12
+ * @category SAGIPL
13
+ * @package Lavi_News
14
+ * @copyright Copyright (c) 2014 SAGIPL. (http://www.sagipl.com/)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * Free Shipping Offer Message
20
+ *
21
+ * @category SAGIPL
22
+ * @package Lavi_News
23
+ * @author Navneet <navneet.kshk@gmail.com>
24
+ */
25
+
26
+ $installer = $this;
27
+
28
+ /**
29
+ * Creating table lavi_news
30
+ */
31
+ $table = $installer->getConnection()
32
+ ->newTable($installer->getTable('lavi_news/news'))
33
+ ->addColumn('news_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
34
+ 'unsigned' => true,
35
+ 'identity' => true,
36
+ 'nullable' => false,
37
+ 'primary' => true,
38
+ ), 'Entity id')
39
+ ->addColumn('title', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array(
40
+ 'nullable' => true,
41
+ ), 'Title')
42
+ ->addColumn('author', Varien_Db_Ddl_Table::TYPE_TEXT, 63, array(
43
+ 'nullable' => true,
44
+ 'default' => null,
45
+ ), 'Author')
46
+ ->addColumn('content', Varien_Db_Ddl_Table::TYPE_TEXT, '2M', array(
47
+ 'nullable' => true,
48
+ 'default' => null,
49
+ ), 'Content')
50
+ ->addColumn('image', Varien_Db_Ddl_Table::TYPE_TEXT, null, array(
51
+ 'nullable' => true,
52
+ 'default' => null,
53
+ ), 'News image media path')
54
+ ->addColumn('published_at', Varien_Db_Ddl_Table::TYPE_DATE, null, array(
55
+ 'nullable' => true,
56
+ 'default' => null,
57
+ ), 'World publish date')
58
+ ->addColumn('created_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array(
59
+ 'nullable' => true,
60
+ 'default' => null,
61
+ ), 'Creation Time')
62
+ ->addIndex($installer->getIdxName(
63
+ $installer->getTable('lavi_news/news'),
64
+ array('published_at'),
65
+ Varien_Db_Adapter_Interface::INDEX_TYPE_INDEX
66
+ ),
67
+ array('published_at'),
68
+ array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_INDEX)
69
+ )
70
+ ->setComment('News item');
71
+
72
+ $installer->getConnection()->createTable($table);
app/design/adminhtml/default/default/layout/lavi_news.xml ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * SAGIPL
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ *
13
+ * @category SAGIPL
14
+ * @package Lavi_News
15
+ * @copyright Copyright (c) 2014 SAGIPL. (http://www.sagipl.com/)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * Free Shipping Offer Message
21
+ *
22
+ * @category SAGIPL
23
+ * @package Lavi_News
24
+ * @author Navneet <navneet.kshk@gmail.com>
25
+ */
26
+ -->
27
+ <layout>
28
+ <adminhtml_news_index>
29
+ <reference name="content">
30
+ <block type="lavi_news/adminhtml_news" name="news" />
31
+ </reference>
32
+ </adminhtml_news_index>
33
+
34
+ <adminhtml_news_grid>
35
+ <block type="lavi_news/adminhtml_news_grid" name="root"/>
36
+ </adminhtml_news_grid>
37
+
38
+ <adminhtml_news_new>
39
+ <update handle="adminhtml_news_edit" />
40
+ </adminhtml_news_new>
41
+
42
+ <adminhtml_news_edit>
43
+ <update handle="editor"/>
44
+ <reference name="content">
45
+ <block type="lavi_news/adminhtml_news_edit" name="news_edit" />
46
+ </reference>
47
+ <reference name="left">
48
+ <block type="lavi_news/adminhtml_news_edit_tabs" name="news_edit_tabs">
49
+ <block type="lavi_news/adminhtml_news_edit_tab_main" name="news_edit_tab_main" />
50
+ <block type="lavi_news/adminhtml_news_edit_tab_content" name="news_edit_tab_content" />
51
+ <block type="lavi_news/adminhtml_news_edit_tab_image" name="news_edit_tab_image" />
52
+ <action method="addTab"><name>main_section</name><block>news_edit_tab_main</block></action>
53
+ <action method="addTab"><name>content_section</name><block>news_edit_tab_content</block></action>
54
+ <action method="addTab"><name>image_section</name><block>news_edit_tab_image</block></action>
55
+ </block>
56
+ </reference>
57
+ </adminhtml_news_edit>
58
+ </layout>
app/design/frontend/base/default/layout/lavi_news.xml ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * SAGIPL
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ *
13
+ * @category SAGIPL
14
+ * @package Lavi_News
15
+ * @copyright Copyright (c) 2014 SAGIPL. (http://www.sagipl.com/)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * Free Shipping Offer Message
21
+ *
22
+ * @category SAGIPL
23
+ * @package Lavi_News
24
+ * @author Navneet <navneet.kshk@gmail.com>
25
+ */
26
+ -->
27
+ <layout version="0.1.0">
28
+ <default>
29
+ <reference name="footer_links">
30
+ <action method="addLink" translate="label title" module="lavi_news" ifconfig="news/view/enabled">
31
+ <label>News</label>
32
+ <url>news</url>
33
+ <title>News</title>
34
+ <prepare>true</prepare>
35
+ </action>
36
+ </reference>
37
+ <reference name="left">
38
+ <block type="lavi_news/sidebar" name="sidebar">
39
+ <action method="setTemplate" module="lavi_news" ifconfig="news/view/showinleft">
40
+ <template>lavi/news/sidebar.phtml</template>
41
+ </action>
42
+ </block>
43
+ </reference>
44
+ <reference name="right">
45
+ <block type="lavi_news/sidebar" name="sidebar">
46
+ <action method="setTemplate" module="lavi_news" ifconfig="news/view/showinright">
47
+ <template>lavi/news/sidebar.phtml</template>
48
+ </action>
49
+ </block>
50
+ </reference>
51
+ </default>
52
+
53
+ <lavi_news_index_index translate="label">
54
+ <label>News Page</label>
55
+ <reference name="root">
56
+ <action method="setTemplate">
57
+ <template>page/2columns-right.phtml</template>
58
+ </action>
59
+ <action method="setHeaderTitle" translate="title" module="lavi_news">
60
+ <title>Site News</title>
61
+ </action>
62
+ </reference>
63
+ <reference name="content">
64
+ <block type="lavi_news/list" name="news.list" template="lavi/news/list.phtml">
65
+ <block type="page/html_pager" name="news.list.pager" as="news_list_pager" />
66
+ </block>
67
+ </reference>
68
+ </lavi_news_index_index>
69
+
70
+ <lavi_news_index_view translate="label">
71
+ <label>News Item Page</label>
72
+ <reference name="root">
73
+ <action method="setTemplate">
74
+ <template>page/2columns-right.phtml</template>
75
+ </action>
76
+ </reference>
77
+ <reference name="content">
78
+ <block type="lavi_news/item" name="news.item" template="lavi/news/item.phtml" />
79
+ </reference>
80
+ </lavi_news_index_view>
81
+ </layout>
app/design/frontend/base/default/template/lavi/news/item.phtml ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * SAGIPL
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ *
12
+ * @category SAGIPL
13
+ * @package Lavi_News
14
+ * @copyright Copyright (c) 2014 SAGIPL. (http://www.sagipl.com/)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * Free Shipping Offer Message
20
+ *
21
+ * @category SAGIPL
22
+ * @package Lavi_News
23
+ * @author Navneet <navneet.kshk@gmail.com>
24
+ */
25
+ ?>
26
+ <?php $_newsItem = $this->helper('lavi_news')->getNewsItemInstance(); ?>
27
+ <div id="news_item_messages"><?php echo $this->getMessagesBlock()->getGroupedHtml() ?></div>
28
+
29
+ <div class="page-title">
30
+ <h1><?php echo $this->escapeHtml($_newsItem->getTitle()) ?></h1>
31
+
32
+ <div class="news_item_subtitle">
33
+ <?php echo $this->formatDate($_newsItem->getTimePublished(), Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM) ?> |
34
+ <?php echo $this->escapeHtml($_newsItem->getAuthor()) ?>
35
+ </div>
36
+ </div>
37
+
38
+ <div class="news_item_view">
39
+ <?php if ($imageUrl = $this->getImageUrl($_newsItem, 400)): ?>
40
+ <p><img src="<?php echo $imageUrl ?>" alt="<?php echo $this->escapeHtml($_newsItem->getTitle()) ?>" /></p>
41
+ <?php endif; ?>
42
+
43
+ <div class="news_item_content"><?php echo $_newsItem->getContent() ?></div>
44
+
45
+ <div class="pager">
46
+ <a href="<?php echo $this->getBackUrl() ?>">
47
+ <?php echo Mage::helper('lavi_news')->__('Return to list') ?>
48
+ </a>
49
+ </div>
50
+ </div>
app/design/frontend/base/default/template/lavi/news/list.phtml ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * SAGIPL
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ *
12
+ * @category SAGIPL
13
+ * @package Lavi_News
14
+ * @copyright Copyright (c) 2014 SAGIPL. (http://www.sagipl.com/)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * Free Shipping Offer Message
20
+ *
21
+ * @category SAGIPL
22
+ * @package Lavi_News
23
+ * @author Navneet <navneet.kshk@gmail.com>
24
+ */
25
+ ?>
26
+ <div id="news_list_messages"><?php echo $this->getMessagesBlock()->getGroupedHtml() ?></div>
27
+ <div class="page-title">
28
+ <h1><?php echo Mage::helper('lavi_news')->__('Site News') ?></h1>
29
+ </div>
30
+
31
+ <div class="news_list_view">
32
+ <?php foreach ($this->getCollection() as $newsItem): ?>
33
+ <div id="item_<?php echo $newsItem->getId() ?>" class="news_list_item">
34
+ <h2>
35
+ <a href="<?php echo $this->getItemUrl($newsItem) ?>">
36
+ <?php echo $this->escapeHtml($newsItem->getTitle()) ?>
37
+ </a>
38
+ </h2>
39
+
40
+ <div class="news_item_subtitle">
41
+ <?php echo $this->formatDate($newsItem->getTimePublished(), 'medium') ?> |
42
+ <?php echo $this->escapeHtml($newsItem->getAuthor()) ?>
43
+ </div>
44
+
45
+ <?php if ($imageUrl = $this->getImageUrl($newsItem, 100)): ?>
46
+ <p><img src="<?php echo $imageUrl ?>" alt="<?php echo $this->escapeHtml($newsItem->getTitle()); ?>" /></p>
47
+ <?php endif; ?>
48
+ </div>
49
+ <?php endforeach; ?>
50
+ </div>
51
+
52
+ <?php echo $this->getPager() ?>
app/design/frontend/base/default/template/lavi/news/sidebar.phtml ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * SAGIPL
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ *
12
+ * @category SAGIPL
13
+ * @package Lavi_News
14
+ * @copyright Copyright (c) 2014 SAGIPL. (http://www.sagipl.com/)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+
18
+ /**
19
+ * Free Shipping Offer Message
20
+ *
21
+ * @category SAGIPL
22
+ * @package Lavi_News
23
+ * @author Navneet <navneet.kshk@gmail.com>
24
+ */
25
+ ?>
26
+ <div id="news_list_messages"><?php echo $this->getMessagesBlock()->getGroupedHtml() ?></div>
27
+ <div class="page-title">
28
+ <h1><?php echo Mage::helper('lavi_news')->__('News') ?></h1>
29
+ </div>
30
+ <marquee behavior="scroll" direction="up" height="150" scrollamount="2" onmouseover="this.stop()" onmouseout="this.start()">
31
+ <div class="news_list_view">
32
+ <?php foreach ($this->getCollection() as $newsItem): ?>
33
+ <div id="item_<?php echo $newsItem->getId() ?>" class="news_list_item">
34
+ <h2>
35
+ <a href="<?php echo $this->getItemUrl($newsItem) ?>">
36
+ <?php echo $this->escapeHtml($newsItem->getTitle()) ?>
37
+ </a>
38
+ </h2>
39
+
40
+ <div class="news_item_subtitle">
41
+ <?php echo $this->formatDate($newsItem->getTimePublished(), 'medium') ?> |
42
+ <?php echo $this->escapeHtml($newsItem->getAuthor()) ?>
43
+ </div>
44
+
45
+ <?php if ($imageUrl = $this->getImageUrl($newsItem, 100)): ?>
46
+ <p><img src="<?php echo $imageUrl ?>" alt="<?php echo $this->escapeHtml($newsItem->getTitle()); ?>" /></p>
47
+ <?php endif; ?>
48
+ </div><br /><br />
49
+ <?php endforeach; ?>
50
+ </div>
51
+ </marquee>
52
+ <?php echo $this->getPager() ?>
app/etc/modules/Lavi_News.xml ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Module initial config
5
+ *
6
+ * @author Magento
7
+ */
8
+ -->
9
+ <config>
10
+ <modules>
11
+ <Lavi_News>
12
+ <active>true</active>
13
+ <codePool>community</codePool>
14
+ <depends>
15
+ <Mage_Adminhtml />
16
+ </depends>
17
+ </Lavi_News>
18
+ </modules>
19
+ </config>
package.xml ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>lavi_news</name>
4
+ <version>1.0.1</version>
5
+ <stability>stable</stability>
6
+ <license>OSL v3.0</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>news for your website.</summary>
10
+ <description>News&#xD;
11
+ &#xD;
12
+ We can create news which will show on left side or right side and give a link in footer.&#xD;
13
+ &#xD;
14
+ &#xD;
15
+ &#xD;
16
+ &#x201C;News&#x201C; extension easy to install and managable. Install module , Clear cache and logout, login again to admin panel. Check System-&gt;Configuration, in left side Go to &#x201C;Lavi News&#x201C;, here manage extension options. On frontend view News in left and right position which is enable in System-&gt;Configuration and also give a link "News" in footer.&#xD;
17
+ &#xD;
18
+ &#xD;
19
+ &#xD;
20
+ Features:&#xD;
21
+ &#xD;
22
+ Create and show news. &#xD;
23
+ &#xD;
24
+ Easy to install&#xD;
25
+ &#xD;
26
+ &#xD;
27
+ &#xD;
28
+ Steps:&#xD;
29
+ &#xD;
30
+ Install module , Clear cache and logout, login again. Check System-&gt;Configuration, in left side Go to &#x201C;Lavi News&#x201C;,here manage extension options.&#xD;
31
+ &#xD;
32
+ Front end: Give a link "News" in footer and view top latest news in left and right position which is enable in System-&gt;Configuration.&#xD;
33
+ &#xD;
34
+ &#xD;
35
+ &#xD;
36
+ Support&#xD;
37
+ &#xD;
38
+ Note :- if you need customization and help Click here to mail. </description>
39
+ <notes>news for your website.</notes>
40
+ <authors><author><name>Navneet</name><user>navneetkoshik</user><email>navneet.kshk@gmail.com</email></author></authors>
41
+ <date>2015-07-04</date>
42
+ <time>08:01:40</time>
43
+ <contents><target name="magecommunity"><dir name="Lavi"><dir name="News"><dir name="Block"><dir name="Adminhtml"><dir name="News"><dir name="Edit"><dir name="Form"><dir name="Element"><file name="Image.php" hash="beceeb4f69d761ca4a8ea2cc7dee3bab"/></dir></dir><file name="Form.php" hash="0f77f2f9d1439f718c1653c43a335004"/><dir name="Tab"><file name="Content.php" hash="7ae75ee0ba29c9f690a4276ce6220bf2"/><file name="Image.php" hash="6f27b652269437818043e10ca038719a"/><file name="Main.php" hash="b821e2fee5bd27fd0e91d450731f445f"/></dir><file name="Tabs.php" hash="0134b49cf07fb0104c4d57b3aa356560"/></dir><file name="Edit.php" hash="2995fcfe3289acecbbdd6dac015a4924"/><file name="Grid.php" hash="1117a2aa9b745db84fa6b5068d9165ae"/></dir><file name="News.php" hash="22b973532c43ee5c77ca1d2cdc1238dd"/></dir><file name="Item.php" hash="cc987c3821dade594be1eff3dbc4ecfd"/><file name="List.php" hash="dca4cc3e3781530fea082872cc3f7806"/><file name="Sidebar.php" hash="910f85d52d83c4f3131a0823f301245c"/></dir><dir name="Helper"><file name="Admin.php" hash="ae3c814a90b237d7518d3df4ff492dff"/><file name="Data.php" hash="d1351978852b5f8926e32cc9e6257573"/><file name="Image.php" hash="806b6cd0087f96e2e30f4fcec7f130dc"/></dir><dir name="Model"><file name="News.php" hash="9e3f1d81ca48f91370aacd4e33e922a9"/><file name="Observer.php" hash="63ca126554a2324e445f1225999358f2"/><dir name="Resource"><dir name="News"><file name="Collection.php" hash="7ca8b024e7851421ce0e26b906acd65e"/></dir><file name="News.php" hash="313d755bc0c001cdc1c2f5deae4899bf"/></dir></dir><dir name="controllers"><dir name="Adminhtml"><file name="NewsController.php" hash="49cafc17f63f33a571cee6f495721307"/></dir><file name="IndexController.php" hash="75880c2d7016b342d7a31e54eb191041"/></dir><dir name="etc"><file name="adminhtml.xml" hash="e3b716b662a733a4a05b5686a4f55fd6"/><file name="config.xml" hash="fc64a8f82fe4546409ef7fa1dd5a23fe"/><file name="system.xml" hash="8c231f1bdca33ad0fcf19fc694ff6625"/></dir><dir name="sql"><dir name="lavi_news_setup"><file name="install-1.0.0.0.1.php" hash="292e06277fe9715265e58f8f95d01c9a"/></dir></dir></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="lavi_news.xml" hash="3287e25d6ac84826ed9ed014f02ebe83"/></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="lavi_news.xml" hash="e1f15bbc2710ed1317038d2d8a1a1442"/></dir><dir name="template"><dir name="lavi"><dir name="news"><file name="item.phtml" hash="22fea186966c75817f7053e39250434c"/><file name="list.phtml" hash="d4ad7bc8e3c7107b3dddcd5fa12e0622"/><file name="sidebar.phtml" hash="2fd8e8259a4f0683bc1b256f2006d67a"/></dir></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Lavi_News.xml" hash="d758e1387b8498a27a69243aac6bbfea"/></dir></target></contents>
44
+ <compatible/>
45
+ <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
46
+ </package>