Example #1
0
 /**
  * Validate all URLS in any attachments
  * (See AttachmentsUpdate::reinstall_permissions() in update.php for details )
  */
 public function reinstall_permissions()
 {
     // Access check.
     if (!JFactory::getUser()->authorise('core.admin', 'com_attachments')) {
         return JError::raiseError(404, JText::_('JERROR_ALERTNOAUTHOR') . ' (ERR 159)');
     }
     require_once JPATH_ADMINISTRATOR . '/components/com_attachments/update.php';
     $msg = AttachmentsUpdate::installAttachmentsPermissions();
     if (JRequest::getBool('close')) {
         $this->enqueueSystemMessage($msg);
         // Close this window and refesh the parent window
         AttachmentsJavascript::closeModal();
     } else {
         $this->setRedirect('index.php?option=' . $this->option, $msg);
     }
 }
Example #2
0
 function update_attachments_table()
 {
     // NOTE: It should be harmless to run this function multiple times
     // Get the existing field names
     $db =& JFactory::getDBO();
     $query = "explain #__attachments";
     $db->setQuery($query);
     $rows = $db->loadObjectList();
     $fields = array();
     foreach ($rows as $row) {
         $fields[] = $row->Field;
     }
     // Define the columns/fields that may need to be added
     $new_fields = array();
     $new_fields['display_filename'] = "ALTER TABLE #__attachments ADD `display_filename` VARCHAR(80) NOT NULL DEFAULT ''";
     $new_fields['user_field_1'] = "ALTER TABLE #__attachments ADD `user_field_1` VARCHAR(100) NOT NULL DEFAULT ''";
     $new_fields['user_field_2'] = "ALTER TABLE #__attachments ADD `user_field_2` VARCHAR(100) NOT NULL DEFAULT ''";
     $new_fields['user_field_3'] = "ALTER TABLE #__attachments ADD `user_field_3` VARCHAR(100) NOT NULL DEFAULT ''";
     $new_fields['create_date'] = "ALTER TABLE #__attachments ADD `create_date` DATETIME DEFAULT NULL";
     $new_fields['modification_date'] = "ALTER TABLE #__attachments ADD `modification_date` DATETIME DEFAULT NULL";
     $new_fields['download_count'] = "ALTER TABLE #__attachments ADD `download_count` INT(11) UNSIGNED DEFAULT '0'";
     // See if we need to add specific fields
     $num_fields_added = 0;
     $dates_added = false;
     foreach ($new_fields as $field => $query) {
         if (!in_array($field, $fields)) {
             echo "&nbsp;&nbsp;&nbsp; Adding missing column '{$field}'<br>";
             $db->setQuery($query);
             if (!$db->query()) {
                 JError::raiseError(500, "Error installing field " . $field . ": " . $db->stderr());
                 return false;
             }
             if ($field == 'create_date') {
                 $dates_added = true;
             }
             $num_fields_added++;
         }
     }
     if ($num_fields_added != 0) {
         echo "";
     }
     if ($dates_added) {
         echo "&nbsp;&nbsp;&nbsp; Adding missing create/modification dates (using date each attachment file was created). <br>";
         require_once JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_attachments' . DS . 'update.php';
         $num = AttachmentsUpdate::update_null_dates();
         if ($num == 0) {
             echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; No attachments needed updating<br>";
         } elseif ($num == 1) {
             echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1 attachment updated<br>";
         } else {
             echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {$num} attachments updated<br>";
         }
     }
     // Get the existing indexed column names
     $query = "show index from #__attachments";
     $db->setQuery($query);
     $rows = $db->loadObjectList();
     $indexes = array();
     foreach ($rows as $row) {
         $indexes[] = $row->Key_name;
     }
     // Define the indexes that may need to get added
     $new_indexes = array();
     $new_indexes['attachment_article_id_index'] = "CREATE INDEX attachment_article_id_index ON `#__attachments` (`article_id`)";
     /* These indeces do not add any benefit
           See: http://dev.mysql.com/doc/refman/5.0/en/order-by-optimization.html
        $new_indexes['attachment_filename_index'] =
            "CREATE INDEX attachment_filename_index ON `#__attachments` (`filename`)";
        $new_indexes['attachment_file_size_index'] =
            "CREATE INDEX attachment_file_size_index ON `#__attachments` (`file_size`)";
        $new_indexes['attachment_create_date_index'] =
            "CREATE INDEX attachment_create_date_index ON `#__attachments` (`create_date`)";
        $new_indexes['attachment_modification_date_index'] =
            "CREATE INDEX attachment_modification_date_index ON `#__attachments` (`modification_date`)";
        */
     // Add any missing indexes
     echo "<br>";
     $num_indexes_added = 0;
     foreach ($new_indexes as $index => $query) {
         if (!in_array($index, $indexes)) {
             echo "&nbsp;&nbsp;&nbsp; Adding index '{$index}'<br>";
             $db->setQuery($query);
             if (!$db->query()) {
                 JError::raiseError(500, "Error installing index " . $index . ": " . $db->stderr());
                 return false;
             }
             $num_indexes_added++;
         }
     }
     echo "<h3>The attachments table is now up to date. <h3>\n";
     return true;
 }
/**
* Attachments component
* @package Attachments
* @Copyright (C) 2007, 2008 Jonathan M. Cameron, All Rights Reserved
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
* @link http://joomlacode.org/gf/project/attachments/frs/
* @author Jonathan M. Cameron
**/
function com_install()
{
    // First make sure that this version of Joomla is 1.5 or greater
    $version = new JVersion();
    if ((double) $version->RELEASE < 1.5) {
        echo "<h1 style=\"color: red;\">The 'Attachments' package will only work on Joomla version 1.5 or later!</h1>";
        return false;
    }
    echo "<h3>Updating Attachments Table...</h3>\n";
    require_once JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_attachments' . DS . 'update.php';
    AttachmentsUpdate::update_attachments_table();
    // Check to see if the plugin has been installed yet
    $plugin_installed = false;
    $plugin_published = false;
    $db =& JFactory::getDBO();
    $query = "SELECT published FROM #__plugins WHERE element='attachments' AND folder='content' LIMIT 1";
    $db->setQuery($query);
    $rows = $db->loadObjectList();
    if (count($rows) > 0) {
        $plugin_installed = true;
        $plugin_published = intval($rows[0]->published) == 1;
    }
    echo '<div class="header">Attachments for articles component succesfully installed! <br>';
    if ($plugin_installed) {
        if (!$plugin_published) {
            echo "<i>Don&rsquo;t forget to enable the plugins!</i>";
        }
    } else {
        echo "<i>Don&rsquo;t forget to install the plugins too!</i>";
    }
    ?>
    </div>
    <h2>NOTES:</h2>

    <p>
        Once the attachment plugins and component have been installed and the plugins are enabled,
        the attachments should work.  The default after installation is for the attachments to be
        visible to anyone that is logged in and for the link to add attachments to visible only
        to the author of the article.   Both of these options can be changed via the attachments
        parameters which can be changed in the component manager (go to the administrative back end,
        select "Article&nbsp;Attachments" under the "Components" menu, and click on the Parameters
        item on the toolbar).
    </p>

    <p>
        Once an attachment is uploaded, it is not visible until it is published.  To do this go to the
        administrative backend and select "Article&nbsp;Attachments" under the "Components" menu.  This will
        show a list of attachments and has controls to publish the attachments.  The option to make
        attachments automatically be published after they are uploaded can be changed via the Attachments
        component manager.
    </p>

    <p>
        This extension respects the options in the Media Manager regarding what types of files can 
        be uploaded.  If you can&rsquo;t attach certain file types (such as zip files), go to the
        "Global Configuration" item under the "Site" menu in the administrative backend.  Click
        on the "System" tab and look for the "Media Settings" section.  You can add appropriate
        file extensions or mime types there.
    </p>

    <p>
        Please see the help page for further details, including known limitations of this extension
        and suggestions on how to upgrade this extension.  To get to the help page, select
        "Article&nbsp;Attachments" under the "Components" menu in the adminstrative    backend.
        Click on the help icon on the toolbar to bring up the help page.  Or you may use this URL:
        <a href="<?php 
    echo JURI::base();
    ?>
components/com_attachments/help/en-GB/help.html"
           target="_blank">Help File (in English)</a>.
    </p>

    <p>
        Please report bugs and suggestions to <a href="mailto:jmcameron@jmcameron.net">jmcameron@jmcameron.net</a>.
    </p>
    <?php 
    return true;
}
Example #4
0
 function regenerate_system_filenames()
 {
     require_once JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_attachments' . DS . 'update.php';
     $close = JRequest::getVar('close', false);
     $msg = AttachmentsUpdate::regenerate_system_filenames();
     if ($close) {
         require_once JPATH_SITE . DS . 'components' . DS . 'com_attachments' . DS . 'helper.php';
         AttachmentsHelper::enqueueSystemMessage($msg);
         echo "<script>window.parent.document.getElementById('sbox-window').close();\n                  window.parent.location.reload();</script>";
     } else {
         global $option;
         $this->setRedirect('index.php?option=' . $option, $msg);
     }
 }
 /**
  * Install the default ACL/permissions rules for the new attachments privileges in the root rule
  */
 protected function installPermissions()
 {
     global $attachments_install_verbose;
     /** Load the Attachments defines */
     require_once JPATH_ADMINISTRATOR . '/components/com_attachments/update.php';
     AttachmentsUpdate::installAttachmentsPermissions($attachments_install_verbose);
 }
Example #6
0
 /**
  * Regenerate the system filenames for all attachments.
  *
  * This function may need to run if the admin has moved the attachments
  * from one computer to another and the actual file paths need to be
  * updated.
  */
 public static function regenerate_system_filenames()
 {
     require_once JPATH_SITE . '/components/com_attachments/helper.php';
     // Get the component parameters
     jimport('joomla.application.component.helper');
     $params = JComponentHelper::getParams('com_attachments');
     // Define where the attachments go
     $upload_url = AttachmentsDefines::$ATTACHMENTS_SUBDIR;
     $upload_dir = JPATH_SITE . '/' . $upload_url;
     // Get all the attachment IDs
     $db = JFactory::getDBO();
     $query = $db->getQuery(true);
     $query->select('id')->from('#__attachments')->where('uri_type=' . $db->quote('file'));
     $db->setQuery($query);
     $attachments = $db->loadObjectList();
     if ($db->getErrorNum()) {
         $errmsg = $db->stderr() . ' (ERR 72)';
         JError::raiseError(500, $errmsg);
     }
     if (count($attachments) == 0) {
         return JText::_('ATTACH_NO_ATTACHMENTS_WITH_FILES');
     }
     $IDs = array();
     foreach ($attachments as $attachment) {
         $IDs[] = $attachment->id;
     }
     // Get the parent plugin manager
     JPluginHelper::importPlugin('attachments');
     $apm = getAttachmentsPluginManager();
     // Update the system filenames for all the attachments
     jimport('joomla.filesystem.file');
     jimport('joomla.filesystem.folder');
     JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_attachments/tables');
     $attachment = JTable::getInstance('Attachment', 'AttachmentsTable');
     $msg = '';
     $numUpdated = 0;
     $numMissing = 0;
     foreach ($IDs as $id) {
         $attachment->load($id);
         // Get the actual parent id for this attachment
         // (Needed because orphaned parent_id is null, which the Table loads as 1)
         $query = $db->getQuery(true);
         $query->select('parent_id')->from('#__attachments')->where('id = ' . (int) $id);
         $db->setQuery($query, 0, 1);
         $parent_id = $db->loadResult();
         if ($db->getErrorNum()) {
             $errmsg = JText::sprintf('ATTACH_ERROR_INVALID_PARENT_S_ID_N', $attachment->parent_entity, $parent_id) . ' (ERR 73)';
             JError::raiseError(500, $errmsg);
         }
         // Construct the updated system filename
         $old_filename_sys = $attachment->filename_sys;
         // Get info about the system filename
         $finfo = AttachmentsUpdate::checkFilename($old_filename_sys);
         $basename = $finfo->basename;
         // Reconstruct the current system filename (in case of migrations)
         $current_filename_sys = JPATH_SITE . '/' . $finfo->relfile;
         // Get the parent object
         $parent = $apm->getAttachmentsPlugin($attachment->parent_type);
         if (!JFile::exists($current_filename_sys)) {
             $msg .= JText::sprintf('ATTACH_ERROR_MISSING_ATTACHMENT_FILE_S', $current_filename_sys) . "<br/>";
             $numMissing++;
         } elseif (!is_numeric($parent_id) || !$parent->parentExists($attachment->parent_id, $attachment->parent_entity)) {
             $msg .= JText::sprintf('ATTACH_ERROR_MISSING_PARENT_FOR_ATTACHMENT_S', $current_filename_sys) . "<br/>";
             $numMissing++;
         } else {
             // Construct the new system filename and url (based on entities, etc)
             $newdir = $parent->getAttachmentPath($attachment->parent_entity, $attachment->parent_id, null);
             $new_path = $upload_dir . '/' . $newdir;
             if ($finfo->oldstyle && $finfo->prefix) {
                 $new_filename_sys = $new_path . $finfo->basename_no_prefix;
                 $attachment->filename = $finfo->basename_no_prefix;
                 $new_url = str_replace(DIRECTORY_SEPARATOR, '/', $upload_url . '/' . $newdir . $finfo->basename_no_prefix);
             } else {
                 $new_filename_sys = $new_path . $basename;
                 $new_url = str_replace(DIRECTORY_SEPARATOR, '/', $upload_url . '/' . $newdir . $basename);
             }
             // If we are on windows, fix the filename and URL
             if (DIRECTORY_SEPARATOR != '/') {
                 $new_filename_sys = str_replace('/', DIRECTORY_SEPARATOR, $new_filename_sys);
                 $new_url = str_replace(DIRECTORY_SEPARATOR, '/', $new_url);
             }
             // Make sure the target directory exists
             if (!JFile::exists($new_path)) {
                 if (!JFolder::create($new_path)) {
                     $errmsg = JText::sprintf('ATTACH_ERROR_UNABLE_TO_SETUP_UPLOAD_DIR_S', $new_path) . ' (ERR 74)';
                     JError::raiseError(500, $errmsg);
                 }
                 AttachmentsHelper::write_empty_index_html($new_path);
             }
             // Move the file!
             if (!JFile::move($current_filename_sys, $new_filename_sys)) {
                 $errmsg = JText::sprintf('ATTACH_ERROR_RENAMING_FILE_S_TO_S', $old_filename_sys, $new_filename_sys) . ' (ERR 75)';
                 JError::raiseError(500, $errmsg);
             }
             // Verify the new system filename exists!
             if (!JFile::exists($new_filename_sys)) {
                 $errmsg = JText::sprintf('ATTACH_ERROR_NEW_SYSTEM_FILENAME_S_NOT_FOUND', $new_filename_sys) . ' (ERR 76)';
                 JError::raiseError(500, $errmsg);
             }
             // Update the record
             $attachment->filename_sys = $new_filename_sys;
             $attachment->url = $new_url;
             if (!$attachment->store()) {
                 $errmsg = $attachment->getError() . ' (ERR 77)';
                 JError::raiseError(500, $errmsg);
             }
             $numUpdated++;
         }
     }
     // Add warning if there are problem files
     if ($numMissing > 0) {
         $msg = JText::sprintf('ATTACH_ERROR_N_FILES_MISSING', $numMissing) . "<br/>" . $msg . "&nbsp;<br/>";
     }
     return $msg . JText::sprintf('ATTACH_REGENERATED_SYSTEM_FILENAMES_FOR_N_ATTACHMENTS', $numUpdated);
 }