Javascript : Sprintf Function

var sprintf = function(str) {
var args = arguments,
flag = true,
i = 1;
str = str.replace(/%s/g, function() {
var arg = args[i++];
if (typeof arg === ‘undefined’) {
flag = false;
return ”;
}
return arg;
});
return flag ? str : ”;
};

zf2 : Show buttons according to user role

    
    $url['action'] = "edit";
            $url['id'] = $val['action']['id'];
            $edit = $this->url()->fromRoute("email-content", $url);
            $url['action'] = "edit-content";
            $editCont = $this->url()->fromRoute("email-content", $url);
            $action = getActionHtml(array(
                        'edit' => array(
                            'url' => $edit,
                            'button_class' => 'btn-info',
                            'icon' => 'fa-pencil',
                            'title' => 'Edit'
                        ),
                        'edit-cont' => array(
                            'url' => $editCont,
                            'button_class' => 'btn-info',
                            'icon' => 'fa-pencil',
                            'title' => 'Edit Content'
                        )
            ));


    /**
     * get button html according to role
     * @param array $params
     * @param string $sap [optional]
     * @return html
     */
    public static function getActionHtml($params, $sap = ' ') {
        $links = array();

        foreach ($params as $param) {
            if (!isset($params['title'])) {
                $params['title'] = '';
            }
            $links[] = self::getActionLink($param);
        }

        $response = '
' .                 implode($sap, $links) .                 '
';         return $response;     }          /**      * Get html anchor link from array      * @param array $params      * @return boolean | html      */     public static function getActionLink($params) {         $target = "";         if (isset($params['target'])) {             $target = $params['target'];         }         if (self::isUrlAllow($params['url'])) {             return '<a href="' . $params['url'] . '"  target="' . $target . '">' .                     '<button class="btn btn-xs ' . $params['button_class'] . '">' .                     '<i class="ace-icon fa  ' . $params['icon'] . ' bigger-120"></i>' . $params['title'] .                     '</button>' .                     '</a>';         }         return false;     }          /**      * get action and controller name from url      * @param string $url      * @return array      */     public static function getRoutsFormUrl($url = "") {         $request = new \Zend\Http\Request();         $request->setUri($url);         $router = self::getServiceLocator()->get('Router');         $routeMatch = $router->match($request);         $return = false;         if ($routeMatch) {             $temp[] = $routeMatch->getParam('__NAMESPACE__');             $temp[] = $routeMatch->getParam('controller');             $return['controller'] = join("\\", $temp);             $return['action'] = $routeMatch->getParam('action');         }         return $return;     }          /**      * It is checking the give url is accesible to current user or not      * @param string $url      * @return boolean      */     public static function isUrlAllow($url = "") {         $routs = self::getRoutsFormUrl($url);         if ($routs == false) {             return false;         }         if (self::$permissions == null || !array_key_exists($routs['controller'], self::$permissions)) {             self::getPermissions($routs['controller']);         }         if (array_key_exists($routs['controller'], self::$permissions)) {             if (in_array($routs['action'], self::$permissions[$routs['controller']])) {                 return true;             }         }         return false;     }     /**      * set permissions into $permission variable from table      * @param string $controller [optional]      * @return void      */     public static function getPermissions($controller = "") {         $user = self::getCurrentUser();         if (!$user) {             return false;         }         $em = self::getEntityManager();         $data = Array(                     'Application\Controller\Developer' => Array('0' => 'add-permission'),                     'Application\Controller\EmailContent' => Array(                             '0' => 'index'                             '1' => 'add'                             '2' => 'edit'                             '3' => 'edit-content'                         )         );                  if (count($data) > 0) {             if (self::$permissions == null) {                 self::$permissions = $data;             } else {                 self::$permissions = array_merge(self::$permissions, $data);             }         }     }