function show_form() { $user_pref = $this->func->get_user_pref($this->uid); $disabled = array(); if ($this->root->twitter_consumer_key && $this->root->twitter_consumer_secret && function_exists('curl_init') && version_compare(PHP_VERSION, '5.0.0', '>') && HypCommonFunc::get_version() >= '20100108') { HypCommonFunc::loadClass('TwitterOAuth'); $state = isset($_SESSION['oauth_state']) ? $_SESSION['oauth_state'] : ''; if (!empty($user_pref['twitter_access_token']) && !empty($user_pref['twitter_access_token_secret'])) { $to = new TwitterOAuth($this->root->twitter_consumer_key, $this->root->twitter_consumer_secret, $user_pref['twitter_access_token'], $user_pref['twitter_access_token_secret']); $content = $to->OAuthRequest('https://twitter.com/account/verify_credentials.xml', 'GET', array()); if (strpos($content, '<error>') === FALSE) { $state = 'ok'; } else { $user_pref['twitter_access_token'] = ''; $user_pref['twitter_access_token_secret'] = ''; } } if (!empty($this->root->get['oauth_token']) && $state === 'start') { $state = 'returned'; unset($_SESSION['oauth_state']); } if (isset($this->root->get['denied'])) { $state = 'denied'; unset($_SESSION['oauth_state']); } switch ($state) { case 'returned': $to = new TwitterOAuth($this->root->twitter_consumer_key, $this->root->twitter_consumer_secret, $_SESSION['oauth_request_token'], $_SESSION['oauth_request_token_secret']); $tok = $to->getAccessToken($this->root->get['oauth_verifier']); $user_pref['twitter_access_token'] = $tok['oauth_token']; $user_pref['twitter_access_token_secret'] = $tok['oauth_token_secret']; $this->msg['twitter_access_token_secret']['description'] = ''; break; case 'denied': $user_pref['twitter_access_token'] = ''; $user_pref['twitter_access_token_secret'] = ''; $this->msg['twitter_access_token_secret']['description'] = ''; break; case 'ok': $this->msg['twitter_access_token_secret']['description'] = ''; break; default: $to = new TwitterOAuth($this->root->twitter_consumer_key, $this->root->twitter_consumer_secret); $tok = $to->getRequestToken($this->root->script . '?cmd=user_pref'); if (!empty($tok['oauth_token'])) { $_SESSION['oauth_request_token'] = $token = $tok['oauth_token']; $_SESSION['oauth_request_token_secret'] = $tok['oauth_token_secret']; $_SESSION['oauth_state'] = "start"; $this->root->twitter_request_link = $to->getAuthorizeURL($token); } else { $disabled['twitter'] = true; } break; } } else { $disabled['twitter'] = true; } if (!empty($disabled['twitter'])) { unset($this->user_pref['twitter_access_token'], $this->user_pref['twitter_access_token_secret']); } // moblog if (!$this->root->use_moblog_user_pref) { unset($this->user_pref['moblog_mail_address'], $this->user_pref['moblog_base_page'], $this->user_pref['moblog_user_mail'], $this->user_pref['moblog_to_twitter'], $this->user_pref['moblog_auth_code']); } else { if (strpos($this->root->moblog_pop_mail, '*') === false) { unset($this->user_pref['moblog_user_mail']); } else { unset($this->user_pref['moblog_mail_address']); if (empty($user_pref['moblog_user_mail'])) { $user_tag = strtolower($this->make_user_tag()); $user_pref['moblog_user_mail'] = str_replace('*', $user_tag, $this->root->moblog_pop_mail); } $this->root->moblog_user_mail = htmlspecialchars($user_pref['moblog_user_mail']); $this->root->moblog_user_mail_rawurlenc = rawurlencode($user_pref['moblog_user_mail']); } if (!$user_pref['twitter_access_token']) { unset($this->user_pref['moblog_to_twitter']); } } // XML-RPC if (!$this->root->use_xmlrpc) { unset($this->user_pref['xmlrpc_pages'], $this->user_pref['xmlrpc_auth_key'], $this->user_pref['xmlrpc_to_twitter']); } else { if (empty($user_pref['xmlrpc_pages'])) { // Read user config $pages = array(); $config = new XpWikiConfig($this->xpwiki, $this->cont['PKWK_CONFIG_USER'] . '/' . $this->root->userinfo['uname']); $table = $config->read() ? $config->get('XML-RPC') : array(); foreach ($table as $row) { if (isset($row[1]) && strtolower(trim($row[0])) === 'myblog') { $page = $this->func->strip_bracket(trim($row[1])); $pages[] = htmlspecialchars($page); } } $user_pref['xmlrpc_pages'] = join("\n", $pages); } if (empty($user_pref['xmlrpc_auth_key'])) { $user_pref['xmlrpc_auth_key'] = substr($this->make_user_tag(), 0, 8); } if (!$user_pref['twitter_access_token']) { unset($this->user_pref['xmlrpc_to_twitter']); } } $script = $this->func->get_script_uri(); if ($this->user_pref) { $body = <<<EOD <div> <h2>{$this->msg['title_description']}</h2> {$this->msg['msg_description']} </div> <hr /> <div class="user_pref"> <form action="{$script}" method="post"> <table> EOD; //var_dump($user_pref); //exit; foreach ($this->user_pref as $key => $conf) { $caption = !empty($conf['caption']) ? $conf['caption'] : (!empty($this->msg[$key]['caption']) ? $this->msg[$key]['caption'] : $key); $description = !empty($conf['description']) ? $conf['description'] : (!empty($this->msg[$key]['description']) ? $this->msg[$key]['description'] : ''); $description = preg_replace('/\\{\\$root->(.+?)\\}/e', '$this->root->$1', $description); $value = isset($user_pref[$key]) ? $user_pref[$key] : ''; $value4disp = htmlspecialchars($value); $name4disp = htmlspecialchars($key); $real = ''; $extention = !empty($this->msg[$key]['extention']) ? $this->msg[$key]['extention'] : ''; list($form, $attr) = array_pad(explode(',', $conf['form'], 2), 2, ''); switch ($form) { case 'select': $forms = array(); if (!isset($conf['list']['group'])) { $conf['list']['group'][0] = $conf['list']; } foreach ($conf['list']['group'] as $label => $optgroup) { if (is_string($label)) { $forms[] = '<optgroup label="' . $label . '">'; } foreach ($optgroup as $list_cap => $list_val) { if ($value == $list_val) { $selected = ' selected="selected"'; } else { $selected = ''; } $forms[] = '<option value="' . $list_val . '"' . $selected . '>' . $list_cap . '</option>'; } if (is_string($label)) { $forms[] = '</optgroup>'; } } $form = '<select name="' . $name4disp . '" ' . $attr . '>' . join('', $forms) . '</select>'; break; case 'yesno': $conf['list'] = array($this->msg['Yes'] => 1, $this->msg['No'] => 0); case 'radio': $forms = array(); $i = 0; foreach ($conf['list'] as $list_cap => $list_val) { if ($value == $list_val) { $checked = ' checked="checked"'; } else { $checked = ''; } $forms[] = '<span class="nowrap"><input id="' . $name4disp . '_' . $i . '" type="radio" name="' . $name4disp . '" value="' . $list_val . '"' . $checked . ' /><label for="' . $name4disp . '_' . $i . '">' . $list_cap . '</label></span>'; $i++; } $form = join(' | ', $forms); break; case 'textarea': $form = '<textarea name="' . $name4disp . '" ' . $attr . ' rel="nowikihelper">' . $value4disp . '</textarea>'; break; case 'hidden': $form = '<input type="hidden" name="' . $name4disp . '" value="' . $value4disp . '" />' . $value4disp; break; case 'text': default: $style = ''; if ($conf['type'] === 'integer' || $conf['type'] === 'integer!0') { $style = ' style="text-align:right;"'; } $form = '<input type="text" name="' . $name4disp . '" value="' . $value4disp . '" ' . $attr . $style . ' />'; } $body .= <<<EOD <tr> <td style="font-weight:bold;padding-top:0.5em" id="{$key}">{$caption}</td> <td style="padding-top:0.5em">{$form}{$extention}</td> </tr> <tr style="border-bottom:1px dotted gray;"> <td colspan="2" style="padding-bottom:0.5em"><p>{$description}</p></td> </tr> EOD; } $body .= <<<EOD <tr> <td> </td> <td><input type="submit" name="submit" value="{$this->msg['btn_submit']}" /></td> </tr> </table> <input type="hidden" name="plugin" value="user_pref" /> <input type="hidden" name="pmode"\t value="post" /> </form> </div> EOD; } else { $body = 'There is no item.'; } return array('msg' => $this->msg['title_form'], 'body' => $body); }
function attach_mime_content_type($filename, $status) { $org_fname = $status['org_fname']; $imagesize = $status['imagesize']; $type = 'application/octet-stream'; //default if (!is_file($filename)) { return $type; } if (is_array($imagesize) && !empty($imagesize[2])) { if (isset($imagesize['mime'])) { return $imagesize['mime']; } // PHP >= 4.3.0 switch ($imagesize[2]) { case 1: return 'image/gif'; case 2: return 'image/jpeg'; case 3: return 'image/png'; case 4: case 13: return 'application/x-shockwave-flash'; default: } } $matches = array(); if (!preg_match('/_((?:[0-9A-F]{2})+)(?:\\.\\d+)?$/', $filename, $matches)) { return $type; } $filename = $org_fname; // mime-type一覧表を取得 $config = new XpWikiConfig($this->xpwiki, $this->cont['ATTACH_CONFIG_PAGE_MIME']); $table = $config->read() ? $config->get('mime-type') : array(); unset($config); // メモリ節約 foreach ($table as $row) { $_type = trim($row[0]); $exts = preg_split('/\\s+|,/', trim($row[1]), -1, PREG_SPLIT_NO_EMPTY); foreach ($exts as $ext) { if (preg_match("/\\.{$ext}\$/i", $filename)) { return $_type; } } } return $type; }
function plugin_tracker_list_render($base, $refer, $config_name, $list, $order_commands = '', $limit = 0) { $base = trim($base); if ($base == '') { return '#tracker_list: Base not specified' . '<br />'; } $refer = trim($refer); $config_name = trim($config_name); if ($config_name == '') { $config_name = $this->cont['PLUGIN_TRACKER_DEFAULT_CONFIG']; } $list = trim($list); if (!is_numeric($limit)) { return $this->cont['PLUGIN_TRACKER_LIST_USAGE'] . '<br />'; } $limit = intval($limit); $config = new XpWikiConfig($this->xpwiki, 'plugin/tracker/' . $config_name); if (!$config->read()) { return '#tracker_list: Config not found: ' . htmlspecialchars($config_name) . '<br />'; } $config->config_name = $config_name; if (!$this->func->is_page($config->page . '/' . $list)) { return '#tracker_list: List not found: ' . $this->func->make_pagelink($config->page . '/' . $list) . '<br />'; } $list =& new XpWikiTracker_list($this->xpwiki, $base, $refer, $config, $list); if ($list->sortRows($order_commands) === FALSE) { return '#tracker_list: ' . htmlspecialchars($list->error) . '<br />'; } $result = $list->toString($limit); if ($result === FALSE) { return '#tracker_list: ' . htmlspecialchars($list->error) . '<br />'; } unset($list); return $this->func->convert_html($result); }
function plugin_referer_ignore_check($url) { // static $ignore_url; static $ignore_url = array(); if (!isset($ignore_url[$this->xpwiki->pid])) { $ignore_url[$this->xpwiki->pid] = array(); } // config.php if (!isset($ignore_url[$this->xpwiki->pid])) { $config = new XpWikiConfig($this->xpwiki, $this->cont['CONFIG_REFERER']); $config->read(); $ignore_url[$this->xpwiki->pid] = $config->get('IGNORE'); unset($config); } foreach ($ignore_url[$this->xpwiki->pid] as $x) { if (strpos($url, $x) !== FALSE) { return 1; } } return 0; }
/** * ファイル名から対応言語を検索する * */ function _plugin_code_extension($name) { //$lang = $this->cont['PLUGIN_CODE_LANGUAGE']; // default //if (! is_file($filename)) return $lang; if (!strncasecmp($name, 'makefile', 8)) { return 'make'; } $extension = strtolower(substr($name, strrpos($name, '.') + 1)); if (!$extension) { return null; } // extension 一覧表を取得 $config = new XpWikiConfig($this->xpwiki, $this->cont['PLUGIN_CODE_CONFIG_PAGE_EXTENSION']); $table = $config->read() ? $config->get('lang') : array(); unset($config); // メモリ節約 // search extension foreach ($table as $row) { $_lang = trim($row[0]); $exts = preg_split('/\\s+|,/', trim($row[1]), -1, PREG_SPLIT_NO_EMPTY); foreach ($exts as $ext) { if ($extension == $ext) { return $_lang; } } } return null; }
function get_autolink_pattern(&$pages, $min_len = -1, $make_a = true, $aliases = false) { if (!$aliases) { $config = new XpWikiConfig($this->xpwiki, 'AutoLink'); $config->read(); $ignorepages = $config->get('IgnoreList'); $forceignorepages = $config->get('ForceIgnoreList'); unset($config); $auto_pages = array_merge($ignorepages, $forceignorepages); } else { $auto_pages = array(); $forceignorepages = array(); } if ($min_len === -1) { $min_len = $this->root->autolink; // set $this->root->autolink, when omitted. } $_aliases = $this->get_pagealiases($pages); foreach (array_merge($pages, $_aliases) as $page) { if (strlen($page) >= $min_len) { $auto_pages[] = $page; } } if (empty($auto_pages)) { $result = $result_a = $this->root->nowikiname ? '(?!)' : $this->root->WikiName; } else { if ($make_a) { $auto_pages_a = array_values(preg_grep('/^[A-Z]+$/i', $auto_pages)); $auto_pages = array_values(array_diff($auto_pages, $auto_pages_a)); list($result) = explode("\t", $this->get_matcher_regex_safe($auto_pages)); list($result_a) = explode("\t", $this->get_matcher_regex_safe($auto_pages_a)); } else { $result = $this->get_matcher_regex_safe($auto_pages); $result_a = '(?!)'; } } return array($result, $result_a, $forceignorepages); }
function plugin_addline_action() { if ($this->cont['PKWK_READONLY']) { return array('msg' => $this->root->_msg_not_editable, 'body' => ''); } $refer = $this->root->vars['refer']; $postdata_old = $this->func->get_source($refer); $configname = $this->root->vars['configname']; $above = $this->root->vars['above']; $block_plugin = 1; if (array_key_exists('addline_inno', $this->root->vars)) { $addline_no = $this->root->vars['addline_inno']; $block_plugin = 0; } else { if (array_key_exists('addline_no', $this->root->vars)) { $addline_no = $this->root->vars['addline_no']; } } $config = new XpWikiConfig($this->xpwiki, 'plugin/addline/' . $configname); if (!$config->read()) { return array('msg' => 'addline error', 'body' => "<p>config file '" . $this->func->htmlspecialchars($configname) . "' is not exist."); } $config->config_name = $configname; $addline = join('', $this->addline_get_source($config->page)); $addline = rtrim($addline); if ($block_plugin) { $postdata = $this->addline_block($addline, $postdata_old, $addline_no, $above); if ($postdata === FALSE) { return array('msg' => $this->root->_msg_not_editable, 'body' => ''); } } else { $postdata = $this->addline_inline($addline, $postdata_old, $addline_no, $above); } $title = $this->root->_title_updated; $body = ''; if ($this->func->get_digests(@join('', $postdata_old)) != $this->root->vars['digest']) { $title = $this->msg['title_collided']; $body = $this->msg['msg_collided'] . $this->func->make_pagelink($refer); } // $body = $postdata; // debug // foreach ( $vars as $k=>$v ){$body .= "[$k:$v]&br;";} $this->func->page_write($refer, $postdata); $retvars['msg'] = $title; $retvars['body'] = $body; return $retvars; }