diff --git a/libraries/Template.class.php b/libraries/Template.class.php
index ba4ca61c8d..49c60d48c7 100644
--- a/libraries/Template.class.php
+++ b/libraries/Template.class.php
@@ -8,7 +8,7 @@ if (! defined('PHPMYADMIN')) {
/**
* Class Template
*
- * Handle template using
+ * Handle front end templating
*
* @package PMA
*/
@@ -41,6 +41,20 @@ class Template
return new Template($name);
}
+ /**
+ * Remove whitespaces between tags and innerHTML
+ *
+ * @param string $content HTML to perform the trim method
+ *
+ * @return string
+ */
+ public static function trim($content)
+ {
+ $regexp = '/(<[^\/][^>]+>)\s+|\s+(<\/)/';
+
+ return preg_replace($regexp, "$1$2", $content);
+ }
+
/**
* Render template
*
@@ -48,9 +62,9 @@ class Template
*
* @return string
*/
- public function render($data = array())
+ public function render($data = array(), $trim = true)
{
- $template = static::BASE_PATH . $this->name . '.php';
+ $template = static::BASE_PATH . $this->name . '.phtml';
try {
extract($data);
ob_start();
@@ -61,11 +75,16 @@ class Template
'The template "' . $template . '" not found.'
);
}
- $content = ob_get_clean();
+ if ($trim) {
+ $content = Template::trim(ob_get_clean());
+ } else {
+ $content = ob_get_clean();
+ }
+
return $content;
} catch (\LogicException $e) {
ob_end_clean();
throw new \LogicException($e->getMessage());
}
}
-}
\ No newline at end of file
+}
diff --git a/libraries/browse_foreigners.lib.php b/libraries/browse_foreigners.lib.php
index c47ca23bbd..1de6a01f23 100644
--- a/libraries/browse_foreigners.lib.php
+++ b/libraries/browse_foreigners.lib.php
@@ -9,20 +9,108 @@ if (! defined('PHPMYADMIN')) {
exit;
}
+/**
+ * Function to get html for one relational key
+ *
+ * @param integer $horizontal_count the current horizontal count
+ * @param string $header table header
+ * @param boolean $odd_row for the row background color
+ * @param array $keys all the keys
+ * @param integer $indexByKeyname index by keyname
+ * @param array $descriptions descriptions
+ * @param integer $indexByDescription index by description
+ * @param string $current_value current value on the edit form
+ *
+ * @return string $html the generated html
+ */
+function PMA_getHtmlForOneKey($horizontal_count, $header, $odd_row, $keys,
+ $indexByKeyname, $descriptions, $indexByDescription, $current_value
+) {
+ $horizontal_count++;
+ $output = '';
+
+ // whether the key name corresponds to the selected value in the form
+ $rightKeynameIsSelected = false;
+ $leftKeynameIsSelected = false;
+
+ if ($GLOBALS['cfg']['RepeatCells'] > 0
+ && $horizontal_count > $GLOBALS['cfg']['RepeatCells']
+ ) {
+ $output .= $header;
+ $horizontal_count = 0;
+ $odd_row = true;
+ }
+
+ // key names and descriptions for the left section,
+ // sorted by key names
+ $leftKeyname = $keys[$indexByKeyname];
+ list(
+ $leftDescription,
+ $leftDescriptionTitle
+ ) = PMA_getDescriptionAndTitle($descriptions[$indexByKeyname]);
+
+ // key names and descriptions for the right section,
+ // sorted by descriptions
+ $rightKeyname = $keys[$indexByDescription];
+ list(
+ $rightDescription,
+ $rightDescriptionTitle
+ ) = PMA_getDescriptionAndTitle($descriptions[$indexByDescription]);
+
+ $indexByDescription++;
+
+ if (! empty($current_value)) {
+ $rightKeynameIsSelected = $rightKeyname == $current_value;
+ $leftKeynameIsSelected = $leftKeyname == $current_value;
+ }
+
+ $output .= '
';
+ $odd_row = ! $odd_row;
+
+ $output .= PMA_getHtmlForColumnElement(
+ 'class="nowrap"', $leftKeynameIsSelected,
+ $leftKeyname, $leftDescription,
+ $leftDescriptionTitle
+ );
+
+ $output .= PMA_getHtmlForColumnElement(
+ '', $leftKeynameIsSelected, $leftKeyname,
+ $leftDescription, $leftDescriptionTitle
+ );
+
+ $output .= ''
+ . ' | ';
+
+ $output .= PMA_getHtmlForColumnElement(
+ '', $rightKeynameIsSelected, $rightKeyname,
+ $rightDescription, $rightDescriptionTitle
+ );
+
+ $output .= PMA_getHtmlForColumnElement(
+ 'class="nowrap"', $rightKeynameIsSelected,
+ $rightKeyname, $rightDescription,
+ $rightDescriptionTitle
+ );
+ $output .= '
';
+
+ return array($output, $horizontal_count, $odd_row, $indexByDescription);
+}
+
/**
* Function to get html for relational field selection
*
- * @param string $db current database
- * @param string $table current table
- * @param string $field field
- * @param array $foreignData foreign column data
- * @param string $fieldkey field key
- * @param array $data data
+ * @param string $db current database
+ * @param string $table current table
+ * @param string $field field
+ * @param array $foreignData foreign column data
+ * @param string $fieldkey field key
+ * @param string $current_value current columns's value
*
* @return string
*/
function PMA_getHtmlForRelationalFieldSelection($db, $table, $field, $foreignData,
- $fieldkey, $data
+ $fieldkey, $current_value
) {
$gotopage = PMA_getHtmlForGotoPage($foreignData);
$showall = PMA_getHtmlForShowAll($foreignData);
@@ -93,78 +181,23 @@ function PMA_getHtmlForRelationalFieldSelection($db, $table, $field, $foreignDat
asort($keys);
- $hcount = 0;
+ $horizontal_count = 0;
$odd_row = true;
$indexByDescription = 0;
- // whether the key name corresponds to the selected value in the form
- $rightKeynameIsSelected = false;
- $leftKeynameIsSelected = false;
-
foreach ($keys as $indexByKeyname => $value) {
- $hcount++;
-
- if ($GLOBALS['cfg']['RepeatCells'] > 0
- && $hcount > $GLOBALS['cfg']['RepeatCells']
- ) {
- $output .= $header;
- $hcount = 0;
- $odd_row = true;
- }
-
- // key names and descriptions for the left section,
- // sorted by key names
- $leftKeyname = $keys[$indexByKeyname];
list(
- $leftDescription,
- $leftDescriptionTitle
- ) = PMA_getDescriptionAndTitle($descriptions[$indexByKeyname]);
-
- // key names and descriptions for the right section,
- // sorted by descriptions
- $rightKeyname = $keys[$indexByDescription];
- list(
- $rightDescription,
- $rightDescriptionTitle
- ) = PMA_getDescriptionAndTitle($descriptions[$indexByDescription]);
-
- $indexByDescription++;
-
- if (! empty($data)) {
- $rightKeynameIsSelected = $rightKeyname == $data;
- $leftKeynameIsSelected = $leftKeyname == $data;
- }
-
- $output .= '';
- $odd_row = ! $odd_row;
-
- $output .= PMA_getHtmlForColumnElement(
- 'class="nowrap"', $leftKeynameIsSelected,
- $leftKeyname, $leftDescription,
- $leftDescriptionTitle
+ $html,
+ $horizontal_count,
+ $odd_row,
+ $indexByDescription
+ ) = PMA_getHtmlForOneKey(
+ $horizontal_count, $header, $odd_row, $keys, $indexByKeyname,
+ $descriptions, $indexByDescription, $current_value
);
+ $output .= $html;
+ }
- $output .= PMA_getHtmlForColumnElement(
- '', $leftKeynameIsSelected, $leftKeyname,
- $leftDescription, $leftDescriptionTitle
- );
-
- $output .= ''
- . ' | ';
-
- $output .= PMA_getHtmlForColumnElement(
- '', $rightKeynameIsSelected, $rightKeyname,
- $rightDescription, $rightDescriptionTitle
- );
-
- $output .= PMA_getHtmlForColumnElement(
- 'class="nowrap"', $rightKeynameIsSelected,
- $rightKeyname, $rightDescription,
- $rightDescriptionTitle
- );
- $output .= '
';
- } // end while
$output .= ''
. '';
diff --git a/libraries/db_designer.lib.php b/libraries/db_designer.lib.php
index 7b2fcca10d..2fdee51b61 100644
--- a/libraries/db_designer.lib.php
+++ b/libraries/db_designer.lib.php
@@ -10,6 +10,7 @@ if (! defined('PHPMYADMIN')) {
}
require_once 'libraries/relation.lib.php';
+require_once 'libraries/Template.class.php';
/**
* Function to get html to display a page selector
@@ -21,17 +22,10 @@ require_once 'libraries/relation.lib.php';
*/
function PMA_getHtmlForPageSelector($cfgRelation, $db)
{
- $html = '';
- return $html;
+ return PMA\Template::get('designer/page_selector')->render(array(
+ 'db' => $db,
+ 'cfgRelation' => $cfgRelation
+ ));
}
/**
@@ -44,23 +38,10 @@ function PMA_getHtmlForPageSelector($cfgRelation, $db)
*/
function PMA_getHtmlForEditOrDeletePages($db, $operation)
{
- $cfgRelation = PMA_getRelationsParam();
- $html = '';
- return $html;
+ return PMA\Template::get('designer/edit_delete_pages')->render(array(
+ 'db' => $db,
+ 'operation' => $operation
+ ));
}
/**
@@ -72,43 +53,9 @@ function PMA_getHtmlForEditOrDeletePages($db, $operation)
*/
function PMA_getHtmlForPageSaveAs($db)
{
- $cfgRelation = PMA_getRelationsParam();
- $choices = array(
- 'same' => __('Save to selected page'),
- 'new' => __('Create a page and save to it')
- );
-
- $html = '';
-
- return $html;
+ return PMA\Template::get('designer/page_save_as')->render(array(
+ 'db' => $db
+ ));
}
/**
@@ -161,22 +108,11 @@ function PMA_getHtmlForSchemaExport($db, $page)
)->getDisplay();
}
- $htmlString = '';
-
- return $htmlString;
+ return PMA\Template::get('designer/schema_export')->render(array(
+ 'db' => $db,
+ 'page' => $page,
+ 'export_list' => $export_list
+ ));
}
/**
@@ -192,34 +128,12 @@ function PMA_getHtmlForSchemaExport($db, $page)
function PMA_getHtmlForJSFields(
$script_tables, $script_contr, $script_display_field, $display_page
) {
- $cfgRelation = PMA_getRelationsParam();
-
- $html = '';
- $html .= htmlspecialchars($GLOBALS['server']);
- $html .= '
';
- $html .= '';
- $html .= htmlspecialchars($_GET['db']);
- $html .= '
';
- $html .= '';
- $html .= htmlspecialchars($_GET['token']);
- $html .= '
';
- $html .= '';
- $html .= htmlspecialchars(json_encode($script_tables));
- $html .= '
';
- $html .= '';
- $html .= htmlspecialchars(json_encode($script_contr));
- $html .= '
';
- $html .= '';
- $html .= htmlspecialchars(json_encode($script_display_field));
- $html .= '
';
- $html .= '';
- $html .= htmlspecialchars($display_page);
- $html .= '
';
- $html .= '';
- $html .= htmlspecialchars($cfgRelation['pdfwork']);
- $html .= '
';
-
- return $html;
+ return PMA\Template::get('designer/js_fields')->render(array(
+ 'script_tables' => $script_tables,
+ 'script_contr' => $script_contr,
+ 'script_display_field' => $script_display_field,
+ 'display_page' => $display_page
+ ));
}
/**
@@ -232,207 +146,10 @@ function PMA_getHtmlForJSFields(
*/
function PMA_getDesignerPageMenu($visualBuilder, $selected_page)
{
- $iconClass = '';
- $textClass = 'hidable hide';
-
- $html = '';
-
- if (!$visualBuilder) {
- $html .= '';
- $html .= '';
- $html .= ($selected_page == null
- ? __("Untitled")
- : htmlspecialchars($selected_page));
- $html .= '';
- $html .= '';
- $html .= ($selected_page == null ? '*' : '') . '';
- $html .= '
';
- }
-
- $html .= '';
-
- return $html;
+ return PMA\Template::get('designer/side_menu')->render(array(
+ 'visualBuilder' => $visualBuilder,
+ 'selected_page' => $selected_page
+ ));
}
/**
@@ -442,12 +159,7 @@ function PMA_getDesignerPageMenu($visualBuilder, $selected_page)
*/
function PMA_getHTMLCanvas()
{
- $html = '';
- $html .= '