Example #1
0
function wikiplugin_snarf($data, $params)
{
    global $tikilib;
    if (!isset($params['url'])) {
        return "<b>" . tra("Missing url parameter for SNARF plugin.") . "</b><br />";
    }
    if (function_exists("curl_init")) {
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $params['url']);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 2);
        curl_setopt($curl, CURLOPT_TIMEOUT, 2);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($curl, CURLOPT_HEADER, false);
        curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
        curl_setopt($curl, CURLOPT_USERAGENT, "TikiWiki Snarf");
        $snarf = curl_exec($curl);
        curl_close($curl);
        // If content is HTML, keep only the content of the body
        if (isset($params['ishtml']) && $params['ishtml'] == 1) {
            // Not using preg_replace due to its limitations to 100.000 characters
            $snarf = eregi_replace('^.*<\\s*body[^>]*>', '', $snarf);
            $snarf = eregi_replace('<\\s*\\/body[^>]*>.*$', '', $snarf);
        }
        // If the user specified a more specialized regex
        if (isset($params['regex']) && isset($params['regexres']) && preg_match('/^(.)(.)+\\1[^e]*$/', $params['regex'])) {
            $snarf = preg_replace($params['regex'], $params['regexres'], $snarf);
        }
        if ($data == '') {
            $data = NULL;
        }
        $code_defaults = array('caption' => $data, 'wrap' => '1', 'colors' => NULL, 'wiki' => '0', 'ln' => NULL, 'rtl' => NULL, 'ishtml' => NULL);
        foreach ($code_defaults as $k => $v) {
            if (isset($params[$k])) {
                $code_defaults[$k] = $params[$k];
            }
            if ($code_defaults[$k] === NULL) {
                unset($code_defaults[$k]);
            }
        }
        include_once 'lib/wiki-plugins/wikiplugin_code.php';
        $ret = wikiplugin_code($snarf, $code_defaults);
    } else {
        $ret = "<p>You need php-curl for the SNARF plugin!</p>\n";
    }
    return $ret;
}
Example #2
0
 /**
  * @dataProvider provider
  */
 public function testWikiPluginCode($data, $expectedOutput, $params = array())
 {
     $this->markTestSkipped("As of 2013-09-30, this tesst is broken. Skipping it for now.");
     $this->assertEquals($expectedOutput, wikiplugin_code($data, $params));
 }
Example #3
0
$assigned_modules_for_export = $modlib->getModulesForExport();
$smarty->assign('modules_for_export', $assigned_modules_for_export);
if (!isset($_REQUEST['export_type'])) {
    $_REQUEST['export_type'] = 'prefs';
}
$smarty->assign('export_type', $_REQUEST['export_type']);
if (isset($_REQUEST['export'])) {
    if ($_REQUEST['export_type'] === 'prefs') {
        $export_yaml = Horde_Yaml::dump(array('preferences' => $_REQUEST['prefs_to_export']), array('indent' => 1, 'wordwrap' => 0));
    } else {
        if ($_REQUEST['export_type'] === 'modules') {
            $modules_to_export = array();
            foreach ($_REQUEST['modules_to_export'] as $k => $v) {
                $modules_to_export[] = $assigned_modules_for_export[$k];
            }
            $export_yaml = Horde_Yaml::dump(array('objects' => $modules_to_export), array('indent' => 1, 'wordwrap' => 0));
        } else {
            $export_yaml = '';
            // something went wrong?
        }
    }
    $export_yaml = preg_replace('/^---\\n/', '', $export_yaml);
    $export_yaml = "{CODE(caption=>YAML,wrap=>0)}\n" . $export_yaml . "{CODE}\n";
    include_once 'lib/wiki-plugins/wikiplugin_code.php';
    $export_yaml = wikiplugin_code($export_yaml, array('caption' => 'Wiki markup', 'colors' => 'tiki'), null, array());
    $export_yaml = preg_replace('/~[\\/]?np~/', '', $export_yaml);
    $smarty->assign('export_yaml', $export_yaml);
    $smarty->assign('prefs_to_export', $_REQUEST['prefs_to_export']);
    $smarty->assign('modules_to_export', $_REQUEST['modules_to_export']);
}
ask_ticket('admin-inc-profiles');
Example #4
0
 function action_export_profile($input)
 {
     if (!Perms::get()->admin_trackers) {
         throw new Services_Exception_Denied(tr('Reserved to tracker administrators'));
     }
     $trackerId = $input->trackerId->int();
     $profile = Tiki_Profile::fromString('dummy', '');
     $data = array();
     $profileObject = new Tiki_Profile_Object($data, $profile);
     $profileTrackerInstallHandler = new Tiki_Profile_InstallHandler_Tracker($profileObject, array());
     $export_yaml = $profileTrackerInstallHandler->_export($trackerId, $profileObject);
     include_once 'lib/wiki-plugins/wikiplugin_code.php';
     $export_yaml = wikiplugin_code($export_yaml, array('caption' => 'YAML', 'colors' => 'yaml'));
     $export_yaml = preg_replace('/~[\\/]?np~/', '', $export_yaml);
     return array('trackerId' => $trackerId, 'yaml' => $export_yaml);
 }
Example #5
0
function wikiplugin_snarf($data, $params)
{
    global $prefs;
    static $url = '';
    static $snarf;
    static $isFresh = true;
    static $iSnarf = 0;
    ++$iSnarf;
    if (empty($params['url'])) {
        return '';
    }
    $smarty = TikiLib::lib('smarty');
    $tikilib = TikiLib::lib('tiki');
    if (!empty($params['ajax'])) {
        $params['iSnarf'] = $iSnarf;
        $params['href'] = '';
        $params['link'] = '-';
        foreach ($params as $key => $value) {
            if ($key == 'ajax' || $key == 'href') {
                continue;
            }
            if (!empty($params['href'])) {
                $params['href'] .= '&amp;';
            }
            $params['href'] .= $key . '=' . urlencode($value);
        }
        $smarty->assign('snarfParams', $params);
        return $smarty->fetch('wiki-plugins/wikiplugin_snarf.tpl');
    }
    if ($url != $params['url']) {
        // already fetch in the page
        if (isset($_REQUEST['snarf_refresh']) && $_REQUEST['snarf_refresh'] == $params['url']) {
            $cachetime = 0;
            unset($_REQUEST['snarf_refresh']);
        } elseif (isset($params['cache']) && $params['cache'] >= 0) {
            $cachetime = $params['cache'] * 60;
        } else {
            $cachetime = $prefs['wikiplugin_snarf_cache'];
        }
        $info = $tikilib->get_cached_url($params['url'], $isFresh, $cachetime);
        $snarf = $info['data'];
        $url = $params['url'];
    }
    // If content is HTML, keep only the content of the body
    if (isset($params['ishtml']) && $params['ishtml'] == 1) {
        // Not using preg_replace due to its limitations to 100.000 characters
        $snarf = preg_replace('/^.*<\\s*body[^>]*>/i', '', $snarf);
        $snarf = preg_replace('/<\\s*\\/body[^>]*>.*$/i', '', $snarf);
    }
    // If the user specified a more specialized regex
    if (isset($params['regex']) && isset($params['regexres'])) {
        // fixes http://dev.tiki.org/item4059
        $params['regex'] = str_replace("", "", $params['regex']);
        if (preg_match('/^(.)(.)+\\1[^e]*$/', $params['regex'])) {
            $snarf = preg_replace($params['regex'], $params['regexres'], $snarf);
        }
    }
    if ($data == '') {
        $data = NULL;
    }
    $code_defaults = array('caption' => $data, 'wrap' => '1', 'colors' => NULL, 'wiki' => '0', 'ln' => NULL, 'rtl' => NULL, 'ishtml' => NULL);
    foreach ($code_defaults as $k => $v) {
        if (isset($params[$k])) {
            $code_defaults[$k] = $params[$k];
        }
        if ($code_defaults[$k] === NULL) {
            unset($code_defaults[$k]);
        }
    }
    include_once 'lib/wiki-plugins/wikiplugin_code.php';
    $ret = wikiplugin_code($snarf, $code_defaults);
    if (!$isFresh && empty($params['link'])) {
        include_once 'lib/smarty_tiki/block.self_link.php';
        $icon = '<div style="text-align:right">' . smarty_block_self_link(array('_icon' => 'arrow_refresh', 'snarf_refresh' => $params['url']), '', $smarty) . '</div>';
        $ret = $icon . $ret;
    }
    return $ret;
}
Example #6
0
 /**
  * @dataProvider provider
  */
 public function testWikiPluginCode($data, $expectedOutput, $params = array())
 {
     $this->assertEquals($expectedOutput, wikiplugin_code($data, $params));
 }