Example #1
0
 * @license http://www.gnu.org/copyleft/lesser.txt GNU Lesser General Public License
 */
// common definitions and initial processing
include_once '../shared/global.php';
include_once 'categories.php';
// what we are looking for
$search = NULL;
if (isset($_REQUEST['search'])) {
    $search = strip_tags($_REQUEST['search']);
}
// load the skin
load_skin('categories');
// the title of the page
$context['page_title'] = i18n::s('Keywords update');
// 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'];
    }
}
// stop crawlers
if (Surfer::is_crawler()) {
    Safe::header('Status: 401 Unauthorized', TRUE, 401);
Example #2
0
 if (Categories::get('my_category')) {
     $text .= sprintf(i18n::s('Category "%s" already exists.'), 'my_category') . BR . "\n";
 } else {
     $fields = array();
     $fields['nick_name'] = 'my_category';
     $fields['title'] = i18n::c('My category');
     $fields['introduction'] = i18n::c('Sample plain 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";
     }
 }
 // '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')) {
Example #3
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 %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);
                 }
             }
         }
     }
 }