Skip to content

Commit

Permalink
minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
shakty committed Oct 16, 2013
1 parent 153b0d1 commit a679eaf
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 17 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
~*
_*
\#*
.\#*
*~
4 changes: 2 additions & 2 deletions includes/constants.inc
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
* Patterns Client constants.
*/


define('PATTERNS_CLIENT_SERVER', 'http://drupal-patterns.org/');
define('PATTERNS_CLIENT_SERVER', 'http://drupal-patterns.org');
define('PATTERNS_CLIENT_SERVER_XMLRPC', PATTERNS_CLIENT_SERVER . 'xmlrpc.php');
define('PATTERNS_CLIENT_CREDENTIALS', 'patterns_client_credentials');


Expand Down
19 changes: 16 additions & 3 deletions includes/io.inc
Original file line number Diff line number Diff line change
Expand Up @@ -220,17 +220,30 @@ function patterns_client_push_patterns($patterns) {
* @return array List of patterns currently stored in the server
*/
function _patterns_client_get_patterns_server_list($limit) {
// Get the current server
$url = variable_get('patterns_client_server', PATTERNS_CLIENT_SERVER);

$info = patterns_client_check_credentials_and_display_warns();

if ($info['ready'] === FALSE) {
return;
}

$url = $info['url'];
$credentials = $info['credentials'];

$friend = d2d_api_friend_get_by_url($url);
// Prepare arguments for the call. In this case just the maximum number of patterns expected


// Prepare arguments for the call. In this case just the maximum number of patterns expected
$post = array(
'limit' => $limit,
);


// Send the request. We explode the result in two different steps
$error_string = '';
$result = d2d_call_secure_rpc($friend, 'patterns_server_get_patterns_list', $post, $error_string);
$result = d2d_explode($result);

// Display communication errors if any
if (!$result) {
drupal_set_message(t('No response from the server. Are you friends with it?'), 'warning');
Expand Down
71 changes: 71 additions & 0 deletions includes/util.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

/**
* @file
* Provides utils for the own module or for developers.
*/

/**
* Display information regarding current
*
* Uses _drupal_set_message_ to display links to the configuration page.
*
* @return bool|array
* Associative array with url of server and credentials, or FALSE if they
* are not set correctly.
*/
function patterns_client_check_credentials_and_display_warns() {

$out = array(
'url' => FALSE,
'credentials' => FALSE,
'friend' => FALSE,
'ready' => FALSE,
);

// Get the current server.
$url = variable_get('patterns_client_server');

if (empty($url)) {
drupal_set_message(t('You are not registered to any Patterns server.'), 'warning');
drupal_set_message(t('Check the Patterns Client !configuration.', array(
'!configuration' => l(t('configuration'), 'admin/patterns/share'),
)));
return $out;
}
else {
$out['url'] = $url;
$friend = d2d_api_friend_get_by_url($url);
if (empty($friend)) {
$pserver_link = l(t('Patterns server'), $url, array(
'attributes' => array('target'=>'_blank'),
));
drupal_set_message(t('You are currently not friend with !server.',
array( '!server' => $pserver_link )), 'warning');
drupal_set_message(t('Check the Patterns Client !configuration.', array(
'!configuration' => l(t('configuration'), 'admin/patterns/share'),
)));
}
else {
$out['friend'] = TRUE;

$credentials = patterns_client_get_full_credentials($url);

if (empty($credentials)) {
$pserver_link = l(t('Patterns server'), $url, array(
'attributes' => array('target'=>'_blank'),
));
drupal_set_message(t('You have not registered a username on the !server yet.',
array( '!server' => $pserver_link )), 'warning');
drupal_set_message(t('Check the Patterns Client !configuration.', array(
'!configuration' => l(t('configuration'), 'admin/patterns/share'),
)));
}
else {
$out['credentials'] = $credentials;
$out['ready'] = TRUE;
}
}
}
return $out;
}
2 changes: 1 addition & 1 deletion patterns_client.info
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ description = Allows the exchange (push/pull) of pattern files from any site run
core = 7.x

package = Patterns
dependencies[] = patterns (>=7.x-2.0)
dependencies[] = patterns (>=7.x-2.x)
dependencies[] = d2d
42 changes: 31 additions & 11 deletions patterns_client.module
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function patterns_client_menu() {
);
// Add new sub tab with search and list as default
$items['admin/patterns/remote/search'] = array(
'title' => 'Patterns at Server',
'title' => 'Remote Search',
'page callback' => 'drupal_get_form',
'page arguments' => array('patterns_client_search_form'),
'access arguments' => array('administer patterns'),
Expand All @@ -45,7 +45,7 @@ function patterns_client_menu() {
$items['admin/patterns/remote/subscriptions'] = array(
'title' => 'Subscriptions',
'page callback' => 'drupal_get_form',
'page arguments' => array('patterns_client_search_form'),
'page arguments' => array('patterns_client_subscription_form'),
'access arguments' => array('administer patterns'),
'type' => MENU_LOCAL_TASK,
);
Expand Down Expand Up @@ -124,14 +124,13 @@ function patterns_client_fetch_pattern($pid) {

/**
* Implements hook_form().
* Generates a form to search for patterns in the server according to different criteria.
* The results are output in a table as part of the form itself. Depending on the existence
* or not of arguments, a different function will be called:
*
* Generates a form to search for patterns in the server according to
* different criteria.
* The results are output in a table as part of the form itself. Depending
* on the existence or not of arguments, a different function will be called:
* - No arguments: returns the whole list of patterns stored in the server.
* - Search: returns only the patterns that match the given criteria.
* @param $form
* @param $form_state
* @return array Form to perform the search.
*/
function patterns_client_search_form($form, &$form_state) {
$form['patterns_search']= array(
Expand All @@ -142,7 +141,10 @@ function patterns_client_search_form($form, &$form_state) {
'#type' => 'textfield',
'#title' => t('Search'),
'#size' => 15,
'#attributes' => array('title' => t('Enter the terms you wish to search for.'), 'class' => array('container-inline')),
'#attributes' => array(
'title' => t('Enter the terms you wish to search for.'),
'class' => array('container-inline'),
),
);
$form['patterns_search']['selected'] = array(
'#type' => 'select',
Expand All @@ -157,9 +159,13 @@ function patterns_client_search_form($form, &$form_state) {
),
);
$form['patterns_search']['actions'] = array('#type' => 'actions');
$form['patterns_search']['actions']['submit'] = array('#type' => 'submit', '#value' => t('Search'));
$form['patterns_search']['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Search'),
);
$form['patterns_search']['#submit'][] = 'patterns_client_search_form_submit';
// Retrieve the whole list if no arguments are given, perform a search otherwise

// Retrieve the whole list if no arguments are given, else perform a search.
$patterns_list = array();
if (!isset($form_state['input']['patterns_list'])) {
$patterns_list = _patterns_client_get_patterns_server_list(10000);
Expand Down Expand Up @@ -245,6 +251,20 @@ function patterns_client_search_form_submit($form, &$form_state) {
$form_state['rebuild'] = TRUE;
}

/**
* Implements hook_form().
*
*/
function patterns_client_subscription_form($form, &$form_state) {
$notice = t('Subscriptions are not yet implemented. Your contribution is welcome...');
drupal_set_message($notice, 'warning');
$form['subscriptions']= array(
'#markup' => '<p>' . $notice . '</p>',
);
return $form;
}


/**
* Implements hook_form_submit().
* Secondary function, to return to the search page without providing any parameters.
Expand Down

0 comments on commit a679eaf

Please sign in to comment.