archive functionality for magento aw_blog extension - magento-1.7

I have been working with a client who wanted a blog in the magento website. After installing the AW blog extension i realized that it doesn't have archive functionality, and i didn't find any solution in the web.
After few days of work, I have finally found a solution for this task. I didn't know where to post it, and I thought that this is the best place to share it.
I know that people usually don't post answers here, but I have to share, because out there, somebody is having difficult time, or might have.

I will presume that you already installed the AW Blog extension to your magento project. blog extension page
1) first of all we need a placeholder for future datepicker. I choose the sidebar of AW_blog extension: app\design\frontend\YOUR_THEME\default\template\aw_blog\menu.phtml
I added following html markup almost to the end:
<div class="block-content">
<div class="menu-recent">
<h5 class="uppercase"><?php echo Mage::helper('blog')->__('Archives'); ?></h5>
<div id="datepicker"></div>
</div>
</div>
2) After this i added jquery ui datepicker into project. we will need it for date selection. jquery ui page. Here I need make some note. I only copied the jquery-ui.js, jquery-ui.css, images folder with theme icons. I did this because i didn't need anything else. you can download everything if you want, but the key files are jquery-ui.js, jquery-ui.css, images folder.
a) copy jquery-ui.js into skin\js directory
b) copy jquery-ui.css and images folder into skin\frontend\YOUR_THEME\default\css directory
3) Add following code to app\design\frontend\default\default\layout\page.xml
<default translate="label" module="page">
<label>All Pages</label>
<block type="page/html" name="root" output="toHtml" template="page/3columns.phtml">
<block type="page/html_head" name="head" as="head">
....
<action method="addJs"><script>jquery-ui.js</script></action>
...
<action method="addCss"><stylesheet>css/jquery-ui.css</stylesheet></action>
4) add following code to app\design\frontend\YOUR_THEME\default\template\page\head.phtml
this is just simple work with datepicker plugin
jQuery(function(){
jQuery( "#datepicker" ).datepicker({
dateFormat:"yy-mm-dd",
onSelect: function(dateText) {
window.location = '<?php echo Mage::getBaseUrl();?>news/?date='+dateText;//refreshes screen
}
});
});
all these four 4 steps are for frontend stuff. now we will go to the backend programming
1) open app\code\community\AW\Blog\Block\blog.php and replace getPosts() function with following code
public function getPosts()
{
$collection = parent::_prepareCollection();
$tag = $this->getRequest()->getParam('tag');
$date = $this->getRequest()->getParam('date');//gets $_GET[date] parameter
if ($tag) {
$collection->addTagFilter(urldecode($tag));
}
else if ($date) { // checks if $date parameter exists
$collection->addDateFilter(urldecode($date));
}
parent::_processCollection($collection);
return $collection;
}
2) open app\code\community\AW\Blog\Model\Mysql4\Blog\Collection.php and add following function
public function addDateFilter($date) {
if ($date = trim($date)) {
$whereString = sprintf("main_table.created_time >= %s", $this->getConnection()->quote($date));
$this->getSelect()->where($whereString);
}
return $this;
}
This is it guys. If you need any help, just let me know. Thanks for your time.

for month and year list archive
public function addDateFilter($date) {
if ($date = trim($date)) {
$whereString = sprintf(
"main_table.created_time = %s OR main_table.created_time LIKE %s OR main_table.created_time LIKE %s ",
$this->getConnection()->quote($date), $this->getConnection()->quote($date . '-%'),
$this->getConnection()->quote('%-' . $date),$this->getConnection()->quote('%-' . $date . '-%')
);
$this->getSelect()->where($whereString);
}
return $this;
}
Examples:
foo.com/index.php/news/?date=2014 or bar.com/index.php/news/?date=2014-02

Related

Magento2 custom price render on product page

How to format the product view page price differently from the one from category page ( and possible others ) ?
If I change in my child theme the:
app/design/frontend/VENDOR/my_theme/Magento_Catalog/templates/product/price/final_price.phtml
The price is being changed on both pages (category and product);
I have tried several approaches but it seems that this price rendering mechanism is complicated as hell in Magento2.
Thanks!
<?php
try {
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$request = $objectManager->get(‘Magento\Framework\App\Action\Context’)->getRequest();
$currentPageXML = $request->getFullActionName();
echo $currentPageXML; //catalog_product_view is product detail page controller action
} catch (Exception $e) {}
?>
The above code will help you get the current area of the environment being accessed, and then you can apply a logic
if ($currentPageXML=="catalog_product_view") {
// render my custom need
} else {
// keep the actual code intact.
}
You are facing a problem because same phtml file is being used by both the catalog and product page, so a change in this file will be reflected everywhere.
I hope this will help you.

Using search feature in Ionic framework

I am a UI person and very new to ionic framework.. I wanted to add search feature in my android app built using Ionic framework. After a research i found that I will need to use this plugin https://github.com/djett41/ionic-filter-bar. but there is no detail documentation available. Can anyone please guide how to use this plugin working. I have made all setup but stuck with actual code.
First of all you must install the plugin. You can use bower for that:
bower install ionic-filter-bar --save
and it will copy all the javascript and css needed in the lib folder inside www.
Then you must add the references to the css to your index.html:
<link href="lib/ionic-filter-bar/dist/ionic.filter.bar.css" rel="stylesheet">
same thing for the javascript:
<script src="lib/ionic-filter-bar/dist/ionic.filter.bar.js"></script>
You have to inject the module jett.ionic.filter.bar you your main module:
var app = angular.module('app', [
'ionic',
'jett.ionic.filter.bar'
]);
and you must reference the service $ionicFilterBar in your controller:
angular.module('app')
.controller('home', function($scope, $ionicFilterBar){
});
Now you can start using it.
In my sample I want to trigger the search-box when the user clicks/taps on a icon in the header. I would add this HTML to the view:
<ion-nav-buttons side="secondary">
<button class="button button-icon icon ion-ios-search-strong" ng-click="showFilterBar()">
</button>
</ion-nav-buttons>
The action trigger an event in my controller showFilterBar:
$scope.showFilterBar = function () {
var filterBarInstance = $ionicFilterBar.show({
cancelText: "<i class='ion-ios-close-outline'></i>",
items: $scope.places,
update: function (filteredItems, filterText) {
$scope.places = filteredItems;
}
});
};
which creates the $ionicFilterBar and shows it.
As you can see here I am using an array of objects $scope.places
$scope.places = [{name:'New York'}, {name: 'London'}, {name: 'Milan'}, {name:'Paris'}];
which I have linked to the items member of my $ionicFilterBar. The update method will give me in filteredItems the items (places) filtered.
You can play with this plunker.
Another option is to use the plugin to actually fetch some data remotely through $http.
If we want to achieve this we can use the update function again.
Now we don't need to bind the items to our array of objects cause we won't need the filtered elements.
We will use the filterText to perform some action:
$scope.showFilterBar = function () {
var filterBarInstance = $ionicFilterBar.show({
cancelText: "<i class='ion-ios-close-outline'></i>",
// items: $scope.places,
update: function (filteredItems, filterText) {
if (filterText) {
console.log(filterText);
$scope.fetchPlaces(filterText);
}
}
});
};
We will call another function which will, maybe, call $http and return some data which we can bind to our array of objects:
$scope.fetchPlaces = function(searchText)
{
$scope.places = <result of $http call>;
}
Another plunker here.
PS:
If you want to configure it using some sort of customization you must do it in your configuration using the provider $ionicFilterBarConfigProvider:
angular.module('app')
.config(function($ionicFilterBarConfigProvider){
$ionicFilterBarConfigProvider.clear('ion-ios-close-empty');
})
PPS:
In my plunker I've included the css and the script directly copying it from the source.
UPDATE:
Someone asked not to replace the list with the updated one.
My cheap and dirty solution is to check if the filterText contains some values. If it's empty (no searches) we go throught each element an set a property found = false otherwise we compare the places array we the filteredItems array.
Matching elements will be marked as found.
function allNotFound(filteredItems) {
angular.forEach($scope.places, function(item){
item.found = false;
});
}
function matchingItems(filteredItems) {
angular.forEach($scope.places, function(item){
var found = $filter('filter')(filteredItems, {name: item.name});
if (found && found.length > 0) {
console.log('found', item.name);
item.found = true;
} else {
item.found = false;
console.log('not found', item.name);
}
});
and now we can integrate the filter bar this way:
$scope.showFilterBar = function () {
var filterBarInstance = $ionicFilterBar.show({
cancelText: "<i class='ion-ios-close-outline'></i>",
items: $scope.places,
update: function (filteredItems, filterText) {
if (!filterText) {
allNotFound();
} else {
matchingItems(filteredItems);
}
}
});
};
We can use the found attribute of the object to change the style of the element.
As always, a Plunker to show how it works.
Ionic uses Angular, and Angular include an atributte filter very useful. Look this: https://docs.angularjs.org/api/ng/filter/filter and the example there. Regards

How can I render preview of FE plugin diplayed in Page module

I have developed TYPO3 (6.2) extensions with some FE plugins.
I need to change informations about plugin, which is displayed in the backend on page view.
Now only Title and name of plugin is displayed ...
I have used flexforms for configure the plugin and I would like to show some of configuration on the plugin "placeholder" in the backend.
I remember, I read some documentation how to do it a few years ago, but I can't find it anymore...
Does anyone know the right way to do it?
If I understood well you are asking for ContentElement preview. You need to use cms/layout/class.tx_cms_layout.php hook for this, here's quite nice gist
just two additions:
don't use t3lib_extMgm class it's removed since 7.x you can register this hook just with:
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['tt_content_drawItem'][$_EXTKEY]
= 'EXT:your_ext/Classes/Hooks/PageLayoutView.php:\Vendor\YourExt\Hooks\PageLayoutView';
Depending on how did you register the plugin (didn't mention) you can also need to check the $row['list_type'] as your $row['CType'] may be just generic list.
Sample class with value from FlexForm field
<?php
namespace Vendor\YourExt\Hooks;
class PageLayoutView implements \TYPO3\CMS\Backend\View\PageLayoutViewDrawItemHookInterface {
public function preProcess(\TYPO3\CMS\Backend\View\PageLayoutView &$parentObject, &$drawItem, &$headerContent, &$itemContent, array &$row) {
if ($row['CType'] == 'list' && $row['list_type'] == 'yourext_yourplugin') {
$drawItem = false;
$linkStart = '<a href="#" onclick="window.location.href=\'../../../alt_doc.php?returnUrl=%2Ftypo3%2Fsysext%2Fcms%2Flayout%2Fdb_layout.php%3Fid%3D' . $row['pid'] . '&edit[tt_content][' . $row['uid'] . ']=edit\'; return false;" title="Edit">';
$linkEnd = '</a>';
$headerContent =
$linkStart .
"<strong>Selected slides</strong>" .
$linkEnd;
$ffXml = \TYPO3\CMS\Core\Utility\GeneralUtility::xml2array($row['pi_flexform']);
$itemContent =
$linkStart .
$ffXml['data']['sDEF']['lDEF']['settings.myFlexField']['vDEF'] .
$linkEnd;
}
}
}

show image on client before upload on server in gwt

I would like to show an image and its dimensions on the client before uploading it to the server. Whenever I try to create an Image widget of gwt ext, it doesn't accept a local file (on the file system). It only accepts http requests. I also tried String img = GWT.getHostPageBaseURL() + "image_name" and the replace function but with same result. Finally I moved to ImagePreloader but its also needs a URL.
ImagePreloader.load("URL of image", new ImageLoadHandler()
{
public void imageLoaded(ImageLoadEvent event)
{
if (event.isLoadFailed())
Window.alert("Image " + event.getImageUrl() + "failed to load.");
else
Window.alert("Image dimensions: " + event.getDimensions().getWidth() + " x " + event.getDimensions().getHeight());
}
});
Can someone suggest a solution that doesn't include uploading the image first?
Have a look at this related question and answer:
Preview an image before it is uploaded
You can include it using JSNI. I'm now aware of a solution within GWT.
Just found gwtupload which claims to be able to preview images before uploading them.
Please take a look at the sample JS code below:
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('#blah').attr('src', e.target.result);
}
reader.readAsDataURL(input.files[0]);
}
}
$("#imgInp").change(function(){
readURL(this);
});
and the associated HTML:
<form id="form1" runat="server">
<input type='file' id="imgInp" />
<img id="blah" src="#" alt="your image" />
</form>

Writing script src dynamically via wicket

I want my page to load javascript dynamically to my body:
<script type= "text/javascript" src="this path should be decided from wicket dynamically"/>
I am using wicket version 1.4 therefore JavaScriptResourceReference does not exist in my version (for my inspection it wasn't ' )
how can I solve this ?
thanks in advance :).
I specify my comment into an answer.
You can use this code snippet:
WebMarkupContainer scriptContainer = new WebMarkupContainer("scriptContainer ");
scriptContainer .add(new AttributeAppender("type", Model.of("text/javascript")));
scriptContainer .add(
new AttributeAppender("src", urlFor(
new JavaScriptResourceReference(
YourClass.class, "JavaScriptFile.js"), null).toString()));
add(scriptContainer );
and the corresponding html:
<script wicket:id="scriptContainer "></script>
Just change the string JavaScriptFile.js to load any other Javascript file.
JavascriptPackageResource.getHeaderContributor() does exactly what you need.
You need nothing in your markup, just add the HeaderContributor it returns to your page.
Update: For Wicket 1.5 see the migration guide, but it goes like this:
public class MyPage extends WebPage {
public MyPage() {
}
public void renderHead(IHeaderResponse response) {
response.renderJavaScriptReference(new PackageResourceReference(YuiLib.class,
"yahoo-dom-event/yahoo-dom-event.js"));
response.renderCSSReference(new PackageResourceReference(AbstractCalendar.class,
"assets/skins/sam/calendar.css"));
}
}
If you want to put your <script> element in the body, you can simply declare it as a WebMarkupContainer and add an AttributeModifier to set the src attribute. Although in that case wicket won't generate the relative URLs for you, you have to do it yourself.
I'm not sure I understood completely.
If you are trying to create and append a script to the body after the page is loaded you should do it this way:
<script type="text/javascript">
function load_js() {
var element = document.createElement("script");
element.src = "scripts/YOUR_SCRIPT_SRC.js"; // <---- HERE <-----
document.body.appendChild(element);
}
// Wait for the page to be loaded
if(window.addEventListener)
window.addEventListener("load",load_js,false);
else if(window.attachEvent)
window.attachEvent("onload",load_js);
else
window.onload = load_js;
</script>
What I did here is create a new script element, and then apply to it its source.
That way you can control dynamicaly the src. After that I append it to the body.
The last part is there so the new element is applied only after the page is loaded.