Пример #1
0
 /**
  * transcode some references
  *
  * @param array of pairs of strings to be used in preg_replace()
  *
  * @see images/images.php
  */
 function transcode($transcoded)
 {
     global $context;
     // no item bound
     if (!isset($this->item['id'])) {
         return;
     }
     // prepare preg_replace()
     $from = array();
     $to = array();
     foreach ($transcoded as $pair) {
         $from[] = $pair[0];
         $to[] = $pair[1];
     }
     // transcode various fields
     $this->item['introduction'] = preg_replace($from, $to, $this->item['introduction']);
     $this->item['description'] = preg_replace($from, $to, $this->item['description']);
     // update the database
     $query = "UPDATE " . SQL::table_name('categories') . " SET " . " introduction = '" . SQL::escape($this->item['introduction']) . "'," . " description = '" . SQL::escape($this->item['description']) . "'" . " WHERE id = " . SQL::escape($this->item['id']);
     SQL::query($query);
     // always clear the cache, even on no update
     Categories::clear($this->item);
 }
Пример #2
0
} elseif (!Surfer::is_member()) {
    Safe::header('Status: 401 Unauthorized', TRUE, 401);
    Logger::error(i18n::s('You are not allowed to perform this operation.'));
    // ensure we have a keyword
} elseif (!$search) {
    Logger::error(i18n::s('No keyword to search for.'));
} elseif (!($articles = Articles::search($search, 1.0, 50, 'raw'))) {
    Logger::error(i18n::s('No item has been found.'));
    // create a category for this keyword if none exists yet
} elseif (!($category =& Categories::get_by_keyword($search))) {
    $fields = array();
    $fields['keywords'] = $search;
    $fields['anchor'] = $root_category;
    $fields['title'] = ucfirst($search);
    if ($fields['id'] = Categories::post($fields)) {
        Categories::clear($fields);
        $category = Categories::get($fields['id']);
    }
}
// ensure we have a valid category for found articles
if (isset($articles) && (!isset($category) || !$category)) {
    Logger::error(i18n::s('No item has been found.'));
} elseif (isset($articles) && is_array($articles)) {
    foreach ($articles as $id => $not_used) {
        if (!Members::assign('category:' . $category['id'], 'article:' . $id)) {
            break;
        }
    }
    // redirect to the updated category, if no error has happened
    if (!count($context['error'])) {
        Safe::redirect(Categories::get_permalink($category));
Пример #3
0
Файл: edit.php Проект: rair/yacs
     // save content of the overlay in the category itself
     $_REQUEST['overlay'] = $overlay->save();
     $_REQUEST['overlay_id'] = $overlay->get_id();
 }
 // display the form on error
 if (!($_REQUEST['id'] = Categories::post($_REQUEST)) || is_object($overlay) && !$overlay->remember('insert', $_REQUEST, 'category:' . $_REQUEST['id'])) {
     $item = $_REQUEST;
     $with_form = TRUE;
     // post-processing
 } else {
     // touch the related anchor
     if (is_object($anchor)) {
         $anchor->touch('category:create', $_REQUEST['id'], isset($_REQUEST['silent']) && $_REQUEST['silent'] == 'Y');
     }
     // clear cache
     Categories::clear($_REQUEST);
     // increment the post counter of the surfer
     Users::increment_posts(Surfer::get_id());
     // reward the poster for new posts
     $context['page_title'] = i18n::s('Thank you for your contribution');
     $context['text'] .= '<p>' . i18n::s('Please review the new page carefully and fix possible errors rapidly.') . '</p>';
     // get the new item
     $category = Anchors::get('category:' . $_REQUEST['id'], TRUE);
     // follow-up commands
     $follow_up = i18n::s('What do you want to do now?');
     $menu = array();
     $menu = array_merge($menu, array($category->get_url() => i18n::s('View the category')));
     if (Surfer::may_upload()) {
         $menu = array_merge($menu, array('images/edit.php?anchor=' . urlencode('category:' . $_REQUEST['id']) => i18n::s('Add an image')));
     }
     if (preg_match('/\\bwith_files\\b/i', $category->item['options']) && Surfer::may_upload()) {
Пример #4
0
 /**
  * remember publications and tags
  *
  * This function links the provided reference to categories, based
  * on publication time and tags.
  *
  * The reference is linked to weekly and monthly categories, except if the
  * global parameter 'users_without_archiving' has been set to 'Y'.
  *
  * @see users/configure.php
  *
  * Tags can be provided either as a string of keywords separated by commas,
  * or as an array of strings.
  *
  * @param string a reference to the published material (e.g., 'article:12')
  * @param string the publication date and time, if any
  * @param mixed a list of related tags, if any
  *
  * @see articles/articles.php
  * @see categories/check.php
  * @see services/blog.php
  */
 public static function remember($reference, $stamp = NULL, $tags = NULL)
 {
     global $context;
     // if automatic archiving has not been disabled
     if (!isset($context['users_without_archiving']) || $context['users_without_archiving'] != 'Y') {
         // if the stamp has a value, this is a valid publication
         if (is_string($stamp) && $stamp > NULL_DATE && ($stamp = strtotime($stamp)) && ($stamp = getdate($stamp))) {
             // weeks are starting on Monday
             $week = mktime(0, 0, 0, $stamp['mon'], $stamp['mday'] - $stamp['wday'] + 1, $stamp['year']);
             // create the category for this week if it does not exist
             if (!($category = Categories::lookup('week ' . date('y/m/d', $week))) && ($anchor = Categories::get(i18n::c('weekly')))) {
                 $fields = array();
                 $fields['anchor'] = 'category:' . $anchor['id'];
                 $fields['nick_name'] = 'week ' . date('y/m/d', $week);
                 $fields['create_date'] = gmstrftime('%Y-%m-%d %H:%M:%S', $week);
                 $fields['edit_date'] = gmstrftime('%Y-%m-%d %H:%M:%S', $week);
                 $fields['title'] = sprintf(i18n::c('Week of&nbsp;%s'), date(i18n::c('m/d/y'), $week));
                 $fields['options'] = 'no_links';
                 if ($fields['id'] = Categories::post($fields)) {
                     Categories::clear($fields);
                     $category = 'category:' . $fields['id'];
                 }
             }
             // link the reference to this weekly category
             if ($category) {
                 Members::assign($category, $reference);
             }
             // months are starting on day 1
             $month = mktime(0, 0, 0, $stamp['mon'], 1, $stamp['year']);
             // create the category for this month if it does not exist
             if (!($category = Categories::lookup('month ' . date('M Y', $month))) && ($anchor = Categories::get(i18n::c('monthly')))) {
                 $fields = array();
                 $fields['anchor'] = 'category:' . $anchor['id'];
                 $fields['nick_name'] = 'month ' . date('M Y', $month);
                 $fields['create_date'] = gmstrftime('%Y-%m-%d %H:%M:%S', $month);
                 $fields['edit_date'] = gmstrftime('%Y-%m-%d %H:%M:%S', $month);
                 $fields['title'] = Skin::build_date($month, 'month', $context['preferred_language']);
                 $fields['options'] = 'no_links';
                 if ($fields['id'] = Categories::post($fields)) {
                     Categories::clear($fields);
                     $category = 'category:' . $fields['id'];
                 }
             }
             // link the reference to this monthly category
             if ($category) {
                 Members::assign($category, $reference);
             }
         }
     }
     // link to selected categories --do not accept ; as separator, because this conflicts with UTF-8 encoding
     if (is_string($tags) && $tags) {
         $tags = preg_split('/[ \\t]*,\\s*/', $tags);
     }
     if (is_array($tags) && count($tags)) {
         // create a category to host keywords, if none exists
         if (!($root_category = Categories::lookup('keywords'))) {
             $fields = array();
             $fields['nick_name'] = 'keywords';
             $fields['title'] = i18n::c('Keywords');
             $fields['introduction'] = i18n::c('Classified pages');
             $fields['description'] = i18n::c('This category is a specialized glossary of terms, made out of tags added to pages, and out of search requests.');
             $fields['rank'] = 29000;
             $fields['options'] = 'no_links';
             if ($fields['id'] = Categories::post($fields)) {
                 Categories::clear($fields);
                 $root_category = 'category:' . $fields['id'];
             }
         }
         // one category per tag
         $assigned = array();
         foreach ($tags as $title) {
             // create a category if tag is unknown
             if (!($category =& Categories::get_by_keyword($title))) {
                 $fields = array();
                 $fields['title'] = ucfirst($title);
                 $fields['keywords'] = $title;
                 if ($root_category) {
                     $fields['anchor'] = $root_category;
                 }
                 if ($fields['id'] = Categories::post($fields)) {
                     Categories::clear($fields);
                     $category = 'category:' . $fields['id'];
                 }
             } else {
                 $category = 'category:' . $category['id'];
             }
             // link page to the category
             if ($category) {
                 Members::assign($category, $reference);
                 $assigned[] = $category;
             }
         }
         // back to a string representation
         $tags = join(', ', $tags);
         // clean assignments for removed tags
         // the list of members
         $query = "SELECT anchor FROM " . SQL::table_name('members') . " WHERE (member LIKE '" . SQL::escape($reference) . "') AND (anchor LIKE 'category:%')" . " LIMIT 0, 500";
         if ($result = SQL::query($query)) {
             while ($row = SQL::fetch($result)) {
                 if (in_array($row['anchor'], $assigned)) {
                     continue;
                 }
                 // assigned, and a keyword exists, but not in the string of tags
                 if (($category = Anchors::get($row['anchor'])) && ($keywords = $category->get_value('keywords')) && stripos($tags, $keywords) === FALSE) {
                     Members::free($row['anchor'], $reference);
                 }
             }
         }
     }
 }