Example #1
0
 /**
  * Checks if route info is valid and performs any required sanitation
  *
  * @param array $data
  * @return bool Returns TRUE iff data is valid
  */
 protected static function validInput(array &$data)
 {
     //if we have nothing we set actions to create, settings
     //if we have a channelid and no action1 or 2 we set actions to create, settings.
     //if we have no channelid and anything but create, settings then we throw an exception
     // if no action is defined, use index
     if (empty($data[self::$actionKey])) {
         $data[self::$actionKey] = 'create';
     }
     if (empty($data['action2'])) {
         $data['action2'] = 'settings';
     }
     if (!isset($data['guid']) or empty($data['guid'])) {
         $data['guid'] = vB_Xml_Export_Route::createGUID($data);
     }
     if ($data[self::$actionKey] == 'admin') {
         return isset($data['nodeid']) and in_array($data['action2'], self::$adminActions);
     }
     if ($data[self::$actionKey] == 'create') {
         return in_array($data['action2'], self::$createActions);
     }
     return false;
 }
Example #2
0
 /**
  * Checks if route info is valid and performs any required sanitation
  *
  * @param array $data
  * @return bool Returns TRUE iff data is valid
  */
 protected static function validInput(array &$data)
 {
     if (!isset($data['guid']) or empty($data['guid'])) {
         $data['guid'] = vB_Xml_Export_Route::createGUID($data);
     }
     $prefixLength = strlen($data['prefix']);
     if (!isset($data['prefix']) or $prefixLength > self::PREFIX_MAXSIZE) {
         if (defined('VB_AREA') and in_array(VB_AREA, array('Install', 'Upgrade'))) {
             // We need to automatically shorten the URL
             $parts = array_reverse(explode('/', $data['prefix']));
             $newPath[] = $part = array_shift($parts);
             $length = strlen($part);
             if ($length > self::PREFIX_MAXSIZE) {
                 // the last element is itself too long
                 $newPrefix = substr($part, 0, self::PREFIX_MAXSIZE);
             } else {
                 // prepend parts until we reach the limit
                 while ($part = array_shift($parts) and $length + 1 + strlen($part) <= self::PREFIX_MAXSIZE) {
                     array_unshift($newPath, $part);
                     $length += 1 + strlen($part);
                 }
                 $newPrefix = implode('/', $newPath);
             }
             // replace in regex
             $data['regex'] = preg_replace("#^{$data['prefix']}#", $newPrefix, $data['regex']);
             $data['prefix'] = $newPrefix;
         } else {
             throw new vB_Exception_Api('url_too_long', array($prefixLength, self::PREFIX_MAXSIZE));
         }
     }
     if (!isset($data['regex']) or strlen($data['regex']) > self::REGEX_MAXSIZE) {
         return false;
     }
     return true;
 }
function get_product_export_xml($productid)
{
    $assertor = vB::getDbAssertor();
    //	Set up the parent tag
    $product_details = $assertor->getRow('product', array('productid' => $productid));
    if (!$product_details) {
        throw new vB_Exception_AdminStopMessage('invalid_product_specified');
    }
    $xml = new vB_XML_Builder();
    // ############## main product info
    $xml->add_group('product', array('productid' => strtolower($product_details['productid']), 'active' => $product_details['active']));
    // Parent for product
    $xml->add_tag('title', $product_details['title']);
    $xml->add_tag('description', $product_details['description']);
    $xml->add_tag('version', $product_details['version']);
    $xml->add_tag('url', $product_details['url']);
    $xml->add_tag('versioncheckurl', $product_details['versioncheckurl']);
    // ############## dependencies
    $product_dependencies = $assertor->assertQuery('productdependency', array('productid' => $productid), array('field' => array('dependencytype', 'parentproductid', 'minversion'), 'direction' => array(vB_dB_Query::SORT_ASC, vB_dB_Query::SORT_ASC, vB_dB_Query::SORT_ASC)));
    $xml->add_group('dependencies');
    while ($product_dependencies and $product_dependencies->valid()) {
        $product_dependency = $product_dependencies->current();
        $deps = array('dependencytype' => $product_dependency['dependencytype']);
        if ($product_dependency['dependencytype'] == 'product') {
            $deps['parentproductid'] = $product_dependency['parentproductid'];
        }
        $deps['minversion'] = $product_dependency['minversion'];
        $deps['maxversion'] = $product_dependency['maxversion'];
        $xml->add_tag('dependency', '', $deps);
        $product_dependencies->next();
    }
    unset($product_dependency);
    $xml->close_group();
    // ############## install / uninstall codes
    $productcodes = $assertor->getRows('productcode', array('productid' => $productid));
    $xml->add_group('codes');
    $productcodes_grouped = array();
    $productcodes_versions = array();
    foreach ($productcodes as $productcode) {
        // have to be careful here, as version numbers are not necessarily unique
        $productcodes_versions["{$productcode['version']}"] = 1;
        $productcodes_grouped["{$productcode['version']}"][] = $productcode;
    }
    $productcodes_versions = array_keys($productcodes_versions);
    usort($productcodes_versions, 'version_sort');
    foreach ($productcodes_versions as $version) {
        foreach ($productcodes_grouped["{$version}"] as $productcode) {
            $xml->add_group('code', array('version' => $productcode['version']));
            $xml->add_tag('installcode', $productcode['installcode']);
            $xml->add_tag('uninstallcode', $productcode['uninstallcode']);
            $xml->close_group();
        }
    }
    $xml->close_group();
    // ############## templates
    $gettemplates = $assertor->assertQuery('template', array('product' => $productid, 'styleid' => -1), 'title');
    $xml->add_group('templates');
    while ($gettemplates and $gettemplates->valid()) {
        $template = $gettemplates->current();
        if (is_newer_version($template['version'], $product_details['version'])) {
            // version in the template is newer than the version of the product,
            // which probably means it's using the vB version
            $template['version'] = $product_details['version'];
        }
        $xml->add_tag('template', $template['templatetype'] == 'template' ? $template['template_un'] : $template['template'], array('name' => htmlspecialchars($template['title']), 'templatetype' => $template['templatetype'], 'date' => $template['dateline'], 'username' => $template['username'], 'version' => htmlspecialchars_uni($template['version'])), true);
        $gettemplates->next();
    }
    $xml->close_group();
    // ############## Stylevars
    $stylevarinfo = get_stylevars_for_export($productid, -1);
    $stylevar_cache = $stylevarinfo['stylevars'];
    $stylevar_dfn_cache = $stylevarinfo['stylevardfns'];
    $xml->add_group('stylevardfns');
    foreach ($stylevar_dfn_cache as $stylevargroupname => $stylevargroup) {
        $xml->add_group('stylevargroup', array('name' => $stylevargroupname));
        foreach ($stylevargroup as $stylevar) {
            $xml->add_tag('stylevar', '', array('name' => htmlspecialchars($stylevar['stylevarid']), 'datatype' => $stylevar['datatype'], 'validation' => base64_encode($stylevar['validation']), 'failsafe' => base64_encode($stylevar['failsafe'])));
        }
        $xml->close_group();
    }
    $xml->close_group();
    $xml->add_group('stylevars');
    foreach ($stylevar_cache as $stylevarid => $stylevar) {
        $xml->add_tag('stylevar', '', array('name' => htmlspecialchars($stylevar['stylevarid']), 'value' => base64_encode($stylevar['value'])));
    }
    $xml->close_group();
    // ############## hooks
    $xml->add_group('hooks');
    $hooks = vB_Api::instanceInternal("Hook")->getHookList(array('hookname'), array('product' => $productid));
    foreach ($hooks as $hook) {
        $xml->add_group('hook');
        $xml->add_tag('hookname', $hook['hookname']);
        $xml->add_tag('title', $hook['title']);
        $xml->add_tag('active', $hook['active']);
        $xml->add_tag('hookorder', $hook['hookorder']);
        $xml->add_tag('template', $hook['template']);
        $xml->add_tag('arguments', $hook['arguments']);
        $xml->close_group();
    }
    $xml->close_group();
    // ############## phrases
    $phrasetypes = vB_Api::instanceInternal('phrase')->fetch_phrasetypes(false);
    $phrases = array();
    $getphrases = $assertor->getRows('vBForum:phrase', array('languageid' => array(-1, 0), 'product' => $productid), array('languageid', 'fieldname', 'varname'));
    foreach ($getphrases as $getphrase) {
        $phrases["{$getphrase['fieldname']}"]["{$getphrase['varname']}"] = $getphrase;
    }
    $xml->add_group('phrases');
    // make sure the phrasegroups are in a reliable order
    ksort($phrases);
    foreach ($phrases as $_fieldname => $typephrases) {
        // create a group for each phrase type that we have phrases for
        // then insert the phrases
        $xml->add_group('phrasetype', array('name' => $phrasetypes["{$_fieldname}"]['title'], 'fieldname' => $_fieldname));
        // make sure the phrases are in a reliable order
        ksort($typephrases);
        foreach ($typephrases as $phrase) {
            $xml->add_tag('phrase', $phrase['text'], array('name' => $phrase['varname'], 'date' => $phrase['dateline'], 'username' => $phrase['username'], 'version' => htmlspecialchars_uni($phrase['version'])), true);
        }
        $xml->close_group();
    }
    $xml->close_group();
    // ############## options
    $setting = array();
    $settinggroup = array();
    $groups = $assertor->getRows('settinggroup', array('volatile' => 1), array('displayorder', 'grouptitle'));
    foreach ($groups as $group) {
        $settinggroup["{$group['grouptitle']}"] = $group;
    }
    ksort($settinggroup);
    $options = $assertor->getRows('setting', array('product' => $productid, 'volatile' => 1), array('displayorder', 'varname'));
    foreach ($options as $row) {
        $setting["{$row['grouptitle']}"][] = $row;
    }
    $xml->add_group('options');
    foreach ($settinggroup as $grouptitle => $group) {
        if (empty($setting["{$grouptitle}"])) {
            continue;
        }
        // add a group for each setting group we have settings for
        $newGroup = array('name' => htmlspecialchars($group['grouptitle']), 'displayorder' => $group['displayorder']);
        if (!empty($group['adminperm'])) {
            $newGroup['adminperm'] = $group['adminperm'];
        }
        $xml->add_group('settinggroup', $newGroup);
        ksort($setting["{$grouptitle}"]);
        foreach ($setting["{$grouptitle}"] as $set) {
            $arr = array('varname' => $set['varname'], 'displayorder' => $set['displayorder']);
            if ($set['advanced']) {
                $arr['advanced'] = 1;
            }
            $xml->add_group('setting', $arr);
            if ($set['datatype']) {
                $xml->add_tag('datatype', $set['datatype']);
            }
            if ($set['optioncode'] != '') {
                $xml->add_tag('optioncode', $set['optioncode']);
            }
            if ($set['validationcode']) {
                $xml->add_tag('validationcode', $set['validationcode']);
            }
            if ($set['defaultvalue'] !== '') {
                $xml->add_tag('defaultvalue', $set['defaultvalue']);
            }
            if ($set['blacklist']) {
                $xml->add_tag('blacklist', 1);
            }
            if ($set['ispublic']) {
                $xml->add_tag('public', 1);
            }
            if ($set['adminperm']) {
                $xml->add_tag('adminperm', $set['adminperm']);
            }
            $xml->close_group();
        }
        $xml->close_group();
    }
    $xml->close_group();
    // ############## admin help
    $help_topics_results = $assertor->getRows('vBForum:adminhelp', array('product' => $productid, 'volatile' => 1), array('script', 'action', 'displayorder', 'optionname'));
    $help_topics = array();
    foreach ($help_topics_results as $help_topic) {
        $help_topics["{$help_topic['script']}"][] = $help_topic;
    }
    ksort($help_topics);
    $xml->add_group('helptopics');
    foreach ($help_topics as $script => $script_topics) {
        $xml->add_group('helpscript', array('name' => $script));
        foreach ($script_topics as $topic) {
            $attr = array('disp' => $topic['displayorder']);
            if ($topic['action']) {
                $attr['act'] = $topic['action'];
            }
            if ($topic['optionname']) {
                $attr['opt'] = $topic['optionname'];
            }
            $xml->add_tag('helptopic', '', $attr);
        }
        $xml->close_group();
    }
    $xml->close_group();
    // ############## Cron entries
    $cron_results = $assertor->getRows('cron', array(vB_dB_Query::CONDITIONS_KEY => array(array('field' => 'product', 'value' => $productid, vB_dB_Query::OPERATOR_KEY => vB_dB_Query::OPERATOR_EQ), array('field' => 'volatile', 'value' => 1, vB_dB_Query::OPERATOR_KEY => vB_dB_Query::OPERATOR_EQ), array('field' => 'varname', 'value' => '', vB_dB_Query::OPERATOR_KEY => vB_dB_Query::OPERATOR_NE))));
    $xml->add_group('cronentries');
    foreach ($cron_results as $cron) {
        $minutes = unserialize($cron['minute']);
        if (!is_array($minutes)) {
            $minutes = array();
        }
        $xml->add_group('cron', array('varname' => $cron['varname'], 'active' => $cron['active'], 'loglevel' => $cron['loglevel']));
        $xml->add_tag('filename', $cron['filename']);
        $xml->add_tag('scheduling', '', array('weekday' => $cron['weekday'], 'day' => $cron['day'], 'hour' => $cron['hour'], 'minute' => implode(',', $minutes)));
        $xml->close_group();
    }
    $xml->close_group();
    $faq_results = $assertor->getRows('vBForum:faq', array('product' => $productid, 'volatile' => 1), 'faqname');
    $xml->add_group('faqentries');
    foreach ($faq_results as $faq) {
        $xml->add_tag('faq', '', array('faqname' => $faq['faqname'], 'faqparent' => $faq['faqparent'], 'displayorder' => $faq['displayorder']));
    }
    $xml->close_group();
    // ############## widgets
    $widgetExporter = new vB_Xml_Export_Widget($productid);
    $widgetExporter->getXml($xml);
    // ############## pagetemplates
    $pageTemplateExporter = new vB_Xml_Export_PageTemplate($productid);
    $pageTemplateExporter->getXml($xml);
    // ############## pages
    $pageExporter = new vB_Xml_Export_Page($productid);
    $pageExporter->getXml($xml);
    // ############## channels
    $channelExporter = new vB_Xml_Export_Channel($productid);
    $channelExporter->getXml($xml);
    // ############## routes
    $routeExporter = new vB_Xml_Export_Route($productid);
    $routeExporter->getXml($xml);
    // ############## Finish up
    $xml->close_group();
    $doc = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\r\n\r\n" . $xml->output();
    unset($xml);
    return $doc;
}