예제 #1
0
function transfer_topics_3_5($p_parentId = 0)
{
    global $g_ado_db;
    $sql = 'SELECT * FROM TopicsOld';
    if (!is_null($p_parentId)) {
        $sql .= " WHERE ParentId = {$p_parentId}";
    }
    $sql .= ' ORDER BY TopicOrder DESC, LanguageId ASC';
    $rows = $g_ado_db->GetAll($sql);
    foreach ($rows as $row) {
        $topic = new Topic($row['Id']);
        if ($topic->exists()) {
            $topic->setName($row['LanguageId'], $row['Name']);
        } else {
            $topic->create(array('parent_id' => $p_parentId, 'names' => array($row['LanguageId'] => $row['Name'])));
            transfer_topics_3_5($topic->getTopicId());
        }
    }
}
예제 #2
0
    /**
     * Returns an articles list based on the given parameters.
     *
     * @param array $p_parameters
     *    An array of ComparisonOperation objects
     * @param string $p_order
     *    An array of columns and directions to order by
     * @param integer $p_start
     *    The record number to start the list
     * @param integer $p_limit
     *    The offset. How many records from $p_start will be retrieved.
     * @param integer $p_count
     *    The total count of the elements; this count is computed without
     *    applying the start ($p_start) and limit parameters ($p_limit)
     *
     * @return array $articlesList
     *    An array of Article objects
     */
    public static function GetList(array $p_parameters, $p_order = null,
                                   $p_start = 0, $p_limit = 0, &$p_count, $p_skipCache = false)
    {
        global $g_ado_db;

        if (!$p_skipCache && CampCache::IsEnabled()) {
            $paramsArray['parameters'] = serialize($p_parameters);
            $paramsArray['order'] = (is_null($p_order)) ? 'null' : $p_order;
            $paramsArray['start'] = $p_start;
            $paramsArray['limit'] = $p_limit;
            $cacheListObj = new CampCacheList($paramsArray, __METHOD__);
            $articlesList = $cacheListObj->fetchFromCache();
            if ($articlesList !== false && is_array($articlesList)) {
                return $articlesList;
            }
        }

        $matchAllTopics = false;
        $hasTopics = array();
        $hasNotTopics = array();
        $selectClauseObj = new SQLSelectClause();
        $otherTables = array();

        // sets the name of the table for the this database object
        $tmpArticle = new Article();
        $articleTable = $tmpArticle->getDbTableName();
        $selectClauseObj->setTable($articleTable);
        unset($tmpArticle);

        $languageId = null;

        // parses the given parameters in order to build the WHERE part of
        // the SQL SELECT sentence
        foreach ($p_parameters as $param) {
            $comparisonOperation = self::ProcessListParameters($param, $otherTables);
            $leftOperand = strtolower($comparisonOperation['left']);
            if ($leftOperand == 'idlanguage' && $comparisonOperation['symbol'] == '=') {
                $languageId = $comparisonOperation['right'];
            }

            if (array_key_exists($leftOperand, Article::$s_regularParameters)) {
                // regular article field, having a direct correspondent in the
                // Article table fields
                $whereCondition = Article::$s_regularParameters[$leftOperand]
                    . ' ' . $comparisonOperation['symbol']
                    . " '" . $g_ado_db->escape($comparisonOperation['right']) . "' ";
                if ($leftOperand == 'reads'
                && strstr($comparisonOperation['symbol'], '=') !== false
                && $comparisonOperation['right'] == 0) {
                    $selectClauseObj->addConditionalWhere($whereCondition);
                    $isNullCond = Article::$s_regularParameters[$leftOperand]
                                . ' IS NULL';
                    $selectClauseObj->addConditionalWhere($isNullCond);
                } elseif ($leftOperand == 'type' && $comparisonOperation['symbol'] == '=' ) {
					$selectClauseObj->addConditionalWhere($whereCondition);
                } else {
                	$selectClauseObj->addWhere($whereCondition);
                }
            } elseif ($leftOperand == 'matchalltopics') {
                // set the matchAllTopics flag
                $matchAllTopics = true;
            } elseif ($leftOperand == 'topic') {
                // add the topic to the list of match/do not match topics depending
                // on the operator
                $topic = new Topic($comparisonOperation['right']);
                if ($topic->exists()) {
                    $topicIds = $topic->getSubtopics(true, 0);
                    $topicIds[] = $comparisonOperation['right'];
                    if ($comparisonOperation['symbol'] == '=') {
                        $hasTopics[] = $topicIds;
                    } else {
                        $hasNotTopics[] = $topicIds;
                    }
                }
            } elseif ($leftOperand == 'author') {
                $otherTables['ArticleAuthors'] = array('__JOIN' => ',');
                $author = Author::ReadName($comparisonOperation['right']);
                $symbol = $comparisonOperation['symbol'];
                $valModifier = strtolower($symbol) == 'like' ? '%' : '';

                $firstName = $g_ado_db->escape($author['first_name']);
                $lastName = $g_ado_db->escape($author['last_name']);
                $whereCondition = "ArticleAuthors.fk_author_id IN
                    (SELECT Authors.id
                     FROM Authors
                     WHERE CONCAT(Authors.first_name, ' ', Authors.last_name) $symbol
                         '$valModifier$firstName $lastName$valModifier')";
                $selectClauseObj->addWhere($whereCondition);
                $selectClauseObj->addWhere('Articles.Number = ArticleAuthors.fk_article_number');
                $selectClauseObj->addWhere('Articles.IdLanguage = ArticleAuthors.fk_language_id');
            } elseif ($leftOperand == 'search_phrase') {
                $searchQuery = ArticleIndex::SearchQuery($comparisonOperation['right']);
                $mainClauseConstraint = "(Articles.Number, Articles.IdLanguage) IN ( $searchQuery )";
                $selectClauseObj->addWhere($mainClauseConstraint);
            } elseif ($leftOperand == 'location') {
                $num = '[-+]?[0-9]+(?:\.[0-9]+)?';
                if (preg_match("/($num) ($num), ($num) ($num)/",
                    trim($comparisonOperation['right']), $matches)) {
                    $queryLocation = Geo_Map::GetGeoSearchSQLQuery(array(
                        array(
                            'latitude' => $matches[1],
                            'longitude' => $matches[2],
                        ), array(
                            'latitude' => $matches[3],
                            'longitude' => $matches[4],
                        ),
                    ));
                    $selectClauseObj->addWhere("Articles.Number IN ($queryLocation)");
                }
            } else {
                // custom article field; has a correspondence in the X[type]
                // table fields
                $sqlQuery = self::ProcessCustomField($comparisonOperation, $languageId);
                if (!is_null($sqlQuery)) {
                    $whereCondition = "Articles.Number IN (\n$sqlQuery        )";
                    $selectClauseObj->addWhere($whereCondition);
                }
            }
        }

        if (count($hasTopics) > 0 || count($hasNotTopics) > 0) {
            $typeAttributes = ArticleTypeField::FetchFields(null, null, 'topic', false,
            false, false, true, $p_skipCache);
        }
        if (count($hasTopics) > 0) {
            if ($matchAllTopics) {
                foreach ($hasTopics as $topicId) {
                    $sqlQuery = Article::BuildTopicSelectClause($topicId, $typeAttributes);
                    $whereCondition = "Articles.Number IN (\n$sqlQuery        )";
                    $selectClauseObj->addWhere($whereCondition);
                }
            } else {
                $sqlQuery = Article::BuildTopicSelectClause($hasTopics, $typeAttributes);
                $whereCondition = "Articles.Number IN (\n$sqlQuery        )";
                $selectClauseObj->addWhere($whereCondition);
            }
        }
        if (count($hasNotTopics) > 0) {
            $sqlQuery = Article::BuildTopicSelectClause($hasNotTopics, $typeAttributes);
            $whereCondition = "Articles.Number NOT IN (\n$sqlQuery        )";
            $selectClauseObj->addWhere($whereCondition);
        }

        // create the count clause object
        $countClauseObj = clone $selectClauseObj;

        if (!is_array($p_order)) {
            $p_order = array();
        }

        // sets the ORDER BY condition
        $p_order = array_merge($p_order, Article::$s_defaultOrder);
        $order = Article::ProcessListOrder($p_order, $otherTables, $otherWhereConditions);
        foreach ($order as $orderDesc) {
            $orderColumn = $orderDesc['field'];
            $orderDirection = $orderDesc['dir'];
            $selectClauseObj->addOrderBy($orderColumn . ' ' . $orderDirection);
        }
        if (count($otherTables) > 0) {
            foreach ($otherTables as $table=>$fields) {
            	$joinType = 'LEFT JOIN';
            	if (isset($fields['__JOIN'])) {
            		$joinType = $fields['__JOIN'];
            	}
                if (isset($fields['__TABLE_ALIAS'])) {
                    $tableAlias = $fields['__TABLE_ALIAS'];
                    $tableJoin = "\n    $joinType $table AS $tableAlias \n";
                } else {
                    $tableAlias = $table;
                    $tableJoin = "\n    $joinType $tableAlias \n";
                }
                $firstCondition = true;
                foreach ($fields as $parent=>$child) {
                    if ($parent == '__TABLE_ALIAS' || $parent == '__JOIN') {
                        continue;
                    }
                    $condOperator = $firstCondition ? ' ON ' : 'AND ';
                    if ($parent == '__CONST') {
                        $constTable = $child['table'];
                        $constField = $child['field'];
                        $value = $child['value'];
                        $negate = isset($child['negate']) ? $child['negate'] : false;
                        if (is_null($value)) {
                            $operator = $negate ? 'IS NOT' : 'IS';
                            $value = 'NULL';
                        } else {
                            $operator = $negate ? '!=' : '=';
                            $value = "'" . $g_ado_db->escape($value) . "'";
                        }
                        $tableJoin .= "        $condOperator`$constTable`.`$constField` $operator $value\n";
                    } else {
                        $tableJoin .= "        $condOperator`$articleTable`.`$parent` = `$tableAlias`.`$child`\n";
                    }
                    $firstCondition = false;
                }
                $selectClauseObj->addJoin($tableJoin);
                $countClauseObj->addJoin($tableJoin);
            }
        }
        // other where conditions needed for certain order options
        foreach ($otherWhereConditions as $whereCondition) {
            $selectClauseObj->addWhere($whereCondition);
            $countClauseObj->addWhere($whereCondition);
        }

        // gets the column list to be retrieved for the database table
        $selectClauseObj->addColumn('Articles.Number');
        $selectClauseObj->addColumn('Articles.IdLanguage');
        $countClauseObj->addColumn('COUNT(*)');

        // sets the LIMIT start and offset values
        $selectClauseObj->setLimit($p_start, $p_limit);

        // builds the SQL query
        $selectQuery = $selectClauseObj->buildQuery();
        $countQuery = $countClauseObj->buildQuery();

        // runs the SQL query
        $articles = $g_ado_db->GetAll($selectQuery);
        if (is_array($articles)) {
            $p_count = $g_ado_db->GetOne($countQuery);

            // builds the array of Article objects
            $articlesList = array();
            foreach ($articles as $article) {
                $articlesList[] = new Article($article['IdLanguage'], $article['Number']);
            }
        } else {
            $articlesList = array();
            $p_count = 0;
        }

        // stores articles list in cache
        if (!$p_skipCache && CampCache::IsEnabled()) {
            $cacheListObj->storeInCache($articlesList);
        }

        return $articlesList;
    } // fn GetList
예제 #3
0
 public function has_topic($p_topicName) {
     $topic = new Topic($p_topicName);
     if (!$topic->exists()) {
         $this->trigger_invalid_value_error('has_topic', $p_topicName);
         return null;
     }
     $articleTopics = $this->getContentCache('article_topics');
     if (is_null($articleTopics)) {
         $articleTopics = ArticleTopic::GetArticleTopics($this->m_dbObject->getArticleNumber());
         $this->setContentCache('article_topics', $articleTopics);
     }
     foreach ($articleTopics as $articleTopic) {
         if ($articleTopic->getTopicId() == $topic->getTopicId()) {
             return (int)true;
         }
     }
     return (int)false;
 }
예제 #4
0
}

// delete
foreach ($articleTopics as $topic) {
    if (!in_array($topic->getTopicId(), $f_topic_ids)) {
        ArticleTopic::RemoveTopicFromArticle($topic->getTopicId(), $f_article_number);
    } else {
        unset($f_topic_ids[array_search($topic->getTopicId(), $f_topic_ids)]);
    }
}

// insert rest
foreach ($f_topic_ids as $topicIdString) {
    // Verify topic exists
    $tmpTopic = new Topic($topicIdString);
    if ($tmpTopic->exists()) {
        ArticleTopic::AddTopicToArticle($topicIdString, $f_article_number);
    }
}

?>

<script type="text/javascript">
<?php if (!is_null($f_topic_ids)) { ?>
try {
    parent.$.fancybox.reload = true;
    parent.$.fancybox.message = '<?php putGS('Topics updated.'); ?>';
} catch (e) {}
<?php } ?>
parent.$.fancybox.close();
</script>
예제 #5
0
	/**
	 * Processes list constraints passed in an array.
	 *
	 * @param array $p_constraints
	 * @return array
	 */
	protected function ProcessConstraints(array $p_constraints)
	{
	    $parameters = array();
	    $state = 1;
	    $attribute = null;
	    $articleTypeName = null;
	    $operator = null;
	    $value = null;
	    $context = CampTemplate::singleton()->context();
	    foreach ($p_constraints as $index=>$word) {
	    	switch ($state) {
	    		case self::CONSTRAINT_ATTRIBUTE_NAME: // reading the parameter name
	    			$attribute = strtolower($word);
	                if (!array_key_exists($attribute, ArticlesList::$s_parameters)) {
	                	// not a static field; is it a article type name?
	                	self::ReadArticleTypes();
	                	if (array_key_exists($attribute, self::$s_articleTypes)) {
	                		$articleTypeName = self::$s_articleTypes[$attribute];
	                		$state = self::CONSTRAINT_DYNAMIC_FIELD;
	                		break;
	                	}

	                	// not an article type name; is it a dynamic field name?
	                	$dynamicFields = self::GetDynamicFields($articleTypeName, $attribute);
	                	if (count($dynamicFields) > 0) {
	                		if (count($dynamicFields) == 1) {
	                			$type = $dynamicFields[0]->getGenericType();
	                		} else {
                                $type = 'string';
	                		}
	                		$state = self::CONSTRAINT_OPERATOR;
	                		break;
	                	}

	                	// unknown attribute
	                	CampTemplate::singleton()->trigger_error("invalid attribute $word in statement list_articles, constraints parameter");
	                	return false;
	                } else {
                        $type = ArticlesList::$s_parameters[$attribute]['type'];
	                }
	                if ($attribute == 'keyword') {
	                    $operator = new Operator('is', 'string');
	                    $state = self::CONSTRAINT_VALUE;
	                } elseif ($attribute == 'matchalltopics' || $attribute == 'matchanytopic') {
	                    if ($attribute == 'matchalltopics') {
	                        $operator = new Operator('is', 'boolean');
	                        $comparisonOperation = new ComparisonOperation($attribute, $operator, 'true');
	                        $parameters[] = $comparisonOperation;
	                    }
	                    $state = self::CONSTRAINT_ATTRIBUTE_NAME;
	                } else {
                        $state = self::CONSTRAINT_OPERATOR;
	                }
	                $this->m_ignoreIssue = $this->m_ignoreIssue || $attribute == 'issue';
	                $this->m_ignoreSection = $this->m_ignoreSection || $attribute == 'section';

	                if ($attribute == 'onfrontpage' || $attribute == 'onsection') {
	                    if (($index + 1) < count($p_constraints)) {
	                        try {
	                            $operator = new Operator($p_constraints[$index+1], 'switch');
	                        }
	                        catch (InvalidOperatorException $e) {
        	                    $operator = new Operator('is', 'switch');
        	                    $comparisonOperation = new ComparisonOperation($attribute, $operator, 'on');
                	            $parameters[] = $comparisonOperation;
                	            $state = self::CONSTRAINT_ATTRIBUTE_NAME;
	                        }
	                    } else {
    	                    $operator = new Operator('is', 'switch');
                            $comparisonOperation = new ComparisonOperation($attribute, $operator, 'on');
                            $parameters[] = $comparisonOperation;
                            $state = self::CONSTRAINT_ATTRIBUTE_NAME;
	                    }
	                }
	                break;
	    		case self::CONSTRAINT_DYNAMIC_FIELD:
	    			$attribute = strtolower($word);
	    			$dynamicFields = self::GetDynamicFields($articleTypeName, $attribute);
	    			if (count($dynamicFields) > 0) {
	    				$type = $dynamicFields[0]->getGenericType();
	    				$state = self::CONSTRAINT_OPERATOR;
	    				break;
	    			}
                    CampTemplate::singleton()->trigger_error("invalid dynamic field $word in statement list_articles, constraints parameter");
                    return false;
	            case self::CONSTRAINT_OPERATOR: // reading the operator
	                try {
	                    $operator = new Operator($word, $type);
	                }
	                catch (InvalidOperatorException $e) {
    	                CampTemplate::singleton()->trigger_error("invalid operator $word of parameter constraints.$attribute in statement list_articles");
	                    return false;
	                }
	                $state = self::CONSTRAINT_VALUE;
	                break;
	            case self::CONSTRAINT_VALUE: // reading the value to compare against
	                $metaClassName = 'Meta'.ucfirst($type);
	                try {
    	                $valueObj = new $metaClassName($word);
	                } catch (InvalidValueException $e) {
                        CampTemplate::singleton()->trigger_error("invalid value $word of parameter constraints.$attribute in statement list_articles");
	                    return false;
	                }
       	            if ($attribute == 'type') {
                        $word = trim($word);
       	                $articleType = new ArticleType($word);
       	                if (!$articleType->exists()) {
	                        CampTemplate::singleton()->trigger_error("invalid value $word of parameter constraints.$attribute in statement list_articles");
	                        return false;
                        }
                        $value = $word;
                    } elseif ($attribute == 'topic') {
                        $topicObj = new Topic($word);
                        if (!$topicObj->exists()) {
                            CampTemplate::singleton()->trigger_error("invalid value $word of parameter constraints.$attribute in statement list_articles");
                            return false;
                        } else {
                            $value = $topicObj->getTopicId();
                        }
                    } elseif ($attribute == 'author') {
                        if (strtolower($word) == '__current') {
                        	$value = $context->article->author->name;
                        } else {
                        	$value = $word;
                        }
       	            } elseif ($type == 'switch') {
       	            	$value = (int)(strtolower($word) == 'on');
       	            } else {
       	                $value = $word;
       	            }
       	            if (!is_null($articleTypeName)) {
       	            	$attribute = "$articleTypeName.$attribute";
       	            }
       	            $comparisonOperation = new ComparisonOperation($attribute, $operator, $value);
       	            $parameters[] = $comparisonOperation;
       	            $state = self::CONSTRAINT_ATTRIBUTE_NAME;
	                $attribute = null;
	                $articleTypeName = null;
	                $type = null;
	                $value = null;
	                break;
	        }
	    }
	    if ($state != self::CONSTRAINT_ATTRIBUTE_NAME) {
            CampTemplate::singleton()->trigger_error("unexpected end of constraints parameter in list_articles");
            return false;
	    }

	    if (!$this->m_ignoreIssue && $context->issue->defined) {
            $this->m_constraints[] = new ComparisonOperation('NrIssue', new Operator('is', 'integer'),
                                                             $context->issue->number);
        }
        if (!$this->m_ignoreSection && $context->section->defined) {
            $this->m_constraints[] = new ComparisonOperation('NrSection', new Operator('is', 'integer'),
                                                             $context->section->number);
        }

	    return $parameters;
	}
예제 #6
0
	private function createAndTest($p_topicId, $p_data, $p_left, $p_right)
	{
		$topic = new Topic($p_topicId);
		$topic->create($p_data);
		unset($topic);
		$topic = new Topic($p_topicId);
		$this->assertTrue($topic->exists());
		foreach ($p_data['names'] as $languageId=>$name) {
			$this->assertEquals($name, $topic->getName($languageId));
		}
		$this->assertEquals($p_left, $topic->getLeft());
		$this->assertEquals($p_right, $topic->getRight());
	}
예제 #7
0
파일: Topic.php 프로젝트: nidzix/Newscoop
 /**
  * Create a new topic.
  *
  * The values array may have the following keys:
  * - parent_id - parent topic identifier
  * - id - topic identifier; if not supplied generated automatically
  * - node_left
  * - node_right
  * - names - array of topic translations of the form: language_id => name
  *
  * @param array $p_values
  * @return boolean
  */
 public function create($p_values = null, $p_allNamesRequired = false)
 {
     global $g_ado_db;
     if (!isset($p_values['names']) || !is_array($p_values['names'])) {
         return false;
     }
     $names_available = array();
     $names_occupied = array();
     foreach ($p_values['names'] as $check_lang_id => $check_topic_name) {
         $check_name_obj = new \TopicName($check_topic_name, $check_lang_id);
         if ($check_name_obj->exists()) {
             $names_occupied[$check_lang_id] = $check_topic_name;
         } else {
             $names_available[$check_lang_id] = $check_topic_name;
         }
         unset($check_name_obj);
     }
     if (empty($names_available)) {
         return false;
     }
     if ($p_allNamesRequired) {
         if (!empty($names_occupied)) {
             return false;
         }
     }
     $p_values['names'] = $names_available;
     $g_ado_db->Execute("LOCK TABLE Topics WRITE, TopicNames WRITE");
     if (isset($p_values['parent_id']) && !empty($p_values['parent_id'])) {
         $parent = new Topic($p_values['parent_id']);
         if (!$parent->exists()) {
             $g_ado_db->Execute("UNLOCK TABLES");
             return false;
         }
         $parentLeft = (int) $parent->getLeft();
     } else {
         $parentLeft = 0;
     }
     $g_ado_db->Execute("UPDATE Topics SET node_left = node_left + 2 WHERE node_left > {$parentLeft}");
     $g_ado_db->Execute("UPDATE Topics SET node_right = node_right + 2 WHERE node_right > {$parentLeft}");
     $this->m_data['node_left'] = $parentLeft + 1;
     $this->m_data['node_right'] = $parentLeft + 2;
     $some_name_set = false;
     $some_name_not_set = false;
     // create node
     if ($success = parent::create($p_values)) {
         // create topic names
         foreach ($p_values['names'] as $languageId => $name) {
             $topicName = new TopicName($this->getTopicId(), $languageId);
             $res = $topicName->create(array('name' => $name));
             if ($res) {
                 $some_name_set = true;
                 $this->m_names[$languageId] = $topicName;
             } else {
                 $some_name_not_set = true;
             }
         }
         if ($p_allNamesRequired && $some_name_not_set) {
             \TopicName::DeleteTopicNames($this->getTopicId());
             $success = false;
         }
         if (!$some_name_set) {
             $success = false;
         }
         if (!$success) {
             $g_ado_db->Execute("DELETE FROM Topics WHERE id = " . $this->getTopicId());
         }
     }
     if (!$success) {
         $g_ado_db->Execute("UPDATE Topics SET node_left = node_left - 2 WHERE node_left > ({$parentLeft} + 2)");
         $g_ado_db->Execute("UPDATE Topics SET node_right = node_right - 2 WHERE node_right > ({$parentLeft} + 2)");
     }
     $g_ado_db->Execute("UNLOCK TABLES");
     if ($success) {
         $this->m_exists = true;
     }
     CampCache::singleton()->clear('user');
     return $success;
 }
예제 #8
0
        /**
     * Returns an blog topics list based on the given parameters.
     *
     * @param array $p_parameters
     *    An array of ComparisonOperation objects
     * @param string $p_order
     *    An array of columns and directions to order by
     * @param integer $p_start
     *    The record number to start the list
     * @param integer $p_limit
     *    The offset. How many records from $p_start will be retrieved.
     * @param integer $p_count
     *    The total count of the elements; this count is computed without
     *    applying the start ($p_start) and limit parameters ($p_limit)
     *
     * @return array $blogTopicsList
     *    An array of Topic objects
     */
    public static function GetList(array $p_parameters, $p_order = null,
                                   $p_start = 0, $p_limit = 0, &$p_count)
    {
        global $g_ado_db;

        $selectClauseObj = new SQLSelectClause();
        $countClauseObj = new SQLSelectClause();

        // processes the parameters
        foreach ($p_parameters as $parameter) {
            $comparisonOperation = self::ProcessListParameters($parameter);
            if (sizeof($comparisonOperation) < 1) {
                break;
            }

            if (strpos($comparisonOperation['left'], 'fk_entry_id') !== false) {
                $hasBlogentryId = true;
            }
            $whereCondition = $comparisonOperation['left'] . ' '
                . $comparisonOperation['symbol'] . " '"
                . $g_ado_db->escape($comparisonOperation['right']) . "' ";
            $selectClauseObj->addWhere($whereCondition);
            $countClauseObj->addWhere($whereCondition);
        }

        // validates whether blog number was given
        if ($hasBlogentryId == false) {
            CampTemplate::singleton()->trigger_error("missed parameter Blogentry Number in statement list_blog_topics");
            return array();
        }

        // sets the main table and columns to be fetched
        $tmpBlogentryTopic = new BlogentryTopic();
        $selectClauseObj->setTable($tmpBlogentryTopic->getDbTableName());
        $selectClauseObj->addColumn('fk_topic_id');
        $countClauseObj->setTable($tmpBlogentryTopic->getDbTableName());
        $countClauseObj->addColumn('COUNT(*)');
        unset($tmpBlogTopic);

        if (!is_array($p_order)) {
            $p_order = array();
        }

        // sets the order condition if any
        foreach ($p_order as $orderColumn => $orderDirection) {
            $selectClauseObj->addOrderBy($orderColumn . ' ' . $orderDirection);
        }

        // sets the limit
        $selectClauseObj->setLimit($p_start, $p_limit);

        // builds the query and executes it
        $selectQuery = $selectClauseObj->buildQuery();
        $topics = $g_ado_db->GetAll($selectQuery);
        if (!is_array($topics)) {
            return array();
        }
        $countQuery = $countClauseObj->buildQuery();
        $p_count = $g_ado_db->GetOne($countQuery);

        // builds the array of topic objects
        $blogentryTopicsList = array();
        foreach ($topics as $topic) {
            $topObj = new Topic($topic['fk_topic_id']);
            if ($topObj->exists()) {
                $blogentryTopicsList[] = $topObj;
            }
        }

        return $blogentryTopicsList;
    } // fn GetList
예제 #9
0
    /**
     * Returns an article topics list based on the given parameters.
     *
     * @param array $p_parameters
     *    An array of ComparisonOperation objects
     * @param string $p_order
     *    An array of columns and directions to order by
     * @param integer $p_start
     *    The record number to start the list
     * @param integer $p_limit
     *    The offset. How many records from $p_start will be retrieved.
     * @param integer $p_count
     *    The total count of the elements; this count is computed without
     *    applying the start ($p_start) and limit parameters ($p_limit)
     *
     * @return array $articleTopicsList
     *    An array of Topic objects
     */
    public static function GetList(array $p_parameters, $p_order = null,
                                   $p_start = 0, $p_limit = 0, &$p_count, $p_skipCache = false)
    {
        global $g_ado_db;

        if (!$p_skipCache && CampCache::IsEnabled()) {
        	$paramsArray['parameters'] = serialize($p_parameters);
        	$paramsArray['order'] = (is_null($p_order)) ? 'null' : $p_order;
        	$paramsArray['start'] = $p_start;
        	$paramsArray['limit'] = $p_limit;
        	$cacheListObj = new CampCacheList($paramsArray, __METHOD__);
        	$articleTopicsList = $cacheListObj->fetchFromCache();
        	if ($articleTopicsList !== false
        	&& is_array($articleTopicsList)) {
        		return $articleTopicsList;
        	}
        }

        $selectClauseObj = new SQLSelectClause();
        $countClauseObj = new SQLSelectClause();
        $rootTopicIds = array();
        // processes the parameters
        foreach ($p_parameters as $parameter) {
            $comparisonOperation = self::ProcessListParameters($parameter);
            if (sizeof($comparisonOperation) < 1) {
                break;
            }

            if (strpos($comparisonOperation['left'], 'NrArticle') !== false) {
                $hasArticleNr = true;
            }

            if (strpos($comparisonOperation['left'], 'RootTopic') !== false) {
                $rootTopicIds[] = (int)$comparisonOperation['right'];
                continue;
            }

            $whereCondition = $comparisonOperation['left'] . ' '
                . $comparisonOperation['symbol'] . " '"
                . $g_ado_db->escape($comparisonOperation['right']) . "' ";
            $selectClauseObj->addWhere($whereCondition);
            $countClauseObj->addWhere($whereCondition);
        }

        // validates whether article number was given
        if ($hasArticleNr === false) {
            CampTemplate::singleton()->trigger_error("missed parameter Article Number in statement list_article_topics");
            return array();
        }

        if(count($rootTopicIds) > 0) {
            $subtopicsQuery = Topic::BuildSubtopicsQueryWithoutDepth($rootTopicIds);
            $whereCondition = 'TopicId IN ('.$subtopicsQuery->buildQuery().')';
            $selectClauseObj->addWhere($whereCondition);
            $countClauseObj->addWhere($whereCondition);
        }

        // sets the main table and columns to be fetched
        $tmpArticleTopic = new ArticleTopic();
        $selectClauseObj->setTable($tmpArticleTopic->getDbTableName());
        $selectClauseObj->addColumn('TopicId');
        $countClauseObj->setTable($tmpArticleTopic->getDbTableName());
        $countClauseObj->addColumn('COUNT(*)');
        unset($tmpArticleTopic);

        if (!is_array($p_order)) {
            $p_order = array();
        }

        // sets the order condition if any
        foreach ($p_order as $orderColumn => $orderDirection) {
            $selectClauseObj->addOrderBy($orderColumn . ' ' . $orderDirection);
        }

        // sets the limit
        $selectClauseObj->setLimit($p_start, $p_limit);

        // builds the query and executes it
        $selectQuery = $selectClauseObj->buildQuery();
        $topics = $g_ado_db->GetAll($selectQuery);
        if (is_array($topics)) {
        	$countQuery = $countClauseObj->buildQuery();
        	$p_count = $g_ado_db->GetOne($countQuery);

        	// builds the array of topic objects
        	$articleTopicsList = array();
        	foreach ($topics as $topic) {
        		$topObj = new Topic($topic['TopicId']);
        		if ($topObj->exists()) {
        			$articleTopicsList[] = $topObj;
        		}
        	}
        } else {
        	$articleTopicsList = array();
        	$p_count = 0;
        }
        if (!$p_skipCache && CampCache::IsEnabled()) {
        	$cacheListObj->storeInCache($articleTopicsList);
        }

        return $articleTopicsList;
    } // fn GetList
예제 #10
0
	camp_html_display_error(getGS('Invalid input: $1', Input::GetErrorString()), null, true);
	exit;
}

if (!$g_user->hasPermission('AttachTopicToArticle')) {
	camp_html_display_error(getGS("You do not have the right to detach topics from articles."), null, true);
	exit;
}

$articleObj = new Article($f_language_selected, $f_article_number);
if (!$articleObj->exists()) {
	camp_html_display_error(getGS('Article does not exist.'), null, true);
	exit;
}
$topicObj = new Topic($f_topic_id);
if (!$topicObj->exists()) {
	camp_html_display_error(getGS('Topic does not exist.'), null, true);
	exit;
}

ArticleTopic::RemoveTopicFromArticle($f_topic_id, $f_article_number);
$topicName = $topicObj->getName($f_language_selected);
if (empty($topicName)) {
	$topicName = $topicObj->getName(1);
}
camp_html_add_msg(getGS("The topic '$1' has been removed from article.", $topicName), "ok");
$url = camp_html_article_url($articleObj, $f_language_id, "edit.php");
camp_html_goto_page($url);

?>
예제 #11
0
	/**
	 * Processes list constraints passed in an array.
	 *
	 * @param array $p_constraints
	 * @return array
	 */
	protected function ProcessConstraints(array $p_constraints)
	{
	    $parameters = array();
	    $state = 1;
	    $attribute = null;
	    $operator = null;
	    $value = null;
	    foreach ($p_constraints as $index=>$word) {
	        switch ($state) {
	            case 1: // reading the parameter name
	                $attribute = strtolower($word);
	                if (!array_key_exists($attribute, self::$s_parameters)) {
	                    CampTemplate::singleton()->trigger_error("invalid attribute $word in statement list_blogentries, constraints parameter");
	                    return false;
	                }
	                if ($attribute == 'keyword') {
	                    $operator = new Operator('is', 'string');
	                    $state = 3;
	                } elseif ($attribute == 'matchalltopics' || $attribute == 'matchanytopic') {
	                    if ($attribute == 'matchalltopics') {
	                        $operator = new Operator('is', 'boolean');
	                        $comparisonOperation = new ComparisonOperation($attribute, $operator, 'true');
	                        $parameters[] = $comparisonOperation;
	                    }
	                    $state = 1;
	                } else {
                        $state = 2;
	                }
	                if ($attribute == 'onfrontpage' || $attribute == 'onsection') {
	                    if (($index + 1) < count($p_constraints)) {
	                        try {
	                            $operator = new Operator($p_constraints[$index+1], 'switch');
	                        }
	                        catch (InvalidOperatorException $e) {
        	                    $operator = new Operator('is', 'switch');
        	                    $comparisonOperation = new ComparisonOperation($attribute, $operator, 'on');
                	            $parameters[] = $comparisonOperation;
                	            $state = 1;
	                        }
	                    } else {
    	                    $operator = new Operator('is', 'switch');
                            $comparisonOperation = new ComparisonOperation($attribute, $operator, 'on');
                            $parameters[] = $comparisonOperation;
                            $state = 1;
	                    }
	                }
	                break;
	            case 2: // reading the operator
	                $type = self::$s_parameters[$attribute]['type'];
	                try {
	                    $operator = new Operator($word, $type);
	                }
	                catch (InvalidOperatorException $e) {
    	                CampTemplate::singleton()->trigger_error("invalid operator $word of parameter constraints.$attribute in statement list_blogentries");
	                    return false;
	                }
	                $state = 3;
	                break;
	            case 3: // reading the value to compare against
	                $type = self::$s_parameters[$attribute]['type'];
	                $metaClassName = 'Meta'.ucfirst($type);
	                try {
    	                $valueObj = new $metaClassName($word);
	                } catch (InvalidValueException $e) {
                        CampTemplate::singleton()->trigger_error("invalid value $word of parameter constraints.$attribute in statement list_blogentries");
	                    return false;
	                }
       	            if ($attribute == 'type') {
                        $word = trim($word);
       	                $blogType = new BlogType($word);
       	                if (!$blogType->exists()) {
	                        CampTemplate::singleton()->trigger_error("invalid value $word of parameter constraints.$attribute in statement list_blogentries");
	                        return false;
       	                }
       	                $value = $word;
       	            } elseif ($attribute == 'topic') {
       	                $topicObj = new Topic($word);
       	                if (!$topicObj->exists()) {
	                        CampTemplate::singleton()->trigger_error("invalid value $word of parameter constraints.$attribute in statement list_blogentries");
	                        return false;
       	                } else {
       	                    $value = $topicObj->getTopicId();
       	                }
       	            } elseif ($attribute == 'author') {
                        if (strtolower($word) == '__current') {
                        	$context = CampTemplate::singleton()->context();
                        	$value = $context->blog->author->name;
                        } else {
                        	$value = $word;
                        }
       	            } else {
       	                $value = $word;
       	            }
       	            $comparisonOperation = new ComparisonOperation($attribute, $operator, $value);
    	            $parameters[] = $comparisonOperation;
	                $state = 1;
	                break;
	        }
	    }
	    if ($state != 1) {
            CampTemplate::singleton()->trigger_error("unexpected end of constraints parameter in list_blogentries");
            return false;
	    }

		return $parameters;
	}
예제 #12
0
파일: Article.php 프로젝트: nidzix/Newscoop
 /**
  * Returns an articles list based on the given parameters.
  *
  * @param array $p_parameters
  *    An array of ComparisonOperation objects
  * @param string $p_order
  *    An array of columns and directions to order by
  * @param integer $p_start
  *    The record number to start the list
  * @param integer $p_limit
  *    The offset. How many records from $p_start will be retrieved.
  * @param integer $p_count
  *    The total count of the elements; this count is computed without
  *    applying the start ($p_start) and limit parameters ($p_limit)
  *
  * @return array $articlesList
  *    An array of Article objects
  */
 public static function GetList(array $p_parameters, $p_order = null, $p_start = 0, $p_limit = 0, &$p_count, $p_skipCache = false, $returnObjs = true)
 {
     global $g_ado_db;
     if (!$p_skipCache && CampCache::IsEnabled()) {
         $paramsArray['parameters'] = serialize($p_parameters);
         $paramsArray['order'] = is_null($p_order) ? 'null' : $p_order;
         $paramsArray['start'] = $p_start;
         $paramsArray['limit'] = $p_limit;
         $cacheListObj = new CampCacheList($paramsArray, __METHOD__);
         $articlesList = $cacheListObj->fetchFromCache();
         if ($articlesList !== false && is_array($articlesList)) {
             return $articlesList;
         }
     }
     $matchAllTopics = false;
     $hasTopics = array();
     $hasNotTopics = array();
     $selectClauseObj = new SQLSelectClause();
     $otherTables = array();
     // sets the name of the table for the this database object
     $tmpArticle = new Article();
     $articleTable = $tmpArticle->getDbTableName();
     $selectClauseObj->setTable($articleTable);
     unset($tmpArticle);
     $languageId = null;
     // parses the given parameters in order to build the WHERE part of
     // the SQL SELECT sentence
     foreach ($p_parameters as $param) {
         $comparisonOperation = self::ProcessListParameters($param, $otherTables);
         $leftOperand = strtolower($comparisonOperation['left']);
         if ($leftOperand == 'idlanguage' && $comparisonOperation['symbol'] == '=') {
             $languageId = $comparisonOperation['right'];
         }
         if (array_key_exists($leftOperand, Article::$s_regularParameters)) {
             // regular article field, having a direct correspondent in the
             // Article table fields
             $whereCondition = Article::$s_regularParameters[$leftOperand] . ' ' . $comparisonOperation['symbol'] . " " . $g_ado_db->escape($comparisonOperation['right']) . " ";
             if ($leftOperand == 'reads' && strstr($comparisonOperation['symbol'], '=') !== false && $comparisonOperation['right'] == 0) {
                 $selectClauseObj->addConditionalWhere($whereCondition);
                 $isNullCond = Article::$s_regularParameters[$leftOperand] . ' IS NULL';
                 $selectClauseObj->addConditionalWhere($isNullCond);
             } elseif ($leftOperand == 'type' && $comparisonOperation['symbol'] == '=') {
                 $selectClauseObj->addConditionalWhere($whereCondition);
             } elseif ($leftOperand == 'workflow_status' && isset($comparisonOperation['pending'])) {
                 $selectClauseObj->addConditionalWhere('Articles.NrIssue = 0');
                 $selectClauseObj->addConditionalWhere('Articles.NrSection = 0');
                 $selectClauseObj->addWhere($whereCondition);
             } else {
                 $selectClauseObj->addWhere($whereCondition);
             }
         } elseif ($leftOperand == 'matchalltopics') {
             // set the matchAllTopics flag
             $matchAllTopics = true;
         } elseif ($leftOperand == 'topic') {
             // add the topic to the list of match/do not match topics depending
             // on the operator
             $topic = new Topic($comparisonOperation['right']);
             if ($topic->exists()) {
                 $topicIds = $topic->getSubtopics(true, 0);
                 $topicIds[] = $comparisonOperation['right'];
                 if ($comparisonOperation['symbol'] == '=') {
                     $hasTopics[] = $topicIds;
                 } else {
                     $hasNotTopics[] = $topicIds;
                 }
             }
         } elseif ($leftOperand == 'author') {
             $otherTables['ArticleAuthors'] = array('__JOIN' => ',');
             $author = Author::ReadName($comparisonOperation['right']);
             $symbol = $comparisonOperation['symbol'];
             $valModifier = strtolower($symbol) == 'like' ? '%' : '';
             $firstName = trim($g_ado_db->escape($author['first_name']), "'");
             $lastName = trim($g_ado_db->escape($author['last_name']), "'");
             $whereCondition = "ArticleAuthors.fk_author_id IN\n                    (SELECT Authors.id\n                     FROM Authors\n                     WHERE CONCAT(Authors.first_name, ' ', Authors.last_name) {$symbol}\n                         '{$valModifier}{$firstName} {$lastName}{$valModifier}')";
             $selectClauseObj->addWhere($whereCondition);
             $selectClauseObj->addWhere('Articles.Number = ArticleAuthors.fk_article_number');
             $selectClauseObj->addWhere('Articles.IdLanguage = ArticleAuthors.fk_language_id');
         } elseif ($leftOperand == 'search_phrase') {
             $searchQuery = ArticleIndex::SearchQuery($comparisonOperation['right'], $comparisonOperation['symbol']);
             if (!empty($searchQuery)) {
                 $otherTables["({$searchQuery})"] = array('__TABLE_ALIAS' => 'search', '__JOIN' => 'INNER JOIN', 'Number' => 'NrArticle', 'IdLanguage' => 'IdLanguage');
             }
         } elseif ($leftOperand == 'location') {
             $num = '[-+]?[0-9]+(?:\\.[0-9]+)?';
             if (preg_match("/({$num}) ({$num}), ({$num}) ({$num})/", trim($comparisonOperation['right']), $matches)) {
                 $queryLocation = Geo_Map::GetGeoSearchSQLQuery(array(array('latitude' => $matches[1], 'longitude' => $matches[2]), array('latitude' => $matches[3], 'longitude' => $matches[4])));
                 $selectClauseObj->addWhere("Articles.Number IN ({$queryLocation})");
             }
         } elseif ($leftOperand == 'insection') {
             $selectClauseObj->addWhere("Articles.NrSection IN " . $comparisonOperation['right']);
         } elseif ($leftOperand == 'complex_date') {
             /* @var $param ComparisonOperation */
             $fieldName = key($roper = $param->getRightOperand());
             $searchValues = array();
             foreach (explode(",", current($roper)) as $values) {
                 list($key, $value) = explode(":", $values, 2);
                 $searchValues[preg_replace("`(?<=[a-z])(_([a-z]))`e", "strtoupper('\\2')", trim($key))] = trim($value);
             }
             $repo = Zend_Registry::get('container')->getService('em')->getRepository('Newscoop\\Entity\\ArticleDatetime');
             /* @var $repo \Newscoop\Entity\Repository\ArticleRepository */
             $searchValues['fieldName'] = $fieldName;
             $sqlQuery = $repo->findDates((object) $searchValues, true)->getFindDatesSQL('dt.articleId');
             if (!is_null($sqlQuery)) {
                 $whereCondition = "Articles.Number IN (\n{$sqlQuery})";
                 $selectClauseObj->addWhere($whereCondition);
             }
         } else {
             // custom article field; has a correspondence in the X[type]
             // table fields
             $sqlQuery = self::ProcessCustomField($comparisonOperation, $languageId);
             if (!is_null($sqlQuery)) {
                 $whereCondition = "Articles.Number IN (\n{$sqlQuery}        )";
                 $selectClauseObj->addWhere($whereCondition);
             }
         }
     }
     if (count($hasTopics) > 0 || count($hasNotTopics) > 0) {
         $typeAttributes = ArticleTypeField::FetchFields(null, null, 'topic', false, false, false, true, $p_skipCache);
     }
     if (count($hasTopics) > 0) {
         if ($matchAllTopics) {
             foreach ($hasTopics as $topicId) {
                 $sqlQuery = Article::BuildTopicSelectClause($topicId, $typeAttributes);
                 $whereCondition = "Articles.Number IN (\n{$sqlQuery}        )";
                 $selectClauseObj->addWhere($whereCondition);
             }
         } else {
             $sqlQuery = Article::BuildTopicSelectClause($hasTopics, $typeAttributes);
             $whereCondition = "Articles.Number IN (\n{$sqlQuery}        )";
             $selectClauseObj->addWhere($whereCondition);
         }
     }
     if (count($hasNotTopics) > 0) {
         $sqlQuery = Article::BuildTopicSelectClause($hasNotTopics, $typeAttributes);
         $whereCondition = "Articles.Number NOT IN (\n{$sqlQuery}        )";
         $selectClauseObj->addWhere($whereCondition);
     }
     // create the count clause object
     $countClauseObj = clone $selectClauseObj;
     if (!is_array($p_order)) {
         $p_order = array();
     }
     // sets the ORDER BY condition
     $p_order = array_merge($p_order, Article::$s_defaultOrder);
     $order = Article::ProcessListOrder($p_order, $otherTables, $otherWhereConditions);
     foreach ($order as $orderDesc) {
         $orderColumn = $orderDesc['field'];
         $orderDirection = $orderDesc['dir'];
         $selectClauseObj->addOrderBy($orderColumn . ' ' . $orderDirection);
     }
     if (count($otherTables) > 0) {
         foreach ($otherTables as $table => $fields) {
             $joinType = 'LEFT JOIN';
             if (isset($fields['__JOIN'])) {
                 $joinType = $fields['__JOIN'];
             }
             if (isset($fields['__TABLE_ALIAS'])) {
                 $tableAlias = $fields['__TABLE_ALIAS'];
                 $tableJoin = "\n    {$joinType} {$table} AS {$tableAlias} \n";
             } else {
                 $tableAlias = $table;
                 $tableJoin = "\n    {$joinType} {$tableAlias} \n";
             }
             $firstCondition = true;
             foreach ($fields as $parent => $child) {
                 if ($parent == '__TABLE_ALIAS' || $parent == '__JOIN') {
                     continue;
                 }
                 $condOperator = $firstCondition ? ' ON ' : 'AND ';
                 if ($parent == '__CONST') {
                     $constTable = $child['table'];
                     $constField = $child['field'];
                     $value = $child['value'];
                     $negate = isset($child['negate']) ? $child['negate'] : false;
                     if (is_null($value)) {
                         $operator = $negate ? 'IS NOT' : 'IS';
                         $value = 'NULL';
                     } else {
                         $operator = $negate ? '!=' : '=';
                         $value = $g_ado_db->escape($value);
                     }
                     $tableJoin .= "        {$condOperator}`{$constTable}`.`{$constField}` {$operator} {$value}\n";
                 } else {
                     $tableJoin .= "        {$condOperator}`{$articleTable}`.`{$parent}` = `{$tableAlias}`.`{$child}`\n";
                 }
                 $firstCondition = false;
             }
             $selectClauseObj->addJoin($tableJoin);
             $countClauseObj->addJoin($tableJoin);
         }
     }
     // other where conditions needed for certain order options
     foreach ($otherWhereConditions as $whereCondition) {
         $selectClauseObj->addWhere($whereCondition);
         $countClauseObj->addWhere($whereCondition);
     }
     // gets the column list to be retrieved for the database table
     $selectClauseObj->addColumn('Articles.Number');
     $selectClauseObj->addColumn('Articles.IdLanguage');
     $countClauseObj->addColumn('COUNT(*)');
     // sets the LIMIT start and offset values
     $selectClauseObj->setLimit($p_start, $p_limit);
     // builds the SQL query
     $selectQuery = $selectClauseObj->buildQuery();
     $countQuery = $countClauseObj->buildQuery();
     // runs the SQL query
     $articles = $g_ado_db->GetAll($selectQuery);
     if (is_array($articles)) {
         $p_count = $g_ado_db->GetOne($countQuery);
         // builds the array of Article objects
         $articlesList = array();
         foreach ($articles as $article) {
             if ($returnObjs) {
                 $articlesList[] = new Article($article['IdLanguage'], $article['Number']);
             } else {
                 $articlesList[] = array('language_id' => $article['IdLanguage'], 'number' => $article['Number']);
             }
         }
     } else {
         $articlesList = array();
         $p_count = 0;
     }
     // stores articles list in cache
     if (!$p_skipCache && CampCache::IsEnabled()) {
         $cacheListObj->storeInCache($articlesList);
     }
     return $articlesList;
 }
예제 #13
0
	/**
	 * Create a new topic.
	 *
	 * The values array may have the following keys:
	 * - parent_id - parent topic identifier
	 * - id - topic identifier; if not supplied generated automatically
	 * - node_left
	 * - node_right
	 * - names - array of topic translations of the form: language_id => name
	 *
	 * @param array $p_values
	 * @return boolean
	 */
	public function create($p_values = null)
	{
		global $g_ado_db;

		if (!isset($p_values['names'])) {
			return false;
		}

		$g_ado_db->Execute("LOCK TABLE Topics WRITE, TopicNames WRITE");

		if (isset($p_values['parent_id']) && !empty($p_values['parent_id'])) {
			$parent = new Topic($p_values['parent_id']);
			if (!$parent->exists()) {
				$g_ado_db->Execute("UNLOCK TABLES");
				return false;
			}
			$parentLeft = (int)$parent->getLeft();
		} else {
			$parentLeft = 0;
		}

		$g_ado_db->Execute("UPDATE Topics SET node_left = node_left + 2 WHERE node_left > $parentLeft");
		$g_ado_db->Execute("UPDATE Topics SET node_right = node_right + 2 WHERE node_right > $parentLeft");

		$this->m_data['node_left'] = $parentLeft + 1;
		$this->m_data['node_right'] = $parentLeft + 2;

		// create node
		if ($success = parent::create($p_values)) {
			// create topic names
			foreach ($p_values['names'] as $languageId=>$name) {
				$topicName = new TopicName($this->getTopicId(), $languageId);
				$topicName->create(array('name'=>$name));
				$this->m_names[$languageId] = $topicName;
			}
		}

		$g_ado_db->Execute("UNLOCK TABLES");

		if ($success) {
			$this->m_exists = true;
			if (function_exists("camp_load_translation_strings")) {
				camp_load_translation_strings("api");
			}
			$logtext = getGS('Topic "$1" ($2) added', implode(', ', $this->m_names), $this->m_data['id']);
			Log::Message($logtext, null, 141);
		}
		CampCache::singleton()->clear('user');
		return $success;
	} // fn create