Custom predefined code template - dreamweaver

I've been looking everywhere but I'm either blind or it's really not there.
I'm looking for some option to add some sort of code template to Dreamweaver (CS5.5) which I can access with some shortcode via the code hinting menu. In Zend (PHP IDE) you could define such code blocks like
$query = "";
$sql = mysql_query($query);
$result = mysql_fetch_assoc($sql);
and let Zend put them into your code when typing "qry" and hitting enter.
Is there such an option in Adobe Dreamweaver CS5.5?

I'we been looking for the same and found a solution. Try to add to your dreamweaver instalation path
"\Adobe Dreamweaver CS5\configuration\CodeHints\php_codehints.xml"
into to the section
<menugroup MMString:name="php/CORE" id="PHP_CORE"></menugroup>
following code:
<menu pattern="$query" doctypes="PHP_MySQL" displayrestriction="PHP_Script"
caseSensitive="true" icon="shared/mm/images/hintKeyword.png"
MMString:source="php/CORE" >
<menuitem label="mssql fetch //complete" value="="
SELECT * FROM
WHERE
";
$Qresult = mssql_query($query);
while ($Qdata = mssql_fetch_assoc($Qresult)) {
echo $Qdata[''];
};
" icon="shared/mm/images/hintMisc.gif"/>
</menu>
Now when you type $query to your code within PHP site, dreamweaver will offer you "mssql fetch //complete"
Analogically other code blocks. For example following:
<menu pattern="for" doctypes="PHP_MySQL" displayrestriction="PHP_Script"
caseSensitive="true" icon="shared/mm/images/hintKeyword.png"
MMString:source="php/CORE" >
<menuitem label="foreach()//complete" value="each ($arr as $k => $v) {
}" icon="shared/mm/images/hintMisc.gif"/>
<menuitem label="for()//complete" value=" ($i=0; $i<=$ ; $i++) {
};" icon="shared/mm/images/hintMisc.gif"/>
</menu>
<menu pattern="if" doctypes="PHP_MySQL" displayrestriction="PHP_Script"
caseSensitive="true" icon="shared/mm/images/hintKeyword.png"
MMString:source="php/CORE" >
<menuitem label="if()//complete" value=" ( ) {
}" icon="shared/mm/images/hintMisc.gif"/>
<menuitem label="if else//complete" value=" ( ) {
}
else {
}" icon="shared/mm/images/hintMisc.gif"/>
</menu>
I thing this solution works on Dreamweaver since CS versions, may be in MX too.
On the other site you can simply use SHIFT+F9 and define your own code block to paste.

Related

How to add asset publisher configuration options in LifeRay 6.2

When using an asset publisher, you can change Display Settings in the asset publisher configuration panel. If you select the Abstracts display template, a new option will be available for you (Abstract Length). How can I add an option like that to my Application Display Templates (ADT) ?
Example for the Abstracts template :
Example for my custom template (Abstract Length not available):
You can use substring in velocity code written inside ADT built for news asset publisher, check below code to display 100 character only of about us page
#if (!$entries.isEmpty())
<div class="news">
#foreach ($entry in $entries)
#set($renderer = $entry.getAssetRenderer() )
#set($className = $renderer.getClassName() )
#if( $className == "com.liferay.portlet.journal.model.JournalArticle" )
#set( $journalArticle = $renderer.getArticle() )
#set( $document = $saxReaderUtil.read($journalArticle.getContent()) )
#set( $rootElement = $document.getRootElement() )
#set( $xPathSelector = $saxReaderUtil.createXPath("dynamic-element[#name='country-portal-image']") )
#set( $countryPortalImage = $xPathSelector.selectSingleNode($rootElement).getStringValue() )
#set( $xPathSelector = $saxReaderUtil.createXPath("dynamic-element[#name='country-portal-title']") )
#set( $countryPortalTitle = $xPathSelector.selectSingleNode($rootElement).getStringValue() )
#set( $xPathSelector = $saxReaderUtil.createXPath("dynamic-element[#name='country-flag-icon']") )
#set( $countryFlagIcon = $xPathSelector.selectSingleNode($rootElement).getStringValue() )
#set( $xPathSelector = $saxReaderUtil.createXPath("dynamic-element[#name='country-portal-about-us']") )
#set( $countryPortalAboutUs = $xPathSelector.selectSingleNode($rootElement).getStringValue().substring(0,100) )
#set( $link = $renderer.getURLViewInContext($renderRequest, $renderResponse, '') )
#set( $viewURL = $assetPublisherHelper.getAssetViewURL($renderRequest, $renderResponse, $entry))
#set($news-summary =$entry.getSummary($locale))
#set($date = $dateTool.format("dd/MM/yyyy hh:mm:ss", $dateTool.toDate( "EEE, dd MMM yyyy hh:mm:ss Z" , $entry.getPublishDate())))
<div class="new">
<h1 class="title">$entry.getTitle($locale)</h1>
$date
<img src="$countryFlagIcon"/>
<img src="$countryPortalImage"/>
<h3 class="sub-title">$countryPortalAboutUs</h3>
<p class="read-more">
Read More
</p>
</div>
#end
#end
</div>
#end
You can create JSP hook to customize Asset Publisher configuration.
The original configuration is rendered by /html/portlet/asset_publisher/configuration.portal.jsp.
In your hook, you can include the original jsp and then add your own preferences.
Example:
<%-- Include the original Asset Publisher configuration JSP. --%>
<%#include file="/html/portlet/asset_publisher/configuration.portal.jsp"%>
<%-- Read current value from portlet preferences. --%>
<% String abstractLength = portletPreferences.getValue("abstractLength", "100"); %>
<%-- Hidden div with custom input fields. --%>
<div id="customPreferences" style="display: none;">
<aui:fieldset label="fieldset.abstractLength">
<aui:input name="abstractLength" label="abstractLength" value="<%= abstractLength %>">
<aui:validator name="number"/>
<aui:validator name="min">1</aui:validator>
</aui:input>
</aui:fieldset>
</div>
<%-- JS code to place custom preferences at the end of Display Settings tab. --%>
<%-- It uses jQuery, but it's not a requirement. --%>
<script>
$(document).ready(function () {
// find div with custom preferences
var $customPreferences = $("#customPreferences");
// find the last fieldset on Display Settings tab
var displaySettingsLastFieldset = $(".nav-tabs:eq(1)").siblings("div:eq(1)").children().filter("fieldset").last();
// insert custom preferences after the last fieldset on Display Settings tab
$customPreferences.insertAfter(displaySettingsLastFieldset);
// show custom preferences
$customPreferences.show();
});
</script>
It is a good approach to extend the original JSPs - ie. include the original and then make the customization. This way, there's a good chance of a painless update to next Liferay versions.
For general guidelines on how to implement JSP hooks, see Liferay Developer's Guide.
You can get a list of all the available portletPreference values available to the asset publisher ADT using:
<#list portletPreferences?keys as prop >
<li>
${prop}
</li>
</#list>
So, for your example, you could get the abstract length value set by the user using:
abstractLength: ${portletPreferences.abstractLength[0]}
best way if you creating your own ADT then manage content length in ADT instead of unnecessarily hooking of AP jsp.

How to display content from a child page within a hierarchial custom post type?

I have a hierarchical custom post type. It has 6 pages, and each page has 3 child pages.
When viewing one of the 6 pages, I need to display content (a title and excerpt) from each of its 3 child/descendent pages.
Here is my current loop:
<?php if(have_posts()):?>
<?php query_posts('&post_type=how-we-do-it&post_parent=0');?>
<?php while(have_posts()):the_post();?>
<?php $color = get_post_meta( get_the_ID(), 'pointb_how-we-do-it-color', true ); ?>
<div class="section">
<div class="title">
<h1 style="background:<?php echo $color;?> !important;">
<?php the_title();?>
</h1>
</div>
<div class="content">
<div class="how-<?php the_slug();?>">the summary here. and here is child content:
<div class="child">child content should be here.</div>
</div>
</div>
</div>
<?php endwhile;?>
<?php wp_reset_query(); ?>
<?php endif;?>
I have tried numerous different approaches to try and accomplish what I need, but none of them work within the custom post type. Here are some of the various methods I have tried:
I tried the suggested code on this page: http://wordpress.org/support/topic/display-child-pages-title-amp-content-on-parent-page
I also tried the following code:
$pageChildren = get_pages('child_of='.$post->ID');
if ( $pageChildren ) {
foreach ( $pageChildren as $pageChild ) {
echo '<h2>'. $pageChild->post_title.'</h2>
';
if ($pageChild->post_excerpt){
echo ''.$pageChild->post_excerpt.'
';
}
}
}
I've tried a number of other methods that I didn't bother saving, so I can't show them.
I'm at the point where I am getting frustrated with this and thought I'd throw it out here to get some fresh perspectives.
The issue with your first sample is that you call if(have_posts()) before you reconstruct the query.
The second sample has a dangling ' after $post->ID.
Try this:
$pageChildren = get_posts( 'post_type=how-we-do-it&post_parent='.$post->ID );
Based on some comments from MarZab above, I got thinking about the post ID.
I made the following tweak to the block of code I originally posted above, and now it works perfectly:
$pageChildren = get_pages('child_of='.$post->ID');
Is now:
$post_id = get_the_ID();
$pageChildren = get_posts( 'post_type=how-we-do-it&echo=0&post_parent='.$post_id );

Get data from previous page

I create a popup window using onclick="window.open()" the question is how can i get the data from previous page? here is my code :
<?php
include ("conn.php");
extract($_GET);
$applicantID = $_GET['applicantID'];
$sql = "SELECT * FROM applicant WHERE applicantID ='$applicantID'";
$query = mysql_query($sql);
$data = mysql_fetch_array($query);
echo $data['applicantID'];
?>
When i echo $data['applicantID']; it doesn't show any data.
I use this <input type="button" value="Check" onclick="window.open('checkstatus.php','popup','width=800,height=800,scrollbars=yes,resizable=no,toolbar=no,directories=no,location=no,menubar=no,status=no,left=0,top=0'); return false" />
Why don't you use window.open('checkstatus.php?applicantID=something')? And retrieve it by $applicantID = $_GET['applicantID'] so that I hope it will work.

Drupal6 - set popup window to a link

In Drupal6, we can use l function to format a link, but how can we set it to a popup window?
Suppose the original code look like:
<?php echo l('product', 'product') ?>
Opening a popup using window.open is not considered a good practice. You may try the lightbox module (http://drupal.org/project/lightbox2) for a better way of showing a popup.
However, if you do want to open a popup using window.open, the following should work -
Create the link with an id
<?php echo l('product', 'product', array('attributes' => array('id' => 'product-link'))); ?>
Add JavaScript (you can add it to your theme's JS file) -
$(document).ready(<br />
function() {<br />
$("#product-link").click(<br />
function(e) {<br />
openWindow(); // function for opening window<br />
e.preventDefault(); // Stop link from opening new page<br />
}
);
}
);

Kohana "has many through" relation

I was wondering what the best method is to edit a 'has many through' relation with a form.
Let's say I have a bunch of users that can belong to multiple categories.
The form would have some checkboxes like this:
<input type="checkbox" name="category_ids" value="1" />
<input type="checkbox" name="category_ids" value="2" />
Then in my controller I could do something like:
// dump all relations
DB::delete('users_categories')->where('user_id','=',$user->id)->execute();
// add new relations
foreach (explode(',', $_POST['category_ids']) as $category)
$user->add('category', ORM::factory('category', $category))
But this looks too complicated to me (also because I have more than one 'has many through' relations). Is there an easier / better way to accomplish this using kohana orm? :)
thats how i do it
// C
$roles = ORM::factory('role')->find_all();
foreach ($roles as $role)
{
$action = isset($form['user']['roles'][$role->id]) ? 'add' : 'remove';
// you dont need this if-statement if you'r using ko2
if ($action === 'add' && $user->has('roles', $role))
{
continue;
}
$user->$action('roles', $role);
}
// V
<?
$roles = ORM::factory('role')->find_all();
foreach ($roles as $role):
?>
<?= form::checkbox('user[roles]['.$role->id.']', $role->id, $user->has('roles', $role)) ?>
<?= form::label('user_roles_'.$role->id, $role->name) ?>
<br />
<? endforeach ?>
To find what was added (reverse the args to find what was removed) consider using array_diff().
With this you should be able to code something more efficient than pure orm.

Resources