Inheritance: extends DatabaseObject
Ejemplo n.º 1
0
 public function setProperty($p_dbColumnName, $p_value, $p_commit = true, $p_isSql = false)
 {
     if (!in_array($p_dbColumnName, $this->m_columnNames)) {
         return false;
     }
     $articleField = new ArticleTypeField($this->m_articleTypeName, substr($p_dbColumnName, 1));
     if ($articleField->getType() == ArticleTypeField::TYPE_BODY) {
         // Replace <span class="subhead"> ... </span> with <!** Title> ... <!** EndTitle>
         $text = preg_replace_callback("/(<\\s*span[^>]*class\\s*=\\s*[\"']campsite_subhead[\"'][^>]*>|<\\s*span|<\\s*\\/\\s*span\\s*>)/i", array('ArticleData', "TransformSubheads"), $p_value);
         // Replace <a href="campsite_internal_link?IdPublication=1&..." ...> ... </a>
         // with <!** Link Internal IdPublication=1&...> ... <!** EndLink>
         $text = preg_replace_callback("/(<\\s*a\\s*(((href\\s*=\\s*[\"'](\\/campsite\\/)?campsite_internal_link[?][\\w&=;]*[\"'])|(\\w+\\s*=\\s*['\"][_\\w]*['\"]))+[\\s]*)*[\\s\\w\"']*>)|(<\\s*\\/a\\s*>)/i", array('ArticleData', "TransformInternalLinks"), $text);
         // Replace <img id=".." src=".." alt=".." title=".." align="..">
         // with <!** Image [image_template_id] align=".." alt=".." sub="..">
         $idAttr = "(id\\s*=\\s*\"[^\"]*\")";
         $srcAttr = "(src\\s*=\\s*\"[^\"]*\")";
         $altAttr = "(alt\\s*=\\s*\"[^\"]*\")";
         $subAttr = "(title\\s*=\\s*\"[^\"]*\")";
         $alignAttr = "(align\\s*=\\s*\"[^\"]*\")";
         $widthAttr = "(width\\s*=\\s*\"[^\"]*\")";
         $heightAttr = "(height\\s*=\\s*\"[^\"]*\")";
         $otherAttr = "(\\w+\\s*=\\s*\"[^\"]*\")*";
         $pattern = "/<\\s*img\\s*(({$idAttr}|{$srcAttr}|{$altAttr}|{$subAttr}|{$alignAttr}|{$widthAttr}|{$heightAttr}|{$otherAttr})\\s*)*\\/>/i";
         $p_value = preg_replace_callback($pattern, array($this, "transformImageTags"), $text);
     }
     if ($articleField->getType() == ArticleTypeField::TYPE_SWITCH) {
         return parent::setProperty($p_dbColumnName, (int) ($p_value == 'on'), $p_commit);
     }
     return parent::setProperty($p_dbColumnName, $p_value, $p_commit, $p_isSql);
 }
Ejemplo n.º 2
0
	/**
	 * Gets the translation for a given language; default language is the
	 * session language.  If no translation is set for that language, we
	 * return the dbTableName.
     *
	 * @param int p_lang
	 *
	 * @return string
	 */
	public function getDisplayName($p_lang = 0)
	{
		$displayName = $this->m_metadata->getDisplayName($p_lang);
		if ($displayName == 'NULL') {
			return $this->m_name;
		}
		return $displayName;
	} // fn getDisplayName
Ejemplo n.º 3
0
 /**
  * Returns the content of the given subtitles of the article body field.
  *
  * @param array $p_subtitles
  * @return string
  */
 private function getContent(array $p_subtitles = array())
 {
     global $Campsite;
     $printAll = count($p_subtitles) == 0;
     $content = '';
     foreach ($this->m_subtitles as $index => $subtitle) {
         if (!$printAll && array_search($index, $p_subtitles) === false) {
             continue;
         }
         $content .= $index > 0 ? $subtitle->formatted_name : '';
         $content .= $subtitle->content;
     }
     if ($this->m_articleTypeField->isContent()) {
         $cacheService = \Zend_Registry::get('container')->getService('newscoop.cache');
         $cacheKeyObjectType = $cacheService->getCacheKey(array('ObjectType', 'article'), 'ObjectType');
         if ($cacheService->contains($cacheKeyObjectType)) {
             $objectType = $cacheService->fetch($cacheKeyObjectType);
         } else {
             $objectType = new ObjectType('article');
             $cacheService->save($cacheKeyObjectType, $objectType);
         }
         $requestObjectId = $this->m_parent_article->getProperty('object_id');
         $updateArticle = empty($requestObjectId);
         try {
             if ($updateArticle) {
                 $requestObject = new RequestObject($requestObjectId);
                 if (!$requestObject->exists()) {
                     $requestObject->create(array('object_type_id' => $objectType->getObjectTypeId()));
                     $requestObjectId = $requestObject->getObjectId();
                 }
                 $this->m_parent_article->setProperty('object_id', $requestObjectId);
             }
             // statistics shall be only gathered if the site admin set it on (and not for editor previews)
             $context = CampTemplate::singleton()->context();
             $preferencesService = \Zend_Registry::get('container')->getService('system_preferences_service');
             if ($preferencesService->CollectStatistics == 'Y' && !$context->preview) {
                 $stat_web_url = $Campsite['WEBSITE_URL'];
                 if ('/' != $stat_web_url[strlen($stat_web_url) - 1]) {
                     $stat_web_url .= '/';
                 }
                 $article_number = $this->m_parent_article->getProperty('Number');
                 $language_obj = new MetaLanguage($this->m_parent_article->getProperty('IdLanguage'));
                 $language_code = $language_obj->Code;
                 $name_spec = '_' . $article_number . '_' . $language_code;
                 $object_type_id = $objectType->getObjectTypeId();
                 $content .= Statistics::JavaScriptTrigger(array('name_spec' => $name_spec, 'object_type_id' => $object_type_id, 'request_object_id' => $requestObjectId));
             }
         } catch (Exception $ex) {
             $content .= "<p><strong><font color=\"red\">INTERNAL ERROR! " . $ex->getMessage() . "</font></strong></p>\n";
             // do something
         }
     }
     return $content;
 }
Ejemplo n.º 4
0
    private static function ProcessCustomField(array $p_comparisonOperation, $p_languageId = null)
    {
        global $g_ado_db;

        $fieldName = $p_comparisonOperation['left'];
        $fieldParts = preg_split('/\./', $fieldName);
        if (count($fieldParts) > 1) {
            $fieldName = $fieldParts[1];
            $articleType = $fieldParts[0];
            $field = new ArticleTypeField($articleType, $fieldName);
            if (!$field->exists()) {
                return null;
            }
            $fields = array($field);
        } else {
            $articleType = null;
            $fields = ArticleTypeField::FetchFields($fieldName, $articleType,
            null, false, false, false, true, true);
            if (count($fields) == 0) {
                return null;
            }
        }
        $queries = array();
        foreach ($fields as $fieldObj) {
            $query .= '        SELECT NrArticle FROM `X' . $fieldObj->getArticleType()
                   . '` WHERE ' . $fieldObj->getName() . ' '
                   . $p_comparisonOperation['symbol']
                   . " '" . $g_ado_db->escape($p_comparisonOperation['right']) . "'";
            if (!is_null($p_languageId)) {
                $query .= " AND IdLanguage = '" . $g_ado_db->escape($p_languageId) . "'";
            }
            $query .= "\n";
            $queries[] = $query;
        }
        if (count($queries) == 0) {
            return null;
        }
        return implode("        union\n", $queries);
    }
Ejemplo n.º 5
0
 /**
  * Returns an array of fields from all article types that match
  * the given conditions.
  *
  * @param $p_name
  *         if specified returns fields with the given name
  * @param $p_articleType
  *         if specified returns fields of the given article type
  * @param $p_dataType
  *         if specified returns the fields having the given data type
  *
  * @return array
  */
 public static function FetchFields($p_name = null, $p_articleType = null, $p_dataType = null, $p_negateName = false, $p_negateArticleType = false, $p_negateDataType = false, $p_selectHidden = true, $p_skipCache = false)
 {
     global $g_ado_db;
     if (!$p_skipCache && CampCache::IsEnabled()) {
         $paramsArray['name'] = is_null($p_name) ? 'null' : $p_name;
         $paramsArray['article_type'] = is_null($p_articleType) ? 'null' : $p_articleType;
         $paramsArray['data_type'] = is_null($p_dataType) ? 'null' : $p_dataType;
         $paramsArray['negate_name'] = $p_negateName == false ? 'false' : 'true';
         $paramsArray['negate_article_type'] = $p_negateArticleType == false ? 'false' : 'true';
         $paramsArray['negate_data_type'] = $p_negateDataType == false ? 'false' : 'true';
         $paramsArray['select_hidden'] = $p_selectHidden == false ? 'false' : 'true';
         $cacheListObj = new CampCacheList($paramsArray, __METHOD__);
         $articleTypeFieldsList = $cacheListObj->fetchFromCache();
         if ($articleTypeFieldsList !== false && is_array($articleTypeFieldsList)) {
             return $articleTypeFieldsList;
         }
     }
     $whereClauses = array();
     if (isset($p_name)) {
         $operator = $p_negateName ? '<>' : '=';
         $whereClauses[] = "field_name {$operator} " . $g_ado_db->escape($p_name);
     }
     if (isset($p_articleType)) {
         $operator = $p_negateArticleType ? '<>' : '=';
         $whereClauses[] = "type_name {$operator} " . $g_ado_db->escape($p_articleType);
     }
     if (isset($p_dataType)) {
         $operator = $p_negateDataType ? '<>' : '=';
         $whereClauses[] = "field_type {$operator} " . $g_ado_db->escape($p_dataType);
     }
     if (!$p_selectHidden) {
         $whereClauses[] = 'is_hidden = false';
     }
     $where = count($whereClauses) > 0 ? ' WHERE ' . implode(' and ', $whereClauses) : null;
     $query = "SELECT * FROM `ArticleTypeMetadata` {$where} ORDER BY type_name ASC, field_weight ASC";
     $rows = $g_ado_db->GetAll($query);
     $fields = array();
     foreach ($rows as $row) {
         $field = new ArticleTypeField($row['type_name'], $row['field_name']);
         if ($field->getPrintName() == '') {
             $field->delete();
             continue;
         }
         $fields[] = $field;
     }
     if (!$p_skipCache && CampCache::IsEnabled()) {
         $cacheListObj->storeInCache($fields);
     }
     return $fields;
 }
Ejemplo n.º 6
0
    protected function getCustomProperty($p_property)
    {
        $property = $this->translateProperty($p_property);
        if (isset($this->m_customProperties[$property])
        && is_array($this->m_customProperties[$property])) {
            try {
                $dbProperty = $this->m_customProperties[$property][0];
                $fieldValue = $this->m_articleData->getProperty('F'.$dbProperty);

                $articleFieldType = new ArticleTypeField($this->type_name, $dbProperty);
                if ($articleFieldType->getType() == ArticleTypeField::TYPE_BODY) {
                    if (is_null($this->getContentCache($property))) {
                    	$context = CampTemplate::singleton()->context();
                    	$subtitleId = $this->subtitle_url_id($property);
                        $subtitleNo = $context->default_url->get_parameter($subtitleId);
                        if (is_null($subtitleNo)) {
                            $subtitleNo = 0;
                        } elseif ($subtitleNo === 'all') {
                            $subtitleNo = null;
                        }
                        $bodyField = new MetaArticleBodyField($fieldValue, $this,
                                         $articleFieldType->getPrintName(), $this->name, $subtitleNo,
                                         '<span class="subtitle"><p>', '</p></span>');
                        $this->setContentCache($property, $bodyField);
                    }
                    $fieldValue = $this->getContentCache($property);
                }
                if ($articleFieldType->getType() == ArticleTypeField::TYPE_TOPIC) {
                    $fieldValue = new MetaTopic($fieldValue);
                }
                return $fieldValue;
            } catch (InvalidPropertyException $e) {
                // do nothing; will throw another exception with original property field name
            }
            throw new InvalidPropertyException(get_class($this->m_dbObject), $p_property);
        }
        return parent::getCustomProperty($p_property);
    }
Ejemplo n.º 7
0
		camp_set_author($field, $errors);
		if (count($errors) == 0) {
			camp_html_add_msg(getGS("The author was set successfuly for articles of type '$1' from the field '$2'.",
			                        $field->getArticleType(), $field->getPrintName()), 'ok');
		} else {
            camp_html_add_msg(getGS("There were errors setting the author for articles of type '$1' from the field '$2'.",
                                    $field->getArticleType(), $field->getPrintName()));
		}
        foreach ($errors as $error) {
            camp_html_add_msg($error);
        }
	}
    camp_html_display_msgs();
}

$availableFields = ArticleTypeField::FetchFields(null, null, 'text', false, false, false, true, true);

?>

<br/>
<form name="f_set_author" method="post">
<TABLE BORDER="0" CELLSPACING="4" CELLPADDING="2" CLASS="table_input">
<TR>
    <TD VALIGN="TOP" align="left" nowrap>
        <?php putGS("Select the field from which to generate the author"); ?>:
    </td>
    <td valign="top" align="left">
        <select name="f_src_author_field">
        <?php
        foreach ($availableFields as $field) {
        	echo "<option value=\"" . htmlspecialchars($field->getPrintName())
Ejemplo n.º 8
0
function camp_set_author(ArticleTypeField $p_sourceField, &$p_errors)
{
    $translator = \Zend_Registry::get('container')->getService('translator');
    $p_errors = array();
    $articles = Article::GetArticlesOfType($p_sourceField->getArticleType());
    foreach ($articles as $article) {
        $articleData = $article->getArticleData();
        $authorName = trim($articleData->getFieldValue($p_sourceField->getPrintName()));
        if (empty($authorName)) {
            continue;
        }
        $author = new Author($authorName);
        if (!$author->exists()) {
            if (!$author->create()) {
                $p_errors[] = $translator->trans('Unable to create author $1 for article no. $2 ($3) of type $4.', array('$1' => $author->getName(), '$2' => $article->getArticleNumber(), '$3' => $article->getName(), '$4' => $article->getType()), 'home');
                continue;
            }
        }
        if (!$article->setAuthorId($author->getId())) {
            $p_errors[] = $translator->trans('Error setting the author $1 for article no. $2 ($3) of type $4.', array('$1' => $author->getName(), '$2' => $article->getArticleNumber(), '$3' => $article->getName(), '$4' => $article->getType()), 'home');
            continue;
        }
    }
    $cacheService = \Zend_Registry::get('container')->getService('newscoop.cache');
    $cacheService->clearNamespace('authors');
    $cacheService->clearNamespace('article');
    return count($p_errors);
}
Ejemplo n.º 9
0
	$valid = ArticleType::IsValidFieldName($f_name);
	if (!$valid) {
		$correct = false;
		$errorMsgs[] = getGS('The $1 field may only contain letters and underscore (_) character.', '<B>' . getGS('Name') . '</B>');
    }

    if ($correct) {
    	$old_articleTypeField = new ArticleTypeField($articleTypeName, $f_oldName);
    	if (!$old_articleTypeField->exists()) {
		    $correct = false;
		    $errorMsgs[] = getGS('The field $1 does not exist.', '<B>'.htmlspecialchars($f_oldName).'</B>');
		}
    }

	if ($correct) {
		$articleTypeField = new ArticleTypeField($articleTypeName, $f_name);
		if ($articleTypeField->exists()) {
			$correct = false;
			$errorMsgs[] = getGS('The field $1 already exists.', '<B>'. htmlspecialchars($f_name). '</B>');
		}
	}

	if ($correct) {
		$article = new MetaArticle();
		if ($article->has_property($f_name) || method_exists($article, $f_name)) {
			$correct = false;
			$errorMsgs[] = getGS("The property '$1' is already in use.", $f_name);
		}
	}

    if ($correct) {
Ejemplo n.º 10
0
 /**
  * Create article type if does not exist
  *
  * @param string $typeName
  * @return ArticleType
  */
 private function getArticleType($typeName)
 {
     $requiredFields = array('guid' => 'text', 'version' => 'text', 'urgency' => 'text', 'copyright' => 'text', 'provider' => 'text', 'description' => 'body', 'dateline' => 'text', 'byline' => 'text', 'creditline' => 'text', 'inlinecontent' => 'body');
     $type = new \ArticleType($typeName);
     if (!$type->exists()) {
         $type->create();
     }
     $missingFields = array_diff(array_keys($requiredFields), $this->getFieldNames($type));
     foreach ($missingFields as $fieldName) {
         $field = new \ArticleTypeField($type->getTypeName(), $fieldName);
         $field->create($requiredFields[$fieldName]);
     }
     return $type;
 }
Ejemplo n.º 11
0
 /**
  * Delete the topic.
  * @return boolean
  */
 public function delete($p_languageId = null)
 {
     global $g_ado_db;
     $g_ado_db->Execute("LOCK TABLE Topics WRITE, TopicNames WRITE, TopicFields READ, ArticleTypeMetadata WRITE");
     $topicId = $this->getTopicId();
     if ($p_languageId > 0 && $this->getNumTranslations() > 1) {
         $deletedName = $this->m_names[$p_languageId];
         $topicName = new TopicName($this->getTopicId(), $p_languageId);
         $deleted = $topicName->delete();
         if ($deleted) {
             unset($this->m_names[$p_languageId]);
         }
     } else {
         $deletedName = implode(",", $this->m_names);
         // Delete the article type field metadata
         $sql = "SELECT * FROM TopicFields WHERE RootTopicId IN " . "(SELECT DISTINCT Id FROM Topics WHERE node_left >= " . $this->m_data['node_left'] . " AND node_right < " . $this->m_data['node_right'] . ")";
         $rows = $g_ado_db->GetAll($sql);
         foreach ($rows as $row) {
             $delATF = new ArticleTypeField($row['ArticleType'], $row['FieldName']);
             $delATF->delete();
         }
         // Delete topic names
         TopicName::DeleteTopicNames($this->getTopicId());
         // Delete children and itself
         $sql = "DELETE FROM Topics WHERE node_left >= " . $this->m_data['node_left'] . ' AND node_right <= ' . $this->m_data['node_right'];
         $deleted = $g_ado_db->Execute($sql);
         if ($deleted) {
             $myWidth = $this->m_data['node_right'] - $this->m_data['node_left'] + 1;
             $sql = "UPDATE Topics SET node_left = node_left - {$myWidth} WHERE node_left > " . $this->m_data['node_left'];
             $g_ado_db->Execute($sql);
             $sql = "UPDATE Topics SET node_right = node_right - {$myWidth} WHERE node_right > " . $this->m_data['node_right'];
             $g_ado_db->Execute($sql);
         }
         $this->m_data = array();
         $this->m_exists = false;
     }
     $g_ado_db->Execute("UNLOCK TABLES");
     CampCache::singleton()->clear('user');
     return $deleted;
 }
Ejemplo n.º 12
0
if (!SecurityToken::isValid()) {
    camp_html_display_error(getGS('Invalid security token!'));
    exit;
}

// Check permissions
if (!$g_user->hasPermission('ManageArticleTypes')) {
	camp_html_display_error(getGS("You do not have the right to add article type fields."));
	exit;
}

$articleTypeName = Input::Get('f_article_type');
$fieldName = trim(Input::Get('f_field_name'));
$fieldType = trim(Input::Get('f_article_field_type'));

$field = new ArticleTypeField($articleTypeName, $fieldName);

$correct = true;
$errorMsgs = array();

if (!$field->exists()) {
	$errorMsgs[] = getGS('The field $1 does not exist.', '<B>'.urlencode($fieldName).'</B>');
	$correct = false;
}

if (array_search($fieldType, $field->getConvertibleToTypes()) === false) {
	$errorMsgs[] = getGS('Can not convert the field $1 from $2 to type $3.',
	$fieldName, $field->getType(), $fieldType);
	$correct = false;
}
Ejemplo n.º 13
0
 public function getdatesAction()
 {
     require_once $GLOBALS['g_campsiteDir'] . '/classes/Article.php';
     require_once $GLOBALS['g_campsiteDir'] . '/classes/ArticleTypeField.php';
     $field_ranks = array();
     $field_infos = array();
     $dark_blues = array('#4040ff', '#8040ff');
     $yellow = '#ffff40';
     $articleId = $this->_request->getParam('articleId');
     $languageId = $this->_request->getParam('languageId');
     $article_obj = new \Article($languageId, $articleId);
     $article_type = $article_obj->getType();
     $repo = $this->_helper->entity->getRepository('Newscoop\\Entity\\ArticleDatetime');
     $return = array();
     $dates = $repo->findDates((object) array('articleId' => "{$articleId}"));
     foreach ($dates as $date) {
         $recurring = $date->getRecurring();
         $event_comment = $date->getEventComment();
         $itemField = $date->getFieldName();
         $itemColor = '#';
         $itemRank = 0;
         $itemHidden = false;
         if (array_key_exists($itemField, $field_ranks)) {
             $itemRank = $field_ranks[$itemField];
         } else {
             $field_obj = new \ArticleTypeField($article_type, $itemField);
             $allItemRanks = $field_obj->getOrders();
             foreach ($allItemRanks as $one_weight => $one_field) {
                 $field_ranks[$one_field] = $one_weight;
                 if ($one_field == $itemField) {
                     $itemRank = $one_weight;
                 }
             }
         }
         if (array_key_exists($itemField, $field_infos)) {
             $itemColor = $field_infos[$itemField]['background_color'];
             $itemHidden = $field_infos[$itemField]['hidden_status'];
         } else {
             $field_obj = new \ArticleTypeField($article_type, $itemField);
             $itemColor = $field_obj->getColor();
             $itemHidden = $field_obj->isHidden();
             $field_infos[$itemField] = array('background_color' => $itemColor, 'hidden_status' => $itemHidden);
         }
         if ($itemHidden) {
             continue;
         }
         if (strlen($recurring) > 1) {
             //daterange
             $start = strtotime($this->getDate($date->getStartDate()->getTimestamp()) . ' ' . $this->getTime(is_null($date->getStartTime()) ? $this->tz : $date->getStartTime()->getTimestamp()) . ' UTC');
             $end = strtotime($this->getDate(is_null($date->getEndDate()) ? $this->distant : $date->getEndDate()->getTimestamp()) . ' ' . $this->getTime(is_null($date->getEndTime()) ? $this->tz + 86399 : $date->getEndTime()->getTimestamp()) . ' UTC');
             $itemStart = $start;
             $itemEnd = strtotime($this->getDate($date->getStartDate()->getTimestamp()) . ' ' . $this->getTime(is_null($date->getEndTime()) ? $this->tz + 86399 : $date->getEndTime()->getTimestamp()) . ' UTC');
             $step = "+1 day";
             switch ($recurring) {
                 case 'weekly':
                     $step = "+1 week";
                     break;
                 case 'monthly':
                     $step = "+1 month";
                     break;
             }
             while ($itemStart <= $end) {
                 $calDate = array();
                 $calDate['id'] = $date->id;
                 $calDate['title'] = $itemField;
                 $calDate['start_utc'] = $itemStart;
                 $calDate['start'] = gmdate('Y-m-d\\TH:i:s\\Z', $itemStart);
                 $calDate['start_day'] = gmdate('m-d', $itemStart);
                 $calDate['end_utc'] = $itemEnd;
                 $calDate['end'] = gmdate('Y-m-d\\TH:i:s\\Z', $itemEnd);
                 $calDate['allDay'] = $this->isAllDay($date);
                 $calDate['field_name'] = $itemField;
                 $calDate['backgroundColor'] = $itemColor;
                 $calDate['textColor'] = '#000000';
                 $calDate['event_comment'] = $event_comment;
                 $calDate['weight'] = $itemRank;
                 $return[] = $calDate;
                 if ('+1 month' == $step) {
                     $curr_start_year = date('Y', $itemStart);
                     $curr_start_month = date('n', $itemStart);
                     $curr_start_day = date('j', $itemStart);
                     while (true) {
                         $curr_start_month += 1;
                         if (13 == $curr_start_month) {
                             $curr_start_month = 1;
                             $curr_start_year += 1;
                         }
                         if (checkdate($curr_start_month, $curr_start_day, $curr_start_year)) {
                             $itemStart = mktime(date('G', $itemStart), 0 + ltrim(date('i', $itemStart), '0'), 0, $curr_start_month, $curr_start_day, $curr_start_year);
                             $itemEnd = mktime(date('G', $itemEnd), 0 + ltrim(date('i', $itemEnd), '0'), 0, $curr_start_month, $curr_start_day, $curr_start_year);
                             break;
                         }
                     }
                 } else {
                     $itemStart = strtotime($step, $itemStart);
                     $itemEnd = strtotime($step, $itemEnd);
                 }
             }
         } else {
             //specific
             $calDate = array();
             $calDate['id'] = $date->id;
             $calDate['title'] = $itemField;
             $itemStart = strtotime($this->getDate($date->getStartDate()->getTimestamp()) . ' ' . $this->getTime(is_null($date->getStartTime()) ? $this->tz : $date->getStartTime()->getTimestamp()) . ' UTC');
             $calDate['start_utc'] = $itemStart;
             $calDate['start'] = gmdate('Y-m-d\\TH:i:s\\Z', $itemStart);
             $calDate['start_day'] = gmdate('m-d', $itemStart);
             $endDate = $date->getEndDate();
             // TODO: at this moment, specific dates without end dates are taken as single-date dates, even though they should be taken as never-ending continuous events
             $itemEnd = 0;
             if (empty($endDate)) {
                 $itemEnd = strtotime($this->getDate($date->getStartDate()->getTimestamp()) . ' ' . $this->getTime(is_null($date->getEndTime()) ? $this->tz + 86399 : $date->getEndTime()->getTimestamp()) . ' UTC');
             } else {
                 $itemEnd = strtotime($this->getDate($date->getEndDate()->getTimestamp()) . ' ' . $this->getTime(is_null($date->getEndTime()) ? $this->tz + 86399 : $date->getEndTime()->getTimestamp()) . ' UTC');
             }
             $calDate['end_utc'] = $itemEnd;
             $calDate['end'] = gmdate('Y-m-d\\TH:i:s\\Z', $itemEnd);
             $calDate['allDay'] = $this->isAllDay($date);
             $calDate['restOfDay'] = false;
             if (!$calDate['allDay']) {
                 if (is_null($date->getEndTime())) {
                     $calDate['restOfDay'] = true;
                 }
             }
             $calDate['field_name'] = $itemField;
             $calDate['backgroundColor'] = $itemColor;
             $calDate['textColor'] = '#000000';
             if (in_array($itemColor, $dark_blues)) {
                 $calDate['textColor'] = $yellow;
             }
             $calDate['event_comment'] = $event_comment;
             $calDate['weight'] = $itemRank;
             $return[] = $calDate;
         }
     }
     $res = usort($return, 'self::EventOrder');
     echo json_encode($return);
     die;
 }
Ejemplo n.º 14
0
//$Path = camp_topic_path($topicParent, $f_topic_language_id);

$errorMsgs = array();
if (empty($f_field_translation_name)) {
	$correct = false;
	$errorMsgs[] = getGS('You must fill in the $1 field.','<B>'.getGS('Name').'</B>');
}

if ($f_field_language_id <= 0) {
	$correct = false;
	$errorMsgs[] = getGS('You must choose a language for the field.');
}

if ($correct) {
	// Translate existing type
	$field = new ArticleTypeField($f_article_type, $f_field_id);
	$created = $field->setName($f_field_language_id, $f_field_translation_name);
	if ($created) {
		camp_html_goto_page("/$ADMIN/article_types/fields/?f_article_type=". $f_article_type);
		exit;
	}
	else {
		$errorMsgs[] = getGS('The translation could not be added.');
	}
}

$crumbs = array();
$crumbs[] = array(getGS("Configure"), "");
$crumbs[] = array(getGS("Article Types"), "/$ADMIN/article_types/");
$crumbs[] = array($f_article_type, '');
$crumbs[] = array(getGS("Article type fields"), "/$ADMIN/article_types/fields/?f_article_type=".urlencode($f_article_type));
 /**
  * Extends article type table with configured fields
  * NOTE: This ia a hack, should be converted to new ArticleType Entity
  */
 private function extendArticleTypeTable()
 {
     // Create article type
     $tableName = $this->getTableName();
     $query = '';
     $types = \ArticleTypeField::DatabaseTypes(null, null);
     $articleTypeFields = $this->getArticleTypeConfiguration();
     foreach ($articleTypeFields as $fieldId => $fieldData) {
         $query .= "ALTER TABLE `" . $tableName . "` ADD COLUMN `F" . $fieldId . '` ' . $types[$fieldData['type']] . ';';
     }
     $this->connection->exec($query);
 }
Ejemplo n.º 16
0
if (!$g_user->hasPermission('ManageArticleTypes')) {
    camp_html_display_error($translator->trans("You do not have the right to add article type fields.", array(), 'article_type_fields'));
    exit;
}
$articleTypeName = Input::Get('f_article_type');
$fieldName = trim(Input::Get('f_field_name'));
$showInEditor = Input::Get('f_show_in_editor', 'int', 0);
$fieldType = trim(Input::Get('f_article_field_type'));
$rootTopicId = Input::Get('f_root_topic_id', 'int', 0);
$isContent = Input::Get('f_is_content');
$precision = Input::Get('f_precision');
$editorSize = Input::Get('f_editor_size');
$editorSizeCustom = Input::Get('f_editor_size_custom');
$maxsize = Input::Get('f_maxsize');
$eventColor = Input::Get('f_event_color');
$field = new ArticleTypeField($articleTypeName, $fieldName);
$correct = true;
$errorMsgs = array();
if (!ArticleType::IsValidFieldName($fieldName)) {
    $errorMsgs[] = $translator->trans('The $1  must not be void and may only contain letters and underscore (_) character.', array('$1' => $translator->trans('Name')), 'article_type_fields');
    $correct = false;
}
if ($field->exists()) {
    $errorMsgs[] = $translator->trans('The field $1 already exists.', array('$1' => '<B>' . urlencode($fieldName) . '</B>'), 'article_type_fields');
    $correct = false;
}
$validTypes = array_keys(ArticleTypeField::DatabaseTypes());
if (!in_array($fieldType, $validTypes)) {
    $errorMsgs[] = $translator->trans('Invalid field type.', array(), 'article_type_fields');
    $correct = false;
}
Ejemplo n.º 17
0
<?php

camp_load_translation_strings("article_types");
require_once $GLOBALS['g_campsiteDir'] . '/classes/Log.php';
require_once $GLOBALS['g_campsiteDir'] . '/classes/Input.php';
require_once $GLOBALS['g_campsiteDir'] . '/classes/Article.php';
require_once $GLOBALS['g_campsiteDir'] . '/classes/ArticleType.php';
if (!Saas::singleton()->hasPermission('ManageArticleTypes')) {
    camp_html_display_error(getGS("You do not have the right to delete article types."));
    exit;
}
if (!SecurityToken::isValid()) {
    camp_html_display_error(getGS('Invalid security token!'));
    exit;
}
$articleTypeName = Input::Get('f_article_type');
$articleTypeFieldName = Input::Get('f_field_name');
$isContent = Input::Get('f_is_content');
$errorMsgs = array();
$articleTypeField = new ArticleTypeField($articleTypeName, $articleTypeFieldName);
$articleTypeField->setIsContent($isContent == 'true');
camp_html_goto_page("/{$ADMIN}/article_types/fields/?f_article_type=" . urlencode($articleTypeName));
Ejemplo n.º 18
0
	private static function ReadDynamicFields()
	{
		if (is_null(self::$s_dynamicFields)) {
            require_once($GLOBALS['g_campsiteDir'].'/classes/ArticleTypeField.php');
			self::$s_dynamicFields = ArticleTypeField::FetchFields();
		}
	}
Ejemplo n.º 19
0
function camp_set_author(ArticleTypeField $p_sourceField, &$p_errors)
{
    $p_errors = array();
    $articles = Article::GetArticlesOfType($p_sourceField->getArticleType());
    foreach ($articles as $article) {
        $articleData = $article->getArticleData();
        $authorName = trim($articleData->getFieldValue($p_sourceField->getPrintName()));
        if (empty($authorName)) {
            continue;
        }
        $author = new Author($authorName);
        if (!$author->exists()) {
            if (!$author->create()) {
                $p_errors[] = getGS('Unable to create author "$1" for article no. $2 ("$3") of type $4.', $author->getName(), $article->getArticleNumber(), $article->getName(), $article->getType());
                continue;
            }
        }
        if (!$article->setAuthorId($author->getId())) {
            $p_errors[] = getGS('Error setting the author "$1" for article no. $2 ("$3") of type $4.', $author->getName(), $article->getArticleNumber(), $article->getName(), $article->getType());
            continue;
        }
    }
    return count($p_errors);
}
Ejemplo n.º 20
0
            print $text;
            ?>
</textarea>
            <?php 
        } else {
            ?>
              <?php 
            p($text);
            ?>
            <?php 
        }
        ?>
          </li>
        <?php 
    } elseif ($dbColumn->getType() == ArticleTypeField::TYPE_TOPIC) {
        $articleTypeField = new ArticleTypeField($articleObj->getType(), substr($dbColumn->getName(), 1));
        $rootTopicId = $articleTypeField->getTopicTypeRootElement();
        $rootTopic = new Topic($rootTopicId);
        $subtopics = Topic::GetTree($rootTopicId);
        $articleTopicId = $articleData->getProperty($dbColumn->getName());
        ?>
          <li>
            <label><?php 
        echo htmlspecialchars($dbColumn->getDisplayName($articleObj->getLanguageId()));
        ?>
</label>
                <?php 
        if (count($subtopics) == 0) {
            ?>
                <?php 
            putGS('No subtopics available');
Ejemplo n.º 21
0
<?php

require_once $GLOBALS['g_campsiteDir'] . '/classes/Log.php';
require_once $GLOBALS['g_campsiteDir'] . '/classes/Input.php';
require_once $GLOBALS['g_campsiteDir'] . '/classes/Article.php';
require_once $GLOBALS['g_campsiteDir'] . '/classes/ArticleType.php';
$translator = \Zend_Registry::get('container')->getService('translator');
// TODO: 4.5 replace this with acl check
if (false) {
    camp_html_display_error($translator->trans("You do not have the right to hide article types.", array(), 'article_type_fields'));
    exit;
}
if (!SecurityToken::isValid()) {
    camp_html_display_error($translator->trans('Invalid security token!'));
    exit;
}
$articleTypeName = Input::Get('f_article_type');
$articleTypeFieldName = Input::Get('f_field_name');
$status = Input::Get('f_status');
$errorMsgs = array();
$articleTypeField = new ArticleTypeField($articleTypeName, $articleTypeFieldName);
$articleTypeField->setStatus($status);
$cacheService = \Zend_Registry::get('container')->getService('newscoop.cache');
$cacheService->clearNamespace('article_type');
camp_html_goto_page("/{$ADMIN}/article_types/fields/?f_article_type=" . urlencode($articleTypeName));
Ejemplo n.º 22
0
<?php

require_once $GLOBALS['g_campsiteDir'] . '/classes/Log.php';
require_once $GLOBALS['g_campsiteDir'] . '/classes/Input.php';
require_once $GLOBALS['g_campsiteDir'] . '/classes/Article.php';
require_once $GLOBALS['g_campsiteDir'] . '/classes/ArticleType.php';
$translator = \Zend_Registry::get('container')->getService('translator');
if (!Saas::singleton()->hasPermission('ManageArticleTypes')) {
    camp_html_display_error($translator->trans("You do not have the right to delete article types.", array(), 'article_types'));
    exit;
}
if (!SecurityToken::isValid()) {
    camp_html_display_error($translator->trans('Invalid security token!'));
    exit;
}
$articleTypeName = Input::Get('f_article_type');
$articleTypeFieldName = Input::Get('f_field_name');
$showInEditor = Input::Get('f_show_in_editor');
$errorMsgs = array();
$articleTypeField = new ArticleTypeField($articleTypeName, $articleTypeFieldName);
$articleTypeField->setShowInEditor($showInEditor == 'true');
$cacheService = \Zend_Registry::get('container')->getService('newscoop.cache');
$cacheService->clearNamespace('article_type');
camp_html_goto_page("/{$ADMIN}/article_types/fields/?f_article_type=" . urlencode($articleTypeName));
Ejemplo n.º 23
0
require_once $GLOBALS['g_campsiteDir'] . '/classes/Input.php';
require_once $GLOBALS['g_campsiteDir'] . '/classes/Log.php';
require_once $GLOBALS['g_campsiteDir'] . '/classes/ArticleType.php';
if (!SecurityToken::isValid()) {
    camp_html_display_error(getGS('Invalid security token!'));
    exit;
}
// Check permissions
if (!$g_user->hasPermission('ManageArticleTypes')) {
    camp_html_display_error(getGS("You do not have the right to reassign article type fields."));
    exit;
}
$articleTypeName = Input::Get('f_article_type');
$fieldName = trim(Input::Get('f_field_name'));
$fieldType = trim(Input::Get('f_article_field_type'));
$field = new ArticleTypeField($articleTypeName, $fieldName);
$correct = true;
$errorMsgs = array();
if (!$field->exists()) {
    $errorMsgs[] = getGS('The field $1 does not exist.', '<B>' . urlencode($fieldName) . '</B>');
    $correct = false;
}
if (array_search($fieldType, $field->getConvertibleToTypes()) === false) {
    $errorMsgs[] = getGS('Can not convert the field $1 from $2 to type $3.', $fieldName, $field->getType(), $fieldType);
    $correct = false;
}
if ($correct) {
    $field->setType($fieldType);
    camp_html_goto_page("/{$ADMIN}/article_types/fields/?f_article_type=" . urlencode($articleTypeName));
}
$crumbs = array();
Ejemplo n.º 24
0
<?php

require_once $GLOBALS['g_campsiteDir'] . '/classes/Log.php';
require_once $GLOBALS['g_campsiteDir'] . '/classes/Input.php';
require_once $GLOBALS['g_campsiteDir'] . '/classes/Article.php';
require_once $GLOBALS['g_campsiteDir'] . '/classes/ArticleType.php';
$translator = \Zend_Registry::get('container')->getService('translator');
if (!Saas::singleton()->hasPermission('ManageArticleTypes')) {
    camp_html_display_error($translator->trans("You do not have the right to reorder article types.", array(), 'article_types'));
    exit;
}
if (!SecurityToken::isValid()) {
    camp_html_display_error($translator->trans('Invalid security token!'));
    exit;
}
$articleTypeName = Input::Get('f_article_type');
$articleTypeFieldName = Input::Get('f_field_name');
$move = Input::Get('f_move');
$errorMsgs = array();
$articleTypeField = new ArticleTypeField($articleTypeName, $articleTypeFieldName);
$articleTypeField->reorder($move);
$cacheService = \Zend_Registry::get('container')->getService('newscoop.cache');
$cacheService->clearNamespace('article_type');
camp_html_goto_page("/{$ADMIN}/article_types/fields/?f_article_type=" . urlencode($articleTypeName));
Ejemplo n.º 25
0
    if (empty($tmp)) {
    	$tmp = 'NULL';
    }
	$f_src_c[$destColumn->getPrintName()] = $tmp;
}


// Verify the merge rules
$ok = true;
$errMsgs = array();

foreach ($f_src_c as $destColumn => $srcColumn) {
	if ($srcColumn == 'NULL') {
		continue;
	}
	$destATF = new ArticleTypeField($f_dest, $destColumn);
	$srcATF = new ArticleTypeField($f_src, $srcColumn);

	if (!$destATF->isConvertibleFrom($srcATF)) {
        $errMsgs[] = getGS('Cannot merge a $1 field ($2) into a $3 field ($4).',
                            getGS($srcATF->getType()), $srcATF->getDisplayName(),
                            getGS($destATF->getType()), $destATF->getDisplayName());
        $ok = false;
	}
}

//
// if f_action is Merge, do the merge and return them to article_types/ screen (or an error)
//
if ($ok && $f_action == 'Merge') {
	if (!SecurityToken::isValid()) {
Ejemplo n.º 26
0
 /**
  * Processes an order directive on custom data fields.
  *
  * @param string $p_fieldName
  * @param string $p_defaultValue
  *
  * @return string
  *                The string containing processed values of the condition
  */
 private static function GetCustomOrder($p_fieldType, $p_articleType, $p_fieldName, $p_defaultValue)
 {
     $p_fieldType = strtolower($p_fieldType);
     if (!in_array($p_fieldType, array('ci', 'cs', 'num'))) {
         $p_fieldType = 'ci';
     }
     $queries = array();
     // all possible custom fields are taken alike for constraints
     $fields = ArticleTypeField::FetchFields($p_fieldName, $p_articleType, null, false, false, false, true, true);
     if (!empty($fields)) {
         foreach ($fields as $fieldObj) {
             $art_type = 'X' . $fieldObj->getArticleType();
             $query = '        SELECT ' . $art_type . '.' . $fieldObj->getName() . ' FROM ' . $art_type . ' ' . 'WHERE ' . $art_type . '.NrArticle = Articles.Number ' . 'AND ' . $art_type . '.IdLanguage = Articles.IdLanguage';
             $queries[] = $query;
         }
     }
     if (empty($queries)) {
         $queries[] = 'SELECT 1';
     }
     $queries_str = implode("       union\n", $queries);
     $res_query = '';
     if ('num' == $p_fieldType) {
         $p_defaultValue = 0 + $p_defaultValue;
         // if no table/row is find, the default value is used, this is done numerically
         $res_query = '(SELECT 0 + COALESCE((' . $queries_str . '), ' . $p_defaultValue . '))';
     } elseif ('cs' == $p_fieldType) {
         // <p> tag is removed, since it can be the initial tag at text area fields
         $p_defaultValue = str_replace('\'', '\'\'', $p_defaultValue);
         // if no table/row is find, the default value is used, this is done case sensitive
         $res_query = '(SELECT REPLACE(COALESCE((' . $queries_str . '), \'' . $p_defaultValue . '\'), "<p>", ""))';
     } else {
         // 'ci'
         // <p> tag is removed, since it can be the initial tag at text area fields
         $p_defaultValue = strtolower(str_replace('\'', '\'\'', $p_defaultValue));
         // if no table/row is find, the default value is used, this is done case insensitive
         $res_query = '(SELECT REPLACE(LOWER(CONVERT(COALESCE((' . $queries_str . '), \'' . $p_defaultValue . '\') USING utf8)), "<p>", ""))';
     }
     return $res_query;
 }
Ejemplo n.º 27
0
require_once $GLOBALS['g_campsiteDir'] . '/classes/Log.php';
require_once $GLOBALS['g_campsiteDir'] . '/classes/ArticleType.php';
$translator = \Zend_Registry::get('container')->getService('translator');
if (!SecurityToken::isValid()) {
    camp_html_display_error($translator->trans('Invalid security token!'));
    exit;
}
// Check permissions
if (!$g_user->hasPermission('ManageArticleTypes')) {
    camp_html_display_error($translator->trans("You do not have the right to reassign article type fields.", array(), 'article_type_fields'));
    exit;
}
$articleTypeName = Input::Get('f_article_type');
$fieldName = trim(Input::Get('f_field_name'));
$fieldType = trim(Input::Get('f_article_field_type'));
$field = new ArticleTypeField($articleTypeName, $fieldName);
$correct = true;
$errorMsgs = array();
if (!$field->exists()) {
    $errorMsgs[] = $translator->trans('The field $1 does not exist.', array('$1' => '<B>' . urlencode($fieldName) . '</B>'), 'article_type_fields');
    $correct = false;
}
if (array_search($fieldType, $field->getConvertibleToTypes()) === false) {
    $errorMsgs[] = $translator->trans('Can not convert the field $1 from $2 to type $3.', array('$1' => $fieldName, '$2' => $field->getType(), '$3' => $fieldType), 'article_type_fields');
    $correct = false;
}
if ($correct) {
    $field->setType($fieldType);
    $cacheService = \Zend_Registry::get('container')->getService('newscoop.cache');
    $cacheService->clearNamespace('article_type');
    camp_html_goto_page("/{$ADMIN}/article_types/fields/?f_article_type=" . urlencode($articleTypeName));
Ejemplo n.º 28
0
}
foreach ($dest->getUserDefinedColumns(null, true, true) as $destColumn) {
    $tmp = trim(Input::get('f_src_' . $destColumn->getPrintName()));
    if (empty($tmp)) {
        $tmp = 'NULL';
    }
    $f_src_c[$destColumn->getPrintName()] = $tmp;
}
// Verify the merge rules
$ok = true;
$errMsgs = array();
foreach ($f_src_c as $destColumn => $srcColumn) {
    if ($srcColumn == 'NULL') {
        continue;
    }
    $destATF = new ArticleTypeField($f_dest, $destColumn);
    $srcATF = new ArticleTypeField($f_src, $srcColumn);
    if (!$destATF->isConvertibleFrom($srcATF)) {
        $errMsgs[] = getGS('Cannot merge a $1 field ($2) into a $3 field ($4).', getGS($srcATF->getType()), $srcATF->getDisplayName(), getGS($destATF->getType()), $destATF->getDisplayName());
        $ok = false;
    }
}
//
// if f_action is Merge, do the merge and return them to article_types/ screen (or an error)
//
if ($ok && $f_action == 'Merge') {
    if (!SecurityToken::isValid()) {
        camp_html_display_error(getGS('Invalid security token!'));
        exit;
    }
    $res = ArticleType::merge($f_src, $f_dest, $f_src_c);
Ejemplo n.º 29
0
<?php

camp_load_translation_strings("article_type_fields");
camp_load_translation_strings("api");
require_once $GLOBALS['g_campsiteDir'] . '/classes/Input.php';
require_once $GLOBALS['g_campsiteDir'] . '/classes/ArticleType.php';
require_once $GLOBALS['g_campsiteDir'] . "/classes/Topic.php";
// Check permissions
if (!$g_user->hasPermission('ManageArticleTypes')) {
    camp_html_display_error(getGS("You do not have the right to reassign a field type."));
    exit;
}
$articleTypeName = Input::Get('f_article_type');
$articleTypeFieldName = Input::Get('f_field_name');
$articleField = new ArticleTypeField($articleTypeName, $articleTypeFieldName);
$crumbs = array();
$crumbs[] = array(getGS("Configure"), "");
$crumbs[] = array(getGS("Article Types"), "/{$ADMIN}/article_types/");
$crumbs[] = array($articleTypeName, '');
$crumbs[] = array(getGS("Article type fields"), "/{$ADMIN}/article_types/fields/?f_article_type=" . urlencode($articleTypeName));
$crumbs[] = array(getGS("Reassign a field type"), "");
echo camp_html_breadcrumbs($crumbs);
include_once $GLOBALS['g_campsiteDir'] . "/{$ADMIN_DIR}/javascript_common.php";
$lang = camp_session_get('LoginLanguageId', 1);
$languageObj = new Language($lang);
// Verify the merge rules
$options = array();
$convertibleFromTypes = $articleField->getConvertibleToTypes();
foreach ($convertibleFromTypes as $type) {
    $options[$type] = ArticleTypeField::VerboseTypeName($type, $languageObj->getLanguageId());
}
Ejemplo n.º 30
0
<?php

require_once $GLOBALS['g_campsiteDir'] . '/classes/Input.php';
require_once $GLOBALS['g_campsiteDir'] . '/classes/Log.php';
require_once $GLOBALS['g_campsiteDir'] . '/classes/ArticleType.php';
$translator = \Zend_Registry::get('container')->getService('translator');
if (!SecurityToken::isValid()) {
    camp_html_display_error($translator->trans('Invalid security token!'));
    exit;
}
// Check permissions
if (!$g_user->hasPermission('DeleteArticleTypes')) {
    camp_html_display_error($translator->trans("You do not have the right to delete article type fields.", array(), 'article_type_fields'));
    exit;
}
$articleTypeName = Input::Get('f_article_type');
$fieldName = Input::Get('f_field_name');
$field = new ArticleTypeField($articleTypeName, $fieldName);
if ($field->exists()) {
    $field->delete();
    $cacheService = \Zend_Registry::get('container')->getService('newscoop.cache');
    $cacheService->clearNamespace('article_type');
}
camp_html_goto_page("/{$ADMIN}/article_types/fields/?f_article_type=" . urlencode($articleTypeName));