Difference between revisions of "Joomla and Extensions Hacks"

From HAA Best Practices Wiki
Jump to navigationJump to search
Line 357: Line 357:
==CBMailing== NOT NEEDED in 3.0
===Modified to recognize special list selection keywords===
===Modified to recognize special list selection keywords===

Latest revision as of 15:04, 23 July 2021

==Lavinya6 Template== No need for any of this in Joomla 3.0

Fix problem with table width in articles[edit]

The original template enclosed article content in a table with a style "contentpaneopen", which called for a cell width of 100%. This caused conflicts when the author specified a table cell width within an article. Fixed it by removing the width specification.

table.contentpaneopen td {
  /* line-height : 18px;*/
  /* font-size : 12px;*/
  line-height : 20px;
  font-size : 14px;
/*  width: 100%; *//* WHB This caused problems when the content specified a table width */

The css for the template is in joomla\templates\lavinya6\css\template.css

Change the size of the banner image[edit]

Edited joomla\template\lavinya6\index.php to increase the height of the banner image from 170 to 235 pixels. You can find the line by searching for "HRGenericPhoto"

Fix problem with menus blinking when you hover[edit]

If you had a narrow window the menus would blink rapidly when you hovered over a two-line menu item. To fix this replace the following code in joomla\templates\lavinya6\css\template.css:

.moduletable_menu li a:hover {
  font-family : Verdana, Arial, Helvetica, sans-serif;
  background-position : left 0%;
  /*background-image : url(../images/menud.png);*/
  height : 16px !important;
  display : block;
  height : 23px;
  color : #a52a2a;
  font-size : 1em;
  /*text-align : center;*/
  text-align : left;
  padding-left : 10px;


.moduletable_menu li a:hover {
  color : #a52a2a;

Increased font size in textareas[edit]

The font in the private email message box was small and hard to read. Increased the size by adding the following code to joomla\templates\lavinya6\css\template.css immediately after the selector for 'inputbox':

  font-size: 1.2em;

Community Builder[edit]

Suppress certain icons during edit of user profile[edit]

During edit of the user profile suppress the display of the icon indicating that the field will not be displayed in the profile from the 'First Name' and 'Last Name' fields. The icon was missleading since the combined full name will be displayed.

In the file joomla\libraries\CBLib\CB\Legacy\LegacyComprofilerFunctions.php add the following lines in the function getFieldIcons, immediately after the declaration of $ueConfig as global.

    // WHB hack to suppress display of the icon saying that the field is not displayed on the profile.  
    // The individual first/last name fields are not, but the composite name field is displayed
    if ($oTitle === "First Name" || $oTitle === "Last Name")
        $oProfile = 1;
    // WHB End of hack.  If we lose this one in an update the worst that happens is the icon reapears.

===Added lastname to the list of fields that can be searched even though not on the profile=== NOT NEEDED in 3.0

NOT FOUND 11/12/16 - need to come back to this one. This is now built into CB. No need for this change. (CB 2.6)

Normally CB won't let you search for a field that isn't displayed in the profile. We want to search for last name, not full name, so I added the lastname field to the list of exceptions. To do so I modified one line of code in the function _getTabFieldsDb in the file joomla\administrator\components\com_comprofiler\comprofiler.class.php. The original line is commented out immediately over the modified line.

switch ( $reason ) {
  case 'profile':
      $where[] = 'f.profile != 0';
  case 'list':
      // WHB hack.  Added lastname to exceptions for fields that are not on the profile yet are searchable.
      // $where[] = "( f.profile != 0 OR f.name = 'username'" . ( in_array( $ueConfig['name_format'], array( 1, 2, 4 ) ) ? " OR f.name = 'name'" : '' ) . ')';
      $where[] = "( f.profile != 0 OR f.name = 'username'" . ( in_array( $ueConfig['name_format'], array( 1, 2, 4 ) ) ? " OR f.name = 'name' OR f.name='lastname'" : '' ) . ')';
      // END WHB hack.				    
   case 'register':
      $where[] = 'f.registration = 1';

===Make the AIM link on the user profile activate AIM=== NOT NEEDED in 3.0

DROP THIS CHANGE - it doesn't work any more 4/22/13

In order to make the AIM link on the Web Contact tab work, we had to reconfigure the link built by Community Builder. The code to make the change is in the file joomla\administrator\components\com_comprofiler\plugin.class.php. It occurs in the functions getFieldRow immediately after the line:

$oValue = $this->getField( $field, $user, $output, $reason, $list_compare_types ); 

The added code is:

// WHB Hack to allow aim in Web page, if we lose it the aim file will simply show the user
// name, without the link.
if ($field->name === "cb_aim")
    if(preg_match("#http://aim#", $oValue))
        $oValue = preg_replace("#http://aim#", "aim", $oValue);
        $oValue = preg_replace("#target=\\\"_blank\\\"#", "", $oValue);
//WHB end of hack.        

===Modify language file to include instructions for uploading profile image=== NOT NEEDED in 3.0

Change the definition of _UE_UPLOAD_DIMENSIONS_AVATAR to include upload instructions in .\components\com_comprofiler\plugin\language\default_language\default_language.php to read:

DEFINE('_UE_UPLOAD_DIMENSIONS_AVATAR','To upload a picture press the "Browse" button and select '
.' a picture on your computer.  Then press the "Choose File" button. '
.'Your image will be resized if needed to a maximum dimension of %s pixels '
.'width x %s height automatically, but your image file should not exceed %s KB.');

Modify the reunion attendees list to include non-user reunion attendees[edit]

Added code to .\administrator\components\com_profiler\library\cb\cb.lists.php

Added the following code after After $usergids = implode(",",$allusergids):

// WHB Hack
// We want to include front end users who have been entered to 
// represent non-user classmates who have indicated that they
// are coming to the reunion.  We do this only for the "Reunion Attendees"  list
    if (false !== stripos($row->title, "Reunion Attendees")){
        $usergids .= ", 1"; // 29 before J1.7

// End of WHB Hack        

Also the following before $queryFrom .= " " . $filterby; in .\administrator\components\com_profiler\library\cb\cb.lists.php

    // WHB Hack
    // We only want to include the front end users if they have cb_dummyregistrant set
    // We also want to eliminate the admin user, provided they aren't specifically included.
        $whbIncludeAdmin =  !strncmp($row->title, "Super Administrators", 19);
        if (!$whbIncludeAdmin){
                $queryFrom .= " AND (u.username != 'admin')";
        if (strlen($row->title) >= 17){
            if (false !== stripos($row->title, "Reunion Attendees", 17)){
                $queryFrom .= " AND (ue.cb_dummyregistrant OR (g.group_id = 2))\n";
    // END WHB Hack

Modified code in .\components\com_comprofiler\comprofiler.html.php

   //WHB HACK we suppress the row click for reunion attendees who are not
   //users of the web site
                if ($user->gid != 1){ // 29 pre J17
                    $jsClickTr .= "'" . cbSef( 'index.php?option=com_comprofiler&task=userProfile&user=' . $user->id . getCBprofileItemid( true ), false ) . "',";
                    $jsClickTr .= "'" . cbSef( 'index.php?option=com_comprofiler&task=userslist&listid=6') . "',";
   // END HACK
   // The next line replaces the hack in the original 
   // $jsClickTr        .=                "'" . cbSef( 'index.php?option=com_comprofiler&task=userProfile&user=' . 
          $user->id . getCBprofileItemid( true ), false ) . "',";

Also added the following code in function _getListTableContent (after assignment of $fieldView->value) in foreach loop that assigns links to the avatars and user names:

 //WHB HACK we strip the links on the avatar and the individual name for Reunion Attendees
 //who are dummy registrants
 if ($user->gid == 1){ // 29 pre J17
     if ($fieldView->name =="avatar" or $fieldView->name == "name"){
         $fieldView->value = preg_replace('/<a.+?>/', , $fieldView->value);    
         $fieldView->value = preg_replace('/<\/a>/', , $fieldView->value);    
 //WHB End hack

Added code to support a summary version of the Reunion Attendees list[edit]

Modified code in .\components\com_comprofiler\comprofiler.html.php

// WHB hack to support summary list
    if (false !== stripos($row->title, "Reunion Attendees - Summary")){
           global $_CB_database;

           // Get the reunion year 
           $_CB_database->setQuery("SELECT params FROM #__comprofiler_plugin WHERE name='HAAReunion'");
           $haaparams = $_CB_database->loadResult();        
           preg_match('/ActiveReunion=([0-9]+)/', $haaparams, $arrYear);
           $whbRyr = $arrYear[1];
           if (false !== stripos($row->title, "Prior")){
                $whbRyr = $whbRyr - 5;

           $whbRyr = (string)$whbRyr;
           if (strlen($whbRyr) == 1 )
               {$whbRyr = '0'.$whbRyr;}

           $whbCount = count($users);
           $whbRowCount =  ceil($whbCount/3);
           $whbLastRowColCount = $whbCount % 3;
           echo "<table>";
           for ($whbIx = 0; $whbIx < $whbRowCount; $whbIx++)
                if ($whbIx == $whbRowCount - 1)
                     if ($whbLastRowColCount == 1)
                          echo $tt = '<tr>'.whbUserCell($whbIx, 0, $whbRowCount, $whbLastRowColCount,  $users, $whbRyr).'</tr>';
                     else if ($whbLastRowColCount == 2)
                          echo $tt = '<tr>'.whbUserCell($whbIx, 0, $whbRowCount, $whbLastRowColCount,  $users, $whbRyr).whbUserCell($whbIx, 1, $whbRowCount, $whbLastRowColCount,  $users, $whbRyr).'</tr>';                
                     else if ($whbLastRowColCount == 0)
                          echo $tt = '<tr>'.whbUserCell($whbIx, 0, $whbRowCount, $whbLastRowColCount,  $users, $whbRyr).whbUserCell($whbIx, 1, $whbRowCount, $whbLastRowColCount,  $users, $whbRyr).whbUserCell($whbIx, 2, $whbRowCount, $whbLastRowColCount,  $users, $whbRyr).'</tr>';                
                    echo $tt = '<tr>'.whbUserCell($whbIx, 0, $whbRowCount, $whbLastRowColCount,  $users, $whbRyr).whbUserCell($whbIx, 1, $whbRowCount, $whbLastRowColCount,  $users, $whbRyr).whbUserCell($whbIx, 2, $whbRowCount, $whbLastRowColCount,  $users, $whbRyr).'</tr>';
           echo "</table>";     
      else {
               if ( $showPaging && ( ( $limitstart != 0 ) || ( $limit <= $total ) ) ) {

                   // top page links:
            <div class="cbUserListPagination cbUserListPaginationTop" style="width:100%;text-align:center;"><?php echo writePagesLinks($limitstart, $limit, $total, $ue_base_url.$pagingSearch.$spoofAmp, $search); ?></div>
               echo HTML_comprofiler::_cbTemplateRender( $cbTemplate, $myUser, 'List', 'drawListBody', array( &$users, &$columns, &$tableContent, $listid, $ueConfig['allow_profilelink'] ) );
  // Original content of hacked area: echo HTML_comprofiler::_cbTemplateRender( $cbTemplate, $myUser, 'List', 'drawListBody', array( &$users, &$columns, &$tableContent, $listid, $ueConfig['allow_profilelink'] ) );

  // End WHB hack           

Added code in .\components\com_comprofiler\comprofiler.html.php

// WHB FUNCTION to print one cell of Reunion Attendees - Summary report

function whbUserCell($row, $col, $lastrow,  $lastrowcolcount, &$users, $Ryr)
    $renplanstmt = '$renp = $users[$rowix]->cb_reunion%02d;';
    $renplanstmt = sprintf($renplanstmt, $Ryr);
    $rowincadj =  ($lastrowcolcount == 1 && $col == 2 ) ? 1 : 0;
    $whbColor = ' color = "gray">';
    $rowix = $col  * $lastrow + $row - $rowincadj;
    if ($renp == "2")
        $whbColor = ' color = "green">';
    return '<td width="200"><font '.$whbColor.$users[$rowix]->name.'</font></td>';   


Also added code before $query = "SELECT ue.*, ....." in .\administrator\components\com_comprofiler\library\cb\cb.lists.php

NOTE that after Joomla 2.* this code needs to go before the test for "checkJversion() == 2"

//WHB Hack
// We don't want to impose a limit on the number of users for the summary report'
if (false !== stripos($row->title, "Reunion Attendees - Summary")){
    $limitstart = 0;
    $limit = $total;

//END WHB Hack // $query = "SELECT u.id, ue.banned, '' AS 'NA' " . ( $fieldsSQL ? ", " . $fieldsSQL . " " : '' ) . $queryFrom . " " . $orderby

===Workaround for CB bug in User Manager=== NOT NEEDED in 3.0 In version 1.2.3 and 1.4 of CB there is a bug in the User Manger that causes a partial display of the advanced search feature when you cancel out of a user edit. CB has opened a bug for this (#1922). A temporary workaround is to suppress the search when you cancel out of the edit. The following code in .\components\com_comprofiler\plugin\user\plug_cbcore\cb.core.php accomplishes this. (The hope is that this won't be required in the next version of CB.) The code is about line 954.

// WHB hack to supress bug in CB 1.2.3 that caused advanced search checkboxes to be displayed if you cancel out of user edit.
   return $query;
// End  WHB hack

Not required in CB 1.7

==GMapsPro== NOT NEEDED in 3.0

===Suppress map on user profile tab=== NOT NEEDED in 3.0




after the code block that does the geocoding right after the comment

// If the users profile needs to be geocoded and IF geocoding is enabled

The effect is to suppress the generation of the map on the user profile tab.

Fix problem with calls to www.sitename.org vs. sitename.org[edit]

// ORIG LINE	$query = 'SELECT * from #__gmaps_config where site = "' . $mosConfig_live_site . '"';
// NEW LINE	$query = 'SELECT * from #__gmaps_config limit 1';

The intent of the original code was to allow a single Joomla installation to support more than one site. The problem was that the URL isn't unique within a site. A better approach would have been to use the database prefix (jos_, for example), which is unique within sites in the same installation. This would not be a difficult modification if it becomes desirable to run multiple sites in a single installation.

Fixed problem in communitybuilderprofileadapter.class.php[edit]

Changed code to suppress second copy of avatar and to add View Profile link.

$desc = "<table><tr><td>"  
 . $row["name"] . "<br/>"
 . $row["cb_address"] . "<br/>"
 . $row["cb_city"] . ", " . $row["cb_state"] . "<br/>"	
 . "<a href='".$profile_path.$row["user_id"]."'>View Profile</a><br />"
 . "</td></tr>

Modified to recognize special list selection keywords[edit]

We have heavily altered CBMailing to integrate it with PHPList. The modified install file is available here: haa_cbmailing.zip

Added the following code in cbmailing.class.php immediately after $filterby is set from the database

// We modify the filter depending on keywords included in the filter
// This code appears in haareunion.php and must be changed in both places!!
// The only difference in the code is the definition of $HaaPrefix and the
// use of $row->filterfields vs. $filterby

$database->setQuery("SELECT params FROM #__comprofiler_plugin WHERE name='HAAReunion'");
$haaparams = $database->loadResult();    // In the form 'ActiveReunion=15'
preg_match('/ActiveReunion=([0-9]+)/', $haaparams, $arrYear);
$actyear = (string)$arrYear[1];
if (strlen($actyear) == 1 )
    {$actyear = '0'.$actyear;}
$prioryear = (string)(((int)$arrYear[1]) - 5);
if (strlen($prioryear) == 1 )
    {$prioryear = '0'.$prioryear;}

if (preg_match('/NoPlansActiveReunion|PlansToComeActiveReunion|IsRegisteredActiveReunion|NoPlansPriorReunion|PlansToComePriorReunion|IsRegisteredPriorReunion/', $filterby))
    $HaaPrefix = "ue.";
    $HaaFilter = $filterby;
    $HaaFilter = preg_replace('/NoPlansActiveReunion/', "(".$HaaPrefix."`cb_reunion".$actyear."` < '1' or ".$HaaPrefix."`cb_reunion".$actyear."` is null)", $HaaFilter);
    $HaaFilter = preg_replace('/PlansToComeActiveReunion/', "(".$HaaPrefix."`cb_reunion".$actyear."` = '1')", $HaaFilter);
    $HaaFilter = preg_replace('/IsRegisteredActiveReunion/', "(".$HaaPrefix."`cb_reunion".$actyear."` ='2')", $HaaFilter);
    $HaaFilter = preg_replace('/NoPlansPriorReunion/', "(".$HaaPrefix."`cb_reunion".$prioryear."` < '1' or ".$HaaPrefix."`cb_reunion".$prioryear."` is null)", $HaaFilter);
    $HaaFilter = preg_replace('/PlansToComePriorReunion/', "(".$HaaPrefix."`cb_reunion".$prioryear."` ='1')", $HaaFilter);
    $HaaFilter = preg_replace('/IsRegisteredPriorReunion/', "(".$HaaPrefix."`cb_reunion".$prioryear."` ='2')", $HaaFilter);
    $filterby = $HaaFilter;

Fixed problem in Javascript in file[edit]

In the file admin.cbmailing.html.php commented out a closing brace (}) and added submitform(pressbutton); right before the final return. The syntax error was showing up in IE with debugging enabled. Once the brace was removed the form wasn't submitted without the call to submit form.

function messageForm( &$lists, &$config, $option ) {      
 <script language="javascript" type="text/javascript">
     //function getSelectedValue(
    function submitbutton(pressbutton) {
    var form = document.adminForm;
    if (pressbutton == 'cancel') {
    submitform( pressbutton );
    // do field validation
   if (form.mm_subject.value == ""){
      alert( "<?php echo _CB_MAILING_FILLINSUBJECT ?>" );      
      return false;
   } else if (getSelectedValue('adminForm','mm_group') < 0){
      alert( "<?php echo _CB_MAILING_SELECTAGROUP ?>" );
      return false;
   } else if (form.mm_message.value == ""){
      alert( "<?php echo _CB_MAILING_FILLINMESSAGE ?>" );
      return false;
   return true;

A few lines further down added the line commented with WHB

// Get all users email
$query = "SELECT email FROM #__users u, #__comprofiler ue WHERE u.id=ue.id AND ue.approved=1 AND ue.banned!=1 AND ue.confirmed=1";
$query .= " AND ue.cb_mailoptin = 1";  // WHB Modification to honor optin field
if (! $this->cbMailingConfig["incBlocked"])
	$query .= " AND u.block!=1";

Supressed sending of blank email[edit]

in joomla\administrator\components\com_cbmailing\cbmailing.class.php Commented out the line calling mosMail in the following. It was trying to send an empty email, resulting in an error.

/* $result = mosMail( $this->cbMailingConfig["debugFromAddr"], 
   $mailedDetails . $msg, 0);      */
// Uncomment the following line to display the message - would need to comment out the mosRedirect
//HTML_cbmailing::errorMessage( $mailedDetails . $msg, NULL );	


Added css to template for body of the comments[edit]

The original style used very small sans-serif type for the comments - too small for aging eyes. Added the following to the end of \joomla\components\com_nicetalk\css\nicetalk.css

OBSOLETE since we switched forum software.

/* WHB addition */

font-family : georgia, Verdana, arial, serif;


Problems with date() in php 5.3[edit]

Must insert


in both index.php files or the date() function fails. This shows up in ExpirePrive

Intermittent bug when editing/creating menu items[edit]

While editing/creating a menu item, when you selected 'Article layout' for the type of page the resulting screen didn't have the dropdown list that is supposed to let you select the article to be associated with the menu item. The problem was intermittent and was often cured by switching browsers.

NOTE: Not installed in Joomla 2.5.0+, so far no reports of problems! (7/15/12)

In administrator\components\com_menus\models\item.php changed the line that read:

$url = JRequest::getVar('url', array(), '', 'array');


// WHB hack to fix intermittent bug with url field in $_REQUEST
$url = JRequest::getVar('url', array(), 'GET', 'array');
if (!isset($url['option'])){
     $url = JRequest::getVar('url', array(), '', 'array');
// WHB end of hack.  Original code was $url = JRequest::getVar('url', array(), '', 'array');

Return to main Master Template page