Category Archives: PHP

How-to for PHP

Drupal 7: Remove “No front page content …” message

Today, I noticed that that Google had found my website and the description showed the Drupal default message “No front page content has been created yet.” Definitely, the front page exists and contained content. However, I had not wanted to create an article page or other item and promote it to the front page. Therefore, Drupal was displaying that message. I had used CSS to hide the phrase, it seemed by a simple solution, but, hiding the content did not hide it from Google … Oops.

An option would have been to recreate the home page and in the administration area request the redefinition of the page to be used as the front page, a page that would not create that message. However, I did not want to recreate the page. I had already created several custom templates, including the page.tpl.php file. However, the message is embedded inside the $page content and printed by the line to render page content:

<?php print render($page[‘content’]); ?>

The question became, how do you remove the particular content and not damage the page as a whole. the answer is to unset the undesired content. the following command at the top of the page.tlp.php file removes the desired message without damaging anything else:


   
    <?php if(drupal_is_front_page()) {
              unset($page['content']['system_main']['default_message']);
          } 
     ?>

This same concept can be used to remove any unwanted text.

 

Drupal 7: Secret to using hook_menu_alter

Are you trying to use hook_menu_alter in Drupal 7 and finding that hook_menu_alter is not appearing to have any effect? There is a reason. Hook_menu_alter is not called every time you run your site. Hook_menu_alter only runs when the menu module is initialized or a menu is initially constructed. If you have an existing menu and you would like hook_menu_alter to affect that menu, you must do a menu rebuild. In theory, there are two trivial ways to do this. However, the 2 trivial methods may not work for you. The trivial methods are:

  • Use Devel module option to request menu rebuild
  • Use drush to request menu rebuild

However, these 2 methods may not be convenient for you. I know that right now (8/2/2014), Devel will not run correctly on my install because there appears to be problem with the current combination of devel, devel_theme & simplehtmldom that is currently available seem to crash my install. At the same time, drush is inconvenient for the install I have available. My solution involved creation of a simple file that will force the menu rebuild.

To do a menu rebuild programattically:

  • Create a file in your site’s base directory, perhaps menuRebuild.php
  • Include the following code in the new file
    
      <?php
      
        chdir("< your-root-directory >") ;
        define("DRUPAL_ROOT", getcwd());
        require_once("./includes/bootstrap.inc") ;
        drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL) ;
        // Rebuild
        menu_rebuild() ;
        echo "rebuilt" ;
    
      ?>
    
    
  • run the file … the menu will be built.

Drupal 7: Notice: Undefined offset: 2 in drupal_http_request() (line 993 of

Using Drupal 7, When registering a new user do you get the following message?

  • “Notice: Undefined offset: 2 in drupal_http_request() (line 993 of”

If you get this message, you are not alone. This is the result of an error communicating with Facebook, and facebook is incorrectly responding. Unfortunately, to correct the problem, you must adjust the core file common.inc. On line 993 of /includes/common.inc insert a technical error in Drupal. The following will correct the error.

Replace:
list($protocol, $code, $status_message) = explode(‘ ‘, trim(array_shift($response)), 3);

With:
list($protocol, $code, $status_message) = explode(‘ ‘, array_shift($response), 3);

Adding a Widget Area to a WordPress Theme

Are you a person interested in adding a new widget area to your WordPress site? Many templates have widgets in the sidebars, or footer, but, perhaps you need another widget area, for example, in the header. The following explains how to create a new widget area.

Adding a new widget area requires two fairly simple steps:

  • Add content to the functions.php file
  • Add a line of code where you want the new widget area

Step 1 – add a widget area definition to functions.php

Add the following code to the end of your functions.php file. (You may create a custom functions.php file in your theme directory)


   if (function_exists('register_sidebar')) {

     register_sidebar(array(
       'name' => 'Header Area',
       'id'   => 'header-area',
       'description'   => 'This is the header area.',
       'before_widget' => '<div id="%1$s" class="widget %2$s">',
       'after_widget'  => '</div>',
       'before_title'  => '<h4>',
       'after_title'   => '</h4>'
     ));
  }

The preceding code would define a widget area that will have the label “Header Area” in the administration area. This widget would have an “h4” header for the title, and bracket the widget with “div.” You can change the widget wrapper and header type to meet your needs.

Add some code where you want the widget to display

Decide where you want the widget displayed. If this were to be added to the header area, modify file header.php, including the following code where you want the widget inserted.



   <div id="header-area">
    <?php if (function_exists('dynamic_sidebar') && 
              dynamic_sidebar('header-area'))  endif; ?>
   </div>

Setting Up Eclipse PDT with UniServer for PHP Development (Part 2 of 2)

Eclipse PDT is an IDE for the development of PHP projects.

Installing Eclipse PDT is not a big challenge. However, Configuring Eclipse for Windows can be entertaining (to say the least). That is what part 2 of this series covers … installation and configuration for Eclipse PDT for Windows environment.

If you have a WAMP installed on your computer, you are ready to install Eclipse PDT. If not, return to part one of this article series to install a WAMP.

Finding Eclipse PDT

To find Eclipse PDT, head on over to http://www.zend.com/en/company/community/pdt/downloads and click download.

You will be required to register with the site, to join the community of users. However, the download is free.

Installing Eclipse PDT

Installation of Eclipse PDT is not a typical Windows install. The package comes as a simple zip file. You will choose a directory you would like to use as the tool’s home, and unpack the zip file into that directory. When done, go to the directory, find zend-eclipse-php.exe and create a link to this on your desktop. This shortcut will be your access to eclipse PDT.

Configuring Eclipse PDT

Configuring can be a nuisance for Eclipse PDT, but, here we go. Follow along and you should be fine.

In preparation, you need to determine a few facts:

  • What physical directory has been defined as your “localhost” by your WAMP?
  • What sub-directory of your WAMP localhost do you want as your development area? You will put all your projects in sub-directories of the development area.
  • What would you like to name your development area? Eclipse PDT will call this your workspace. Your projects will end up as sub-directories in the workspace

Now you are ready… begin:

  1. Define your workspace – if you have not yet defined a workspace

    • Click “File” in the toolbar.
    • Hover over “Switch Workspace” and click “Other.”
    • On the switch workplace screen, select browse and browse to the location you would like to make into a workplace. You may use the browse tool to create new directories, and select that directory as the directory to switch too.

    Be certain your new workspace is in the path defined as your development server.

  2. Configure Your General Preference

    • Click “Window” in the toolbar, a menu will pop-down.
    • Click Preferences in the drop down menu and a form will open.
    • Configure for PHP
      • Click “PHP” in the left column of drop down, a submenu will appear.
      • Click on “PHP Executables,” a list may appear … it may be blank.
      • If PHP 5 is not already listed, Click on “Add…,” a form will appear.
      • Fill in the Add PHP Executable” form with

        • PHP 5
        • (browse to and select your php.exe file)
        • CGI
        • XDebug
      • Click Debug, a new configurable set will open. Configure as follows:

        • XDebug
        • Default PHP Web Server
        • PHP 5
        • UTF-8
        • UTF-8
        • will already be set correctly, no need for change
        • click if you want to stop on first line for your debug purposes.
      • Click “PHP Servers,” a new configurable set will open. Assure the default PHP Web Server is mapped to http://localhost.” if not, either edit or add that information to the list of managed servers.

  3. Define a New Empty Project

    • Click “File” in the toolbar, the menu will dropdown.
    • Hover over “New,” and click the sub-option “Local PHP Project,” a form will pop up
    • Fill in the project name, the physical address of the directory to be used for the project, select to use either Basic or Zend Framework. The path must be in your workspace, and if you do know what a Zend Framework is … select Basic. Then, click “Next,” another form will appear.
    • On the new form, the host name should be fine, but, adjust the Base Path to include your path from the “localhost,” assuring that the “Project URL” on the page is correctly defined to location your project. Then, click “Next.”
    • On the Library Configuration page, select the usual libraries you use … typically, I select (a) JavaScript Web Project Support, (b) JQuery Library and (c) ExtJS Library. Then, Click Finish. The existing directory will be set up for use with Eclipse PDT.
    • If you would like to bring in files from other directories, do not simply copy them in, Import them or Eclipse will not recognize them.
  4. Create a project from an Existing Directory

    • Copy your files into a directory you would like to define as a new project directory
    • Click “File” in the toolbar, the menu will drop down.
    • Hover over “New,” and click the sub-option “PHP Project from Existing Directory, a form will pop up
    • Fill in the projects and the physical address of the project in a subdirectory of the workspace, a from will pop up. Then, click
      “Next.”
    • The host name should be fine, but, adjust the Base Path to include your path from the “localhost,” assuring that the Project URL on the page is correctly defined to location your project. Then, click “Next.”
    • On the Library Configuration page, select the usual libraries you use … typically, I select (a) JavaScript Web Project Support, (b) JQuery Library and (c) ExtJS Library. Then, Click “Finish.” The existing directory will be set up for use with Eclipse PDT.
  5. Configure Your Properties

    • Click “Project” in the toolbar, a menu will pop-down.
    • Click “Properties” in the drop down menu and a form will open.
    • Configure for PHP debugging
      • Click “PHP Debug” in the left column of drop down, Configurables will change in the right column.
      • Configure as follows:

        • XDebug
        • Default PHP Web Server
        • PHP 5
        • UTF-8
        • UTF-8
        • will already be set correctly, no need for change
        • click if you want to stop on first line for your debug purposes.