Inheritance: extends DbRecord
Ejemplo n.º 1
0
    public function delete()
    {
        if (!$this->exists()) {
            return false;
        }
        // Deleting the from from disk path is the most common place for
        // something to go wrong, so we do that first.
        $file = $this->getStorageLocation();
        if (file_exists($file) && is_file($file)) {
            unlink($file);
        }

        // Delete all the references to this image.
        ArticleAttachment::OnAttachmentDelete($this->m_data['id']);

        // Delete the description
        Translation::deletePhrase($this->m_data['fk_description_id']);

        $tmpData = $this->m_data;

        // Delete the record in the database
        $success = parent::delete();

        $logtext = getGS('File #$1 "$2" deleted.', $tmpData['id'], $tmpData['file_name']);
        Log::Message($logtext, null, 39);
        return $success;
    } // fn delete
	/**
	 * Creates the list of objects. Sets the parameter $p_hasNextElements to
	 * true if this list is limited and elements still exist in the original
	 * list (from which this was truncated) after the last element of this
	 * list.
	 *
	 * @param int $p_start
	 * @param int $p_limit
	 * @param array $p_parameters
	 * @param int &$p_count
	 * @return array
	 */
	protected function CreateList($p_start = 0, $p_limit = 0, array $p_parameters, &$p_count)
	{
	    $articleAttachmentsList = ArticleAttachment::GetList($this->m_constraints, $this->m_order, $p_start, $p_limit, $p_count);
	    $metaAttachmentsList = array();
	    foreach ($articleAttachmentsList as $attachment) {
	        $metaAttachmentsList[] = new MetaAttachment($attachment->getAttachmentId());
	    }
	    return $metaAttachmentsList;
	}
 /**
  * Creates the list of objects. Sets the parameter $p_hasNextElements to
  * true if this list is limited and elements still exist in the original
  * list (from which this was truncated) after the last element of this
  * list.
  *
  * @param int $p_start
  * @param int $p_limit
  * @param array $p_parameters
  * @param int &$p_count
  * @return array
  */
 protected function CreateList($p_start = 0, $p_limit = 0, array $p_parameters, &$p_count)
 {
     $cacheService = \Zend_Registry::get('container')->getService('newscoop.cache');
     $cacheKey = $cacheService->getCacheKey(array('metaAttachmentsList', implode('-', $this->m_constraints), implode('-', $this->m_order), $p_start, $p_limit, $p_count), 'attachments');
     if ($cacheService->contains($cacheKey)) {
         $metaAttachmentsList = $cacheService->fetch($cacheKey);
     } else {
         $articleAttachmentsList = ArticleAttachment::GetList($this->m_constraints, $this->m_order, $p_start, $p_limit, $p_count);
         $metaAttachmentsList = array();
         foreach ($articleAttachmentsList as $attachment) {
             $metaAttachmentsList[] = new MetaAttachment($attachment->getAttachmentId());
         }
         $cacheService->save($cacheKey, $metaAttachmentsList);
     }
     return $metaAttachmentsList;
 }
Ejemplo n.º 4
0
 /**
  * Get all the files and directories of a relative path.
  *
  * @param string $p_articleId
  *
  * @return array of file and path information.
  * <code>
  *   array('url'=>'full url',
  *         'storage'=>'full file path')
  * </code>
  */
 function getFiles($p_articleId, $p_languageId = null)
 {
     $files = array();
     if ($this->isValidBase() == false) {
         return $files;
     }
     $articleAttachments = ArticleAttachment::GetAttachmentsByArticleNumber($p_articleId, $p_languageId);
     foreach ($articleAttachments as $articleAttachment) {
         if (!$this->m_config['validate_files']) {
             $file['attachment'] = $articleAttachment;
             $file['url'] = $articleAttachment->getAttachmentUrl();
             $file['storage'] = $articleAttachment->getStorageLocation();
             $files[$articleAttachment->getAttachmentId()] = $file;
         }
     }
     ksort($files);
     return $files;
 }
Ejemplo n.º 5
0
 /**
  * Get all the files and directories of a relative path.
  *
  * @param string $p_articleId
  *
  * @return array of file and path information.
  * <code>
  *   array('url'=>'full url',
  *         'storage'=>'full file path')
  * </code>
  */
 function getFiles($p_articleId, $p_languageId = null, $p_filter = true)
 {
     $files = array();
     if ($this->isValidBase() == false) {
         return $files;
     }
     $mediaFormats = array();
     if ($p_filter == true) {
         $mediaFormats = explode(',', $this->m_config['media_formats']);
     }
     $articleAttachments = ArticleAttachment::GetAttachmentsByArticleNumber($p_articleId, $p_languageId);
     foreach ($articleAttachments as $articleAttachment) {
         if (!$this->m_config['validate_files']) {
             if (in_array($articleAttachment->getExtension(), $mediaFormats)) {
                 $file['attachment'] = $articleAttachment;
                 $file['url'] = $articleAttachment->getAttachmentUrl();
                 $file['storage'] = $articleAttachment->getStorageLocation();
                 $files[$articleAttachment->getAttachmentId()] = $file;
             }
         }
     }
     ksort($files);
     return $files;
 }
Ejemplo n.º 6
0
 protected function hasAttachments()
 {
     $attachments = ArticleAttachment::GetAttachmentsByArticleNumber($this->m_dbObject->getProperty('Number'));
     return (int)(sizeof($attachments) > 0);
 }
Ejemplo n.º 7
0
    /**
     * Delete article from database.  This will
     * only delete one specific translation of the article.
     *
     * @return boolean
     */
    public function delete()
    {
        // It is an optimization to put these here because in most cases
        // you dont need these files.
        require_once($GLOBALS['g_campsiteDir'].'/classes/ArticleImage.php');
        require_once($GLOBALS['g_campsiteDir'].'/classes/ArticleTopic.php');
        require_once($GLOBALS['g_campsiteDir'].'/classes/ArticleIndex.php');
        require_once($GLOBALS['g_campsiteDir'].'/classes/ArticleAttachment.php');
        require_once($GLOBALS['g_campsiteDir'].'/classes/ArticleComment.php');
        require_once($GLOBALS['g_campsiteDir'].'/classes/ArticlePublish.php');

        // Delete scheduled publishing
        ArticlePublish::OnArticleDelete($this->m_data['Number'], $this->m_data['IdLanguage']);

        // Delete Article Comments
        ArticleComment::OnArticleDelete($this->m_data['Number'], $this->m_data['IdLanguage']);

        // is this the last translation?
        if (count($this->getLanguages()) <= 1) {
            // Delete image pointers
            ArticleImage::OnArticleDelete($this->m_data['Number']);

            // Delete topics pointers
            ArticleTopic::OnArticleDelete($this->m_data['Number']);

            // Delete file pointers
            ArticleAttachment::OnArticleDelete($this->m_data['Number']);

            // Delete indexes
            ArticleIndex::OnArticleDelete($this->getPublicationId(), $this->getIssueNumber(),
                $this->getSectionNumber(), $this->getLanguageId(), $this->getArticleNumber());
        }

        // geo-map processing
        // is this the last translation?
        if (count($this->getLanguages()) <= 1) {
            // unlink the article-map pointers
            Geo_Map::OnArticleDelete($this->m_data['Number']);
        }
        else {
            // removing non-last translation of the map poi contents
            Geo_Map::OnLanguageDelete($this->m_data['Number'], $this->m_data['IdLanguage']);
        }

        // Delete row from article type table.
        $articleData = new ArticleData($this->m_data['Type'],
            $this->m_data['Number'],
            $this->m_data['IdLanguage']);
        $articleData->delete();

        $tmpObj = clone $this; // for log
        $tmpData = $this->m_data;
        $tmpData['languageName'] = $this->getLanguageName();
        // Delete row from Articles table.
        $deleted = parent::delete();

        if ($deleted) {
            if (function_exists("camp_load_translation_strings")) {
                camp_load_translation_strings("api");
            }
            Log::ArticleMessage($tmpObj, getGS('Article deleted.'), null, 32);
        }
        $this->m_cacheUpdate = true;
        return $deleted;
    } // fn delete
Ejemplo n.º 8
0
 /**
  * Delete article from database.  This will
  * only delete one specific translation of the article.
  *
  * @return boolean
  */
 public function delete()
 {
     // It is an optimization to put these here because in most cases
     // you dont need these files.
     require_once $GLOBALS['g_campsiteDir'] . '/classes/ArticleImage.php';
     require_once $GLOBALS['g_campsiteDir'] . '/classes/ArticleTopic.php';
     require_once $GLOBALS['g_campsiteDir'] . '/classes/ArticleIndex.php';
     require_once $GLOBALS['g_campsiteDir'] . '/classes/ArticleAttachment.php';
     require_once $GLOBALS['g_campsiteDir'] . '/classes/ArticlePublish.php';
     // Delete scheduled publishing
     ArticlePublish::OnArticleDelete($this->m_data['Number'], $this->m_data['IdLanguage']);
     $translator = \Zend_Registry::get('container')->getService('translator');
     // Delete Article Comments
     // @todo change this with DOCTRINE2 CASCADE DELETE
     $em = Zend_Registry::get('container')->getService('em');
     $repository = $em->getRepository('Newscoop\\Entity\\Comment');
     $repository->deleteArticle($this->m_data['Number'], $this->m_data['IdLanguage']);
     $repository = $em->getRepository('Newscoop\\Entity\\ArticleDatetime');
     $repository->deleteByArticle($this->m_data['Number']);
     $em->flush();
     // is this the last translation?
     if (count($this->getLanguages()) <= 1) {
         // Delete image pointers
         ArticleImage::OnArticleDelete($this->m_data['Number']);
         // Delete topics pointers
         ArticleTopic::OnArticleDelete($this->m_data['Number']);
         // Delete file pointers
         ArticleAttachment::OnArticleDelete($this->m_data['Number']);
         // Delete related articles
         ContextBox::OnArticleDelete($this->m_data['Number']);
         ContextBoxArticle::OnArticleDelete($this->m_data['Number']);
         // Delete the article from playlists
         $em = Zend_Registry::get('container')->getService('em');
         $repository = $em->getRepository('Newscoop\\Entity\\PlaylistArticle');
         $repository->deleteArticle($this->m_data['Number']);
         $em->flush();
         // Delete indexes
         ArticleIndex::OnArticleDelete($this->getPublicationId(), $this->getIssueNumber(), $this->getSectionNumber(), $this->getLanguageId(), $this->getArticleNumber());
     }
     // geo-map processing
     // is this the last translation?
     if (count($this->getLanguages()) <= 1) {
         // unlink the article-map pointers
         Geo_Map::OnArticleDelete($this->m_data['Number']);
     } else {
         // removing non-last translation of the map poi contents
         Geo_Map::OnLanguageDelete($this->m_data['Number'], $this->m_data['IdLanguage']);
     }
     // Delete row from article type table.
     $articleData = new ArticleData($this->m_data['Type'], $this->m_data['Number'], $this->m_data['IdLanguage']);
     $articleData->delete();
     $tmpObj = clone $this;
     // for log
     $tmpData = $this->m_data;
     $tmpData['languageName'] = $this->getLanguageName();
     // Delete row from Articles table.
     $deleted = parent::delete();
     if ($deleted) {
         $cacheService = \Zend_Registry::get('container')->getService('newscoop.cache');
         $cacheService->clearNamespace('article');
         Log::ArticleMessage($tmpObj, $translator->trans('Article deleted.', array(), 'api'), null, 32);
     }
     $this->m_cacheUpdate = true;
     return $deleted;
 }
Ejemplo n.º 9
0
        }
    }
}
// save file attachment if any
if ($_FILES["attachment"]["error"] != UPLOAD_ERR_NO_FILE) {
    $uploadedFile = UploadHandler::handleUpload("attachment");
    $split = explode(".", $uploadedFile);
    $extension = strtolower(array_pop($split));
    $type = ArticleAttachment::TYPE_OTHER;
    switch ($extension) {
        case "jpg":
        case "png":
        case "gif":
        case "jpeg":
            $type = ArticleAttachment::TYPE_IMAGE;
            break;
        case "doc":
        case "docx":
        case "ppt":
        case "pptx":
        case "pdf":
            $type = ArticleAttachment::TYPE_DOCUMENT;
            break;
    }
    $attachment = new ArticleAttachment();
    $attachment->data = $uploadedFile;
    $attachment->article = $article->id;
    $attachment->type = $type;
    $attachment->save();
}
CommonUtil::redirect("admin/edit/" . $article->id . "/");
Ejemplo n.º 10
0
$f_article_number = Input::Get('f_article_number', 'int', 0);
$f_attachment_id = Input::Get('f_attachment_id', 'int', 0);
// Check input
if (!Input::IsValid()) {
    camp_html_display_error($translator->trans('Invalid input: $1', array('$1' => Input::GetErrorString())), null, true);
    exit;
}
if (!$g_user->hasPermission("DeleteFile")) {
    camp_html_display_error($translator->trans("You do not have the right to delete file attachments.", array(), 'article_files'), null, true);
    exit;
}
$articleObj = new Article($f_language_selected, $f_article_number);
if (!$articleObj->exists()) {
    camp_html_display_error($translator->trans("Article does not exist."), null, true);
    exit;
}
$attachmentObj = new Attachment($f_attachment_id);
if (!$attachmentObj->exists()) {
    camp_html_display_error($translator->trans('Attachment does not exist.', array(), 'article_files'), null, true);
    exit;
}
$filePath = dirname($attachmentObj->getStorageLocation()) . '/' . $attachmentObj->getFileName();
ArticleAttachment::RemoveAttachmentFromArticle($f_attachment_id, $f_article_number);
$logtext = $translator->trans('File #$1 "$2" unattached', array('$1' => $attachmentObj->getAttachmentId(), '$2' => $attachmentObj->getFileName()), 'article_files');
Log::ArticleMessage($articleObj, $logtext, null, 39);
$attachmentFileName = $attachmentObj->getFileName();
$cacheService = \Zend_Registry::get('container')->getService('newscoop.cache');
$cacheService->clearNamespace('attachments');
// Go back to article.
camp_html_add_msg($translator->trans("File \$1 unattached.", array('$1' => $attachmentFileName), 'article_files'), "ok");
camp_html_goto_page(camp_html_article_url($articleObj, $f_language_id, 'edit.php'));
Ejemplo n.º 11
0
window.opener.location.reload();
</script>
<?php
	exit;
}

$f_language_selected = Input::Get('f_language_selected', 'int', 0);
$f_article_number = Input::Get('f_article_number', 'int', 0);
$articleObj = new Article($f_language_selected, $f_article_number);
if (!$articleObj->exists()) {
	camp_html_display_error(getGS("Article does not exist."), null, true);
	exit;
}

foreach ((array) $_POST['item'] as $attachmentId) {
    ArticleAttachment::AddFileToArticle((int) $attachmentId, $articleObj->getArticleNumber());
}
$logtext = getGS('$1 file/s attached to article', sizeof($_POST['item']));
Log::ArticleMessage($articleObj, $logtext, null, 38, TRUE);

?>
<script type="text/javascript">
try {
    parent.$.fancybox.reload = true;
    parent.$.fancybox.message = '<?php putGS('Files attached.'); ?>';
    parent.$.fancybox.close();
} catch (e) {}
</script>

<?php exit; ?>
Ejemplo n.º 12
0
    $userSection = $blogService->getSection($g_user);
    if (empty($userSection) || $userSection->getSectionId() != $articleObj->getSection()->getSectionId()) {
        camp_html_display_error(getGS("You're not allowed to edit article."));
        exit;
    }
}
$articleData = $articleObj->getArticleData();
// Get article type fields.
$dbColumns = $articleData->getUserDefinedColumns(FALSE, TRUE);
$articleType = new ArticleType($articleObj->getType());
$articleImages = ArticleImage::GetImagesByArticleNumber($f_article_number);
$lockUserObj = new User($articleObj->getLockedByUser());
$articleCreator = new User($articleObj->getCreatorId());
$articleEvents = ArticlePublish::GetArticleEvents($f_article_number, $f_language_selected, TRUE);
$articleTopics = ArticleTopic::GetArticleTopics($f_article_number);
$articleFiles = ArticleAttachment::GetAttachmentsByArticleNumber($f_article_number, $f_language_selected);
$articleLanguages = $articleObj->getLanguages();
// Create displayable "last modified" time.
$lastModified = strtotime($articleObj->getLastModified());
$today = getdate();
$savedOn = getdate($lastModified);
$savedToday = true;
if ($today['year'] != $savedOn['year'] || $today['mon'] != $savedOn['mon'] || $today['mday'] != $savedOn['mday']) {
    $savedToday = FALSE;
}
$sectionObj = null;
$showComments = FALSE;
$showCommentControls = FALSE;
if ($f_publication_id > 0) {
    $publicationObj = new Publication($f_publication_id);
    if ($publicationObj->exists()) {
Ejemplo n.º 13
0
<?php

require_once "../inc/init.php";
if (!Session::canAccess(AccessLevels::CONTENT_PROVIDER)) {
    CommonUtil::redirect("index");
    exit(0);
}
if (!isset($_GET["id"])) {
    CommonUtil::redirect("admin/contentmanager");
    exit(0);
}
$a = ArticleAttachment::model()->findByPk($_GET["id"]);
if (!$a) {
    CommonUtil::redirect("admin/contentmanager");
    exit(0);
}
$article = $a->article;
$a->delete();
CommonUtil::redirect("admin/edit/" . $article . "/");
Ejemplo n.º 14
0
 protected function hasAttachments()
 {
     $cacheService = \Zend_Registry::get('container')->getService('newscoop.cache');
     $cacheKey = $cacheService->getCacheKey(array('hasAttachments', $this->m_dbObject->getProperty('Number')), 'attachments');
     if ($cacheService->contains($cacheKey)) {
         $attachments = $cacheService->fetch($cacheKey);
     } else {
         $attachments = ArticleAttachment::GetAttachmentsByArticleNumber($this->m_dbObject->getProperty('Number'));
         $cacheService->save($cacheKey, $attachments);
     }
     return (int) (sizeof($attachments) > 0);
 }
Ejemplo n.º 15
0
    public function testGetListBadParameter()
    {
        global $g_ado_db;

        // builds the constraint
        $leftOperand = 'Attachment.file_name';
        $rightOperand = 'Robotic submarine reaches new depths';
        $operator = new Operator('not', 'sql');
        $comparisonOperationObj = new ComparisonOperation($leftOperand,
                                                          $operator,
                                                          $rightOperand);

        // sets the params for ArticleAttachment::GetList()
        $params = array($comparisonOperationObj);
        $order = array();
        $limitStart = 0;
        $limitOffset = 0;

        $this->assertEquals(null, ArticleAttachment::GetList($params, $order, $limitStart, $limitOffset));
    } // fn testGetListBadParameter
Ejemplo n.º 16
0
 public function getAttachments()
 {
     return ArticleAttachment::model()->findAll("article = ?", $this->id);
 }
Ejemplo n.º 17
0
}

if (!empty($_FILES['f_file'])) {
	$file = Attachment::OnFileUpload($_FILES['f_file'], $attributes);
} else {
	camp_html_goto_page(camp_html_article_url($articleObj, $f_language_id, 'files/popup.php'));
}

// Check if image was added successfully
if (PEAR::isError($file)) {
    setMessage($file->getMessage());
	camp_html_goto_page($BackLink);
}

if (!$inArchive) {
    ArticleAttachment::AddFileToArticle($file->getAttachmentId(), $articleObj->getArticleNumber());

    $logtext = getGS('File #$1 "$2" attached to article',
        $file->getAttachmentId(), $file->getFileName());
    Log::ArticleMessage($articleObj, $logtext, null, 38, TRUE);

    setMessage(getGS('File attached.'));
} else { ?>
<script type="text/javascript"><!--
    if (opener && !opener.closed && opener.onUpload) {
        opener.onUpload();
        opener.focus();
        window.close();
    }
//--></script>
<?php } ?>
Ejemplo n.º 18
0
<tr>
                                <td><?php 
        echo $attachment->getTypeString();
        ?>
</td>
                                <td><?php 
        echo $attachment->data;
        ?>
</td>
                                <td>
                                    <select name="attachment[<?php 
        echo $attachment->id;
        ?>
]">
                                    <?php 
        foreach (ArticleAttachment::getSlotNames() as $slot => $name) {
            ?>
<option value="<?php 
            echo $slot;
            ?>
" <?php 
            echo $slot == $attachment->slot ? "selected" : "";
            ?>
><?php 
            echo $name;
            ?>
</option><?php 
        }
        ?>
                                    </select>
                                </td>