magento-keywordlink - Version 1.0.0

Version Notes

A plugin that allows you to define keyword/link pairs within your Magento store. The keywords are automatically linked in your product page,Homepage,CMS page. This is usefull for improving the internal cross referencing pages inside your site or to automatically link to external partners (SEO).

Download this release

Release Info

Developer iifire
Extension magento-keywordlink
Version 1.0.0
Comparing to
See all releases


Version 1.0.0

Files changed (27) hide show
  1. app/code/community/Magentokey/Keyword/Block/Adminhtml/Keyword/List.php +39 -0
  2. app/code/community/Magentokey/Keyword/Block/Adminhtml/Keyword/List/Grid.php +149 -0
  3. app/code/community/Magentokey/Keyword/Block/Adminhtml/Keyword/New.php +101 -0
  4. app/code/community/Magentokey/Keyword/Block/Adminhtml/Keyword/New/Form.php +185 -0
  5. app/code/community/Magentokey/Keyword/Block/Adminhtml/Keyword/Word.php +29 -0
  6. app/code/community/Magentokey/Keyword/Block/Adminhtml/Keyword/Word/Grid.php +80 -0
  7. app/code/community/Magentokey/Keyword/Block/Js.php +15 -0
  8. app/code/community/Magentokey/Keyword/Helper/Data.php +176 -0
  9. app/code/community/Magentokey/Keyword/Model/Keyword.php +27 -0
  10. app/code/community/Magentokey/Keyword/Model/Mysql4/Keyword.php +13 -0
  11. app/code/community/Magentokey/Keyword/Model/Mysql4/Keyword/Collection.php +13 -0
  12. app/code/community/Magentokey/Keyword/Model/Mysql4/Word.php +13 -0
  13. app/code/community/Magentokey/Keyword/Model/Mysql4/Word/Collection.php +13 -0
  14. app/code/community/Magentokey/Keyword/Model/Word.php +13 -0
  15. app/code/community/Magentokey/Keyword/controllers/Adminhtml/Keyword/IndexController.php +181 -0
  16. app/code/community/Magentokey/Keyword/controllers/IndexController.php +19 -0
  17. app/code/community/Magentokey/Keyword/etc/adminhtml.xml +29 -0
  18. app/code/community/Magentokey/Keyword/etc/config.xml +126 -0
  19. app/code/community/Magentokey/Keyword/etc/system.xml +77 -0
  20. app/code/community/Magentokey/Keyword/sql/magentokey_keyword_setup/mysql4-install-1.0.0.php +42 -0
  21. app/design/adminhtml/default/default/template/magentokey/keyword/list.phtml +15 -0
  22. app/design/adminhtml/default/default/template/magentokey/keyword/new.phtml +31 -0
  23. app/design/adminhtml/default/default/template/magentokey/keyword/word.phtml +15 -0
  24. app/design/frontend/default/default/layout/magentokey_keyword.xml +8 -0
  25. app/design/frontend/default/default/template/magentokey/keyword/js.phtml +62 -0
  26. app/etc/modules/Magentokey_Keyword.xml +12 -0
  27. package.xml +18 -0
app/code/community/Magentokey/Keyword/Block/Adminhtml/Keyword/List.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Joy <yanggaojiao@qq.com> (http://www.hifasion.org)
4
+ * @copyright Copyright &copy; 2011, Hifashion (http://www.magentokey.com, http://www.hifasion.org)
5
+ * @version 1.0.0
6
+ */
7
+ class Magentokey_Keyword_Block_Adminhtml_Keyword_List extends Mage_Adminhtml_Block_Template
8
+ {
9
+ public function __construct()
10
+ {
11
+ parent::__construct();
12
+ $this->setTemplate('magentokey/keyword/list.phtml');
13
+ }
14
+
15
+
16
+ protected function _prepareLayout()
17
+ {
18
+ $this->setChild('grid', $this->getLayout()->createBlock('magentokey_keyword/adminhtml_keyword_list_grid', 'keyword.list.grid'));
19
+ return parent::_prepareLayout();
20
+ }
21
+ public function getNewUrl()
22
+ {
23
+ return $this->getUrl('*/*/add');
24
+ }
25
+ public function getWordUrl()
26
+ {
27
+ return $this->getUrl('*/*/word');
28
+ }
29
+ public function getForm()
30
+ {
31
+ return $this->getLayout()
32
+ ->createBlock('magentokey_keyword/adminhtml_keyword_list_form')
33
+ ->toHtml();
34
+ }
35
+ public function getHeaderText()
36
+ {
37
+ return Mage::helper('magentokey_keyword')->__('Magentokey keyword Link');
38
+ }
39
+ }
app/code/community/Magentokey/Keyword/Block/Adminhtml/Keyword/List/Grid.php ADDED
@@ -0,0 +1,149 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Joy <yanggaojiao@qq.com> (http://www.hifasion.org)
4
+ * @copyright Copyright &copy; 2011, Hifashion (http://www.magentokey.com, http://www.hifasion.org)
5
+ * @version 1.0.0
6
+ */
7
+ class Magentokey_Keyword_Block_Adminhtml_Keyword_List_Grid extends Mage_Adminhtml_Block_Widget_Grid
8
+ {
9
+ protected function _construct()
10
+ {
11
+ $this->setEmptyText(Mage::helper('magentokey_keyword')->__('No Record Found'));
12
+ $this->setDefaultSort('added_at');
13
+ $this->setDefaultOrder('desc');
14
+ }
15
+
16
+ protected function _prepareCollection()
17
+ {
18
+ $collection = Mage::getResourceSingleton('magentokey_keyword/keyword_collection');
19
+ $this->setCollection($collection);
20
+ return parent::_prepareCollection();
21
+ }
22
+
23
+ protected function _prepareColumns()
24
+ {
25
+ $this->addColumn('link_id',
26
+ array(
27
+ 'header' => Mage::helper('magentokey_keyword')->__('ID'),
28
+ 'align' => 'center',
29
+ 'width' => '50px',
30
+ 'index' => 'link_id',
31
+ ));
32
+ $this->addColumn('link_code',
33
+ array(
34
+ 'header' =>Mage::helper('magentokey_keyword')->__('Keyword'),
35
+ 'index' =>'link_code',
36
+ 'align' => 'center',
37
+ 'width' => '120px',
38
+ ));
39
+ $this->addColumn('link_value',
40
+ array(
41
+ 'header' =>Mage::helper('magentokey_keyword')->__('Link'),
42
+ 'index' =>'link_value',
43
+ 'width' => '300px',
44
+ ));
45
+ $this->addColumn('link_description',
46
+ array(
47
+ 'header'=>Mage::helper('magentokey_keyword')->__('Link Description'),
48
+ 'index'=>'link_description',
49
+ ));
50
+ $this->addColumn('link_status',
51
+ array(
52
+ 'header'=>Mage::helper('magentokey_keyword')->__('Enable'),
53
+ 'index'=>'link_status',
54
+ 'width'=>'50px',
55
+ 'type' => 'options',
56
+ 'options' => array(
57
+ 1 => Mage::helper('magentokey_keyword')->__('Yes'),
58
+ 0 => Mage::helper('magentokey_keyword')->__('No'),
59
+ ),
60
+ ));
61
+ $this->addColumn('no_follow',
62
+ array(
63
+ 'header'=>Mage::helper('magentokey_keyword')->__('No Follow'),
64
+ 'index'=>'no_follow',
65
+ 'type' => 'options',
66
+ 'options' => array(
67
+ 1 => Mage::helper('magentokey_keyword')->__('Yes'),
68
+ 0 => Mage::helper('magentokey_keyword')->__('No'),
69
+ ),
70
+ ));
71
+ $this->addColumn('first_match_only',
72
+ array(
73
+ 'header'=>Mage::helper('magentokey_keyword')->__('First Match Only'),
74
+ 'index'=>'first_match_only',
75
+ 'type' => 'options',
76
+ 'options' => array(
77
+ 1 => Mage::helper('magentokey_keyword')->__('Yes'),
78
+ 0 => Mage::helper('magentokey_keyword')->__('No'),
79
+ ),
80
+ ));
81
+ $this->addColumn('new_window',
82
+ array(
83
+ 'header'=>Mage::helper('magentokey_keyword')->__('New Window'),
84
+ 'index'=>'new_window',
85
+ 'type' => 'options',
86
+ 'options' => array(
87
+ 1 => Mage::helper('magentokey_keyword')->__('Yes'),
88
+ 0 => Mage::helper('magentokey_keyword')->__('No'),
89
+ ),
90
+ ));
91
+ $this->addColumn('ignore_case',
92
+ array(
93
+ 'header'=>Mage::helper('magentokey_keyword')->__('Ignore Case'),
94
+ 'index'=>'ignore_case',
95
+ 'type' => 'options',
96
+ 'options' => array(
97
+ 1 => Mage::helper('magentokey_keyword')->__('Yes'),
98
+ 0 => Mage::helper('magentokey_keyword')->__('No'),
99
+ ),
100
+ ));
101
+ $this->addColumn('is_afiliate',
102
+ array(
103
+ 'header'=>Mage::helper('magentokey_keyword')->__('Is Afiliate'),
104
+ 'index'=>'is_afiliate',
105
+ 'type' => 'options',
106
+ 'options' => array(
107
+ 1 => Mage::helper('magentokey_keyword')->__('Yes'),
108
+ 0 => Mage::helper('magentokey_keyword')->__('No'),
109
+ ),
110
+ ));
111
+ $this->addColumn('for_zhcn',
112
+ array(
113
+ 'header'=>Mage::helper('magentokey_keyword')->__('For zh_CN'),
114
+ 'index'=>'for_zhcn',
115
+ 'type' => 'options',
116
+ 'options' => array(
117
+ 1 => Mage::helper('magentokey_keyword')->__('Yes'),
118
+ 0 => Mage::helper('magentokey_keyword')->__('No'),
119
+ ),
120
+ ));
121
+
122
+ $this->addColumn('store', array(
123
+ 'header' => Mage::helper('magentokey_keyword')->__('Store View'),
124
+ 'index' => 'store_id',
125
+ 'type' => 'options',
126
+ 'options' => $this->_getStoreOptions()
127
+ ));
128
+ return $this;
129
+ }
130
+ protected function _prepareMassaction()
131
+ {
132
+ $this->setMassactionIdField('link_id');
133
+ $this->getMassactionBlock()->addItem('delete', array(
134
+ 'label' => Mage::helper('magentokey_keyword')->__('Delete'),
135
+ 'url' => $this->getUrl('*/*/massDelete'),
136
+ 'confirm' => Mage::helper('magentokey_keyword')->__('Are you sure?')
137
+ ));
138
+ return $this;
139
+ }
140
+ public function getRowUrl($row)
141
+ {
142
+ return $this->getUrl('*/*/edit', array('id'=>$row->getId()));
143
+ }
144
+ protected function _getStoreOptions()
145
+ {
146
+ return Mage::getModel('adminhtml/system_store')->getStoreOptionHash();
147
+ }
148
+ }
149
+
app/code/community/Magentokey/Keyword/Block/Adminhtml/Keyword/New.php ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Joy <yanggaojiao@qq.com> (http://www.hifasion.org)
4
+ * @copyright Copyright &copy; 2011, Hifashion (http://www.magentokey.com, http://www.hifasion.org)
5
+ * @version 1.0.0
6
+ */
7
+ class Magentokey_Keyword_Block_Adminhtml_Keyword_New extends Mage_Adminhtml_Block_Template
8
+ {
9
+ public function __construct()
10
+ {
11
+ parent::__construct();
12
+ $this->setTemplate('magentokey/keyword/new.phtml');
13
+ }
14
+ protected function _prepareLayout()
15
+ {
16
+ $this->setChild('back_button',
17
+ $this->getLayout()->createBlock('adminhtml/widget_button')
18
+ ->setData(array(
19
+ 'label' => Mage::helper('magentokey_keyword')->__('Back'),
20
+ 'onclick' => "window.location.href = '" . $this->getUrl('*/*/') . "'",
21
+ 'class' => 'back'
22
+ ))
23
+ );
24
+
25
+ $this->setChild('reset_button',
26
+ $this->getLayout()->createBlock('adminhtml/widget_button')
27
+ ->setData(array(
28
+ 'label' => Mage::helper('magentokey_keyword')->__('Reset'),
29
+ 'onclick' => 'window.location.href = window.location.href'
30
+ ))
31
+ );
32
+ $this->setChild('save_button',
33
+ $this->getLayout()->createBlock('adminhtml/widget_button')
34
+ ->setData(array(
35
+ 'label' => Mage::helper('magentokey_keyword')->__('Save Link'),
36
+ 'onclick' => 'keywordControl.save();',
37
+ 'class' => 'save'
38
+ ))
39
+ );
40
+ $this->setChild('continue_button',
41
+ $this->getLayout()->createBlock('adminhtml/widget_button')
42
+ ->setData(array(
43
+ 'label' => Mage::helper('magentokey_keyword')->__('Save and Continue'),
44
+ 'onclick' => 'keywordControl.continue();',
45
+ 'class' => 'save'
46
+ ))
47
+ );
48
+ }
49
+ public function getContinueButtonHtml()
50
+ {
51
+ return $this->getChildHtml('continue_button');
52
+ }
53
+ /**
54
+ * Retrieve Back Button HTML
55
+ *
56
+ * @return string
57
+ */
58
+ public function getBackButtonHtml()
59
+ {
60
+ return $this->getChildHtml('back_button');
61
+ }
62
+
63
+ /**
64
+ * Retrieve Reset Button HTML
65
+ *
66
+ * @return string
67
+ */
68
+ public function getResetButtonHtml()
69
+ {
70
+ return $this->getChildHtml('reset_button');
71
+ }
72
+
73
+ /**
74
+ * Retrieve Save Button HTML
75
+ *
76
+ * @return string
77
+ */
78
+ public function getSaveButtonHtml()
79
+ {
80
+ return $this->getChildHtml('save_button');
81
+ }
82
+ public function getSaveUrl()
83
+ {
84
+ return $this->getUrl('*/*/save');
85
+ }
86
+ public function getForm()
87
+ {
88
+ return $this->getLayout()
89
+ ->createBlock('magentokey_keyword/adminhtml_keyword_new_form')
90
+ ->toHtml();
91
+ }
92
+ public function getHeaderText()
93
+ {
94
+ if ($this->getRequest()->getParam('id')) {
95
+ return Mage::helper('magentokey_keyword')->__('Edit Keyword Link');
96
+ } else {
97
+ return Mage::helper('magentokey_keyword')->__('Add Keyword Link');
98
+ }
99
+
100
+ }
101
+ }
app/code/community/Magentokey/Keyword/Block/Adminhtml/Keyword/New/Form.php ADDED
@@ -0,0 +1,185 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Joy <yanggaojiao@qq.com> (http://www.hifasion.org)
4
+ * @copyright Copyright &copy; 2011, Hifashion (http://www.magentokey.com, http://www.hifasion.org)
5
+ * @version 1.0.0
6
+ */
7
+ class Magentokey_Keyword_Block_Adminhtml_Keyword_New_Form extends Mage_Adminhtml_Block_Widget_Form
8
+ {
9
+ /**
10
+ * Define Form settings
11
+ *
12
+ */
13
+ public function __construct()
14
+ {
15
+ parent::__construct();
16
+ }
17
+
18
+ /**
19
+ * Prepare form before rendering HTML
20
+ *
21
+ * @return Mage_Adminhtml_Block_Newsletter_Template_Edit_Form
22
+ */
23
+ protected function _prepareForm()
24
+ {
25
+
26
+ $form = new Varien_Data_Form(array(
27
+ 'id' => 'new_form',
28
+ 'action' => $this->getData('action'),
29
+ 'method' => 'post'
30
+ ));
31
+ $model = Mage::getModel('magentokey_keyword/keyword');
32
+ if ($id = $this->getRequest()->getParam('id')) {
33
+ $model = $model->load($id);
34
+ }
35
+
36
+ $fieldset = $form->addFieldset('base_fieldset', array(
37
+ 'legend' => Mage::helper('magentokey_keyword')->__('Keyword Link Setting'),
38
+ 'class' => 'fieldset-wide'
39
+ ));
40
+ if ($model->getId()) {
41
+ $fieldset->addField('link_id', 'hidden', array(
42
+ 'name' => 'link_id',
43
+ 'value' => $model->getLinkId(),
44
+ ));
45
+ }
46
+ $fieldset->addField('link_code', 'text', array(
47
+ 'name' => 'link_code',
48
+ 'label' => Mage::helper('magentokey_keyword')->__('Keyword'),
49
+ 'title' => Mage::helper('magentokey_keyword')->__('Keyword'),
50
+ 'required' => true,
51
+ 'value' => $model->getLinkCode(),
52
+
53
+ ));
54
+ $fieldset->addField('link_value', 'text', array(
55
+ 'name' => 'link_value',
56
+ 'label' => Mage::helper('magentokey_keyword')->__('Link'),
57
+ 'title' => Mage::helper('magentokey_keyword')->__('Link'),
58
+ 'required' => true,
59
+ 'value' => $model->getLinkValue(),
60
+
61
+ ));
62
+ $fieldset->addField('link_description', 'text', array(
63
+ 'name' => 'link_description',
64
+ 'label' => Mage::helper('magentokey_keyword')->__('Description'),
65
+ 'title' => Mage::helper('magentokey_keyword')->__('Description'),
66
+ 'required' => false,
67
+ 'value' => $model->getLinkDescription(),
68
+
69
+ ));
70
+ $fieldset->addField('no_follow', 'select', array(
71
+ 'name' => 'no_follow',
72
+ 'label' => Mage::helper('magentokey_keyword')->__('No Follow'),
73
+ 'title' => Mage::helper('magentokey_keyword')->__('No Follow'),
74
+ 'options' => array(
75
+ 1 => Mage::helper('magentokey_keyword')->__('Yes'),
76
+ 0 => Mage::helper('magentokey_keyword')->__('No'),
77
+ ),
78
+ 'value' => $model->getNoFollow(),
79
+ 'required' => true,
80
+
81
+ ));
82
+ $fieldset->addField('first_match_only', 'select', array(
83
+ 'name' => 'first_match_only',
84
+ 'label' => Mage::helper('magentokey_keyword')->__('First Match Only'),
85
+ 'title' => Mage::helper('magentokey_keyword')->__('First Match Only'),
86
+ 'options' => array(
87
+ 1 => Mage::helper('magentokey_keyword')->__('Yes'),
88
+ 0 => Mage::helper('magentokey_keyword')->__('No'),
89
+ ),
90
+ 'value' => $model->getFirstMatchOnly(),
91
+ 'required' => true,
92
+
93
+ ));
94
+ $fieldset->addField('new_window', 'select', array(
95
+ 'name' => 'new_window',
96
+ 'label' => Mage::helper('magentokey_keyword')->__('New Window'),
97
+ 'title' => Mage::helper('magentokey_keyword')->__('New Window'),
98
+ 'options' => array(
99
+ 1 => Mage::helper('magentokey_keyword')->__('Yes'),
100
+ 0 => Mage::helper('magentokey_keyword')->__('No'),
101
+ ),
102
+ 'value' => $model->getNewWindow(),
103
+ 'required' => true,
104
+
105
+ ));
106
+ $fieldset->addField('ignore_case', 'select', array(
107
+ 'name' => 'ignore_case',
108
+ 'label' => Mage::helper('magentokey_keyword')->__('Ignore Case'),
109
+ 'title' => Mage::helper('magentokey_keyword')->__('Ignore Case'),
110
+ 'options' => array(
111
+ 1 => Mage::helper('magentokey_keyword')->__('Yes'),
112
+ 0 => Mage::helper('magentokey_keyword')->__('No'),
113
+ ),
114
+ 'value' => $model->getIngoreCase(),
115
+ 'required' => true,
116
+
117
+ ));
118
+ $fieldset->addField('is_afiliate', 'select', array(
119
+ 'name' => 'is_afiliate',
120
+ 'label' => Mage::helper('magentokey_keyword')->__('Is Afiliate'),
121
+ 'title' => Mage::helper('magentokey_keyword')->__('Is Afiliate'),
122
+ 'options' => array(
123
+ 1 => Mage::helper('magentokey_keyword')->__('Yes'),
124
+ 0 => Mage::helper('magentokey_keyword')->__('No'),
125
+ ),
126
+ 'value' => $model->getIsAfiliate(),
127
+ 'required' => true,
128
+
129
+ ));
130
+ $fieldset->addField('for_zhcn', 'select', array(
131
+ 'name' => 'for_zhcn',
132
+ 'label' => Mage::helper('magentokey_keyword')->__('For zh_CN'),
133
+ 'title' => Mage::helper('magentokey_keyword')->__('For zh_CN'),
134
+ 'options' => array(
135
+ 1 => Mage::helper('magentokey_keyword')->__('Yes'),
136
+ 0 => Mage::helper('magentokey_keyword')->__('No'),
137
+ ),
138
+ 'value' => $model->getForZhcn(),
139
+ 'required' => true,
140
+
141
+ ));
142
+ $fieldset->addField('link_status', 'select', array(
143
+ 'name' => 'link_status',
144
+ 'label' => Mage::helper('magentokey_keyword')->__('Status'),
145
+ 'title' => Mage::helper('magentokey_keyword')->__('Status'),
146
+ 'options' => array(
147
+ 1 => Mage::helper('magentokey_keyword')->__('Yes'),
148
+ 0 => Mage::helper('magentokey_keyword')->__('No'),
149
+ ),
150
+ 'value' => $model->getLinkStatus(),
151
+ 'required' => true,
152
+
153
+ ));
154
+ if ($model->getId()) {
155
+ $fieldset->addField('store_id', 'text', array(
156
+ 'label' => Mage::helper('magentokey_keyword')->__('Visible In'),
157
+ 'name' => 'store_id',
158
+ 'value' => Mage::getSingleton('adminhtml/system_store')->getStoreName($model->getStoreId()),
159
+ 'disabled' => true,
160
+
161
+ ));
162
+ } else {
163
+ if (!Mage::app()->isSingleStoreMode()) {
164
+ $fieldset->addField('store_ids', 'select', array(
165
+ 'label' => Mage::helper('magentokey_keyword')->__('Visible In'),
166
+ 'required' => true,
167
+ 'name' => 'store_ids[]',
168
+ 'values' => Mage::getSingleton('adminhtml/system_store')->getStoreValuesForForm(),
169
+ ));
170
+ } else {
171
+ $fieldset->addField('store_ids', 'hidden', array(
172
+ 'name' => 'store_ids[]',
173
+ 'value' => Mage::app()->getStore(true)->getId(),
174
+
175
+ ));
176
+ }
177
+ }
178
+
179
+ $form->setAction($this->getUrl('*/*/save'));
180
+ $form->setUseContainer(true);
181
+ $this->setForm($form);
182
+
183
+ return parent::_prepareForm();
184
+ }
185
+ }
app/code/community/Magentokey/Keyword/Block/Adminhtml/Keyword/Word.php ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Joy <yanggaojiao@qq.com> (http://www.hifasion.org)
4
+ * @copyright Copyright &copy; 2011, Hifashion (http://www.magentokey.com, http://www.hifasion.org)
5
+ * @version 1.0.0
6
+ */
7
+ class Magentokey_Keyword_Block_Adminhtml_Keyword_Word extends Mage_Adminhtml_Block_Template
8
+ {
9
+ public function __construct()
10
+ {
11
+ parent::__construct();
12
+ $this->setTemplate('magentokey/keyword/word.phtml');
13
+ }
14
+
15
+
16
+ protected function _prepareLayout()
17
+ {
18
+ $this->setChild('grid', $this->getLayout()->createBlock('magentokey_keyword/adminhtml_keyword_word_grid', 'keyword.word.grid'));
19
+ return parent::_prepareLayout();
20
+ }
21
+ public function getBackUrl()
22
+ {
23
+ return $this->getUrl('*/*/');
24
+ }
25
+ public function getHeaderText()
26
+ {
27
+ return Mage::helper('magentokey_keyword')->__('Keyword from Search Engine');
28
+ }
29
+ }
app/code/community/Magentokey/Keyword/Block/Adminhtml/Keyword/Word/Grid.php ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Joy <yanggaojiao@qq.com> (http://www.hifasion.org)
4
+ * @copyright Copyright &copy; 2011, Hifashion (http://www.magentokey.com, http://www.hifasion.org)
5
+ * @version 1.0.0
6
+ */
7
+ class Magentokey_Keyword_Block_Adminhtml_Keyword_Word_Grid extends Mage_Adminhtml_Block_Widget_Grid
8
+ {
9
+ protected function _construct()
10
+ {
11
+ $this->setEmptyText(Mage::helper('magentokey_keyword')->__('No Record Found'));
12
+ $this->setDefaultSort('word_id');
13
+ $this->setDefaultOrder('desc');
14
+ }
15
+
16
+ protected function _prepareCollection()
17
+ {
18
+ $collection = Mage::getResourceSingleton('magentokey_keyword/word_collection');
19
+ $this->setCollection($collection);
20
+ return parent::_prepareCollection();
21
+ }
22
+
23
+ protected function _prepareColumns()
24
+ {
25
+ $this->addColumn('word_id',
26
+ array(
27
+ 'header' => Mage::helper('magentokey_keyword')->__('ID'),
28
+ 'align' => 'center',
29
+ 'width' => '50px',
30
+ 'index' => 'word_id',
31
+ ));
32
+ $this->addColumn('word',
33
+ array(
34
+ 'header' =>Mage::helper('magentokey_keyword')->__('Keyword'),
35
+ 'index' =>'word',
36
+ 'align' => 'center',
37
+ 'width' => '120px',
38
+ ));
39
+ $this->addColumn('engine',
40
+ array(
41
+ 'header' =>Mage::helper('magentokey_keyword')->__('From'),
42
+ 'index' =>'engine',
43
+ 'align' => 'center',
44
+ 'width' => '120px',
45
+ ));
46
+ $this->addColumn('added_at',
47
+ array(
48
+ 'header'=>Mage::helper('magentokey_keyword')->__('Added At'),
49
+ 'index'=>'added_at',
50
+ 'gmtoffset' => true,
51
+ 'type'=>'datetime'
52
+ ));
53
+ $this->addColumn('store', array(
54
+ 'header' => Mage::helper('magentokey_keyword')->__('Store View'),
55
+ 'index' => 'store_id',
56
+ 'type' => 'options',
57
+ 'options' => $this->_getStoreOptions()
58
+ ));
59
+ return $this;
60
+ }
61
+ protected function _prepareMassaction()
62
+ {
63
+ $this->setMassactionIdField('link_id');
64
+ $this->getMassactionBlock()->addItem('delete', array(
65
+ 'label' => Mage::helper('magentokey_keyword')->__('Delete'),
66
+ 'url' => $this->getUrl('*/*/deleteWord'),
67
+ 'confirm' => Mage::helper('magentokey_keyword')->__('Are you sure?')
68
+ ));
69
+ return $this;
70
+ }
71
+ public function getRowUrl($row)
72
+ {
73
+ return $this->getUrl('*/*/edit', array('id'=>$row->getId()));
74
+ }
75
+ protected function _getStoreOptions()
76
+ {
77
+ return Mage::getModel('adminhtml/system_store')->getStoreOptionHash();
78
+ }
79
+ }
80
+
app/code/community/Magentokey/Keyword/Block/Js.php ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Joy <yanggaojiao@qq.com> (http://www.hifasion.org)
4
+ * @copyright Copyright &copy; 2011, Hifashion (http://www.magentokey.com, http://www.hifasion.org)
5
+ * @version 1.0.0
6
+ */
7
+ class Magentokey_Keyword_Block_Js extends Mage_Core_Block_Template
8
+ {
9
+
10
+ public function getAjaxUrl()
11
+ {
12
+ return $this->getUrl('keyword/index/',array('ajax'=>true));
13
+ }
14
+ }
15
+
app/code/community/Magentokey/Keyword/Helper/Data.php ADDED
@@ -0,0 +1,176 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Joy <yanggaojiao@qq.com> (http://www.hifasion.org)
4
+ * @copyright Copyright &copy; 2011, Hifashion (http://www.magentokey.com, http://www.hifasion.org)
5
+ * @version 1.0.0
6
+ */
7
+ class Magentokey_Keyword_Helper_Data extends Mage_Core_Helper_Abstract
8
+ {
9
+ public function addKeywordLink($content)
10
+ {
11
+ $enable = Mage::getStoreConfig(Magentokey_Keyword_Model_Keyword::XML_KEYWORD_ENABLE);
12
+ if ($enable) {
13
+ $content = $this->keywordLinkReplace($content);
14
+ }
15
+ return $content;
16
+ }
17
+ public function linkItself()
18
+ {
19
+ return Mage::getStoreConfig(Magentokey_Keyword_Model_Keyword::XML_KEYWORD_LINK_ITSELF);
20
+ }
21
+ public function getMatchFrom()
22
+ {
23
+ return (int)Mage::getStoreConfig(Magentokey_Keyword_Model_Keyword::XML_KEYWORD_MATCHED_FROM);
24
+ }
25
+ public function getMatchTo()
26
+ {
27
+ return (int)Mage::getStoreConfig(Magentokey_Keyword_Model_Keyword::XML_KEYWORD_MATCHED_TO);
28
+ }
29
+ public function keywordLinkReplace($content)
30
+ {
31
+ $match_num_from = $this->getMatchFrom() ? $this->getMatchFrom() : 2;
32
+ $match_num_to = $this->getMatchTo() ? $this->getMatchTo() : 3;
33
+ $link_itself = $this->linkItself() ? $this->linkItself() : 0;
34
+ $ignore_pre = 1;
35
+
36
+ $collection = Mage::getResourceModel('magentokey_keyword/keyword_collection')
37
+ ->addFieldToFilter('link_status', Magentokey_Keyword_Model_Keyword::KEYWORD_STATUS_ENABLE)
38
+ ->setOrder('link_code', 'desc');
39
+ foreach ($collection as $_c) {
40
+ $keyword = $_c->getLinkCode();
41
+ $link = $_c->getLinkValue();
42
+ $nofollow = $_c->getNoFollow();
43
+ $firstonly = $_c->getFirstMatchOnly();
44
+ $newwindow = $_c->getNewWindow();
45
+ $ignorecase = $_c->getIgnoreCase();
46
+ $isaffiliate = $_c->getIsAffiliate();
47
+ $zh_CN = $_c->getForZhcn();
48
+ $desc = $_c->getLinkDescription();
49
+
50
+ if($link_itself){
51
+ $recent_url = 'http://'.$_SERVER['SERVER_NAME'].$_SERVER["REQUEST_URI"];
52
+ if($link == $recent_url)
53
+ continue;
54
+ }
55
+
56
+ $cleankeyword = stripslashes($keyword);
57
+ if (!$desc) { $desc = $cleankeyword; }
58
+
59
+ $desc = addcslashes($desc, '$');
60
+ if ($isaffiliate) {
61
+ $url = "<span class='mk_keywordlink_affiliate'>";
62
+ } else {
63
+ $url = "<span class='mk_keywordlink'>";
64
+ }
65
+ $url .= "<a href=\"$link\" title=\"$desc\"";
66
+ if ($nofollow) { $url .= ' rel="nofollow"'; }
67
+ if ($newwindow) { $url .= ' target="_blank"'; }
68
+
69
+ $url .= ">".addcslashes($cleankeyword, '$')."</a>";
70
+ $url .= "</span>";
71
+
72
+ if ($firstonly) $limit = 1; else $limit= rand($match_num_from,$match_num_to);
73
+ if ($ignorecase) $case = "i"; else $case="";
74
+
75
+ $ex_word = preg_quote($cleankeyword,'\'');
76
+ //ignore pre & ignore_keywordlink
77
+ if( $num_2 = preg_match_all("/<mk_nokeywordlink>.*?<\/mk_nokeywordlink>/is", $content, $ignore_keywordlink) )
78
+ for($i=1;$i<=$num_2;$i++)
79
+ $content = preg_replace( "/<mk_nokeywordlink>.*?<\/mk_nokeywordlink>/is", "%ignore_keywordlink_$i%", $content, 1);
80
+ if($ignore_pre){
81
+ if( $num_1 = preg_match_all("/<pre.*?>.*?<\/pre>/is", $content, $ignore_pre) )
82
+ for($i=1;$i<=$num_1;$i++)
83
+ $content = preg_replace( "/<pre.*?>.*?<\/pre>/is", "%ignore_pre_$i%", $content, 1);
84
+ }
85
+ $content = preg_replace( '|(<img)(.*?)('.$ex_word.')(.*?)(>)|U', '$1$2%&&&&&%$4$5', $content);
86
+ // For keywords with quotes (') to work, we need to disable word boundary matching
87
+ $cleankeyword = preg_quote($cleankeyword,'\'');
88
+
89
+ if ($zh_CN)
90
+ $regEx = '\'(?!((<.*?)|(<a.*?)))(' . $cleankeyword . ')(?!(([^<>]*?)>)|([^>]*?</a>))\'s' . $case;
91
+ elseif (strpos( $cleankeyword , '\'')>0)
92
+ $regEx = '\'(?!((<.*?)|(<a.*?)))(' . $cleankeyword . ')(?!(([^<>]*?)>)|([^>]*?</a>))\'s' . $case;
93
+ else
94
+ $regEx = '\'(?!((<.*?)|(<a.*?)))(\b'. $cleankeyword . '\b)(?!(([^<>]*?)>)|([^>]*?</a>))\'s' . $case;
95
+
96
+ $content = preg_replace($regEx,$url,$content,$limit);
97
+ $content = str_replace( '%&&&&&%', stripslashes($ex_word), $content);
98
+
99
+ //ignore pre & ignore_keywordlink
100
+ if($ignore_pre){
101
+ for($i=1;$i<=$num_1;$i++){
102
+ $content = str_replace( "%ignore_pre_$i%", $ignore_pre[0][$i-1], $content);
103
+ }
104
+ }
105
+ for($i=1;$i<=$num_2;$i++){
106
+ $content = str_replace( "%ignore_keywordlink_$i%", $ignore_keywordlink[0][$i-1], $content);
107
+ }
108
+ }
109
+ return $content;
110
+ }
111
+
112
+
113
+ function searchword($q = '')
114
+ {
115
+ $url = Mage::getBaseUrl();
116
+ if (empty($q)) {
117
+ return null;
118
+ }
119
+ list($enginer,$keys)=explode('?',trim($q));
120
+ if (strpos($q,'#')) {
121
+ list($enginer,$keys)=explode('#',trim($q));
122
+ }
123
+ $is_utf8=false;
124
+ $query = array();
125
+ parse_str($keys,$query);
126
+
127
+ if(strpos($enginer,'baidu') != false){
128
+ $keyword= $query["wd"] ? $query["wd"] : $query["word"];
129
+ $is_utf8 = ($query["ie"] == 'utf-8')?true:false;
130
+ $enginer = 'baidu';
131
+ } elseif(strpos($enginer,'google') != false) {
132
+ $keyword = $query["q"];
133
+ $enginer = 'google';
134
+ $is_utf8 =($query["ie"] =='gb2312'||$query["ie"] == 'gb') ? false : true;
135
+ } elseif (strpos($enginer,'soso') != false) {
136
+ $keyword = $query["w"];
137
+ $is_utf8 =false;
138
+ $enginer = 'soso';
139
+ } elseif (strpos($enginer,'sogou') != false) {
140
+ $keyword = $query["query"];
141
+ $is_utf8 = false;
142
+ $enginer = 'sogou';
143
+ } elseif (strpos($enginer,'youdao') != false) {
144
+ $keyword = $query["q"];
145
+ $enginer = 'youdao';
146
+ $is_utf8 =(strtolower($query["ue"]) == 'gb2312') ? false : true;
147
+ } elseif (strpos($enginer,'bing')!=false) {
148
+ $keyword = $query["q"];
149
+ $is_utf8 = true;
150
+ $enginer = 'bing';
151
+ } elseif (strpos($enginer,'yahoo')!=false) {
152
+ $keyword = $query["p"];
153
+ $is_utf8 = true;
154
+ $enginer = 'yahoo';
155
+ } else{
156
+ $keyword = null;
157
+ $enginer = 'others';
158
+ }
159
+
160
+ $keyword = urldecode($is_utf8 ? $keyword : iconv("gb2312","utf-8",$keyword));
161
+ //echo $keyword;
162
+ if ($keyword) {
163
+ //keep keyword record in database
164
+ $storeId = Mage::app()->getStore()->getId();
165
+ $wordModel = Mage::getModel('magentokey_keyword/word');
166
+ $wordModel->setWord($keyword)
167
+ ->setStoreId($storeId)
168
+ ->setEngine($enginer)
169
+ ->setAddedAt(Mage::getSingleton('core/date')->gmtDate());
170
+ try {
171
+ $wordModel->save();
172
+ } catch (Exception $e) {}
173
+ }
174
+ return $keyword;
175
+ }
176
+ }
app/code/community/Magentokey/Keyword/Model/Keyword.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Joy <yanggaojiao@qq.com> (http://www.hifasion.org)
4
+ * @copyright Copyright &copy; 2011, Hifashion (http://www.magentokey.com, http://www.hifasion.org)
5
+ * @version 1.0.0
6
+ */
7
+ class Magentokey_Keyword_Model_Keyword extends Mage_Core_Model_Abstract
8
+ {
9
+ const KEYWORD_STATUS_ENABLE = 1;
10
+ const KEYWORD_STATUS_DISABLE = 0;
11
+
12
+ const XML_KEYWORD_ENABLE = 'magentokey_keyword/options/enable';
13
+ const XML_KEYWORD_MATCHED_FROM = 'magentokey_keyword/options/match_num_from';
14
+ const XML_KEYWORD_MATCHED_TO = 'magentokey_keyword/options/match_num_to';
15
+ const XML_KEYWORD_LINK_ITSELF = 'magentokey_keyword/options/link_itself';
16
+ protected function _construct()
17
+ {
18
+ $this->_init('magentokey_keyword/keyword','link_id');
19
+ }
20
+
21
+ protected function _getWrite()
22
+ {
23
+ $resource = Mage::getSingleton('core/resource');
24
+ $writeConnection = $resource->getConnection('core_write');
25
+ return $writeConnection;
26
+ }
27
+ }
app/code/community/Magentokey/Keyword/Model/Mysql4/Keyword.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Joy <yanggaojiao@qq.com> (http://www.hifasion.org)
4
+ * @copyright Copyright &copy; 2011, Hifashion (http://www.magentokey.com, http://www.hifasion.org)
5
+ * @version 1.0.0
6
+ */
7
+ class Magentokey_Keyword_Model_Mysql4_Keyword extends Mage_Core_Model_Mysql4_Abstract
8
+ {
9
+ protected function _construct()
10
+ {
11
+ $this->_init('magentokey_keyword/keyword','link_id');
12
+ }
13
+ }
app/code/community/Magentokey/Keyword/Model/Mysql4/Keyword/Collection.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Joy <yanggaojiao@qq.com> (http://www.hifasion.org)
4
+ * @copyright Copyright &copy; 2011, Hifashion (http://www.magentokey.com, http://www.hifasion.org)
5
+ * @version 1.0.0
6
+ */
7
+ class Magentokey_Keyword_Model_Mysql4_Keyword_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
8
+ {
9
+ protected function _construct()
10
+ {
11
+ $this->_init('magentokey_keyword/keyword');
12
+ }
13
+ }
app/code/community/Magentokey/Keyword/Model/Mysql4/Word.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Joy <yanggaojiao@qq.com> (http://www.hifasion.org)
4
+ * @copyright Copyright &copy; 2011, Hifashion (http://www.magentokey.com, http://www.hifasion.org)
5
+ * @version 1.0.0
6
+ */
7
+ class Magentokey_Keyword_Model_Mysql4_Word extends Mage_Core_Model_Mysql4_Abstract
8
+ {
9
+ protected function _construct()
10
+ {
11
+ $this->_init('magentokey_keyword/word','word_id');
12
+ }
13
+ }
app/code/community/Magentokey/Keyword/Model/Mysql4/Word/Collection.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Joy <yanggaojiao@qq.com> (http://www.hifasion.org)
4
+ * @copyright Copyright &copy; 2011, Hifashion (http://www.magentokey.com, http://www.hifasion.org)
5
+ * @version 1.0.0
6
+ */
7
+ class Magentokey_Keyword_Model_Mysql4_Word_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
8
+ {
9
+ protected function _construct()
10
+ {
11
+ $this->_init('magentokey_keyword/word');
12
+ }
13
+ }
app/code/community/Magentokey/Keyword/Model/Word.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Joy <yanggaojiao@qq.com> (http://www.hifasion.org)
4
+ * @copyright Copyright &copy; 2011, Hifashion (http://www.magentokey.com, http://www.hifasion.org)
5
+ * @version 1.0.0
6
+ */
7
+ class Magentokey_Keyword_Model_Word extends Mage_Core_Model_Abstract
8
+ {
9
+ protected function _construct()
10
+ {
11
+ $this->_init('magentokey_keyword/word','word_id');
12
+ }
13
+ }
app/code/community/Magentokey/Keyword/controllers/Adminhtml/Keyword/IndexController.php ADDED
@@ -0,0 +1,181 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Joy <yanggaojiao@qq.com> (http://www.hifasion.org)
4
+ * @copyright Copyright &copy; 2011, Hifashion (http://www.magentokey.com, http://www.hifasion.org)
5
+ * @version 1.0.0
6
+ */
7
+ class Magentokey_Keyword_Adminhtml_Keyword_IndexController extends Mage_Adminhtml_Controller_Action
8
+ {
9
+ public function indexAction()
10
+ {
11
+ $this->_title($this->__('Magentokey Keyword Link'));
12
+ if ($this->getRequest()->getQuery('ajax')) {
13
+ $this->_forward('grid');
14
+ return;
15
+ }
16
+ $this->loadLayout();
17
+ $this->_setActiveMenu('magentokey_keyword');
18
+ $this->_addContent($this->getLayout()->createBlock('magentokey_keyword/adminhtml_keyword_list', 'keyword.list'));
19
+ $this->renderLayout();
20
+ }
21
+ public function wordAction()
22
+ {
23
+ $this->_title($this->__('Keyword from Search Engine'));
24
+ $this->loadLayout();
25
+ $this->_setActiveMenu('magentokey_keyword');
26
+ $this->_addContent($this->getLayout()->createBlock('magentokey_keyword/adminhtml_keyword_word', 'keyword.word'));
27
+ $this->renderLayout();
28
+ }
29
+ public function addAction()
30
+ {
31
+ $this->_forward('edit');
32
+ }
33
+ public function editAction()
34
+ {
35
+ if ($id = $this->getRequest()->getParam('id')) {
36
+ $this->_title($this->__('Edit Keyword Link'));
37
+ } else {
38
+ $this->_title($this->__('Add Keyword Link'));
39
+ }
40
+ $this->loadLayout();
41
+ $this->_setActiveMenu('magentokey_keyword');
42
+ $this->_addContent($this->getLayout()->createBlock('magentokey_keyword/adminhtml_keyword_new', 'keyword.new'));
43
+ $this->renderLayout();
44
+ }
45
+ public function massDeleteAction()
46
+ {
47
+ $ids= $this->getRequest()->getParam('massaction');
48
+ if (count($ids)) {
49
+ try {
50
+ $i = 0;
51
+ foreach ($ids as $id) {
52
+ if($id) {
53
+ $model = Mage::getModel('magentokey_keyword/keyword')
54
+ ->load($id);
55
+ if ($model->getId()) {
56
+ $model->delete();
57
+ }
58
+ $i++;
59
+ }
60
+ }
61
+ $this->_getSession()->addSuccess(
62
+ Mage::helper('magentokey_keyword')->__('Total of %d record(s) have been deleted.', $i)
63
+ );
64
+
65
+ } catch (Mage_Core_Exception $e) {
66
+ $this->_getSession()->addError($e->getLink());
67
+ } catch (Exception $e) {
68
+ $session->addException($e, Mage::helper('magentokey_keyword')->__('An error occurred when delete record(s).'));
69
+ }
70
+ }
71
+ $this->_redirect('*/*/index');
72
+ }
73
+ public function deleteWordAction()
74
+ {
75
+ $ids= $this->getRequest()->getParam('massaction');
76
+ if (count($ids)) {
77
+ try {
78
+ $i = 0;
79
+ foreach ($ids as $id) {
80
+ if($id) {
81
+ $model = Mage::getModel('magentokey_keyword/word')
82
+ ->load($id);
83
+ if ($model->getId()) {
84
+ $model->delete();
85
+ }
86
+ $i++;
87
+ }
88
+ }
89
+ $this->_getSession()->addSuccess(
90
+ Mage::helper('magentokey_keyword')->__('Total of %d record(s) have been deleted.', $i)
91
+ );
92
+
93
+ } catch (Mage_Core_Exception $e) {
94
+ $this->_getSession()->addError($e->getLink());
95
+ } catch (Exception $e) {
96
+ $session->addException($e, Mage::helper('magentokey_keyword')->__('An error occurred when delete record(s).'));
97
+ }
98
+ }
99
+ $this->_redirect('*/*/word');
100
+ }
101
+ public function gridAction()
102
+ {
103
+ $this->loadLayout();
104
+ $this->getResponse()->setBody($this->getLayout()->createBlock('magentokey_keyword/adminhtml_keyword_list_grid')->toHtml());
105
+ }
106
+
107
+ public function saveAction()
108
+ {
109
+
110
+ $request = $this->getRequest();
111
+ $id = (int)$request->getParam('link_id');
112
+ $code = $request->getParam('link_code');
113
+ $value = $request->getParam('link_value');
114
+ $storeId = $request->getParam('store_ids');
115
+ if ($code && $value) {
116
+
117
+ $linkDescription = trim($request->getParam('link_description'));
118
+ $linkStatus = $request->getParam('link_status') ? (int)$request->getParam('link_status') : 0;
119
+ $noFollow = $request->getParam('no_follow') ? (int)$request->getParam('no_follow') : 0;
120
+ $FirstMatchOnly = $request->getParam('first_match_only') ? (int)$request->getParam('first_match_only') : 0;
121
+ $newWindow = $request->getParam('new_window') ? (int)$request->getParam('new_window') : 0;
122
+ $ignoreCase = $request->getParam('ignore_case') ? (int)$request->getParam('ignore_case') : 0;
123
+ $isAfiliate = $request->getParam('is_afiliate') ? (int)$request->getParam('is_afiliate') : 0;
124
+ $forZhcn = $request->getParam('for_zhcn') ? (int)$request->getParam('for_zhcn') : 0;
125
+ $i = $j = 0;
126
+ $keywordModel = Mage::getModel('magentokey_keyword/keyword');
127
+ if ($id) {
128
+ $keywordModel = $keywordModel->load($id);
129
+ }
130
+ $keywordModel->setLinkCode($code)
131
+ ->setLinkValue($value)
132
+ ->setLinkDescription($linkDescription)
133
+ ->setLinkStatus($linkStatus)
134
+ ->setNoFollow($noFollow)
135
+ ->setFirstMatchOnly($FirstMatchOnly)
136
+ ->setNewWindow($newWindow)
137
+ ->setIgnoreCase($ignoreCase)
138
+ ->setIsAfiliate($isAfiliate)
139
+ ->setForZhcn($forZhcn)
140
+
141
+ ->setAddedAt(Mage::getSingleton('core/date')->gmtDate());
142
+ if (!$id) {
143
+ $keywordModel->setStoreId((int)$storeId);
144
+ }
145
+ try {
146
+ $keywordModel->save();
147
+ $i++;
148
+ } catch (Exception $e) {
149
+ $j++;
150
+ }
151
+
152
+ if ($i == 0) {
153
+ $this->_getSession()->addError(Mage::helper('magentokey_keyword')->__("Keyword link save failed."));
154
+ } elseif($j==0) {
155
+ $this->_getSession()->addSuccess(Mage::helper('magentokey_keyword')->__("Keyword link save successfully."));
156
+ } else {
157
+ $this->_getSession()->addSuccess(Mage::helper('')->__("%d keyword link(s) save successfully.",$i));
158
+ $this->_getSession()->addError(Mage::helper('')->__("%d keyword link(s) save failed.",$j));
159
+ }
160
+
161
+ } else {
162
+ $this->_getSession()->addError(Mage::helper('magentokey_keyword')->__("Keyword and Link cann't be null."));
163
+ }
164
+ if ($request->getParam('continue')) {
165
+ if (!$id) {
166
+ $this->_redirect('*/*/edit');
167
+ } else {
168
+ $this->_redirect('*/*/edit',array('id'=>$id));
169
+ }
170
+
171
+ } else {
172
+ $this->_redirect('*/*/index');
173
+ }
174
+ }
175
+ protected function _getWrite()
176
+ {
177
+ $resource = Mage::getSingleton('core/resource');
178
+ $writeConnection = $resource->getConnection('core_write');
179
+ return $writeConnection;
180
+ }
181
+ }
app/code/community/Magentokey/Keyword/controllers/IndexController.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Joy <yanggaojiao@qq.com> (http://www.hifasion.org)
4
+ * @copyright Copyright &copy; 2011, Hifashion (http://www.magentokey.com, http://www.hifasion.org)
5
+ * @version 1.0.0
6
+ */
7
+ class Magentokey_Keyword_IndexController extends Mage_Core_Controller_Front_Action
8
+ {
9
+ public function indexAction()
10
+ {
11
+ if ($this->getRequest()->getParam('ajax')) {
12
+ $url = $this->getRequest()->getParam('url');
13
+ if ($url) {
14
+ echo Mage::helper('magentokey_keyword')->searchword($url);
15
+ }
16
+ }
17
+
18
+ }
19
+ }
app/code/community/Magentokey/Keyword/etc/adminhtml.xml ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * @author Joy <yanggaojiao@qq.com> (http://www.hifasion.org)
5
+ * @copyright Copyright &copy; 2011, Hifashion (http://www.magentokey.com, http://www.hifasion.org)
6
+ * @version 1.0.0
7
+ */
8
+ -->
9
+ <config>
10
+ <menu>
11
+ <magentokey_keyword>
12
+ <title>KeywordLink</title>
13
+ <sort_order>62</sort_order>
14
+ <action>adminhtml/keyword_index/index</action>
15
+ </magentokey_keyword>
16
+ </menu>
17
+ <acl>
18
+ <resources>
19
+ <admin>
20
+ <children>
21
+ <magentokey_keyword translate="title" module="magentokey_keyword">
22
+ <title>Magentokey Keyword Link</title>
23
+ <sort_order>62</sort_order>
24
+ </magentokey_keyword>
25
+ </children>
26
+ </admin>
27
+ </resources>
28
+ </acl>
29
+ </config>
app/code/community/Magentokey/Keyword/etc/config.xml ADDED
@@ -0,0 +1,126 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * @author Joy <yanggaojiao@qq.com> (http://www.hifasion.org)
5
+ * @copyright Copyright &copy; 2011, Hifashion (http://www.magentokey.com, http://www.hifasion.org)
6
+ * @version 1.0.0
7
+ */
8
+ -->
9
+ <config>
10
+ <modules>
11
+ <Magentokey_Keyword>
12
+ <version>1.0.0</version>
13
+ </Magentokey_Keyword>
14
+ </modules>
15
+ <global>
16
+ <blocks>
17
+ <magentokey_keyword>
18
+ <class>Magentokey_Keyword_Block</class>
19
+ </magentokey_keyword>
20
+ </blocks>
21
+ <helpers>
22
+ <magentokey_keyword>
23
+ <class>Magentokey_Keyword_Helper</class>
24
+ </magentokey_keyword>
25
+ </helpers>
26
+ <models>
27
+ <magentokey_keyword>
28
+ <class>Magentokey_Keyword_Model</class>
29
+ <resourceModel>magentokey_keyword_mysql4</resourceModel>
30
+ </magentokey_keyword>
31
+ <magentokey_keyword_mysql4>
32
+ <class>Magentokey_Keyword_Model_Mysql4</class>
33
+ <entities>
34
+ <keyword>
35
+ <table>magentokey_keyword_link</table>
36
+ </keyword>
37
+ <word>
38
+ <table>magentokey_keyword</table>
39
+ </word>
40
+ </entities>
41
+ </magentokey_keyword_mysql4>
42
+ </models>
43
+ <resources>
44
+ <magentokey_keyword_setup>
45
+ <setup>
46
+ <module>Magentokey_Keyword</module>
47
+ </setup>
48
+ </magentokey_keyword_setup>
49
+ </resources>
50
+ </global>
51
+ <frontend>
52
+ <routers>
53
+ <magentokey_keyword module="Magentokey_Keyword">
54
+ <use>standard</use>
55
+ <args>
56
+ <module>Magentokey_Keyword</module>
57
+ <frontName>keyword</frontName>
58
+ </args>
59
+ </magentokey_keyword>
60
+ </routers>
61
+ <translate>
62
+ <modules>
63
+ <magentokey_keyword>
64
+ <files>
65
+ <default>Magentokey_Keyword.csv</default>
66
+ </files>
67
+ </magentokey_keyword>
68
+ </modules>
69
+ </translate>
70
+ <layout>
71
+ <updates>
72
+ <magentokey_keyword>
73
+ <file>magentokey_keyword.xml</file>
74
+ </magentokey_keyword>
75
+ </updates>
76
+ </layout>
77
+ </frontend>
78
+ <admin>
79
+ <routers>
80
+ <adminhtml>
81
+ <args>
82
+ <modules>
83
+ <Magentokey_Keyword before="Mage_Adminhtml">Magentokey_Keyword_Adminhtml</Magentokey_Keyword>
84
+ </modules>
85
+ </args>
86
+ </adminhtml>
87
+ </routers>
88
+ </admin>
89
+ <adminhtml>
90
+ <layout>
91
+ <updates>
92
+ <magentokey_keyword>
93
+ <file>magentokey_keyword.xml</file>
94
+ </magentokey_keyword>
95
+ </updates>
96
+ </layout>
97
+ <translate>
98
+ <modules>
99
+ <magentokey_keyword>
100
+ <files>
101
+ <default>Magentokey_Keyword.csv</default>
102
+ </files>
103
+ </magentokey_keyword>
104
+ </modules>
105
+ </translate>
106
+ <acl>
107
+ <resources>
108
+ <admin>
109
+ <children>
110
+ <system>
111
+ <children>
112
+ <config>
113
+ <children>
114
+ <magentokey_keyword>
115
+ <title>Magentokey Keyword Link</title>
116
+ </magentokey_keyword>
117
+ </children>
118
+ </config>
119
+ </children>
120
+ </system>
121
+ </children>
122
+ </admin>
123
+ </resources>
124
+ </acl>
125
+ </adminhtml>
126
+ </config>
app/code/community/Magentokey/Keyword/etc/system.xml ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * @author Joy <yanggaojiao@qq.com> (http://www.hifasion.org)
5
+ * @copyright Copyright &copy; 2011, Hifashion (http://www.magentokey.com, http://www.hifasion.org)
6
+ * @version 1.0.0
7
+ */
8
+ -->
9
+ <config>
10
+ <sections>
11
+ <magentokey_keyword translate="label" module="magentokey_keyword">
12
+ <label>Magentokey Keyword Link</label>
13
+ <tab>catalog</tab>
14
+ <frontend_type>text</frontend_type>
15
+ <sort_order>1</sort_order>
16
+ <show_in_default>1</show_in_default>
17
+ <show_in_website>1</show_in_website>
18
+ <show_in_store>1</show_in_store>
19
+ <groups>
20
+ <options translate="label">
21
+ <label>Magentokey Keyword Link Options</label>
22
+ <frontend_type>text</frontend_type>
23
+ <sort_order>1</sort_order>
24
+ <show_in_default>1</show_in_default>
25
+ <show_in_website>1</show_in_website>
26
+ <show_in_store>1</show_in_store>
27
+ <fields>
28
+ <enable translate="label">
29
+ <label>Enable Magentokey Keyword Link</label>
30
+ <frontend_type>select</frontend_type>
31
+ <source_model>adminhtml/system_config_source_yesno</source_model>
32
+ <sort_order>1</sort_order>
33
+ <show_in_default>1</show_in_default>
34
+ <show_in_website>1</show_in_website>
35
+ <show_in_store>1</show_in_store>
36
+ </enable>
37
+ <match_num_from translate="label">
38
+ <label>(Number of Keyword matched)From</label>
39
+ <frontend_type>text</frontend_type>
40
+ <sort_order>10</sort_order>
41
+ <show_in_default>1</show_in_default>
42
+ <show_in_website>1</show_in_website>
43
+ <show_in_store>1</show_in_store>
44
+ </match_num_from>
45
+ <match_num_to translate="label">
46
+ <label>(Number of Keyword matched)To</label>
47
+ <frontend_type>text</frontend_type>
48
+ <sort_order>20</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
+ </match_num_to>
53
+ <link_itself translate="label">
54
+ <label>Keywords does not link itself</label>
55
+ <frontend_type>select</frontend_type>
56
+ <source_model>adminhtml/system_config_source_yesno</source_model>
57
+ <sort_order>30</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
+ </link_itself>
62
+
63
+ <!--<tag2keyword_enable translate="label">
64
+ <label>Auto Tag to keyword</label>
65
+ <frontend_type>select</frontend_type>
66
+ <source_model>adminhtml/system_config_source_yesno</source_model>
67
+ <sort_order>30</sort_order>
68
+ <show_in_default>1</show_in_default>
69
+ <show_in_website>1</show_in_website>
70
+ <show_in_store>1</show_in_store>
71
+ </tag2keyword_enable>-->
72
+ </fields>
73
+ </options>
74
+ </groups>
75
+ </magentokey_keyword>
76
+ </sections>
77
+ </config>
app/code/community/Magentokey/Keyword/sql/magentokey_keyword_setup/mysql4-install-1.0.0.php ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Joy <yanggaojiao@qq.com> (http://www.hifasion.org)
4
+ * @copyright Copyright &copy; 2011, Hifashion (http://www.magentokey.com, http://www.hifasion.org)
5
+ * @version 1.0.0
6
+ */
7
+ $installer = $this;
8
+ $installer->startSetup();
9
+ $installer->run("
10
+ DROP TABLE IF EXISTS `{$installer->getTable('magentokey_keyword_link')}`;
11
+ CREATE TABLE `{$installer->getTable('magentokey_keyword_link')}` (
12
+ `link_id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Link Id',
13
+ `link_code` varchar(200) NOT NULL COMMENT 'Link Code',
14
+ `link_value` varchar(255) NOT NULL COMMENT 'Link Value',
15
+ `link_description` varchar(255) DEFAULT NULL COMMENT 'Link Description',
16
+ `link_status` smallint(6) DEFAULT 0 COMMENT 'Link Status',
17
+ `no_follow` smallint(6) DEFAULT 0 COMMENT 'No Follow',
18
+ `first_match_only` smallint(6) DEFAULT 0 COMMENT 'First Match Only',
19
+ `new_window` smallint(6) DEFAULT 0 COMMENT 'New Window',
20
+ `ignore_case` smallint(6) DEFAULT 0 COMMENT 'Ignore Case',
21
+ `is_afiliate` smallint(6) DEFAULT 0 COMMENT 'Is Afiliate',
22
+ `for_zhcn` smallint(6) DEFAULT 0 COMMENT 'For zh_CN',
23
+ `store_id` smallint(5) unsigned DEFAULT '0' COMMENT 'Store Id',
24
+ `added_at` datetime DEFAULT NULL COMMENT 'Added At',
25
+ PRIMARY KEY (`link_id`),
26
+ UNIQUE KEY `IDX_KEYWORD_LINK_CODE` (`link_code`,`store_id`) USING BTREE,
27
+ KEY `IDX_KEYWORD_LINK_ID` (`link_id`),
28
+ KEY `IDX_KEYWORD_LINK_VALUE` (`link_value`),
29
+ KEY `IDX_KEYWORD_LINK_STORE` (`store_id`)
30
+ ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COMMENT='Magentokey Keyword Link';
31
+ DROP TABLE IF EXISTS `{$installer->getTable('magentokey_keyword')}`;
32
+ CREATE TABLE `{$installer->getTable('magentokey_keyword')}` (
33
+ `word_id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Word Id',
34
+ `word` varchar(255) NOT NULL COMMENT 'Word',
35
+ `store_id` smallint(5) unsigned DEFAULT '0' COMMENT 'Store Id',
36
+ `added_at` datetime DEFAULT NULL COMMENT 'Added At',
37
+ PRIMARY KEY (`word_id`),
38
+ KEY `IDX_KEYWORD_WORD` (`word`),
39
+ KEY `IDX_KEYWORD_WORD_STORE` (`store_id`)
40
+ ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COMMENT='Magentokey Keyword';
41
+ ");
42
+ $installer->endSetup();
app/design/adminhtml/default/default/template/magentokey/keyword/list.phtml ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div class="content-header">
2
+ <table cellspacing="0">
3
+ <tr>
4
+ <td style="width:50%;"><h3 class="icon-head head-newsletter-list"><?php echo $this->getHeaderText() ?></h3></td>
5
+ <td class="form-buttons">
6
+ <button class="scalable" onclick="window.location='<?php echo $this->getWordUrl() ?>'"><span><?php echo Mage::helper('magentokey_keyword')->__('Keyword from Search Engine'); ?></span></button>
7
+ <button class="scalable add" onclick="window.location='<?php echo $this->getNewUrl() ?>'"><span><?php echo Mage::helper('magentokey_keyword')->__('New Keyword Link'); ?></span></button>
8
+ </td>
9
+ </tr>
10
+
11
+ </table>
12
+ </div>
13
+ <div>
14
+ <?php echo $this->getChildHtml('grid') ?>
15
+ </div>
app/design/adminhtml/default/default/template/magentokey/keyword/new.phtml ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div class="content-header">
2
+ <h3 class="icon-head head-message-list"><?php echo $this->getHeaderText() ?></h3>
3
+ <p class="content-buttons form-buttons">
4
+ <?php echo $this->getBackButtonHtml(); ?>
5
+ <?php echo $this->getResetButtonHtml(); ?>
6
+ <?php echo $this->getSaveButtonHtml(); ?>
7
+ <?php echo $this->getContinueButtonHtml(); ?>
8
+ </p>
9
+ </div>
10
+ <form action="<?php echo $this->getSaveUrl(); ?>" method="post" id="magentokey_keyword_form">
11
+ <div class="no-display">
12
+ <input type="hidden" id="continue" name="continue" value="" />
13
+ </div>
14
+ <?php echo $this->getForm(); ?>
15
+ </form>
16
+ <script type="text/javascript">
17
+ //<![CDATA[
18
+ var keywordForm = new varienForm('magentokey_keyword_form');
19
+ var keywordControl = {
20
+ save: function() {
21
+ keywordForm.submit();
22
+ return false;
23
+ },
24
+ continue: function() {
25
+ $('continue').writeAttribute('value',1);
26
+ keywordForm.submit();
27
+ return false;
28
+ }
29
+ }
30
+ //]]>
31
+ </script>
app/design/adminhtml/default/default/template/magentokey/keyword/word.phtml ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div class="content-header">
2
+ <table cellspacing="0">
3
+ <tr>
4
+ <td style="width:50%;"><h3 class="icon-head"><?php echo $this->getHeaderText() ?></h3></td>
5
+ <td class="form-buttons">
6
+ <button class="scalable back" onclick="window.location='<?php echo $this->getBackUrl() ?>'"><span><?php echo Mage::helper('magentokey_keyword')->__('Back'); ?></span></button>
7
+
8
+ </td>
9
+ </tr>
10
+
11
+ </table>
12
+ </div>
13
+ <div>
14
+ <?php echo $this->getChildHtml('grid') ?>
15
+ </div>
app/design/frontend/default/default/layout/magentokey_keyword.xml ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <layout>
3
+ <default>
4
+ <reference name="footer">
5
+ <block type="magentokey_keyword/js" name="magentokey_keyword_js" as="magentokey_keyword_js" template="magentokey/keyword/js.phtml" />
6
+ </reference>
7
+ </default>
8
+ </layout>
app/design/frontend/default/default/template/magentokey/keyword/js.phtml ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <style type="text/css">
2
+ span.m_highlight { color:#FF2900 !important; }
3
+ </style>
4
+ <script type="text/javascript">
5
+ //<![CDATA[
6
+ document.observe("dom:loaded", function() {
7
+ var m_pre_url = document.referrer;
8
+ if ((m_pre_url.indexOf('?')!=-1 || m_pre_url.indexOf('#')!=-1) && m_pre_url && m_pre_url.match(/google|baidu|sougou|youdao|bing|yahoo|soso/i)) {
9
+ var m_url = '<?php echo $this->getAjaxUrl(); ?>';
10
+ new Ajax.Request(m_url, {
11
+ method: 'post',
12
+ parameters: {"url":m_pre_url},
13
+ onSuccess: function(transport) {
14
+ var m_q = transport.responseText;
15
+ if (m_q) {
16
+ var words = m_q.split(' ');
17
+ for (w=0;w<words.length;w++) {
18
+ $$('div.col-main').each(function(s){
19
+ MagentokeyHighlight(s,words[w]);
20
+ })
21
+ }
22
+ }
23
+ }
24
+ })
25
+ }
26
+ })
27
+ function MagentokeyHighlight(node,word) {
28
+ // Iterate into this nodes childNodes
29
+ if (node.hasChildNodes) {
30
+ var hi_cn;
31
+ for (hi_cn=0;hi_cn<node.childNodes.length;hi_cn++) {
32
+ MagentokeyHighlight(node.childNodes[hi_cn],word);
33
+ }
34
+ }
35
+ // And do this node itself
36
+ if (node.nodeType == 3) { // text node
37
+ tempNodeVal = node.nodeValue.toLowerCase();
38
+ tempWordVal = word.toLowerCase();
39
+ if (tempNodeVal.indexOf(tempWordVal) != -1) {
40
+ pn = node.parentNode;
41
+ if (pn.className != "m_highlight") {
42
+ // word has not already been highlighted!
43
+ nv = node.nodeValue;
44
+ ni = tempNodeVal.indexOf(tempWordVal);
45
+ // Create a load of replacement nodes
46
+ before = document.createTextNode(nv.substr(0,ni));
47
+ docWordVal = nv.substr(ni,word.length);
48
+ after = document.createTextNode(nv.substr(ni+word.length));
49
+ hiwordtext = document.createTextNode(docWordVal);
50
+ hiword = document.createElement("span");
51
+ hiword.className = "m_highlight";
52
+ hiword.appendChild(hiwordtext);
53
+ pn.insertBefore(before,node);
54
+ pn.insertBefore(hiword,node);
55
+ pn.insertBefore(after,node);
56
+ pn.removeChild(node);
57
+ }
58
+ }
59
+ }
60
+ }
61
+ //]]>
62
+ </script>
app/etc/modules/Magentokey_Keyword.xml ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Magentokey_Keyword>
5
+ <active>true</active>
6
+ <codePool>community</codePool>
7
+ <depends>
8
+ <Mage_Core />
9
+ </depends>
10
+ </Magentokey_Keyword>
11
+ </modules>
12
+ </config>
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>magento-keywordlink</name>
4
+ <version>1.0.0</version>
5
+ <stability>stable</stability>
6
+ <license>GPL</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Define keyword/link pairs within your Magento . The keywords are automatically linked in your pages. </summary>
10
+ <description>A plugin that allows you to define keyword/link pairs within your Magento store. The keywords are automatically linked in your product page,Homepage,CMS page. This is usefull for improving the internal cross referencing pages inside your site or to automatically link to external partners (SEO). </description>
11
+ <notes>A plugin that allows you to define keyword/link pairs within your Magento store. The keywords are automatically linked in your product page,Homepage,CMS page. This is usefull for improving the internal cross referencing pages inside your site or to automatically link to external partners (SEO). </notes>
12
+ <authors><author><name>iifire</name><user>yanggaojiao</user><email>yanggaojiao@qq.com</email></author></authors>
13
+ <date>2012-08-22</date>
14
+ <time>09:44:46</time>
15
+ <contents><target name="magecommunity"><dir name="Magentokey"><dir name="Keyword"><dir name="Block"><dir name="Adminhtml"><dir name="Keyword"><dir name="List"><file name="Grid.php" hash="7ce140889caeb534278ae4639c0ac136"/></dir><file name="List.php" hash="3d24669437afe861a4c4b1fac2f08809"/><dir name="New"><file name="Form.php" hash="6ae210db8a52ddb1011e6d330a473689"/></dir><file name="New.php" hash="b3946ffa0e56b0319778d30d5b1751c7"/><dir name="Word"><file name="Grid.php" hash="069dc9177a8ef9e69b9074197018bd81"/></dir><file name="Word.php" hash="1d1d30a63b89861e4129f9d8044a4467"/></dir></dir><file name="Js.php" hash="b112e5beed533ffe792fa5a9c1342f0f"/></dir><dir name="Helper"><file name="Data.php" hash="4eb875c93079a80f4d9285b452b499c7"/></dir><dir name="Model"><file name="Keyword.php" hash="a914a391b7ecb79435d1d0cff4126689"/><dir name="Mysql4"><dir name="Keyword"><file name="Collection.php" hash="9467aab038345c0a8eb82a9845e0f596"/></dir><file name="Keyword.php" hash="4ab6ccb5b9880fa82f5ba6f7ecea5e2d"/><dir name="Word"><file name="Collection.php" hash="6e7cf4ffe04f07cd8fa5ce9d80bbe796"/></dir><file name="Word.php" hash="4090124941586d0dcb6887ae8bb0f842"/></dir><file name="Word.php" hash="52df8e400f8590e86ff7c11924d4bb26"/></dir><dir name="controllers"><dir name="Adminhtml"><dir name="Keyword"><file name="IndexController.php" hash="916a35d5855fc15489f71998e2f43d40"/></dir></dir><file name="IndexController.php" hash="95c5b06c54d3aaa1afaa347dfa74ce81"/></dir><dir name="etc"><file name="adminhtml.xml" hash="14a01b266059a83663af7d382dfd873e"/><file name="config.xml" hash="25c178dfa9ea82b658ab994d20675815"/><file name="system.xml" hash="bbdef559e31c00f195e8d13a2119aa07"/></dir><dir name="sql"><dir name="magentokey_keyword_setup"><file name="mysql4-install-1.0.0.php" hash="479e1973fc93e6615716454a953c5e20"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Magentokey_Keyword.xml" hash="94eb4dfceccfa2a53d9c2b7d598e2e27"/></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="template"><dir name="magentokey"><dir name="keyword"><file name="list.phtml" hash="30e45c51ee8cf9ae5cb50e7a2764bc3a"/><file name="new.phtml" hash="86016071e8b3b913275a30cadb2ee16b"/><file name="word.phtml" hash="7b2129230ff5c4e98d6065a36b16fec0"/></dir></dir></dir></dir></dir></dir><dir name="frontend"><dir name="default"><dir name="default"><dir name="template"><dir name="magentokey"><dir name="keyword"><file name="js.phtml" hash="1b981abb68b888afb80545bba9602c2c"/></dir></dir></dir><dir name="layout"><file name="magentokey_keyword.xml" hash="97dbe400f7c7df3afd49eec061bc0cc3"/></dir></dir></dir></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
18
+ </package>