Exemplo n.º 1
0
 function install($plugin_version, &$errors = array())
 {
     global $conf;
     if (empty($conf['flickr2piwigo'])) {
         conf_update_param('flickr2piwigo', $this->default_conf, true);
     }
     mkgetdir(PHPWG_ROOT_PATH . $conf['data_location'] . 'flickr_cache/', MKGETDIR_DEFAULT & ~MKGETDIR_DIE_ON_ERROR);
 }
Exemplo n.º 2
0
function ilog()
{
    global $conf;
    if (!$conf['enable_i_log']) {
        return;
    }
    $line = date("c");
    foreach (func_get_args() as $arg) {
        $line .= ' ';
        if (is_array($arg)) {
            $line .= implode(' ', $arg);
        } else {
            $line .= $arg;
        }
    }
    $file = PHPWG_ROOT_PATH . $conf['data_location'] . 'tmp/i.log';
    if (false == file_put_contents($file, $line . "\n", FILE_APPEND)) {
        mkgetdir(dirname($file));
    }
}
Exemplo n.º 3
0
 function set($key, $value, $lifetime = null)
 {
     if ($lifetime === null) {
         $lifetime = $this->default_lifetime;
     }
     if (rand() % 97 == 0) {
         $this->purge(false);
     }
     $serialized = serialize(array('expire' => time() + $lifetime, 'data' => $value));
     if (false === @file_put_contents($this->dir . $key . '.cache', $serialized)) {
         mkgetdir($this->dir, MKGETDIR_DEFAULT & ~MKGETDIR_DIE_ON_ERROR);
         if (false === @file_put_contents($this->dir . $key . '.cache', $serialized)) {
             return false;
         }
     }
     return true;
 }
Exemplo n.º 4
0
Arquivo: i.php Projeto: donseba/Piwigo
        }
    } catch (Exception $e) {
        $logger->error($e->getMessage(), 'i.php');
    }
} else {
    $page['rotation_angle'] = 0;
}
pwg_db_close();
if (!try_switch_source($params, $src_mtime) && $params->type == IMG_CUSTOM) {
    $sharpen = 0;
    foreach (ImageStdParams::get_defined_type_map() as $std_params) {
        $sharpen += $std_params->sharpen;
    }
    $params->sharpen = round($sharpen / count(ImageStdParams::get_defined_type_map()));
}
if (!mkgetdir(dirname($page['derivative_path']))) {
    ierror("dir create error", 500);
}
ignore_user_abort(true);
@set_time_limit(0);
$image = new pwg_image($page['src_path']);
$timing['load'] = time_step($step);
$changes = 0;
// rotate
if (0 != $page['rotation_angle']) {
    $image->rotate($page['rotation_angle']);
    $changes++;
    $timing['rotate'] = time_step($step);
}
// Crop & scale
$o_size = $d_size = array($image->get_width(), $image->get_height());
Exemplo n.º 5
0
$user_upload_conf['uploadable_categories'] = array();
while ($row = pwg_db_fetch_assoc($result)) {
    array_push($user_upload_conf['uploadable_categories'], $row['id']);
}
// save configuration for a future use by the Community plugin
$backup_filepath = PHPWG_ROOT_PATH . $conf['data_location'] . 'plugins/core_user_upload_to_community.php';
$save_conf = true;
if (is_dir(dirname($backup_filepath))) {
    if (!is_writable(dirname($backup_filepath))) {
        $save_conf = false;
    }
} elseif (!is_writable(PHPWG_ROOT_PATH . $conf['data_location'])) {
    $save_conf = false;
}
if ($save_conf) {
    mkgetdir(dirname($backup_filepath));
    file_put_contents($backup_filepath, '<?php $user_upload_conf = \'' . serialize($user_upload_conf) . '\'; ?>');
}
//
// remove all what is related to user upload in the database
//
// categories.uploadable
pwg_query('ALTER TABLE ' . CATEGORIES_TABLE . ' DROP COLUMN uploadable;');
// waiting
pwg_query('DROP TABLE ' . PREFIX_TABLE . 'waiting;');
// config parameter settings : upload_user_access, upload_link_everytime
$query = '
DELETE FROM ' . PREFIX_TABLE . 'config
  WHERE param IN (\'upload_user_access\', \'upload_link_everytime\', \'email_admin_on_picture_uploaded\')
;';
pwg_query($query);
Exemplo n.º 6
0
/**
 * Saves a copy of the mail if _data/tmp.
 *
 * @param boolean $success
 * @param PHPMailer $mail
 * @param array $args
 */
function pwg_send_mail_test($success, $mail, $args)
{
    global $conf, $user, $lang_info;
    $dir = PHPWG_ROOT_PATH . $conf['data_location'] . 'tmp';
    if (mkgetdir($dir, MKGETDIR_DEFAULT & ~MKGETDIR_DIE_ON_ERROR)) {
        $filename = $dir . '/mail.' . stripslashes($user['username']) . '.' . $lang_info['code'] . '-' . date('YmdHis') . ($success ? '' : '.ERROR');
        if ($args['content_format'] == 'text/plain') {
            $filename .= '.txt';
        } else {
            $filename .= '.html';
        }
        $file = fopen($filename, 'w+');
        if (!$success) {
            fwrite($file, "ERROR: " . $mail->ErrorInfo . "\n\n");
        }
        fwrite($file, $mail->getSentMIMEMessage());
        fclose($file);
    }
}
// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
// | USA.                                                                  |
// +-----------------------------------------------------------------------+
if (!defined("PHPWG_ROOT_PATH")) {
    die("Hacking attempt!");
}
$errors = array();
$pwatermark = $_POST['w'];
// step 0 - manage upload if any
if (isset($_FILES['watermarkImage']) and !empty($_FILES['watermarkImage']['tmp_name'])) {
    list($width, $height, $type) = getimagesize($_FILES['watermarkImage']['tmp_name']);
    if (IMAGETYPE_PNG != $type) {
        $errors['watermarkImage'] = sprintf(l10n('Allowed file types: %s.'), 'PNG');
    } else {
        $upload_dir = PHPWG_ROOT_PATH . PWG_LOCAL_DIR . 'watermarks';
        if (mkgetdir($upload_dir, MKGETDIR_DEFAULT & ~MKGETDIR_DIE_ON_ERROR)) {
            $new_name = get_filename_wo_extension($_FILES['watermarkImage']['name']) . '.png';
            $file_path = $upload_dir . '/' . $new_name;
            if (move_uploaded_file($_FILES['watermarkImage']['tmp_name'], $file_path)) {
                $pwatermark['file'] = substr($file_path, strlen(PHPWG_ROOT_PATH));
            } else {
                $page['errors'][] = $errors['watermarkImage'] = "{$file_path} " . l10n('no write access');
            }
        } else {
            $page['errors'][] = $errors['watermarkImage'] = sprintf(l10n('Add write access to the "%s" directory'), $upload_dir);
        }
    }
}
// step 1 - sanitize HTML input
switch ($pwatermark['position']) {
    case 'topleft':
Exemplo n.º 8
0
 /**
  * Process a set of pending files.
  *
  * @param array &$result
  * @param array &$pending
  * @param string[] $key
  * @param bool $force
  */
 private function flush_pending(&$result, &$pending, $key, $force)
 {
     if (count($pending) > 1) {
         $key = join('>', $key);
         $file = PWG_COMBINED_DIR . base_convert(crc32($key), 10, 36) . '.' . $this->type;
         if ($force || !file_exists(PHPWG_ROOT_PATH . $file)) {
             $output = '';
             $header = '';
             foreach ($pending as $combinable) {
                 $output .= "/*BEGIN {$combinable->path} */\n";
                 $output .= $this->process_combinable($combinable, true, $force, $header);
                 $output .= "\n";
             }
             $output = "/*BEGIN header */\n" . $header . "\n" . $output;
             mkgetdir(dirname(PHPWG_ROOT_PATH . $file));
             file_put_contents(PHPWG_ROOT_PATH . $file, $output);
             @chmod(PHPWG_ROOT_PATH . $file, 0644);
         }
         $result[] = new Combinable("combi", $file, false);
     } elseif (count($pending) == 1) {
         $header = '';
         $this->process_combinable($pending[0], false, $force, $header);
         $result[] = $pending[0];
     }
     $key = array();
     $pending = array();
 }
Exemplo n.º 9
0
 /**
  * Open the log file if not already oppenned
  */
 private function open()
 {
     if ($this->status() == self::STATUS_LOG_CLOSED) {
         if (!file_exists($this->options['directory'])) {
             mkgetdir($this->options['directory'], MKGETDIR_DEFAULT | MKGETDIR_PROTECT_HTACCESS);
         }
         if (file_exists($this->options['filePath']) && !is_writable($this->options['filePath'])) {
             $this->_logStatus = self::STATUS_OPEN_FAILED;
             throw new RuntimeException(self::$_messages['writefail']);
             return;
         }
         if (($this->_fileHandle = fopen($this->options['filePath'], 'a')) != false) {
             $this->_logStatus = self::STATUS_LOG_OPEN;
         } else {
             $this->_logStatus = self::STATUS_OPEN_FAILED;
             throw new RuntimeException(self::$_messages['openfail']);
         }
     }
 }
Exemplo n.º 10
0
/**
 * Recursively delete a directory.
 *
 * @param string $path
 * @param string $trash_path, try to move the directory to this path if it cannot be delete
 */
function deltree($path, $trash_path = null)
{
    if (is_dir($path)) {
        $fh = opendir($path);
        while ($file = readdir($fh)) {
            if ($file != '.' and $file != '..') {
                $pathfile = $path . '/' . $file;
                if (is_dir($pathfile)) {
                    deltree($pathfile, $trash_path);
                } else {
                    @unlink($pathfile);
                }
            }
        }
        closedir($fh);
        if (@rmdir($path)) {
            return true;
        } elseif (!empty($trash_path)) {
            if (!is_dir($trash_path)) {
                @mkgetdir($trash_path, MKGETDIR_RECURSIVE | MKGETDIR_DIE_ON_ERROR | MKGETDIR_PROTECT_HTACCESS);
            }
            while ($r = $trash_path . '/' . md5(uniqid(rand(), true))) {
                if (!is_dir($r)) {
                    @rename($path, $r);
                    break;
                }
            }
        } else {
            return false;
        }
    }
}
Exemplo n.º 11
0
 static function upgrade_to($upgrade_to, &$step, $check_current_version = true)
 {
     global $page, $conf, $template;
     if ($check_current_version and !version_compare($upgrade_to, PHPWG_VERSION, '>')) {
         redirect(get_root_url() . 'admin.php?page=plugin-' . basename(dirname(__FILE__)));
     }
     if ($step == 2) {
         preg_match('/(\\d+\\.\\d+)\\.(\\d+)/', PHPWG_VERSION, $matches);
         $code = $matches[1] . '.x_to_' . $upgrade_to;
         $dl_code = str_replace(array('.', '_'), '', $code);
         $remove_path = $code;
         $obsolete_list = 'obsolete.list';
     } else {
         $code = $upgrade_to;
         $dl_code = $code;
         $remove_path = version_compare($code, '2.0.8', '>=') ? 'piwigo' : 'piwigo-' . $code;
         $obsolete_list = PHPWG_ROOT_PATH . 'install/obsolete.list';
     }
     if (empty($page['errors'])) {
         $path = PHPWG_ROOT_PATH . $conf['data_location'] . 'update';
         $filename = $path . '/' . $code . '.zip';
         @mkgetdir($path);
         $chunk_num = 0;
         $end = false;
         $zip = @fopen($filename, 'w');
         while (!$end) {
             $chunk_num++;
             if (@fetchRemote(PHPWG_URL . '/download/dlcounter.php?code=' . $dl_code . '&chunk_num=' . $chunk_num, $result) and $input = @unserialize($result)) {
                 if (0 == $input['remaining']) {
                     $end = true;
                 }
                 @fwrite($zip, base64_decode($input['data']));
             } else {
                 $end = true;
             }
         }
         @fclose($zip);
         if (@filesize($filename)) {
             $zip = new PclZip($filename);
             if ($result = $zip->extract(PCLZIP_OPT_PATH, PHPWG_ROOT_PATH, PCLZIP_OPT_REMOVE_PATH, $remove_path, PCLZIP_OPT_SET_CHMOD, 0755, PCLZIP_OPT_REPLACE_NEWER)) {
                 //Check if all files were extracted
                 $error = '';
                 foreach ($result as $extract) {
                     if (!in_array($extract['status'], array('ok', 'filtered', 'already_a_directory'))) {
                         // Try to change chmod and extract
                         if (@chmod(PHPWG_ROOT_PATH . $extract['filename'], 0777) and $res = $zip->extract(PCLZIP_OPT_BY_NAME, $remove_path . '/' . $extract['filename'], PCLZIP_OPT_PATH, PHPWG_ROOT_PATH, PCLZIP_OPT_REMOVE_PATH, $remove_path, PCLZIP_OPT_SET_CHMOD, 0755, PCLZIP_OPT_REPLACE_NEWER) and isset($res[0]['status']) and $res[0]['status'] == 'ok') {
                             continue;
                         } else {
                             $error .= $extract['filename'] . ': ' . $extract['status'] . "\n";
                         }
                     }
                 }
                 if (empty($error)) {
                     self::process_obsolete_list($obsolete_list);
                     deltree(PHPWG_ROOT_PATH . $conf['data_location'] . 'update');
                     invalidate_user_cache(true);
                     $template->delete_compiled_templates();
                     unset($_SESSION['need_update']);
                     if ($step == 2) {
                         $page['infos'][] = l10n('Update Complete');
                         $page['infos'][] = $upgrade_to;
                         $step = -1;
                     } else {
                         redirect(PHPWG_ROOT_PATH . 'upgrade.php?now=');
                     }
                 } else {
                     file_put_contents(PHPWG_ROOT_PATH . $conf['data_location'] . 'update/log_error.txt', $error);
                     $page['errors'][] = l10n('An error has occured during extract. Please check files permissions of your piwigo installation.<br><a href="%s">Click here to show log error</a>.', get_root_url() . $conf['data_location'] . 'update/log_error.txt');
                 }
             } else {
                 deltree(PHPWG_ROOT_PATH . $conf['data_location'] . 'update');
                 $page['errors'][] = l10n('An error has occured during upgrade.');
             }
         } else {
             $page['errors'][] = l10n('Piwigo cannot retrieve upgrade file from server');
         }
     }
 }
Exemplo n.º 12
0
/**
 * API method
 * Adds a image (simple way)
 * @param mixed[] $params
 *    @option int[] category
 *    @option string name (optional)
 *    @option string author (optional)
 *    @option string comment (optional)
 *    @option int level
 *    @option string|string[] tags
 *    @option int image_id (optional)
 */
function ws_images_upload($params, $service)
{
    global $conf;
    if (get_pwg_token() != $params['pwg_token']) {
        return new PwgError(403, 'Invalid security token');
    }
    // usleep(100000);
    // if (!isset($_FILES['image']))
    // {
    //   return new PwgError(405, 'The image (file) is missing');
    // }
    // file_put_contents('/tmp/plupload.log', "[".date('c')."] ".__FUNCTION__."\n\n", FILE_APPEND);
    // file_put_contents('/tmp/plupload.log', '$_FILES = '.var_export($_FILES, true)."\n", FILE_APPEND);
    // file_put_contents('/tmp/plupload.log', '$_POST = '.var_export($_POST, true)."\n", FILE_APPEND);
    $upload_dir = $conf['upload_dir'] . '/buffer';
    // create the upload directory tree if not exists
    if (!mkgetdir($upload_dir, MKGETDIR_DEFAULT & ~MKGETDIR_DIE_ON_ERROR)) {
        return new PwgError(500, 'error during buffer directory creation');
    }
    // Get a file name
    if (isset($_REQUEST["name"])) {
        $fileName = $_REQUEST["name"];
    } elseif (!empty($_FILES)) {
        $fileName = $_FILES["file"]["name"];
    } else {
        $fileName = uniqid("file_");
    }
    $filePath = $upload_dir . DIRECTORY_SEPARATOR . $fileName;
    // Chunking might be enabled
    $chunk = isset($_REQUEST["chunk"]) ? intval($_REQUEST["chunk"]) : 0;
    $chunks = isset($_REQUEST["chunks"]) ? intval($_REQUEST["chunks"]) : 0;
    // file_put_contents('/tmp/plupload.log', "[".date('c')."] ".__FUNCTION__.', '.$fileName.' '.($chunk+1).'/'.$chunks."\n", FILE_APPEND);
    // Open temp file
    if (!($out = @fopen("{$filePath}.part", $chunks ? "ab" : "wb"))) {
        die('{"jsonrpc" : "2.0", "error" : {"code": 102, "message": "Failed to open output stream."}, "id" : "id"}');
    }
    if (!empty($_FILES)) {
        if ($_FILES["file"]["error"] || !is_uploaded_file($_FILES["file"]["tmp_name"])) {
            die('{"jsonrpc" : "2.0", "error" : {"code": 103, "message": "Failed to move uploaded file."}, "id" : "id"}');
        }
        // Read binary input stream and append it to temp file
        if (!($in = @fopen($_FILES["file"]["tmp_name"], "rb"))) {
            die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "Failed to open input stream."}, "id" : "id"}');
        }
    } else {
        if (!($in = @fopen("php://input", "rb"))) {
            die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "Failed to open input stream."}, "id" : "id"}');
        }
    }
    while ($buff = fread($in, 4096)) {
        fwrite($out, $buff);
    }
    @fclose($out);
    @fclose($in);
    // Check if file has been uploaded
    if (!$chunks || $chunk == $chunks - 1) {
        // Strip the temp .part suffix off
        rename("{$filePath}.part", $filePath);
        include_once PHPWG_ROOT_PATH . 'admin/include/functions_upload.inc.php';
        $image_id = add_uploaded_file($filePath, stripslashes($params['name']), $params['category'], $params['level'], null);
        $query = '
SELECT
    id,
    name,
    representative_ext,
    path
  FROM ' . IMAGES_TABLE . '
  WHERE id = ' . $image_id . '
;';
        $image_infos = pwg_db_fetch_assoc(pwg_query($query));
        $query = '
SELECT
    COUNT(*) AS nb_photos
  FROM ' . IMAGE_CATEGORY_TABLE . '
  WHERE category_id = ' . $params['category'][0] . '
;';
        $category_infos = pwg_db_fetch_assoc(pwg_query($query));
        $category_name = get_cat_display_name_from_id($params['category'][0], null);
        return array('image_id' => $image_id, 'src' => DerivativeImage::thumb_url($image_infos), 'name' => $image_infos['name'], 'category' => array('id' => $params['category'][0], 'nb_photos' => $category_infos['nb_photos'], 'label' => $category_name));
    }
}
Exemplo n.º 13
0
    // update the last check from time to time to avoid deletion by maintenance tasks
    if (!isset($feed_row['last_check']) or time() - datetime_to_ts($feed_row['last_check']) > 30 * 24 * 3600) {
        $query = '
UPDATE ' . USER_FEED_TABLE . '
  SET last_check = ' . pwg_db_get_recent_period_expression(-15, $dbnow) . '
  WHERE id = \'' . $feed_id . '\'
;';
        pwg_query($query);
    }
}
$dates = get_recent_post_dates_array($conf['recent_post_dates']['RSS']);
foreach ($dates as $date_detail) {
    // for each recent post date we create a feed item
    $item = new FeedItem();
    $date = $date_detail['date_available'];
    $item->title = get_title_recent_post_date($date_detail);
    $item->link = make_index_url(array('chronology_field' => 'posted', 'chronology_style' => 'monthly', 'chronology_view' => 'calendar', 'chronology_date' => explode('-', substr($date, 0, 10))));
    $item->description .= '<a href="' . make_index_url() . '">' . $conf['gallery_title'] . '</a><br> ';
    $item->description .= get_html_description_recent_post_date($date_detail);
    $item->descriptionHtmlSyndicated = true;
    $item->date = ts_to_iso8601(datetime_to_ts($date));
    $item->author = $conf['rss_feed_author'];
    $item->guid = sprintf('%s', 'pics-' . $date);
    $rss->addItem($item);
}
$fileName = PHPWG_ROOT_PATH . $conf['data_location'] . 'tmp';
mkgetdir($fileName);
// just in case
$fileName .= '/feed.xml';
// send XML feed
echo $rss->saveFeed('RSS2.0', $fileName, true);