Example #1
0
     $fields['description'] = i18n::c('This category has been created for experimentation purpose. Feel free to change this text, to add some images, to play with codes, etc. Have you checked the help link on the side of this page? Once you will feel more comfortable with the handling of categories, just delete this one and create other categories of your own.');
     if (Categories::post($fields)) {
         $text .= sprintf(i18n::s('A category "%s" has been created.'), $fields['nick_name']) . BR . "\n";
     }
 }
 // 'my_sub_category' category
 if (Categories::get('my_sub_category')) {
     $text .= sprintf(i18n::s('Category "%s" already exists.'), 'my_sub_category') . BR . "\n";
 } elseif ($anchor = Categories::lookup('my_category')) {
     $fields = array();
     $fields['nick_name'] = 'my_sub_category';
     $fields['anchor'] = $anchor;
     $fields['title'] = i18n::c('My sub-category');
     $fields['introduction'] = i18n::c('Sample sub category');
     $fields['description'] = i18n::c('This category has been created for experimentation purpose. Feel free to change this text, to add some images, to play with codes, etc. Have you checked the help link on the side of this page? Once you will feel more comfortable with the handling of categories, just delete this one and create other categories of your own.');
     if (Categories::post($fields)) {
         $text .= sprintf(i18n::s('A category "%s" has been created.'), $fields['nick_name']) . BR . "\n";
     }
 }
 // articles
 //
 $text .= Skin::build_block(i18n::s('Pages'), 'subtitle');
 // 'my_article' article
 if (Articles::get('my_article')) {
     $text .= sprintf(i18n::s('A page "%s" already exists.'), 'my_article') . BR . "\n";
 } elseif ($anchor = Sections::lookup('my_section')) {
     $fields = array();
     $fields['anchor'] = $anchor;
     $fields['nick_name'] = 'my_article';
     $fields['title'] = i18n::c('Edit me');
     $fields['introduction'] = i18n::c('Sample article');
Example #2
0
    Logger::error(i18n::s('No item has been found.'));
} 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'])) {
Example #3
0
File: edit.php Project: rair/yacs
     $_REQUEST['active'] = $anchor->ceil_rights($_REQUEST['active_set']);
 } else {
     $_REQUEST['active'] = $_REQUEST['active_set'];
 }
 // when the page has been overlaid
 if (is_object($overlay)) {
     // allow for change detection
     $overlay->snapshot();
     // update the overlay from form content
     $overlay->parse_fields($_REQUEST);
     // 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>';
Example #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);
                 }
             }
         }
     }
 }