/**
 * Returns the name of a cachefile from given data
 *
 * The needed directory is created by this function!
 *
 * @author Andreas Gohr <*****@*****.**>
 * @author Tim Kroeger <*****@*****.**>
 *
 * @param string $data  This data is used to create a unique md5 name
 * @param string $ext   This is appended to the filename if given
 * @return string       The filename of the cachefile
 */
function getCacheName($data, $ext = '')
{
    global $bmzConf;
    $md5 = md5($data);
    $file = $bmzConf['cachedir'] . '/' . $md5[0] . '/' . $md5 . $ext;
    io_makeFileDir($file);
    return $file;
}
 /**
  * @group slow
  */
 public function test_moveSingleMedia_colonstart()
 {
     global $AUTH_ACL;
     $AUTH_ACL[] = "wiki:*\t@ALL\t16";
     $AUTH_ACL[] = "foobar:*\t@ALL\t8";
     $filepath = DOKU_TMP_DATA . 'media/wiki/testimage.png';
     io_makeFileDir($filepath);
     io_saveFile($filepath, '');
     saveWikiText('wiki:movetest', '{{:wiki:testimage.png?200}}', 'Test initialized');
     idx_addPage('wiki:movetest');
     $src = 'wiki:testimage.png';
     $dst = 'foobar:logo_2.png';
     /** @var helper_plugin_move_op $move */
     $move = plugin_load('helper', 'move_op');
     $this->assertTrue($move->moveMedia($src, $dst));
     $this->assertTrue(@file_exists(mediaFn('foobar:logo_2.png')));
     $this->assertEquals('{{:foobar:logo_2.png?200}}', rawWiki('wiki:movetest'));
 }
Example #3
0
/**
 * Returns the name of a cachefile from given data
 *
 * The needed directory is created by this function!
 *
 * @author Andreas Gohr <*****@*****.**>
 *
 * @param string $data  This data is used to create a unique md5 name
 * @param string $ext   This is appended to the filename if given
 * @return string       The filename of the cachefile
 */
function getCacheName($data, $ext = '')
{
    global $conf;
    $md5 = md5($data);
    $file = $conf['cachedir'] . '/' . $md5[0] . '/' . $md5 . $ext;
    if ($conf['syslog']) {
        syslog(LOG_WARNING, '[pageutils.php] getCacheName: data: ' . $data);
    }
    if ($conf['syslog']) {
        syslog(LOG_WARNING, '[pageutils.php] getCacheName: cache name generated from md5sum of data: ' . $file);
    }
    io_makeFileDir($file);
    return $file;
}
/**
 * Create missing namespace directories and send the IO_NAMESPACE_CREATED events
 * in the order of directory creation. (Parent directories first.)
 *
 * Event data:
 * $data[0]    ns: The colon separated namespace path minus the trailing page name.
 * $data[1]    ns_type: 'pages' or 'media' namespace tree.
 *
 * @author Ben Coburn <*****@*****.**>
 */
function io_createNamespace($id, $ns_type = 'pages')
{
    // verify ns_type
    $types = array('pages' => 'wikiFN', 'media' => 'mediaFN');
    if (!isset($types[$ns_type])) {
        trigger_error('Bad $ns_type parameter for io_createNamespace().');
        return;
    }
    // make event list
    $missing = array();
    $ns_stack = explode(':', $id);
    $ns = $id;
    $tmp = dirname($file = call_user_func($types[$ns_type], $ns));
    while (!@is_dir($tmp) && !(@file_exists($tmp) && !is_dir($tmp))) {
        array_pop($ns_stack);
        $ns = implode(':', $ns_stack);
        if (strlen($ns) == 0) {
            break;
        }
        $missing[] = $ns;
        $tmp = dirname(call_user_func($types[$ns_type], $ns));
    }
    // make directories
    io_makeFileDir($file);
    // send the events
    $missing = array_reverse($missing);
    // inside out
    foreach ($missing as $ns) {
        $data = array($ns, $ns_type);
        trigger_event('IO_NAMESPACE_CREATED', $data);
    }
}
Example #5
0
     if ($_FILES['medium_image']['name'] != '') {
         $data['mediumImgExtension'] = substr($_FILES['medium_image']['name'], strrpos($_FILES['medium_image']['name'], '.'));
         $data['mediumFileName'] = 'medium/' . $data['imgBaseDir'] . $data['imgBase'] . $data['imgSuffix'] . IMAGE_SUFFIX_MEDIUM . $data['mediumImgExtension'];
         io_makeFileDir(DIR_FS_CATALOG_IMAGES . $data['mediumFileName']);
         $source_name = $_FILES['medium_image']['tmp_name'];
         $destination_name = DIR_FS_CATALOG_IMAGES . $data['mediumFileName'];
         if (!move_uploaded_file($source_name, $destination_name)) {
             $messageStack->add(TEXT_MSG_NOUPLOAD_MEDIUM, "error");
             $check = 1;
         }
     }
     // large image
     if ($_FILES['large_image']['name'] != '') {
         $data['largeImgExtension'] = substr($_FILES['large_image']['name'], strrpos($_FILES['large_image']['name'], '.'));
         $data['largeFileName'] = 'large/' . $data['imgBaseDir'] . $data['imgBase'] . $data['imgSuffix'] . IMAGE_SUFFIX_LARGE . $data['largeImgExtension'];
         io_makeFileDir(DIR_FS_CATALOG_IMAGES . $data['largeFileName']);
         $source_name = $_FILES['large_image']['tmp_name'];
         $destination_name = DIR_FS_CATALOG_IMAGES . $data['largeFileName'];
         if (!move_uploaded_file($source_name, $destination_name)) {
             $messageStack->add(TEXT_MSG_NOUPLOAD_LARGE, "error");
             $check = 1;
         }
     }
 }
 if ($check == 1) {
     if ($_GET['imgEdit'] == 1) {
         $action = "layout_edit";
     } else {
         $action = "layout_new";
     }
     $repeat_check = 1;
Example #6
0
/**
 * Moves the current version of media file to the media_attic
 * directory
 *
 * @author Kate Arzamastseva <*****@*****.**>
 * @param string $id
 * @return int - revision date
 */
function media_saveOldRevision($id)
{
    global $conf, $lang;
    $oldf = mediaFN($id);
    if (!@file_exists($oldf)) {
        return '';
    }
    $date = filemtime($oldf);
    if (!$conf['mediarevisions']) {
        return $date;
    }
    $medialog = new MediaChangeLog($id);
    if (!$medialog->getRevisionInfo($date)) {
        // there was an external edit,
        // there is no log entry for current version of file
        if (!@file_exists(mediaMetaFN($id, '.changes'))) {
            addMediaLogEntry($date, $id, DOKU_CHANGE_TYPE_CREATE, $lang['created']);
        } else {
            addMediaLogEntry($date, $id, DOKU_CHANGE_TYPE_EDIT);
        }
    }
    $newf = mediaFN($id, $date);
    io_makeFileDir($newf);
    if (copy($oldf, $newf)) {
        // Set the correct permission here.
        // Always chmod media because they may be saved with different permissions than expected from the php umask.
        // (Should normally chmod to $conf['fperm'] only if $conf['fperm'] is set.)
        chmod($newf, $conf['fmode']);
    }
    return $date;
}
 /**
  * get to-be directory and filename (without extension)
  *
  * all files are stored in the media directory into 'plugin_abc/<namespaces>/'
  * and the filename is a mixture of abc-id and abc-title (e.g. 42_the_title.abc|...)
  *
  */
 function _getFileBase($src)
 {
     global $ID;
     global $ACT;
     global $conf;
     $mediadir = $conf['mediadir'];
     // where to store the abc media files
     $abcdir = $this->getConf('mediaNS') ? $mediadir . '/' . $this->getConf('mediaNS') : $mediadir;
     io_makeFileDir($abcdir);
     $fileDir = $abcdir . '/' . utf8_encodeFN(str_replace(':', '/', getNS($ID)));
     // the abcID is what comes after the 'X:'
     preg_match("/\\s?X\\s?:(.*?)\n/se", $src, $matchesX);
     $abcID = preg_replace('/\\s?X\\s?:/', '', $matchesX[0]);
     // the abcTitle is what comes after the (first) 'T:'
     preg_match("/\\s?T\\s?:(.*?)\n/se", $src, $matchesT);
     $abcTitle = preg_replace('/\\s?T\\s?:/', '', $matchesT[0]);
     $fileName = cleanID($abcID . "_" . $abcTitle);
     // no double slash when in root namespace
     $slashStr = getNS($ID) ? "/" : "";
     // have different fileBase for previewing
     $previewPrefix = $ACT != 'preview' ? "" : "x";
     $fileBase = $fileDir . $slashStr . $previewPrefix . $fileName;
     // unfortunately abcm2ps seems not to be able to handle
     // file names (realpath) of more than 120 characters
     $realFileBaseLen = strlen(fullpath($abcdir)) - strlen($abcdir) + strlen($fileBase);
     $char_len = 114;
     if ($realFileBaseLen >= $char_len) {
         $truncLen = strlen($fileBase) + ($char_len - $realFileBaseLen);
         $fileBase = substr($fileBase, 0, $truncLen);
     }
     return $fileBase;
 }
 if (!move_uploaded_file($source_name, $destination_name)) {
     //mytest
     $messageStack->add(TEXT_MSG_NOUPLOAD_LARGE, "error");
 } else {
     $messageStack->add(TEXT_MSG_UPLOAD_LARGE, "success");
 }
 $data['smallFileName'] = 's/' . $nameBase . $data['ImgExtension'];
 $data['mediumFileName'] = 'l/' . $nameBase . $data['ImgExtension'];
 //print_r($data['mediumFileName']);
 $data['largeFileName'] = 'v/' . $nameBase . $data['ImgExtension'];
 //print_r($data['largeFileName']);
 $destination_name_small = DIR_FS_CATALOG_IMAGES . $data['smallFileName'];
 $destination_name_medium = DIR_FS_CATALOG_IMAGES . $data['mediumFileName'];
 $destination_name_large = DIR_FS_CATALOG_IMAGES . $data['largeFileName'];
 io_makeFileDir($destination_name_medium);
 io_makeFileDir($destination_name_large);
 if (!copy($destination_name, $destination_name_medium)) {
     $messageStack->add('failed to copy ' . $file . '...', "error");
 } else {
     $messageStack->add('Successed to copy ' . $file . '...', "success");
     if ($data['ImgExtension'] == ".jpg" || $data['ImgExtension'] == ".jpeg") {
         $im = @imagecreatefromjpeg($destination_name_medium);
     }
     if ($data['ImgExtension'] == ".gif") {
         $im = @imagecreatefromgif($destination_name_medium);
     }
     if ($data['ImgExtension'] == ".png") {
         $im = @imagecreatefrompng($destination_name_medium);
     }
     list($width_orig, $height_orig) = getimagesize($destination_name_medium);
     $width = PRODUCT_MEDIUM_IMAGE_WIDTH;
Example #9
0
 /**
  * replaces the replacement parts in the local ini
  *
  * @param string $new the new ini contents
  */
 protected function replaceini($new)
 {
     global $conf;
     $ini = DOKU_CONF . "tpl/" . $conf['template'] . "/style.ini";
     if (file_exists($ini)) {
         $old = io_readFile($ini);
         $old = preg_replace('/\\[replacements\\]\\n.*?(\\n\\[.*]|$)/s', '\\1', $old);
         $old = trim($old);
     } else {
         $old = '';
     }
     io_makeFileDir($ini);
     io_saveFile($ini, "{$old}\n\n{$new}");
 }
 /**
  * This is an integration test, which checks the correct working of an entire namespace move.
  * Hence it is not an unittest, hence it @coversNothing
  *
  * @group slow
  */
 public function test_move_small_namespace_subscription_page()
 {
     global $AUTH_ACL;
     $AUTH_ACL[] = "subns:*\t@ALL\t16";
     $AUTH_ACL[] = "newns:*\t@ALL\t16";
     saveWikiText('subns:start', 'Lorem Ipsum', 'setup');
     idx_addPage('subns:start');
     $oldfilepath = DOKU_TMP_DATA . 'meta/subns/start.mlist';
     $subscription = 'doe every 1427984341';
     io_makeFileDir($oldfilepath);
     io_saveFile($oldfilepath, $subscription);
     $newfilepath = DOKU_TMP_DATA . 'meta/newns/start.mlist';
     /** @var helper_plugin_move_plan $plan  */
     $plan = plugin_load('helper', 'move_plan');
     $this->assertFalse($plan->inProgress());
     $plan->addPageNamespaceMove('subns', 'newns');
     $plan->commit();
     $this->assertSame(1, $plan->nextStep(), 'pages');
     $this->assertSame(1, $plan->nextStep(), 'namespace');
     $this->assertSame(0, $plan->nextStep(), 'done');
     $this->assertFileExists(wikiFN('newns:start'));
     $this->assertFileExists($newfilepath);
     $this->assertFileNotExists(wikiFN('subns:start'));
     $this->assertFileNotExists($oldfilepath);
     $this->assertSame($subscription, file_get_contents($newfilepath));
 }
 function test_findMissingDocuments_nonMissingMedia()
 {
     $filepath = DOKU_TMP_DATA . 'media/oldns/oldnsimage.png';
     io_makeFileDir($filepath);
     io_saveFile($filepath, '');
     saveWikiText('start', '{{oldns:oldnsimage.png}}', 'test edit');
     idx_addPage('start');
     $this->plan->findMissingDocuments('oldns:', 'newns:', helper_plugin_move_plan::TYPE_MEDIA);
     $tmpstore = $this->plan->getTmpstore();
     $this->assertSame(array(), $tmpstore['miss_media']);
 }