Пример #1
0
/**
 * Loads a SQL file and executes all queries.
 * Before executing a query, $replaced is... replaced by $replacing. This is
 * useful when the SQL file contains generic words. Drop table queries are
 * not executed.
 *
 * @param string $filepath
 * @param string $replaced
 * @param string $replacing
 */
function execute_sqlfile($filepath, $replaced, $replacing, $dblayer)
{
    $sql_lines = file($filepath);
    $query = '';
    foreach ($sql_lines as $sql_line) {
        $sql_line = trim($sql_line);
        if (preg_match('/(^--|^$)/', $sql_line)) {
            continue;
        }
        $query .= ' ' . $sql_line;
        // if we reached the end of query, we execute it and reinitialize the
        // variable "query"
        if (preg_match('/;$/', $sql_line)) {
            $query = trim($query);
            $query = str_replace($replaced, $replacing, $query);
            // we don't execute "DROP TABLE" queries
            if (!preg_match('/^DROP TABLE/i', $query)) {
                if ('mysql' == $dblayer) {
                    if (preg_match('/^(CREATE TABLE .*)[\\s]*;[\\s]*/im', $query, $matches)) {
                        $query = $matches[1] . ' DEFAULT CHARACTER SET utf8' . ';';
                    }
                }
                pwg_query($query);
            }
            $query = '';
        }
    }
}
Пример #2
0
function upgrade_250_255()
{
    global $conf;
    // Add new field in Register_FluxBB ID links table
    $query = 'ALTER TABLE ' . Register_FluxBB_ID_TABLE . ' ADD PwdSynch VARCHAR(3) NULL DEFAULT NULL;';
    pwg_query($query);
}
Пример #3
0
function upgrade65_change_table_to_charset($table, $field_definitions, $db_charset)
{
    $changes = array();
    foreach ($field_definitions as $row) {
        if (!isset($row['Collation']) or $row['Collation'] == 'NULL') {
            continue;
        }
        $query = $row['Field'] . ' ' . $row['Type'];
        $query .= ' CHARACTER SET ' . $db_charset;
        if (strpos($row['Collation'], '_bin') !== false) {
            $query .= ' BINARY';
        }
        if ($row['Null'] != 'YES') {
            $query .= ' NOT NULL';
            if (isset($row['Default'])) {
                $query .= ' DEFAULT "' . addslashes($row['Default']) . '"';
            }
        } else {
            if (!isset($row['Default'])) {
                $query .= ' DEFAULT NULL';
            } else {
                $query .= ' DEFAULT "' . addslashes($row['Default']) . '"';
            }
        }
        if ($row['Extra'] == 'auto_increment') {
            $query .= ' auto_increment';
        }
        $changes[] = 'MODIFY COLUMN ' . $query;
    }
    if (count($changes)) {
        $query = 'ALTER TABLE `' . $table . '` ' . implode(', ', $changes);
        pwg_query($query);
    }
}
Пример #4
0
 function uninstall()
 {
     global $conf;
     conf_delete_param('forecast_conf');
     $q = 'DROP VIEW forecast;';
     pwg_query($q);
 }
Пример #5
0
function vjs_begin_delete_elements($ids)
{
    if (count($ids) == 0) {
        return 0;
    }
    $vjs_extensions = array('ogg', 'ogv', 'mp4', 'm4v', 'webm', 'webmv');
    $files_ext = array_merge(array(), $vjs_extensions, array_map('strtoupper', $vjs_extensions));
    // Find details base on ID and if supported video files
    $query = '
SELECT
    id,
    path,
    representative_ext
  FROM ' . IMAGES_TABLE . '
  WHERE id IN (' . implode(',', $ids) . ') AND ' . SQL_VIDEOS . '
;';
    $result = pwg_query($query);
    while ($row = pwg_db_fetch_assoc($result)) {
        if (url_is_remote($row['path'])) {
            continue;
        }
        $files = array();
        $files[] = get_element_path($row);
        $ok = true;
        if (!isset($conf['never_delete_originals'])) {
            foreach ($files as $path) {
                // Don't delete the actual video or representative
                // It is done by PWG core
                // Delete any other video source format
                $file_wo_ext = pathinfo($path);
                $file_dir = dirname($path);
                foreach ($files_ext as $file_ext) {
                    $path_ext = $file_dir . "/pwg_representative/" . $file_wo_ext['filename'] . "." . $file_ext;
                    if (is_file($path_ext) and !unlink($path_ext)) {
                        $ok = false;
                        trigger_error('"' . $path_ext . '" cannot be removed', E_USER_WARNING);
                        break;
                    }
                }
                // Delete video thumbnails
                $filematch = $file_dir . "/pwg_representative/" . $file_wo_ext['filename'] . "-th_*";
                $matches = glob($filematch);
                if (is_array($matches)) {
                    foreach ($matches as $filename) {
                        if (is_file($filename) and !unlink($filename)) {
                            $ok = false;
                            trigger_error('"' . $filename . '" cannot be removed', E_USER_WARNING);
                            break;
                        }
                    }
                }
                // End videos thumbnails
            }
            // End for each files
        }
        // End IF
    }
    // End While
}
 function uninstall()
 {
     global $prefixeTable;
     $query = 'ALTER TABLE ' . IMAGES_TABLE . ' DROP pqv_validated;';
     pwg_query($query);
     $query = 'DROP TABLE ' . GROUPS_TABLE . ' DROP pqv_enabled;';
     pwg_query($query);
 }
Пример #7
0
function plugin_uninstall()
{
    $query = '
    DELETE FROM ' . CONFIG_TABLE . '
    WHERE param=\'eml\'
  ;';
    pwg_query($query);
}
 function uninstall()
 {
     global $prefixeTable;
     pwg_query('DROP TABLE ' . $prefixeTable . 'pshare_keys;');
     pwg_query('DROP TABLE ' . $prefixeTable . 'pshare_log;');
     $query = 'DROP TABLE ' . GROUPS_TABLE . ' DROP pshare_enabled;';
     pwg_query($query);
 }
Пример #9
0
function plugin_uninstall()
{
    if (is_dir(PHPWG_ROOT_PATH . PWG_LOCAL_DIR . 'GThumb')) {
        gtdeltree(PHPWG_ROOT_PATH . PWG_LOCAL_DIR . 'GThumb');
    }
    $query = 'DELETE FROM ' . CONFIG_TABLE . ' WHERE param="GThumb" LIMIT 1;';
    pwg_query($query);
}
Пример #10
0
function plugin_uninstall()
{
    global $prefixeTable;
    $query = '
    DROP TABLE ' . $prefixeTable . 'stereo
    ;';
    pwg_query($query);
}
Пример #11
0
function get_summary($year = null, $month = null, $day = null)
{
    $query = '
SELECT
    year,
    month,
    day,
    hour,
    nb_pages
  FROM ' . HISTORY_SUMMARY_TABLE;
    if (isset($day)) {
        $query .= '
  WHERE year = ' . $year . '
    AND month = ' . $month . '
    AND day = ' . $day . '
    AND hour IS NOT NULL
  ORDER BY
    year ASC,
    month ASC,
    day ASC,
    hour ASC
;';
    } elseif (isset($month)) {
        $query .= '
  WHERE year = ' . $year . '
    AND month = ' . $month . '
    AND day IS NOT NULL
    AND hour IS NULL
  ORDER BY
    year ASC,
    month ASC,
    day ASC
;';
    } elseif (isset($year)) {
        $query .= '
  WHERE year = ' . $year . '
    AND month IS NOT NULL
    AND day IS NULL
  ORDER BY
    year ASC,
    month ASC
;';
    } else {
        $query .= '
  WHERE year IS NOT NULL
    AND month IS NULL
  ORDER BY
    year ASC
;';
    }
    $result = pwg_query($query);
    $output = array();
    while ($row = pwg_db_fetch_assoc($result)) {
        $output[] = $row;
    }
    return $output;
}
Пример #12
0
function plugin_uninstall()
{
    $q = 'DELETE FROM ' . CONFIG_TABLE . ' WHERE param = "jplayer_skin";';
    pwg_query($q);
    $q = 'DELETE FROM ' . CONFIG_TABLE . ' WHERE param = "jplayer_autoplay";';
    pwg_query($q);
    $q = 'DELETE FROM ' . CONFIG_TABLE . ' WHERE param = "jplayer_jplayer_representative_as_poster";';
    pwg_query($q);
    // TODO : Do we need to purge the videos from the images table?
}
 function uninstall()
 {
     global $prefixeTable;
     $query = 'DROP TABLE ' . $prefixeTable . 'pfemail_mailboxes;';
     pwg_query($query);
     $query = 'DROP TABLE ' . $prefixeTable . 'pfemail_pendings;';
     pwg_query($query);
     // delete configuration
     pwg_query('DELETE FROM `' . CONFIG_TABLE . '` WHERE param IN ("pfemail_last_check");');
 }
Пример #14
0
function plugin_uninstall()
{
    global $conf;
    if (isset($conf['PruneHistory'])) {
        $q = '
DELETE FROM ' . CONFIG_TABLE . '
WHERE param="PruneHistory"
;';
        pwg_query($q);
    }
}
function plugin_uninstall()
{
    global $conf;
    if (isset($conf['CommentsManager'])) {
        $q = '
DELETE FROM ' . CONFIG_TABLE . '
WHERE param="CommentsManager"
;';
        pwg_query($q);
    }
}
Пример #16
0
function get_site_url($category_id)
{
    global $page;
    $query = '
SELECT galleries_url
  FROM ' . SITES_TABLE . ' AS s,' . CATEGORIES_TABLE . ' AS c
  WHERE s.id = c.site_id
    AND c.id = ' . $category_id . '
;';
    $row = pwg_db_fetch_assoc(pwg_query($query));
    return $row['galleries_url'];
}
Пример #17
0
function plugin_uninstall()
{
    global $conf;
    if (isset($conf['Register_PhpBB'])) {
        $q = '
DELETE FROM ' . CONFIG_TABLE . '
WHERE param="Register_PhpBB" LIMIT 1
;';
        pwg_query($q);
    }
    $q = 'DROP TABLE ' . Register_PhpBB_ID_TABLE . ';';
    pwg_query($q);
}
Пример #18
0
function osm_items_have_latlon($items)
{
    $query = '
SELECT id FROM ' . IMAGES_TABLE . '
WHERE latitude IS NOT NULL
  AND id IN (' . implode(',', $items) . ')
ORDER BY NULL
LIMIT 0,1';
    if (pwg_db_num_rows(pwg_query($query)) > 0) {
        return true;
    }
    return false;
}
Пример #19
0
 function activate($theme_version, &$errors = array())
 {
     global $conf, $prefixeTable;
     if (empty($conf['smartpocket'])) {
         $conf['smartpocket'] = serialize($this->default_conf);
         $query = "\n  INSERT INTO " . CONFIG_TABLE . " (param,value,comment)\n  VALUES ('smartpocket' , '" . pwg_db_real_escape_string($conf['smartpocket']) . "' , 'loop#autohide');";
         pwg_query($query);
     } elseif (count(unserialize($conf['smartpocket'])) != 2) {
         $conff = unserialize($conf['smartpocket']);
         $config = array('loop' => !empty($conff['loop']) ? $conff['loop'] : true, 'autohide' => !empty($conff['autohide']) ? $conff['autohide'] : 5000);
         conf_update_param('smartpocket', pwg_db_real_escape_string(serialize($config)));
         load_conf_from_db();
     }
     $this->installed = true;
 }
Пример #20
0
/**
 * search an available feed_id
 *
 * @return string feed identifier
 */
function find_available_feed_id()
{
    while (true) {
        $key = generate_key(50);
        $query = '
SELECT COUNT(*)
  FROM ' . USER_FEED_TABLE . '
  WHERE id = \'' . $key . '\'
;';
        list($count) = pwg_db_fetch_row(pwg_query($query));
        if (0 == $count) {
            return $key;
        }
    }
}
function get_oauth_id($user_id)
{
    $query = '
SELECT oauth_id FROM ' . USER_INFOS_TABLE . '
  WHERE user_id = ' . $user_id . '
  AND oauth_id != ""
;';
    $result = pwg_query($query);
    if (!pwg_db_num_rows($result)) {
        return null;
    } else {
        list($oauth_id) = pwg_db_fetch_row($result);
        return $oauth_id;
    }
}
Пример #22
0
function ws_extref_categories_set($params, &$service)
{
    // does the category really exist?
    $query = '
SELECT COUNT(*)
  FROM ' . CATEGORIES_TABLE . '
  WHERE id = ' . $params['category_id'] . '
;';
    list($count) = pwg_db_fetch_row(pwg_query($query));
    if ($count == 0) {
        return new PwgError(404, 'category_id not found');
    }
    single_update(CATEGORIES_TABLE, array('external_reference' => $params['external_reference']), array('id' => $params['category_id']));
    return true;
}
Пример #23
0
/**
 * list all columns of each given table
 *
 * @return array of array
 */
function get_columns_of($tables)
{
    $columns_of = array();
    foreach ($tables as $table) {
        $query = '
DESC ' . $table . '
;';
        $result = pwg_query($query);
        $columns_of[$table] = array();
        while ($row = pwg_db_fetch_row($result)) {
            $columns_of[$table][] = $row[0];
        }
    }
    return $columns_of;
}
Пример #24
0
function NBMS_Load_Profile()
{
    global $conf, $user, $template, $lang;
    $query = '
  SELECT enabled
    FROM ' . USER_MAIL_NOTIFICATION_TABLE . '
    WHERE user_id = \'' . $user['id'] . '\'
  ;';
    $data = pwg_db_fetch_assoc(pwg_query($query));
    $values = $data['enabled'];
    if (is_null($values)) {
        $values = 'false';
    }
    $template->assign('radio_options', array('true' => l10n('Yes'), 'false' => l10n('No')));
    $template->assign(array('NBMS' => $values));
    $template->set_prefilter('profile_content', 'NBMS_prefilter');
}
function upgrade_211()
{
    global $conf;
    // Create new HIPE entry in plugins table
    $query = '
INSERT INTO ' . PLUGINS_TABLE . ' (id, state, version)
VALUES ("HistoryIPExcluder","active","2.2.0")
;';
    pwg_query($query);
    // Delete old plugin entry in plugins table
    $query = '
DELETE FROM ' . PLUGINS_TABLE . '
WHERE id="nbc_HistoryIPExcluder"
LIMIT 1
;';
    pwg_query($query);
    // rename directory
    if (!rename(PHPWG_PLUGINS_PATH . 'nbc_HistoryIPExcluder', PHPWG_PLUGINS_PATH . 'HistoryIPExcluder')) {
        die('Fatal error on plugin upgrade process : Unable to rename directory ! Please, rename manualy the plugin directory name from ../plugins/nbc_HistoryIPExcluder to ../plugins/HistoryIPExcluder.');
    }
}
Пример #26
0
 function install($plugin_version, &$errors = array())
 {
     global $conf;
     // configuration
     if (!isset($conf['cdnplus_conf']) || empty($conf['cdnplus_conf'])) {
         $this->default_config['last_clean'] = time();
         /* Generate file_ext from current ext supported */
         $filetypes_arr = array_fill_keys(array_intersect_key($conf['file_ext'], array_unique(array_map('strtolower', $conf['file_ext']))), false);
         $this->default_config['cdn_1']['filetypes'] = $filetypes_arr;
         $this->default_config['cdn_2']['filetypes'] = $filetypes_arr;
         $this->default_config['cdn_3']['filetypes'] = $filetypes_arr;
         $this->default_config['cdn_4']['filetypes'] = $filetypes_arr;
         $this->default_config['cdn_5']['filetypes'] = $filetypes_arr;
         conf_update_param('cdnplus_conf', $this->default_config, true);
         $q = 'UPDATE ' . CONFIG_TABLE . ' SET `comment` = "Configuration settings for piwigo-cdnplus plugin" WHERE `param` = "cdnplus_conf";';
         pwg_query($q);
     } else {
         $new_conf = safe_unserialize($conf['cdnplus_conf']);
         conf_update_param('cdnplus_conf', $new_conf, true);
     }
 }
/**
 * interrupt normal login if corresponding to an oauth user
 */
function oauth_try_log_user($success, $username)
{
    global $conf, $redirect_to;
    $query = '
SELECT oauth_id
  FROM ' . USER_INFOS_TABLE . ' AS i
    INNER JOIN ' . USERS_TABLE . ' AS u
    ON i.user_id = u.' . $conf['user_fields']['id'] . '
  WHERE ' . $conf['user_fields']['username'] . ' = "' . pwg_db_real_escape_string($username) . '"
  AND oauth_id != ""
;';
    $result = pwg_query($query);
    if (pwg_db_num_rows($result)) {
        list($oauth_id) = pwg_db_fetch_row($result);
        list($provider) = explode('---', $oauth_id, 2);
        $_SESSION['page_errors'][] = l10n('You registered with a %s account, please sign in with the same account.', $provider);
        $redirect_to = get_root_url() . 'identification.php';
        // variable used by identification.php
        return true;
    }
    return false;
}
function language_controler_switch()
{
    global $user;
    $same = $user['language'];
    if (isset($_GET['lang'])) {
        include_once PHPWG_ROOT_PATH . 'admin/include/languages.class.php';
        $languages = new languages();
        if (!in_array($_GET['lang'], array_keys($languages->fs_languages))) {
            $_GET['lang'] = PHPWG_DEFAULT_LANGUAGE;
        }
        if (!empty($_GET['lang']) and file_exists(PHPWG_ROOT_PATH . 'language/' . $_GET['lang'] . '/common.lang.php')) {
            if (is_a_guest() or is_generic()) {
                pwg_set_session_var('lang_switch', $_GET['lang']);
            } else {
                $query = '
UPDATE ' . USER_INFOS_TABLE . '
  SET language = \'' . $_GET['lang'] . '\'
  WHERE user_id = ' . $user['id'] . '
;';
                pwg_query($query);
            }
            $user['language'] = $_GET['lang'];
        }
    } elseif (is_a_guest() or is_generic()) {
        $user['language'] = pwg_get_session_var('lang_switch', $user['language']);
    }
    // Reload language only if it isn't the same one
    if ($same !== $user['language']) {
        load_language('common.lang', '', array('language' => $user['language']));
        load_language('lang', PHPWG_ROOT_PATH . PWG_LOCAL_DIR, array('language' => $user['language'], 'no_fallback' => true, 'local' => true));
        if (defined('IN_ADMIN') and IN_ADMIN) {
            // Never currently
            load_language('admin.lang', '', array('language' => $user['language']));
        }
    }
}
Пример #29
0
function pfemail_admin_menu($menu)
{
    global $page;
    $query = '
SELECT
    COUNT(*)
  FROM ' . PFEMAIL_PENDINGS_TABLE . '
    JOIN ' . IMAGES_TABLE . ' ON image_id = id
  WHERE state = \'moderation_pending\'
;';
    $result = pwg_query($query);
    list($page['pfemail_nb_pendings']) = pwg_db_fetch_row($result);
    $name = 'Photo from Email';
    if ($page['pfemail_nb_pendings'] > 0) {
        $style = 'background-color:#666;';
        $style .= 'color:white;';
        $style .= 'padding:1px 5px;';
        $style .= 'border-radius:10px;';
        $style .= 'margin-left:5px;';
        $name .= '<span style="' . $style . '">' . $page['pfemail_nb_pendings'] . '</span>';
    }
    array_push($menu, array('NAME' => $name, 'URL' => get_root_url() . 'admin.php?page=plugin-photo_from_email'));
    return $menu;
}
Пример #30
0
// +-----------------------------------------------------------------------+
// | This program is free software; you can redistribute it and/or modify  |
// | it under the terms of the GNU General Public License as published by  |
// | the Free Software Foundation                                          |
// |                                                                       |
// | This program is distributed in the hope that it will be useful, but   |
// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
// | General Public License for more details.                              |
// |                                                                       |
// | You should have received a copy of the GNU General Public License     |
// | along with this program; if not, write to the Free Software           |
// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
// | USA.                                                                  |
// +-----------------------------------------------------------------------+
if (!defined("PHPWG_ROOT_PATH")) {
    die('Hacking attempt!');
}
$upgrade_description = 'Add display configuration for picture properties.';
$query = '
INSERT INTO ' . CONFIG_TABLE . ' (param,value,comment)
  VALUES
    ("picture_download_icon","true","Display download icon on picture page"),
    (
      "picture_informations", 
      "a:11:{s:6:\\"author\\";b:1;s:10:\\"created_on\\";b:1;s:9:\\"posted_on\\";b:1;s:10:\\"dimensions\\";b:1;s:4:\\"file\\";b:1;s:8:\\"filesize\\";b:1;s:4:\\"tags\\";b:1;s:10:\\"categories\\";b:1;s:6:\\"visits\\";b:1;s:12:\\"average_rate\\";b:1;s:13:\\"privacy_level\\";b:1;}",
      "Information displayed on picture page"
    )
;';
pwg_query($query);
echo "\n" . $upgrade_description . "\n";