Esempio n. 1
0
 /**
  * Checks if fast_url already exists in a table, if it doesn't then it returns
  * the original fast_url (the param value). However, if it already exists then 
  * it starts looking for a 'valid' fast_url using the 'foobar-[1...n]' schema.
  *
  * @access  protected
  * @param   string     $fast_url     Fast URL
  * @param   string     $table        DB table name (without [[ ]])
  * @param   bool       $unique_check must be false in update methods
  * @param   string     $field        Table field where fast_url is stored
  * @return  string     Correct fast URL
  */
 public function GetRealFastURL($fast_url, $table, $unique_check = true, $field = 'fast_url')
 {
     if (is_numeric($fast_url)) {
         $fast_url = '-' . $fast_url . '-';
     }
     $fast_url = Jaws_UTF8::trim(Jaws_XSS::defilter($fast_url));
     $fast_url = preg_replace(array('#[^\\p{L}[:digit:]_\\.\\-\\s]#u', '#[\\s_\\-]#u', '#\\-\\+#u'), array('', '-', '-'), Jaws_UTF8::strtolower($fast_url));
     $fast_url = Jaws_UTF8::substr($fast_url, 0, 90);
     if (!$unique_check) {
         return $fast_url;
     }
     $tblReg = Jaws_ORM::getInstance()->table($table);
     $result = $tblReg->select("count({$field})")->where($field, $fast_url . '%', 'like')->fetchOne();
     if (Jaws_Error::IsError($result) || empty($result)) {
         return $fast_url;
     }
     return $fast_url . '-' . $result;
 }
Esempio n. 2
0
 /**
  * Displays the recent posts of a dynamic category
  *
  * @access  public
  * @param   int $cat    Category ID
  * @param   int $limit
  * @return  string  XHTML Template content
  */
 function CategoryEntries($cat = null, $limit = 0)
 {
     $cModel = $this->gadget->model->load('Categories');
     $pModel = $this->gadget->model->load('Posts');
     if (is_null($cat)) {
         $title = _t('BLOG_RECENT_POSTS');
     } else {
         $category = $cModel->GetCategory($cat);
         if (Jaws_Error::isError($category)) {
             return false;
         }
         if (array_key_exists('name', $category)) {
             $cat = $category['id'];
             $title = _t('BLOG_RECENT_POSTS_BY_CATEGORY', $category['name']);
         } else {
             $cat = null;
             $title = _t('BLOG_RECENT_POSTS_BY_CATEGORY');
         }
     }
     $entries = $pModel->GetRecentEntries($cat, (int) $limit);
     if (Jaws_Error::IsError($entries) || empty($entries)) {
         return false;
     }
     $tpl = $this->gadget->template->load('RecentPosts.html');
     $tpl->SetBlock('recent_posts');
     $tpl->SetVariable('cat', empty($cat) ? '0' : $cat);
     $tpl->SetVariable('title', $title);
     $date = Jaws_Date::getInstance();
     foreach ($entries as $e) {
         $tpl->SetBlock('recent_posts/item');
         $id = empty($e['fast_url']) ? $e['id'] : $e['fast_url'];
         $perm_url = $this->gadget->urlMap('SingleView', array('id' => $id));
         $summary = $e['summary'];
         $text = $e['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
             $pModel->SplitEntry($e['id'], $summary, $text);
         }
         $summary = empty($summary) ? $text : $summary;
         $summary = $this->gadget->ParseText($summary);
         $text = $this->gadget->ParseText($text);
         if (Jaws_UTF8::trim($text) != '') {
             $tpl->SetBlock('recent_posts/item/read-more');
             $tpl->SetVariable('url', $perm_url);
             $tpl->SetVariable('read_more', _t('BLOG_READ_MORE'));
             $tpl->ParseBlock('recent_posts/item/read-more');
         }
         $tpl->SetVariable('url', $perm_url);
         $tpl->SetVariable('title', $e['title']);
         $tpl->SetVariable('text', $summary);
         $tpl->SetVariable('username', $e['username']);
         $tpl->SetVariable('posted_by', _t('BLOG_POSTED_BY'));
         $tpl->SetVariable('name', $e['nickname']);
         $tpl->SetVariable('author-url', $this->gadget->urlMap('ViewAuthorPage', array('id' => $e['username'])));
         $tpl->SetVariable('createtime', $date->Format($e['publishtime']));
         $tpl->SetVariable('createtime-monthname', $date->Format($e['publishtime'], 'MN'));
         $tpl->SetVariable('createtime-month', $date->Format($e['publishtime'], 'm'));
         $tpl->SetVariable('createtime-day', $date->Format($e['publishtime'], 'd'));
         $tpl->SetVariable('createtime-year', $date->Format($e['publishtime'], 'Y'));
         $tpl->SetVariable('createtime-time', $date->Format($e['publishtime'], 'g:ia'));
         if (empty($e['image'])) {
             $tpl->SetVariable('image', _t('GLOBAL_NOIMAGE'));
             $tpl->SetVariable('url_image', 'data:image/png;base64,');
         } else {
             $tpl->SetVariable('image', $e['image']);
             $tpl->SetVariable('url_image', $GLOBALS['app']->getDataURL() . 'blog/images/' . $e['image']);
         }
         $tpl->ParseBlock('recent_posts/item');
     }
     $tpl->ParseBlock('recent_posts');
     return $tpl->Get();
 }
Esempio n. 3
0
 /**
  * Update the info of a group
  *
  * @access  public
  * @param   int     $id     Group ID
  * @param   array   $gData  Group information data
  * @param   int     $owner  The owner of group 
  * @return  bool    Returns true if group was sucessfully updated, false if not
  */
 function UpdateGroup($id, $gData, $owner = 0)
 {
     // unset invalid keys
     $invalids = array_diff(array_keys($gData), array('name', 'title', 'description', 'enabled'));
     foreach ($invalids as $invalid) {
         unset($gData[$invalid]);
     }
     // name
     if (isset($gData['name'])) {
         $gData['name'] = trim($gData['name'], '-_.@');
         if (!preg_match('/^[[:alnum:]-_.@]{3,32}$/', $gData['name'])) {
             return Jaws_Error::raiseError(_t('GLOBAL_ERROR_INVALID_GROUPNAME'), __FUNCTION__, JAWS_ERROR_NOTICE);
         }
         $gData['name'] = strtolower($gData['name']);
     }
     $gData['owner'] = (int) $owner;
     // title
     if (isset($gData['title'])) {
         $gData['title'] = Jaws_UTF8::trim($gData['title']);
         if (empty($gData['title'])) {
             return Jaws_Error::raiseError(_t('GLOBAL_ERROR_INCOMPLETE_FIELDS'), __FUNCTION__, JAWS_ERROR_NOTICE);
         }
     }
     if (isset($gData['enabled'])) {
         $gData['enabled'] = (bool) $gData['enabled'];
     }
     $groupsTable = Jaws_ORM::getInstance()->table('groups');
     $result = $groupsTable->update($gData)->where('id', $id)->exec();
     if (Jaws_Error::IsError($result)) {
         if (MDB2_ERROR_CONSTRAINT == $result->getCode()) {
             $result->SetMessage(_t('USERS_GROUPS_ALREADY_EXISTS', $gData['name']));
         }
         return $result;
     }
     // Let everyone know a group has been updated
     $res = $GLOBALS['app']->Listener->Shout('Users', 'UpdateGroup', $id);
     if (Jaws_Error::IsError($res)) {
         //do nothing
     }
     return true;
 }
Esempio n. 4
0
File: Default.php Progetto: 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();
 }
Esempio n. 5
0
File: Model.php Progetto: uda/jaws
 /**
  * it starts looking for a 'valid' meta_title using the 'foobar-[1...n]' schema.
  *
  * @access  protected
  * @param   string     $meta_title     Meta title
  * @return  string     Correct fast URL
  */
 public function GetMetaTitleURL($meta_title)
 {
     if (is_numeric($meta_title)) {
         $meta_title = '-' . $meta_title . '-';
     }
     $meta_title = Jaws_UTF8::trim(Jaws_XSS::defilter($meta_title));
     $meta_title = preg_replace(array('#[^\\p{L}[:digit:]_\\.\\-\\s]#u', '#[\\s_\\-]#u', '#\\-\\+#u'), array('', '-', '-'), Jaws_UTF8::strtolower($meta_title));
     $fast_url = Jaws_UTF8::substr($meta_title, 0, 90);
     return $meta_title;
 }
Esempio n. 6
0
 /**
  * Parses a search phrase to find the excluding matches, exact matches,
  * any matches and all other words
  *
  * @access  public
  * @param   string  $phrase     Phrase to parse
  * @param   array   $searchable List of searchable gadgets
  * @return  array   An array with the following indexes (and results):
  *                     - all, exact, least and exclude
  */
 function parseSearch($options, &$searchable)
 {
     $phrase = $options['all'];
     if (!empty($phrase)) {
         $phrase .= chr(32);
     }
     $newOptions = array('all' => '', 'exact' => '', 'least' => '', 'exclude' => '', 'date' => '');
     $size = Jaws_UTF8::strlen($phrase);
     $lastKey = '';
     $tmpWord = '';
     for ($i = 0; $i < $size; $i++) {
         $word = Jaws_UTF8::substr($phrase, $i, 1);
         $ord = Jaws_UTF8::ord($word);
         $tmpWord .= $word;
         switch ($ord) {
             case 34:
                 // Quotes..
                 if ($lastKey == 'exact') {
                     //Open exact was open, we are closing it
                     $newOptions['exact'] .= Jaws_UTF8::substr($tmpWord, 1, Jaws_UTF8::strlen($tmpWord) - 2);
                     $lastKey = '';
                     $tmpWord = '';
                 } else {
                     if (empty($lastKey)) {
                         $lastKey = 'exact';
                         //We open the exact match
                     }
                 }
                 break;
             case 43:
                 //Plus
                 if ($lastKey != 'exact') {
                     $lastKey = 'least';
                 }
                 break;
             case 45:
                 //Minus
                 if ($lastKey != 'exclude') {
                     $lastKey = 'exclude';
                 }
                 break;
             case 32:
                 //Space
                 if ($lastKey != 'exact' && !empty($lastKey)) {
                     if ($lastKey != 'all') {
                         $substrCount = 1;
                         if ($tmpWord[0] == ' ') {
                             $substrCount = 2;
                         }
                         $newOptions[$lastKey] .= Jaws_UTF8::substr($tmpWord, $substrCount);
                     } else {
                         $newOptions[$lastKey] .= $tmpWord;
                     }
                     $lastKey = '';
                     $tmpWord = '';
                 }
                 break;
             default:
                 //Any other word opens all
                 if (empty($lastKey)) {
                     $lastKey = 'all';
                 }
                 break;
         }
     }
     $options['all'] = '';
     $min_key_len = $this->gadget->registry->fetch('min_key_len');
     foreach (array_keys($newOptions) as $option) {
         if (!empty($newOptions[$option])) {
             $options[$option] = trim(isset($options[$option]) ? $options[$option] . ' ' . $newOptions[$option] : $newOptions[$option]);
         }
         $content = isset($options[$option]) ? $options[$option] : '';
         $content = $content;
         $content = Jaws_UTF8::strtolower(Jaws_UTF8::trim($content));
         if (Jaws_UTF8::strlen($content) >= $min_key_len) {
             $searchable = true;
         }
         $options[$option] = '';
         switch ($option) {
             case 'exclude':
             case 'least':
             case 'all':
                 $options[$option] = array_filter(explode(' ', $content));
                 break;
             case 'exact':
                 $options[$option] = array($content);
                 break;
             case 'date':
                 if (in_array($content, array('past_1month', 'past_2month', 'past_3month', 'past_6month', 'past_1year', 'anytime'))) {
                     $options[$option] = array($content);
                 } else {
                     $options[$option] = array('anytime');
                 }
                 break;
         }
     }
     return $options;
 }