Example #1
0
 /**
  * Load and get captcha
  *
  * @access  public
  * @param   object  $tpl            Jaws_Template object
  * @param   string  $tpl_base_block Template block name
  * @param   string  $field
  * @return  bool    True if captcha loaded successfully
  */
 function loadCaptcha(&$tpl, $tpl_base_block, $field = 'default')
 {
     if (!extension_loaded('gd')) {
         $GLOBALS['log']->Log(JAWS_LOG_ERROR, 'LoadCaptcha error: GD extension not loaded');
         return false;
     }
     $status = $this->gadget->registry->fetch($field . '_captcha_status');
     switch ($field) {
         case 'login':
             $bad_logins = (int) $GLOBALS['app']->Session->GetAttribute('bad_login_count');
             if ($status == 'DISABLED' || $bad_logins < (int) $status) {
                 return false;
             }
             break;
         default:
             if ($status == 'DISABLED' || $status == 'ANONYMOUS' && $GLOBALS['app']->Session->Logged()) {
                 return false;
             }
     }
     $dCaptcha = $this->gadget->registry->fetch($field . '_captcha_driver');
     $objCaptcha = Jaws_Captcha::getInstance($dCaptcha);
     $resCaptcha = $objCaptcha->get();
     if (empty($resCaptcha['key'])) {
         $tpl->SetBlock("{$tpl_base_block}/block_captcha");
         $tpl->SetVariable('lbl_captcha', $resCaptcha['label']);
         $tpl->SetVariable('captcha_title', $resCaptcha['title']);
         $tpl->SetVariable('captcha_text', $resCaptcha['text']);
         $tpl->ParseBlock("{$tpl_base_block}/block_captcha");
     } else {
         if (empty($resCaptcha['text'])) {
             $tpl->SetBlock("{$tpl_base_block}/image_captcha");
             $tpl->SetVariable('key', $resCaptcha['key']);
             $tpl->SetVariable('lbl_captcha', $resCaptcha['label']);
             $tpl->SetVariable('captcha_title', $resCaptcha['title']);
             $tpl->SetVariable('url', $this->gadget->urlMap('Captcha', array('field' => $field, 'key' => $resCaptcha['key'])));
             $tpl->SetVariable('description', $resCaptcha['description']);
             $tpl->SetVariable('entry_title', _t('GLOBAL_CAPTCHA_CASE_INSENSITIVE'));
             $tpl->ParseBlock("{$tpl_base_block}/image_captcha");
         } else {
             $tpl->SetBlock("{$tpl_base_block}/text_captcha");
             $tpl->SetVariable('key', $resCaptcha['key']);
             $tpl->SetVariable('lbl_captcha', $resCaptcha['label']);
             $tpl->SetVariable('captcha_title', $resCaptcha['title']);
             $tpl->SetVariable('captcha_text', $resCaptcha['text']);
             $tpl->SetVariable('description', $resCaptcha['description']);
             $tpl->SetVariable('entry_title', _t('GLOBAL_CAPTCHA_CASE_INSENSITIVE'));
             $tpl->ParseBlock("{$tpl_base_block}/text_captcha");
         }
     }
 }
Example #2
0
 /**
  * Get page navigation links
  *
  * @access  public
  * @param   object  $tpl
  * @param   string  $base_block
  * @param   int     $page       page number
  * @param   int     $page_size  Entries count per page
  * @param   int     $total      Total entries count
  * @param   string  $total_string
  * @param   string  $action     Action name
  * @param   array   $params     Action params array
  * @return  string  XHTML template content
  */
 function GetPagesNavigation(&$tpl, $base_block, $page, $page_size, $total, $total_string, $action, $params = array())
 {
     $pager = $this->GetNumberedPagesNavigation($page, $page_size, $total);
     if (count($pager) > 0) {
         $tpl->SetBlock("{$base_block}/pager");
         $tpl->SetVariable('total', $total_string);
         foreach ($pager as $k => $v) {
             $tpl->SetBlock("{$base_block}/pager/item");
             $params['page'] = $v;
             if ($k == 'next') {
                 if ($v) {
                     $tpl->SetBlock("{$base_block}/pager/item/next");
                     $tpl->SetVariable('lbl_next', _t('GLOBAL_NEXTPAGE'));
                     $url = $this->gadget->urlMap($action, $params);
                     $tpl->SetVariable('url_next', $url);
                     $tpl->ParseBlock("{$base_block}/pager/item/next");
                 } else {
                     $tpl->SetBlock("{$base_block}/pager/item/no_next");
                     $tpl->SetVariable('lbl_next', _t('GLOBAL_NEXTPAGE'));
                     $tpl->ParseBlock("{$base_block}/pager/item/no_next");
                 }
             } elseif ($k == 'previous') {
                 if ($v) {
                     $tpl->SetBlock("{$base_block}/pager/item/previous");
                     $tpl->SetVariable('lbl_previous', _t('GLOBAL_PREVIOUSPAGE'));
                     $url = $this->gadget->urlMap($action, $params);
                     $tpl->SetVariable('url_previous', $url);
                     $tpl->ParseBlock("{$base_block}/pager/item/previous");
                 } else {
                     $tpl->SetBlock("{$base_block}/pager/item/no_previous");
                     $tpl->SetVariable('lbl_previous', _t('GLOBAL_PREVIOUSPAGE'));
                     $tpl->ParseBlock("{$base_block}/pager/item/no_previous");
                 }
             } elseif ($k == 'separator1' || $k == 'separator2') {
                 $tpl->SetBlock("{$base_block}/pager/item/page_separator");
                 $tpl->ParseBlock("{$base_block}/pager/item/page_separator");
             } elseif ($k == 'current') {
                 $tpl->SetBlock("{$base_block}/pager/item/page_current");
                 $url = $this->gadget->urlMap($action, $params);
                 $tpl->SetVariable('lbl_page', $v);
                 $tpl->SetVariable('url_page', $url);
                 $tpl->ParseBlock("{$base_block}/pager/item/page_current");
             } elseif ($k != 'total' && $k != 'next' && $k != 'previous') {
                 $tpl->SetBlock("{$base_block}/pager/item/page_number");
                 $url = $this->gadget->urlMap($action, $params);
                 $tpl->SetVariable('lbl_page', $v);
                 $tpl->SetVariable('url_page', $url);
                 $tpl->ParseBlock("{$base_block}/pager/item/page_number");
             }
             $tpl->ParseBlock("{$base_block}/pager/item");
         }
         $tpl->ParseBlock("{$base_block}/pager");
     }
 }
Example #3
0
 /**
  * Get lists of phone number, email address, address
  *
  * @access  public
  * @param   object  $tpl
  * @param   string  $base_block
  * @param   array   $inputValue
  * @param   array   $options
  * @return  string  XHTML template content
  */
 function GetItemsLable(&$tpl, $base_block, $inputValue, $options = null, $seperatChar = ',')
 {
     if (trim($inputValue) == '') {
         return;
     }
     $inputValue = explode($seperatChar, trim($inputValue));
     foreach ($inputValue as $val) {
         $tpl->SetBlock("address/{$base_block}");
         if (isset($options)) {
             $result = explode(':', $val);
             $tpl->SetVariable('item', $result[1]);
             $tpl->SetVariable('lbl_item', _t('ADDRESSBOOK_' . $options[$result[0]]['lang']));
         } else {
             $tpl->SetVariable('item', $val);
             $tpl->SetVariable('lbl_item', _t('ADDRESSBOOK_ITEMS_URL'));
         }
         $tpl->ParseBlock("address/{$base_block}");
     }
 }
Example #4
0
 /**
  * Get reference tags
  *
  * @access  public
  * @param   string  $gadget         Gadget name
  * @param   string  $action         Action name
  * @param   int     $reference      Reference ID
  * @param   object  $tpl            Jaws_Template object
  * @param   string  $tpl_base_block Template block name
  * @param   int     $user           User owner of tag(0: for global tags)
  * @return  void
  */
 function loadReferenceTags($gadget, $action, $reference, &$tpl, $tpl_base_block, $user = 0)
 {
     $tagsModel = $this->gadget->model->load('Tags');
     $tags = $tagsModel->GetReferenceTags($gadget, $action, $reference, $user);
     if (Jaws_Error::IsError($tags)) {
         return false;
     }
     if (!empty($tags)) {
         // store tags of main request for later use
         if ($GLOBALS['app']->inMainRequest) {
             self::$mainRequestReference = array('gadget' => $gadget, 'action' => $action, 'reference' => $reference);
             self::$mainRequestTags = array_column($tags, 'id');
         }
         $tpl->SetBlock("{$tpl_base_block}/tags");
         $tpl->SetVariable('lbl_tags', _t('GLOBAL_TAGS'));
         foreach ($tags as $tag) {
             $tpl->SetBlock("{$tpl_base_block}/tags/tag");
             $tpl->SetVariable('name', $tag['name']);
             $tpl->SetVariable('title', $tag['title']);
             $tpl->SetVariable('url', $this->gadget->urlMap('ViewTag', array('tag' => $tag['name'], 'tagged_gadget' => $gadget)));
             $tpl->ParseBlock("{$tpl_base_block}/tags/tag");
         }
         $tpl->ParseBlock("{$tpl_base_block}/tags");
     }
 }
Example #5
0
File: Default.php Project: uda/jaws
 /**
  * Displays a given blog entry according to given parameters
  *
  * @access  public
  * @param   object  $tpl            Jaws_Template object
  * @param   string  $tpl_base_block Template block name
  * @param   int     $entry          entry id
  * @param   bool    $show_summary   Show post summary
  * @return  string XHTML template content
  */
 function ShowEntry(&$tpl, $tpl_base_block, $entry, $show_summary = true)
 {
     $tpl->SetBlock("{$tpl_base_block}/entry");
     $tpl->SetVariablesArray($entry);
     $tpl->SetVariable('posted_by', _t('BLOG_POSTED_BY'));
     $tpl->SetVariable('author-url', $this->gadget->urlMap('ViewAuthorPage', array('id' => $entry['username'])));
     $date = Jaws_Date::getInstance();
     $tpl->SetVariable('createtime-iso', $date->ToISO($entry['publishtime']));
     $tpl->SetVariable('createtime', $date->Format($entry['publishtime']));
     $tpl->SetVariable('createtime-monthname', $date->Format($entry['publishtime'], 'MN'));
     $tpl->SetVariable('createtime-monthabbr', $date->Format($entry['publishtime'], 'M'));
     $tpl->SetVariable('createtime-month', $date->Format($entry['publishtime'], 'm'));
     $tpl->SetVariable('createtime-dayname', $date->Format($entry['publishtime'], 'DN'));
     $tpl->SetVariable('createtime-dayabbr', $date->Format($entry['publishtime'], 'D'));
     $tpl->SetVariable('createtime-day', $date->Format($entry['publishtime'], 'd'));
     $tpl->SetVariable('createtime-year', $date->Format($entry['publishtime'], 'Y'));
     $tpl->SetVariable('createtime-time', $date->Format($entry['publishtime'], 'g:ia'));
     $tpl->SetVariable('entry-visits', _t('BLOG_ENTRY_VISITS', $entry['clicks']));
     if (empty($entry['image'])) {
         $tpl->SetVariable('image', _t('GLOBAL_NOIMAGE'));
         $tpl->SetVariable('url_image', 'data:image/png;base64,');
     } else {
         $tpl->SetVariable('image', $entry['image']);
         $tpl->SetVariable('url_image', $GLOBALS['app']->getDataURL() . 'blog/images/' . $entry['image']);
     }
     $id = empty($entry['fast_url']) ? $entry['id'] : $entry['fast_url'];
     $perm_url = $this->gadget->urlMap('SingleView', array('id' => $id));
     $summary = $entry['summary'];
     $text = $entry['text'];
     // for compatibility with old versions
     $more_pos = Jaws_UTF8::strpos($text, '[more]');
     if ($more_pos !== false) {
         $summary = Jaws_UTF8::substr($text, 0, $more_pos);
         $text = Jaws_UTF8::str_replace('[more]', '', $text);
         // Update this entry to split summary and body of post
         $model = $this->gadget->model->load('Posts');
         $model->SplitEntry($entry['id'], $summary, $text);
     }
     $summary = empty($summary) ? $text : $summary;
     $summary = $this->gadget->ParseText($summary);
     $text = $this->gadget->ParseText($text);
     if ($show_summary) {
         if (Jaws_UTF8::trim($text) != '') {
             $tpl->SetBlock("{$tpl_base_block}/entry/read-more");
             $tpl->SetVariable('url', $perm_url);
             $tpl->SetVariable('read_more', _t('BLOG_READ_MORE'));
             $tpl->ParseBlock("{$tpl_base_block}/entry/read-more");
         }
         $tpl->SetVariable('text', $summary);
     } else {
         $GLOBALS['app']->Layout->AddHeadLink($this->gadget->urlMap('Atom'), 'alternate', 'application/atom+xml', 'Atom - All');
         $GLOBALS['app']->Layout->AddHeadLink($this->gadget->urlMap('RSS'), 'alternate', 'application/rss+xml', 'RSS 2.0 - All');
         $tpl->SetVariable('text', empty($text) ? $summary : $text);
     }
     $tpl->SetVariable('permanent-link', $perm_url);
     $pos = 1;
     $tpl->SetVariable('posted_in', _t('BLOG_POSTED_IN'));
     foreach ($entry['categories'] as $cat) {
         $tpl->SetBlock("{$tpl_base_block}/entry/category");
         $tpl->SetVariable('id', $cat['id']);
         $tpl->SetVariable('name', $cat['name']);
         $cid = empty($cat['fast_url']) ? $cat['id'] : $cat['fast_url'];
         $tpl->SetVariable('url', $this->gadget->urlMap('ShowCategory', array('id' => $cid)));
         if ($pos == count($entry['categories'])) {
             $tpl->SetVariable('separator', '');
         } else {
             $tpl->SetVariable('separator', ',');
         }
         $pos++;
         $tpl->ParseBlock("{$tpl_base_block}/entry/category");
     }
     $commentsCount = 0;
     $comments = _t('BLOG_NO_COMMENT');
     if (Jaws_Gadget::IsGadgetInstalled('Comments')) {
         $cModel = Jaws_Gadget::getInstance('Comments')->model->load('Comments');
         $commentsCount = $cModel->GetCommentsCount('Blog', 'Post', $entry['id'], '', Comments_Info::COMMENTS_STATUS_APPROVED);
         if (!empty($commentsCount)) {
             $comments = _t('BLOG_HAS_N_COMMENTS', $commentsCount);
         }
     }
     if ($commentsCount != 0 || $entry['allow_comments'] === true && $this->gadget->registry->fetch('allow_comments') == 'true' && $this->gadget->registry->fetch('allow_comments', 'Comments') != 'false') {
         $tpl_block = $show_summary ? 'comment-link' : 'comments-statistic';
         $tpl->SetBlock("{$tpl_base_block}/entry/{$tpl_block}");
         $tpl->SetVariable('url', $perm_url);
         $tpl->SetVariable('text_comments', $comments);
         $tpl->SetVariable('num_comments', $commentsCount);
         $tpl->ParseBlock("{$tpl_base_block}/entry/{$tpl_block}");
     }
     // Show Tags
     if (Jaws_Gadget::IsGadgetInstalled('Tags')) {
         $tagsHTML = Jaws_Gadget::getInstance('Tags')->action->load('Tags');
         $tagsHTML->loadReferenceTags('Blog', 'post', $entry['id'], $tpl, 'single_view/entry');
     }
     // Show Rating
     if (Jaws_Gadget::IsGadgetInstalled('Rating')) {
         $ratingHTML = Jaws_Gadget::getInstance('Rating')->action->load('RatingTypes');
         $ratingHTML->loadReferenceRating('Blog', 'post', $entry['id'], 0, $tpl, 'single_view/entry');
     }
     $tpl->ParseBlock("{$tpl_base_block}/entry");
     return $tpl->Get();
 }
Example #6
0
 /**
  * Fill and get input with url
  *
  * @access  public
  * @param   object  $tpl
  * @param   string  $base_block
  * @param   array   $inputValue
  * @return  string  XHTML template content
  */
 function GetItemsInput(&$tpl, $base_block, $inputValue, &$startIndex)
 {
     foreach ($inputValue as $val) {
         $tpl->SetBlock("address/{$base_block}");
         $tpl->SetVariable('lbl_url', _t('ADDRESSBOOK_ITEMS_URL'));
         $tpl->SetVariable('icon_add', STOCK_ADD);
         $tpl->SetVariable('icon_remove', STOCK_REMOVE);
         $tpl->SetVariable('index', $startIndex);
         $tpl->SetVariable('value', $val);
         $tpl->ParseBlock("address/{$base_block}");
         $startIndex += 1;
     }
 }
Example #7
0
 /**
  * Get reference tags
  *
  * @access  public
  * @param   string  $gadget         Gadget name
  * @param   string  $action         Action name
  * @param   int     $reference      Reference ID
  * @param   object  $tpl            Jaws_Template object
  * @param   string  $tpl_base_block Template block name
  * @param   int     $user           User owner of tag(0: for global tags)
  * @return  void
  */
 function loadReferenceTags($gadget, $action, $reference, &$tpl, $tpl_base_block, $user = 0)
 {
     $tagsModel = $this->gadget->model->load('Tags');
     $tags = $tagsModel->GetReferenceTags($gadget, $action, $reference, $user);
     if (Jaws_Error::IsError($tags)) {
         return false;
     }
     if (!empty($tags)) {
         $tpl->SetBlock("{$tpl_base_block}/tags");
         $tpl->SetVariable('lbl_tags', _t('GLOBAL_TAGS'));
         foreach ($tags as $tag) {
             $tpl->SetBlock("{$tpl_base_block}/tags/tag");
             $tpl->SetVariable('name', $tag['name']);
             $tpl->SetVariable('title', $tag['title']);
             $tpl->SetVariable('url', $this->gadget->urlMap('ViewTag', array('tag' => $tag['name'], 'tagged_gadget' => $gadget)));
             $tpl->ParseBlock("{$tpl_base_block}/tags/tag");
         }
         $tpl->ParseBlock("{$tpl_base_block}/tags");
     }
 }
Example #8
0
 /**
  * Get reference like rating
  *
  * @access  public
  * @param   string  $gadget         Gadget name
  * @param   string  $action         Action name
  * @param   int     $reference      Reference ID
  * @param   int     $item           Item number
  * @param   object  $tpl            Jaws_Template object
  * @param   string  $tpl_base_block Template block name
  * @return  void
  */
 function loadReferenceLike($gadget, $action, $reference, $item, &$tpl, $tpl_base_block)
 {
     $rModel = $this->gadget->model->load('Rating');
     // get rating statistics
     $rating = $rModel->GetRating($gadget, $action, $reference, $item);
     if (Jaws_Error::IsError($rating)) {
         return $rating;
     } elseif (empty($rating)) {
         $rating = array('rates_count' => 0);
     }
     // get user last rating
     $usrRating = $rModel->GetUserRating($gadget, $action, $reference, $item);
     if (Jaws_Error::IsError($rating)) {
         return $usrRating;
     }
     $GLOBALS['app']->Layout->AddScriptLink('gadgets/Rating/Resources/index.js');
     $tpl->SetBlock("{$tpl_base_block}/like");
     $tpl->SetVariable('lbl_like', _t('RATING_LIKE'));
     $tpl->SetVariable('gadget', $gadget);
     $tpl->SetVariable('action', $action);
     $tpl->SetVariable('reference', $reference);
     $tpl->SetVariable('item', $item);
     $tpl->SetVariable('rates_count', (int) $rating['rates_count']);
     if ($usrRating) {
         $tpl->SetBlock("{$tpl_base_block}/like/checked");
         $tpl->ParseBlock("{$tpl_base_block}/like/checked");
     }
     $tpl->ParseBlock("{$tpl_base_block}/like");
 }