Pages

Monday, 30 December 2013

Spark update: ready for alpha testing

The Spark distribution is a Drupal 7 distribution which aims to prototype cutting-edge authoring experience improvements that we hope to propose for inclusion in Drupal 8 core. Since we announced Spark back in May, we've shown videos of prototypes of inline editing, responsive layout building and mobile administration. The rest of the Spark team (Angela Byron, Kevin O'Leary, Wim Leers, Gábor Hojtsy, Jesse Beach, Preston So and Dharmesh Mistry) has also been working hard to make these designs a reality.
There has been a lot of great progress over the past months, and with the release of Spark 7.x-1.0-alpha4, Spark is now ready for some community testing! Each module/theme that Spark builds upon is a separate, standalone contributed project that can be integrated into existing sites. This alpha release includes:
  • Inline Editing, courtesy of Edit module. You can click into a node, switch the “View / Edit" toggle in the toolbar, and then click directly into any field to edit its contents, instead of having to be redirected to the backend.
  • True WYSIWYG, courtesy of Aloha Editor. Edit your rich text with your theme's direct styling through the inline editor. It even works with images + captions, links directly to content in the site, and has basic support for tokenized strings.
  • Responsive Layout Builder, courtesy of the Layout and Gridbuildermodules. You can configure layouts for separate breakpoints (e.g. Mobile, Tablet, Desktop) and even define your own grids for them to snap to. These technologies layer on top of Panels,though it's been architected so it could be integrated with other layout solutions as well.
  • New admin theme, brought to you by Ember. This brings some nice light styling on Drupal core's Seven admin theme as well integrating theAdmin module to better support mobile devices. A more fleshed out mobile toolbar and administrative experience is slated for implementation soon.
If you'd like to try the distribution out without downloading and installing it, check our demo site at http://demo.sparkdrupal.com. (Note that since this site is open to anyone, it might look a bit funny at any given time. If things are really broken, please check back later.)
There is still much to do, but hopefully this release will provide a good understanding of the direction Spark is taking, and what we hope to propose for inclusion in Drupal 8 core. We greatly welcome feedback, bug reports and patches in the Spark issue queue.
At DrupalCon Munich next week, we'd love to talk more about how we can move some of these things into Drupal 8 core. We've setup various Spark sessions and BoFs at DrupalCon Munich to plan and brainstorm about this.

Node.js integration to Drupal

Node.js integration
===================
This module adds Node.js integration to Drupal.
Setup
=====
1. Install Node.js.

 Installing Node.js and NPM on Ubuntu/Debian

How to Install Node.js

2. Install required Node.js modules with the Node Package Manager (NPM).
Make sure you are in the nodejs module directory - NPM needs the package.json
file that comes with the nodejs module to install the right modules.
cd path/to/your/nodejs/module/directory
npm install
npm uninstall express
npm install express@2.5.9
3. Create a 'nodejs.config.js' file in your nodejs module directory.
Read the 'nodejs.config.js.example' file. A basic configuration can be as simple as:
/**
* This configuration file was built using the 'Node.js server configuration builder'.
* For a more fully commented example see the file nodejs.config.js.example in the root of this module
*/
backendSettings = {
"scheme":"http",
"host":"192.168.1.61",
"port":8080,
"key":"/path/to/key/file",
"cert":"/path/to/cert/file",
"resource":"/socket.io",
"publishUrl":"publish",
"serviceKey":"",
"backend":{
"port":80,
"host":"localhost",
"messagePath":"/drupal7/nodejs/message/"},
"clientsCanWriteToChannels":false,
"clientsCanWriteToClients":false,
"extensions":"",
"debug":true,
"transports":["websocket",
"flashsocket",
"htmlfile",
"xhr-polling",
"jsonp-polling"],
"jsMinification":true,
"jsEtag":true,
"logLevel":1};
Set debug to false when you are happy with your setup.
4. Run the node server with the command: node server.js
As long as you have 'debug: true' in your configuration file, you'll see lots of helpful messages.

Installing Node.js and NPM on Ubuntu/Debian

This is just short snippet on how to install Node.js (any version) and NPM (Node Package Manager) on your Ubuntu/Debian system.
Step 1 - Update your system
sudo apt-get update
sudo apt-get install git-core curl build-essential openssl libssl-dev
Step 2 - Install Node.js
First, clone the Node.js repository:
git clone https://github.com/joyent/node.git
cd node
Now, if you require a specific version of Node:
git tag # Gives you a list of released versions
git checkout v0.4.12
Then compile and install Node like this:
./configure
make
sudo make install
Then, check if node was installed correctly:
node -v
Step 3 - Install NPM
Simply run the NPM install script:
curl http://npmjs.org/install.sh | sudo sh
And then check it works:
npm -v
That's all.

How to Install Node.js Essay Steps

This was the first in a series of posts leading up to Node.js Knockout on how to use node.js.
I have been given permission to repost the articles from the contest here (in wheat format) for general consumption. Expect more to come.
In this post we detail how to install node on Mac, Ubuntu, and Windows.

Mac

If you're using the excellent homebrew package manager, you can install node with one command: brew install node.
Otherwise, follow the below steps:
  1. Install Xcode.
  2. Install git.
  3. Run the following commands:
darwin_setup.sh
git clone git://github.com/ry/node.git cd node ./configure make sudo make install
You can check it worked with a simple Hello, World! example.

Ubuntu

  1. Install the dependencies:
    • sudo apt-get install g++ curl libssl-dev apache2-utils
    • sudo apt-get install git-core
  2. Run the following commands:
ubuntu_setup.sh
git clone git://github.com/ry/node.git cd node ./configure make sudo make install
 Step 3 - Install NPM
Simply run the NPM install script:
curl http://npmjs.org/install.sh | sudo sh
And then check it works:
npm -v
You can check it worked with a simple Hello, World! example.
Thanks to code-diesel for the Ubuntu dependencies.

Windows

Currently, you must use cygwin to install node. To do so, follow these steps:
  1. Install cygwin.
  2. Use setup.exein the cygwin folder to install the following packages:
    • devel → openssl
    • devel → g++-gcc
    • devel → make
    • python → python
    • devel → git
  3. Open the cygwin command line with Start > Cygwin > Cygwin Bash Shell.
  4. Run the below commands to download and build node.
cygwin_setup.sh
git clone git://github.com/ry/node.git cd node ./configure make sudo make install
For more details, including information on troubleshooting, please see the GitHub wiki page.

Hello Node.js!

Here's a quick program to make sure everything is up and running correctly:
hello_node.js
var http = require('http'); http.createServer(function (req, res) {   res.writeHead(200, {'Content-Type': 'text/plain'});   res.end('Hello Node.js\n'); }).listen(8124, "127.0.0.1"); console.log('Server running at http://127.0.0.1:8124/');
Run the code with the node command line utility:
> node hello_node.js Server running at http://127.0.0.1:8124/ 
Now, if you navigate to http://127.0.0.1:8124/ in your browser, you should see a nice message.

Congrats!

You've installed node.js.

8 Practical PHP Regular Expressions

Validating a Username:
Quote: Something often overlooked, but simple to do with a regular expression would be username validation. For example, we may want our usernames to be between 4 and 28 characters in length, alpha-numeric, and allow underscores. PHP Code: $string = "userNaME4234432_";
if (preg_match('/^[a-z\d_]{4,28}$/i', $string)) {
echo "example 1 successful.";
}
Telephone Numbers:
Quote: Number in the following form: (###) ###-#### PHP Code: $string = "(232) 555-5555";
if (preg_match('/^(\(?[0-9]{3,3}\)?|[0-9]{3,3}[-. ]?)[ ][0-9]{3,3}[-. ]?[0-9]{4,4}$/', $string)) {
echo "example 2 successful.";
}
Emails:
PHP Code: $string = "first.last@domain.co.uk";
if (preg_match(
'/^[^0-9][a-zA-Z0-9_]+([.][a-zA-Z0-9_]+)*[@][a-zA-Z0-9_]+([.][a-zA-Z0-9_]+)*[.][a-zA-Z]{2,4}$/',
$string)) {
echo "example 3 successful.";
}
Postal Codes:
PHP Code: $string = "55324-4324";
if (preg_match('/^[0-9]{5,5}([- ]?[0-9]{4,4})?$/', $string)) {
echo "example 4 successful.";
}
Ip Address:
PHP Code: $string = "255.255.255.0";
if (preg_match(
'^(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:[.](?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}$',
$string)) {
echo "example 5 successful.";
}
Hexadecimal Colors:
PHP Code: $string = "#666666";
if (preg_match('/^#(?:(?:[a-f\d]{3}){1,2})$/i', $string)) {
echo "example 6 successful.";
}
Multi-line Comments:
PHP Code: $string = "/* commmmment */";
if (preg_match('/^[(/*)+.+(*/)]$/', $string)) {
echo "example 7 successful.";
}
Dates:
Quote: MM/DD/YYYY format PHP Code: $string = "10/15/2007";
if (preg_match('/^\d{1,2}\/\d{1,2}\/\d{4}$/', $string)) {
echo "example 8 successful.";
}
Some might be more/less useful than the others but that will depend on the project you are working on.

Cropping Images using PHP

This script will allow you to make a smaller image of a bigger image, but at the same time crop it. This will prevent the image looking stretched and deformed.
We will create this using a class (Sorry using PHP 4 at the moment, but should work on 5)
Firstly lets set up the class.
PHP Code: class cropImage{
//code here
}
Now we need to set up some variables to be used throughout the program.
PHP Code: var $imgSrc,$myImage,$cropHeight,$cropWidth,$x,$y,$thumb;
The variables above will be explained once we use them. Now we need to create the first function. This function will get the image we are going to crop, work out its dimension and then use them dimensions to work out how we are going to crop it.
PHP Code:
function setImage($image)
{
//Your Image
$this->imgSrc = $image;
//getting the image dimensions
list($width, $height) = getimagesize($this->imgSrc);
//create image from the jpeg
this->myImage = imagecreatefromjpeg($this->imgSrc) or die("Error: Cannot find image!");
if($width > $height) $biggestSide = $width; //find biggest length
else $biggestSide = $height;
//The crop size will be half that of the largest side
$cropPercent = .5; // This will zoom in to 50% zoom (crop)
$this->cropWidth   = $biggestSide*$cropPercent;
$this->cropHeight  = $biggestSide*$cropPercent;
//getting the top left coordinate
$this->x = ($width-$this->cropWidth)/2;
$this->y = ($height-$this->cropHeight)/2;
}
Now we actually need to start creating the actual cropped image.
PHP Code: function createThumb()
{
$thumbSize = 250; // will create a 250 x 250 thumb
$this->thumb = imagecreatetruecolor($thumbSize, $thumbSize);
imagecopyresampled($this->thumb, $this->myImage, 0, 0,$this->x, $this->y, $thumbSize, $thumbSize, $this->cropWidth, $this->cropHeight);
}
Now all we need to do is render the image out.
PHP Code: function renderImage()
{
header('Content-type: image/jpeg');
imagejpeg($this->thumb);
imagedestroy($this->thumb);
}
Now we just need to create the instance
PHP Code: $image = new cropImage;
$image->setImage($src);
$image->createThumb();
$image->renderImage();
You can use this script to display a thumb of images on a new page, by using the following page.
PHP Code: <img src="thumbcreate.php?src=images/largimg.jpg"> //link to large image

Test Credit Card Account Numbers

While testing, use only the credit card numbers listed here. Other numbers produce an error.
Expiration Date must be a valid date in the future (use the mmyy format).

Test Credit Card Account Numbers

Credit Card TypeCredit Card Number
American Express378282246310005
American Express371449635398431
American Express Corporate378734493671000
Australian BankCard5610591081018250
Diners Club30569309025904
Diners Club38520000023237
Discover6011111111111117
Discover6011000990139424
JCB3530111333300000
JCB3566002020360505
MasterCard5555555555554444
MasterCard5105105105105100
Visa4111111111111111
Visa4012888888881881
Visa4222222222222
Note : Even though this number has a different character count than the other test numbers, it is the correct and functional number.
Processor-specific Cards
Dankort (PBS)76009244561
Dankort (PBS)5019717010103742
Switch/Solo (Paymentech)6331101999990016