Archive for the ‘Concrete 5’ Category

Concrete 5, basePath

Friday, January 8th, 2010

You can get a BasePath from your Template by calling:

$path = $this->getThemeDirectory();

This returns the actual file path to the directory on your server.

Concrete5 and __autoload

Friday, January 8th, 2010

At the moment I'm trying to include a library in a package which depends on it's own autoload function.

Concrete 5 already defines it's own __autoload function, so the other one never gets to execute and the whole app dies.

Trying to include all files in the directory also fails, because some of them depend on others which will be included later.

A search on php.net yielded the following:

spl_autoload_register – a function to register autoload functions.
The function is described in German here.

Concrete uses it in it's Zend library. (Which I hope is included by default …)

/**
* Register {@link autoload()} with spl_autoload()
*
* @param string $class (optional)
* @param boolean $enabled (optional)
* @return void
* @throws Zend_Exception if spl_autoload() is not found
* or if the specified class does not have an autoload() method.
*/
public static function registerAutoload($class = 'Zend_Loader', $enabled = true)
{
if (!function_exists('spl_autoload_register')) {
require_once 'Zend/Exception.php';
throw new Zend_Exception('spl_autoload does not exist in this PHP installation');
}

self::loadClass($class);
$methods = get_class_methods($class);
if (!in_array('autoload', (array) $methods)) {
require_once 'Zend/Exception.php';
throw new Zend_Exception("The class \"$class\" does not have an autoload() method");
}

if ($enabled === true) {
spl_autoload_register(array($class, 'autoload'));
} else {
spl_autoload_unregister(array($class, 'autoload'));
}
}

To solve my problem, I include the following:

spl_autoload_register('__autoload');
spl_autoload_register('DOMPDF_autoload');

where DOMPDF_autoload is the function to load the required classes:

function DOMPDF_autoload($class) {
$filename = mb_strtolower($class) . ".cls.php";
include_once(DOMPDF_INC_DIR . "/$filename");
}

Note: The first line ('__autoload') ensures that Concrete's existing autoloader is also included.

Be sure to check out my pdfhelper package to see this in action!

How do I show files inline with Concrete?

Thursday, January 7th, 2010

If you add a file to your Content Block, Concrete actually adds a link, which forces the browser to download the file, even if it could be viewed inline.

The trick is to change the URL:

turn this

/download_file/-/view/21/

into

/download_file/-/view_inline/21/

Advanced Concrete 5 configuration options

Tuesday, December 15th, 2009

http://www.concrete5.org/help/building_with_concrete5/installation/advanced_configuration_options/

i.e. Disable Automatic URL Redirection:

<?php define('REDIRECT_TO_BASE_URL', false); ?>

Concrete 5 forgot e-Mail adress login

Sunday, November 22nd, 2009

I just had this issue – after switching to e-Mail adress logins, I couldn't access the system – I must have entered a different e-Mail adress, which I didn't remember.

But there's PHPMyAdmin to help with this problem. Just look in the table Users and you'll find all the e-mail adresses.

Now you can even get a new password, if you've forgotten that, too :-)

C5 and Opera

Monday, August 31st, 2009

Problem: You can't edit anything in C5 using Opera 9.6, because the included TinyMCE doesn't load properly.
Easy solution: Use Opera 10 Beta.
Proper solution: Contact us and ask us to develop a plugin for C5 which will fix this problem.

C5 and sundry other items

Sunday, July 5th, 2009

Adding a block to all sub pages

see http://www.smartwebprojects.net/concrete5-blog/38/settting-default-blocks-in-concrete5/

JQuery

C5 includes JQuery 1.3.2 by default (as of writing this), so there is no need to include JQuery additionally. Including it twice can even break things for you! (It did for me with BeautyTips).

Forms

Forms are sent using the admin user's mailaddress. Even if you renamed the admin user.  If you want to change this, you have to edit concrete/blocks/form/controller.php

if(intval($this->notifyMeOnSubmission)>0){
$adminUser=User::getByUserID(1);
if( $adminUser && $adminUser->isSuperUser() ){
$adminUserInfo=UserInfo::getByID( $adminUser->getUserID() );
if($adminUserInfo)
$adminEmail = $adminUserInfo->getUserEmail();
}

$mh = Loader::helper('mail');
$mh->to( $this->recipientEmail );
$mh->from( $adminEmail );
$mh->addParameter('formName', $this->surveyName);
$mh->addParameter('questionSetId', $this->questionSetId);
$mh->addParameter('questionAnswerPairs', $questionAnswerPairs);
$mh->load('block_form_submission');
$mh->setSubject($this->surveyName.' '.t('Form Submission') );
//echo $mh->body.'<br>';
@$mh->sendMail();
}

Edit mode

Use this code in your template to check whether C5 is in edit mode (so you could display additional spacers for instance):

if ($c->isEditMode()) {}
else {}

Coexisting Non-UTF-8 HTML pages

You've got a bunch of old HTML pages with Umlaut's and other non-US characters encoded in, say ISO-8859-1 (windows-1252), which are to be kept alongside of C5, which uses UTF-8. Please add to your .htaccess:

AddDefaultCharset UTF-8
AddCharset windows-1252 .html
AddCharset windows-1252 .htm

In this example, we set up the Default Charset to be UTF-8 (on a server which does not use it as default), but tell the server to serve .html and .htm files using the Charset windows 1252. Did we make your day? Donate us a smile!
Another tip, btw: in Opera you can quickly access the encoding and other information in the sidebar under page info.

Misc. code snippets

Get site title

<?php echo $c->getCollectionName();?>

Create a breadcrumb

See http://www.concrete5.org/index.php?cID=537

C5 and missing images on new host

Sunday, July 5th, 2009

Another installment in the C5 series.

You've moved your new C5 site from the development directory (somewhere deep in the Carribean …) to a brand-new domain. Everything else being fine so far, suddenly you discover your images were lost in the process. At least they don't show up!

No panic, SQL to the rescue!

C5 stores the image paths in the HTML and does not adjust them for the unlikely case of site-moving (yet).

An entry in the DB looks like this, for instance:

(…)
<p><img style="float: left;" src="/103/files/8412/4458/1377/icon_arrow_53_arrow-left.png" alt="icon_arrow_53_arrow-left.png" width="70" height="70" /></p>
(…)

Notice the /103/ ? It's where the installation used to be in before it got it's very own domain.  What we're going to do, is replace all these /103/'s (or  other paths in your case!) with /,  so the images  will be accessible once again.

But first: DO YOURSELF A FAVOUR AND BACKUP THE DB! If you're unsure how to do it, and feel uneasy about the whole process, contact us for a quote. We'd be glad to be of service, but won't be held responsible if we're not doing the task ourselves :-)!

Ok, here  goes:

update `btContentLocal` set content = replace(content,'/103/','/');

Please take care with the string you search for. While I'm 100% sure the string is quite unique in the site I'm fixing, in your case it might turn up somewhere else in the text and be replaced.

Easy, huh? Run the statement through your PHPMyAdmin, inside your C5's database. These are single quotation marks for '/103/' and '/' by the way, the blog might mis-display them.

C5 and dropdown menus

Thursday, June 11th, 2009

How to add custom drop-down menus to your C5 site:

You will need access to the template, and this JQuery Plugin: droppy

Upload the files provided with droppy to your template's webdirectory. I added all of them to  a subdirectory "assets".

Then include this code into your template HTML HEAD:

<!– Drop Down Menus –>
<!–<script type='text/javascript' src='<?=$this->getThemePath()?>/assets/jquery.js'></script>–>
<script type='text/javascript' src='<?=$this->getThemePath()?>/assets/jquery.droppy.js'></script>
<link rel="stylesheet" href="<?=$this->getThemePath()?>/assets/droppy.css" type="text/css" />

Note, I commented out JQuery, because C5 ships with JQuery already, and it may be a newer version than the one you would upload. Leave it as it is (commented out) in case editing blocks stops working.

Next add this handy function to get a menu of all subpages and all sub-subpages of a certain page ID (also called collection ID), just drop it into your template above the future menus:

<?php
function gen_menu($gmid){
$bt = BlockType::getByHandle('autonav');
$bt->controller->displayPages = 'custom';
$bt->controller->displayPagesCID = $gmid;
$bt->controller->orderBy = 'display_asc';
$bt->controller->displaySubPages = 'all';
$bt->controller->displaySubPageLevels = 'all';
$bt->controller->displaySystemPages = false;
$bt->render('view');
}
?>

This tells C5 to return an unordered list of all pages under the page with the CID $gmid (an int), to order them in ascending order and to hide System pages. There's a couple of other settings available, you might want to check it out in the C5 sources. (Search for displayPagesCID to jump to the correct file).

Include the function to generate the menu (above the menu itself!):

<!– Hover menus –>
<script type='text/javascript'>
$(function() {
$('#nav').droppy();
});
</script>

Please note – I already had an object with the id "nav", so I edited droppy.css, and changed  everything in it to nav-menu – so, if you also have an object with the id "nav" and your side looks weird and the menu doesn't work – despair not! Just change the id in droppy.css and in the call to the menu and the menu itself.

Next, it's the menu itself:

<ul id="nav">

<li><a href="a-link">Menu with submenus</a>
<ul>
<li><a href="b-link">Submenu-from Page 85</a>
<?php gen_menu(85)?>
<li><a href="c-link">Submenu from Page 88</a>
<?php gen_menu(88)?>
</ul>
</li>

<li><a href="<?php echo $this->url('/correct-link-toplevel')?>">Another top menu</a>
<?php gen_menu(173)?>
</li>
</ul>

The code builds a horizontal menu bar. The topmost li items specify the menu headings. Each li includes the submenu wrapped in ul's. C5 already renders the <ul>'s and <li>'s necessary, so if you want to include all pages beneath a C5 page, go to dashboard, right click on the page (Show), jot down the CID as seen in the URL bar of your browser, and drop it into gen_menu(x) (x marks the spot). If you want to include several pages with their subcontents in a menu, you'd have to go about this similar to the first menu entry above (Menu with submenus).

OK, if you're very confused about this, but still want the menus – I'll be coming up with an extension for C5 shortly for this, and you're very welcome to hire us to build the menu for you.