/**
  * Handle matches of the <feedaggregator> tag, storing the list of feeds in
  * a file in the ~/data/tmp/feedaggregator directory.
  *
  * @param string $match The match of the syntax
  * @param int    $state The state of the handler
  * @param int    $pos The position in the document
  * @param Doku_Handler    $handler The handler
  * @return array Data for the renderer
  */
 public function handle($match, $state, $pos, Doku_Handler $handler)
 {
     global $conf;
     $data = array();
     // Are we to handle this match? If not, don't.
     if ($state !== DOKU_LEXER_UNMATCHED) {
         return $data;
     }
     // Get the feed URLs.
     $matchedFeeds = preg_split('/[\\n\\r]+/', $match, -1, PREG_SPLIT_NO_EMPTY);
     $feeds = array();
     foreach ($matchedFeeds as $feed) {
         if (filter_var($feed, FILTER_VALIDATE_URL) === false) {
             msg("Feed URL not valid: <code>{$feed}</code>", 2);
             continue;
         }
         $feeds[] = $feed;
     }
     $feedList = array_unique($feeds);
     // Save the feeds to a temporary CSV. It'll be ready by the action script.
     $file = fullpath($conf['tmpdir'] . '/feedaggregator.csv');
     file_put_contents($file, join("\n", $feedList));
     // Get the most-recently generated HTML feed aggregation. This won't be
     // up to date with the above feeds yet, but that's okay.
     $data['html'] = io_readFile(fullpath($conf['cachedir'] . '/feedaggregator/output.html'));
     return $data;
 }
Beispiel #2
0
 /**
  * Loads the template for a new blog post and does some text replacements
  *
  * @author Gina Haeussge <*****@*****.**>
  */
 function _prepare_template($id, $title)
 {
     $tpl = io_readFile(DOKU_PLUGIN . 'blogtng/tpl/newentry.txt');
     $replace = array('@TITLE@' => $title);
     $tpl = str_replace(array_keys($replace), array_values($replace), $tpl);
     return $tpl;
 }
 function pagefromtemplate(&$event, $param)
 {
     if (strlen(trim($_REQUEST['newpagetemplate'])) > 0) {
         global $conf;
         global $INFO;
         global $ID;
         $tpl = io_readFile(wikiFN($_REQUEST['newpagetemplate']));
         if ($this->getConf('userreplace')) {
             $stringvars = array_map(create_function('$v', 'return explode(",",$v,2);'), explode(';', $_REQUEST['newpagevars']));
             foreach ($stringvars as $value) {
                 $tpl = str_replace(trim($value[0]), trim($value[1]), $tpl);
             }
         }
         if ($this->getConf('standardreplace')) {
             // replace placeholders
             $file = noNS($ID);
             $page = strtr($file, '_', ' ');
             $tpl = str_replace(array('@ID@', '@NS@', '@FILE@', '@!FILE@', '@!FILE!@', '@PAGE@', '@!PAGE@', '@!!PAGE@', '@!PAGE!@', '@USER@', '@NAME@', '@MAIL@', '@DATE@'), array($ID, getNS($ID), $file, utf8_ucfirst($file), utf8_strtoupper($file), $page, utf8_ucfirst($page), utf8_ucwords($page), utf8_strtoupper($page), $_SERVER['REMOTE_USER'], $INFO['userinfo']['name'], $INFO['userinfo']['mail'], $conf['dformat']), $tpl);
             // we need the callback to work around strftime's char limit
             $tpl = preg_replace_callback('/%./', create_function('$m', 'return strftime($m[0]);'), $tpl);
         }
         $event->result = $tpl;
         $event->preventDefault();
     }
 }
Beispiel #4
0
/**
 * Check for new messages from upstream
 *
 * @author Andreas Gohr <*****@*****.**>
 */
function checkUpdateMessages()
{
    global $conf;
    global $INFO;
    global $updateVersion;
    if (!$conf['updatecheck']) {
        return;
    }
    if ($conf['useacl'] && !$INFO['ismanager']) {
        return;
    }
    $cf = $conf['cachedir'] . '/messages.txt';
    $lm = @filemtime($cf);
    // check if new messages needs to be fetched
    if ($lm < time() - 60 * 60 * 24 || $lm < @filemtime(DOKU_INC . DOKU_SCRIPT)) {
        @touch($cf);
        dbglog("checkUpdatesMessages(): downloading messages.txt");
        $http = new DokuHTTPClient();
        $http->timeout = 12;
        $data = $http->get(DOKU_MESSAGEURL . $updateVersion);
        io_saveFile($cf, $data);
    } else {
        dbglog("checkUpdatesMessages(): messages.txt up to date");
        $data = io_readFile($cf);
    }
    // show messages through the usual message mechanism
    $msgs = explode("\n%\n", $data);
    foreach ($msgs as $msg) {
        if ($msg) {
            msg($msg, 2);
        }
    }
}
Beispiel #5
0
/**
 * this converts individual discussion pages to .comment meta files
 */
function convertDiscussionPage($file)
{
    // read the old file
    $data = io_readFile($file['old'], false);
    // handle file with no comments yet
    if (trim($data) == '') {
        io_saveFile($file['new'], serialize(array('status' => 1, 'number' => 0)));
        @unlink($file['old']);
        return true;
    }
    // break it up into pieces
    $old = explode('----', $data);
    // merge with possibly already existing (newer) comments
    $comments = array();
    if (@file_exists($file['new'])) {
        $comments = unserialize(io_readFile($file['old'], false));
    }
    // set general info
    if (!isset($comments['status'])) {
        $comments['status'] = 1;
    }
    $comments['number'] += count($old);
    foreach ($old as $comment) {
        // prepare comment data
        if (strpos($comment, '<sub>') !== false) {
            $in = '<sub>';
            $out = ':</sub>';
        } else {
            $in = '//';
            $out = ': //';
        }
        list($meta, $raw) = explode($out, $comment, 2);
        $raw = trim($raw);
        // skip empty comments
        if (!$raw) {
            $comments['number']--;
            continue;
        }
        list($mail, $meta) = explode($in, $meta, 2);
        list($name, $strd) = explode(', ', $meta, 2);
        $date = strtotime($strd);
        if ($date == -1) {
            $date = time();
        }
        if ($mail) {
            list($mail) = explode(' |', $mail, 2);
            $mail = substr(strrchr($mail, '>'), 1);
        }
        $cid = md5($name . $date);
        // render comment
        $xhtml = p_render('xhtml', p_get_instructions($raw), $info);
        // fill in the converted comment
        $comments['comments'][$cid] = array('user' => array('name' => hsc($name), 'mail' => hsc($mail)), 'date' => array('created' => $date), 'show' => true, 'raw' => $raw, 'xhtml' => $xhtml, 'replies' => array());
    }
    // save the new file
    io_saveFile($file['new'], serialize($comments));
    // remove the old file
    @unlink($file['old']);
    return true;
}
Beispiel #6
0
 /**
  * Handle the match
  */
 function handle($match, $state, $pos, &$handler)
 {
     global $ID;
     global $ACT;
     // don't show linkback section on blog mainpages
     if (defined('IS_BLOG_MAINPAGE')) {
         return false;
     }
     // don't allow usage of syntax in comments
     if (isset($_REQUEST['comment'])) {
         return false;
     }
     // get linkback meta file name
     $file = metaFN($ID, '.linkbacks');
     $data = array('send' => false, 'receive' => false, 'display' => false, 'sentpings' => array(), 'receivedpings' => array(), 'number' => 0);
     if (@file_exists($file)) {
         $data = unserialize(io_readFile($file, false));
     }
     if ($match == '~~LINKBACK~~') {
         $data['receive'] = true;
         $data['display'] = true;
     } else {
         if ($match == '~~LINKBACK:off~~') {
             $data['receive'] = false;
             $data['display'] = false;
         } else {
             $data['receive'] = false;
             $data['display'] = true;
         }
     }
     io_saveFile($file, serialize($data));
 }
 /**
  * Handle the match
  */
 function handle($match, $state, $pos, &$handler)
 {
     global $ID, $ACT;
     // strip markup
     $match = substr($match, 12, -2);
     // split title (if there is one)
     list($match, $title) = explode('|', $match, 2);
     // assign discussion state
     if ($match == ':off') {
         $status = 0;
     } else {
         if ($match == ':closed') {
             $status = 2;
         } else {
             $status = 1;
         }
     }
     if ($ACT == 'preview') {
         return;
     }
     // get discussion meta file name
     $file = metaFN($ID, '.comments');
     $data = array();
     if (@file_exists($file)) {
         $data = unserialize(io_readFile($file, false));
     }
     $data['title'] = $title;
     $data['status'] = $status;
     io_saveFile($file, serialize($data));
     return $status;
 }
Beispiel #8
0
/**
 * Check for new messages from upstream
 *
 * @author Andreas Gohr <*****@*****.**>
 */
function checkUpdateMessages()
{
    global $conf;
    global $INFO;
    if (!$conf['updatecheck']) {
        return;
    }
    if ($conf['useacl'] && !$INFO['ismanager']) {
        return;
    }
    $cf = $conf['cachedir'] . '/messages.txt';
    $lm = @filemtime($cf);
    // check if new messages needs to be fetched
    if ($lm < time() - 60 * 60 * 24 || $lm < @filemtime(DOKU_CONF . 'msg')) {
        $num = @file(DOKU_CONF . 'msg');
        $num = is_array($num) ? (int) $num[0] : 0;
        $http = new DokuHTTPClient();
        $http->timeout = 8;
        $data = $http->get(DOKU_MESSAGEURL . $num);
        io_saveFile($cf, $data);
    } else {
        $data = io_readFile($cf);
    }
    // show messages through the usual message mechanism
    $msgs = explode("\n%\n", $data);
    foreach ($msgs as $msg) {
        if ($msg) {
            msg($msg, 2);
        }
    }
}
Beispiel #9
0
function _fail()
{
    header("HTTP/1.0 404 Not Found");
    header('Content-Type: image/png');
    echo io_readFile('broken.png', false);
    exit;
}
 /**
  * @depends test_ext_bz2
  */
 function test_bzfiles()
 {
     $this->assertEquals("The\nTest\n", io_readFile(__DIR__ . '/io_readfile/test.txt.bz2'));
     $this->assertEquals("The\r\nTest\r\n", io_readFile(__DIR__ . '/io_readfile/test.txt.bz2', false));
     $this->assertEquals(false, io_readFile(__DIR__ . '/io_readfile/nope.txt.bz2'));
     // this test hangs
     //$this->assertEquals(false, io_readFile(__DIR__.'/io_readfile/corrupt.txt.bz2'));
 }
Beispiel #11
0
 function _write($file)
 {
     $contents = "The\nWrite\nTest\n";
     $this->assertTrue(io_saveFile($file, $contents));
     $this->assertEquals($contents, io_readFile($file));
     $this->assertTrue(io_saveFile($file, $contents, true));
     $this->assertEquals($contents . $contents, io_readFile($file));
 }
Beispiel #12
0
 function __construct()
 {
     $this->script_file = metaFN('epub:cache', '.ser');
     $this->cache = unserialize(io_readFile($this->script_file, false));
     if (!$this->cache) {
         $this->cache = array();
     }
 }
Beispiel #13
0
 function __construct()
 {
     $this->script_file = metaFN('quickstats:cache', '.ser');
     $this->cache = unserialize(io_readFile($this->script_file, false));
     if (!$this->cache) {
         $this->cache = array();
     }
     $this->cc_arrays = new ccArraysDat();
 }
 /**
  * Load the data from disk
  *
  * @param string $service
  * @return array
  */
 protected function loadServiceFile($service)
 {
     $file = $this->getServiceFile($service);
     if (file_exists($file)) {
         return unserialize(io_readFile($file, false));
     } else {
         return array();
     }
 }
 function test_fullsyntax()
 {
     $input = io_readFile(dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.txt');
     $this->assertTrue(strlen($input) > 1000);
     // make sure we got what we want
     $output = $this->render($input);
     $input = $this->noWS($input);
     $output = $this->noWS($output);
     $this->assertEquals($input, $output);
 }
 function test_delete()
 {
     $file = TMP_DIR . '/test.txt';
     $contents = "The\nDelete\nDelete01\nDelete02\nDelete\nDeleteX\nTest\n";
     io_saveFile($file, $contents);
     $this->assertTrue(io_deleteFromFile($file, "Delete\n"));
     $this->assertEquals("The\nDelete01\nDelete02\nDeleteX\nTest\n", io_readFile($file));
     $this->assertTrue(io_deleteFromFile($file, "#Delete\\d+\n#", true));
     $this->assertEquals("The\nDeleteX\nTest\n", io_readFile($file));
 }
Beispiel #17
0
 function render($mode, &$renderer, $data)
 {
     if ($mode == 'xhtml') {
         list($inc, $tplname) = $data;
         $file = DOKU_INC . 'lib/tpl/' . $tplname . '/style.ini';
         $renderer->code(io_readFile($file), 'ini');
         return true;
     }
     return false;
 }
 /**
  * Should carry out any processing required by the plugin.
  */
 public function handle()
 {
     global $INPUT;
     global $ID;
     global $config_cascade;
     $config_file_path = end($config_cascade['main']['local']);
     // form submit
     $table = Schema::cleanTableName($INPUT->str('table'));
     if ($table && $INPUT->bool('save') && checkSecurityToken()) {
         $builder = new SchemaBuilder($table, $INPUT->arr('schema'));
         if (!$builder->build()) {
             msg('something went wrong while saving', -1);
         }
         touch($config_file_path);
     }
     // export
     if ($table && $INPUT->bool('export')) {
         $builder = new Schema($table);
         header('Content-Type: application/json');
         header("Content-Disposition: attachment; filename={$table}.struct.json");
         echo $builder->toJSON();
         exit;
     }
     // import
     if ($table && $INPUT->bool('import')) {
         if (isset($_FILES['schemafile']['tmp_name'])) {
             $json = io_readFile($_FILES['schemafile']['tmp_name'], false);
             if (!$json) {
                 msg('Something went wrong with the upload', -1);
             } else {
                 $builder = new SchemaImporter($table, $json, $INPUT->bool('lookup'));
                 if (!$builder->build()) {
                     msg('something went wrong while saving', -1);
                 }
                 touch($config_file_path);
             }
         }
     }
     // delete
     if ($table && $INPUT->bool('delete')) {
         if ($table != $INPUT->str('confirm')) {
             msg($this->getLang('del_fail'), -1);
         } else {
             try {
                 $schema = new Schema($table);
                 $schema->delete();
                 msg($this->getLang('del_ok'), 1);
                 touch($config_file_path);
                 send_redirect(wl($ID, array('do' => 'admin', 'page' => 'struct_schemas'), true, '&'));
             } catch (StructException $e) {
                 msg(hsc($e->getMessage()), -1);
             }
         }
     }
 }
 /**
  * Handler to load page template.
  *
  * @param Doku_Event $event  event object by reference
  * @param mixed      $param  [the parameters passed as fifth argument to register_hook() when this
  *                           handler was registered]
  * @return void
  */
 public function get_template(Doku_Event &$event, $param)
 {
     if (strlen($_REQUEST['copyfrom']) > 0) {
         $template_id = $_REQUEST['copyfrom'];
         if (auth_quickaclcheck($template_id) >= AUTH_READ) {
             $tpl = io_readFile(wikiFN($template_id));
             $event->data['tpl'] = $tpl;
             $event->preventDefault();
         }
     }
 }
Beispiel #20
0
 function _readFile($file, $ser = false)
 {
     $ret = io_readFile($file, $ser);
     if ($ser) {
         if (!$ret) {
             return array();
         }
         return unserialize($ret);
     }
     return $ret;
 }
Beispiel #21
0
 /**
  * @depends test_ext_bz2
  */
 function test_bzfiles()
 {
     $this->assertEquals("The\nTest\n", io_readFile(__DIR__ . '/io_readfile/test.txt.bz2'));
     $this->assertEquals("The\r\nTest\r\n", io_readFile(__DIR__ . '/io_readfile/test.txt.bz2', false));
     $this->assertEquals(false, io_readFile(__DIR__ . '/io_readfile/nope.txt.bz2'));
     $this->assertEquals(false, io_readFile(__DIR__ . '/io_readfile/corrupt.txt.bz2'));
     // internal bzfile function
     $this->assertEquals(array("The\r\n", "Test\r\n"), bzfile(__DIR__ . '/io_readfile/test.txt.bz2', true));
     $this->assertEquals(array_fill(0, 120, str_repeat('a', 80) . "\n"), bzfile(__DIR__ . '/io_readfile/large.txt.bz2', true));
     $line = str_repeat('a', 8888) . "\n";
     $this->assertEquals(array($line, "\n", $line, "!"), bzfile(__DIR__ . '/io_readfile/long.txt.bz2', true));
 }
Beispiel #22
0
 private function used_legacy_syntax_not_too_long_ago()
 {
     $legacySyntax = io_readFile(action_plugin_nspages::legacySyntaxFilename());
     if ($legacySyntax) {
         if ($legacySyntax > time() - 365 * 86400) {
             return true;
         } else {
             unlink(action_plugin_nspages::legacySyntaxFilename());
         }
     }
     return false;
 }
Beispiel #23
0
 /**
  * Return a media file
  *
  * @author Gina Haeussge <*****@*****.**>
  * @param string $id file id
  * @return media file
  */
 function getAttachment($id)
 {
     $id = cleanID($id);
     if (auth_quickaclcheck(getNS($id) . ':*') < AUTH_READ) {
         throw new RemoteAccessDeniedException('You are not allowed to read this file', 211);
     }
     $file = mediaFN($id);
     if (!@file_exists($file)) {
         throw new RemoteException('The requested file does not exist', 221);
     }
     $data = io_readFile($file, false);
     return $this->api->toFile($data);
 }
Beispiel #24
0
 function admin_plugin_404manager()
 {
     //Set the redirection data
     $this->Vc_DataFileLocation = dirname(__FILE__) . '/404managerRedirect.conf';
     if (@file_exists($this->Vc_DataFileLocation)) {
         $this->Vc_RedirectData = unserialize(io_readFile($this->Vc_DataFileLocation, false));
     }
     // enable direct access to language strings
     // of use of $this_>getLang
     $this->setupLocale();
     $this->InfoPlugIn = $this->getInfo();
     $this->Vc_CurrentDate = date("d/m/Y");
 }
Beispiel #25
0
 /**
  * output appropriate html
  */
 function html()
 {
     global $lang;
     echo $this->locale_xhtml('intro');
     echo '<form action="" method="post" >';
     echo '<input type="hidden" name="do" value="admin" />';
     echo '<input type="hidden" name="page" value="redirect" />';
     echo '<textarea class="edit" rows="15" cols="80" style="height: 300px" name="redirdata">';
     echo formtext(io_readFile(dirname(__FILE__) . '/redirect.conf'));
     echo '</textarea><br />';
     echo '<input type="submit" value="' . $lang['btn_save'] . '" class="button" />';
     echo '</form>';
 }
Beispiel #26
0
 /**
  * output appropriate html
  */
 public function html()
 {
     global $lang;
     $helper = $this->loadHelper('loadskin', true);
     print '<div id="plugin__loadskin">';
     print $this->locale_xhtml('intro');
     $form = new Doku_Form(array());
     $form->startFieldSet('Add rule');
     $form->addHidden('id', $ID);
     $form->addHidden('do', 'admin');
     $form->addHidden('page', 'loadskin');
     $form->addHidden('act', 'add');
     $form->addElement(form_makeOpenTag('p'));
     $form->addElement(form_makeTextField('pattern', '', $this->getLang('pattern')));
     $form->addElement(form_makeCloseTag('p'));
     $form->addElement(form_makeOpenTag('p'));
     $form->addElement(form_makeListboxField('tpl', $helper->getTemplates(), '', $this->getLang('template')));
     $form->addElement(form_makeCloseTag('p'));
     $form->addElement(form_makeButton('submit', '', $lang['btn_save']));
     $form->endFieldSet();
     $form->printForm();
     if (@file_exists($this->config)) {
         $data = unserialize(io_readFile($this->config, false));
         if (!empty($data)) {
             echo '<table class="inline">' . DOKU_LF;
             echo '  <tr>' . DOKU_LF;
             echo '    <th>' . $this->getLang('pattern') . '</th>' . DOKU_LF;
             echo '    <th>' . $this->getLang('template') . '</th>' . DOKU_LF;
             echo '    <th>' . $this->getLang('action') . '</th>' . DOKU_LF;
             echo '  </tr>' . DOKU_LF;
             foreach ($data as $key => $value) {
                 echo '  <tr>' . DOKU_LF;
                 echo '    <td>' . $key . '</td>' . DOKU_LF;
                 echo '    <td>' . $value . '</td>' . DOKU_LF;
                 echo '    <td>' . DOKU_LF;
                 $form = new Doku_Form(array());
                 $form->addHidden('do', 'admin');
                 $form->addHidden('page', 'loadskin');
                 $form->addHidden('act', 'del');
                 $form->addHidden('id', $ID);
                 $form->addHidden('pattern', $key);
                 $form->addElement(form_makeButton('submit', '', $lang['btn_delete']));
                 $form->printForm();
                 echo '    </td>' . DOKU_LF;
                 echo '  </tr>' . DOKU_LF;
             }
             echo '</table>' . DOKU_LF;
         }
     }
     print '</div>';
 }
Beispiel #27
0
 /**
  * Constructor
  *
  * Loads the cache
  */
 public function __construct()
 {
     global $conf;
     $this->logfile = fullpath($conf['metadir'] . '/' . $this->getConf('accesslog'));
     // file not found? assume absolute path
     if (!file_exists($this->logfile)) {
         $this->logfile = $this->getConf('accesslog');
     }
     // load the cache file
     $this->logcache = getCacheName($this->getConf('accesslog'), '.statdisplay');
     if (file_exists($this->logcache)) {
         $this->logdata = unserialize(io_readFile($this->logcache, false));
     }
 }
Beispiel #28
0
 /**
  * Sends a notify mail on new linkback
  *
  * @param  string $ID       id of the wiki page for which the
  *                          linkback was received 
  * @param  array  $comment  data array of the new linkback
  *
  * @author Andreas Gohr <*****@*****.**>
  * @author Esther Brunner <*****@*****.**>
  * @author Gina Haeussge <*****@*****.**>
  */
 function notify($ID, $linkback)
 {
     global $conf;
     if (!$conf['notify']) {
         return;
     }
     $to = $conf['notify'];
     $text = io_readFile($this->localFN('subscribermail'));
     $search = array('@PAGE@', '@TITLE@', '@DATE@', '@URL@', '@TEXT@', '@UNSUBSCRIBE@', '@DOKUWIKIURL@', '@PAGEURL@');
     $replace = array($ID, $conf['title'], strftime($conf['dformat'], $linkback['received']), $linkback['url'], $linkback['excerpt'], wl($ID, 'do=unsubscribe', true, '&'), DOKU_URL, wl($ID, '', true));
     $text = str_replace($search, $replace, $text);
     $subject = '[' . $conf['title'] . '] ' . $this->getLang('mail_newlinkback');
     mail_send($to, $subject, $text, $conf['mailfrom'], '');
 }
Beispiel #29
0
 /**
  *
  */
 public static function load($sectionName)
 {
     $pluginRoot = DOKU_PLUGIN . 'refnotes/';
     $fileName = $pluginRoot . $sectionName . '.local.dat';
     if (!file_exists($fileName)) {
         $fileName = $pluginRoot . $sectionName . '.dat';
         if (!file_exists($fileName)) {
             $fileName = '';
         }
     }
     if ($fileName != '') {
         $result = unserialize(io_readFile($fileName, false));
     } else {
         $result = array();
     }
     return $result;
 }
Beispiel #30
0
function loadTranslationMeta($id)
{
    global $REV;
    # Loading meta for current version is simple
    if (empty($REV)) {
        return unserialize(io_readFile(metaFN($id, '.translate'), false));
    }
    # Old revision, do it the hard way...
    $ret = array();
    $meta = unserialize(io_readFile(metaFN($id, '.translateHistory'), false));
    $oldrev = intval($REV);
    for ($i = 0; $i < count($meta[$oldrev]); $i++) {
        $tmp = empty($meta[$oldrev][$i]['changed']) ? $oldrev : $meta[$oldrev][$i]['changed'];
        $ret[$i] = $meta[$tmp][$i];
        $ret[$i]['changed'] = $tmp;
    }
    return $ret;
}