Skip to content

Commit

Permalink
Mobile Theme added, refs zikula#436.
Browse files Browse the repository at this point in the history
  • Loading branch information
Phaidon authored and Drak committed Sep 9, 2012
1 parent 6c3b720 commit bc713a7
Show file tree
Hide file tree
Showing 39 changed files with 1,013 additions and 19 deletions.
13 changes: 12 additions & 1 deletion src/lib/util/UserUtil.php
Expand Up @@ -1896,9 +1896,20 @@ public static function getTheme($force = false)
if (isset($theme) && !$force) {
return $theme;
}

if (CookieUtil::getCookie('zikulaMobileTheme') == '1' && ModUtil::getVar('Theme', 'enable_mobile_theme', false)) {
$pagetheme = 'Mobile';
} else if (CookieUtil::getCookie('zikulaMobileTheme') != '2' && ModUtil::getVar('Theme', 'enable_mobile_theme', false)) {
include_once("system/Theme/lib/vendor/Mobile_Detect.php");
$detect = new Mobile_Detect();
if ($detect->isMobile()) {
$pagetheme = 'Mobile';
}
} else {
$pagetheme = FormUtil::getPassedValue('theme', null, 'GETPOST');
}

// Page-specific theme
$pagetheme = FormUtil::getPassedValue('theme', null, 'GETPOST');
$type = FormUtil::getPassedValue('type', null, 'GETPOST');
$qstring = System::serverGetVar('QUERY_STRING');
if (!empty($pagetheme)) {
Expand Down
23 changes: 9 additions & 14 deletions src/lib/viewplugins/function.button.php
Expand Up @@ -82,14 +82,8 @@ function smarty_function_button($params, Zikula_View $view)
// we're going to make use of pnimg for path searching
require_once $view->_get_plugin_filepath('function', 'img');

if (!isset($params['src'])) {
$view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('smarty_function_button', 'src')));

return false;
}
if (!isset($params['set'])) {
if (isset($params['src']) && !isset($params['set'])) {
$view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('smarty_function_button', 'set')));

return false;
}
$type = isset($params['type']) ? $params['type'] : 'submit';
Expand Down Expand Up @@ -124,16 +118,17 @@ function smarty_function_button($params, Zikula_View $view)
$alt = (isset($params['alt']) ? $params['alt'] : '');

// call the pnimg plugin and work out the src from the assigned template vars
smarty_function_img(array('assign' => 'buttonsrc', 'src' => $params['src'], 'set' => $params['set'], 'modname' => 'core'), $view);
$imgvars = $view->get_template_vars('buttonsrc');
$imgsrc = $imgvars['src'];
if (isset($params['src'])) {
smarty_function_img(array('assign' => 'buttonsrc', 'src' => $params['src'], 'set' => $params['set'], 'modname' => 'core'), $view);
$imgvars = $view->get_template_vars('buttonsrc');
$imgsrc = $imgvars['src'];
$img = '<img src="'.DataUtil::formatForDisplay($imgsrc).'" alt="'.DataUtil::formatForDisplay($alt).'" />';
}

// form the button html
if ($mode == 'button') {
$return = '<button'.$id.$class.' type="'.DataUtil::formatForDisplay($type).
'"'.$name.$value.' title="'.DataUtil::formatForDisplay($title).'"><img src="'.
DataUtil::formatForDisplay($imgsrc).'" alt="'.DataUtil::formatForDisplay($alt).
'" />'.$text.'</button>';
'"'.$name.$value.' title="'.DataUtil::formatForDisplay($title).'">'.$img.$text.'</button>';
} else {
$return = '<input'.$id.$class.' type="image"'.$name.$value.' title="'.
DataUtil::formatForDisplay($title).'" src="'.DataUtil::formatForDisplay($imgsrc).
Expand All @@ -145,4 +140,4 @@ function smarty_function_button($params, Zikula_View $view)
} else {
return $return;
}
}
}
3 changes: 3 additions & 0 deletions src/system/Theme/lib/Theme/Controller/Admin.php
Expand Up @@ -1152,6 +1152,9 @@ public function updateconfig($args)

$theme_change = (bool)FormUtil::getPassedValue('theme_change', isset($args['theme_change']) ? $args['theme_change'] : false, 'POST');
System::setVar('theme_change', $theme_change);

$enable_mobile_theme = (bool)FormUtil::getPassedValue('enable_mobile_theme', isset($args['enable_mobile_theme']) ? $args['enable_mobile_theme'] : false, 'POST');
$this->setVar('enable_mobile_theme', $enable_mobile_theme);

$itemsperpage = (int)FormUtil::getPassedValue('itemsperpage', isset($args['itemsperpage']) ? $args['itemsperpage'] : 25, 'POST');
if ($itemsperpage < 1) $itemsperpage = 25;
Expand Down
25 changes: 25 additions & 0 deletions src/system/Theme/lib/Theme/Controller/User.php
Expand Up @@ -86,4 +86,29 @@ public function resettodefault()
LogUtil::registerStatus($this->__('Done! Theme has been reset to the default site theme.'));
$this->redirect(ModUtil::url('Theme', 'user', 'main'));
}


/**
* Enable mobile Theme
*
* @return string html output
*/
public function enableMobileTheme()
{
CookieUtil::setCookie('zikulaMobileTheme', '1', time()+3600*24*365, '/');
return $this->redirect(System::getHomepageUrl());
}


/**
* Disable mobile Theme
*
* @return string html output
*/
public function disableMobileTheme()
{
CookieUtil::setCookie('zikulaMobileTheme', '2', time()+3600*24*365, '/');
return $this->redirect(System::getHomepageUrl());
}

}

0 comments on commit bc713a7

Please sign in to comment.