/** * @param string $pluginName * @param array|bool $inactiveModules * * @return mixed */ public static function getPlugins($pluginName = 'system', $inactiveModules = false) { static $plugins = array(); if (!isset($plugins[$pluginName])) { $plugins[$pluginName] = array(); $xoops = \Xoops::getInstance(); //Load interface for this plugin if (!\XoopsLoad::loadFile($xoops->path("modules/{$pluginName}/class/plugin/interface.php"))) { return $plugins[$pluginName]; } $dirnames = $xoops->getActiveModules(); if (is_array($inactiveModules)) { $dirnames = array_merge($dirnames, $inactiveModules); } foreach ($dirnames as $dirname) { if (\XoopsLoad::loadFile($xoops->path("modules/{$dirname}/class/plugin/{$pluginName}.php"))) { $className = '\\' . ucfirst($dirname) . ucfirst($pluginName) . 'Plugin'; $interface = '\\' . ucfirst($pluginName) . 'PluginInterface'; $class = new $className($dirname); if ($class instanceof \Xoops\Module\Plugin\PluginAbstract && $class instanceof $interface) { $plugins[$pluginName][$dirname] = $class; } } } } return $plugins[$pluginName]; }
/** * execute the command * * @param InputInterface $input input handler * @param OutputInterface $output output handler * @return void */ protected function execute(InputInterface $input, OutputInterface $output) { $xoops = \Xoops::getInstance(); $module = $input->getArgument('module'); if (false === \XoopsLoad::fileExists($xoops->path("modules/{$module}/xoops_version.php"))) { $output->writeln(sprintf('<error>No module named %s found!</error>', $module)); return; } $output->writeln(sprintf('Installing %s', $module)); if (false !== $xoops->getModuleByDirname($module)) { $output->writeln(sprintf('<error>%s module is already installed!</error>', $module)); return; } $xoops->setTpl(new XoopsTpl()); \XoopsLoad::load('module', 'system'); $sysmod = new \SystemModule(); $result = $sysmod->install($module); foreach ($sysmod->trace as $message) { if (is_array($message)) { foreach ($message as $subMessage) { if (!is_array($subMessage)) { $output->writeln(strip_tags($subMessage)); } } } else { $output->writeln(strip_tags($message)); } } if ($result === false) { $output->writeln(sprintf('<error>Install of %s failed!</error>', $module)); } else { $output->writeln(sprintf('<info>Install of %s completed.</info>', $module)); } $xoops->cache()->delete('system'); }
function smarty_function_xoPageNav($params, &$smarty) { $xoops = Xoops::getInstance(); extract($params); if ($pageSize < 1) { $pageSize = 10; } $pagesCount = (int) ($itemsCount / $pageSize); if ($itemsCount <= $pageSize || $pagesCount < 2) { return ''; } $str = ''; $currentPage = (int) ($offset / $pageSize) + 1; $lastPage = (int) ($itemsCount / $pageSize) + 1; $minPage = min(1, ceil($currentPage - $linksCount / 2)); $maxPage = max($lastPage, floor($currentPage + $linksCount / 2)); //TODO Remove this hardocded strings if ($currentPage > 1) { $str .= '<a href="' . $xoops->url(str_replace('%s', $offset - $pageSize, $url)) . '">Previous</a>'; } for ($i = $minPage; $i <= $maxPage; ++$i) { $tgt = htmlspecialchars($xoops->url(str_replace('%s', ($i - 1) * $pageSize, $url)), ENT_QUOTES); $str .= "<a href='{$tgt}'>{$i}</a>"; } if ($currentPage < $lastPage) { $str .= '<a href="' . $xoops->url(str_replace('%s', $offset + $pageSize, $url)) . '">Next</a>'; } $class = @(!empty($class)) ? htmlspecialchars($class, ENT_QUOTES) : 'pagenav'; $str = "<div class='{$class}'>{$str}</div>"; return $str; }
/** * getQRUrl * * @param string $qrText text for QR code * * @return string URL to obtain QR Code image of $qrText */ private function getQRUrl($qrText) { $xoops = \Xoops::getInstance(); $params = array('text' => (string) $qrText); $url = $xoops->buildUrl($xoops->url($this->renderScript), $params); return $url; }
function smarty_block_assets($params, $content, $template, &$repeat) { // Opening tag (first call only) if ($repeat) { $xoops = \Xoops::getInstance(); $assets = explode(',', $params['assets']); if (isset($params['filters'])) { $filters = $params['filters']; } else { $filters = 'default'; } $output = strtolower($params['output']); $debug = isset($params['debug']) ? (bool) $params['debug'] : false; if ($debug) { $xoops->assets()->setDebug($debug); } $url = $xoops->assets()->getUrlToAssets($output, $assets, $filters); if (isset($params['asset_url'])) { $asset_url = $params['asset_url']; } else { $asset_url = 'asset_url'; } $template->assign($asset_url, $url); } else { // Closing tag if (isset($content)) { return $content; } } }
/** * search - search * * @param string[] $queryArray search terms * @param string $andor and/or how to treat search terms * @param integer $limit max number to return * @param integer $offset offset of first row to return * @param integer $userid a specific user id to limit the query * * @return array of result items * 'title' => the item title * 'content' => brief content or summary * 'link' => link to visit item * 'time' => time modified (unix timestamp) * 'uid' => author uid * 'image' => icon for search display * */ public function search($queryArray, $andor, $limit, $offset, $userid) { $andor = strtolower($andor) == 'and' ? 'and' : 'or'; $qb = \Xoops::getInstance()->db()->createXoopsQueryBuilder(); $eb = $qb->expr(); $qb->select('DISTINCT *')->fromPrefix('page_content')->where($eb->neq('content_status', '0'))->orderBy('content_create', 'DESC')->setFirstResult($offset)->setMaxResults($limit); if (is_array($queryArray) && !empty($queryArray)) { $queryParts = array(); foreach ($queryArray as $i => $q) { $qterm = ':qterm' . $i; $qb->setParameter($qterm, '%' . $q . '%', \PDO::PARAM_STR); $queryParts[] = $eb->orX($eb->like('content_title', $qterm), $eb->like('content_text', $qterm), $eb->like('content_shorttext', $qterm)); } if ($andor == 'and') { $qb->andWhere(call_user_func_array(array($eb, "andX"), $queryParts)); } else { $qb->andWhere(call_user_func_array(array($eb, "orX"), $queryParts)); } } else { $qb->setParameter(':uid', (int) $userid, \PDO::PARAM_INT); $qb->andWhere($eb->eq('content_author', ':uid')); } $myts = MyTextSanitizer::getInstance(); $items = array(); $result = $qb->execute(); while ($myrow = $result->fetch(\PDO::FETCH_ASSOC)) { $content = $myrow["content_shorttext"] . "<br /><br />" . $myrow["content_text"]; $content = $myts->xoopsCodeDecode($content); $items[] = array('title' => $myrow['content_title'], 'content' => Metagen::getSearchSummary($content, $queryArray), 'link' => "viewpage.php?id=" . $myrow["content_id"], 'time' => $myrow['content_create'], 'uid' => $myrow['content_author'], 'image' => 'images/logo_small.png'); } return $items; }
function smarty_function_xoInboxCount($params, &$smarty) { $xoops = Xoops::getInstance(); if (!$xoops->isUser()) { return; } $time = time(); if (isset($_SESSION['xoops_inbox_count']) && @$_SESSION['xoops_inbox_count_expire'] > $time) { $count = (int) $_SESSION['xoops_inbox_count']; } else { $pm_handler = $xoops->getHandlerPrivateMessage(); $xoopsPreload = XoopsPreload::getInstance(); $xoopsPreload->triggerEvent('core.class.smarty.xoops_plugins.xoinboxcount', array($pm_handler)); $criteria = new CriteriaCompo(new Criteria('read_msg', 0)); $criteria->add(new Criteria('to_userid', $xoops->user->getVar('uid'))); $count = (int) $pm_handler->getCount($criteria); $_SESSION['xoops_inbox_count'] = $count; $_SESSION['xoops_inbox_count_expire'] = $time + 60; } if (!@empty($params['assign'])) { $smarty->assign($params['assign'], $count); } else { echo $count; } }
/** * get counts matching a condition * * @param CriteriaElement|null $criteria criteria to match * * @return array of counts */ public function getCounts(CriteriaElement $criteria = null) { $qb = \Xoops::getInstance()->db()->createXoopsQueryBuilder(); $ret = array(); $limit = null; $start = null; $groupby_key = $this->handler->keyName; if (isset($criteria) && $criteria instanceof CriteriaElement) { if ($groupBy = $criteria->getGroupBy()) { $groupby_key = $groupBy; } } $qb->select($groupby_key)->addSelect('COUNT(*)')->from($this->handler->table, null); if (isset($criteria) && $criteria instanceof CriteriaElement) { $qb = $criteria->renderQb($qb); } $result = $qb->execute(); if (!$result) { return $ret; } while (list($id, $count) = $result->fetch(\PDO::FETCH_NUM)) { $ret[$id] = $count; } return $ret; }
/** * @param string $dirname * * @return bool|Xoops\Module\Helper\HelperAbstract */ public static function getHelper($dirname = 'system') { static $modules = array(); $dirname = strtolower($dirname); if (!isset($modules[$dirname])) { $modules[$dirname] = false; $xoops = \Xoops::getInstance(); if ($xoops->isActiveModule($dirname)) { //Load Module helper if available if (\XoopsLoad::loadFile($xoops->path("modules/{$dirname}/class/helper.php"))) { $className = '\\' . ucfirst($dirname); if (class_exists($className)) { $class = new $className(); if ($class instanceof \Xoops\Module\Helper\HelperAbstract) { $modules[$dirname] = $class::getInstance(); } } } else { //Create Module Helper $xoops->registry()->set('module_helper_id', $dirname); $class = \Xoops\Module\Helper\Dummy::getInstance(); $class->setDirname($dirname); $modules[$dirname] = $class; } } } return $modules[$dirname]; }
/** * @param array $param array of parameters with these keys: * 'obj' => ImagesCategory|XoopsObject $obj * 'target' => textarea id */ public function __construct($param) { $xoops = Xoops::getInstance(); $groups = $xoops->getUserGroups(); extract($param); $helper = Xoops\Module\Helper::getHelper('images'); $categories = $helper->getHandlerCategories()->getListByPermission($groups, 'imgcat_read'); parent::__construct('', '', $xoops->getEnv('PHP_SELF'), 'post', false, 'inline'); $select = new Xoops\Form\Select('', 'imgcat_id', $imgcat_id); $select->addOption(0, _AM_IMAGES_CAT_SELECT); $select->addOptionArray($categories); if (isset($target)) { $select->setExtra("onchange='javascript:window.location.href=\"" . $xoops->getEnv('PHP_SELF') . "?target=" . $target . "&imgcat_id=\" + this.value'"); } else { $select->setExtra("onchange='javascript:window.location.href=\"" . $xoops->getEnv('PHP_SELF') . "?imgcat_id=\" + this.value'"); } $this->addElement($select); if (isset($target)) { $this->addElement(new Xoops\Form\Hidden('target', $target)); } $write = $helper->getHandlerCategories()->getListByPermission($groups, 'imgcat_write'); if ($imgcat_id > 0 && array_key_exists($imgcat_id, $write)) { $this->addElement(new Xoops\Form\Hidden('op', 'upload')); $button = new Xoops\Form\Button('', 'submit', _IMAGES_ADD, 'submit'); $button->setClass('btn btn-success floatright'); $this->addElement($button); } }
/** * Get a reference to the only instance of database class and connects to DB * * if the class has not been instantiated yet, this will also take * care of that * * Doctrine connection function * * NOTE: Persistance connection is not included. XOOPS_DB_PCONNECT is ignored. * allowWebChanges also needs to be addressed * * @param array $options driverOptions for Doctrine * * @return Connection|null Reference to the only instance of database class * * @todo change driver to support other databases and support for port, unix_socket and driver options. */ public static function getConnection($options = null) { static $instance; if (!isset($instance)) { $xoops = \Xoops::getInstance(); $config = new \Doctrine\DBAL\Configuration(); $config->setSQLLogger(new XoopsDebugStack()); $parameters = \XoopsBaseConfig::get('db-parameters'); if (!empty($parameters) && is_array($parameters)) { $connectionParams = $parameters; $connectionParams['wrapperClass'] = '\\Xoops\\Core\\Database\\Connection'; } else { $driver = 'pdo_' . \XoopsBaseConfig::get('db-type'); $connectionParams = array('dbname' => \XoopsBaseConfig::get('db-name'), 'user' => \XoopsBaseConfig::get('db-user'), 'password' => \XoopsBaseConfig::get('db-pass'), 'host' => \XoopsBaseConfig::get('db-host'), 'charset' => \XoopsBaseConfig::get('db-charset'), 'driver' => $driver, 'wrapperClass' => '\\Xoops\\Core\\Database\\Connection'); // Support for other doctrine databases $xoops_db_port = \XoopsBaseConfig::get('db-port'); if (!empty($xoops_db_port)) { $connectionParams['port'] = $xoops_db_port; } $xoops_db_socket = \XoopsBaseConfig::get('db-socket'); if (!empty($xoops_db_socket)) { $connectionParams['unix_socket'] = $xoops_db_socket; } if (!is_null($options) && is_array($options)) { $connectionParams['driverOptions'] = $options; } } $instance = \Doctrine\DBAL\DriverManager::getConnection($connectionParams, $config); } return $instance; }
/** * execute the command * * @param InputInterface $input input handler * @param OutputInterface $output output handler * @return void */ protected function execute(InputInterface $input, OutputInterface $output) { $xoops = \Xoops::getInstance(); $name = $input->getArgument('name'); $value = $input->getArgument('value'); $configHandler = $xoops->getHandlerConfig(); $sysmodule = $xoops->getModuleByDirname('system'); if (empty($sysmodule)) { $output->writeln('<error>Module system is not installed!</error>'); return; } $mid = $sysmodule->mid(); $criteria = new CriteriaCompo(); $criteria->add(new Criteria('conf_modid', $mid)); $criteria->add(new Criteria('conf_name', $name)); $objArray = $configHandler->getConfigs($criteria); $configItem = reset($objArray); if (empty($configItem)) { $output->writeln(sprintf('<error>Config item %s not found!</error>', $name)); return; } $configItem->setConfValueForInput($value); $result = $configHandler->insertConfig($configItem); if ($result === false) { $output->writeln(sprintf('<error>Could not set %s!</error>', $name)); } $output->writeln(sprintf('Set %s', $name)); }
/** * @param null $obj */ public function __construct($object = null) { $this->object = $object; $this->config = $object->config; $xoops = Xoops::getInstance(); parent::__construct('', 'xcaptchaform', $xoops->getEnv('PHP_SELF'), 'post', true, 'horizontal'); $activate = new Xoops\Form\Radio(_AM_XCAPTCHA_ACTIVATE, 'disabled', $this->config['disabled']); $activate->addOption(1, _AM_XCAPTCHA_ENABLE); $activate->addOption(0, _AM_XCAPTCHA_DISABLE); $this->addElement($activate, false); $plugin_List = new Xoops\Form\Select(_AM_XCAPTCHA_PLUGINS, 'mode', $this->config['mode']); $plugin_List->addOptionArray($this->object->plugin_List); $this->addElement($plugin_List, false); $this->addElement(new Xoops\Form\Text(_AM_XCAPTCHA_NAME, 'name', 50, 50, $this->config['name']), true); $skipmember = new Xoops\Form\Radio(_AM_XCAPTCHA_SKIPMEMBER, 'skipmember', $this->config['skipmember']); $skipmember->addOption(1, _AM_XCAPTCHA_ENABLE); $skipmember->addOption(0, _AM_XCAPTCHA_DISABLE); $this->addElement($skipmember, false); $this->addElement(new Xoops\Form\Text(_AM_XCAPTCHA_MAXATTEMPTS, 'maxattempts', 2, 2, $this->config['maxattempts']), true); $this->addElement(new Xoops\Form\Hidden('type', 'config')); $buttonTray = new Xoops\Form\ElementTray('', ''); $buttonTray->addElement(new Xoops\Form\Hidden('op', 'save')); $buttonTray->addElement(new Xoops\Form\Button('', 'submit', XoopsLocale::A_SUBMIT, 'submit')); $buttonTray->addElement(new Xoops\Form\Button('', 'reset', XoopsLocale::A_RESET, 'reset')); $buttonCancelSend = new Xoops\Form\Button('', 'cancel', XoopsLocale::A_CANCEL, 'button'); $buttonCancelSend->setExtra("onclick='javascript:history.go(-1);'"); $buttonTray->addElement($buttonCancelSend); $this->addElement($buttonTray); }
/** * Constructor * * @param string $caption caption * @param string $name element name * @param bool $include_anon Include user "anonymous"? * @param mixed $value Pre-selected value (or array of them). * For an item with massive members, such as "Registered Users", * "$value" should be used to store selected temporary users only * instead of all members of that item * @param int $size Number or rows. "1" makes a drop-down-list. * @param bool $multiple Allow multiple selections? */ public function __construct($caption, $name, $include_anon = false, $value = null, $size = 1, $multiple = false) { $xoops = \Xoops::getInstance(); $limit = 200; $select_element = new Select('', $name, $value, $size, $multiple); if ($include_anon) { $select_element->addOption(0, $xoops->getConfig('anonymous')); } $member_handler = $xoops->getHandlerMember(); $user_count = $member_handler->getUserCount(); $value = is_array($value) ? $value : (empty($value) ? array() : array($value)); if ($user_count > $limit && count($value) > 0) { $criteria = new CriteriaCompo(new Criteria('uid', '(' . implode(',', $value) . ')', 'IN')); } else { $criteria = new CriteriaCompo(); $criteria->setLimit($limit); } $criteria->setSort('uname'); $criteria->setOrder('ASC'); $users = $member_handler->getUserList($criteria); $select_element->addOptionArray($users); if ($user_count <= $limit) { parent::__construct($caption, "", $name); $this->addElement($select_element); return; } $js_addusers = "<script type='text/javascript'>\n function addusers(opts){\n var num = opts.substring(0, opts.indexOf(':'));\n opts = opts.substring(opts.indexOf(':')+1, opts.length);\n var sel = xoopsGetElementById('" . $name . "');\n var arr = new Array(num);\n for (var n=0; n < num; n++) {\n var nm = opts.substring(0, opts.indexOf(':'));\n opts = opts.substring(opts.indexOf(':')+1, opts.length);\n var val = opts.substring(0, opts.indexOf(':'));\n opts = opts.substring(opts.indexOf(':')+1, opts.length);\n var txt = opts.substring(0, nm - val.length);\n opts = opts.substring(nm - val.length, opts.length);\n var added = false;\n for (var k = 0; k < sel.options.length; k++) {\n if(sel.options[k].value == val){\n added = true;\n break;\n }\n }\n if (added == false) {\n sel.options[k] = new Option(txt, val);\n sel.options[k].selected = true;\n }\n }\n return true;\n }\n </script>"; $token = $xoops->security()->createToken(); $action_tray = new ElementTray("", " | "); $action_tray->addElement(new Label('', '<a href="#" onclick="var sel = xoopsGetElementById(\'' . $name . '\');for (var i = sel.options.length-1; i >= 0; i--) {if (!sel.options[i].selected) ' . '{sel.options[i] = null;}}; return false;">' . \XoopsLocale::REMOVE_UNSELECTED_USERS . "</a>")); $action_tray->addElement(new Label('', '<a href="#" onclick="openWithSelfMain(\'' . \XoopsBaseConfig::get('url') . '/include/findusers.php?target=' . $name . '&multiple=' . $multiple . '&token=' . $token . '\', \'userselect\', 800, 600, null); return false;" >' . \XoopsLocale::SEARCH_USERS . "</a>" . $js_addusers)); parent::__construct($caption, '<br /><br />', $name); $this->addElement($select_element); $this->addElement($action_tray); }
/** * Get a list of imagesCategories * * @param array $groups * @param string $perm * @param null $display * @param null $storetype * * @return array Array of {@link ImagesImage} objects */ public function getListByPermission($groups = array(), $perm = 'imgcat_read', $display = null, $storetype = null) { $xoops = Xoops::getInstance(); $criteria = new CriteriaCompo(); if (is_array($groups) && !empty($groups)) { $criteriaTray = new CriteriaCompo(); foreach ($groups as $gid) { $criteriaTray->add(new Criteria('gperm_groupid', $gid), 'OR'); } $criteria->add($criteriaTray); if ($perm == 'imgcat_read' || $perm == 'imgcat_write') { $criteria->add(new Criteria('gperm_name', $perm)); $mid = $xoops->getModuleByDirname('images')->getVar('mid'); $criteria->add(new Criteria('gperm_modid', $mid)); } } if (isset($display)) { $criteria->add(new Criteria('imgcat_display', (int) $display)); } if (isset($storetype)) { $criteria->add(new Criteria('imgcat_storetype', $storetype)); } $categories = $this->getPermittedObjects($criteria, 0, 0, true); $ret = array(); foreach (array_keys($categories) as $i) { $ret[$i] = $categories[$i]->getVar('imgcat_name'); } return $ret; }
function execute() { $xoops = Xoops::getInstance(); if (!function_exists('mb_strlen')) { return true; } // registered users always pass this plugin if ($xoops->isUser()) { return true; } $lengths = array(0 => 100, 'message' => 2, 'com_text' => 2, 'excerpt' => 2); foreach ($_POST as $key => $data) { // dare to ignore arrays/objects if (!is_string($data)) { continue; } $check_length = isset($lengths[$key]) ? $lengths[$key] : $lengths[0]; if (strlen($data) > $check_length) { if (strlen($data) == mb_strlen($data)) { $this->protector->message .= "No multibyte character was found ({$data})\n"; $this->protector->output_log('Singlebyte SPAM', 0, false, 128); die('Protector rejects your post, because your post looks like SPAM'); } } } return true; }
/** * establish access to other classes we will use */ public function __construct() { $this->xoops = \Xoops::getInstance(); $this->httpRequest = HttpRequest::getInstance(); $this->sessionUser = new SessionUser($this); $this->fingerprint = new Fingerprint(); }
function smarty_function_xoMemberInfo($params, &$smarty) { $xoops = Xoops::getInstance(); $time = time(); $member_info = $_SESSION['xoops_member_info']; if (!$xoops->isUser()) { $member_info['uname'] = $xoops->getConfig('anonymous'); } else { if (@empty($params['infos'])) { $params['infos'] = 'uname|name|email|user_avatar|url|user_icq|user_aim|user_yim|user_msnm|posts|user_from|user_occ|user_intrest|bio|user_sig'; } $infos = explode("|", $params['infos']); if (!is_array($member_info)) { $member_info = array(); } foreach ($infos as $info) { if (!array_key_exists($info, $member_info) && @$_SESSION['xoops_member_info'][$info . '_expire'] < $time) { $member_info[$info] = $xoops->user->getVar($info, 'E'); $_SESSION['xoops_member_info'][$info] = $member_info[$info]; $_SESSION['xoops_member_info'][$info . '_expire'] = $time + 60; } } } if (!@empty($params['assign'])) { $smarty->assign($params['assign'], $member_info); } }
/** * XXX * * @copyright XOOPS Project (http://xoops.org) * @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html) * @since 2.6.0 * @author Mage Grégory (AKA Mage) * @version $Id: $ */ function xoops_module_update_search(XoopsModule &$module) { $xoops = Xoops::getInstance(); // Copy old configs in new configs and delete old configs $config_handler = $xoops->getHandlerConfig(); $criteria = new CriteriaCompo(); $criteria->add(new Criteria('conf_modid', 0)); $criteria->add(new Criteria('conf_catid', 5)); $configs = $config_handler->getConfigs($criteria); $confcount = count($configs); if ($confcount > 0) { for ($i = 0; $i < $confcount; ++$i) { $criteria = new CriteriaCompo(); $criteria->add(new Criteria('conf_modid', $module->getVar('mid'))); $criteria->add(new Criteria('conf_name', $configs[$i]->getvar('conf_name'))); $new_configs = $config_handler->getConfigs($criteria); $new_confcount = count($new_configs); if ($new_confcount > 0) { for ($j = 0; $j < $new_confcount; ++$j) { $obj = $config_handler->getConfig($new_configs[$j]->getvar('conf_id')); } $obj->setVar("conf_value", $configs[$i]->getvar('conf_value')); $config_handler->insertConfig($obj); $config_handler->deleteConfig($configs[$i]); } } } return true; }
/** * smarty_function_thumbnail * @param array $params associative array of parameters * image => xoops virtual path to image * w => thumbnail width in pixels * w => thumbnail height in pixels * @param object &$smarty smarty context * * @return string */ function smarty_function_thumbnail($params, &$smarty) { $image = isset($params['image']) ? $params['image'] : ''; $w = isset($params['w']) ? $params['w'] : 0; $h = isset($params['h']) ? $params['h'] : 0; return \Xoops::getInstance()->service('thumbnail')->getImgUrl($image, $w, $h)->getValue(); }
function page_blocks_edit($options) { $block_form = new Xoops\Form\BlockForm(); if ($options[0] != 'id') { $mode_form = new Xoops\Form\Select(PageLocale::CONF_BLOCK_MODE, 'options[0]', $options[0], 1, false); $mode_form->addOption('content', PageLocale::CONF_BLOCK_L_CONTENT); $mode_form->addOption('list', PageLocale::CONF_BLOCK_L_LIST); $block_form->addElement($mode_form); $order_form = new Xoops\Form\Select(PageLocale::CONF_BLOCK_ORDER, 'options[1]', $options[1], 1, false); $order_form->addOption('create', PageLocale::CONF_BLOCK_L_RECENT); $order_form->addOption('hits', PageLocale::CONF_BLOCK_L_HITS); $order_form->addOption('rating', PageLocale::CONF_BLOCK_L_RATING); $order_form->addOption('random', PageLocale::CONF_BLOCK_L_RANDOM); $block_form->addElement($order_form); $sort_form = new Xoops\Form\Select(PageLocale::CONF_BLOCK_SORT, 'options[2]', $options[2], 1, false); $sort_form->addOption('ASC', PageLocale::CONF_BLOCK_L_ASC); $sort_form->addOption('DESC', PageLocale::CONF_BLOCK_L_DESC); $block_form->addElement($sort_form); $block_form->addElement(new Xoops\Form\Text(PageLocale::CONF_BLOCK_DISPLAY_NUMBER, 'options[3]', 1, 2, $options[3]), true); $block_form->addElement(new Xoops\Form\RadioYesNo(PageLocale::CONF_BLOCK_ALL_CONTENT, 'options[4]', $options[4])); } else { $xoops = \Xoops::getInstance(); $page = $xoops->getModuleHelper('page'); $block_form->addElement(new Xoops\Form\Hidden('options[0]', $options[0])); $content = $page->getContentHandler()->getPageTitle(1); $select_form = new Xoops\Form\Select(PageLocale::CONF_BLOCK_CONTENTDISPLAY, 'options[1]', $options[1], 1, false); foreach ($content as $value) { $select_form->addOption($value['content_id'], $value['content_title']); } $block_form->addElement($select_form); } return $block_form->render(); }
/** * render * * @return string rendered form element */ public function render() { static $included = false; $xoops = \Xoops::getInstance(); $ele_value = (string) $this->getValue(false); $display_value = $ele_value; if (0 < (int) $ele_value) { $display_value = date(\XoopsLocale::getFormatShortDate(), $ele_value); } if ($this->getSize() > $this->getMaxcols()) { $maxcols = $this->getMaxcols(); } else { $maxcols = $this->getSize(); } $this->addAttribute('class', 'span' . $maxcols); $dlist = $this->isDatalist(); if (!empty($dlist)) { $this->addAttribute('list', 'list_' . $this->getName()); } $attributes = $this->renderAttributeString(); $xoops->theme()->addBaseStylesheetAssets('@jqueryuicss'); $xoops->theme()->addBaseScriptAssets('@jqueryui'); // TODO - select and apply script by locale, example: // $i18nScript = 'media/jquery/ui/i18n/datepicker-es.js'; // $xoops->theme()->addBaseScriptAssets($i18nScript); $xoops->theme()->addScript('', '', ' $(function() { $( "#' . $this->getAttribute('id') . '" ).datepicker({' . 'showOn: "button", buttonImageOnly: false, ' . 'buttonImage: "' . $xoops->url('media/xoops/images/icons/calendar.png') . '", ' . 'buttonImageOnly: false, buttonText: "' . \XoopsLocale::A_SELECT . '" }); }); '); return '<input ' . $attributes . 'value="' . $display_value . '" ' . $this->getExtra() . ' >'; }
/** *__construct * * @param array $xlanguage language options array */ public function __construct($xlanguage) { $xoops = Xoops::getInstance(); parent::__construct('', 'xlanguage_form', $xoops->getEnv('PHP_SELF'), 'post', true, 'horizontal'); $lang_tray = new Xoops\Form\Select(_XLANGUAGE_TINYMCE_SUBTITLE, 'select_language'); $lang_tray->addOption('', _XLANGUAGE_TINYMCE_SELECT); foreach ($xlanguage as $k => $v) { $lang_tray->addOption($v['xlanguage_code'], $v['xlanguage_description']); } $this->addElement($lang_tray, true); $text_tray = new Xoops\Form\TextArea('', 'text_language', '', 7, 7); $text_tray->setExtra('onkeyup="Xoops_xlanguageDialog.onkeyupMLC(this);"'); $this->addElement($text_tray); $this->addElement(new Xoops\Form\Raw('<div id="text_language_msg"><script type="text/javascript">Xoops_xlanguageDialog.onkeyupMLC(this);</script></div>')); /** * Buttons */ $button_tray = new Xoops\Form\ElementTray('', ''); $button = new Xoops\Form\Button('', 'submit', XoopsLocale::A_SUBMIT, 'insert'); $button->setExtra('onclick="Xoops_xlanguageDialog.insertMLC();return false;"'); $button->setClass('btn btn-success'); $button_tray->addElement($button); $button_2 = new Xoops\Form\Button('', 'button', XoopsLocale::A_CLOSE, 'button'); $button_2->setExtra('onclick="tinyMCEPopup.close();"'); $button_2->setClass('btn btn-danger'); $button_tray->addElement($button_2); $this->addElement($button_tray); }
/** * synchronize number of posts credited to user * * @param int $uid uid of user row * @param string $type type of processing, 'user' for one user, 'all users' for all * * @return void */ function synchronize($uid, $type) { $xoops = Xoops::getInstance(); $db = $xoops->db(); switch ($type) { case 'user': $total_posts = 0; /* @var $plugin SystemPluginInterface */ $plugins = \Xoops\Module\Plugin::getPlugins(); foreach ($plugins as $plugin) { if ($res = $plugin->userPosts($uid)) { $total_posts += $res; } } $query = $db->createXoopsQueryBuilder()->updatePrefix('system_user')->set('posts', ':posts')->where('uid = :uid')->setParameter(':posts', $total_posts)->setParameter(':uid', $uid); $result = $query->execute(); //if (!$result) { // $xoops->redirect("admin.php?fct=users", 1, XoopsLocale::E_USER_NOT_UPDATED); //} break; case 'all users': $sql = $db->createXoopsQueryBuilder()->select('uid')->fromPrefix('system_user', 'u'); $result = $sql->execute(); if (!$result) { $xoops->redirect("admin.php?fct=users", 1, XoopsLocale::E_USER_ID_NOT_FETCHED); } $rows = $result->fetchAll(); foreach ($rows as $row) { synchronize($row['uid'], "user"); } break; } }
/** * @param string $category * @param int $item_id * * @return array */ public function item($category, $item_id) { $xoops = Xoops::getInstance(); $item = array(); $item_id = (int) $item_id; if ($category == 'global') { $item['name'] = ''; $item['url'] = ''; return $item; } if ($category == 'category') { // Assume we have a valid category id $sql = 'SELECT name, short_url FROM ' . $xoopsDB->prefix('publisher_categories') . ' WHERE categoryid = ' . $item_id; $result = $xoopsDB->query($sql); // TODO: error check $result_array = $xoopsDB->fetchArray($result); $item['name'] = $result_array['name']; $item['url'] = PublisherUtils::seoGenUrl('category', $item_id, $result_array['short_url']); return $item; } if ($category == 'item') { // Assume we have a valid story id $sql = 'SELECT title, short_url FROM ' . $xoopsDB->prefix('publisher_items') . ' WHERE itemid = ' . $item_id; $result = $xoopsDB->query($sql); // TODO: error check $result_array = $xoopsDB->fetchArray($result); $item['name'] = $result_array['title']; $item['url'] = PublisherUtils::seoGenUrl('item', $item_id, $result_array['short_url']); return $item; } return $item; }
/** * Instantiate the specified theme * * @param array $options options array * * @return XoopsTheme */ public function createInstance($options = array()) { $xoops = \Xoops::getInstance(); // Grab the theme folder from request vars if present if (empty($options['folderName'])) { if (($req = @$_REQUEST['xoops_theme_select']) && $this->isThemeAllowed($req)) { $options['folderName'] = $req; if (isset($_SESSION) && $this->allowUserSelection) { $_SESSION[$this->xoBundleIdentifier]['defaultTheme'] = $req; } } else { if (isset($_SESSION[$this->xoBundleIdentifier]['defaultTheme'])) { $options['folderName'] = $_SESSION[$this->xoBundleIdentifier]['defaultTheme']; } else { if (empty($options['folderName']) || !$this->isThemeAllowed($options['folderName'])) { $options['folderName'] = $this->defaultTheme; } } } $xoops->setConfig('theme_set', $options['folderName']); } $options['path'] = \XoopsBaseConfig::get('themes-path') . '/' . $options['folderName']; $inst = new XoopsTheme(); foreach ($options as $k => $v) { $inst->{$k} = $v; } $inst->xoInit(); return $inst; }
/** * Get a list of localized timezone names * * @return array */ public static function getList() { $xoops = \Xoops::getInstance(); $locale = \Xoops\Locale::getCurrent(); $key = ['system', 'lists', 'timezone', $locale]; //$xoops->cache()->delete($key); $timeZones = $xoops->cache()->cacheRead($key, function () { $timeZones = array(); $territories = Territory::getContinentsAndCountries(); $maxLen = 0; $utcDtz = new \DateTimeZone('UTC'); foreach ($territories as $byContinent) { $continent = $byContinent['name']; foreach ($byContinent['children'] as $cCode => $cName) { $allZones = $utcDtz->listIdentifiers(\DateTimeZone::PER_COUNTRY, $cCode); foreach ($allZones as $zone) { $maxLen = max(strlen($zone), $maxLen); $name = Calendar::getTimezoneExemplarCity($zone); if (!isset($timeZones[$zone]) && !empty($name)) { $timeZones[$zone] = $continent . '/' . $name; } } } } \XoopsLocale::asort($timeZones); $default = array('UTC' => Calendar::getTimezoneNameNoLocationSpecific(new \DateTimeZone('GMT'))); $timeZones = array_merge($default, $timeZones); return $timeZones; }); return $timeZones; }
/** * Censor text string according to * * @param string $text text to censor * * @return string */ public function applyFilter($text) { $xoops = \Xoops::getInstance(); $enabled = (bool) $xoops->getConfig('censor_enable'); $censorWords = (array) $xoops->getConfig('censor_words'); $censorWords = empty($censorWords) ? $this->config['censor_words'] : $censorWords; $censorReplace = $xoops->getConfig('censor_replace'); $censorReplace = empty($censorReplace) ? $this->config['censor_replace'] : $censorReplace; if ($enabled === false || empty($censorWords) || false === $this->config['censor_admin'] && $xoops->userIsAdmin) { return $text; } $patterns = []; $replacements = []; foreach ($censorWords as $bad) { $bad = trim($bad); if (!empty($bad)) { if (false === stripos($text, $bad)) { continue; } if ((bool) $this->config['censor_terminate']) { trigger_error("Censor words found", E_USER_ERROR); return ''; } $patterns[] = "/(^|[^0-9a-z_]){$bad}([^0-9a-z_]|\$)/siU"; $replacements[] = "\\1{$censorReplace}\\2"; } } $text = preg_replace($patterns, $replacements, $text); return $text; }
protected function execute(InputInterface $input, OutputInterface $output) { $module = $input->getArgument('module'); $output->writeln(sprintf('Uninstalling %s', $module)); $xoops = \Xoops::getInstance(); if (false === $xoops->getModuleByDirname($module)) { $output->writeln(sprintf('<error>%s is not an installed module!</error>', $module)); return; } $xoops->setTpl(new \XoopsTpl()); \XoopsLoad::load('module', 'system'); $sysmod = new \SystemModule(); $result = $sysmod->uninstall($module); foreach ($sysmod->trace as $message) { if (is_array($message)) { foreach ($message as $subMessage) { if (!is_array($subMessage)) { $output->writeln(strip_tags($subMessage)); } } } else { $output->writeln(strip_tags($message)); } } if ($result === false) { $output->writeln(sprintf('<error>Uninstall of %s failed!</error>', $module)); } else { $output->writeln(sprintf('<info>Uninstall of %s completed.</info>', $module)); } $xoops->cache()->delete('system'); }
/** * Ask each sanitizer extension for default configuration * * @return array */ public function buildDefaultConfiguration() { $this->registerComponent(\Xoops\Core\Text\Sanitizer::getDefaultConfig()); $extensions = File::getList(__DIR__ . '/Extensions'); foreach ($extensions as $extensionFile) { if (substr($extensionFile, -4) === '.php') { $class = __NAMESPACE__ . '\\Extensions\\' . substr($extensionFile, 0, -4); if (is_a($class, 'Xoops\\Core\\Text\\Sanitizer\\SanitizerConfigurable', true)) { $this->registerComponent($class::getDefaultConfig()); } } } /** * Register any 3rd party extensions * * Listeners will be passed a Configuration object as the single argument, and should * call $arg->registerComponent() to register extensions * * All extensions must implement SanitizerConfigurable, extending either ExtensionAbstract * or FilterAbstract, and MUST autoload * * NB: Extensions and Filters all share the same configuration space, so a 3rd party * extension that has the same short name as system extension will override the system * supplied one. */ \Xoops::getInstance()->events()->triggerEvent('core.sanitizer.configuration.defaults', $this); return (array) $this; }