Esempio n. 1
0
function xsl_transform_feed($feedUrl, $xslPath)
{
    $doc = new DOMDocument();
    $xsl = new XSLTProcessor();
    $doc->load(parse_path($xslPath));
    $xsl->importStyleSheet($doc);
    $doc->loadXML(file_get_contents(parse_path($feedUrl)));
    $xsl->registerPHPFunctions(array('xsl_counter'));
    return $xsl->transformToXML($doc);
}
Esempio n. 2
0
function parse_path($dir)
{
    $css_files = array();
    // Retrieving files
    $files = glob($dir . '*', GLOB_MARK);
    // Ordering by name
    asort($files);
    foreach ($files as $file) {
        // Searching for files inside a folder
        if (is_dir($file)) {
            $css_files = array_merge(parse_path($file), $css_files);
        } elseif (substr($file, -3, 3) == 'css') {
            $css_files[] = $file;
        }
    }
    return $css_files;
}
<?php

function parse_path()
{
    $path = array();
    if (isset($_SERVER['REQUEST_URI'])) {
        $request_path = explode('?', $_SERVER['REQUEST_URI']);
        $path['base'] = rtrim(dirname($_SERVER['SCRIPT_NAME']), '\\/');
        $path['call_utf8'] = substr(urldecode($request_path[0]), strlen($path['base']) + 1);
        $path['call'] = utf8_decode($path['call_utf8']);
        if ($path['call'] == basename($_SERVER['PHP_SELF'])) {
            $path['call'] = '';
        }
        $path['call_parts'] = explode('/', $path['call']);
    }
    return $path;
}
$path_info = parse_path();
Esempio n. 4
0
define('PUBLIC_ENDPOINT', false);
// Can anyone can access this endpoint
# Including our configuration
require_once __DIR__ . '/_includes/config.php';
require_once __DIR__ . '/_includes/validate-app.php';
# Our return class
$content = new stdClass();
$content->success = true;
$content->env = PostParser::create_attribute($G_APP_ENVIRONMENT);
$content->error_message = [];
$content->replaced = [];
$content->path = [];
$content->url = [];
$content->version = [];
# Our target directory
$G_PATH_DATA = parse_path($_CGET['dir'], $_ENDPOINT, $G_TOKEN_SESSION_DATA);
$G_DIRECTORY_DATA = directory_hierarchy($G_STORAGE_CONTROLLER_DBLINK, $G_APP_DATA['id'], $G_APP_ENVIRONMENT, $G_PATH_DATA->absolute, $G_APP_DATA['file_auto_makedir'] == 1);
# Getting our server where we are going to store the files
$query = "\tSELECT\n\t\t\t\t*\n\t\t\tFROM\n\t\t\t\t" . NQ_SERVERS_TABLE . "\n\t\t\tWHERE\n\t\t\t\t`server_type`\t='file' AND\n\t\t\t\t`environment`\t='" . mysqli_escape_string($G_CONTROLLER_DBLINK, $G_APP_ENVIRONMENT) . "'\n\t\t\tORDER BY\n\t\t\t\t`tier` ASC,\n\t\t\t\t`available_space` DESC\n\t\t\tLIMIT 1";
$G_SERVER_DATA = mysqli_single_result_query($G_CONTROLLER_DBLINK, $query);
# Combining our host properties into our path
$G_SERVER_HOST = NQ_FILE_STORAGE_PROTOCOL . $G_SERVER_DATA['username'] . NQ_FILE_STORAGE_CRED_SEPARATOR . $G_SERVER_DATA['password'] . NQ_FILE_STORAGE_HOST_SEPARATOR . $G_SERVER_DATA['host'] . $G_SERVER_DATA['path'];
# Tracking filesize changes
$G_FILESIZE_ADDED = 0;
# Looping through our files
foreach ($_FILES as $file) {
    # Our names and tmp_name files
    $names = array();
    $tmp_names = array();
    $file_types = array();
    # If we have an array or we don't we need to make it an array
Esempio n. 5
0
 /**
  * Test install a package.
  */
 public function action_install()
 {
     global $txt, $context, $scripturl, $settings;
     // You have to specify a file!!
     if (!isset($_REQUEST['package']) || trim($_REQUEST['package']) == '') {
         redirectexit('action=admin;area=packages');
     }
     $context['filename'] = preg_replace('~[\\.]+~', '.', $_REQUEST['package']);
     // Do we have an existing id, for uninstalls and the like.
     $context['install_id'] = isset($_REQUEST['pid']) ? (int) $_REQUEST['pid'] : 0;
     // These will be needed
     require_once SUBSDIR . '/Package.subs.php';
     require_once SUBSDIR . '/Themes.subs.php';
     // Load up the package FTP information?
     create_chmod_control();
     // Make sure temp directory exists and is empty.
     if (file_exists(BOARDDIR . '/packages/temp')) {
         deltree(BOARDDIR . '/packages/temp', false);
     }
     // Attempt to create the temp directory
     if (!mktree(BOARDDIR . '/packages/temp', 0755)) {
         deltree(BOARDDIR . '/packages/temp', false);
         if (!mktree(BOARDDIR . '/packages/temp', 0777)) {
             deltree(BOARDDIR . '/packages/temp', false);
             create_chmod_control(array(BOARDDIR . '/packages/temp/delme.tmp'), array('destination_url' => $scripturl . '?action=admin;area=packages;sa=' . $_REQUEST['sa'] . ';package=' . $context['filename'], 'crash_on_error' => true));
             deltree(BOARDDIR . '/packages/temp', false);
             if (!mktree(BOARDDIR . '/packages/temp', 0777)) {
                 fatal_lang_error('package_cant_download', false);
             }
         }
     }
     // Change our last link tree item for more information on this Packages area.
     $context['uninstalling'] = $_REQUEST['sa'] === 'uninstall';
     $context['linktree'][count($context['linktree']) - 1] = array('url' => $scripturl . '?action=admin;area=packages;sa=browse', 'name' => $context['uninstalling'] ? $txt['package_uninstall_actions'] : $txt['install_actions']);
     $context['page_title'] .= ' - ' . ($context['uninstalling'] ? $txt['package_uninstall_actions'] : $txt['install_actions']);
     $context['sub_template'] = 'view_package';
     if (!file_exists(BOARDDIR . '/packages/' . $context['filename'])) {
         deltree(BOARDDIR . '/packages/temp');
         fatal_lang_error('package_no_file', false);
     }
     // Extract the files so we can get things like the readme, etc.
     if (is_file(BOARDDIR . '/packages/' . $context['filename'])) {
         $context['extracted_files'] = read_tgz_file(BOARDDIR . '/packages/' . $context['filename'], BOARDDIR . '/packages/temp');
         if ($context['extracted_files'] && !file_exists(BOARDDIR . '/packages/temp/package-info.xml')) {
             foreach ($context['extracted_files'] as $file) {
                 if (basename($file['filename']) == 'package-info.xml') {
                     $context['base_path'] = dirname($file['filename']) . '/';
                     break;
                 }
             }
         }
         if (!isset($context['base_path'])) {
             $context['base_path'] = '';
         }
     } elseif (is_dir(BOARDDIR . '/packages/' . $context['filename'])) {
         copytree(BOARDDIR . '/packages/' . $context['filename'], BOARDDIR . '/packages/temp');
         $context['extracted_files'] = listtree(BOARDDIR . '/packages/temp');
         $context['base_path'] = '';
     } else {
         fatal_lang_error('no_access', false);
     }
     // Load up any custom themes we may want to install into...
     $theme_paths = getThemesPathbyID();
     // Get the package info...
     $packageInfo = getPackageInfo($context['filename']);
     if (!is_array($packageInfo)) {
         fatal_lang_error($packageInfo);
     }
     $packageInfo['filename'] = $context['filename'];
     $context['package_name'] = isset($packageInfo['name']) ? $packageInfo['name'] : $context['filename'];
     // Set the type of extraction...
     $context['extract_type'] = isset($packageInfo['type']) ? $packageInfo['type'] : 'modification';
     // The mod isn't installed.... unless proven otherwise.
     $context['is_installed'] = false;
     // See if it is installed?
     $package_installed = isPackageInstalled($packageInfo['id']);
     $context['database_changes'] = array();
     if (isset($packageInfo['uninstall']['database'])) {
         $context['database_changes'][] = $txt['execute_database_changes'] . ' - ' . $packageInfo['uninstall']['database'];
     } elseif (!empty($package_installed['db_changes'])) {
         foreach ($package_installed['db_changes'] as $change) {
             if (isset($change[2]) && isset($txt['package_db_' . $change[0]])) {
                 $context['database_changes'][] = sprintf($txt['package_db_' . $change[0]], $change[1], $change[2]);
             } elseif (isset($txt['package_db_' . $change[0]])) {
                 $context['database_changes'][] = sprintf($txt['package_db_' . $change[0]], $change[1]);
             } else {
                 $context['database_changes'][] = $change[0] . '-' . $change[1] . (isset($change[2]) ? '-' . $change[2] : '');
             }
         }
     }
     // Uninstalling?
     if ($context['uninstalling']) {
         // Wait, it's not installed yet!
         if (!isset($package_installed['old_version']) && $context['uninstalling']) {
             deltree(BOARDDIR . '/packages/temp');
             fatal_lang_error('package_cant_uninstall', false);
         }
         $actions = parsePackageInfo($packageInfo['xml'], true, 'uninstall');
         // Gadzooks!  There's no uninstaller at all!?
         if (empty($actions)) {
             deltree(BOARDDIR . '/packages/temp');
             fatal_lang_error('package_uninstall_cannot', false);
         }
         // Can't edit the custom themes it's edited if you're unisntalling, they must be removed.
         $context['themes_locked'] = true;
         // Only let them uninstall themes it was installed into.
         foreach ($theme_paths as $id => $data) {
             if ($id != 1 && !in_array($id, $package_installed['old_themes'])) {
                 unset($theme_paths[$id]);
             }
         }
     } elseif (isset($package_installed['old_version']) && $package_installed['old_version'] != $packageInfo['version']) {
         // Look for an upgrade...
         $actions = parsePackageInfo($packageInfo['xml'], true, 'upgrade', $package_installed['old_version']);
         // There was no upgrade....
         if (empty($actions)) {
             $context['is_installed'] = true;
         } else {
             // Otherwise they can only upgrade themes from the first time around.
             foreach ($theme_paths as $id => $data) {
                 if ($id != 1 && !in_array($id, $package_installed['old_themes'])) {
                     unset($theme_paths[$id]);
                 }
             }
         }
     } elseif (isset($package_installed['old_version']) && $package_installed['old_version'] == $packageInfo['version']) {
         $context['is_installed'] = true;
     }
     if (!isset($package_installed['old_version']) || $context['is_installed']) {
         $actions = parsePackageInfo($packageInfo['xml'], true, 'install');
     }
     $context['actions'] = array();
     $context['ftp_needed'] = false;
     $context['has_failure'] = false;
     $chmod_files = array();
     // No actions found, return so we can display an error
     if (empty($actions)) {
         return;
     }
     // This will hold data about anything that can be installed in other themes.
     $themeFinds = array('candidates' => array(), 'other_themes' => array());
     // Now prepare things for the template.
     foreach ($actions as $action) {
         // Not failed until proven otherwise.
         $failed = false;
         $thisAction = array();
         if ($action['type'] == 'chmod') {
             $chmod_files[] = $action['filename'];
             continue;
         } elseif ($action['type'] == 'readme' || $action['type'] == 'license') {
             $type = 'package_' . $action['type'];
             if (file_exists(BOARDDIR . '/packages/temp/' . $context['base_path'] . $action['filename'])) {
                 $context[$type] = htmlspecialchars(trim(file_get_contents(BOARDDIR . '/packages/temp/' . $context['base_path'] . $action['filename']), "\n\r"), ENT_COMPAT, 'UTF-8');
             } elseif (file_exists($action['filename'])) {
                 $context[$type] = htmlspecialchars(trim(file_get_contents($action['filename']), "\n\r"), ENT_COMPAT, 'UTF-8');
             }
             if (!empty($action['parse_bbc'])) {
                 require_once SUBSDIR . '/Post.subs.php';
                 preparsecode($context[$type]);
                 $context[$type] = parse_bbc($context[$type]);
             } else {
                 $context[$type] = nl2br($context[$type]);
             }
             continue;
         } elseif ($action['type'] == 'redirect') {
             continue;
         } elseif ($action['type'] == 'error') {
             $context['has_failure'] = true;
             if (isset($action['error_msg']) && isset($action['error_var'])) {
                 $context['failure_details'] = sprintf($txt['package_will_fail_' . $action['error_msg']], $action['error_var']);
             } elseif (isset($action['error_msg'])) {
                 $context['failure_details'] = isset($txt['package_will_fail_' . $action['error_msg']]) ? $txt['package_will_fail_' . $action['error_msg']] : $action['error_msg'];
             }
         } elseif ($action['type'] == 'modification') {
             if (!file_exists(BOARDDIR . '/packages/temp/' . $context['base_path'] . $action['filename'])) {
                 $context['has_failure'] = true;
                 $context['actions'][] = array('type' => $txt['execute_modification'], 'action' => Util::htmlspecialchars(strtr($action['filename'], array(BOARDDIR => '.'))), 'description' => $txt['package_action_error'], 'failed' => true);
             } else {
                 if ($action['boardmod']) {
                     $mod_actions = parseBoardMod(@file_get_contents(BOARDDIR . '/packages/temp/' . $context['base_path'] . $action['filename']), true, $action['reverse'], $theme_paths);
                 } else {
                     $mod_actions = parseModification(@file_get_contents(BOARDDIR . '/packages/temp/' . $context['base_path'] . $action['filename']), true, $action['reverse'], $theme_paths);
                 }
                 if (count($mod_actions) == 1 && isset($mod_actions[0]) && $mod_actions[0]['type'] == 'error' && $mod_actions[0]['filename'] == '-') {
                     $mod_actions[0]['filename'] = $action['filename'];
                 }
                 foreach ($mod_actions as $key => $mod_action) {
                     // Lets get the last section of the file name.
                     if (isset($mod_action['filename']) && substr($mod_action['filename'], -13) != '.template.php') {
                         $actual_filename = strtolower(substr(strrchr($mod_action['filename'], '/'), 1) . '||' . $action['filename']);
                     } elseif (isset($mod_action['filename']) && preg_match('~([\\w]*)/([\\w]*)\\.template\\.php$~', $mod_action['filename'], $matches)) {
                         $actual_filename = strtolower($matches[1] . '/' . $matches[2] . '.template.php||' . $action['filename']);
                     } else {
                         $actual_filename = $key;
                     }
                     if ($mod_action['type'] == 'opened') {
                         $failed = false;
                     } elseif ($mod_action['type'] == 'failure') {
                         if (empty($mod_action['is_custom'])) {
                             $context['has_failure'] = true;
                         }
                         $failed = true;
                     } elseif ($mod_action['type'] == 'chmod') {
                         $chmod_files[] = $mod_action['filename'];
                     } elseif ($mod_action['type'] == 'saved') {
                         if (!empty($mod_action['is_custom'])) {
                             if (!isset($context['theme_actions'][$mod_action['is_custom']])) {
                                 $context['theme_actions'][$mod_action['is_custom']] = array('name' => $theme_paths[$mod_action['is_custom']]['name'], 'actions' => array(), 'has_failure' => $failed);
                             } else {
                                 $context['theme_actions'][$mod_action['is_custom']]['has_failure'] |= $failed;
                             }
                             $context['theme_actions'][$mod_action['is_custom']]['actions'][$actual_filename] = array('type' => $txt['execute_modification'], 'action' => Util::htmlspecialchars(strtr($mod_action['filename'], array(BOARDDIR => '.'))), 'description' => $failed ? $txt['package_action_failure'] : $txt['package_action_success'], 'failed' => $failed);
                         } elseif (!isset($context['actions'][$actual_filename])) {
                             $context['actions'][$actual_filename] = array('type' => $txt['execute_modification'], 'action' => Util::htmlspecialchars(strtr($mod_action['filename'], array(BOARDDIR => '.'))), 'description' => $failed ? $txt['package_action_failure'] : $txt['package_action_success'], 'failed' => $failed);
                         } else {
                             $context['actions'][$actual_filename]['failed'] |= $failed;
                             $context['actions'][$actual_filename]['description'] = $context['actions'][$actual_filename]['failed'] ? $txt['package_action_failure'] : $txt['package_action_success'];
                         }
                     } elseif ($mod_action['type'] == 'skipping') {
                         $context['actions'][$actual_filename] = array('type' => $txt['execute_modification'], 'action' => Util::htmlspecialchars(strtr($mod_action['filename'], array(BOARDDIR => '.'))), 'description' => $txt['package_action_skipping']);
                     } elseif ($mod_action['type'] == 'missing' && empty($mod_action['is_custom'])) {
                         $context['has_failure'] = true;
                         $context['actions'][$actual_filename] = array('type' => $txt['execute_modification'], 'action' => Util::htmlspecialchars(strtr($mod_action['filename'], array(BOARDDIR => '.'))), 'description' => $txt['package_action_missing'], 'failed' => true);
                     } elseif ($mod_action['type'] == 'error') {
                         $context['actions'][$actual_filename] = array('type' => $txt['execute_modification'], 'action' => Util::htmlspecialchars(strtr($mod_action['filename'], array(BOARDDIR => '.'))), 'description' => $txt['package_action_error'], 'failed' => true);
                     }
                 }
                 // We need to loop again just to get the operations down correctly.
                 foreach ($mod_actions as $operation_key => $mod_action) {
                     // Lets get the last section of the file name.
                     if (isset($mod_action['filename']) && substr($mod_action['filename'], -13) != '.template.php') {
                         $actual_filename = strtolower(substr(strrchr($mod_action['filename'], '/'), 1) . '||' . $action['filename']);
                     } elseif (isset($mod_action['filename']) && preg_match('~([\\w]*)/([\\w]*)\\.template\\.php$~', $mod_action['filename'], $matches)) {
                         $actual_filename = strtolower($matches[1] . '/' . $matches[2] . '.template.php||' . $action['filename']);
                     } else {
                         $actual_filename = $operation_key;
                     }
                     // We just need it for actual parse changes.
                     if (!in_array($mod_action['type'], array('error', 'result', 'opened', 'saved', 'end', 'missing', 'skipping', 'chmod'))) {
                         if (empty($mod_action['is_custom'])) {
                             $context['actions'][$actual_filename]['operations'][] = array('type' => $txt['execute_modification'], 'action' => Util::htmlspecialchars(strtr($mod_action['filename'], array(BOARDDIR => '.'))), 'description' => $mod_action['failed'] ? $txt['package_action_failure'] : $txt['package_action_success'], 'position' => $mod_action['position'], 'operation_key' => $operation_key, 'filename' => $action['filename'], 'is_boardmod' => $action['boardmod'], 'failed' => $mod_action['failed'], 'ignore_failure' => !empty($mod_action['ignore_failure']));
                         }
                         // Themes are under the saved type.
                         if (isset($mod_action['is_custom']) && isset($context['theme_actions'][$mod_action['is_custom']])) {
                             $context['theme_actions'][$mod_action['is_custom']]['actions'][$actual_filename]['operations'][] = array('type' => $txt['execute_modification'], 'action' => Util::htmlspecialchars(strtr($mod_action['filename'], array(BOARDDIR => '.'))), 'description' => $mod_action['failed'] ? $txt['package_action_failure'] : $txt['package_action_success'], 'position' => $mod_action['position'], 'operation_key' => $operation_key, 'filename' => $action['filename'], 'is_boardmod' => $action['boardmod'], 'failed' => $mod_action['failed'], 'ignore_failure' => !empty($mod_action['ignore_failure']));
                         }
                     }
                 }
             }
         } elseif ($action['type'] == 'code') {
             $thisAction = array('type' => $txt['execute_code'], 'action' => Util::htmlspecialchars($action['filename']));
         } elseif ($action['type'] == 'database') {
             $thisAction = array('type' => $txt['execute_database_changes'], 'action' => Util::htmlspecialchars($action['filename']));
         } elseif (in_array($action['type'], array('create-dir', 'create-file'))) {
             $thisAction = array('type' => $txt['package_create'] . ' ' . ($action['type'] == 'create-dir' ? $txt['package_tree'] : $txt['package_file']), 'action' => Util::htmlspecialchars(strtr($action['destination'], array(BOARDDIR => '.'))));
         } elseif ($action['type'] == 'hook') {
             $action['description'] = !isset($action['hook'], $action['function']) ? $txt['package_action_failure'] : $txt['package_action_success'];
             if (!isset($action['hook'], $action['function'])) {
                 $context['has_failure'] = true;
             }
             $thisAction = array('type' => $action['reverse'] ? $txt['execute_hook_remove'] : $txt['execute_hook_add'], 'action' => sprintf($txt['execute_hook_action'], Util::htmlspecialchars($action['hook'])));
         } elseif ($action['type'] == 'credits') {
             $thisAction = array('type' => $txt['execute_credits_add'], 'action' => sprintf($txt['execute_credits_action'], Util::htmlspecialchars($action['title'])));
         } elseif ($action['type'] == 'requires') {
             $installed_version = false;
             $version_check = true;
             // Package missing required values?
             if (!isset($action['id'])) {
                 $context['has_failure'] = true;
             } else {
                 // See if this dependency is installed
                 $installed_version = checkPackageDependency($action['id']);
                 // Do a version level check (if requested) in the most basic way
                 $version_check = isset($action['version']) ? $installed_version == $action['version'] : true;
             }
             // Set success or failure information
             $action['description'] = $installed_version && $version_check ? $txt['package_action_success'] : $txt['package_action_failure'];
             $context['has_failure'] = !($installed_version && $version_check);
             $thisAction = array('type' => $txt['package_requires'], 'action' => $txt['package_check_for'] . ' ' . $action['id'] . (isset($action['version']) ? ' / ' . ($version_check ? $action['version'] : '<span class="error">' . $action['version'] . '</span>') : ''));
         } elseif (in_array($action['type'], array('require-dir', 'require-file'))) {
             // Do this one...
             $thisAction = array('type' => $txt['package_extract'] . ' ' . ($action['type'] == 'require-dir' ? $txt['package_tree'] : $txt['package_file']), 'action' => Util::htmlspecialchars(strtr($action['destination'], array(BOARDDIR => '.'))));
             // Could this be theme related?
             if (!empty($action['unparsed_destination']) && preg_match('~^\\$(languagedir|languages_dir|imagesdir|themedir|themes_dir)~i', $action['unparsed_destination'], $matches)) {
                 // Is the action already stated?
                 $theme_action = !empty($action['theme_action']) && in_array($action['theme_action'], array('no', 'yes', 'auto')) ? $action['theme_action'] : 'auto';
                 // If it's not auto do we think we have something we can act upon?
                 if ($theme_action != 'auto' && !in_array($matches[1], array('languagedir', 'languages_dir', 'imagesdir', 'themedir'))) {
                     $theme_action = '';
                 } elseif ($theme_action == 'auto' && $matches[1] != 'imagesdir') {
                     $theme_action = '';
                 }
                 // So, we still want to do something?
                 if ($theme_action != '') {
                     $themeFinds['candidates'][] = $action;
                 } elseif ($matches[1] == 'themes_dir') {
                     $themeFinds['other_themes'][] = strtolower(strtr(parse_path($action['unparsed_destination']), array('\\' => '/')) . '/' . basename($action['filename']));
                 }
             }
         } elseif (in_array($action['type'], array('move-dir', 'move-file'))) {
             $thisAction = array('type' => $txt['package_move'] . ' ' . ($action['type'] == 'move-dir' ? $txt['package_tree'] : $txt['package_file']), 'action' => Util::htmlspecialchars(strtr($action['source'], array(BOARDDIR => '.'))) . ' => ' . Util::htmlspecialchars(strtr($action['destination'], array(BOARDDIR => '.'))));
         } elseif (in_array($action['type'], array('remove-dir', 'remove-file'))) {
             $thisAction = array('type' => $txt['package_delete'] . ' ' . ($action['type'] == 'remove-dir' ? $txt['package_tree'] : $txt['package_file']), 'action' => Util::htmlspecialchars(strtr($action['filename'], array(BOARDDIR => '.'))));
             // Could this be theme related?
             if (!empty($action['unparsed_filename']) && preg_match('~^\\$(languagedir|languages_dir|imagesdir|themedir|themes_dir)~i', $action['unparsed_filename'], $matches)) {
                 // Is the action already stated?
                 $theme_action = !empty($action['theme_action']) && in_array($action['theme_action'], array('no', 'yes', 'auto')) ? $action['theme_action'] : 'auto';
                 $action['unparsed_destination'] = $action['unparsed_filename'];
                 // If it's not auto do we think we have something we can act upon?
                 if ($theme_action != 'auto' && !in_array($matches[1], array('languagedir', 'languages_dir', 'imagesdir', 'themedir'))) {
                     $theme_action = '';
                 } elseif ($theme_action == 'auto' && $matches[1] != 'imagesdir') {
                     $theme_action = '';
                 }
                 // So, we still want to do something?
                 if ($theme_action != '') {
                     $themeFinds['candidates'][] = $action;
                 } elseif ($matches[1] == 'themes_dir') {
                     $themeFinds['other_themes'][] = strtolower(strtr(parse_path($action['unparsed_filename']), array('\\' => '/')) . '/' . basename($action['filename']));
                 }
             }
         }
         if (empty($thisAction)) {
             continue;
         }
         if (isset($action['filename'])) {
             if ($context['uninstalling']) {
                 $file = in_array($action['type'], array('remove-dir', 'remove-file')) ? $action['filename'] : BOARDDIR . '/packages/temp/' . $context['base_path'] . $action['filename'];
             } else {
                 $file = BOARDDIR . '/packages/temp/' . $context['base_path'] . $action['filename'];
             }
             if (!file_exists($file)) {
                 $context['has_failure'] = true;
                 $thisAction += array('description' => $txt['package_action_error'], 'failed' => true);
             }
         }
         // @todo None given?
         if (empty($thisAction['description'])) {
             $thisAction['description'] = isset($action['description']) ? $action['description'] : '';
         }
         $context['actions'][] = $thisAction;
     }
     // Have we got some things which we might want to do "multi-theme"?
     if (!empty($themeFinds['candidates'])) {
         foreach ($themeFinds['candidates'] as $action_data) {
             // Get the part of the file we'll be dealing with.
             preg_match('~^\\$(languagedir|languages_dir|imagesdir|themedir)(\\|/)*(.+)*~i', $action_data['unparsed_destination'], $matches);
             if ($matches[1] == 'imagesdir') {
                 $path = '/' . basename($settings['default_images_url']);
             } elseif ($matches[1] == 'languagedir' || $matches[1] == 'languages_dir') {
                 $path = '/languages';
             } else {
                 $path = '';
             }
             if (!empty($matches[3])) {
                 $path .= $matches[3];
             }
             if (!$context['uninstalling']) {
                 $path .= '/' . basename($action_data['filename']);
             }
             // Loop through each custom theme to note it's candidacy!
             foreach ($theme_paths as $id => $theme_data) {
                 if (isset($theme_data['theme_dir']) && $id != 1) {
                     $real_path = $theme_data['theme_dir'] . $path;
                     // Confirm that we don't already have this dealt with by another entry.
                     if (!in_array(strtolower(strtr($real_path, array('\\' => '/'))), $themeFinds['other_themes'])) {
                         // Check if we will need to chmod this.
                         if (!mktree(dirname($real_path), false)) {
                             $temp = dirname($real_path);
                             while (!file_exists($temp) && strlen($temp) > 1) {
                                 $temp = dirname($temp);
                             }
                             $chmod_files[] = $temp;
                         }
                         if ($action_data['type'] == 'require-dir' && !is_writable($real_path) && (file_exists($real_path) || !is_writable(dirname($real_path)))) {
                             $chmod_files[] = $real_path;
                         }
                         if (!isset($context['theme_actions'][$id])) {
                             $context['theme_actions'][$id] = array('name' => $theme_data['name'], 'actions' => array());
                         }
                         if ($context['uninstalling']) {
                             $context['theme_actions'][$id]['actions'][] = array('type' => $txt['package_delete'] . ' ' . ($action_data['type'] == 'require-dir' ? $txt['package_tree'] : $txt['package_file']), 'action' => strtr($real_path, array('\\' => '/', BOARDDIR => '.')), 'description' => '', 'value' => base64_encode(serialize(array('type' => $action_data['type'], 'orig' => $action_data['filename'], 'future' => $real_path, 'id' => $id))), 'not_mod' => true);
                         } else {
                             $context['theme_actions'][$id]['actions'][] = array('type' => $txt['package_extract'] . ' ' . ($action_data['type'] == 'require-dir' ? $txt['package_tree'] : $txt['package_file']), 'action' => strtr($real_path, array('\\' => '/', BOARDDIR => '.')), 'description' => '', 'value' => base64_encode(serialize(array('type' => $action_data['type'], 'orig' => $action_data['destination'], 'future' => $real_path, 'id' => $id))), 'not_mod' => true);
                         }
                     }
                 }
             }
         }
     }
     // Trash the cache... which will also check permissions for us!
     package_flush_cache(true);
     if (file_exists(BOARDDIR . '/packages/temp')) {
         deltree(BOARDDIR . '/packages/temp');
     }
     if (!empty($chmod_files)) {
         $ftp_status = create_chmod_control($chmod_files);
         $context['ftp_needed'] = !empty($ftp_status['files']['notwritable']) && !empty($context['package_ftp']);
     }
     $context['post_url'] = $scripturl . '?action=admin;area=packages;sa=' . ($context['uninstalling'] ? 'uninstall' : 'install') . ($context['ftp_needed'] ? '' : '2') . ';package=' . $context['filename'] . ';pid=' . $context['install_id'];
     checkSubmitOnce('register');
 }
Esempio n. 6
0
# Setting our constants
define('CACHEABLE', false);
// Can this page be cached on the users browser
define('PUBLIC_ENDPOINT', false);
// Can anyone can access this endpoint
define('INCLUDE_IMAGE_CLASS', false);
// Are you going to be using the image class
# Including our configuration
require_once __DIR__ . '/_includes/config.php';
require_once __DIR__ . '/_includes/validate-app.php';
# Handling our global json parsing
$_JPOST = PostParser::decode();
# Our return class
$content = new stdClass();
# Creating our directory
$G_PATH_DATA = parse_path($_JPOST->dir, $_ENDPOINT, $G_TOKEN_SESSION_DATA);
$G_DIRECTORY_DATA = directory_hierarchy($G_STORAGE_CONTROLLER_DBLINK, $G_APP_DATA['id'], $G_APP_ENVIRONMENT, $G_PATH_DATA->absolute, true);
# Our return values!
$content->success = true;
$content->env = PostParser::create_attribute($G_APP_ENVIRONMENT);
$content->path = $G_PATH_DATA->urlpath;
# How are we going to return our data
PostParser::send($content);
/* --- Connection closed wit PostParser::send --- Below this point things need to be tracked and cleaned up --- */
# Closing the storage connection
mysqli_shared_close($G_STORAGE_CONTROLLER_DBLINK, $G_SHARED_DBLINKS);
# Closing controller if tracking is different
if (NQ_CONTROLLER_HOST != NQ_TRACKING_HOST) {
    mysqli_shared_close($G_CONTROLLER_DBLINK, $G_SHARED_DBLINKS);
}
# Adding our usage
Esempio n. 7
0
function PackageInstallTest()
{
    global $boarddir, $txt, $context, $scripturl, $sourcedir, $modSettings, $settings;
    // You have to specify a file!!
    if (!isset($_REQUEST['package']) || $_REQUEST['package'] == '') {
        redirectexit('action=admin;area=packages');
    }
    $context['filename'] = preg_replace('~[\\.]+~', '.', $_REQUEST['package']);
    // Do we have an existing id, for uninstalls and the like.
    $context['install_id'] = isset($_REQUEST['pid']) ? (int) $_REQUEST['pid'] : 0;
    require_once $sourcedir . '/lib/Subs-Package.php';
    // Load up the package FTP information?
    create_chmod_control();
    // Make sure temp directory exists and is empty.
    if (file_exists($boarddir . '/Packages/temp')) {
        deltree($boarddir . '/Packages/temp', false);
    }
    if (!mktree($boarddir . '/Packages/temp', 0755)) {
        deltree($boarddir . '/Packages/temp', false);
        if (!mktree($boarddir . '/Packages/temp', 0777)) {
            deltree($boarddir . '/Packages/temp', false);
            create_chmod_control(array($boarddir . '/Packages/temp/delme.tmp'), array('destination_url' => $scripturl . '?action=admin;area=packages;sa=' . $_REQUEST['sa'] . ';package=' . $_REQUEST['package'], 'crash_on_error' => true));
            deltree($boarddir . '/Packages/temp', false);
            if (!mktree($boarddir . '/Packages/temp', 0777)) {
                fatal_lang_error('package_cant_download', false);
            }
        }
    }
    $context['uninstalling'] = $_REQUEST['sa'] == 'uninstall';
    // Change our last link tree item for more information on this Packages area.
    $context['linktree'][count($context['linktree']) - 1] = array('url' => $scripturl . '?action=admin;area=packages;sa=browse', 'name' => $context['uninstalling'] ? $txt['package_uninstall_actions'] : $txt['install_actions']);
    $context['page_title'] .= ' - ' . ($context['uninstalling'] ? $txt['package_uninstall_actions'] : $txt['install_actions']);
    $context['sub_template'] = 'view_package';
    if (!file_exists($boarddir . '/Packages/' . $context['filename'])) {
        deltree($boarddir . '/Packages/temp');
        fatal_lang_error('package_no_file', false);
    }
    // Extract the files so we can get things like the readme, etc.
    if (is_file($boarddir . '/Packages/' . $context['filename'])) {
        $context['extracted_files'] = read_tgz_file($boarddir . '/Packages/' . $context['filename'], $boarddir . '/Packages/temp');
        if ($context['extracted_files'] && !file_exists($boarddir . '/Packages/temp/package-info.xml')) {
            foreach ($context['extracted_files'] as $file) {
                if (basename($file['filename']) == 'package-info.xml') {
                    $context['base_path'] = dirname($file['filename']) . '/';
                    break;
                }
            }
        }
        if (!isset($context['base_path'])) {
            $context['base_path'] = '';
        }
    } elseif (is_dir($boarddir . '/Packages/' . $context['filename'])) {
        copytree($boarddir . '/Packages/' . $context['filename'], $boarddir . '/Packages/temp');
        $context['extracted_files'] = listtree($boarddir . '/Packages/temp');
        $context['base_path'] = '';
    } else {
        fatal_lang_error('no_access', false);
    }
    // Load up any custom themes we may want to install into...
    $request = smf_db_query('
		SELECT id_theme, variable, value
		FROM {db_prefix}themes
		WHERE (id_theme = {int:default_theme} OR id_theme IN ({array_int:known_theme_list}))
			AND variable IN ({string:name}, {string:theme_dir})', array('known_theme_list' => explode(',', $modSettings['knownThemes']), 'default_theme' => 1, 'name' => 'name', 'theme_dir' => 'theme_dir'));
    $theme_paths = array();
    while ($row = mysql_fetch_assoc($request)) {
        $theme_paths[$row['id_theme']][$row['variable']] = $row['value'];
    }
    mysql_free_result($request);
    // Get the package info...
    $packageInfo = getPackageInfo($context['filename']);
    if (!is_array($packageInfo)) {
        fatal_lang_error($packageInfo);
    }
    $packageInfo['filename'] = $context['filename'];
    $context['package_name'] = isset($packageInfo['name']) ? $packageInfo['name'] : $context['filename'];
    // Set the type of extraction...
    $context['extract_type'] = isset($packageInfo['type']) ? $packageInfo['type'] : 'modification';
    // The mod isn't installed.... unless proven otherwise.
    $context['is_installed'] = false;
    // See if it is installed?
    $request = smf_db_query('
		SELECT version, themes_installed, db_changes
		FROM {db_prefix}log_packages
		WHERE package_id = {string:current_package}
			AND install_state != {int:not_installed}
		ORDER BY time_installed DESC
		LIMIT 1', array('not_installed' => 0, 'current_package' => $packageInfo['id']));
    while ($row = mysql_fetch_assoc($request)) {
        $old_themes = explode(',', $row['themes_installed']);
        $old_version = $row['version'];
        $db_changes = empty($row['db_changes']) ? array() : unserialize($row['db_changes']);
    }
    mysql_free_result($request);
    $context['database_changes'] = array();
    if (!empty($db_changes)) {
        foreach ($db_changes as $change) {
            if (isset($change[2]) && isset($txt['package_db_' . $change[0]])) {
                $context['database_changes'][] = sprintf($txt['package_db_' . $change[0]], $change[1], $change[2]);
            } elseif (isset($txt['package_db_' . $change[0]])) {
                $context['database_changes'][] = sprintf($txt['package_db_' . $change[0]], $change[1]);
            } else {
                $context['database_changes'][] = $change[0] . '-' . $change[1] . (isset($change[2]) ? '-' . $change[2] : '');
            }
        }
    }
    // Uninstalling?
    if ($context['uninstalling']) {
        // Wait, it's not installed yet!
        if (!isset($old_version) && $context['uninstalling']) {
            deltree($boarddir . '/Packages/temp');
            fatal_lang_error('package_cant_uninstall', false);
        }
        $actions = parsePackageInfo($packageInfo['xml'], true, 'uninstall');
        // Gadzooks!  There's no uninstaller at all!?
        if (empty($actions)) {
            deltree($boarddir . '/Packages/temp');
            fatal_lang_error('package_uninstall_cannot', false);
        }
        // Can't edit the custom themes it's edited if you're unisntalling, they must be removed.
        $context['themes_locked'] = true;
        // Only let them uninstall themes it was installed into.
        foreach ($theme_paths as $id => $data) {
            if ($id != 1 && !in_array($id, $old_themes)) {
                unset($theme_paths[$id]);
            }
        }
    } elseif (isset($old_version) && $old_version != $packageInfo['version']) {
        // Look for an upgrade...
        $actions = parsePackageInfo($packageInfo['xml'], true, 'upgrade', $old_version);
        // There was no upgrade....
        if (empty($actions)) {
            $context['is_installed'] = true;
        } else {
            // Otherwise they can only upgrade themes from the first time around.
            foreach ($theme_paths as $id => $data) {
                if ($id != 1 && !in_array($id, $old_themes)) {
                    unset($theme_paths[$id]);
                }
            }
        }
    } elseif (isset($old_version) && $old_version == $packageInfo['version']) {
        $context['is_installed'] = true;
    }
    if (!isset($old_version) || $context['is_installed']) {
        $actions = parsePackageInfo($packageInfo['xml'], true, 'install');
    }
    $context['actions'] = array();
    $context['ftp_needed'] = false;
    $context['has_failure'] = false;
    $chmod_files = array();
    if (empty($actions)) {
        return;
    }
    // This will hold data about anything that can be installed in other themes.
    $themeFinds = array('candidates' => array(), 'other_themes' => array());
    // Now prepare things for the template.
    foreach ($actions as $action) {
        // Not failed until proven otherwise.
        $failed = false;
        if ($action['type'] == 'chmod') {
            $chmod_files[] = $action['filename'];
            continue;
        } elseif ($action['type'] == 'readme') {
            if (file_exists($boarddir . '/Packages/temp/' . $context['base_path'] . $action['filename'])) {
                $context['package_readme'] = htmlspecialchars(trim(file_get_contents($boarddir . '/Packages/temp/' . $context['base_path'] . $action['filename']), "\n\r"));
            } elseif (file_exists($action['filename'])) {
                $context['package_readme'] = htmlspecialchars(trim(file_get_contents($action['filename']), "\n\r"));
            }
            if (!empty($action['parse_bbc'])) {
                require_once $sourcedir . '/lib/Subs-Post.php';
                preparsecode($context['package_readme']);
                $context['package_readme'] = parse_bbc($context['package_readme']);
            } else {
                $context['package_readme'] = nl2br($context['package_readme']);
            }
            continue;
        } elseif ($action['type'] == 'redirect') {
            continue;
        } elseif ($action['type'] == 'error') {
            $context['has_failure'] = true;
        } elseif ($action['type'] == 'modification') {
            if (!file_exists($boarddir . '/Packages/temp/' . $context['base_path'] . $action['filename'])) {
                $context['has_failure'] = true;
                $context['actions'][] = array('type' => $txt['execute_modification'], 'action' => commonAPI::htmlspecialchars(strtr($action['filename'], array($boarddir => '.'))), 'description' => $txt['package_action_error'], 'failed' => true);
            }
            if ($action['boardmod']) {
                $mod_actions = parseBoardMod(@file_get_contents($boarddir . '/Packages/temp/' . $context['base_path'] . $action['filename']), true, $action['reverse'], $theme_paths);
            } else {
                $mod_actions = parseModification(@file_get_contents($boarddir . '/Packages/temp/' . $context['base_path'] . $action['filename']), true, $action['reverse'], $theme_paths);
            }
            if (count($mod_actions) == 1 && isset($mod_actions[0]) && $mod_actions[0]['type'] == 'error' && $mod_actions[0]['filename'] == '-') {
                $mod_actions[0]['filename'] = $action['filename'];
            }
            foreach ($mod_actions as $key => $mod_action) {
                // Lets get the last section of the file name.
                if (isset($mod_action['filename']) && substr($mod_action['filename'], -13) != '.template.php') {
                    $actual_filename = strtolower(substr(strrchr($mod_action['filename'], '/'), 1) . '||' . $action['filename']);
                } elseif (isset($mod_action['filename']) && preg_match('~([\\w]*)/([\\w]*)\\.template\\.php$~', $mod_action['filename'], $matches)) {
                    $actual_filename = strtolower($matches[1] . '/' . $matches[2] . '.template.php' . '||' . $action['filename']);
                } else {
                    $actual_filename = $key;
                }
                if ($mod_action['type'] == 'opened') {
                    $failed = false;
                } elseif ($mod_action['type'] == 'failure') {
                    if (empty($mod_action['is_custom'])) {
                        $context['has_failure'] = true;
                    }
                    $failed = true;
                } elseif ($mod_action['type'] == 'chmod') {
                    $chmod_files[] = $mod_action['filename'];
                } elseif ($mod_action['type'] == 'saved') {
                    if (!empty($mod_action['is_custom'])) {
                        if (!isset($context['theme_actions'][$mod_action['is_custom']])) {
                            $context['theme_actions'][$mod_action['is_custom']] = array('name' => $theme_paths[$mod_action['is_custom']]['name'], 'actions' => array(), 'has_failure' => $failed);
                        } else {
                            $context['theme_actions'][$mod_action['is_custom']]['has_failure'] |= $failed;
                        }
                        $context['theme_actions'][$mod_action['is_custom']]['actions'][$actual_filename] = array('type' => $txt['execute_modification'], 'action' => commonAPI::htmlspecialchars(strtr($mod_action['filename'], array($boarddir => '.'))), 'description' => $failed ? $txt['package_action_failure'] : $txt['package_action_success'], 'failed' => $failed);
                    } elseif (!isset($context['actions'][$actual_filename])) {
                        $context['actions'][$actual_filename] = array('type' => $txt['execute_modification'], 'action' => commonAPI::htmlspecialchars(strtr($mod_action['filename'], array($boarddir => '.'))), 'description' => $failed ? $txt['package_action_failure'] : $txt['package_action_success'], 'failed' => $failed);
                    } else {
                        $context['actions'][$actual_filename]['failed'] |= $failed;
                        $context['actions'][$actual_filename]['description'] = $context['actions'][$actual_filename]['failed'] ? $txt['package_action_failure'] : $txt['package_action_success'];
                    }
                } elseif ($mod_action['type'] == 'skipping') {
                    $context['actions'][$actual_filename] = array('type' => $txt['execute_modification'], 'action' => commonAPI::htmlspecialchars(strtr($mod_action['filename'], array($boarddir => '.'))), 'description' => $txt['package_action_skipping']);
                } elseif ($mod_action['type'] == 'missing' && empty($mod_action['is_custom'])) {
                    $context['has_failure'] = true;
                    $context['actions'][$actual_filename] = array('type' => $txt['execute_modification'], 'action' => commonAPI::htmlspecialchars(strtr($mod_action['filename'], array($boarddir => '.'))), 'description' => $txt['package_action_missing'], 'failed' => true);
                } elseif ($mod_action['type'] == 'error') {
                    $context['actions'][$actual_filename] = array('type' => $txt['execute_modification'], 'action' => commonAPI::htmlspecialchars(strtr($mod_action['filename'], array($boarddir => '.'))), 'description' => $txt['package_action_error'], 'failed' => true);
                }
            }
            // We need to loop again just to get the operations down correctly.
            foreach ($mod_actions as $operation_key => $mod_action) {
                // Lets get the last section of the file name.
                if (isset($mod_action['filename']) && substr($mod_action['filename'], -13) != '.template.php') {
                    $actual_filename = strtolower(substr(strrchr($mod_action['filename'], '/'), 1) . '||' . $action['filename']);
                } elseif (isset($mod_action['filename']) && preg_match('~([\\w]*)/([\\w]*)\\.template\\.php$~', $mod_action['filename'], $matches)) {
                    $actual_filename = strtolower($matches[1] . '/' . $matches[2] . '.template.php' . '||' . $action['filename']);
                } else {
                    $actual_filename = $key;
                }
                // We just need it for actual parse changes.
                if (!in_array($mod_action['type'], array('error', 'result', 'opened', 'saved', 'end', 'missing', 'skipping', 'chmod'))) {
                    if (empty($mod_action['is_custom'])) {
                        $context['actions'][$actual_filename]['operations'][] = array('type' => $txt['execute_modification'], 'action' => commonAPI::htmlspecialchars(strtr($mod_action['filename'], array($boarddir => '.'))), 'description' => $mod_action['failed'] ? $txt['package_action_failure'] : $txt['package_action_success'], 'position' => $mod_action['position'], 'operation_key' => $operation_key, 'filename' => $action['filename'], 'is_boardmod' => $action['boardmod'], 'failed' => $mod_action['failed'], 'ignore_failure' => !empty($mod_action['ignore_failure']));
                    }
                    // Themes are under the saved type.
                    if (isset($mod_action['is_custom']) && isset($context['theme_actions'][$mod_action['is_custom']])) {
                        $context['theme_actions'][$mod_action['is_custom']]['actions'][$actual_filename]['operations'][] = array('type' => $txt['execute_modification'], 'action' => commonAPI::htmlspecialchars(strtr($mod_action['filename'], array($boarddir => '.'))), 'description' => $mod_action['failed'] ? $txt['package_action_failure'] : $txt['package_action_success'], 'position' => $mod_action['position'], 'operation_key' => $operation_key, 'filename' => $action['filename'], 'is_boardmod' => $action['boardmod'], 'failed' => $mod_action['failed'], 'ignore_failure' => !empty($mod_action['ignore_failure']));
                    }
                }
            }
            // Don't add anything else.
            $thisAction = array();
        } elseif ($action['type'] == 'code') {
            $thisAction = array('type' => $txt['execute_code'], 'action' => commonAPI::htmlspecialchars($action['filename']));
        } elseif ($action['type'] == 'database') {
            $thisAction = array('type' => $txt['execute_database_changes'], 'action' => commonAPI::htmlspecialchars($action['filename']));
        } elseif (in_array($action['type'], array('create-dir', 'create-file'))) {
            $thisAction = array('type' => $txt['package_create'] . ' ' . ($action['type'] == 'create-dir' ? $txt['package_tree'] : $txt['package_file']), 'action' => commonAPI::htmlspecialchars(strtr($action['destination'], array($boarddir => '.'))));
        } elseif (in_array($action['type'], array('require-dir', 'require-file'))) {
            // Do this one...
            $thisAction = array('type' => $txt['package_extract'] . ' ' . ($action['type'] == 'require-dir' ? $txt['package_tree'] : $txt['package_file']), 'action' => commonAPI::htmlspecialchars(strtr($action['destination'], array($boarddir => '.'))));
            // Could this be theme related?
            if (!empty($action['unparsed_destination']) && preg_match('~^\\$(languagedir|languages_dir|imagesdir|themedir|themes_dir)~i', $action['unparsed_destination'], $matches)) {
                // Is the action already stated?
                $theme_action = !empty($action['theme_action']) && in_array($action['theme_action'], array('no', 'yes', 'auto')) ? $action['theme_action'] : 'auto';
                // If it's not auto do we think we have something we can act upon?
                if ($theme_action != 'auto' && !in_array($matches[1], array('languagedir', 'languages_dir', 'imagesdir', 'themedir'))) {
                    $theme_action = '';
                } elseif ($theme_action == 'auto' && $matches[1] != 'imagesdir') {
                    $theme_action = '';
                }
                // So, we still want to do something?
                if ($theme_action != '') {
                    $themeFinds['candidates'][] = $action;
                } elseif ($matches[1] == 'themes_dir') {
                    $themeFinds['other_themes'][] = strtolower(strtr(parse_path($action['unparsed_destination']), array('\\' => '/')) . '/' . basename($action['filename']));
                }
            }
        } elseif (in_array($action['type'], array('move-dir', 'move-file'))) {
            $thisAction = array('type' => $txt['package_move'] . ' ' . ($action['type'] == 'move-dir' ? $txt['package_tree'] : $txt['package_file']), 'action' => commonAPI::htmlspecialchars(strtr($action['source'], array($boarddir => '.'))) . ' => ' . commonAPI::htmlspecialchars(strtr($action['destination'], array($boarddir => '.'))));
        } elseif (in_array($action['type'], array('remove-dir', 'remove-file'))) {
            $thisAction = array('type' => $txt['package_delete'] . ' ' . ($action['type'] == 'remove-dir' ? $txt['package_tree'] : $txt['package_file']), 'action' => commonAPI::htmlspecialchars(strtr($action['filename'], array($boarddir => '.'))));
            // Could this be theme related?
            if (!empty($action['unparsed_filename']) && preg_match('~^\\$(languagedir|languages_dir|imagesdir|themedir|themes_dir)~i', $action['unparsed_filename'], $matches)) {
                // Is the action already stated?
                $theme_action = !empty($action['theme_action']) && in_array($action['theme_action'], array('no', 'yes', 'auto')) ? $action['theme_action'] : 'auto';
                $action['unparsed_destination'] = $action['unparsed_filename'];
                // If it's not auto do we think we have something we can act upon?
                if ($theme_action != 'auto' && !in_array($matches[1], array('languagedir', 'languages_dir', 'imagesdir', 'themedir'))) {
                    $theme_action = '';
                } elseif ($theme_action == 'auto' && $matches[1] != 'imagesdir') {
                    $theme_action = '';
                }
                // So, we still want to do something?
                if ($theme_action != '') {
                    $themeFinds['candidates'][] = $action;
                } elseif ($matches[1] == 'themes_dir') {
                    $themeFinds['other_themes'][] = strtolower(strtr(parse_path($action['unparsed_filename']), array('\\' => '/')) . '/' . basename($action['filename']));
                }
            }
        }
        if (empty($thisAction)) {
            continue;
        }
        // !!! None given?
        $thisAction['description'] = isset($action['description']) ? $action['description'] : '';
        $context['actions'][] = $thisAction;
    }
    // Have we got some things which we might want to do "multi-theme"?
    if (!empty($themeFinds['candidates'])) {
        foreach ($themeFinds['candidates'] as $action_data) {
            // Get the part of the file we'll be dealing with.
            preg_match('~^\\$(languagedir|languages_dir|imagesdir|themedir)(\\|/)*(.+)*~i', $action_data['unparsed_destination'], $matches);
            if ($matches[1] == 'imagesdir') {
                $path = '/' . basename($settings['default_images_url']);
            } elseif ($matches[1] == 'languagedir' || $matches[1] == 'languages_dir') {
                $path = '/languages';
            } else {
                $path = '';
            }
            if (!empty($matches[3])) {
                $path .= $matches[3];
            }
            if (!$context['uninstalling']) {
                $path .= '/' . basename($action_data['filename']);
            }
            // Loop through each custom theme to note it's candidacy!
            foreach ($theme_paths as $id => $theme_data) {
                if (isset($theme_data['theme_dir']) && $id != 1) {
                    $real_path = $theme_data['theme_dir'] . $path;
                    // Confirm that we don't already have this dealt with by another entry.
                    if (!in_array(strtolower(strtr($real_path, array('\\' => '/'))), $themeFinds['other_themes'])) {
                        // Check if we will need to chmod this.
                        if (!mktree(dirname($real_path), false)) {
                            $temp = dirname($real_path);
                            while (!file_exists($temp) && strlen($temp) > 1) {
                                $temp = dirname($temp);
                            }
                            $chmod_files[] = $temp;
                        }
                        if ($action_data['type'] == 'require-dir' && !is_writable($real_path) && (file_exists($real_path) || !is_writable(dirname($real_path)))) {
                            $chmod_files[] = $real_path;
                        }
                        if (!isset($context['theme_actions'][$id])) {
                            $context['theme_actions'][$id] = array('name' => $theme_data['name'], 'actions' => array());
                        }
                        if ($context['uninstalling']) {
                            $context['theme_actions'][$id]['actions'][] = array('type' => $txt['package_delete'] . ' ' . ($action_data['type'] == 'require-dir' ? $txt['package_tree'] : $txt['package_file']), 'action' => strtr($real_path, array('\\' => '/', $boarddir => '.')), 'description' => '', 'value' => base64_encode(serialize(array('type' => $action_data['type'], 'orig' => $action_data['filename'], 'future' => $real_path, 'id' => $id))), 'not_mod' => true);
                        } else {
                            $context['theme_actions'][$id]['actions'][] = array('type' => $txt['package_extract'] . ' ' . ($action_data['type'] == 'require-dir' ? $txt['package_tree'] : $txt['package_file']), 'action' => strtr($real_path, array('\\' => '/', $boarddir => '.')), 'description' => '', 'value' => base64_encode(serialize(array('type' => $action_data['type'], 'orig' => $action_data['destination'], 'future' => $real_path, 'id' => $id))), 'not_mod' => true);
                        }
                    }
                }
            }
        }
    }
    // Trash the cache... which will also check permissions for us!
    package_flush_cache(true);
    if (file_exists($boarddir . '/Packages/temp')) {
        deltree($boarddir . '/Packages/temp');
    }
    if (!empty($chmod_files)) {
        $ftp_status = create_chmod_control($chmod_files);
        $context['ftp_needed'] = !empty($ftp_status['files']['notwritable']) && !empty($context['package_ftp']);
    }
    checkSubmitOnce('register');
}
Esempio n. 8
0
function icopy($path, $dir)
{
    if (!file_exists($path)) {
        return false;
    }
    $tmpPath = parse_path($path);
    if (!is_dir($path)) {
        create_dir($dir);
        if (!copy($path, $dir . '/' . $tmpPath['filename'])) {
            return false;
        }
    } else {
        create_dir($dir);
        foreach ((array) list_dir($path) as $lineArray) {
            if ($lineArray['type'] == 'dir') {
                icopy($lineArray['path'], $dir . '/' . $lineArray['filename']);
            } else {
                icopy($lineArray['path'], $dir);
            }
        }
    }
    return true;
}
Esempio n. 9
0
		FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
		AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
		LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
		OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
		THE SOFTWARE.
*/
# Setting our constants
define('CACHEABLE', false);
// Can this page be cached on the users browser
define('PUBLIC_ENDPOINT', false);
// Can anyone can access this endpoint
# Including our configuration
require_once __DIR__ . '/_includes/config.php';
require_once __DIR__ . '/_includes/validate-app.php';
# Getting our directory
$G_PATH_DATA = parse_path(implode('/', array_splice($_BASEDIR, 3)), $_ENDPOINT, $G_TOKEN_SESSION_DATA);
$query = "\tSELECT\n\t\t\t\t*\n\t\t\tFROM\n\t\t\t\t" . NQ_DIRECTORY_TABLE . "\n\t\t\tWHERE\n\t\t\t\t`app_id`\t=" . (int) $G_APP_DATA['id'] . " AND\n\t\t\t\t`environment`\t='" . mysqli_escape_string($G_STORAGE_CONTROLLER_DBLINK, $G_APP_ENVIRONMENT) . "' AND\n\t\t\t\t`path`\t\t='" . mysqli_escape_string($G_STORAGE_CONTROLLER_DBLINK, urldecode($G_PATH_DATA->dir)) . "' AND\n\t\t\t\t`name`\t\t='" . mysqli_escape_string($G_STORAGE_CONTROLLER_DBLINK, urldecode($G_PATH_DATA->name)) . "'\n\t\t\tLIMIT 1";
$directory_data = mysqli_single_result_query($G_STORAGE_CONTROLLER_DBLINK, $query);
# Checking to see if we are blacklisted
$tid = isset($G_TOKEN_DATA['id']) ? $G_TOKEN_DATA['id'] : 0;
check_directory_blacklisted($G_CONTROLLER_DBLINK, $tid, $G_TOKEN_SESSION_DATA, $directory_data['path'] . $directory_data['name'], true);
# Getting our file
$query = "\tSELECT\n\t\t\t\t`created`,\n\t\t\t\t`filesize`,\n\t\t\t\t`file_id`,\n\t\t\t\t`meta_height` AS `height`,\n\t\t\t\t1 AS `live`,\n\t\t\t\t`modified`,\n\t\t\t\t`name`,\n\t\t\t\t`version`,\n\t\t\t\t`meta_width` AS `width`,\n\t\t\t\tCONCAT('" . NQ_DOMAIN_ROOT . '/' . $G_APP_DATA['id'] . '/view' . "','" . substr($directory_data['path'], 2) . $directorty_data['name'] . "','/',`name`" . ($G_APP_ENVIRONMENT == 'prod' ? "" : ",'?env=" . $G_APP_ENVIRONMENT . "'") . ") AS `url`\n  \t\t\tFROM\n\t\t\t\t" . NQ_FILE_TABLE . "\n\t\t\tWHERE \n\t\t\t\t`app_id`\t=" . (int) $G_APP_DATA['id'] . " AND\n\t\t\t\t`environment`\t='" . mysqli_escape_string($G_STORAGE_CONTROLLER_DBLINK, $G_APP_ENVIRONMENT) . "' AND\n\t\t\t\t`directory_id`\t=" . (int) $directory_data['id'] . " AND\n\t\t\t\t`name`\t\t='" . mysqli_escape_string($G_STORAGE_CONTROLLER_DBLINK, urldecode($_FILENAME)) . "'\n\t\t\tLIMIT 1";
$file_data = mysqli_single_result_query($G_STORAGE_CONTROLLER_DBLINK, $query);
# Erroring if we don't have a file
if (!isset($file_data['name'])) {
    exit_fail(NQ_INVALID_VALUE, LANG_INVALID_FILE);
}
# Getting our file
$query = "\tSELECT\n\t\t\t\t`created`,\n\t\t\t\t`filesize`,\n\t\t\t\t`meta_height` AS `height`,\n\t\t\t\t0 AS `live`,\n\t\t\t\t`modified`,\n\t\t\t\t`name`,\n\t\t\t\t`version`,\n\t\t\t\t`meta_width` AS `width`,\n\t\t\t\tCONCAT('" . NQ_DOMAIN_ROOT . '/' . $G_APP_DATA['id'] . '/view' . "','" . substr($directory_data['path'], 2) . $directorty_data['name'] . "','/',`name`,'?version=',`version`" . ($G_APP_ENVIRONMENT == 'prod' ? "" : ",'&env=" . $G_APP_ENVIRONMENT . "'") . ") AS `url`\n  \t\t\tFROM\n\t\t\t\t" . NQ_FILE_VERSION_TABLE . "\n\t\t\tWHERE \n\t\t\t\t`file_id`\t=" . (int) $file_data['file_id'] . "\n\t\t\tORDER BY \n\t\t\t\t`version` DESC";
$result = mysqli_multi_result_query($G_STORAGE_CONTROLLER_DBLINK, $query);
Esempio n. 10
0
function parseBoardMod($file, $testing = true, $undo = false)
{
    global $boarddir, $sourcedir, $settings, $txt, $modSettings;
    @set_time_limit(600);
    $file = strtr($file, array("\r" => ''));
    $working_file = null;
    $working_search = null;
    $working_data = '';
    $replace_with = null;
    $actions = array();
    $everything_found = true;
    while (preg_match('~<(edit file|file|search|search for|add|add after|replace|add before|add above|above|before)>\\n(.*?)\\n</\\1>~is', $file, $code_match) != 0) {
        // Edit a specific file.
        if ($code_match[1] == 'file' || $code_match[1] == 'edit file') {
            // Backup the old file.
            if ($working_file !== null) {
                package_chmod($working_file);
                // Don't even dare.
                if (basename($working_file) == 'Settings_bak.php') {
                    continue;
                }
                if (!is_writable($working_file)) {
                    $actions[] = array('type' => 'chmod', 'filename' => $working_file);
                }
                if (!$testing && !empty($modSettings['package_make_backups']) && file_exists($working_file)) {
                    if (basename($working_file) == 'Settings.php') {
                        @copy($working_file, dirname($working_file) . '/Settings_bak.php');
                    } else {
                        @copy($working_file, $working_file . '~');
                    }
                }
                package_put_contents($working_file, $working_data, $testing);
            }
            if ($working_file !== null) {
                $actions[] = array('type' => 'saved', 'filename' => $working_file);
            }
            // Make sure the file exists!
            $working_file = parse_path($code_match[2]);
            if ($working_file[0] != '/' && $working_file[1] != ':') {
                trigger_error('parseBoardMod(): The filename \'' . $working_file . '\' is not a full path!', E_USER_WARNING);
                $working_file = $boarddir . '/' . $working_file;
            }
            if (!file_exists($working_file)) {
                $places_to_check = array($boarddir, $sourcedir, $settings['default_theme_dir'], $settings['default_theme_dir'] . '/languages');
                foreach ($places_to_check as $place) {
                    if (file_exists($place . '/' . $working_file)) {
                        $working_file = $place . '/' . $working_file;
                        break;
                    }
                }
            }
            if (file_exists($working_file)) {
                // Load the new file.
                $working_data = str_replace("\r", '', package_get_contents($working_file));
                $actions[] = array('type' => 'opened', 'filename' => $working_file);
            } else {
                $actions[] = array('type' => 'missing', 'filename' => $working_file);
                $working_file = null;
                $everything_found = false;
            }
            // Can't be searching for something...
            $working_search = null;
        } elseif (($code_match[1] == 'search' || $code_match[1] == 'search for') && $working_file !== null) {
            if ($working_search !== null) {
                $actions[] = array('type' => 'error', 'filename' => $working_file);
                $everything_found = false;
            }
            $working_search = $code_match[2];
        } elseif ($working_search !== null) {
            // This is the base string....
            $replace_with = $code_match[2];
            // Add this afterward...
            if ($code_match[1] == 'add' || $code_match[1] == 'add after') {
                $replace_with = $working_search . "\n" . $replace_with;
            } elseif ($code_match[1] == 'before' || $code_match[1] == 'add before' || $code_match[1] == 'above' || $code_match[1] == 'add above') {
                $replace_with .= "\n" . $working_search;
            }
            // Otherwise.. replace with $replace_with ;).
        }
        // If we have a search string, replace string, and open file..
        if ($working_search !== null && $replace_with !== null && $working_file !== null) {
            // Make sure it's somewhere in the string.
            if ($undo) {
                $temp = $replace_with;
                $replace_with = $working_search;
                $working_search = $temp;
            }
            if (strpos($working_data, $working_search) !== false) {
                $working_data = str_replace($working_search, $replace_with, $working_data);
                $actions[] = array('type' => 'replace', 'filename' => $working_file, 'search' => $working_search, 'replace' => $replace_with);
            } else {
                $actions[] = array('type' => 'failure', 'filename' => $working_file, 'search' => $working_search);
                $everything_found = false;
            }
            // These don't hold any meaning now.
            $working_search = null;
            $replace_with = null;
        }
        // Get rid of the old tag.
        $file = substr_replace($file, '', strpos($file, $code_match[0]), strlen($code_match[0]));
    }
    // Backup the old file.
    if ($working_file !== null) {
        package_chmod($working_file);
        if (!is_writable($working_file)) {
            $actions[] = array('type' => 'chmod', 'filename' => $working_file);
        }
        if (!$testing && !empty($modSettings['package_make_backups']) && file_exists($working_file)) {
            if (basename($working_file) == 'Settings.php') {
                @copy($working_file, dirname($working_file) . '/Settings_bak.php');
            } else {
                @copy($working_file, $working_file . '~');
            }
        }
        package_put_contents($working_file, $working_data, $testing);
    }
    if ($working_file !== null) {
        $actions[] = array('type' => 'saved', 'filename' => $working_file);
    }
    $actions[] = array('type' => 'result', 'status' => $everything_found);
    return $actions;
}
Esempio n. 11
0
/**
 * Callback function for the integration hooks list (list_integration_hooks)
 *
 * What it does:
 * - Gets all of the hooks in the system and their status
 * - Would be better documented if Ema was not lazy
 *
 * @package AddonSettings
 * @param int $start
 * @param int $per_page
 * @param string $sort
 * @return array
 */
function list_integration_hooks_data($start, $per_page, $sort)
{
    global $txt, $context, $scripturl, $modSettings;
    require_once SUBSDIR . '/Package.subs.php';
    $hooks = $temp_hooks = get_integration_hooks();
    $hooks_data = $temp_data = $hook_status = array();
    $files = get_files_recursive(SOURCEDIR);
    if (!empty($files)) {
        foreach ($files as $file) {
            if (is_file($file['dir'] . '/' . $file['name']) && substr($file['name'], -4) === '.php') {
                $fp = fopen($file['dir'] . '/' . $file['name'], 'rb');
                $fc = strtr(fread($fp, filesize($file['dir'] . '/' . $file['name'])), array("\r" => '', "\n" => ''));
                fclose($fp);
                foreach ($temp_hooks as $hook => $functions) {
                    foreach ($functions as $function_o) {
                        $hook_name = str_replace(']', '', $function_o);
                        if (strpos($hook_name, '::') !== false) {
                            $function = explode('::', $hook_name);
                            $class = $function[0];
                            $function = $function[1];
                        } else {
                            $class = '';
                            $function = $hook_name;
                        }
                        $function = explode('|', $function);
                        $function = $function[0];
                        if (substr($hook, -8) === '_include') {
                            $real_path = parse_path(trim($hook_name));
                            if ($real_path == $hook_name) {
                                $hook_status[$hook][$hook_name]['exists'] = false;
                            } else {
                                $hook_status[$hook][$hook_name]['exists'] = file_exists(parse_path(ltrim($real_path, '|')));
                            }
                            // I need to know if there is at least one function called in this file.
                            $temp_data['include'][basename($function)] = array('hook' => $hook, 'function' => $function);
                            unset($temp_hooks[$hook][$function_o]);
                        } elseif (empty($class) && strpos(str_replace(' (', '(', $fc), 'function ' . trim($function) . '(') !== false) {
                            $hook_status[$hook][$hook_name]['exists'] = true;
                            $hook_status[$hook][$hook_name]['in_file'] = $file['name'];
                            // I want to remember all the functions called within this file (to check later if they are
                            // enabled or disabled and decide if the integrate_*_include of that file can be disabled too)
                            $temp_data['function'][$file['name']][] = $function_o;
                            unset($temp_hooks[$hook][$function_o]);
                        } elseif (!empty($class) && preg_match('~class\\s*' . preg_quote(trim($class)) . '.*function\\s*' . preg_quote(trim($function), '~') . '\\s*\\(~i', $fc) != 0) {
                            $hook_status[$hook][$hook_name]['exists'] = true;
                            $hook_status[$hook][$hook_name]['in_file'] = $file['name'];
                            // I want to remember all the functions called within this file (to check later if they are
                            // enabled or disabled and decide if the integrate_*_include of that file can be disabled too)
                            $temp_data['function'][$file['name']][] = $function_o;
                            unset($temp_hooks[$hook][$function_o]);
                        }
                    }
                }
            }
        }
    }
    $sort_types = array('hook_name' => array('hook_name', SORT_ASC), 'hook_name DESC' => array('hook_name', SORT_DESC), 'function_name' => array('function_name', SORT_ASC), 'function_name DESC' => array('function_name', SORT_DESC), 'file_name' => array('file_name', SORT_ASC), 'file_name DESC' => array('file_name', SORT_DESC), 'status' => array('status', SORT_ASC), 'status DESC' => array('status', SORT_DESC));
    $sort_options = $sort_types[$sort];
    $sort = array();
    $hooks_filters = array();
    foreach ($hooks as $hook => $functions) {
        $hooks_filters[] = '<option ' . ($context['current_filter'] == $hook ? 'selected="selected" ' : '') . ' value="' . $hook . '">' . $hook . '</option>';
        foreach ($functions as $function) {
            $function = str_replace(']', '', $function);
            // This is a not an include and the function is included in a certain file (if not it doesn't exists so don't care)
            if (substr($hook, -8) !== '_include' && isset($hook_status[$hook][$function]['in_file'])) {
                $current_hook = isset($temp_data['include'][$hook_status[$hook][$function]['in_file']]) ? $temp_data['include'][$hook_status[$hook][$function]['in_file']] : '';
                $enabled = false;
                // Checking all the functions within this particular file
                // if any of them is enable then the file *must* be included and the integrate_*_include hook cannot be disabled
                foreach ($temp_data['function'][$hook_status[$hook][$function]['in_file']] as $func) {
                    $enabled = $enabled || strstr($func, ']') !== false;
                }
                if (!$enabled && !empty($current_hook)) {
                    $hook_status[$current_hook['hook']][$current_hook['function']]['enabled'] = true;
                }
            }
        }
    }
    addInlineJavascript('
			var hook_name_header = document.getElementById(\'header_list_integration_hooks_hook_name\');
			hook_name_header.innerHTML += ' . JavaScriptEscape('
				<select onchange="window.location = \'' . $scripturl . '?action=admin;area=maintain;sa=hooks\' + (this.value ? \';filter=\' + this.value : \'\');">
					<option>---</option>
					<option value="">' . $txt['hooks_reset_filter'] . '</option>' . implode('', $hooks_filters) . '</select>' . '
				</select>') . ';', true);
    $temp_data = array();
    $id = 0;
    foreach ($hooks as $hook => $functions) {
        if (empty($context['filter']) || !empty($context['filter']) && $context['filter'] == $hook) {
            foreach ($functions as $function) {
                $enabled = strstr($function, ']') === false;
                $function = str_replace(']', '', $function);
                $hook_exists = !empty($hook_status[$hook][$function]['exists']);
                if (strpos($function, '::') !== false) {
                    $function = explode('::', $function);
                    $function = $function[1];
                }
                $exploded = explode('|', $function);
                $temp_data[] = array('id' => 'hookid_' . $id++, 'hook_name' => $hook, 'function_name' => $function, 'real_function' => $exploded[0], 'included_file' => isset($exploded[1]) ? parse_path(trim($exploded[1])) : '', 'file_name' => isset($hook_status[$hook][$function]['in_file']) ? $hook_status[$hook][$function]['in_file'] : '', 'hook_exists' => $hook_exists, 'status' => $hook_exists ? $enabled ? 'allow' : 'moderate' : 'deny', 'img_text' => $txt['hooks_' . ($hook_exists ? $enabled ? 'active' : 'disabled' : 'missing')], 'enabled' => $enabled, 'can_be_disabled' => !empty($modSettings['handlinghooks_enabled']) && !isset($hook_status[$hook][$function]['enabled']));
                // Build the array of sort to values
                $sort_end = end($temp_data);
                $sort[] = $sort_end[$sort_options[0]];
            }
        }
    }
    array_multisort($sort, $sort_options[1], $temp_data);
    $counter = 0;
    $start++;
    foreach ($temp_data as $data) {
        if (++$counter < $start) {
            continue;
        } elseif ($counter == $start + $per_page) {
            break;
        }
        $hooks_data[] = $data;
    }
    return $hooks_data;
}
Esempio n. 12
0
/**
 * @param Exception $exception
 */
function stewie_exception_handler(Exception $exception)
{
    if (_DEBUG_MODE_) {
        echo "<div style='padding: 5px;border:2px solid black;background-color: #ff6e66;color: #FFFFFF;font-family: sans-serif;font-weight: bold;'>" . $exception->getMessage() . "</div>";
        foreach ($exception->getTrace() as $trace) {
            echo "<div style='padding: 5px;margin-top: 10px; background-color: #47B1F0;color: #000000;font-family:sans-serif'>";
            foreach ($trace as $key => $value) {
                if (!is_array($value)) {
                    echo $key . " : " . $value . "<br>";
                } else {
                    echo $key . " : <br><blockquote style='color:#FFFFFF'>";
                    foreach ($value as $v) {
                        echo "{$v}";
                    }
                    echo "</blockquote><br>";
                }
            }
            echo "</div>";
        }
        echo "<div style='padding: 5px;margin-top: 10px;border: 2px solid #ff4c4a; background-color: #fafafa;color: #1e1e1e;font-family:sans-serif'>";
        echo "<h2>REQUEST DETAILS</h2>";
        echo "<h3>\$_SERVER</h3>";
        clearPrint($_SERVER);
        echo "<h3>parse path</h3>";
        import("ParsePath");
        clearPrint(parse_path());
        echo "<h3>Session</h3>";
        clearPrint($_SESSION);
        echo "<h3>POST</h3>";
        clearPrint($_POST);
        echo "<h3>Cookies</h3>";
        clearPrint($_COOKIE);
        echo "</div>";
    } else {
        s_error_log($exception->getCode(), $exception->getMessage(), $exception->getFile(), $exception->getLine());
    }
}
Esempio n. 13
0
require_once __DIR__ . '/_includes/validate-app.php';
# Handling our global json parsing
$_JPOST = PostParser::decode();
# Initializing our return value
$content = new stdClass();
$content->success = true;
$content->env = PostParser::create_attribute($G_APP_ENVIRONMENT);
# Getting our source directory
$G_SRC_PATH_DATA = parse_path($_JPOST->src, $_ENDPOINT, $G_TOKEN_SESSION_DATA);
$query = "\tSELECT\n\t\t\t\t*\n\t\t\tFROM\n\t\t\t\t" . NQ_DIRECTORY_TABLE . "\n\t\t\tWHERE\n\t\t\t\t`app_id`\t=" . (int) $G_APP_DATA['id'] . " AND\n\t\t\t\t`environment`\t='" . mysqli_escape_string($G_STORAGE_CONTROLLER_DBLINK, $G_APP_ENVIRONMENT) . "' AND\n\t\t\t\t`path`\t\t='" . mysqli_escape_string($G_STORAGE_CONTROLLER_DBLINK, $G_SRC_PATH_DATA->dir) . "' AND\n\t\t\t\t`name`\t\t='" . mysqli_escape_string($G_STORAGE_CONTROLLER_DBLINK, $G_SRC_PATH_DATA->name) . "'\n\t\t\tLIMIT 1";
$G_SRC_DIR_DATA = mysqli_single_result_query($G_STORAGE_CONTROLLER_DBLINK, $query);
!isset($G_SRC_DIR_DATA['id']) && exit_fail(NQ_ERROR_INVALID_VALUE, LANG_INVALID_SRC_DIR);
# If we aren't allowed in this directory
check_directory_blacklisted($G_CONTROLLER_DBLINK, $G_TOKEN_DATA['id'], $G_TOKEN_SESSION_DATA, $G_SRC_DIR_DATA['path'] . $G_SRC_DIR_DATA['name']);
# Getting our destination directory
$G_DEST_PATH_DATA = parse_path($_JPOST->dest, $_ENDPOINT, $G_TOKEN_SESSION_DATA);
$query = "\tSELECT\n\t\t\t\t*\n\t\t\tFROM\n\t\t\t\t" . NQ_DIRECTORY_TABLE . "\n\t\t\tWHERE\n\t\t\t\t`app_id`\t=" . (int) $G_APP_DATA['id'] . " AND\n\t\t\t\t`environment`\t='" . mysqli_escape_string($G_STORAGE_CONTROLLER_DBLINK, $G_APP_ENVIRONMENT) . "' AND\n\t\t\t\t`path`\t\t='" . mysqli_escape_string($G_STORAGE_CONTROLLER_DBLINK, $G_DEST_PATH_DATA->dir) . "' AND\n\t\t\t\t`name`\t\t='" . mysqli_escape_string($G_STORAGE_CONTROLLER_DBLINK, $G_DEST_PATH_DATA->name) . "'\n\t\t\tLIMIT 1";
$G_DEST_DIR_DATA = mysqli_single_result_query($G_STORAGE_CONTROLLER_DBLINK, $query);
!isset($G_DEST_DIR_DATA['id']) && exit_fail(NQ_ERROR_INVALID_VALUE, LANG_INVALID_DEST_DIR);
# If we aren't allowed in this directory
check_directory_blacklisted($G_CONTROLLER_DBLINK, $G_TOKEN_DATA['id'], $G_TOKEN_SESSION_DATA, $G_DEST_DIR_DATA['path'] . $G_DEST_DIR_DATA['name']);
# If we are updating a directory
if (boolval_ext($_JPOST->is_dir)) {
    # Making sure we have our directory we are trying to move
    $dirname = str_replace(str_split(NQ_INVALID_PATH_CHARS), '', $_JPOST->name);
    $query = "\tSELECT\n\t\t\t\t\t*\n\t\t\t\tFROM\n\t\t\t\t\t" . NQ_DIRECTORY_TABLE . "\n\t\t\t\tWHERE\n\t\t\t\t\t`app_id`\t\t=" . (int) $G_APP_DATA['id'] . " AND\n\t\t\t\t\t`environment`\t\t='" . mysqli_escape_string($G_STORAGE_CONTROLLER_DBLINK, $G_APP_ENVIRONMENT) . "' AND\n\t\t\t\t\t`parent_directory_id`\t=" . (int) $G_SRC_DIR_DATA['id'] . " AND\n\t\t\t\t\t`name`\t\t\t='" . mysqli_escape_string($G_STORAGE_CONTROLLER_DBLINK, $dirname) . "'\n\t\t\t\tLIMIT 1";
    $directory_data = mysqli_single_result_query($G_STORAGE_CONTROLLER_DBLINK, $query);
    !isset($directory_data['id']) && exit_fail(NQ_ERROR_INVALID_VALUE, LANG_INVALID_DIR);
    # If we aren't allowed in this directory
    check_directory_blacklisted($G_STORAGE_CONTROLLER_DBLINK, $G_TOKEN_DATA['id'], $G_TOKEN_SESSION_DATA, $directory_data['path'] . $directory_data['name']);
    # Checking to make sure we don't put the folder inside itself
Esempio n. 14
0
 public function splitFormat(string $path) : array
 {
     $path = rtrim($path, KE_PATH_NOISE);
     $format = '';
     if ($path !== '') {
         $parse = parse_path($path);
         $path = '';
         if ($parse[0] !== '') {
             $path = $parse[0];
         }
         if ($parse[1] !== '') {
             $path .= ($path === '' ? '' : '/') . $parse[1];
         }
         if (isset($parse[2]) && $parse[2] !== '') {
             $format = $parse[2];
         }
     }
     return [$path, $format];
 }
Esempio n. 15
0
      $path['query_utf8'] = urldecode($request_path[1]);
       $path['query'] = utf8_decode(urldecode($request_path[1]));
    $vars = explode('&', $path['query']);
    foreach ($vars as $var) {
      $t = explode('=', $var);
      $path['query_vars'][$t[0]] = $t[1];
    }
    }
   
   
  }
return $path;
}

//first url path
$path = parse_path();
$path_url = $path['call_parts'][1];

//second path
$path_act = (isset($path['call_parts'][2]))?$path['call_parts'][2]:'';
//third path
$path_id = (isset($path['call_parts'][3]))?$path['call_parts'][3]:'';


//simpan role url page user di array sesuai login session level
  $role_user=array();
  $role_act=array();
foreach ($db->fetch_custom("select sys_menu.url from sys_menu inner join sys_menu_role on sys_menu.id=sys_menu_role.id_menu
    where sys_menu_role.group_id=? and sys_menu_role.read_act=?",array('sys_menu_role.group_id'=>$_SESSION['level'],'sys_menu_role.read_act'=>'Y')) as $role) {
  $role_user[]=$role->url;
}
Esempio n. 16
0
 public function __construct()
 {
     $this->address = "/" . parse_path()["call_utf8"];
 }
Esempio n. 17
0
function parseBoardMod($file, $testing = true, $undo = false, $theme_paths = array())
{
    global $boarddir, $sourcedir, $settings, $txt, $modSettings;
    @set_time_limit(600);
    $file = strtr($file, array("\r" => ''));
    $working_file = null;
    $working_search = null;
    $working_data = '';
    $replace_with = null;
    $actions = array();
    $everything_found = true;
    // This holds all the template changes in the standard mod file.
    $template_changes = array();
    // This is just the temporary file.
    $temp_file = $file;
    // This holds the actual changes on a step counter basis.
    $temp_changes = array();
    $counter = 0;
    $step_counter = 0;
    // Before we do *anything*, let's build a list of what we're editing, as it's going to be used for other theme edits.
    while (preg_match('~<(edit file|file|search|search for|add|add after|replace|add before|add above|above|before)>\\n(.*?)\\n</\\1>~is', $temp_file, $code_match) != 0) {
        $counter++;
        // Get rid of the old stuff.
        $temp_file = substr_replace($temp_file, '', strpos($temp_file, $code_match[0]), strlen($code_match[0]));
        // No interest to us?
        if ($code_match[1] != 'edit file' && $code_match[1] != 'file') {
            // It's a step, let's add that to the current steps.
            if (isset($temp_changes[$step_counter])) {
                $temp_changes[$step_counter]['changes'][] = $code_match[0];
            }
            continue;
        }
        // We've found a new edit - let's make ourself heard, kind of.
        $step_counter = $counter;
        $temp_changes[$step_counter] = array('title' => $code_match[0], 'changes' => array());
        $filename = parse_path($code_match[2]);
        // Now, is this a template file, and if so, which?
        foreach ($theme_paths as $id => $theme) {
            // If this filename is relative, if so take a guess at what it should be.
            if (strpos($filename, 'Themes') === 0) {
                $filename = $boarddir . '/' . $filename;
            }
            if (strpos($filename, $theme['theme_dir']) === 0) {
                $template_changes[$id][$counter] = substr($filename, strlen($theme['theme_dir']) + 1);
            }
        }
    }
    // Anything above $counter must be for custom themes.
    $custom_template_begin = $counter;
    // Reference for what theme ID this action belongs to.
    $theme_id_ref = array();
    // Now we know what templates we need to touch, cycle through each theme and work out what we need to edit.
    if (!empty($template_changes[1])) {
        foreach ($theme_paths as $id => $theme) {
            // Don't do default, it means nothing to me.
            if ($id == 1) {
                continue;
            }
            // Now, for each file do we need to edit it?
            foreach ($template_changes[1] as $pos => $template_file) {
                // It does? Add it to the list darlin'.
                if (file_exists($theme['theme_dir'] . '/' . $template_file) && (!isset($template_changes[$id][$pos]) || !in_array($template_file, $template_changes[$id][$pos]))) {
                    // Actually add it to the mod file too, so we can see that it will work ;)
                    if (!empty($temp_changes[$pos]['changes'])) {
                        $file .= "\n\n" . '<edit file>' . "\n" . $theme['theme_dir'] . '/' . $template_file . "\n" . '</edit file>' . "\n\n" . implode("\n\n", $temp_changes[$pos]['changes']);
                        $theme_id_ref[$counter] = $id;
                        $counter += 1 + count($temp_changes[$pos]['changes']);
                    }
                }
            }
        }
    }
    $counter = 0;
    $is_custom = 0;
    while (preg_match('~<(edit file|file|search|search for|add|add after|replace|add before|add above|above|before)>\\n(.*?)\\n</\\1>~is', $file, $code_match) != 0) {
        // This is for working out what we should be editing.
        $counter++;
        // Edit a specific file.
        if ($code_match[1] == 'file' || $code_match[1] == 'edit file') {
            // Backup the old file.
            if ($working_file !== null) {
                package_chmod($working_file);
                // Don't even dare.
                if (basename($working_file) == 'Settings_bak.php') {
                    continue;
                }
                if (!is_writable($working_file)) {
                    $actions[] = array('type' => 'chmod', 'filename' => $working_file);
                }
                if (!$testing && !empty($modSettings['package_make_backups']) && file_exists($working_file)) {
                    if (basename($working_file) == 'Settings.php') {
                        @copy($working_file, dirname($working_file) . '/Settings_bak.php');
                    } else {
                        @copy($working_file, $working_file . '~');
                    }
                }
                package_put_contents($working_file, $working_data, $testing);
            }
            if ($working_file !== null) {
                $actions[] = array('type' => 'saved', 'filename' => $working_file, 'is_custom' => $is_custom);
            }
            // Is this "now working on" file a theme specific one?
            $is_custom = isset($theme_id_ref[$counter - 1]) ? $theme_id_ref[$counter - 1] : 0;
            // Make sure the file exists!
            $working_file = parse_path($code_match[2]);
            if ($working_file[0] != '/' && $working_file[1] != ':') {
                trigger_error('parseBoardMod(): The filename \'' . $working_file . '\' is not a full path!', E_USER_WARNING);
                $working_file = $boarddir . '/' . $working_file;
            }
            if (!file_exists($working_file)) {
                $places_to_check = array($boarddir, $sourcedir, $settings['default_theme_dir'], $settings['default_theme_dir'] . '/languages');
                foreach ($places_to_check as $place) {
                    if (file_exists($place . '/' . $working_file)) {
                        $working_file = $place . '/' . $working_file;
                        break;
                    }
                }
            }
            if (file_exists($working_file)) {
                // Load the new file.
                $working_data = str_replace("\r", '', package_get_contents($working_file));
                $actions[] = array('type' => 'opened', 'filename' => $working_file);
            } else {
                $actions[] = array('type' => 'missing', 'filename' => $working_file);
                $working_file = null;
                $everything_found = false;
            }
            // Can't be searching for something...
            $working_search = null;
        } elseif (($code_match[1] == 'search' || $code_match[1] == 'search for') && $working_file !== null) {
            if ($working_search !== null) {
                $actions[] = array('type' => 'error', 'filename' => $working_file);
                $everything_found = false;
            }
            $working_search = $code_match[2];
        } elseif ($working_search !== null) {
            // This is the base string....
            $replace_with = $code_match[2];
            // Add this afterward...
            if ($code_match[1] == 'add' || $code_match[1] == 'add after') {
                $replace_with = $working_search . "\n" . $replace_with;
            } elseif ($code_match[1] == 'before' || $code_match[1] == 'add before' || $code_match[1] == 'above' || $code_match[1] == 'add above') {
                $replace_with .= "\n" . $working_search;
            }
            // Otherwise.. replace with $replace_with ;).
        }
        // If we have a search string, replace string, and open file..
        if ($working_search !== null && $replace_with !== null && $working_file !== null) {
            // Make sure it's somewhere in the string.
            if ($undo) {
                $temp = $replace_with;
                $replace_with = $working_search;
                $working_search = $temp;
            }
            if (strpos($working_data, $working_search) !== false) {
                $working_data = str_replace($working_search, $replace_with, $working_data);
                $actions[] = array('type' => 'replace', 'filename' => $working_file, 'search' => $working_search, 'replace' => $replace_with, 'search_original' => $working_search, 'replace_original' => $replace_with, 'position' => $code_match[1] == 'replace' ? 'replace' : ($code_match[1] == 'add' || $code_match[1] == 'add after' ? 'before' : 'after'), 'is_custom' => $is_custom, 'failed' => false);
            } else {
                $actions[] = array('type' => 'failure', 'filename' => $working_file, 'search' => $working_search, 'is_custom' => $is_custom, 'search_original' => $working_search, 'replace_original' => $replace_with, 'position' => $code_match[1] == 'replace' ? 'replace' : ($code_match[1] == 'add' || $code_match[1] == 'add after' ? 'before' : 'after'), 'is_custom' => $is_custom, 'failed' => true);
                $everything_found = false;
            }
            // These don't hold any meaning now.
            $working_search = null;
            $replace_with = null;
        }
        // Get rid of the old tag.
        $file = substr_replace($file, '', strpos($file, $code_match[0]), strlen($code_match[0]));
    }
    // Backup the old file.
    if ($working_file !== null) {
        package_chmod($working_file);
        if (!is_writable($working_file)) {
            $actions[] = array('type' => 'chmod', 'filename' => $working_file);
        }
        if (!$testing && !empty($modSettings['package_make_backups']) && file_exists($working_file)) {
            if (basename($working_file) == 'Settings.php') {
                @copy($working_file, dirname($working_file) . '/Settings_bak.php');
            } else {
                @copy($working_file, $working_file . '~');
            }
        }
        package_put_contents($working_file, $working_data, $testing);
    }
    if ($working_file !== null) {
        $actions[] = array('type' => 'saved', 'filename' => $working_file, 'is_custom' => $is_custom);
    }
    $actions[] = array('type' => 'result', 'status' => $everything_found);
    return $actions;
}
Esempio n. 18
0
             $stroke = imagecolorallocate($im, $strokeArray[0], $strokeArray[1], $strokeArray[2]);
             imageline($im, $x1, $y1, $x2, $y2, $stroke);
             break;
         case "text":
             $x = $shape["left"];
             $y = $shape["top"];
             $text = $shape["text"];
             $size = $shape["textSize"];
             $fillArray = sscanf($shape['fillColor'], '#%2x%2x%2x');
             $fill = imagecolorallocate($im, $fillArray[0], $fillArray[1], $fillArray[2]);
             imagettftext($im, $size / 1.3, 0, $x, $y, $fill, "FONT/times.ttf", $text);
             //$font = imageloadfont('./04b.gdf');
             //imagestring($im, $font, $x, $y, $text, $fill);
             break;
         case "path":
             $points = parse_path($shape["points"]);
             //echo count($points).";";
             $fillArray = sscanf($shape['fillColor'], '#%2x%2x%2x');
             $fill = imagecolorallocate($im, $fillArray[0], $fillArray[1], $fillArray[2]);
             imagefilledpolygon($im, $points, count($points) / 2, $fill);
             imagesetthickness($im, $shape["lineWidth"]);
             $strokeArray = sscanf($shape['lineColor'], '#%2x%2x%2x');
             $stroke = imagecolorallocate($im, $strokeArray[0], $strokeArray[1], $strokeArray[2]);
             imagepolygon($im, $points, count($points) / 2, $stroke);
             $points = array();
             break;
     }
 }
 ob_start();
 imagegif($im);
 imagedestroy($im);