Preksha Patel's blog

Preksha Patel's picture

How to make Panels Custom Layout

As we know, Panels3 module provides different layouts by default. But in some case, if it does not satisfy with our requirement custom layout creation of panel is required.

Before start, Install and enable panels3 module.

By default, Layout files are located under directory plugins/layouts i.e. sites/all/modules/panels/plugins/layouts. Copy one layout folder lets say "twocol" in your themes folder at path sites/all/themes/yourtheme/plugins/layouts/twocol. Rename twocol folder name with your_layout name.

The layout contains four files:

twocol.png - a screenshot of the layout.

twocol.css - a stylesheet for the layout.

twocol.inc - contains only an implementation of hook_panels_layouts().

panels-twocol.tpl.php - the template file for the layout.

 

Now rename all files with your_layout name, your files will be your_layout.png, your_layout.css, your_layout.inc, your_layout.tpl.php.

Now modify these files according to your requirement. The your_layout.inc file contains the plugin definition as follow:

$plugin = array( 'title' => t('Two column'), // Title of the layout (Your Layout) 'category' => t('Your Category'), // Category under which it should be appear. 'icon' => 'twocol.png', // Screenshot of the layout (your_layout.png) 'theme' => 'panels_twocol', // template file name (your_layout.tpl.php) 'css' => 'twocol.css', (your_layout.css) 'regions' => array( // Add regions as per your requirement 'left' => t('Left side'), 'right' => t('Right side') ), );

Modify your_layout.inc as shown above. Same way modify rest of the files.

Enable your custom layout in your theme, add the following lines in your custom theme's .info file:

; Panels settings plugins[panels][layouts] = layouts

Now clear cache and try to change the layout of your any panel page, in dropdown you will see one additionally category "Your Category", select it and you will see your_layout, select it. Under contents add the content in regions as per your requirement and you are done.

Preksha Patel's picture

How to create View based Resource creating Services display in a View

Services Views module is very easiest and effective way to make web service in drupal. It creates view based resource to display service output in a view. It executes any view via calling the view resource created by view's service.

Create web service using views by following steps:

1. Download and install Views module (7.x-3.x or later). 

2. Download and install Services module (7.x-3.x or later), enable services and rest_server module.

3. Download and install CTools module.

4. Download and install Services Views module.

5. Under admin -> Structure -> Services, Create Endpoint, enter Endpoint name, select server as REST server, enter Endpoint path and save it.

6. Now edit the Endpoint and under Server tab, select Reponse Formatter and Request Parsing.

7. Create a view:

   - Enter view name lets say it "Services", select show "Content" and type of "your content type" for which content should be displyed, select sorting crieteria as per your requirement.

   - Create a page, enter the path let's say "services_content" that will be your resource under your Endpoint. Now select fileds, filters as per your requirement. 

8. Under admin -> Structure -> Services, Edit your Endpoint and enable the resource created in views.

   Now, you can access resource like:

     http://yoursitename.com/yourEndPointPath/services_content - Here services_content is your resource name i.e. path given in views.

9. You can also create the exposed filters and pass them in resource as a query string. For example, your exposed filter is tag, then you can access the resource like:

   http://yoursitename.com/yourEndPointPath/services_content?tag=5

Cheers!!!

Preksha Patel's picture

How to make TinyMCE WYSIWYG to work with GESHI Filter

GeShi Filter provides a filter for source code syntax highlighting for various languages in any posts, for example in Blog Post.

I got TinyMCE WYSIWYG to work with GESHI filter using the following steps:

1. Download and install WYSIWYG module.

2. Download TinyMCE into sites/all/libraries.

3. Download and install WYSIWYG Filter module.

4. Created a new Text Format with the name "WYSIWYG Filter".

    Enabled the following under Enabled Filters and put them in the filter processing order as listed below:

  •         WYSIWYG Filter
  •         Encode email addresses: Javascript-wrapped HTML entities
  •         Encode email addresses: HTML entities
  •         Convert URLs into links
  •         Correct faulty and chopped off HTML
  •         GeSHi filter
  •         Convert line breaks into HTML

    For Filter Settings: Under WYSIWYG Filter, I added the tags GESHI to the HTML elements and attributes i.e. php as I need php code to be highlighted.

5. In WYSIWYG Profiles I set text format Editor as TinyMCE. To configure it, edit it and under "Cleanup and Output" I disabled everything except Apply Source formatting.

6. Left defaults for GESHI configuration (no line numbers)

7. Now to use the syntax highlighting in a textarea with WYSIWYG:

  •     Disable rich text-format
  •     Enter in <php>your code here</php> wherever you need it
  •     Re-enable rich text format and continue using WYSIWYG

I recognized that all HTML correction from TinyMCE WYSIWYG profile under Cleanup and output needs to be disabled to keep php tag and replace it with p tag, else it was not working for me, the php tag displayed as it is.

Also, under the WYSIWYG Filter, in the filter processing order, it was necessary to keep GeShi filter before the convert line breaks into HTML, else br tag was ended up throughtout the PHP code.

Cheers!!!

Preksha Patel's picture

Druproid Installation Guide

Druproid is an Android application which enables user to access Drupal admin panel to manage contents, users, taxonomy(Drupal 6), backup and migrate database, site configuration, reports etc for Drupal 6 and 7.

1. Drupal 6 : Download services_extra module from https://github.com/yarrait/services_extra

       


 Drupal 7 : Download services_extra7 module from   

 https://github.com/yarrait/services_extra7


         


2. Extract the folder into sites/all/module/custom and rename the folder name services_extra-master to services_extra.

   This module configure all the settings of the services module like endpoint sets as default “druproid”, server is “rest server” and enable all resources of services and              services_extra module.

3.   Download/Enable all dependencies of services_extra module.

      Drupal 6   

      Drupa 7

4.   Additional functionality

To Download the Druproid Installation Guide Click Here.

Preksha Patel's picture

How to create Fieldable Panel Panes bundles or types

As you know, the entity, fieldable panel pane is a powerful feature in Drupal. Since they are fieldable entities, they can contain any kind of data that field API can provide. Fieldable panel pane is very effective to add block content and display contents in a structured way. Fieldable panel pane by default provides many bundles. you can also create bundle of fieldable panel pane entity as per your requirement.It can be done in a your module via hook_entity_info_alter() and it will look like this: function your_module_name_entity_info_alter(&$entity_info) { $entity_info['fieldable_panels_pane']['bundles']['your_bundle_name'] = array( 'label' => t('Your bundle name'), 'pane category' => t('Your category name'), 'pane top level' => FALSE, // set to true to make this show as a top level icon 'pane icon' => '/path/to/custom/icon/for/this/pane.png', 'admin' => array( 'path' => 'admin/structure/fieldable-panels-panes/manage/%fieldable_panels_panes_type', 'bundle argument' => 4, // Note that this has all _ replaced with - from the bundle name. 'real path' => 'admin/structure/fieldable-panels-panes/manage/your-bundle-name', 'access arguments' => array('administer fieldable panels panes'), ), ); } Now you can add different fields in your created bundle of Fieldable Panel Pane. Cheers!!!
Preksha Patel's picture

Solution for the Expurrel and longurl gem to get the original url from the short url

We have these two gems(and many others) to get the original url from the short url.I have used both of these two gems and its works fine.

But I was getting the error like this.”URI::InvalidURIError in FoosController#foo(action)” or “bad URI for the expurrel gem” or “bad URI for the longurl gem”, then I passed shorturl as an argument after use 'gsub' operation on the shorturl.

For Example,

one shorturl like @str = “http://bit.ly/dtR48F” then try for the following code:
@short_url = @str.to_s.gsub("(","").gsub(")","")
if you use Expurrel gem then:
e = Expurrel.new(@short_url)
e.decode
and if you use Longurl gem then:
e = LongURL::Expander.new
e.expand(@short_url)

that's it!!!

Such error was ocuuring because sometimes user enters the shorturl within “( )” brackets and gem can not expand such a URL so it gives “Bad URI” error.

I hope it would help anyone.

Preksha Patel's picture

Web scraping/data extraction using mechanize gem in ruby on rails

A mechanize gem which provides the data extraction in a simple and easiest way in ruby on rails.

To use this gem, install it by:

gem install mechanize

than in your controller:

require 'mechanize'

agent = Mechanize.new # creates the mechanize object

doc = agent.get(“your_url”) #pass your url for which you want to extract the data

web_title = agent.page.title #this will give you title of the specified url

web_url = agent.page.uri.to_s.split("http://").to_s.split("/")[0] #this will give you website name e.g.www.abc.com

sometimes url contains https:// rather than http:// in that case use following code:

if web_url.to_s == "https:"
web_url = agent.page.uri.to_s.split("https://").to_s.split("/")[0]
end
html = agent.page.content
#this will give you contents of the whole page

The whole contents you can parse using hpricot so don't forget to add this line in your controller: 'require hpricot'
doc2 = Hpricot.parse(html)
(doc2/ :p).each do |link|
# this will give you all p tags of specified url
puts link.attributes
end

you would have inner_html using:
p = doc2/ :p
puts p.inner_html

That's it!!