Check user is pro to use custom fonts

This commit is contained in:
Hillel Coren 2016-01-11 14:50:17 +02:00
parent 904627e5b4
commit cf24684adb
2 changed files with 21 additions and 17 deletions

View File

@ -908,15 +908,8 @@ class Account extends Eloquent
} }
public function getFontsUrl($protocol = ''){ public function getFontsUrl($protocol = ''){
if ($this->isPro()){ $bodyFont = $this->getHeaderFontId();
$bodyFont = $this->body_font_id; $headerFont = $this->getBodyFontId();
$headerFont = $this->header_font_id;
}
else{
$bodyFont = DEFAULT_BODY_FONT;
$headerFont = DEFAULT_HEADER_FONT;
}
$bodyFontSettings = Utils::getFromCache($bodyFont, 'fonts'); $bodyFontSettings = Utils::getFromCache($bodyFont, 'fonts');
$google_fonts = array($bodyFontSettings['google_font']); $google_fonts = array($bodyFontSettings['google_font']);
@ -929,16 +922,24 @@ class Account extends Eloquent
return ($protocol?$protocol.':':'').'//fonts.googleapis.com/css?family='.implode('|',$google_fonts); return ($protocol?$protocol.':':'').'//fonts.googleapis.com/css?family='.implode('|',$google_fonts);
} }
public function getHeaderFontId() {
return $this->isPro() ? $this->header_font_id : DEFAULT_HEADER_FONT;
}
public function getBodyFontId() {
return $this->isPro() ? $this->body_font_id : DEFAULT_BODY_FONT;
}
public function getHeaderFontName(){ public function getHeaderFontName(){
return Utils::getFromCache($this->header_font_id, 'fonts')['name']; return Utils::getFromCache($this->getHeaderFontId(), 'fonts')['name'];
} }
public function getBodyFontName(){ public function getBodyFontName(){
return Utils::getFromCache($this->body_font_id, 'fonts')['name']; return Utils::getFromCache($this->getBodyFontId(), 'fonts')['name'];
} }
public function getHeaderFontCss($include_weight = true){ public function getHeaderFontCss($include_weight = true){
$font_data = Utils::getFromCache($this->header_font_id, 'fonts'); $font_data = Utils::getFromCache($this->getHeaderFontId(), 'fonts');
$css = 'font-family:'.$font_data['css_stack'].';'; $css = 'font-family:'.$font_data['css_stack'].';';
if($include_weight){ if($include_weight){
@ -949,7 +950,7 @@ class Account extends Eloquent
} }
public function getBodyFontCss($include_weight = true){ public function getBodyFontCss($include_weight = true){
$font_data = Utils::getFromCache($this->body_font_id, 'fonts'); $font_data = Utils::getFromCache($this->getBodyFontId(), 'fonts');
$css = 'font-family:'.$font_data['css_stack'].';'; $css = 'font-family:'.$font_data['css_stack'].';';
if($include_weight){ if($include_weight){
@ -960,7 +961,7 @@ class Account extends Eloquent
} }
public function getFonts(){ public function getFonts(){
return array_unique(array($this->header_font_id, $this->body_font_id)); return array_unique(array($this->getHeaderFontId(), $this->getBodyFontId()));
} }
public function getFontsData(){ public function getFontsData(){

View File

@ -52,9 +52,12 @@
NINJA.primaryColor = $('#primary_color').val(); NINJA.primaryColor = $('#primary_color').val();
NINJA.secondaryColor = $('#secondary_color').val(); NINJA.secondaryColor = $('#secondary_color').val();
NINJA.fontSize = parseInt($('#font_size').val()); NINJA.fontSize = parseInt($('#font_size').val());
NINJA.headerFont = $('#header_font_id option:selected').text(); @if (Auth::user()->isPro())
NINJA.bodyFont = $('#body_font_id option:selected').text(); NINJA.headerFont = $('#header_font_id option:selected').text();
NINJA.bodyFont = $('#body_font_id option:selected').text();
@else
NINJA.headerFont = NINJA.bodyFont = 'Roboto';
@endif
var fields = ['item', 'description', 'unit_cost', 'quantity', 'line_total', 'terms']; var fields = ['item', 'description', 'unit_cost', 'quantity', 'line_total', 'terms'];
invoiceLabels.old = {}; invoiceLabels.old = {};
for (var i=0; i<fields.length; i++) { for (var i=0; i<fields.length; i++) {