Skip to content

Commit

Permalink
#18 - Rewrite {COOKBOOK_EDIT} shortcode to allow for more options
Browse files Browse the repository at this point in the history
  • Loading branch information
Moc committed Aug 16, 2022
1 parent 301c446 commit 1491534
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 7 deletions.
45 changes: 39 additions & 6 deletions cookbook_shortcodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,14 +286,47 @@ function sc_cookbook_instructions($parm = array())
return e107::getParser()->toHTML($this->var["r_instructions"], TRUE);
}


/**
* Renders edit link for a specific recipe
*
* @param string $class - a custom class for the <a> tag
* @param string $icon - FontAwesome icon to use
* @param string $type - link or icon (default is 'link')
*
*
* @example {COOKBOOK_EDIT: class=btn btn-default}
* @example {COOKBOOK_EDIT: type=icon}
* @example {COOKBOOK_EDIT: type=icon&icon=fa pencil}
*
*/
function sc_cookbook_edit($parm = array())
{
if(check_class(e107::getPlugPref('cookbook', 'submission_userclass')))
{
$link = e_PLUGIN_ABS.'cookbook/admin_config.php?action=edit&id='.$this->var["r_id"].'';
return '<li><i class="fa-li fa fa-pencil"></i> <a href="'.$link.'">'.LAN_EDIT.'</a></li>';
}
return;
// Check permissions
if(!check_class(e107::getPlugPref('cookbook', 'submission_userclass')))
{
return;
}

// Set class
$class = (!empty($parm['class'])) ? $parm['class'] : '';


// Set icon
$icon = (!empty($parm['icon'])) ? $parm['icon'] : '';

// Set type
$type = (!empty($parm['type'])) ? $parm['type'] : 'link';


$url = e_PLUGIN_ABS.'cookbook/admin_config.php?action=edit&id='.$this->var["r_id"].'';

if($parm['type'] == "icon" && !empty($icon))
{
return '<a class="'.$class.'" href="'.$url.'">'.e107::getParser()->toGlyph($icon).'</a>';
}

return '<a class="'.$class.'" href="'.$url.'">'.LAN_EDIT.'</a>';
}

function sc_cookbook_bookmark($parm = '')
Expand Down
2 changes: 1 addition & 1 deletion templates/cookbook_template.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
<h3>{LAN=LAN_CB_ACTIONS}</h3>
<ul class="fa-ul">
{COOKBOOK_BOOKMARK}
{COOKBOOK_EDIT}
<li><i class="fa-li fa fa-pencil"></i> {COOKBOOK_EDIT}</li>
{COOKBOOK_PRINT}
</ul>
</div>
Expand Down

0 comments on commit 1491534

Please sign in to comment.