@@ -20,9 +20,9 @@ discard block |
||
| 20 | 20 | |
| 21 | 21 | use Xmf\Request; |
| 22 | 22 | use XoopsModules\Songlist\{ |
| 23 | - Common\Cloner, |
|
| 24 | - Helper, |
|
| 25 | - Utility |
|
| 23 | + Common\Cloner, |
|
| 24 | + Helper, |
|
| 25 | + Utility |
|
| 26 | 26 | }; |
| 27 | 27 | |
| 28 | 28 | require_once __DIR__ . '/admin_header.php'; |
@@ -32,53 +32,53 @@ discard block |
||
| 32 | 32 | $helper = Helper::getInstance(); |
| 33 | 33 | |
| 34 | 34 | if ('submit' === Request::getString('op', '', 'POST')) { |
| 35 | - if (!$GLOBALS['xoopsSecurity']->check()) { |
|
| 36 | - redirect_header('clone.php', 3, implode('<br>', $GLOBALS['xoopsSecurity']->getErrors())); |
|
| 37 | - } |
|
| 35 | + if (!$GLOBALS['xoopsSecurity']->check()) { |
|
| 36 | + redirect_header('clone.php', 3, implode('<br>', $GLOBALS['xoopsSecurity']->getErrors())); |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - // $clone = $_POST['clone']; |
|
| 40 | - $clone = Request::getString('clone', '', 'POST'); |
|
| 39 | + // $clone = $_POST['clone']; |
|
| 40 | + $clone = Request::getString('clone', '', 'POST'); |
|
| 41 | 41 | |
| 42 | - //check if name is valid |
|
| 43 | - if (empty($clone) || preg_match('/[^a-zA-Z0-9\_\-]/', $clone)) { |
|
| 44 | - redirect_header('clone.php', 3, sprintf(constant('CO_' . $moduleDirNameUpper . '_' . 'CLONE_INVALIDNAME'), $clone)); |
|
| 45 | - } |
|
| 42 | + //check if name is valid |
|
| 43 | + if (empty($clone) || preg_match('/[^a-zA-Z0-9\_\-]/', $clone)) { |
|
| 44 | + redirect_header('clone.php', 3, sprintf(constant('CO_' . $moduleDirNameUpper . '_' . 'CLONE_INVALIDNAME'), $clone)); |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - // Check wether the cloned module exists or not |
|
| 48 | - if ($clone && is_dir($GLOBALS['xoops']->path('modules/' . $clone))) { |
|
| 49 | - redirect_header('clone.php', 3, sprintf(constant('CO_' . $moduleDirNameUpper . '_' . 'CLONE_EXISTS'), $clone)); |
|
| 50 | - } |
|
| 47 | + // Check wether the cloned module exists or not |
|
| 48 | + if ($clone && is_dir($GLOBALS['xoops']->path('modules/' . $clone))) { |
|
| 49 | + redirect_header('clone.php', 3, sprintf(constant('CO_' . $moduleDirNameUpper . '_' . 'CLONE_EXISTS'), $clone)); |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - $patterns = [ |
|
| 53 | - \mb_strtolower($helper->dirname()) => \mb_strtolower($clone), |
|
| 54 | - \mb_strtoupper($helper->dirname()) => \mb_strtoupper($clone), |
|
| 55 | - ucfirst(mb_strtolower($helper->dirname())) => ucfirst(mb_strtolower($clone)), |
|
| 56 | - ]; |
|
| 52 | + $patterns = [ |
|
| 53 | + \mb_strtolower($helper->dirname()) => \mb_strtolower($clone), |
|
| 54 | + \mb_strtoupper($helper->dirname()) => \mb_strtoupper($clone), |
|
| 55 | + ucfirst(mb_strtolower($helper->dirname())) => ucfirst(mb_strtolower($clone)), |
|
| 56 | + ]; |
|
| 57 | 57 | |
| 58 | - $patKeys = array_keys($patterns); |
|
| 59 | - $patValues = array_values($patterns); |
|
| 60 | - Cloner::cloneFileFolder($helper->path()); |
|
| 61 | - $logocreated = Cloner::createLogo(mb_strtolower($clone)); |
|
| 58 | + $patKeys = array_keys($patterns); |
|
| 59 | + $patValues = array_values($patterns); |
|
| 60 | + Cloner::cloneFileFolder($helper->path()); |
|
| 61 | + $logocreated = Cloner::createLogo(mb_strtolower($clone)); |
|
| 62 | 62 | |
| 63 | - $msg = ''; |
|
| 64 | - if (is_dir($GLOBALS['xoops']->path('modules/' . \mb_strtolower($clone)))) { |
|
| 65 | - $msg .= sprintf(constant('CO_' . $moduleDirNameUpper . '_' . 'CLONE_CONGRAT'), "<a href='" . XOOPS_URL . "/modules/system/admin.php?fct=modulesadmin'>" . ucfirst(mb_strtolower($clone)) . '</a>') . "<br>\n"; |
|
| 66 | - if (!$logocreated) { |
|
| 67 | - $msg .= constant('CO_' . $moduleDirNameUpper . '_' . 'CLONE_IMAGEFAIL'); |
|
| 68 | - } |
|
| 69 | - } else { |
|
| 70 | - $msg .= constant('CO_' . $moduleDirNameUpper . '_' . 'CLONE_FAIL'); |
|
| 71 | - } |
|
| 72 | - echo $msg; |
|
| 63 | + $msg = ''; |
|
| 64 | + if (is_dir($GLOBALS['xoops']->path('modules/' . \mb_strtolower($clone)))) { |
|
| 65 | + $msg .= sprintf(constant('CO_' . $moduleDirNameUpper . '_' . 'CLONE_CONGRAT'), "<a href='" . XOOPS_URL . "/modules/system/admin.php?fct=modulesadmin'>" . ucfirst(mb_strtolower($clone)) . '</a>') . "<br>\n"; |
|
| 66 | + if (!$logocreated) { |
|
| 67 | + $msg .= constant('CO_' . $moduleDirNameUpper . '_' . 'CLONE_IMAGEFAIL'); |
|
| 68 | + } |
|
| 69 | + } else { |
|
| 70 | + $msg .= constant('CO_' . $moduleDirNameUpper . '_' . 'CLONE_FAIL'); |
|
| 71 | + } |
|
| 72 | + echo $msg; |
|
| 73 | 73 | } else { |
| 74 | - require_once $GLOBALS['xoops']->path('class/xoopsformloader.php'); |
|
| 75 | - $form = new \XoopsThemeForm(sprintf(constant('CO_' . $moduleDirNameUpper . '_' . 'CLONE_TITLE'), (string)$helper->getModule()->getVar('name', 'E')), 'clone', 'clone.php', 'post', true); |
|
| 76 | - $clone = new \XoopsFormText(constant('CO_' . $moduleDirNameUpper . '_' . 'CLONE_NAME'), 'clone', 20, 20, ''); |
|
| 77 | - $clone->setDescription(constant('CO_' . $moduleDirNameUpper . '_' . 'CLONE_NAME_DSC')); |
|
| 78 | - $form->addElement($clone, true); |
|
| 79 | - $form->addElement(new \XoopsFormHidden('op', 'submit')); |
|
| 80 | - $form->addElement(new \XoopsFormButton('', '', _SUBMIT, 'submit')); |
|
| 81 | - $form->display(); |
|
| 74 | + require_once $GLOBALS['xoops']->path('class/xoopsformloader.php'); |
|
| 75 | + $form = new \XoopsThemeForm(sprintf(constant('CO_' . $moduleDirNameUpper . '_' . 'CLONE_TITLE'), (string)$helper->getModule()->getVar('name', 'E')), 'clone', 'clone.php', 'post', true); |
|
| 76 | + $clone = new \XoopsFormText(constant('CO_' . $moduleDirNameUpper . '_' . 'CLONE_NAME'), 'clone', 20, 20, ''); |
|
| 77 | + $clone->setDescription(constant('CO_' . $moduleDirNameUpper . '_' . 'CLONE_NAME_DSC')); |
|
| 78 | + $form->addElement($clone, true); |
|
| 79 | + $form->addElement(new \XoopsFormHidden('op', 'submit')); |
|
| 80 | + $form->addElement(new \XoopsFormButton('', '', _SUBMIT, 'submit')); |
|
| 81 | + $form->display(); |
|
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | require_once __DIR__ . '/admin_footer.php'; |
@@ -25,13 +25,13 @@ discard block |
||
| 25 | 25 | Utility |
| 26 | 26 | }; |
| 27 | 27 | |
| 28 | -require_once __DIR__ . '/admin_header.php'; |
|
| 28 | +require_once __DIR__.'/admin_header.php'; |
|
| 29 | 29 | |
| 30 | 30 | xoops_cp_header(); |
| 31 | 31 | |
| 32 | 32 | $helper = Helper::getInstance(); |
| 33 | 33 | |
| 34 | -if ('submit' === Request::getString('op', '', 'POST')) { |
|
| 34 | +if ('submit'===Request::getString('op', '', 'POST')) { |
|
| 35 | 35 | if (!$GLOBALS['xoopsSecurity']->check()) { |
| 36 | 36 | redirect_header('clone.php', 3, implode('<br>', $GLOBALS['xoopsSecurity']->getErrors())); |
| 37 | 37 | } |
@@ -41,12 +41,12 @@ discard block |
||
| 41 | 41 | |
| 42 | 42 | //check if name is valid |
| 43 | 43 | if (empty($clone) || preg_match('/[^a-zA-Z0-9\_\-]/', $clone)) { |
| 44 | - redirect_header('clone.php', 3, sprintf(constant('CO_' . $moduleDirNameUpper . '_' . 'CLONE_INVALIDNAME'), $clone)); |
|
| 44 | + redirect_header('clone.php', 3, sprintf(constant('CO_'.$moduleDirNameUpper.'_'.'CLONE_INVALIDNAME'), $clone)); |
|
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | // Check wether the cloned module exists or not |
| 48 | - if ($clone && is_dir($GLOBALS['xoops']->path('modules/' . $clone))) { |
|
| 49 | - redirect_header('clone.php', 3, sprintf(constant('CO_' . $moduleDirNameUpper . '_' . 'CLONE_EXISTS'), $clone)); |
|
| 48 | + if ($clone && is_dir($GLOBALS['xoops']->path('modules/'.$clone))) { |
|
| 49 | + redirect_header('clone.php', 3, sprintf(constant('CO_'.$moduleDirNameUpper.'_'.'CLONE_EXISTS'), $clone)); |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | $patterns = [ |
@@ -61,24 +61,24 @@ discard block |
||
| 61 | 61 | $logocreated = Cloner::createLogo(mb_strtolower($clone)); |
| 62 | 62 | |
| 63 | 63 | $msg = ''; |
| 64 | - if (is_dir($GLOBALS['xoops']->path('modules/' . \mb_strtolower($clone)))) { |
|
| 65 | - $msg .= sprintf(constant('CO_' . $moduleDirNameUpper . '_' . 'CLONE_CONGRAT'), "<a href='" . XOOPS_URL . "/modules/system/admin.php?fct=modulesadmin'>" . ucfirst(mb_strtolower($clone)) . '</a>') . "<br>\n"; |
|
| 64 | + if (is_dir($GLOBALS['xoops']->path('modules/'.\mb_strtolower($clone)))) { |
|
| 65 | + $msg .= sprintf(constant('CO_'.$moduleDirNameUpper.'_'.'CLONE_CONGRAT'), "<a href='".XOOPS_URL."/modules/system/admin.php?fct=modulesadmin'>".ucfirst(mb_strtolower($clone)).'</a>')."<br>\n"; |
|
| 66 | 66 | if (!$logocreated) { |
| 67 | - $msg .= constant('CO_' . $moduleDirNameUpper . '_' . 'CLONE_IMAGEFAIL'); |
|
| 67 | + $msg .= constant('CO_'.$moduleDirNameUpper.'_'.'CLONE_IMAGEFAIL'); |
|
| 68 | 68 | } |
| 69 | 69 | } else { |
| 70 | - $msg .= constant('CO_' . $moduleDirNameUpper . '_' . 'CLONE_FAIL'); |
|
| 70 | + $msg .= constant('CO_'.$moduleDirNameUpper.'_'.'CLONE_FAIL'); |
|
| 71 | 71 | } |
| 72 | 72 | echo $msg; |
| 73 | 73 | } else { |
| 74 | 74 | require_once $GLOBALS['xoops']->path('class/xoopsformloader.php'); |
| 75 | - $form = new \XoopsThemeForm(sprintf(constant('CO_' . $moduleDirNameUpper . '_' . 'CLONE_TITLE'), (string)$helper->getModule()->getVar('name', 'E')), 'clone', 'clone.php', 'post', true); |
|
| 76 | - $clone = new \XoopsFormText(constant('CO_' . $moduleDirNameUpper . '_' . 'CLONE_NAME'), 'clone', 20, 20, ''); |
|
| 77 | - $clone->setDescription(constant('CO_' . $moduleDirNameUpper . '_' . 'CLONE_NAME_DSC')); |
|
| 75 | + $form = new \XoopsThemeForm(sprintf(constant('CO_'.$moduleDirNameUpper.'_'.'CLONE_TITLE'), (string) $helper->getModule()->getVar('name', 'E')), 'clone', 'clone.php', 'post', true); |
|
| 76 | + $clone = new \XoopsFormText(constant('CO_'.$moduleDirNameUpper.'_'.'CLONE_NAME'), 'clone', 20, 20, ''); |
|
| 77 | + $clone->setDescription(constant('CO_'.$moduleDirNameUpper.'_'.'CLONE_NAME_DSC')); |
|
| 78 | 78 | $form->addElement($clone, true); |
| 79 | 79 | $form->addElement(new \XoopsFormHidden('op', 'submit')); |
| 80 | 80 | $form->addElement(new \XoopsFormButton('', '', _SUBMIT, 'submit')); |
| 81 | 81 | $form->display(); |
| 82 | 82 | } |
| 83 | 83 | |
| 84 | -require_once __DIR__ . '/admin_footer.php'; |
|
| 84 | +require_once __DIR__.'/admin_footer.php'; |
|
@@ -21,156 +21,156 @@ |
||
| 21 | 21 | $filter = !empty($_REQUEST['filter']) ? '' . $_REQUEST['filter'] . '' : '1,1'; |
| 22 | 22 | |
| 23 | 23 | switch ($op) { |
| 24 | - default: |
|
| 25 | - case 'requests': |
|
| 26 | - switch ($fct) { |
|
| 27 | - default: |
|
| 28 | - case 'list': |
|
| 29 | - $adminObject = Admin::getInstance(); |
|
| 30 | - $adminObject->displayNavigation(basename(__FILE__)); |
|
| 31 | - |
|
| 32 | - /** @var RequestsHandler $requestsHandler */ |
|
| 33 | - $requestsHandler = Helper::getInstance()->getHandler('Requests'); |
|
| 34 | - |
|
| 35 | - $criteria = $requestsHandler->getFilterCriteria($GLOBALS['filter']); |
|
| 36 | - $ttl = $requestsHandler->getCount($criteria); |
|
| 37 | - $GLOBALS['sort'] = !empty($_REQUEST['sort']) ? '' . $_REQUEST['sort'] . '' : 'created'; |
|
| 38 | - |
|
| 39 | - $pagenav = new \XoopsPageNav($ttl, $GLOBALS['limit'], $GLOBALS['start'], 'start', 'limit=' . $GLOBALS['limit'] . '&sort=' . $GLOBALS['sort'] . '&order=' . $GLOBALS['order'] . '&op=' . $GLOBALS['op'] . '&fct=' . $GLOBALS['fct'] . '&filter=' . $GLOBALS['filter']); |
|
| 40 | - $GLOBALS['xoopsTpl']->assign('pagenav', $pagenav->renderNav()); |
|
| 41 | - |
|
| 42 | - foreach ($requestsHandler->filterFields() as $id => $key) { |
|
| 43 | - $GLOBALS['xoopsTpl']->assign( |
|
| 44 | - \mb_strtolower(str_replace('-', '_', $key) . '_th'), |
|
| 45 | - '<a href="' |
|
| 46 | - . $_SERVER['SCRIPT_NAME'] |
|
| 47 | - . '?start=' |
|
| 48 | - . $GLOBALS['start'] |
|
| 49 | - . '&limit=' |
|
| 50 | - . $GLOBALS['limit'] |
|
| 51 | - . '&sort=' |
|
| 52 | - . $key |
|
| 53 | - . '&order=' |
|
| 54 | - . (($key == $GLOBALS['sort']) ? ('DESC' === $GLOBALS['order'] ? 'ASC' : 'DESC') : $GLOBALS['order']) |
|
| 55 | - . '&op=' |
|
| 56 | - . $GLOBALS['op'] |
|
| 57 | - . '&filter=' |
|
| 58 | - . $GLOBALS['filter'] |
|
| 59 | - . '">' |
|
| 60 | - . (defined('_AM_SONGLIST_TH_' . \mb_strtoupper(str_replace('-', '_', $key))) ? constant('_AM_SONGLIST_TH_' . \mb_strtoupper(str_replace('-', '_', $key))) : '_AM_SONGLIST_TH_' . \mb_strtoupper(str_replace('-', '_', $key))) |
|
| 61 | - . '</a>' |
|
| 62 | - ); |
|
| 63 | - $GLOBALS['xoopsTpl']->assign('filter_' . \mb_strtolower(str_replace('-', '_', $key)) . '_th', $requestsHandler->getFilterForm($GLOBALS['filter'], $key, $GLOBALS['sort'], $GLOBALS['op'], $GLOBALS['fct'])); |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - $GLOBALS['xoopsTpl']->assign('limit', $GLOBALS['limit']); |
|
| 67 | - $GLOBALS['xoopsTpl']->assign('start', $GLOBALS['start']); |
|
| 68 | - $GLOBALS['xoopsTpl']->assign('order', $GLOBALS['order']); |
|
| 69 | - $GLOBALS['xoopsTpl']->assign('sort', $GLOBALS['sort']); |
|
| 70 | - $GLOBALS['xoopsTpl']->assign('filter', $GLOBALS['filter']); |
|
| 71 | - $GLOBALS['xoopsTpl']->assign('xoConfig', $GLOBALS['songlistModuleConfig']); |
|
| 72 | - |
|
| 73 | - $criteria->setStart($GLOBALS['start']); |
|
| 74 | - $criteria->setLimit($GLOBALS['limit']); |
|
| 75 | - $criteria->setSort('`' . $GLOBALS['sort'] . '`'); |
|
| 76 | - $criteria->setOrder($GLOBALS['order']); |
|
| 77 | - |
|
| 78 | - $requestss = $requestsHandler->getObjects($criteria, true); |
|
| 79 | - foreach ($requestss as $cid => $requests) { |
|
| 80 | - if (is_object($requests)) { |
|
| 81 | - $GLOBALS['xoopsTpl']->append('requests', $requests->toArray()); |
|
| 82 | - } |
|
| 83 | - } |
|
| 84 | - $GLOBALS['xoopsTpl']->assign('form', FormController::getFormRequests(false)); |
|
| 85 | - $GLOBALS['xoopsTpl']->assign('php_self', $_SERVER['SCRIPT_NAME']); |
|
| 86 | - $GLOBALS['xoopsTpl']->display('db:songlist_cpanel_requests_list.tpl'); |
|
| 87 | - break; |
|
| 88 | - case 'new': |
|
| 89 | - case 'edit': |
|
| 90 | - $adminObject = Admin::getInstance(); |
|
| 91 | - $adminObject->displayNavigation(basename(__FILE__)); |
|
| 92 | - |
|
| 93 | - $requestsHandler = Helper::getInstance()->getHandler('Requests'); |
|
| 94 | - if (Request::hasVar('id', 'REQUEST')) { |
|
| 95 | - $requests = $requestsHandler->get(Request::getInt('id', 0, 'REQUEST')); |
|
| 96 | - } else { |
|
| 97 | - $requests = $requestsHandler->create(); |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - $GLOBALS['xoopsTpl']->assign('form', $requests->getForm()); |
|
| 101 | - $GLOBALS['xoopsTpl']->assign('php_self', $_SERVER['SCRIPT_NAME']); |
|
| 102 | - $GLOBALS['xoopsTpl']->display('db:songlist_cpanel_requests_edit.tpl'); |
|
| 103 | - break; |
|
| 104 | - case 'save': |
|
| 105 | - $requestsHandler = Helper::getInstance()->getHandler('Requests'); |
|
| 106 | - $id = 0; |
|
| 107 | - $id = Request::getInt('id', 0, 'REQUEST'); |
|
| 108 | - if ($id) { |
|
| 109 | - $requests = $requestsHandler->get($id); |
|
| 110 | - } else { |
|
| 111 | - $requests = $requestsHandler->create(); |
|
| 112 | - } |
|
| 113 | - $requests->setVars($_POST[$id]); |
|
| 114 | - |
|
| 115 | - if (!$id = $requestsHandler->insert($requests)) { |
|
| 116 | - redirect_header($_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], 10, _AM_SONGLIST_MSG_REQUESTS_FAILEDTOSAVE); |
|
| 117 | - exit(0); |
|
| 118 | - } |
|
| 119 | - if ('new' === $_REQUEST['state'][$_REQUEST['id']]) { |
|
| 120 | - redirect_header( |
|
| 121 | - $_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=edit&id=' . $_REQUEST['id'] . '&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], |
|
| 122 | - 10, |
|
| 123 | - _AM_SONGLIST_MSG_REQUESTS_SAVEDOKEY |
|
| 124 | - ); |
|
| 125 | - } else { |
|
| 126 | - redirect_header($_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], 10, _AM_SONGLIST_MSG_REQUESTS_SAVEDOKEY); |
|
| 127 | - } |
|
| 128 | - exit(0); |
|
| 129 | - |
|
| 130 | - break; |
|
| 131 | - case 'savelist': |
|
| 132 | - $requestsHandler = Helper::getInstance()->getHandler('Requests'); |
|
| 133 | - foreach ($_REQUEST['id'] as $id) { |
|
| 134 | - $requests = $requestsHandler->get($id); |
|
| 135 | - $requests->setVars($_POST[$id]); |
|
| 136 | - if (!$requestsHandler->insert($requests)) { |
|
| 137 | - redirect_header( |
|
| 138 | - $_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], |
|
| 139 | - 10, |
|
| 140 | - _AM_SONGLIST_MSG_REQUESTS_FAILEDTOSAVE |
|
| 141 | - ); |
|
| 142 | - exit(0); |
|
| 143 | - } |
|
| 144 | - } |
|
| 145 | - redirect_header($_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], 10, _AM_SONGLIST_MSG_REQUESTS_SAVEDOKEY); |
|
| 146 | - exit(0); |
|
| 147 | - break; |
|
| 148 | - case 'delete': |
|
| 149 | - $requestsHandler = Helper::getInstance()->getHandler('Requests'); |
|
| 150 | - $id = 0; |
|
| 151 | - if (Request::hasVar('id', 'POST') && $id = Request::getInt('id', 0, 'POST')) { |
|
| 152 | - $requests = $requestsHandler->get($id); |
|
| 153 | - if (!$requestsHandler->delete($requests)) { |
|
| 154 | - redirect_header( |
|
| 155 | - $_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], |
|
| 156 | - 10, |
|
| 157 | - _AM_SONGLIST_MSG_REQUESTS_FAILEDTODELETE |
|
| 158 | - ); |
|
| 159 | - exit(0); |
|
| 160 | - } |
|
| 161 | - redirect_header($_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], 10, _AM_SONGLIST_MSG_REQUESTS_DELETED); |
|
| 162 | - exit(0); |
|
| 163 | - } |
|
| 164 | - $requests = $requestsHandler->get(Request::getInt('id', 0, 'REQUEST')); |
|
| 165 | - xoops_confirm( |
|
| 166 | - ['id' => $_REQUEST['id'], 'op' => $_REQUEST['op'], 'fct' => $_REQUEST['fct'], 'limit' => $_REQUEST['limit'], 'start' => $_REQUEST['start'], 'order' => $_REQUEST['order'], 'sort' => $_REQUEST['sort'], 'filter' => $_REQUEST['filter']], |
|
| 167 | - $_SERVER['SCRIPT_NAME'], |
|
| 168 | - sprintf(_AM_SONGLIST_MSG_REQUESTS_DELETE, $requests->getVar('name')) |
|
| 169 | - ); |
|
| 170 | - |
|
| 171 | - break; |
|
| 172 | - } |
|
| 173 | - break; |
|
| 24 | + default: |
|
| 25 | + case 'requests': |
|
| 26 | + switch ($fct) { |
|
| 27 | + default: |
|
| 28 | + case 'list': |
|
| 29 | + $adminObject = Admin::getInstance(); |
|
| 30 | + $adminObject->displayNavigation(basename(__FILE__)); |
|
| 31 | + |
|
| 32 | + /** @var RequestsHandler $requestsHandler */ |
|
| 33 | + $requestsHandler = Helper::getInstance()->getHandler('Requests'); |
|
| 34 | + |
|
| 35 | + $criteria = $requestsHandler->getFilterCriteria($GLOBALS['filter']); |
|
| 36 | + $ttl = $requestsHandler->getCount($criteria); |
|
| 37 | + $GLOBALS['sort'] = !empty($_REQUEST['sort']) ? '' . $_REQUEST['sort'] . '' : 'created'; |
|
| 38 | + |
|
| 39 | + $pagenav = new \XoopsPageNav($ttl, $GLOBALS['limit'], $GLOBALS['start'], 'start', 'limit=' . $GLOBALS['limit'] . '&sort=' . $GLOBALS['sort'] . '&order=' . $GLOBALS['order'] . '&op=' . $GLOBALS['op'] . '&fct=' . $GLOBALS['fct'] . '&filter=' . $GLOBALS['filter']); |
|
| 40 | + $GLOBALS['xoopsTpl']->assign('pagenav', $pagenav->renderNav()); |
|
| 41 | + |
|
| 42 | + foreach ($requestsHandler->filterFields() as $id => $key) { |
|
| 43 | + $GLOBALS['xoopsTpl']->assign( |
|
| 44 | + \mb_strtolower(str_replace('-', '_', $key) . '_th'), |
|
| 45 | + '<a href="' |
|
| 46 | + . $_SERVER['SCRIPT_NAME'] |
|
| 47 | + . '?start=' |
|
| 48 | + . $GLOBALS['start'] |
|
| 49 | + . '&limit=' |
|
| 50 | + . $GLOBALS['limit'] |
|
| 51 | + . '&sort=' |
|
| 52 | + . $key |
|
| 53 | + . '&order=' |
|
| 54 | + . (($key == $GLOBALS['sort']) ? ('DESC' === $GLOBALS['order'] ? 'ASC' : 'DESC') : $GLOBALS['order']) |
|
| 55 | + . '&op=' |
|
| 56 | + . $GLOBALS['op'] |
|
| 57 | + . '&filter=' |
|
| 58 | + . $GLOBALS['filter'] |
|
| 59 | + . '">' |
|
| 60 | + . (defined('_AM_SONGLIST_TH_' . \mb_strtoupper(str_replace('-', '_', $key))) ? constant('_AM_SONGLIST_TH_' . \mb_strtoupper(str_replace('-', '_', $key))) : '_AM_SONGLIST_TH_' . \mb_strtoupper(str_replace('-', '_', $key))) |
|
| 61 | + . '</a>' |
|
| 62 | + ); |
|
| 63 | + $GLOBALS['xoopsTpl']->assign('filter_' . \mb_strtolower(str_replace('-', '_', $key)) . '_th', $requestsHandler->getFilterForm($GLOBALS['filter'], $key, $GLOBALS['sort'], $GLOBALS['op'], $GLOBALS['fct'])); |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + $GLOBALS['xoopsTpl']->assign('limit', $GLOBALS['limit']); |
|
| 67 | + $GLOBALS['xoopsTpl']->assign('start', $GLOBALS['start']); |
|
| 68 | + $GLOBALS['xoopsTpl']->assign('order', $GLOBALS['order']); |
|
| 69 | + $GLOBALS['xoopsTpl']->assign('sort', $GLOBALS['sort']); |
|
| 70 | + $GLOBALS['xoopsTpl']->assign('filter', $GLOBALS['filter']); |
|
| 71 | + $GLOBALS['xoopsTpl']->assign('xoConfig', $GLOBALS['songlistModuleConfig']); |
|
| 72 | + |
|
| 73 | + $criteria->setStart($GLOBALS['start']); |
|
| 74 | + $criteria->setLimit($GLOBALS['limit']); |
|
| 75 | + $criteria->setSort('`' . $GLOBALS['sort'] . '`'); |
|
| 76 | + $criteria->setOrder($GLOBALS['order']); |
|
| 77 | + |
|
| 78 | + $requestss = $requestsHandler->getObjects($criteria, true); |
|
| 79 | + foreach ($requestss as $cid => $requests) { |
|
| 80 | + if (is_object($requests)) { |
|
| 81 | + $GLOBALS['xoopsTpl']->append('requests', $requests->toArray()); |
|
| 82 | + } |
|
| 83 | + } |
|
| 84 | + $GLOBALS['xoopsTpl']->assign('form', FormController::getFormRequests(false)); |
|
| 85 | + $GLOBALS['xoopsTpl']->assign('php_self', $_SERVER['SCRIPT_NAME']); |
|
| 86 | + $GLOBALS['xoopsTpl']->display('db:songlist_cpanel_requests_list.tpl'); |
|
| 87 | + break; |
|
| 88 | + case 'new': |
|
| 89 | + case 'edit': |
|
| 90 | + $adminObject = Admin::getInstance(); |
|
| 91 | + $adminObject->displayNavigation(basename(__FILE__)); |
|
| 92 | + |
|
| 93 | + $requestsHandler = Helper::getInstance()->getHandler('Requests'); |
|
| 94 | + if (Request::hasVar('id', 'REQUEST')) { |
|
| 95 | + $requests = $requestsHandler->get(Request::getInt('id', 0, 'REQUEST')); |
|
| 96 | + } else { |
|
| 97 | + $requests = $requestsHandler->create(); |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + $GLOBALS['xoopsTpl']->assign('form', $requests->getForm()); |
|
| 101 | + $GLOBALS['xoopsTpl']->assign('php_self', $_SERVER['SCRIPT_NAME']); |
|
| 102 | + $GLOBALS['xoopsTpl']->display('db:songlist_cpanel_requests_edit.tpl'); |
|
| 103 | + break; |
|
| 104 | + case 'save': |
|
| 105 | + $requestsHandler = Helper::getInstance()->getHandler('Requests'); |
|
| 106 | + $id = 0; |
|
| 107 | + $id = Request::getInt('id', 0, 'REQUEST'); |
|
| 108 | + if ($id) { |
|
| 109 | + $requests = $requestsHandler->get($id); |
|
| 110 | + } else { |
|
| 111 | + $requests = $requestsHandler->create(); |
|
| 112 | + } |
|
| 113 | + $requests->setVars($_POST[$id]); |
|
| 114 | + |
|
| 115 | + if (!$id = $requestsHandler->insert($requests)) { |
|
| 116 | + redirect_header($_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], 10, _AM_SONGLIST_MSG_REQUESTS_FAILEDTOSAVE); |
|
| 117 | + exit(0); |
|
| 118 | + } |
|
| 119 | + if ('new' === $_REQUEST['state'][$_REQUEST['id']]) { |
|
| 120 | + redirect_header( |
|
| 121 | + $_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=edit&id=' . $_REQUEST['id'] . '&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], |
|
| 122 | + 10, |
|
| 123 | + _AM_SONGLIST_MSG_REQUESTS_SAVEDOKEY |
|
| 124 | + ); |
|
| 125 | + } else { |
|
| 126 | + redirect_header($_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], 10, _AM_SONGLIST_MSG_REQUESTS_SAVEDOKEY); |
|
| 127 | + } |
|
| 128 | + exit(0); |
|
| 129 | + |
|
| 130 | + break; |
|
| 131 | + case 'savelist': |
|
| 132 | + $requestsHandler = Helper::getInstance()->getHandler('Requests'); |
|
| 133 | + foreach ($_REQUEST['id'] as $id) { |
|
| 134 | + $requests = $requestsHandler->get($id); |
|
| 135 | + $requests->setVars($_POST[$id]); |
|
| 136 | + if (!$requestsHandler->insert($requests)) { |
|
| 137 | + redirect_header( |
|
| 138 | + $_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], |
|
| 139 | + 10, |
|
| 140 | + _AM_SONGLIST_MSG_REQUESTS_FAILEDTOSAVE |
|
| 141 | + ); |
|
| 142 | + exit(0); |
|
| 143 | + } |
|
| 144 | + } |
|
| 145 | + redirect_header($_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], 10, _AM_SONGLIST_MSG_REQUESTS_SAVEDOKEY); |
|
| 146 | + exit(0); |
|
| 147 | + break; |
|
| 148 | + case 'delete': |
|
| 149 | + $requestsHandler = Helper::getInstance()->getHandler('Requests'); |
|
| 150 | + $id = 0; |
|
| 151 | + if (Request::hasVar('id', 'POST') && $id = Request::getInt('id', 0, 'POST')) { |
|
| 152 | + $requests = $requestsHandler->get($id); |
|
| 153 | + if (!$requestsHandler->delete($requests)) { |
|
| 154 | + redirect_header( |
|
| 155 | + $_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], |
|
| 156 | + 10, |
|
| 157 | + _AM_SONGLIST_MSG_REQUESTS_FAILEDTODELETE |
|
| 158 | + ); |
|
| 159 | + exit(0); |
|
| 160 | + } |
|
| 161 | + redirect_header($_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], 10, _AM_SONGLIST_MSG_REQUESTS_DELETED); |
|
| 162 | + exit(0); |
|
| 163 | + } |
|
| 164 | + $requests = $requestsHandler->get(Request::getInt('id', 0, 'REQUEST')); |
|
| 165 | + xoops_confirm( |
|
| 166 | + ['id' => $_REQUEST['id'], 'op' => $_REQUEST['op'], 'fct' => $_REQUEST['fct'], 'limit' => $_REQUEST['limit'], 'start' => $_REQUEST['start'], 'order' => $_REQUEST['order'], 'sort' => $_REQUEST['sort'], 'filter' => $_REQUEST['filter']], |
|
| 167 | + $_SERVER['SCRIPT_NAME'], |
|
| 168 | + sprintf(_AM_SONGLIST_MSG_REQUESTS_DELETE, $requests->getVar('name')) |
|
| 169 | + ); |
|
| 170 | + |
|
| 171 | + break; |
|
| 172 | + } |
|
| 173 | + break; |
|
| 174 | 174 | } |
| 175 | 175 | |
| 176 | 176 | xoops_cp_footer(); |
@@ -6,7 +6,7 @@ discard block |
||
| 6 | 6 | use XoopsModules\Songlist\RequestsHandler; |
| 7 | 7 | use XoopsModules\Songlist\Form\FormController; |
| 8 | 8 | |
| 9 | -require __DIR__ . '/header.php'; |
|
| 9 | +require __DIR__.'/header.php'; |
|
| 10 | 10 | |
| 11 | 11 | xoops_loadLanguage('admin', 'songlist'); |
| 12 | 12 | |
@@ -17,8 +17,8 @@ discard block |
||
| 17 | 17 | $limit = Request::getInt('limit', 30, 'REQUEST'); |
| 18 | 18 | $start = Request::getInt('start', 0, 'REQUEST'); |
| 19 | 19 | $order = !empty($_REQUEST['order']) ? $_REQUEST['order'] : 'DESC'; |
| 20 | -$sort = !empty($_REQUEST['sort']) ? '' . $_REQUEST['sort'] . '' : 'created'; |
|
| 21 | -$filter = !empty($_REQUEST['filter']) ? '' . $_REQUEST['filter'] . '' : '1,1'; |
|
| 20 | +$sort = !empty($_REQUEST['sort']) ? ''.$_REQUEST['sort'].'' : 'created'; |
|
| 21 | +$filter = !empty($_REQUEST['filter']) ? ''.$_REQUEST['filter'].'' : '1,1'; |
|
| 22 | 22 | |
| 23 | 23 | switch ($op) { |
| 24 | 24 | default: |
@@ -34,14 +34,14 @@ discard block |
||
| 34 | 34 | |
| 35 | 35 | $criteria = $requestsHandler->getFilterCriteria($GLOBALS['filter']); |
| 36 | 36 | $ttl = $requestsHandler->getCount($criteria); |
| 37 | - $GLOBALS['sort'] = !empty($_REQUEST['sort']) ? '' . $_REQUEST['sort'] . '' : 'created'; |
|
| 37 | + $GLOBALS['sort'] = !empty($_REQUEST['sort']) ? ''.$_REQUEST['sort'].'' : 'created'; |
|
| 38 | 38 | |
| 39 | - $pagenav = new \XoopsPageNav($ttl, $GLOBALS['limit'], $GLOBALS['start'], 'start', 'limit=' . $GLOBALS['limit'] . '&sort=' . $GLOBALS['sort'] . '&order=' . $GLOBALS['order'] . '&op=' . $GLOBALS['op'] . '&fct=' . $GLOBALS['fct'] . '&filter=' . $GLOBALS['filter']); |
|
| 39 | + $pagenav = new \XoopsPageNav($ttl, $GLOBALS['limit'], $GLOBALS['start'], 'start', 'limit='.$GLOBALS['limit'].'&sort='.$GLOBALS['sort'].'&order='.$GLOBALS['order'].'&op='.$GLOBALS['op'].'&fct='.$GLOBALS['fct'].'&filter='.$GLOBALS['filter']); |
|
| 40 | 40 | $GLOBALS['xoopsTpl']->assign('pagenav', $pagenav->renderNav()); |
| 41 | 41 | |
| 42 | 42 | foreach ($requestsHandler->filterFields() as $id => $key) { |
| 43 | 43 | $GLOBALS['xoopsTpl']->assign( |
| 44 | - \mb_strtolower(str_replace('-', '_', $key) . '_th'), |
|
| 44 | + \mb_strtolower(str_replace('-', '_', $key).'_th'), |
|
| 45 | 45 | '<a href="' |
| 46 | 46 | . $_SERVER['SCRIPT_NAME'] |
| 47 | 47 | . '?start=' |
@@ -51,16 +51,16 @@ discard block |
||
| 51 | 51 | . '&sort=' |
| 52 | 52 | . $key |
| 53 | 53 | . '&order=' |
| 54 | - . (($key == $GLOBALS['sort']) ? ('DESC' === $GLOBALS['order'] ? 'ASC' : 'DESC') : $GLOBALS['order']) |
|
| 54 | + . (($key==$GLOBALS['sort']) ? ('DESC'===$GLOBALS['order'] ? 'ASC' : 'DESC') : $GLOBALS['order']) |
|
| 55 | 55 | . '&op=' |
| 56 | 56 | . $GLOBALS['op'] |
| 57 | 57 | . '&filter=' |
| 58 | 58 | . $GLOBALS['filter'] |
| 59 | 59 | . '">' |
| 60 | - . (defined('_AM_SONGLIST_TH_' . \mb_strtoupper(str_replace('-', '_', $key))) ? constant('_AM_SONGLIST_TH_' . \mb_strtoupper(str_replace('-', '_', $key))) : '_AM_SONGLIST_TH_' . \mb_strtoupper(str_replace('-', '_', $key))) |
|
| 60 | + . (defined('_AM_SONGLIST_TH_'.\mb_strtoupper(str_replace('-', '_', $key))) ? constant('_AM_SONGLIST_TH_'.\mb_strtoupper(str_replace('-', '_', $key))) : '_AM_SONGLIST_TH_'.\mb_strtoupper(str_replace('-', '_', $key))) |
|
| 61 | 61 | . '</a>' |
| 62 | 62 | ); |
| 63 | - $GLOBALS['xoopsTpl']->assign('filter_' . \mb_strtolower(str_replace('-', '_', $key)) . '_th', $requestsHandler->getFilterForm($GLOBALS['filter'], $key, $GLOBALS['sort'], $GLOBALS['op'], $GLOBALS['fct'])); |
|
| 63 | + $GLOBALS['xoopsTpl']->assign('filter_'.\mb_strtolower(str_replace('-', '_', $key)).'_th', $requestsHandler->getFilterForm($GLOBALS['filter'], $key, $GLOBALS['sort'], $GLOBALS['op'], $GLOBALS['fct'])); |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | $GLOBALS['xoopsTpl']->assign('limit', $GLOBALS['limit']); |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | |
| 73 | 73 | $criteria->setStart($GLOBALS['start']); |
| 74 | 74 | $criteria->setLimit($GLOBALS['limit']); |
| 75 | - $criteria->setSort('`' . $GLOBALS['sort'] . '`'); |
|
| 75 | + $criteria->setSort('`'.$GLOBALS['sort'].'`'); |
|
| 76 | 76 | $criteria->setOrder($GLOBALS['order']); |
| 77 | 77 | |
| 78 | 78 | $requestss = $requestsHandler->getObjects($criteria, true); |
@@ -113,17 +113,17 @@ discard block |
||
| 113 | 113 | $requests->setVars($_POST[$id]); |
| 114 | 114 | |
| 115 | 115 | if (!$id = $requestsHandler->insert($requests)) { |
| 116 | - redirect_header($_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], 10, _AM_SONGLIST_MSG_REQUESTS_FAILEDTOSAVE); |
|
| 116 | + redirect_header($_SERVER['SCRIPT_NAME'].'?op='.$GLOBALS['op'].'&fct=list&limit='.$GLOBALS['limit'].'&start='.$GLOBALS['start'].'&order='.$GLOBALS['order'].'&sort='.$GLOBALS['sort'].'&filter='.$GLOBALS['filter'], 10, _AM_SONGLIST_MSG_REQUESTS_FAILEDTOSAVE); |
|
| 117 | 117 | exit(0); |
| 118 | 118 | } |
| 119 | - if ('new' === $_REQUEST['state'][$_REQUEST['id']]) { |
|
| 119 | + if ('new'===$_REQUEST['state'][$_REQUEST['id']]) { |
|
| 120 | 120 | redirect_header( |
| 121 | - $_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=edit&id=' . $_REQUEST['id'] . '&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], |
|
| 121 | + $_SERVER['SCRIPT_NAME'].'?op='.$GLOBALS['op'].'&fct=edit&id='.$_REQUEST['id'].'&limit='.$GLOBALS['limit'].'&start='.$GLOBALS['start'].'&order='.$GLOBALS['order'].'&sort='.$GLOBALS['sort'].'&filter='.$GLOBALS['filter'], |
|
| 122 | 122 | 10, |
| 123 | 123 | _AM_SONGLIST_MSG_REQUESTS_SAVEDOKEY |
| 124 | 124 | ); |
| 125 | 125 | } else { |
| 126 | - redirect_header($_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], 10, _AM_SONGLIST_MSG_REQUESTS_SAVEDOKEY); |
|
| 126 | + redirect_header($_SERVER['SCRIPT_NAME'].'?op='.$GLOBALS['op'].'&fct=list&limit='.$GLOBALS['limit'].'&start='.$GLOBALS['start'].'&order='.$GLOBALS['order'].'&sort='.$GLOBALS['sort'].'&filter='.$GLOBALS['filter'], 10, _AM_SONGLIST_MSG_REQUESTS_SAVEDOKEY); |
|
| 127 | 127 | } |
| 128 | 128 | exit(0); |
| 129 | 129 | |
@@ -135,14 +135,14 @@ discard block |
||
| 135 | 135 | $requests->setVars($_POST[$id]); |
| 136 | 136 | if (!$requestsHandler->insert($requests)) { |
| 137 | 137 | redirect_header( |
| 138 | - $_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], |
|
| 138 | + $_SERVER['SCRIPT_NAME'].'?op='.$GLOBALS['op'].'&fct=list&limit='.$GLOBALS['limit'].'&start='.$GLOBALS['start'].'&order='.$GLOBALS['order'].'&sort='.$GLOBALS['sort'].'&filter='.$GLOBALS['filter'], |
|
| 139 | 139 | 10, |
| 140 | 140 | _AM_SONGLIST_MSG_REQUESTS_FAILEDTOSAVE |
| 141 | 141 | ); |
| 142 | 142 | exit(0); |
| 143 | 143 | } |
| 144 | 144 | } |
| 145 | - redirect_header($_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], 10, _AM_SONGLIST_MSG_REQUESTS_SAVEDOKEY); |
|
| 145 | + redirect_header($_SERVER['SCRIPT_NAME'].'?op='.$GLOBALS['op'].'&fct=list&limit='.$GLOBALS['limit'].'&start='.$GLOBALS['start'].'&order='.$GLOBALS['order'].'&sort='.$GLOBALS['sort'].'&filter='.$GLOBALS['filter'], 10, _AM_SONGLIST_MSG_REQUESTS_SAVEDOKEY); |
|
| 146 | 146 | exit(0); |
| 147 | 147 | break; |
| 148 | 148 | case 'delete': |
@@ -152,13 +152,13 @@ discard block |
||
| 152 | 152 | $requests = $requestsHandler->get($id); |
| 153 | 153 | if (!$requestsHandler->delete($requests)) { |
| 154 | 154 | redirect_header( |
| 155 | - $_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], |
|
| 155 | + $_SERVER['SCRIPT_NAME'].'?op='.$GLOBALS['op'].'&fct=list&limit='.$GLOBALS['limit'].'&start='.$GLOBALS['start'].'&order='.$GLOBALS['order'].'&sort='.$GLOBALS['sort'].'&filter='.$GLOBALS['filter'], |
|
| 156 | 156 | 10, |
| 157 | 157 | _AM_SONGLIST_MSG_REQUESTS_FAILEDTODELETE |
| 158 | 158 | ); |
| 159 | 159 | exit(0); |
| 160 | 160 | } |
| 161 | - redirect_header($_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], 10, _AM_SONGLIST_MSG_REQUESTS_DELETED); |
|
| 161 | + redirect_header($_SERVER['SCRIPT_NAME'].'?op='.$GLOBALS['op'].'&fct=list&limit='.$GLOBALS['limit'].'&start='.$GLOBALS['start'].'&order='.$GLOBALS['order'].'&sort='.$GLOBALS['sort'].'&filter='.$GLOBALS['filter'], 10, _AM_SONGLIST_MSG_REQUESTS_DELETED); |
|
| 162 | 162 | exit(0); |
| 163 | 163 | } |
| 164 | 164 | $requests = $requestsHandler->get(Request::getInt('id', 0, 'REQUEST')); |
@@ -1,4 +1,4 @@ |
||
| 1 | 1 | <?php declare(strict_types=1); |
| 2 | 2 | |
| 3 | -require_once __DIR__ . '/header.php'; |
|
| 4 | -require_once XOOPS_ROOT_PATH . '/modules/tag/list.tag.php'; |
|
| 3 | +require_once __DIR__.'/header.php'; |
|
| 4 | +require_once XOOPS_ROOT_PATH.'/modules/tag/list.tag.php'; |
|
@@ -29,19 +29,19 @@ discard block |
||
| 29 | 29 | */ |
| 30 | 30 | function xoops_module_pre_install_songlist(\XoopsModule $module): bool |
| 31 | 31 | { |
| 32 | - require_once \dirname(__DIR__) . '/preloads/autoloader.php'; |
|
| 33 | - $utility = new Utility(); |
|
| 34 | - $xoopsSuccess = $utility::checkVerXoops($module); |
|
| 35 | - $phpSuccess = $utility::checkVerPhp($module); |
|
| 32 | + require_once \dirname(__DIR__) . '/preloads/autoloader.php'; |
|
| 33 | + $utility = new Utility(); |
|
| 34 | + $xoopsSuccess = $utility::checkVerXoops($module); |
|
| 35 | + $phpSuccess = $utility::checkVerPhp($module); |
|
| 36 | 36 | |
| 37 | - if ($xoopsSuccess && $phpSuccess) { |
|
| 38 | - $moduleTables = &$module->getInfo('tables'); |
|
| 39 | - foreach ($moduleTables as $table) { |
|
| 40 | - $GLOBALS['xoopsDB']->queryF('DROP TABLE IF EXISTS ' . $GLOBALS['xoopsDB']->prefix($table) . ';'); |
|
| 41 | - } |
|
| 42 | - } |
|
| 37 | + if ($xoopsSuccess && $phpSuccess) { |
|
| 38 | + $moduleTables = &$module->getInfo('tables'); |
|
| 39 | + foreach ($moduleTables as $table) { |
|
| 40 | + $GLOBALS['xoopsDB']->queryF('DROP TABLE IF EXISTS ' . $GLOBALS['xoopsDB']->prefix($table) . ';'); |
|
| 41 | + } |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - return $xoopsSuccess && $phpSuccess; |
|
| 44 | + return $xoopsSuccess && $phpSuccess; |
|
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | /** |
@@ -52,48 +52,48 @@ discard block |
||
| 52 | 52 | */ |
| 53 | 53 | function xoops_module_install_songlist(\XoopsModule $module): bool |
| 54 | 54 | { |
| 55 | - require \dirname(__DIR__, 3) . '/mainfile.php'; |
|
| 55 | + require \dirname(__DIR__, 3) . '/mainfile.php'; |
|
| 56 | 56 | |
| 57 | - $moduleDirName = \basename(\dirname(__DIR__)); |
|
| 58 | - $helper = Helper::getInstance(); |
|
| 59 | - $utility = new Utility(); |
|
| 60 | - $configurator = new Songlist\Common\Configurator(); |
|
| 61 | - // Load language files |
|
| 62 | - $helper->loadLanguage('admin'); |
|
| 63 | - $helper->loadLanguage('modinfo'); |
|
| 57 | + $moduleDirName = \basename(\dirname(__DIR__)); |
|
| 58 | + $helper = Helper::getInstance(); |
|
| 59 | + $utility = new Utility(); |
|
| 60 | + $configurator = new Songlist\Common\Configurator(); |
|
| 61 | + // Load language files |
|
| 62 | + $helper->loadLanguage('admin'); |
|
| 63 | + $helper->loadLanguage('modinfo'); |
|
| 64 | 64 | |
| 65 | - // default Permission Settings ---------------------- |
|
| 66 | - global $xoopsModule; |
|
| 67 | - $moduleId = $xoopsModule->getVar('mid'); |
|
| 68 | - // $moduleId2 = \XoopsModules\Songlist\Helper::getInstance()->getModule()->mid(); |
|
| 69 | - /** @var \XoopsGroupPermHandler $grouppermHandler */ |
|
| 70 | - $grouppermHandler = xoops_getHandler('groupperm'); |
|
| 71 | - // access rights ------------------------------------------ |
|
| 72 | - $grouppermHandler->addRight($moduleDirName . '_approve', 1, XOOPS_GROUP_ADMIN, $moduleId); |
|
| 73 | - $grouppermHandler->addRight($moduleDirName . '_submit', 1, XOOPS_GROUP_ADMIN, $moduleId); |
|
| 74 | - $grouppermHandler->addRight($moduleDirName . '_view', 1, XOOPS_GROUP_ADMIN, $moduleId); |
|
| 75 | - $grouppermHandler->addRight($moduleDirName . '_view', 1, XOOPS_GROUP_USERS, $moduleId); |
|
| 76 | - $grouppermHandler->addRight($moduleDirName . '_view', 1, XOOPS_GROUP_ANONYMOUS, $moduleId); |
|
| 65 | + // default Permission Settings ---------------------- |
|
| 66 | + global $xoopsModule; |
|
| 67 | + $moduleId = $xoopsModule->getVar('mid'); |
|
| 68 | + // $moduleId2 = \XoopsModules\Songlist\Helper::getInstance()->getModule()->mid(); |
|
| 69 | + /** @var \XoopsGroupPermHandler $grouppermHandler */ |
|
| 70 | + $grouppermHandler = xoops_getHandler('groupperm'); |
|
| 71 | + // access rights ------------------------------------------ |
|
| 72 | + $grouppermHandler->addRight($moduleDirName . '_approve', 1, XOOPS_GROUP_ADMIN, $moduleId); |
|
| 73 | + $grouppermHandler->addRight($moduleDirName . '_submit', 1, XOOPS_GROUP_ADMIN, $moduleId); |
|
| 74 | + $grouppermHandler->addRight($moduleDirName . '_view', 1, XOOPS_GROUP_ADMIN, $moduleId); |
|
| 75 | + $grouppermHandler->addRight($moduleDirName . '_view', 1, XOOPS_GROUP_USERS, $moduleId); |
|
| 76 | + $grouppermHandler->addRight($moduleDirName . '_view', 1, XOOPS_GROUP_ANONYMOUS, $moduleId); |
|
| 77 | 77 | |
| 78 | - // --- CREATE FOLDERS --------------- |
|
| 79 | - if (count($configurator->uploadFolders) > 0) { |
|
| 80 | - // foreach (array_keys($GLOBALS['uploadFolders']) as $i) { |
|
| 81 | - foreach (array_keys($configurator->uploadFolders) as $i) { |
|
| 82 | - $utility::createFolder($configurator->uploadFolders[$i]); |
|
| 83 | - } |
|
| 84 | - } |
|
| 78 | + // --- CREATE FOLDERS --------------- |
|
| 79 | + if (count($configurator->uploadFolders) > 0) { |
|
| 80 | + // foreach (array_keys($GLOBALS['uploadFolders']) as $i) { |
|
| 81 | + foreach (array_keys($configurator->uploadFolders) as $i) { |
|
| 82 | + $utility::createFolder($configurator->uploadFolders[$i]); |
|
| 83 | + } |
|
| 84 | + } |
|
| 85 | 85 | |
| 86 | - // --- COPY blank.png FILES --------------- |
|
| 87 | - if (count($configurator->copyBlankFiles) > 0) { |
|
| 88 | - $file = \dirname(__DIR__) . '/assets/images/blank.png'; |
|
| 89 | - foreach (array_keys($configurator->copyBlankFiles) as $i) { |
|
| 90 | - $dest = $configurator->copyBlankFiles[$i] . '/blank.png'; |
|
| 91 | - $utility::copyFile($file, $dest); |
|
| 92 | - } |
|
| 93 | - } |
|
| 94 | - //delete .html entries from the tpl table |
|
| 95 | - $sql = 'DELETE FROM ' . $GLOBALS['xoopsDB']->prefix('tplfile') . " WHERE `tpl_module` = '" . $xoopsModule->getVar('dirname', 'n') . "' AND `tpl_file` LIKE '%.tpl%'"; |
|
| 96 | - $GLOBALS['xoopsDB']->queryF($sql); |
|
| 86 | + // --- COPY blank.png FILES --------------- |
|
| 87 | + if (count($configurator->copyBlankFiles) > 0) { |
|
| 88 | + $file = \dirname(__DIR__) . '/assets/images/blank.png'; |
|
| 89 | + foreach (array_keys($configurator->copyBlankFiles) as $i) { |
|
| 90 | + $dest = $configurator->copyBlankFiles[$i] . '/blank.png'; |
|
| 91 | + $utility::copyFile($file, $dest); |
|
| 92 | + } |
|
| 93 | + } |
|
| 94 | + //delete .html entries from the tpl table |
|
| 95 | + $sql = 'DELETE FROM ' . $GLOBALS['xoopsDB']->prefix('tplfile') . " WHERE `tpl_module` = '" . $xoopsModule->getVar('dirname', 'n') . "' AND `tpl_file` LIKE '%.tpl%'"; |
|
| 96 | + $GLOBALS['xoopsDB']->queryF($sql); |
|
| 97 | 97 | |
| 98 | - return true; |
|
| 98 | + return true; |
|
| 99 | 99 | } |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | */ |
| 30 | 30 | function xoops_module_pre_install_songlist(\XoopsModule $module): bool |
| 31 | 31 | { |
| 32 | - require_once \dirname(__DIR__) . '/preloads/autoloader.php'; |
|
| 32 | + require_once \dirname(__DIR__).'/preloads/autoloader.php'; |
|
| 33 | 33 | $utility = new Utility(); |
| 34 | 34 | $xoopsSuccess = $utility::checkVerXoops($module); |
| 35 | 35 | $phpSuccess = $utility::checkVerPhp($module); |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | if ($xoopsSuccess && $phpSuccess) { |
| 38 | 38 | $moduleTables = &$module->getInfo('tables'); |
| 39 | 39 | foreach ($moduleTables as $table) { |
| 40 | - $GLOBALS['xoopsDB']->queryF('DROP TABLE IF EXISTS ' . $GLOBALS['xoopsDB']->prefix($table) . ';'); |
|
| 40 | + $GLOBALS['xoopsDB']->queryF('DROP TABLE IF EXISTS '.$GLOBALS['xoopsDB']->prefix($table).';'); |
|
| 41 | 41 | } |
| 42 | 42 | } |
| 43 | 43 | |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | */ |
| 53 | 53 | function xoops_module_install_songlist(\XoopsModule $module): bool |
| 54 | 54 | { |
| 55 | - require \dirname(__DIR__, 3) . '/mainfile.php'; |
|
| 55 | + require \dirname(__DIR__, 3).'/mainfile.php'; |
|
| 56 | 56 | |
| 57 | 57 | $moduleDirName = \basename(\dirname(__DIR__)); |
| 58 | 58 | $helper = Helper::getInstance(); |
@@ -69,14 +69,14 @@ discard block |
||
| 69 | 69 | /** @var \XoopsGroupPermHandler $grouppermHandler */ |
| 70 | 70 | $grouppermHandler = xoops_getHandler('groupperm'); |
| 71 | 71 | // access rights ------------------------------------------ |
| 72 | - $grouppermHandler->addRight($moduleDirName . '_approve', 1, XOOPS_GROUP_ADMIN, $moduleId); |
|
| 73 | - $grouppermHandler->addRight($moduleDirName . '_submit', 1, XOOPS_GROUP_ADMIN, $moduleId); |
|
| 74 | - $grouppermHandler->addRight($moduleDirName . '_view', 1, XOOPS_GROUP_ADMIN, $moduleId); |
|
| 75 | - $grouppermHandler->addRight($moduleDirName . '_view', 1, XOOPS_GROUP_USERS, $moduleId); |
|
| 76 | - $grouppermHandler->addRight($moduleDirName . '_view', 1, XOOPS_GROUP_ANONYMOUS, $moduleId); |
|
| 72 | + $grouppermHandler->addRight($moduleDirName.'_approve', 1, XOOPS_GROUP_ADMIN, $moduleId); |
|
| 73 | + $grouppermHandler->addRight($moduleDirName.'_submit', 1, XOOPS_GROUP_ADMIN, $moduleId); |
|
| 74 | + $grouppermHandler->addRight($moduleDirName.'_view', 1, XOOPS_GROUP_ADMIN, $moduleId); |
|
| 75 | + $grouppermHandler->addRight($moduleDirName.'_view', 1, XOOPS_GROUP_USERS, $moduleId); |
|
| 76 | + $grouppermHandler->addRight($moduleDirName.'_view', 1, XOOPS_GROUP_ANONYMOUS, $moduleId); |
|
| 77 | 77 | |
| 78 | 78 | // --- CREATE FOLDERS --------------- |
| 79 | - if (count($configurator->uploadFolders) > 0) { |
|
| 79 | + if (count($configurator->uploadFolders)>0) { |
|
| 80 | 80 | // foreach (array_keys($GLOBALS['uploadFolders']) as $i) { |
| 81 | 81 | foreach (array_keys($configurator->uploadFolders) as $i) { |
| 82 | 82 | $utility::createFolder($configurator->uploadFolders[$i]); |
@@ -84,15 +84,15 @@ discard block |
||
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | // --- COPY blank.png FILES --------------- |
| 87 | - if (count($configurator->copyBlankFiles) > 0) { |
|
| 88 | - $file = \dirname(__DIR__) . '/assets/images/blank.png'; |
|
| 87 | + if (count($configurator->copyBlankFiles)>0) { |
|
| 88 | + $file = \dirname(__DIR__).'/assets/images/blank.png'; |
|
| 89 | 89 | foreach (array_keys($configurator->copyBlankFiles) as $i) { |
| 90 | - $dest = $configurator->copyBlankFiles[$i] . '/blank.png'; |
|
| 90 | + $dest = $configurator->copyBlankFiles[$i].'/blank.png'; |
|
| 91 | 91 | $utility::copyFile($file, $dest); |
| 92 | 92 | } |
| 93 | 93 | } |
| 94 | 94 | //delete .html entries from the tpl table |
| 95 | - $sql = 'DELETE FROM ' . $GLOBALS['xoopsDB']->prefix('tplfile') . " WHERE `tpl_module` = '" . $xoopsModule->getVar('dirname', 'n') . "' AND `tpl_file` LIKE '%.tpl%'"; |
|
| 95 | + $sql = 'DELETE FROM '.$GLOBALS['xoopsDB']->prefix('tplfile')." WHERE `tpl_module` = '".$xoopsModule->getVar('dirname', 'n')."' AND `tpl_file` LIKE '%.tpl%'"; |
|
| 96 | 96 | $GLOBALS['xoopsDB']->queryF($sql); |
| 97 | 97 | |
| 98 | 98 | return true; |
@@ -5,12 +5,12 @@ |
||
| 5 | 5 | /** @var \XoopsConfigHandler $configHandler */ |
| 6 | 6 | $configHandler = xoops_getHandler('config'); |
| 7 | 7 | if (!isset($GLOBALS['songlistModule'])) { |
| 8 | - $GLOBALS['songlistModule'] = $moduleHandler->getByDirname('songlist'); |
|
| 8 | + $GLOBALS['songlistModule'] = $moduleHandler->getByDirname('songlist'); |
|
| 9 | 9 | } |
| 10 | 10 | if (is_object($GLOBALS['songlistModule'])) { |
| 11 | - if (!isset($GLOBALS['songlistModuleConfig'])) { |
|
| 12 | - $GLOBALS['songlistModuleConfig'] = $configHandler->getConfigList($GLOBALS['songlistModule']->getVar('mid')); |
|
| 13 | - } |
|
| 11 | + if (!isset($GLOBALS['songlistModuleConfig'])) { |
|
| 12 | + $GLOBALS['songlistModuleConfig'] = $configHandler->getConfigList($GLOBALS['songlistModule']->getVar('mid')); |
|
| 13 | + } |
|
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | require_once $GLOBALS['xoops']->path('class/xoopsformloader.php'); |
@@ -9,611 +9,611 @@ |
||
| 9 | 9 | use XoopsModules\Songlist\Form\SelectVoiceForm; |
| 10 | 10 | |
| 11 | 11 | if (!function_exists('songlist_getToken')) { |
| 12 | - /** |
|
| 13 | - * @return mixed |
|
| 14 | - */ |
|
| 15 | - function songlist_getToken() |
|
| 16 | - { |
|
| 17 | - $sql = 'SELECT md5(rand()/rand()*rand()/rand()*rand()*rand()/rand()*rand()) as `salt`'; |
|
| 18 | - $result = $GLOBALS['xoopsDB']->queryF($sql); |
|
| 19 | - [$salt] = $GLOBALS['xoopsDB']->fetchRow($result); |
|
| 20 | - |
|
| 21 | - return $salt; |
|
| 22 | - } |
|
| 12 | + /** |
|
| 13 | + * @return mixed |
|
| 14 | + */ |
|
| 15 | + function songlist_getToken() |
|
| 16 | + { |
|
| 17 | + $sql = 'SELECT md5(rand()/rand()*rand()/rand()*rand()*rand()/rand()*rand()) as `salt`'; |
|
| 18 | + $result = $GLOBALS['xoopsDB']->queryF($sql); |
|
| 19 | + [$salt] = $GLOBALS['xoopsDB']->fetchRow($result); |
|
| 20 | + |
|
| 21 | + return $salt; |
|
| 22 | + } |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | if (!function_exists('ucword')) { |
| 26 | - /** |
|
| 27 | - * @param $string |
|
| 28 | - * @return string |
|
| 29 | - */ |
|
| 30 | - function ucword($string): string |
|
| 31 | - { |
|
| 32 | - $ret = []; |
|
| 33 | - foreach (explode(' ', \mb_strtolower($string)) as $part) { |
|
| 34 | - $ret[] = ucfirst($part); |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - return implode(' ', $ret); |
|
| 38 | - } |
|
| 26 | + /** |
|
| 27 | + * @param $string |
|
| 28 | + * @return string |
|
| 29 | + */ |
|
| 30 | + function ucword($string): string |
|
| 31 | + { |
|
| 32 | + $ret = []; |
|
| 33 | + foreach (explode(' ', \mb_strtolower($string)) as $part) { |
|
| 34 | + $ret[] = ucfirst($part); |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + return implode(' ', $ret); |
|
| 38 | + } |
|
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | if (!function_exists('songlist_getIPData')) { |
| 42 | - /** |
|
| 43 | - * @param bool|string $ip |
|
| 44 | - * @return array |
|
| 45 | - */ |
|
| 46 | - function songlist_getIPData($ip = false): array |
|
| 47 | - { |
|
| 48 | - $ret = []; |
|
| 49 | - if (is_object($GLOBALS['xoopsUser'])) { |
|
| 50 | - $ret['uid'] = $GLOBALS['xoopsUser']->getVar('uid'); |
|
| 51 | - $ret['uname'] = $GLOBALS['xoopsUser']->getVar('uname'); |
|
| 52 | - $ret['email'] = $GLOBALS['xoopsUser']->getVar('email'); |
|
| 53 | - } else { |
|
| 54 | - $ret['uid'] = 0; |
|
| 55 | - $ret['uname'] = ($_REQUEST['uname'] ?? ''); |
|
| 56 | - $ret['email'] = ($_REQUEST['email'] ?? ''); |
|
| 57 | - } |
|
| 58 | - $ret['agent'] = $_SERVER['HTTP_USER_AGENT']; |
|
| 59 | - if ($ip) { |
|
| 60 | - $ret['is_proxied'] = false; |
|
| 61 | - $ret['network-addy'] = @gethostbyaddr($ip); |
|
| 62 | - $ret['long'] = @ip2long($ip); |
|
| 63 | - if (is_ipv6($ip)) { |
|
| 64 | - $ret['ip6'] = true; |
|
| 65 | - $ret['ip4'] = false; |
|
| 66 | - } else { |
|
| 67 | - $ret['ip4'] = true; |
|
| 68 | - $ret['ip6'] = false; |
|
| 69 | - } |
|
| 70 | - $ret['ip'] = $ip; |
|
| 71 | - } elseif (Request::hasVar('HTTP_X_FORWARDED_FOR', 'SERVER')) { |
|
| 72 | - $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; |
|
| 73 | - $ret['is_proxied'] = true; |
|
| 74 | - $proxy_ip = $_SERVER['REMOTE_ADDR']; |
|
| 75 | - $ret['network-addy'] = @gethostbyaddr($ip); |
|
| 76 | - $ret['long'] = @ip2long($ip); |
|
| 77 | - if (is_ipv6($ip)) { |
|
| 78 | - $ret['ip6'] = true; |
|
| 79 | - $ret['proxy-ip6'] = true; |
|
| 80 | - $ret['ip4'] = false; |
|
| 81 | - $ret['proxy-ip4'] = false; |
|
| 82 | - } else { |
|
| 83 | - $ret['ip4'] = true; |
|
| 84 | - $ret['proxy-ip4'] = true; |
|
| 85 | - $ret['ip6'] = false; |
|
| 86 | - $ret['proxy-ip6'] = false; |
|
| 87 | - } |
|
| 88 | - $ret['ip'] = $ip; |
|
| 89 | - $ret['proxy-ip'] = $proxy_ip; |
|
| 90 | - } else { |
|
| 91 | - $ret['is_proxied'] = false; |
|
| 92 | - $ip = $_SERVER['REMOTE_ADDR']; |
|
| 93 | - $ret['network-addy'] = @gethostbyaddr($ip); |
|
| 94 | - $ret['long'] = @ip2long($ip); |
|
| 95 | - if (is_ipv6($ip)) { |
|
| 96 | - $ret['ip6'] = true; |
|
| 97 | - $ret['ip4'] = false; |
|
| 98 | - } else { |
|
| 99 | - $ret['ip4'] = true; |
|
| 100 | - $ret['ip6'] = false; |
|
| 101 | - } |
|
| 102 | - $ret['ip'] = $ip; |
|
| 103 | - } |
|
| 104 | - $ret['made'] = time(); |
|
| 105 | - |
|
| 106 | - return $ret; |
|
| 107 | - } |
|
| 42 | + /** |
|
| 43 | + * @param bool|string $ip |
|
| 44 | + * @return array |
|
| 45 | + */ |
|
| 46 | + function songlist_getIPData($ip = false): array |
|
| 47 | + { |
|
| 48 | + $ret = []; |
|
| 49 | + if (is_object($GLOBALS['xoopsUser'])) { |
|
| 50 | + $ret['uid'] = $GLOBALS['xoopsUser']->getVar('uid'); |
|
| 51 | + $ret['uname'] = $GLOBALS['xoopsUser']->getVar('uname'); |
|
| 52 | + $ret['email'] = $GLOBALS['xoopsUser']->getVar('email'); |
|
| 53 | + } else { |
|
| 54 | + $ret['uid'] = 0; |
|
| 55 | + $ret['uname'] = ($_REQUEST['uname'] ?? ''); |
|
| 56 | + $ret['email'] = ($_REQUEST['email'] ?? ''); |
|
| 57 | + } |
|
| 58 | + $ret['agent'] = $_SERVER['HTTP_USER_AGENT']; |
|
| 59 | + if ($ip) { |
|
| 60 | + $ret['is_proxied'] = false; |
|
| 61 | + $ret['network-addy'] = @gethostbyaddr($ip); |
|
| 62 | + $ret['long'] = @ip2long($ip); |
|
| 63 | + if (is_ipv6($ip)) { |
|
| 64 | + $ret['ip6'] = true; |
|
| 65 | + $ret['ip4'] = false; |
|
| 66 | + } else { |
|
| 67 | + $ret['ip4'] = true; |
|
| 68 | + $ret['ip6'] = false; |
|
| 69 | + } |
|
| 70 | + $ret['ip'] = $ip; |
|
| 71 | + } elseif (Request::hasVar('HTTP_X_FORWARDED_FOR', 'SERVER')) { |
|
| 72 | + $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; |
|
| 73 | + $ret['is_proxied'] = true; |
|
| 74 | + $proxy_ip = $_SERVER['REMOTE_ADDR']; |
|
| 75 | + $ret['network-addy'] = @gethostbyaddr($ip); |
|
| 76 | + $ret['long'] = @ip2long($ip); |
|
| 77 | + if (is_ipv6($ip)) { |
|
| 78 | + $ret['ip6'] = true; |
|
| 79 | + $ret['proxy-ip6'] = true; |
|
| 80 | + $ret['ip4'] = false; |
|
| 81 | + $ret['proxy-ip4'] = false; |
|
| 82 | + } else { |
|
| 83 | + $ret['ip4'] = true; |
|
| 84 | + $ret['proxy-ip4'] = true; |
|
| 85 | + $ret['ip6'] = false; |
|
| 86 | + $ret['proxy-ip6'] = false; |
|
| 87 | + } |
|
| 88 | + $ret['ip'] = $ip; |
|
| 89 | + $ret['proxy-ip'] = $proxy_ip; |
|
| 90 | + } else { |
|
| 91 | + $ret['is_proxied'] = false; |
|
| 92 | + $ip = $_SERVER['REMOTE_ADDR']; |
|
| 93 | + $ret['network-addy'] = @gethostbyaddr($ip); |
|
| 94 | + $ret['long'] = @ip2long($ip); |
|
| 95 | + if (is_ipv6($ip)) { |
|
| 96 | + $ret['ip6'] = true; |
|
| 97 | + $ret['ip4'] = false; |
|
| 98 | + } else { |
|
| 99 | + $ret['ip4'] = true; |
|
| 100 | + $ret['ip6'] = false; |
|
| 101 | + } |
|
| 102 | + $ret['ip'] = $ip; |
|
| 103 | + } |
|
| 104 | + $ret['made'] = time(); |
|
| 105 | + |
|
| 106 | + return $ret; |
|
| 107 | + } |
|
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | if (!function_exists('is_ipv6')) { |
| 111 | - /** |
|
| 112 | - * @param string $ip |
|
| 113 | - * @return bool |
|
| 114 | - */ |
|
| 115 | - function is_ipv6($ip = ''): bool |
|
| 116 | - { |
|
| 117 | - if ('' == $ip) { |
|
| 118 | - return false; |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - if (mb_substr_count($ip, ':') > 0) { |
|
| 122 | - return true; |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - return false; |
|
| 126 | - } |
|
| 111 | + /** |
|
| 112 | + * @param string $ip |
|
| 113 | + * @return bool |
|
| 114 | + */ |
|
| 115 | + function is_ipv6($ip = ''): bool |
|
| 116 | + { |
|
| 117 | + if ('' == $ip) { |
|
| 118 | + return false; |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + if (mb_substr_count($ip, ':') > 0) { |
|
| 122 | + return true; |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + return false; |
|
| 126 | + } |
|
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | if (!function_exists('songlist_getFilterElement')) { |
| 130 | - /** |
|
| 131 | - * @param $filter |
|
| 132 | - * @param $field |
|
| 133 | - * @param string $sort |
|
| 134 | - * @param string $op |
|
| 135 | - * @param string $fct |
|
| 136 | - * @return bool|\XoopsModules\Songlist\Form\SelectAlbumForm|\XoopsModules\Songlist\Form\SelectArtistForm|\XoopsModules\Songlist\Form\SelectCategoryForm|\XoopsModules\Songlist\Form\SelectGenreForm|\XoopsModules\Songlist\Form\SelectVoiceForm |
|
| 137 | - */ |
|
| 138 | - function songlist_getFilterElement($filter, $field, $sort = 'created', $op = '', $fct = '') |
|
| 139 | - { |
|
| 140 | - $components = songlist_getFilterURLComponents($filter, $field, $sort); |
|
| 141 | - $ele = false; |
|
| 142 | - require_once __DIR__ . '/songlist.object.php'; |
|
| 143 | - switch ($field) { |
|
| 144 | - case 'gid': |
|
| 145 | - if ('genre' !== $op) { |
|
| 146 | - $ele = new SelectGenreForm('', 'filter_' . $field . '', $components['value'], 1, false); |
|
| 147 | - $ele->setExtra( |
|
| 148 | - 'onchange="window.open(\'' |
|
| 149 | - . $_SERVER['SCRIPT_NAME'] |
|
| 150 | - . '?' |
|
| 151 | - . $components['extra'] |
|
| 152 | - . '&filter=' |
|
| 153 | - . $components['filter'] |
|
| 154 | - . (!empty($components['filter']) ? '|' : '') |
|
| 155 | - . $field |
|
| 156 | - . ',\'+this.options[this.selectedIndex].value' |
|
| 157 | - . (!empty($components['operator']) ? '+\',' |
|
| 158 | - . $components['operator'] |
|
| 159 | - . '\'' : '') |
|
| 160 | - . ',\'_self\')"' |
|
| 161 | - ); |
|
| 162 | - } |
|
| 163 | - break; |
|
| 164 | - case 'vcid': |
|
| 165 | - if ('voice' !== $op) { |
|
| 166 | - $ele = new SelectVoiceForm('', 'filter_' . $field . '', $components['value'], 1, false); |
|
| 167 | - $ele->setExtra( |
|
| 168 | - 'onchange="window.open(\'' |
|
| 169 | - . $_SERVER['SCRIPT_NAME'] |
|
| 170 | - . '?' |
|
| 171 | - . $components['extra'] |
|
| 172 | - . '&filter=' |
|
| 173 | - . $components['filter'] |
|
| 174 | - . (!empty($components['filter']) ? '|' : '') |
|
| 175 | - . $field |
|
| 176 | - . ',\'+this.options[this.selectedIndex].value' |
|
| 177 | - . (!empty($components['operator']) ? '+\',' |
|
| 178 | - . $components['operator'] |
|
| 179 | - . '\'' : '') |
|
| 180 | - . ',\'_self\')"' |
|
| 181 | - ); |
|
| 182 | - } |
|
| 183 | - break; |
|
| 184 | - case 'cid': |
|
| 185 | - if ('category' !== $op) { |
|
| 186 | - $ele = new SelectCategoryForm('', 'filter_' . $field . '', $components['value'], 1, false); |
|
| 187 | - $ele->setExtra( |
|
| 188 | - 'onchange="window.open(\'' |
|
| 189 | - . $_SERVER['SCRIPT_NAME'] |
|
| 190 | - . '?' |
|
| 191 | - . $components['extra'] |
|
| 192 | - . '&filter=' |
|
| 193 | - . $components['filter'] |
|
| 194 | - . (!empty($components['filter']) ? '|' : '') |
|
| 195 | - . $field |
|
| 196 | - . ',\'+this.options[this.selectedIndex].value' |
|
| 197 | - . (!empty($components['operator']) ? '+\',' |
|
| 198 | - . $components['operator'] |
|
| 199 | - . '\'' : '') |
|
| 200 | - . ',\'_self\')"' |
|
| 201 | - ); |
|
| 202 | - } |
|
| 203 | - break; |
|
| 204 | - case 'pid': |
|
| 205 | - $ele = new SelectCategoryForm('', 'filter_' . $field . '', $components['value'], 1, false); |
|
| 206 | - $ele->setExtra( |
|
| 207 | - 'onchange="window.open(\'' |
|
| 208 | - . $_SERVER['SCRIPT_NAME'] |
|
| 209 | - . '?' |
|
| 210 | - . $components['extra'] |
|
| 211 | - . '&filter=' |
|
| 212 | - . $components['filter'] |
|
| 213 | - . (!empty($components['filter']) ? '|' : '') |
|
| 214 | - . $field |
|
| 215 | - . ',\'+this.options[this.selectedIndex].value' |
|
| 216 | - . (!empty($components['operator']) ? '+\',' |
|
| 217 | - . $components['operator'] |
|
| 218 | - . '\'' : '') |
|
| 219 | - . ',\'_self\')"' |
|
| 220 | - ); |
|
| 221 | - break; |
|
| 222 | - case 'abid': |
|
| 223 | - if ('albums' !== $op) { |
|
| 224 | - $ele = new SelectAlbumForm('', 'filter_' . $field . '', $components['value'], 1, false); |
|
| 225 | - $ele->setExtra( |
|
| 226 | - 'onchange="window.open(\'' |
|
| 227 | - . $_SERVER['SCRIPT_NAME'] |
|
| 228 | - . '?' |
|
| 229 | - . $components['extra'] |
|
| 230 | - . '&filter=' |
|
| 231 | - . $components['filter'] |
|
| 232 | - . (!empty($components['filter']) ? '|' : '') |
|
| 233 | - . $field |
|
| 234 | - . ',\'+this.options[this.selectedIndex].value' |
|
| 235 | - . (!empty($components['operator']) ? '+\',' |
|
| 236 | - . $components['operator'] |
|
| 237 | - . '\'' : '') |
|
| 238 | - . ',\'_self\')"' |
|
| 239 | - ); |
|
| 240 | - } |
|
| 241 | - break; |
|
| 242 | - case 'aid': |
|
| 243 | - if ('artists' !== $op) { |
|
| 244 | - $ele = new SelectArtistForm('', 'filter_' . $field . '', $components['value'], 1, false); |
|
| 245 | - $ele->setExtra( |
|
| 246 | - 'onchange="window.open(\'' |
|
| 247 | - . $_SERVER['SCRIPT_NAME'] |
|
| 248 | - . '?' |
|
| 249 | - . $components['extra'] |
|
| 250 | - . '&filter=' |
|
| 251 | - . $components['filter'] |
|
| 252 | - . (!empty($components['filter']) ? '|' : '') |
|
| 253 | - . $field |
|
| 254 | - . ',\'+this.options[this.selectedIndex].value' |
|
| 255 | - . (!empty($components['operator']) ? '+\',' |
|
| 256 | - . $components['operator'] |
|
| 257 | - . '\'' : '') |
|
| 258 | - . ',\'_self\')"' |
|
| 259 | - ); |
|
| 260 | - } |
|
| 261 | - break; |
|
| 262 | - case 'sid': |
|
| 263 | - if ('songs' !== $op) { |
|
| 264 | - $ele = new SelectSongForm('', 'filter_' . $field . '', $components['value'], 1, false); |
|
| 265 | - $ele->setExtra( |
|
| 266 | - 'onchange="window.open(\'' |
|
| 267 | - . $_SERVER['SCRIPT_NAME'] |
|
| 268 | - . '?' |
|
| 269 | - . $components['extra'] |
|
| 270 | - . '&filter=' |
|
| 271 | - . $components['filter'] |
|
| 272 | - . (!empty($components['filter']) ? '|' : '') |
|
| 273 | - . $field |
|
| 274 | - . ',\'+this.options[this.selectedIndex].value' |
|
| 275 | - . (!empty($components['operator']) ? '+\',' |
|
| 276 | - . $components['operator'] |
|
| 277 | - . '\'' : '') |
|
| 278 | - . ',\'_self\')"' |
|
| 279 | - ); |
|
| 280 | - } |
|
| 281 | - break; |
|
| 282 | - case 'name': |
|
| 283 | - case 'title': |
|
| 284 | - case 'artists': |
|
| 285 | - case 'albums': |
|
| 286 | - case 'songs': |
|
| 287 | - case 'hits': |
|
| 288 | - case 'rank': |
|
| 289 | - case 'votes': |
|
| 290 | - case 'description': |
|
| 291 | - case 'lyrics': |
|
| 292 | - case 'songid': |
|
| 293 | - case 'tags': |
|
| 294 | - $ele = new \XoopsFormElementTray(''); |
|
| 295 | - $ele->addElement(new \XoopsFormText('', 'filter_' . $field . '', 11, 40, $components['value'])); |
|
| 296 | - $button = new \XoopsFormButton('', 'button_' . $field . '', '[+]'); |
|
| 297 | - $button->setExtra( |
|
| 298 | - 'onclick="window.open(\'' |
|
| 299 | - . $_SERVER['SCRIPT_NAME'] |
|
| 300 | - . '?' |
|
| 301 | - . $components['extra'] |
|
| 302 | - . '&filter=' |
|
| 303 | - . $components['filter'] |
|
| 304 | - . (!empty($components['filter']) ? '|' : '') |
|
| 305 | - . $field |
|
| 306 | - . ',\'+$(\'#filter_' |
|
| 307 | - . $field |
|
| 308 | - . '\').val()' |
|
| 309 | - . (!empty($components['operator']) ? '+\',' |
|
| 310 | - . $components['operator'] |
|
| 311 | - . '\'' : '') |
|
| 312 | - . ',\'_self\')"' |
|
| 313 | - ); |
|
| 314 | - $ele->addElement($button); |
|
| 315 | - break; |
|
| 316 | - } |
|
| 317 | - |
|
| 318 | - return $ele; |
|
| 319 | - } |
|
| 130 | + /** |
|
| 131 | + * @param $filter |
|
| 132 | + * @param $field |
|
| 133 | + * @param string $sort |
|
| 134 | + * @param string $op |
|
| 135 | + * @param string $fct |
|
| 136 | + * @return bool|\XoopsModules\Songlist\Form\SelectAlbumForm|\XoopsModules\Songlist\Form\SelectArtistForm|\XoopsModules\Songlist\Form\SelectCategoryForm|\XoopsModules\Songlist\Form\SelectGenreForm|\XoopsModules\Songlist\Form\SelectVoiceForm |
|
| 137 | + */ |
|
| 138 | + function songlist_getFilterElement($filter, $field, $sort = 'created', $op = '', $fct = '') |
|
| 139 | + { |
|
| 140 | + $components = songlist_getFilterURLComponents($filter, $field, $sort); |
|
| 141 | + $ele = false; |
|
| 142 | + require_once __DIR__ . '/songlist.object.php'; |
|
| 143 | + switch ($field) { |
|
| 144 | + case 'gid': |
|
| 145 | + if ('genre' !== $op) { |
|
| 146 | + $ele = new SelectGenreForm('', 'filter_' . $field . '', $components['value'], 1, false); |
|
| 147 | + $ele->setExtra( |
|
| 148 | + 'onchange="window.open(\'' |
|
| 149 | + . $_SERVER['SCRIPT_NAME'] |
|
| 150 | + . '?' |
|
| 151 | + . $components['extra'] |
|
| 152 | + . '&filter=' |
|
| 153 | + . $components['filter'] |
|
| 154 | + . (!empty($components['filter']) ? '|' : '') |
|
| 155 | + . $field |
|
| 156 | + . ',\'+this.options[this.selectedIndex].value' |
|
| 157 | + . (!empty($components['operator']) ? '+\',' |
|
| 158 | + . $components['operator'] |
|
| 159 | + . '\'' : '') |
|
| 160 | + . ',\'_self\')"' |
|
| 161 | + ); |
|
| 162 | + } |
|
| 163 | + break; |
|
| 164 | + case 'vcid': |
|
| 165 | + if ('voice' !== $op) { |
|
| 166 | + $ele = new SelectVoiceForm('', 'filter_' . $field . '', $components['value'], 1, false); |
|
| 167 | + $ele->setExtra( |
|
| 168 | + 'onchange="window.open(\'' |
|
| 169 | + . $_SERVER['SCRIPT_NAME'] |
|
| 170 | + . '?' |
|
| 171 | + . $components['extra'] |
|
| 172 | + . '&filter=' |
|
| 173 | + . $components['filter'] |
|
| 174 | + . (!empty($components['filter']) ? '|' : '') |
|
| 175 | + . $field |
|
| 176 | + . ',\'+this.options[this.selectedIndex].value' |
|
| 177 | + . (!empty($components['operator']) ? '+\',' |
|
| 178 | + . $components['operator'] |
|
| 179 | + . '\'' : '') |
|
| 180 | + . ',\'_self\')"' |
|
| 181 | + ); |
|
| 182 | + } |
|
| 183 | + break; |
|
| 184 | + case 'cid': |
|
| 185 | + if ('category' !== $op) { |
|
| 186 | + $ele = new SelectCategoryForm('', 'filter_' . $field . '', $components['value'], 1, false); |
|
| 187 | + $ele->setExtra( |
|
| 188 | + 'onchange="window.open(\'' |
|
| 189 | + . $_SERVER['SCRIPT_NAME'] |
|
| 190 | + . '?' |
|
| 191 | + . $components['extra'] |
|
| 192 | + . '&filter=' |
|
| 193 | + . $components['filter'] |
|
| 194 | + . (!empty($components['filter']) ? '|' : '') |
|
| 195 | + . $field |
|
| 196 | + . ',\'+this.options[this.selectedIndex].value' |
|
| 197 | + . (!empty($components['operator']) ? '+\',' |
|
| 198 | + . $components['operator'] |
|
| 199 | + . '\'' : '') |
|
| 200 | + . ',\'_self\')"' |
|
| 201 | + ); |
|
| 202 | + } |
|
| 203 | + break; |
|
| 204 | + case 'pid': |
|
| 205 | + $ele = new SelectCategoryForm('', 'filter_' . $field . '', $components['value'], 1, false); |
|
| 206 | + $ele->setExtra( |
|
| 207 | + 'onchange="window.open(\'' |
|
| 208 | + . $_SERVER['SCRIPT_NAME'] |
|
| 209 | + . '?' |
|
| 210 | + . $components['extra'] |
|
| 211 | + . '&filter=' |
|
| 212 | + . $components['filter'] |
|
| 213 | + . (!empty($components['filter']) ? '|' : '') |
|
| 214 | + . $field |
|
| 215 | + . ',\'+this.options[this.selectedIndex].value' |
|
| 216 | + . (!empty($components['operator']) ? '+\',' |
|
| 217 | + . $components['operator'] |
|
| 218 | + . '\'' : '') |
|
| 219 | + . ',\'_self\')"' |
|
| 220 | + ); |
|
| 221 | + break; |
|
| 222 | + case 'abid': |
|
| 223 | + if ('albums' !== $op) { |
|
| 224 | + $ele = new SelectAlbumForm('', 'filter_' . $field . '', $components['value'], 1, false); |
|
| 225 | + $ele->setExtra( |
|
| 226 | + 'onchange="window.open(\'' |
|
| 227 | + . $_SERVER['SCRIPT_NAME'] |
|
| 228 | + . '?' |
|
| 229 | + . $components['extra'] |
|
| 230 | + . '&filter=' |
|
| 231 | + . $components['filter'] |
|
| 232 | + . (!empty($components['filter']) ? '|' : '') |
|
| 233 | + . $field |
|
| 234 | + . ',\'+this.options[this.selectedIndex].value' |
|
| 235 | + . (!empty($components['operator']) ? '+\',' |
|
| 236 | + . $components['operator'] |
|
| 237 | + . '\'' : '') |
|
| 238 | + . ',\'_self\')"' |
|
| 239 | + ); |
|
| 240 | + } |
|
| 241 | + break; |
|
| 242 | + case 'aid': |
|
| 243 | + if ('artists' !== $op) { |
|
| 244 | + $ele = new SelectArtistForm('', 'filter_' . $field . '', $components['value'], 1, false); |
|
| 245 | + $ele->setExtra( |
|
| 246 | + 'onchange="window.open(\'' |
|
| 247 | + . $_SERVER['SCRIPT_NAME'] |
|
| 248 | + . '?' |
|
| 249 | + . $components['extra'] |
|
| 250 | + . '&filter=' |
|
| 251 | + . $components['filter'] |
|
| 252 | + . (!empty($components['filter']) ? '|' : '') |
|
| 253 | + . $field |
|
| 254 | + . ',\'+this.options[this.selectedIndex].value' |
|
| 255 | + . (!empty($components['operator']) ? '+\',' |
|
| 256 | + . $components['operator'] |
|
| 257 | + . '\'' : '') |
|
| 258 | + . ',\'_self\')"' |
|
| 259 | + ); |
|
| 260 | + } |
|
| 261 | + break; |
|
| 262 | + case 'sid': |
|
| 263 | + if ('songs' !== $op) { |
|
| 264 | + $ele = new SelectSongForm('', 'filter_' . $field . '', $components['value'], 1, false); |
|
| 265 | + $ele->setExtra( |
|
| 266 | + 'onchange="window.open(\'' |
|
| 267 | + . $_SERVER['SCRIPT_NAME'] |
|
| 268 | + . '?' |
|
| 269 | + . $components['extra'] |
|
| 270 | + . '&filter=' |
|
| 271 | + . $components['filter'] |
|
| 272 | + . (!empty($components['filter']) ? '|' : '') |
|
| 273 | + . $field |
|
| 274 | + . ',\'+this.options[this.selectedIndex].value' |
|
| 275 | + . (!empty($components['operator']) ? '+\',' |
|
| 276 | + . $components['operator'] |
|
| 277 | + . '\'' : '') |
|
| 278 | + . ',\'_self\')"' |
|
| 279 | + ); |
|
| 280 | + } |
|
| 281 | + break; |
|
| 282 | + case 'name': |
|
| 283 | + case 'title': |
|
| 284 | + case 'artists': |
|
| 285 | + case 'albums': |
|
| 286 | + case 'songs': |
|
| 287 | + case 'hits': |
|
| 288 | + case 'rank': |
|
| 289 | + case 'votes': |
|
| 290 | + case 'description': |
|
| 291 | + case 'lyrics': |
|
| 292 | + case 'songid': |
|
| 293 | + case 'tags': |
|
| 294 | + $ele = new \XoopsFormElementTray(''); |
|
| 295 | + $ele->addElement(new \XoopsFormText('', 'filter_' . $field . '', 11, 40, $components['value'])); |
|
| 296 | + $button = new \XoopsFormButton('', 'button_' . $field . '', '[+]'); |
|
| 297 | + $button->setExtra( |
|
| 298 | + 'onclick="window.open(\'' |
|
| 299 | + . $_SERVER['SCRIPT_NAME'] |
|
| 300 | + . '?' |
|
| 301 | + . $components['extra'] |
|
| 302 | + . '&filter=' |
|
| 303 | + . $components['filter'] |
|
| 304 | + . (!empty($components['filter']) ? '|' : '') |
|
| 305 | + . $field |
|
| 306 | + . ',\'+$(\'#filter_' |
|
| 307 | + . $field |
|
| 308 | + . '\').val()' |
|
| 309 | + . (!empty($components['operator']) ? '+\',' |
|
| 310 | + . $components['operator'] |
|
| 311 | + . '\'' : '') |
|
| 312 | + . ',\'_self\')"' |
|
| 313 | + ); |
|
| 314 | + $ele->addElement($button); |
|
| 315 | + break; |
|
| 316 | + } |
|
| 317 | + |
|
| 318 | + return $ele; |
|
| 319 | + } |
|
| 320 | 320 | } |
| 321 | 321 | |
| 322 | 322 | if (!function_exists('songlist_getFilterURLComponents')) { |
| 323 | - /** |
|
| 324 | - * @param $filter |
|
| 325 | - * @param $field |
|
| 326 | - * @param string $sort |
|
| 327 | - * @return array |
|
| 328 | - */ |
|
| 329 | - function songlist_getFilterURLComponents($filter, $field, $sort = 'created'): array |
|
| 330 | - { |
|
| 331 | - $parts = explode('|', $filter); |
|
| 332 | - $ret = []; |
|
| 333 | - $value = ''; |
|
| 334 | - $ele_value = ''; |
|
| 335 | - $operator = ''; |
|
| 336 | - foreach ($parts as $part) { |
|
| 337 | - $var = explode(',', $part); |
|
| 338 | - if (count($var) > 1) { |
|
| 339 | - if ($var[0] == $field) { |
|
| 340 | - $ele_value = $var[1]; |
|
| 341 | - if (isset($var[2])) { |
|
| 342 | - $operator = $var[2]; |
|
| 343 | - } |
|
| 344 | - } elseif (1 != $var[0]) { |
|
| 345 | - $ret[] = implode(',', $var); |
|
| 346 | - } |
|
| 347 | - } |
|
| 348 | - } |
|
| 349 | - $pagenav = []; |
|
| 350 | - $pagenav['op'] = $_REQUEST['op'] ?? 'videos'; |
|
| 351 | - $pagenav['fct'] = $_REQUEST['fct'] ?? 'list'; |
|
| 352 | - $pagenav['limit'] = Request::getInt('limit', 30, 'REQUEST'); |
|
| 353 | - $pagenav['start'] = 0; |
|
| 354 | - $pagenav['order'] = !empty($_REQUEST['order']) ? $_REQUEST['order'] : 'DESC'; |
|
| 355 | - $pagenav['sort'] = !empty($_REQUEST['sort']) ? '' . $_REQUEST['sort'] . '' : $sort; |
|
| 356 | - $retb = []; |
|
| 357 | - foreach ($pagenav as $key => $value) { |
|
| 358 | - $retb[] = "$key=$value"; |
|
| 359 | - } |
|
| 360 | - |
|
| 361 | - return ['value' => $ele_value, 'field' => $field, 'operator' => $operator, 'filter' => implode('|', $ret), 'extra' => implode('&', $retb)]; |
|
| 362 | - } |
|
| 323 | + /** |
|
| 324 | + * @param $filter |
|
| 325 | + * @param $field |
|
| 326 | + * @param string $sort |
|
| 327 | + * @return array |
|
| 328 | + */ |
|
| 329 | + function songlist_getFilterURLComponents($filter, $field, $sort = 'created'): array |
|
| 330 | + { |
|
| 331 | + $parts = explode('|', $filter); |
|
| 332 | + $ret = []; |
|
| 333 | + $value = ''; |
|
| 334 | + $ele_value = ''; |
|
| 335 | + $operator = ''; |
|
| 336 | + foreach ($parts as $part) { |
|
| 337 | + $var = explode(',', $part); |
|
| 338 | + if (count($var) > 1) { |
|
| 339 | + if ($var[0] == $field) { |
|
| 340 | + $ele_value = $var[1]; |
|
| 341 | + if (isset($var[2])) { |
|
| 342 | + $operator = $var[2]; |
|
| 343 | + } |
|
| 344 | + } elseif (1 != $var[0]) { |
|
| 345 | + $ret[] = implode(',', $var); |
|
| 346 | + } |
|
| 347 | + } |
|
| 348 | + } |
|
| 349 | + $pagenav = []; |
|
| 350 | + $pagenav['op'] = $_REQUEST['op'] ?? 'videos'; |
|
| 351 | + $pagenav['fct'] = $_REQUEST['fct'] ?? 'list'; |
|
| 352 | + $pagenav['limit'] = Request::getInt('limit', 30, 'REQUEST'); |
|
| 353 | + $pagenav['start'] = 0; |
|
| 354 | + $pagenav['order'] = !empty($_REQUEST['order']) ? $_REQUEST['order'] : 'DESC'; |
|
| 355 | + $pagenav['sort'] = !empty($_REQUEST['sort']) ? '' . $_REQUEST['sort'] . '' : $sort; |
|
| 356 | + $retb = []; |
|
| 357 | + foreach ($pagenav as $key => $value) { |
|
| 358 | + $retb[] = "$key=$value"; |
|
| 359 | + } |
|
| 360 | + |
|
| 361 | + return ['value' => $ele_value, 'field' => $field, 'operator' => $operator, 'filter' => implode('|', $ret), 'extra' => implode('&', $retb)]; |
|
| 362 | + } |
|
| 363 | 363 | } |
| 364 | 364 | |
| 365 | 365 | if (!function_exists('songlist_obj2array')) { |
| 366 | - /** |
|
| 367 | - * @param $objects |
|
| 368 | - * @return array |
|
| 369 | - */ |
|
| 370 | - function songlist_obj2array($objects): array |
|
| 371 | - { |
|
| 372 | - $ret = []; |
|
| 373 | - foreach ((array)$objects as $key => $value) { |
|
| 374 | - if (is_a($value, 'stdClass')) { |
|
| 375 | - $ret[$key] = songlist_obj2array($value); |
|
| 376 | - } elseif (is_array($value)) { |
|
| 377 | - $ret[$key] = songlist_obj2array($value); |
|
| 378 | - } else { |
|
| 379 | - $ret[$key] = $value; |
|
| 380 | - } |
|
| 381 | - } |
|
| 382 | - |
|
| 383 | - return $ret; |
|
| 384 | - } |
|
| 366 | + /** |
|
| 367 | + * @param $objects |
|
| 368 | + * @return array |
|
| 369 | + */ |
|
| 370 | + function songlist_obj2array($objects): array |
|
| 371 | + { |
|
| 372 | + $ret = []; |
|
| 373 | + foreach ((array)$objects as $key => $value) { |
|
| 374 | + if (is_a($value, 'stdClass')) { |
|
| 375 | + $ret[$key] = songlist_obj2array($value); |
|
| 376 | + } elseif (is_array($value)) { |
|
| 377 | + $ret[$key] = songlist_obj2array($value); |
|
| 378 | + } else { |
|
| 379 | + $ret[$key] = $value; |
|
| 380 | + } |
|
| 381 | + } |
|
| 382 | + |
|
| 383 | + return $ret; |
|
| 384 | + } |
|
| 385 | 385 | } |
| 386 | 386 | |
| 387 | 387 | if (!function_exists('songlist_shortenurl')) { |
| 388 | - /** |
|
| 389 | - * @param $url |
|
| 390 | - * @return mixed |
|
| 391 | - */ |
|
| 392 | - function songlist_shortenurl($url) |
|
| 393 | - { |
|
| 394 | - /** @var \XoopsModuleHandler $moduleHandler */ |
|
| 395 | - $moduleHandler = xoops_getHandler('module'); |
|
| 396 | - /** @var \XoopsConfigHandler $configHandler */ |
|
| 397 | - $configHandler = xoops_getHandler('config'); |
|
| 398 | - $GLOBALS['songlistModule'] = $moduleHandler->getByDirname('songlist'); |
|
| 399 | - $GLOBALS['songlistModuleConfig'] = $configHandler->getConfigList($GLOBALS['songlistModule']->getVar('mid')); |
|
| 400 | - |
|
| 401 | - if (!empty($GLOBALS['songlistModuleConfig']['bitly_username']) && !empty($GLOBALS['songlistModuleConfig']['bitly_apikey'])) { |
|
| 402 | - $source_url = $GLOBALS['songlistModuleConfig']['bitly_apiurl'] . '/shorten?login=' . $GLOBALS['songlistModuleConfig']['bitly_username'] . '&apiKey=' . $GLOBALS['songlistModuleConfig']['bitly_apikey'] . '&format=json&longUrl=' . urlencode($url); |
|
| 403 | - $cookies = XOOPS_ROOT_PATH . '/uploads/songlist_' . md5($GLOBALS['songlistModuleConfig']['bitly_apikey']) . '.cookie'; |
|
| 404 | - if (!$ch = curl_init($source_url)) { |
|
| 405 | - return $url; |
|
| 406 | - } |
|
| 407 | - curl_setopt($ch, CURLOPT_COOKIEJAR, $cookies); |
|
| 408 | - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
|
| 409 | - curl_setopt($ch, CURLOPT_USERAGENT, $GLOBALS['songlistModuleConfig']['user_agent']); |
|
| 410 | - curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $GLOBALS['songlistModuleConfig']['curl_connect_timeout']); |
|
| 411 | - curl_setopt($ch, CURLOPT_TIMEOUT, $GLOBALS['songlistModuleConfig']['curl_timeout']); |
|
| 412 | - $data = curl_exec($ch); |
|
| 413 | - curl_close($ch); |
|
| 414 | - $result = songlist_object2array(json_decode($data)); |
|
| 415 | - $result['status_code'] = 200; |
|
| 416 | - if ($result['status_code']) { |
|
| 417 | - if (!empty($result['data']['url'])) { |
|
| 418 | - return $result['data']['url']; |
|
| 419 | - } |
|
| 420 | - |
|
| 421 | - return $url; |
|
| 422 | - } |
|
| 423 | - |
|
| 424 | - return $url; |
|
| 425 | - } |
|
| 426 | - |
|
| 427 | - return $url; |
|
| 428 | - } |
|
| 388 | + /** |
|
| 389 | + * @param $url |
|
| 390 | + * @return mixed |
|
| 391 | + */ |
|
| 392 | + function songlist_shortenurl($url) |
|
| 393 | + { |
|
| 394 | + /** @var \XoopsModuleHandler $moduleHandler */ |
|
| 395 | + $moduleHandler = xoops_getHandler('module'); |
|
| 396 | + /** @var \XoopsConfigHandler $configHandler */ |
|
| 397 | + $configHandler = xoops_getHandler('config'); |
|
| 398 | + $GLOBALS['songlistModule'] = $moduleHandler->getByDirname('songlist'); |
|
| 399 | + $GLOBALS['songlistModuleConfig'] = $configHandler->getConfigList($GLOBALS['songlistModule']->getVar('mid')); |
|
| 400 | + |
|
| 401 | + if (!empty($GLOBALS['songlistModuleConfig']['bitly_username']) && !empty($GLOBALS['songlistModuleConfig']['bitly_apikey'])) { |
|
| 402 | + $source_url = $GLOBALS['songlistModuleConfig']['bitly_apiurl'] . '/shorten?login=' . $GLOBALS['songlistModuleConfig']['bitly_username'] . '&apiKey=' . $GLOBALS['songlistModuleConfig']['bitly_apikey'] . '&format=json&longUrl=' . urlencode($url); |
|
| 403 | + $cookies = XOOPS_ROOT_PATH . '/uploads/songlist_' . md5($GLOBALS['songlistModuleConfig']['bitly_apikey']) . '.cookie'; |
|
| 404 | + if (!$ch = curl_init($source_url)) { |
|
| 405 | + return $url; |
|
| 406 | + } |
|
| 407 | + curl_setopt($ch, CURLOPT_COOKIEJAR, $cookies); |
|
| 408 | + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
|
| 409 | + curl_setopt($ch, CURLOPT_USERAGENT, $GLOBALS['songlistModuleConfig']['user_agent']); |
|
| 410 | + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $GLOBALS['songlistModuleConfig']['curl_connect_timeout']); |
|
| 411 | + curl_setopt($ch, CURLOPT_TIMEOUT, $GLOBALS['songlistModuleConfig']['curl_timeout']); |
|
| 412 | + $data = curl_exec($ch); |
|
| 413 | + curl_close($ch); |
|
| 414 | + $result = songlist_object2array(json_decode($data)); |
|
| 415 | + $result['status_code'] = 200; |
|
| 416 | + if ($result['status_code']) { |
|
| 417 | + if (!empty($result['data']['url'])) { |
|
| 418 | + return $result['data']['url']; |
|
| 419 | + } |
|
| 420 | + |
|
| 421 | + return $url; |
|
| 422 | + } |
|
| 423 | + |
|
| 424 | + return $url; |
|
| 425 | + } |
|
| 426 | + |
|
| 427 | + return $url; |
|
| 428 | + } |
|
| 429 | 429 | } |
| 430 | 430 | |
| 431 | 431 | if (!function_exists('songlist_xml2array')) { |
| 432 | - /** |
|
| 433 | - * @param $contents |
|
| 434 | - * @param int $get_attributes |
|
| 435 | - * @param string $priority |
|
| 436 | - * @return array|void |
|
| 437 | - */ |
|
| 438 | - function songlist_xml2array($contents, $get_attributes = 1, $priority = 'tag') |
|
| 439 | - { |
|
| 440 | - if (!$contents) { |
|
| 441 | - return []; |
|
| 442 | - } |
|
| 443 | - |
|
| 444 | - if (!function_exists('xml_parser_create')) { |
|
| 445 | - return []; |
|
| 446 | - } |
|
| 447 | - |
|
| 448 | - //Get the XML parser of PHP - PHP must have this module for the parser to work |
|
| 449 | - $parser = xml_parser_create(''); |
|
| 450 | - xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, 'UTF-8'); # https://minutillo.com/steve/weblog/2004/6/17/php-xml-and-character-encodings-a-tale-of-sadness-rage-and-data-loss |
|
| 451 | - xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0); |
|
| 452 | - xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1); |
|
| 453 | - xml_parse_into_struct($parser, trim($contents), $xml_values); |
|
| 454 | - xml_parser_free($parser); |
|
| 455 | - |
|
| 456 | - if (!$xml_values) { |
|
| 457 | - return; |
|
| 458 | - }//Hmm... |
|
| 459 | - |
|
| 460 | - //Initializations |
|
| 461 | - $xml_array = []; |
|
| 462 | - $parents = []; |
|
| 463 | - $opened_tags = []; |
|
| 464 | - $arr = []; |
|
| 465 | - |
|
| 466 | - $current = &$xml_array; //Refference |
|
| 467 | - |
|
| 468 | - //Go through the tags. |
|
| 469 | - $repeated_tag_index = []; //Multiple tags with same name will be turned into an array |
|
| 470 | - foreach ($xml_values as $data) { |
|
| 471 | - unset($attributes, $value); //Remove existing values, or there will be trouble |
|
| 472 | - |
|
| 473 | - //This command will extract these variables into the foreach scope |
|
| 474 | - // tag(string), type(string), level(int), attributes(array). |
|
| 475 | - extract($data); //We could use the array by itself, but this cooler. |
|
| 476 | - |
|
| 477 | - $result = []; |
|
| 478 | - $attributes_data = []; |
|
| 479 | - |
|
| 480 | - if (isset($value)) { |
|
| 481 | - if ('tag' === $priority) { |
|
| 482 | - $result = $value; |
|
| 483 | - } else { |
|
| 484 | - $result['value'] = $value; |
|
| 485 | - } //Put the value in a assoc array if we are in the 'Attribute' mode |
|
| 486 | - } |
|
| 487 | - |
|
| 488 | - //Set the attributes too. |
|
| 489 | - if (isset($attributes) and $get_attributes) { |
|
| 490 | - foreach ($attributes as $attr => $val) { |
|
| 491 | - if ('tag' === $priority) { |
|
| 492 | - $attributes_data[$attr] = $val; |
|
| 493 | - } else { |
|
| 494 | - $result['attr'][$attr] = $val; |
|
| 495 | - } //Set all the attributes in a array called 'attr' |
|
| 496 | - } |
|
| 497 | - } |
|
| 498 | - |
|
| 499 | - //See tag status and do the needed. |
|
| 500 | - if ('open' === $type) {//The starting of the tag '<tag>' |
|
| 501 | - $parent[$level - 1] = &$current; |
|
| 502 | - if (!is_array($current) or (!array_key_exists($tag, $current))) { //Insert New tag |
|
| 503 | - $current[$tag] = $result; |
|
| 504 | - if ($attributes_data) { |
|
| 505 | - $current[$tag . '_attr'] = $attributes_data; |
|
| 506 | - } |
|
| 507 | - $repeated_tag_index[$tag . '_' . $level] = 1; |
|
| 508 | - |
|
| 509 | - $current = &$current[$tag]; |
|
| 510 | - } else { //There was another element with the same tag name |
|
| 511 | - if (isset($current[$tag][0])) {//If there is a 0th element it is already an array |
|
| 512 | - $current[$tag][$repeated_tag_index[$tag . '_' . $level]] = $result; |
|
| 513 | - $repeated_tag_index[$tag . '_' . $level]++; |
|
| 514 | - } else {//This section will make the value an array if multiple tags with the same name appear together |
|
| 515 | - $current[$tag] = [$current[$tag], $result]; //This will combine the existing item and the new item together to make an array |
|
| 516 | - $repeated_tag_index[$tag . '_' . $level] = 2; |
|
| 517 | - |
|
| 518 | - if (isset($current[$tag . '_attr'])) { //The attribute of the last(0th) tag must be moved as well |
|
| 519 | - $current[$tag]['0_attr'] = $current[$tag . '_attr']; |
|
| 520 | - unset($current[$tag . '_attr']); |
|
| 521 | - } |
|
| 522 | - } |
|
| 523 | - $last_item_index = $repeated_tag_index[$tag . '_' . $level] - 1; |
|
| 524 | - $current = &$current[$tag][$last_item_index]; |
|
| 525 | - } |
|
| 526 | - } elseif ('complete' === $type) { //Tags that ends in 1 line '<tag>' |
|
| 527 | - //See if the key is already taken. |
|
| 528 | - if (isset($current[$tag])) { //If taken, put all things inside a list(array) |
|
| 529 | - if (isset($current[$tag][0]) and is_array($current[$tag])) {//If it is already an array... |
|
| 530 | - // ...push the new element into that array. |
|
| 531 | - $current[$tag][$repeated_tag_index[$tag . '_' . $level]] = $result; |
|
| 532 | - |
|
| 533 | - if ('tag' === $priority and $get_attributes and $attributes_data) { |
|
| 534 | - $current[$tag][$repeated_tag_index[$tag . '_' . $level] . '_attr'] = $attributes_data; |
|
| 535 | - } |
|
| 536 | - $repeated_tag_index[$tag . '_' . $level]++; |
|
| 537 | - } else { //If it is not an array... |
|
| 538 | - $current[$tag] = [$current[$tag], $result]; //...Make it an array using using the existing value and the new value |
|
| 539 | - $repeated_tag_index[$tag . '_' . $level] = 1; |
|
| 540 | - if ('tag' === $priority and $get_attributes) { |
|
| 541 | - if (isset($current[$tag . '_attr'])) { //The attribute of the last(0th) tag must be moved as well |
|
| 542 | - $current[$tag]['0_attr'] = $current[$tag . '_attr']; |
|
| 543 | - unset($current[$tag . '_attr']); |
|
| 544 | - } |
|
| 545 | - |
|
| 546 | - if ($attributes_data) { |
|
| 547 | - $current[$tag][$repeated_tag_index[$tag . '_' . $level] . '_attr'] = $attributes_data; |
|
| 548 | - } |
|
| 549 | - } |
|
| 550 | - $repeated_tag_index[$tag . '_' . $level]++; //0 and 1 index is already taken |
|
| 551 | - } |
|
| 552 | - } else { //New Key |
|
| 553 | - $current[$tag] = $result; |
|
| 554 | - $repeated_tag_index[$tag . '_' . $level] = 1; |
|
| 555 | - if ('tag' === $priority and $attributes_data) { |
|
| 556 | - $current[$tag . '_attr'] = $attributes_data; |
|
| 557 | - } |
|
| 558 | - } |
|
| 559 | - } elseif ('close' === $type) { //End of tag '</tag>' |
|
| 560 | - $current = &$parent[$level - 1]; |
|
| 561 | - } |
|
| 562 | - } |
|
| 563 | - |
|
| 564 | - return $xml_array; |
|
| 565 | - } |
|
| 432 | + /** |
|
| 433 | + * @param $contents |
|
| 434 | + * @param int $get_attributes |
|
| 435 | + * @param string $priority |
|
| 436 | + * @return array|void |
|
| 437 | + */ |
|
| 438 | + function songlist_xml2array($contents, $get_attributes = 1, $priority = 'tag') |
|
| 439 | + { |
|
| 440 | + if (!$contents) { |
|
| 441 | + return []; |
|
| 442 | + } |
|
| 443 | + |
|
| 444 | + if (!function_exists('xml_parser_create')) { |
|
| 445 | + return []; |
|
| 446 | + } |
|
| 447 | + |
|
| 448 | + //Get the XML parser of PHP - PHP must have this module for the parser to work |
|
| 449 | + $parser = xml_parser_create(''); |
|
| 450 | + xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, 'UTF-8'); # https://minutillo.com/steve/weblog/2004/6/17/php-xml-and-character-encodings-a-tale-of-sadness-rage-and-data-loss |
|
| 451 | + xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0); |
|
| 452 | + xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1); |
|
| 453 | + xml_parse_into_struct($parser, trim($contents), $xml_values); |
|
| 454 | + xml_parser_free($parser); |
|
| 455 | + |
|
| 456 | + if (!$xml_values) { |
|
| 457 | + return; |
|
| 458 | + }//Hmm... |
|
| 459 | + |
|
| 460 | + //Initializations |
|
| 461 | + $xml_array = []; |
|
| 462 | + $parents = []; |
|
| 463 | + $opened_tags = []; |
|
| 464 | + $arr = []; |
|
| 465 | + |
|
| 466 | + $current = &$xml_array; //Refference |
|
| 467 | + |
|
| 468 | + //Go through the tags. |
|
| 469 | + $repeated_tag_index = []; //Multiple tags with same name will be turned into an array |
|
| 470 | + foreach ($xml_values as $data) { |
|
| 471 | + unset($attributes, $value); //Remove existing values, or there will be trouble |
|
| 472 | + |
|
| 473 | + //This command will extract these variables into the foreach scope |
|
| 474 | + // tag(string), type(string), level(int), attributes(array). |
|
| 475 | + extract($data); //We could use the array by itself, but this cooler. |
|
| 476 | + |
|
| 477 | + $result = []; |
|
| 478 | + $attributes_data = []; |
|
| 479 | + |
|
| 480 | + if (isset($value)) { |
|
| 481 | + if ('tag' === $priority) { |
|
| 482 | + $result = $value; |
|
| 483 | + } else { |
|
| 484 | + $result['value'] = $value; |
|
| 485 | + } //Put the value in a assoc array if we are in the 'Attribute' mode |
|
| 486 | + } |
|
| 487 | + |
|
| 488 | + //Set the attributes too. |
|
| 489 | + if (isset($attributes) and $get_attributes) { |
|
| 490 | + foreach ($attributes as $attr => $val) { |
|
| 491 | + if ('tag' === $priority) { |
|
| 492 | + $attributes_data[$attr] = $val; |
|
| 493 | + } else { |
|
| 494 | + $result['attr'][$attr] = $val; |
|
| 495 | + } //Set all the attributes in a array called 'attr' |
|
| 496 | + } |
|
| 497 | + } |
|
| 498 | + |
|
| 499 | + //See tag status and do the needed. |
|
| 500 | + if ('open' === $type) {//The starting of the tag '<tag>' |
|
| 501 | + $parent[$level - 1] = &$current; |
|
| 502 | + if (!is_array($current) or (!array_key_exists($tag, $current))) { //Insert New tag |
|
| 503 | + $current[$tag] = $result; |
|
| 504 | + if ($attributes_data) { |
|
| 505 | + $current[$tag . '_attr'] = $attributes_data; |
|
| 506 | + } |
|
| 507 | + $repeated_tag_index[$tag . '_' . $level] = 1; |
|
| 508 | + |
|
| 509 | + $current = &$current[$tag]; |
|
| 510 | + } else { //There was another element with the same tag name |
|
| 511 | + if (isset($current[$tag][0])) {//If there is a 0th element it is already an array |
|
| 512 | + $current[$tag][$repeated_tag_index[$tag . '_' . $level]] = $result; |
|
| 513 | + $repeated_tag_index[$tag . '_' . $level]++; |
|
| 514 | + } else {//This section will make the value an array if multiple tags with the same name appear together |
|
| 515 | + $current[$tag] = [$current[$tag], $result]; //This will combine the existing item and the new item together to make an array |
|
| 516 | + $repeated_tag_index[$tag . '_' . $level] = 2; |
|
| 517 | + |
|
| 518 | + if (isset($current[$tag . '_attr'])) { //The attribute of the last(0th) tag must be moved as well |
|
| 519 | + $current[$tag]['0_attr'] = $current[$tag . '_attr']; |
|
| 520 | + unset($current[$tag . '_attr']); |
|
| 521 | + } |
|
| 522 | + } |
|
| 523 | + $last_item_index = $repeated_tag_index[$tag . '_' . $level] - 1; |
|
| 524 | + $current = &$current[$tag][$last_item_index]; |
|
| 525 | + } |
|
| 526 | + } elseif ('complete' === $type) { //Tags that ends in 1 line '<tag>' |
|
| 527 | + //See if the key is already taken. |
|
| 528 | + if (isset($current[$tag])) { //If taken, put all things inside a list(array) |
|
| 529 | + if (isset($current[$tag][0]) and is_array($current[$tag])) {//If it is already an array... |
|
| 530 | + // ...push the new element into that array. |
|
| 531 | + $current[$tag][$repeated_tag_index[$tag . '_' . $level]] = $result; |
|
| 532 | + |
|
| 533 | + if ('tag' === $priority and $get_attributes and $attributes_data) { |
|
| 534 | + $current[$tag][$repeated_tag_index[$tag . '_' . $level] . '_attr'] = $attributes_data; |
|
| 535 | + } |
|
| 536 | + $repeated_tag_index[$tag . '_' . $level]++; |
|
| 537 | + } else { //If it is not an array... |
|
| 538 | + $current[$tag] = [$current[$tag], $result]; //...Make it an array using using the existing value and the new value |
|
| 539 | + $repeated_tag_index[$tag . '_' . $level] = 1; |
|
| 540 | + if ('tag' === $priority and $get_attributes) { |
|
| 541 | + if (isset($current[$tag . '_attr'])) { //The attribute of the last(0th) tag must be moved as well |
|
| 542 | + $current[$tag]['0_attr'] = $current[$tag . '_attr']; |
|
| 543 | + unset($current[$tag . '_attr']); |
|
| 544 | + } |
|
| 545 | + |
|
| 546 | + if ($attributes_data) { |
|
| 547 | + $current[$tag][$repeated_tag_index[$tag . '_' . $level] . '_attr'] = $attributes_data; |
|
| 548 | + } |
|
| 549 | + } |
|
| 550 | + $repeated_tag_index[$tag . '_' . $level]++; //0 and 1 index is already taken |
|
| 551 | + } |
|
| 552 | + } else { //New Key |
|
| 553 | + $current[$tag] = $result; |
|
| 554 | + $repeated_tag_index[$tag . '_' . $level] = 1; |
|
| 555 | + if ('tag' === $priority and $attributes_data) { |
|
| 556 | + $current[$tag . '_attr'] = $attributes_data; |
|
| 557 | + } |
|
| 558 | + } |
|
| 559 | + } elseif ('close' === $type) { //End of tag '</tag>' |
|
| 560 | + $current = &$parent[$level - 1]; |
|
| 561 | + } |
|
| 562 | + } |
|
| 563 | + |
|
| 564 | + return $xml_array; |
|
| 565 | + } |
|
| 566 | 566 | } |
| 567 | 567 | |
| 568 | 568 | if (!function_exists('songlist_toXml')) { |
| 569 | - /** |
|
| 570 | - * @param $array |
|
| 571 | - * @param $name |
|
| 572 | - * @param $standalone |
|
| 573 | - * @param $beginning |
|
| 574 | - * @param $nested |
|
| 575 | - * @return string |
|
| 576 | - */ |
|
| 577 | - function songlist_toXml($array, $name, $standalone, $beginning, $nested): string |
|
| 578 | - { |
|
| 579 | - $output = ''; |
|
| 580 | - if ($beginning) { |
|
| 581 | - if ($standalone) { |
|
| 582 | - header('content-type:text/xml;charset=' . _CHARSET); |
|
| 583 | - } |
|
| 584 | - $output .= '<' . '?' . 'xml version="1.0" encoding="' . _CHARSET . '"' . '?' . '>' . "\n"; |
|
| 585 | - $output .= '<' . $name . '>' . "\n"; |
|
| 586 | - $nested = 0; |
|
| 587 | - } |
|
| 588 | - |
|
| 589 | - if (is_array($array)) { |
|
| 590 | - foreach ($array as $key => $value) { |
|
| 591 | - ++$nested; |
|
| 592 | - if (is_array($value)) { |
|
| 593 | - $output .= str_repeat("\t", (int)$nested) . '<' . (is_string($key) ? $key : $name . '_' . $key) . '>' . "\n"; |
|
| 594 | - ++$nested; |
|
| 595 | - $output .= songlist_toXml($value, $name, false, false, $nested); |
|
| 596 | - $nested--; |
|
| 597 | - $output .= str_repeat("\t", (int)$nested) . '</' . (is_string($key) ? $key : $name . '_' . $key) . '>' . "\n"; |
|
| 598 | - } elseif ('' != $value) { |
|
| 599 | - ++$nested; |
|
| 600 | - $output .= str_repeat("\t", (int)$nested) . ' <' . (is_string($key) ? $key : $name . '_' . $key) . '>' . trim($value) . '</' . (is_string($key) ? $key : $name . '_' . $key) . '>' . "\n"; |
|
| 601 | - $nested--; |
|
| 602 | - } |
|
| 603 | - $nested--; |
|
| 604 | - } |
|
| 605 | - } elseif ('' != $array) { |
|
| 606 | - ++$nested; |
|
| 607 | - $output .= str_repeat("\t", (int)$nested) . trim($array) . "\n"; |
|
| 608 | - $nested--; |
|
| 609 | - } |
|
| 610 | - |
|
| 611 | - if ($beginning) { |
|
| 612 | - $output .= '</' . $name . '>'; |
|
| 613 | - |
|
| 614 | - return $output; |
|
| 615 | - } |
|
| 616 | - |
|
| 617 | - return $output; |
|
| 618 | - } |
|
| 569 | + /** |
|
| 570 | + * @param $array |
|
| 571 | + * @param $name |
|
| 572 | + * @param $standalone |
|
| 573 | + * @param $beginning |
|
| 574 | + * @param $nested |
|
| 575 | + * @return string |
|
| 576 | + */ |
|
| 577 | + function songlist_toXml($array, $name, $standalone, $beginning, $nested): string |
|
| 578 | + { |
|
| 579 | + $output = ''; |
|
| 580 | + if ($beginning) { |
|
| 581 | + if ($standalone) { |
|
| 582 | + header('content-type:text/xml;charset=' . _CHARSET); |
|
| 583 | + } |
|
| 584 | + $output .= '<' . '?' . 'xml version="1.0" encoding="' . _CHARSET . '"' . '?' . '>' . "\n"; |
|
| 585 | + $output .= '<' . $name . '>' . "\n"; |
|
| 586 | + $nested = 0; |
|
| 587 | + } |
|
| 588 | + |
|
| 589 | + if (is_array($array)) { |
|
| 590 | + foreach ($array as $key => $value) { |
|
| 591 | + ++$nested; |
|
| 592 | + if (is_array($value)) { |
|
| 593 | + $output .= str_repeat("\t", (int)$nested) . '<' . (is_string($key) ? $key : $name . '_' . $key) . '>' . "\n"; |
|
| 594 | + ++$nested; |
|
| 595 | + $output .= songlist_toXml($value, $name, false, false, $nested); |
|
| 596 | + $nested--; |
|
| 597 | + $output .= str_repeat("\t", (int)$nested) . '</' . (is_string($key) ? $key : $name . '_' . $key) . '>' . "\n"; |
|
| 598 | + } elseif ('' != $value) { |
|
| 599 | + ++$nested; |
|
| 600 | + $output .= str_repeat("\t", (int)$nested) . ' <' . (is_string($key) ? $key : $name . '_' . $key) . '>' . trim($value) . '</' . (is_string($key) ? $key : $name . '_' . $key) . '>' . "\n"; |
|
| 601 | + $nested--; |
|
| 602 | + } |
|
| 603 | + $nested--; |
|
| 604 | + } |
|
| 605 | + } elseif ('' != $array) { |
|
| 606 | + ++$nested; |
|
| 607 | + $output .= str_repeat("\t", (int)$nested) . trim($array) . "\n"; |
|
| 608 | + $nested--; |
|
| 609 | + } |
|
| 610 | + |
|
| 611 | + if ($beginning) { |
|
| 612 | + $output .= '</' . $name . '>'; |
|
| 613 | + |
|
| 614 | + return $output; |
|
| 615 | + } |
|
| 616 | + |
|
| 617 | + return $output; |
|
| 618 | + } |
|
| 619 | 619 | } |
@@ -114,11 +114,11 @@ discard block |
||
| 114 | 114 | */ |
| 115 | 115 | function is_ipv6($ip = ''): bool |
| 116 | 116 | { |
| 117 | - if ('' == $ip) { |
|
| 117 | + if (''==$ip) { |
|
| 118 | 118 | return false; |
| 119 | 119 | } |
| 120 | 120 | |
| 121 | - if (mb_substr_count($ip, ':') > 0) { |
|
| 121 | + if (mb_substr_count($ip, ':')>0) { |
|
| 122 | 122 | return true; |
| 123 | 123 | } |
| 124 | 124 | |
@@ -139,11 +139,11 @@ discard block |
||
| 139 | 139 | { |
| 140 | 140 | $components = songlist_getFilterURLComponents($filter, $field, $sort); |
| 141 | 141 | $ele = false; |
| 142 | - require_once __DIR__ . '/songlist.object.php'; |
|
| 142 | + require_once __DIR__.'/songlist.object.php'; |
|
| 143 | 143 | switch ($field) { |
| 144 | 144 | case 'gid': |
| 145 | - if ('genre' !== $op) { |
|
| 146 | - $ele = new SelectGenreForm('', 'filter_' . $field . '', $components['value'], 1, false); |
|
| 145 | + if ('genre'!==$op) { |
|
| 146 | + $ele = new SelectGenreForm('', 'filter_'.$field.'', $components['value'], 1, false); |
|
| 147 | 147 | $ele->setExtra( |
| 148 | 148 | 'onchange="window.open(\'' |
| 149 | 149 | . $_SERVER['SCRIPT_NAME'] |
@@ -162,8 +162,8 @@ discard block |
||
| 162 | 162 | } |
| 163 | 163 | break; |
| 164 | 164 | case 'vcid': |
| 165 | - if ('voice' !== $op) { |
|
| 166 | - $ele = new SelectVoiceForm('', 'filter_' . $field . '', $components['value'], 1, false); |
|
| 165 | + if ('voice'!==$op) { |
|
| 166 | + $ele = new SelectVoiceForm('', 'filter_'.$field.'', $components['value'], 1, false); |
|
| 167 | 167 | $ele->setExtra( |
| 168 | 168 | 'onchange="window.open(\'' |
| 169 | 169 | . $_SERVER['SCRIPT_NAME'] |
@@ -182,8 +182,8 @@ discard block |
||
| 182 | 182 | } |
| 183 | 183 | break; |
| 184 | 184 | case 'cid': |
| 185 | - if ('category' !== $op) { |
|
| 186 | - $ele = new SelectCategoryForm('', 'filter_' . $field . '', $components['value'], 1, false); |
|
| 185 | + if ('category'!==$op) { |
|
| 186 | + $ele = new SelectCategoryForm('', 'filter_'.$field.'', $components['value'], 1, false); |
|
| 187 | 187 | $ele->setExtra( |
| 188 | 188 | 'onchange="window.open(\'' |
| 189 | 189 | . $_SERVER['SCRIPT_NAME'] |
@@ -202,7 +202,7 @@ discard block |
||
| 202 | 202 | } |
| 203 | 203 | break; |
| 204 | 204 | case 'pid': |
| 205 | - $ele = new SelectCategoryForm('', 'filter_' . $field . '', $components['value'], 1, false); |
|
| 205 | + $ele = new SelectCategoryForm('', 'filter_'.$field.'', $components['value'], 1, false); |
|
| 206 | 206 | $ele->setExtra( |
| 207 | 207 | 'onchange="window.open(\'' |
| 208 | 208 | . $_SERVER['SCRIPT_NAME'] |
@@ -220,8 +220,8 @@ discard block |
||
| 220 | 220 | ); |
| 221 | 221 | break; |
| 222 | 222 | case 'abid': |
| 223 | - if ('albums' !== $op) { |
|
| 224 | - $ele = new SelectAlbumForm('', 'filter_' . $field . '', $components['value'], 1, false); |
|
| 223 | + if ('albums'!==$op) { |
|
| 224 | + $ele = new SelectAlbumForm('', 'filter_'.$field.'', $components['value'], 1, false); |
|
| 225 | 225 | $ele->setExtra( |
| 226 | 226 | 'onchange="window.open(\'' |
| 227 | 227 | . $_SERVER['SCRIPT_NAME'] |
@@ -240,8 +240,8 @@ discard block |
||
| 240 | 240 | } |
| 241 | 241 | break; |
| 242 | 242 | case 'aid': |
| 243 | - if ('artists' !== $op) { |
|
| 244 | - $ele = new SelectArtistForm('', 'filter_' . $field . '', $components['value'], 1, false); |
|
| 243 | + if ('artists'!==$op) { |
|
| 244 | + $ele = new SelectArtistForm('', 'filter_'.$field.'', $components['value'], 1, false); |
|
| 245 | 245 | $ele->setExtra( |
| 246 | 246 | 'onchange="window.open(\'' |
| 247 | 247 | . $_SERVER['SCRIPT_NAME'] |
@@ -260,8 +260,8 @@ discard block |
||
| 260 | 260 | } |
| 261 | 261 | break; |
| 262 | 262 | case 'sid': |
| 263 | - if ('songs' !== $op) { |
|
| 264 | - $ele = new SelectSongForm('', 'filter_' . $field . '', $components['value'], 1, false); |
|
| 263 | + if ('songs'!==$op) { |
|
| 264 | + $ele = new SelectSongForm('', 'filter_'.$field.'', $components['value'], 1, false); |
|
| 265 | 265 | $ele->setExtra( |
| 266 | 266 | 'onchange="window.open(\'' |
| 267 | 267 | . $_SERVER['SCRIPT_NAME'] |
@@ -292,8 +292,8 @@ discard block |
||
| 292 | 292 | case 'songid': |
| 293 | 293 | case 'tags': |
| 294 | 294 | $ele = new \XoopsFormElementTray(''); |
| 295 | - $ele->addElement(new \XoopsFormText('', 'filter_' . $field . '', 11, 40, $components['value'])); |
|
| 296 | - $button = new \XoopsFormButton('', 'button_' . $field . '', '[+]'); |
|
| 295 | + $ele->addElement(new \XoopsFormText('', 'filter_'.$field.'', 11, 40, $components['value'])); |
|
| 296 | + $button = new \XoopsFormButton('', 'button_'.$field.'', '[+]'); |
|
| 297 | 297 | $button->setExtra( |
| 298 | 298 | 'onclick="window.open(\'' |
| 299 | 299 | . $_SERVER['SCRIPT_NAME'] |
@@ -335,13 +335,13 @@ discard block |
||
| 335 | 335 | $operator = ''; |
| 336 | 336 | foreach ($parts as $part) { |
| 337 | 337 | $var = explode(',', $part); |
| 338 | - if (count($var) > 1) { |
|
| 339 | - if ($var[0] == $field) { |
|
| 338 | + if (count($var)>1) { |
|
| 339 | + if ($var[0]==$field) { |
|
| 340 | 340 | $ele_value = $var[1]; |
| 341 | 341 | if (isset($var[2])) { |
| 342 | 342 | $operator = $var[2]; |
| 343 | 343 | } |
| 344 | - } elseif (1 != $var[0]) { |
|
| 344 | + } elseif (1!=$var[0]) { |
|
| 345 | 345 | $ret[] = implode(',', $var); |
| 346 | 346 | } |
| 347 | 347 | } |
@@ -352,7 +352,7 @@ discard block |
||
| 352 | 352 | $pagenav['limit'] = Request::getInt('limit', 30, 'REQUEST'); |
| 353 | 353 | $pagenav['start'] = 0; |
| 354 | 354 | $pagenav['order'] = !empty($_REQUEST['order']) ? $_REQUEST['order'] : 'DESC'; |
| 355 | - $pagenav['sort'] = !empty($_REQUEST['sort']) ? '' . $_REQUEST['sort'] . '' : $sort; |
|
| 355 | + $pagenav['sort'] = !empty($_REQUEST['sort']) ? ''.$_REQUEST['sort'].'' : $sort; |
|
| 356 | 356 | $retb = []; |
| 357 | 357 | foreach ($pagenav as $key => $value) { |
| 358 | 358 | $retb[] = "$key=$value"; |
@@ -370,7 +370,7 @@ discard block |
||
| 370 | 370 | function songlist_obj2array($objects): array |
| 371 | 371 | { |
| 372 | 372 | $ret = []; |
| 373 | - foreach ((array)$objects as $key => $value) { |
|
| 373 | + foreach ((array) $objects as $key => $value) { |
|
| 374 | 374 | if (is_a($value, 'stdClass')) { |
| 375 | 375 | $ret[$key] = songlist_obj2array($value); |
| 376 | 376 | } elseif (is_array($value)) { |
@@ -399,8 +399,8 @@ discard block |
||
| 399 | 399 | $GLOBALS['songlistModuleConfig'] = $configHandler->getConfigList($GLOBALS['songlistModule']->getVar('mid')); |
| 400 | 400 | |
| 401 | 401 | if (!empty($GLOBALS['songlistModuleConfig']['bitly_username']) && !empty($GLOBALS['songlistModuleConfig']['bitly_apikey'])) { |
| 402 | - $source_url = $GLOBALS['songlistModuleConfig']['bitly_apiurl'] . '/shorten?login=' . $GLOBALS['songlistModuleConfig']['bitly_username'] . '&apiKey=' . $GLOBALS['songlistModuleConfig']['bitly_apikey'] . '&format=json&longUrl=' . urlencode($url); |
|
| 403 | - $cookies = XOOPS_ROOT_PATH . '/uploads/songlist_' . md5($GLOBALS['songlistModuleConfig']['bitly_apikey']) . '.cookie'; |
|
| 402 | + $source_url = $GLOBALS['songlistModuleConfig']['bitly_apiurl'].'/shorten?login='.$GLOBALS['songlistModuleConfig']['bitly_username'].'&apiKey='.$GLOBALS['songlistModuleConfig']['bitly_apikey'].'&format=json&longUrl='.urlencode($url); |
|
| 403 | + $cookies = XOOPS_ROOT_PATH.'/uploads/songlist_'.md5($GLOBALS['songlistModuleConfig']['bitly_apikey']).'.cookie'; |
|
| 404 | 404 | if (!$ch = curl_init($source_url)) { |
| 405 | 405 | return $url; |
| 406 | 406 | } |
@@ -478,7 +478,7 @@ discard block |
||
| 478 | 478 | $attributes_data = []; |
| 479 | 479 | |
| 480 | 480 | if (isset($value)) { |
| 481 | - if ('tag' === $priority) { |
|
| 481 | + if ('tag'===$priority) { |
|
| 482 | 482 | $result = $value; |
| 483 | 483 | } else { |
| 484 | 484 | $result['value'] = $value; |
@@ -488,7 +488,7 @@ discard block |
||
| 488 | 488 | //Set the attributes too. |
| 489 | 489 | if (isset($attributes) and $get_attributes) { |
| 490 | 490 | foreach ($attributes as $attr => $val) { |
| 491 | - if ('tag' === $priority) { |
|
| 491 | + if ('tag'===$priority) { |
|
| 492 | 492 | $attributes_data[$attr] = $val; |
| 493 | 493 | } else { |
| 494 | 494 | $result['attr'][$attr] = $val; |
@@ -497,67 +497,67 @@ discard block |
||
| 497 | 497 | } |
| 498 | 498 | |
| 499 | 499 | //See tag status and do the needed. |
| 500 | - if ('open' === $type) {//The starting of the tag '<tag>' |
|
| 501 | - $parent[$level - 1] = &$current; |
|
| 500 | + if ('open'===$type) {//The starting of the tag '<tag>' |
|
| 501 | + $parent[$level-1] = &$current; |
|
| 502 | 502 | if (!is_array($current) or (!array_key_exists($tag, $current))) { //Insert New tag |
| 503 | 503 | $current[$tag] = $result; |
| 504 | 504 | if ($attributes_data) { |
| 505 | - $current[$tag . '_attr'] = $attributes_data; |
|
| 505 | + $current[$tag.'_attr'] = $attributes_data; |
|
| 506 | 506 | } |
| 507 | - $repeated_tag_index[$tag . '_' . $level] = 1; |
|
| 507 | + $repeated_tag_index[$tag.'_'.$level] = 1; |
|
| 508 | 508 | |
| 509 | 509 | $current = &$current[$tag]; |
| 510 | 510 | } else { //There was another element with the same tag name |
| 511 | 511 | if (isset($current[$tag][0])) {//If there is a 0th element it is already an array |
| 512 | - $current[$tag][$repeated_tag_index[$tag . '_' . $level]] = $result; |
|
| 513 | - $repeated_tag_index[$tag . '_' . $level]++; |
|
| 512 | + $current[$tag][$repeated_tag_index[$tag.'_'.$level]] = $result; |
|
| 513 | + $repeated_tag_index[$tag.'_'.$level]++; |
|
| 514 | 514 | } else {//This section will make the value an array if multiple tags with the same name appear together |
| 515 | 515 | $current[$tag] = [$current[$tag], $result]; //This will combine the existing item and the new item together to make an array |
| 516 | - $repeated_tag_index[$tag . '_' . $level] = 2; |
|
| 516 | + $repeated_tag_index[$tag.'_'.$level] = 2; |
|
| 517 | 517 | |
| 518 | - if (isset($current[$tag . '_attr'])) { //The attribute of the last(0th) tag must be moved as well |
|
| 519 | - $current[$tag]['0_attr'] = $current[$tag . '_attr']; |
|
| 520 | - unset($current[$tag . '_attr']); |
|
| 518 | + if (isset($current[$tag.'_attr'])) { //The attribute of the last(0th) tag must be moved as well |
|
| 519 | + $current[$tag]['0_attr'] = $current[$tag.'_attr']; |
|
| 520 | + unset($current[$tag.'_attr']); |
|
| 521 | 521 | } |
| 522 | 522 | } |
| 523 | - $last_item_index = $repeated_tag_index[$tag . '_' . $level] - 1; |
|
| 523 | + $last_item_index = $repeated_tag_index[$tag.'_'.$level]-1; |
|
| 524 | 524 | $current = &$current[$tag][$last_item_index]; |
| 525 | 525 | } |
| 526 | - } elseif ('complete' === $type) { //Tags that ends in 1 line '<tag>' |
|
| 526 | + } elseif ('complete'===$type) { //Tags that ends in 1 line '<tag>' |
|
| 527 | 527 | //See if the key is already taken. |
| 528 | 528 | if (isset($current[$tag])) { //If taken, put all things inside a list(array) |
| 529 | 529 | if (isset($current[$tag][0]) and is_array($current[$tag])) {//If it is already an array... |
| 530 | 530 | // ...push the new element into that array. |
| 531 | - $current[$tag][$repeated_tag_index[$tag . '_' . $level]] = $result; |
|
| 531 | + $current[$tag][$repeated_tag_index[$tag.'_'.$level]] = $result; |
|
| 532 | 532 | |
| 533 | - if ('tag' === $priority and $get_attributes and $attributes_data) { |
|
| 534 | - $current[$tag][$repeated_tag_index[$tag . '_' . $level] . '_attr'] = $attributes_data; |
|
| 533 | + if ('tag'===$priority and $get_attributes and $attributes_data) { |
|
| 534 | + $current[$tag][$repeated_tag_index[$tag.'_'.$level].'_attr'] = $attributes_data; |
|
| 535 | 535 | } |
| 536 | - $repeated_tag_index[$tag . '_' . $level]++; |
|
| 536 | + $repeated_tag_index[$tag.'_'.$level]++; |
|
| 537 | 537 | } else { //If it is not an array... |
| 538 | 538 | $current[$tag] = [$current[$tag], $result]; //...Make it an array using using the existing value and the new value |
| 539 | - $repeated_tag_index[$tag . '_' . $level] = 1; |
|
| 540 | - if ('tag' === $priority and $get_attributes) { |
|
| 541 | - if (isset($current[$tag . '_attr'])) { //The attribute of the last(0th) tag must be moved as well |
|
| 542 | - $current[$tag]['0_attr'] = $current[$tag . '_attr']; |
|
| 543 | - unset($current[$tag . '_attr']); |
|
| 539 | + $repeated_tag_index[$tag.'_'.$level] = 1; |
|
| 540 | + if ('tag'===$priority and $get_attributes) { |
|
| 541 | + if (isset($current[$tag.'_attr'])) { //The attribute of the last(0th) tag must be moved as well |
|
| 542 | + $current[$tag]['0_attr'] = $current[$tag.'_attr']; |
|
| 543 | + unset($current[$tag.'_attr']); |
|
| 544 | 544 | } |
| 545 | 545 | |
| 546 | 546 | if ($attributes_data) { |
| 547 | - $current[$tag][$repeated_tag_index[$tag . '_' . $level] . '_attr'] = $attributes_data; |
|
| 547 | + $current[$tag][$repeated_tag_index[$tag.'_'.$level].'_attr'] = $attributes_data; |
|
| 548 | 548 | } |
| 549 | 549 | } |
| 550 | - $repeated_tag_index[$tag . '_' . $level]++; //0 and 1 index is already taken |
|
| 550 | + $repeated_tag_index[$tag.'_'.$level]++; //0 and 1 index is already taken |
|
| 551 | 551 | } |
| 552 | 552 | } else { //New Key |
| 553 | 553 | $current[$tag] = $result; |
| 554 | - $repeated_tag_index[$tag . '_' . $level] = 1; |
|
| 555 | - if ('tag' === $priority and $attributes_data) { |
|
| 556 | - $current[$tag . '_attr'] = $attributes_data; |
|
| 554 | + $repeated_tag_index[$tag.'_'.$level] = 1; |
|
| 555 | + if ('tag'===$priority and $attributes_data) { |
|
| 556 | + $current[$tag.'_attr'] = $attributes_data; |
|
| 557 | 557 | } |
| 558 | 558 | } |
| 559 | - } elseif ('close' === $type) { //End of tag '</tag>' |
|
| 560 | - $current = &$parent[$level - 1]; |
|
| 559 | + } elseif ('close'===$type) { //End of tag '</tag>' |
|
| 560 | + $current = &$parent[$level-1]; |
|
| 561 | 561 | } |
| 562 | 562 | } |
| 563 | 563 | |
@@ -579,10 +579,10 @@ discard block |
||
| 579 | 579 | $output = ''; |
| 580 | 580 | if ($beginning) { |
| 581 | 581 | if ($standalone) { |
| 582 | - header('content-type:text/xml;charset=' . _CHARSET); |
|
| 582 | + header('content-type:text/xml;charset='._CHARSET); |
|
| 583 | 583 | } |
| 584 | - $output .= '<' . '?' . 'xml version="1.0" encoding="' . _CHARSET . '"' . '?' . '>' . "\n"; |
|
| 585 | - $output .= '<' . $name . '>' . "\n"; |
|
| 584 | + $output .= '<'.'?'.'xml version="1.0" encoding="'._CHARSET.'"'.'?'.'>'."\n"; |
|
| 585 | + $output .= '<'.$name.'>'."\n"; |
|
| 586 | 586 | $nested = 0; |
| 587 | 587 | } |
| 588 | 588 | |
@@ -590,26 +590,26 @@ discard block |
||
| 590 | 590 | foreach ($array as $key => $value) { |
| 591 | 591 | ++$nested; |
| 592 | 592 | if (is_array($value)) { |
| 593 | - $output .= str_repeat("\t", (int)$nested) . '<' . (is_string($key) ? $key : $name . '_' . $key) . '>' . "\n"; |
|
| 593 | + $output .= str_repeat("\t", (int) $nested).'<'.(is_string($key) ? $key : $name.'_'.$key).'>'."\n"; |
|
| 594 | 594 | ++$nested; |
| 595 | 595 | $output .= songlist_toXml($value, $name, false, false, $nested); |
| 596 | 596 | $nested--; |
| 597 | - $output .= str_repeat("\t", (int)$nested) . '</' . (is_string($key) ? $key : $name . '_' . $key) . '>' . "\n"; |
|
| 598 | - } elseif ('' != $value) { |
|
| 597 | + $output .= str_repeat("\t", (int) $nested).'</'.(is_string($key) ? $key : $name.'_'.$key).'>'."\n"; |
|
| 598 | + } elseif (''!=$value) { |
|
| 599 | 599 | ++$nested; |
| 600 | - $output .= str_repeat("\t", (int)$nested) . ' <' . (is_string($key) ? $key : $name . '_' . $key) . '>' . trim($value) . '</' . (is_string($key) ? $key : $name . '_' . $key) . '>' . "\n"; |
|
| 600 | + $output .= str_repeat("\t", (int) $nested).' <'.(is_string($key) ? $key : $name.'_'.$key).'>'.trim($value).'</'.(is_string($key) ? $key : $name.'_'.$key).'>'."\n"; |
|
| 601 | 601 | $nested--; |
| 602 | 602 | } |
| 603 | 603 | $nested--; |
| 604 | 604 | } |
| 605 | - } elseif ('' != $array) { |
|
| 605 | + } elseif (''!=$array) { |
|
| 606 | 606 | ++$nested; |
| 607 | - $output .= str_repeat("\t", (int)$nested) . trim($array) . "\n"; |
|
| 607 | + $output .= str_repeat("\t", (int) $nested).trim($array)."\n"; |
|
| 608 | 608 | $nested--; |
| 609 | 609 | } |
| 610 | 610 | |
| 611 | 611 | if ($beginning) { |
| 612 | - $output .= '</' . $name . '>'; |
|
| 612 | + $output .= '</'.$name.'>'; |
|
| 613 | 613 | |
| 614 | 614 | return $output; |
| 615 | 615 | } |
@@ -6,17 +6,17 @@ discard block |
||
| 6 | 6 | */ |
| 7 | 7 | function xoops_module_update_songlist(&$module): bool |
| 8 | 8 | { |
| 9 | - $sql = []; |
|
| 9 | + $sql = []; |
|
| 10 | 10 | |
| 11 | - $sql[] = 'CREATE TABLE `' |
|
| 12 | - . $GLOBALS['xoopsDB']->prefix('songlist_voice') |
|
| 13 | - . "` ( `vcid` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, `name` VARCHAR(128) DEFAULT NULL, `artists` INT(12) UNSIGNED DEFAULT '0', `albums` INT(12) UNSIGNED DEFAULT '0', `songs` INT(12) UNSIGNED DEFAULT '0', `rank` DECIMAL(10,3) UNSIGNED DEFAULT '0.000', `votes` INT(10) UNSIGNED DEFAULT '0', `created` INT(12) UNSIGNED DEFAULT '0', `updated` INT(12) UNSIGNED DEFAULT '0', PRIMARY KEY (`vcid`), KEY `SORT` (`name`(32),`rank`,`votes`,`created`)) ENGINE=InnoDB DEFAULT CHARSET=utf8"; |
|
| 14 | - $sql[] = 'ALTER TABLE `' . $GLOBALS['xoopsDB']->prefix('songlist_songs') . "` ADD COLUMN `vcid` INT(12) UNSIGNED DEFAULT '0'"; |
|
| 15 | - $sql[] = 'ALTER TABLE `' . $GLOBALS['xoopsDB']->prefix('songlist_songs') . '` CHANGE COLUMN `lyrics` `lyrics` LONGTEXT'; |
|
| 16 | - $sql[] = 'ALTER TABLE `' . $GLOBALS['xoopsDB']->prefix('songlist_songs') . "` ADD COLUMN `mp3` VARCHAR(500) DEFAULT ''"; |
|
| 17 | - $sql[] = 'ALTER TABLE `' . $GLOBALS['xoopsDB']->prefix('songlist_songs') . '` CHANGE COLUMN `traxid` `traxid` INT(4) UNSIGNED ZEROFILL DEFAULT NULL'; |
|
| 11 | + $sql[] = 'CREATE TABLE `' |
|
| 12 | + . $GLOBALS['xoopsDB']->prefix('songlist_voice') |
|
| 13 | + . "` ( `vcid` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, `name` VARCHAR(128) DEFAULT NULL, `artists` INT(12) UNSIGNED DEFAULT '0', `albums` INT(12) UNSIGNED DEFAULT '0', `songs` INT(12) UNSIGNED DEFAULT '0', `rank` DECIMAL(10,3) UNSIGNED DEFAULT '0.000', `votes` INT(10) UNSIGNED DEFAULT '0', `created` INT(12) UNSIGNED DEFAULT '0', `updated` INT(12) UNSIGNED DEFAULT '0', PRIMARY KEY (`vcid`), KEY `SORT` (`name`(32),`rank`,`votes`,`created`)) ENGINE=InnoDB DEFAULT CHARSET=utf8"; |
|
| 14 | + $sql[] = 'ALTER TABLE `' . $GLOBALS['xoopsDB']->prefix('songlist_songs') . "` ADD COLUMN `vcid` INT(12) UNSIGNED DEFAULT '0'"; |
|
| 15 | + $sql[] = 'ALTER TABLE `' . $GLOBALS['xoopsDB']->prefix('songlist_songs') . '` CHANGE COLUMN `lyrics` `lyrics` LONGTEXT'; |
|
| 16 | + $sql[] = 'ALTER TABLE `' . $GLOBALS['xoopsDB']->prefix('songlist_songs') . "` ADD COLUMN `mp3` VARCHAR(500) DEFAULT ''"; |
|
| 17 | + $sql[] = 'ALTER TABLE `' . $GLOBALS['xoopsDB']->prefix('songlist_songs') . '` CHANGE COLUMN `traxid` `traxid` INT(4) UNSIGNED ZEROFILL DEFAULT NULL'; |
|
| 18 | 18 | |
| 19 | - return xoops_module_update_vs_executesql($sql); |
|
| 19 | + return xoops_module_update_vs_executesql($sql); |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | /** |
@@ -25,31 +25,31 @@ discard block |
||
| 25 | 25 | */ |
| 26 | 26 | function xoops_module_update_vs_executesql($sql): bool |
| 27 | 27 | { |
| 28 | - if (is_string($sql)) { |
|
| 29 | - if ($GLOBALS['xoopsDB']->queryF($sql)) { |
|
| 30 | - xoops_error($sql, 'SQL Executed Successfully!!!'); |
|
| 31 | - } |
|
| 32 | - } elseif (is_array($sql)) { |
|
| 33 | - foreach ($sql as $id => $question) { |
|
| 34 | - if (is_array($question)) { |
|
| 35 | - foreach ($question as $kquestion => $questionb) { |
|
| 36 | - if ($GLOBALS['xoopsDB']->queryF($kquestion)) { |
|
| 37 | - xoops_error($kquestion, 'SQL Executed Successfully!!!'); |
|
| 38 | - xoops_module_update_vs_executesql($questionb); |
|
| 39 | - } |
|
| 40 | - } |
|
| 41 | - } elseif ($GLOBALS['xoopsDB']->queryF($id)) { |
|
| 42 | - xoops_error($id, 'SQL Executed Successfully!!!'); |
|
| 43 | - if ($GLOBALS['xoopsDB']->queryF($question)) { |
|
| 44 | - xoops_error($question, 'SQL Executed Successfully!!!'); |
|
| 45 | - } |
|
| 46 | - } elseif ($GLOBALS['xoopsDB']->queryF($question)) { |
|
| 47 | - xoops_error($question, 'SQL Executed Successfully!!!'); |
|
| 48 | - } |
|
| 49 | - } |
|
| 50 | - } else { |
|
| 51 | - return false; |
|
| 52 | - } |
|
| 28 | + if (is_string($sql)) { |
|
| 29 | + if ($GLOBALS['xoopsDB']->queryF($sql)) { |
|
| 30 | + xoops_error($sql, 'SQL Executed Successfully!!!'); |
|
| 31 | + } |
|
| 32 | + } elseif (is_array($sql)) { |
|
| 33 | + foreach ($sql as $id => $question) { |
|
| 34 | + if (is_array($question)) { |
|
| 35 | + foreach ($question as $kquestion => $questionb) { |
|
| 36 | + if ($GLOBALS['xoopsDB']->queryF($kquestion)) { |
|
| 37 | + xoops_error($kquestion, 'SQL Executed Successfully!!!'); |
|
| 38 | + xoops_module_update_vs_executesql($questionb); |
|
| 39 | + } |
|
| 40 | + } |
|
| 41 | + } elseif ($GLOBALS['xoopsDB']->queryF($id)) { |
|
| 42 | + xoops_error($id, 'SQL Executed Successfully!!!'); |
|
| 43 | + if ($GLOBALS['xoopsDB']->queryF($question)) { |
|
| 44 | + xoops_error($question, 'SQL Executed Successfully!!!'); |
|
| 45 | + } |
|
| 46 | + } elseif ($GLOBALS['xoopsDB']->queryF($question)) { |
|
| 47 | + xoops_error($question, 'SQL Executed Successfully!!!'); |
|
| 48 | + } |
|
| 49 | + } |
|
| 50 | + } else { |
|
| 51 | + return false; |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - return true; |
|
| 54 | + return true; |
|
| 55 | 55 | } |
@@ -11,10 +11,10 @@ |
||
| 11 | 11 | $sql[] = 'CREATE TABLE `' |
| 12 | 12 | . $GLOBALS['xoopsDB']->prefix('songlist_voice') |
| 13 | 13 | . "` ( `vcid` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, `name` VARCHAR(128) DEFAULT NULL, `artists` INT(12) UNSIGNED DEFAULT '0', `albums` INT(12) UNSIGNED DEFAULT '0', `songs` INT(12) UNSIGNED DEFAULT '0', `rank` DECIMAL(10,3) UNSIGNED DEFAULT '0.000', `votes` INT(10) UNSIGNED DEFAULT '0', `created` INT(12) UNSIGNED DEFAULT '0', `updated` INT(12) UNSIGNED DEFAULT '0', PRIMARY KEY (`vcid`), KEY `SORT` (`name`(32),`rank`,`votes`,`created`)) ENGINE=InnoDB DEFAULT CHARSET=utf8"; |
| 14 | - $sql[] = 'ALTER TABLE `' . $GLOBALS['xoopsDB']->prefix('songlist_songs') . "` ADD COLUMN `vcid` INT(12) UNSIGNED DEFAULT '0'"; |
|
| 15 | - $sql[] = 'ALTER TABLE `' . $GLOBALS['xoopsDB']->prefix('songlist_songs') . '` CHANGE COLUMN `lyrics` `lyrics` LONGTEXT'; |
|
| 16 | - $sql[] = 'ALTER TABLE `' . $GLOBALS['xoopsDB']->prefix('songlist_songs') . "` ADD COLUMN `mp3` VARCHAR(500) DEFAULT ''"; |
|
| 17 | - $sql[] = 'ALTER TABLE `' . $GLOBALS['xoopsDB']->prefix('songlist_songs') . '` CHANGE COLUMN `traxid` `traxid` INT(4) UNSIGNED ZEROFILL DEFAULT NULL'; |
|
| 14 | + $sql[] = 'ALTER TABLE `'.$GLOBALS['xoopsDB']->prefix('songlist_songs')."` ADD COLUMN `vcid` INT(12) UNSIGNED DEFAULT '0'"; |
|
| 15 | + $sql[] = 'ALTER TABLE `'.$GLOBALS['xoopsDB']->prefix('songlist_songs').'` CHANGE COLUMN `lyrics` `lyrics` LONGTEXT'; |
|
| 16 | + $sql[] = 'ALTER TABLE `'.$GLOBALS['xoopsDB']->prefix('songlist_songs')."` ADD COLUMN `mp3` VARCHAR(500) DEFAULT ''"; |
|
| 17 | + $sql[] = 'ALTER TABLE `'.$GLOBALS['xoopsDB']->prefix('songlist_songs').'` CHANGE COLUMN `traxid` `traxid` INT(4) UNSIGNED ZEROFILL DEFAULT NULL'; |
|
| 18 | 18 | |
| 19 | 19 | return xoops_module_update_vs_executesql($sql); |
| 20 | 20 | } |
@@ -76,271 +76,271 @@ discard block |
||
| 76 | 76 | */ |
| 77 | 77 | class ServicesJSON |
| 78 | 78 | { |
| 79 | - /** |
|
| 80 | - * constructs a new JSON instance |
|
| 81 | - * |
|
| 82 | - * @param int $use object behavior flags; combine with boolean-OR |
|
| 83 | - * |
|
| 84 | - * possible values: |
|
| 85 | - * - SERVICES_JSON_LOOSE_TYPE: loose typing. |
|
| 86 | - * "{...}" syntax creates associative arrays |
|
| 87 | - * instead of objects in decode(). |
|
| 88 | - * - SERVICES_JSON_SUPPRESS_ERRORS: error suppression. |
|
| 89 | - * Values which can't be encoded (e.g. resources) |
|
| 90 | - * appear as NULL instead of throwing errors. |
|
| 91 | - * By default, a deeply-nested resource will |
|
| 92 | - * bubble up with an error, so all return values |
|
| 93 | - * from encode() should be checked with isError() |
|
| 94 | - */ |
|
| 95 | - public function __construct($use = 0) |
|
| 96 | - { |
|
| 97 | - $this->use = $use; |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * convert a string from one UTF-16 char to one UTF-8 char |
|
| 102 | - * |
|
| 103 | - * Normally should be handled by mb_convert_encoding, but |
|
| 104 | - * provides a slower PHP-only method for installations |
|
| 105 | - * that lack the multibye string extension. |
|
| 106 | - * |
|
| 107 | - * @param string $utf16 UTF-16 character |
|
| 108 | - * @return string UTF-8 character |
|
| 109 | - */ |
|
| 110 | - public function utf162utf8($utf16): string |
|
| 111 | - { |
|
| 112 | - // oh please oh please oh please oh please oh please |
|
| 113 | - if (function_exists('mb_convert_encoding')) { |
|
| 114 | - return mb_convert_encoding($utf16, 'UTF-8', 'UTF-16'); |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - $bytes = (ord($utf16[0]) << 8) | ord($utf16[1]); |
|
| 118 | - |
|
| 119 | - switch (true) { |
|
| 120 | - case ((0x7F & $bytes) == $bytes): |
|
| 121 | - // this case should never be reached, because we are in ASCII range |
|
| 122 | - // see: https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
| 123 | - return chr(0x7F & $bytes); |
|
| 124 | - case (0x07FF & $bytes) == $bytes: |
|
| 125 | - // return a 2-byte UTF-8 character |
|
| 126 | - // see: https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
| 127 | - return chr(0xC0 | (($bytes >> 6) & 0x1F)) . chr(0x80 | ($bytes & 0x3F)); |
|
| 128 | - case (0xFFFF & $bytes) == $bytes: |
|
| 129 | - // return a 3-byte UTF-8 character |
|
| 130 | - // see: https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
| 131 | - return chr(0xE0 | (($bytes >> 12) & 0x0F)) . chr(0x80 | (($bytes >> 6) & 0x3F)) . chr(0x80 | ($bytes & 0x3F)); |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - // ignoring UTF-32 for now, sorry |
|
| 135 | - return ''; |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * convert a string from one UTF-8 char to one UTF-16 char |
|
| 140 | - * |
|
| 141 | - * Normally should be handled by mb_convert_encoding, but |
|
| 142 | - * provides a slower PHP-only method for installations |
|
| 143 | - * that lack the multibye string extension. |
|
| 144 | - * |
|
| 145 | - * @param string $utf8 UTF-8 character |
|
| 146 | - * @return string UTF-16 character |
|
| 147 | - */ |
|
| 148 | - public function utf82utf16($utf8): string |
|
| 149 | - { |
|
| 150 | - // oh please oh please oh please oh please oh please |
|
| 151 | - if (function_exists('mb_convert_encoding')) { |
|
| 152 | - return mb_convert_encoding($utf8, 'UTF-16', 'UTF-8'); |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - switch (mb_strlen($utf8)) { |
|
| 156 | - case 1: |
|
| 157 | - // this case should never be reached, because we are in ASCII range |
|
| 158 | - // see: https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
| 159 | - return $utf8; |
|
| 160 | - case 2: |
|
| 161 | - // return a UTF-16 character from a 2-byte UTF-8 char |
|
| 162 | - // see: https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
| 163 | - return chr(0x07 & (ord($utf8[0]) >> 2)) . chr((0xC0 & (ord($utf8[0]) << 6)) | (0x3F & ord($utf8[1]))); |
|
| 164 | - case 3: |
|
| 165 | - // return a UTF-16 character from a 3-byte UTF-8 char |
|
| 166 | - // see: https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
| 167 | - return chr((0xF0 & (ord($utf8[0]) << 4)) | (0x0F & (ord($utf8[1]) >> 2))) . chr((0xC0 & (ord($utf8[1]) << 6)) | (0x7F & ord($utf8[2]))); |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - // ignoring UTF-32 for now, sorry |
|
| 171 | - return ''; |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - /** |
|
| 175 | - * encodes an arbitrary variable into JSON format (and sends JSON Header) |
|
| 176 | - * |
|
| 177 | - * @param mixed $var any number, boolean, string, array, or object to be encoded. |
|
| 178 | - * see argument 1 to ServicesJSON() above for array-parsing behavior. |
|
| 179 | - * if var is a strng, note that encode() always expects it |
|
| 180 | - * to be in ASCII or UTF-8 format! |
|
| 181 | - * |
|
| 182 | - * @return mixed JSON string representation of input var or an error if a problem occurs |
|
| 183 | - */ |
|
| 184 | - public function encode($var) |
|
| 185 | - { |
|
| 186 | - header('Document-type: application/json'); |
|
| 187 | - |
|
| 188 | - return $this->encodeUnsafe($var); |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - /** |
|
| 192 | - * encodes an arbitrary variable into JSON format without JSON Header - warning - may allow CSS!!!!) |
|
| 193 | - * |
|
| 194 | - * @param mixed $var any number, boolean, string, array, or object to be encoded. |
|
| 195 | - * see argument 1 to ServicesJSON() above for array-parsing behavior. |
|
| 196 | - * if var is a strng, note that encode() always expects it |
|
| 197 | - * to be in ASCII or UTF-8 format! |
|
| 198 | - * |
|
| 199 | - * @return mixed JSON string representation of input var or an error if a problem occurs |
|
| 200 | - */ |
|
| 201 | - public function encodeUnsafe($var) |
|
| 202 | - { |
|
| 203 | - // see bug #16908 - regarding numeric locale printing |
|
| 204 | - $lc = setlocale(LC_NUMERIC, 0); |
|
| 205 | - setlocale(LC_NUMERIC, 'C'); |
|
| 206 | - $ret = $this->_encode($var); |
|
| 207 | - setlocale(LC_NUMERIC, $lc); |
|
| 208 | - |
|
| 209 | - return $ret; |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - /** |
|
| 213 | - * PRIVATE CODE that does the work of encodes an arbitrary variable into JSON format |
|
| 214 | - * |
|
| 215 | - * @param mixed $var any number, boolean, string, array, or object to be encoded. |
|
| 216 | - * see argument 1 to ServicesJSON() above for array-parsing behavior. |
|
| 217 | - * if var is a strng, note that encode() always expects it |
|
| 218 | - * to be in ASCII or UTF-8 format! |
|
| 219 | - * |
|
| 220 | - * @return mixed JSON string representation of input var or an error if a problem occurs |
|
| 221 | - */ |
|
| 222 | - public function _encode($var) |
|
| 223 | - { |
|
| 224 | - switch (gettype($var)) { |
|
| 225 | - case 'boolean': |
|
| 226 | - return $var ? 'true' : 'false'; |
|
| 227 | - case 'NULL': |
|
| 228 | - return 'null'; |
|
| 229 | - case 'integer': |
|
| 230 | - return (int)$var; |
|
| 231 | - case 'double': |
|
| 232 | - case 'float': |
|
| 233 | - return (float)$var; |
|
| 234 | - case 'string': |
|
| 235 | - // STRINGS ARE EXPECTED TO BE IN ASCII OR UTF-8 FORMAT |
|
| 236 | - $ascii = ''; |
|
| 237 | - $strlen_var = mb_strlen($var); |
|
| 238 | - |
|
| 239 | - /* |
|
| 79 | + /** |
|
| 80 | + * constructs a new JSON instance |
|
| 81 | + * |
|
| 82 | + * @param int $use object behavior flags; combine with boolean-OR |
|
| 83 | + * |
|
| 84 | + * possible values: |
|
| 85 | + * - SERVICES_JSON_LOOSE_TYPE: loose typing. |
|
| 86 | + * "{...}" syntax creates associative arrays |
|
| 87 | + * instead of objects in decode(). |
|
| 88 | + * - SERVICES_JSON_SUPPRESS_ERRORS: error suppression. |
|
| 89 | + * Values which can't be encoded (e.g. resources) |
|
| 90 | + * appear as NULL instead of throwing errors. |
|
| 91 | + * By default, a deeply-nested resource will |
|
| 92 | + * bubble up with an error, so all return values |
|
| 93 | + * from encode() should be checked with isError() |
|
| 94 | + */ |
|
| 95 | + public function __construct($use = 0) |
|
| 96 | + { |
|
| 97 | + $this->use = $use; |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * convert a string from one UTF-16 char to one UTF-8 char |
|
| 102 | + * |
|
| 103 | + * Normally should be handled by mb_convert_encoding, but |
|
| 104 | + * provides a slower PHP-only method for installations |
|
| 105 | + * that lack the multibye string extension. |
|
| 106 | + * |
|
| 107 | + * @param string $utf16 UTF-16 character |
|
| 108 | + * @return string UTF-8 character |
|
| 109 | + */ |
|
| 110 | + public function utf162utf8($utf16): string |
|
| 111 | + { |
|
| 112 | + // oh please oh please oh please oh please oh please |
|
| 113 | + if (function_exists('mb_convert_encoding')) { |
|
| 114 | + return mb_convert_encoding($utf16, 'UTF-8', 'UTF-16'); |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + $bytes = (ord($utf16[0]) << 8) | ord($utf16[1]); |
|
| 118 | + |
|
| 119 | + switch (true) { |
|
| 120 | + case ((0x7F & $bytes) == $bytes): |
|
| 121 | + // this case should never be reached, because we are in ASCII range |
|
| 122 | + // see: https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
| 123 | + return chr(0x7F & $bytes); |
|
| 124 | + case (0x07FF & $bytes) == $bytes: |
|
| 125 | + // return a 2-byte UTF-8 character |
|
| 126 | + // see: https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
| 127 | + return chr(0xC0 | (($bytes >> 6) & 0x1F)) . chr(0x80 | ($bytes & 0x3F)); |
|
| 128 | + case (0xFFFF & $bytes) == $bytes: |
|
| 129 | + // return a 3-byte UTF-8 character |
|
| 130 | + // see: https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
| 131 | + return chr(0xE0 | (($bytes >> 12) & 0x0F)) . chr(0x80 | (($bytes >> 6) & 0x3F)) . chr(0x80 | ($bytes & 0x3F)); |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + // ignoring UTF-32 for now, sorry |
|
| 135 | + return ''; |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * convert a string from one UTF-8 char to one UTF-16 char |
|
| 140 | + * |
|
| 141 | + * Normally should be handled by mb_convert_encoding, but |
|
| 142 | + * provides a slower PHP-only method for installations |
|
| 143 | + * that lack the multibye string extension. |
|
| 144 | + * |
|
| 145 | + * @param string $utf8 UTF-8 character |
|
| 146 | + * @return string UTF-16 character |
|
| 147 | + */ |
|
| 148 | + public function utf82utf16($utf8): string |
|
| 149 | + { |
|
| 150 | + // oh please oh please oh please oh please oh please |
|
| 151 | + if (function_exists('mb_convert_encoding')) { |
|
| 152 | + return mb_convert_encoding($utf8, 'UTF-16', 'UTF-8'); |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + switch (mb_strlen($utf8)) { |
|
| 156 | + case 1: |
|
| 157 | + // this case should never be reached, because we are in ASCII range |
|
| 158 | + // see: https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
| 159 | + return $utf8; |
|
| 160 | + case 2: |
|
| 161 | + // return a UTF-16 character from a 2-byte UTF-8 char |
|
| 162 | + // see: https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
| 163 | + return chr(0x07 & (ord($utf8[0]) >> 2)) . chr((0xC0 & (ord($utf8[0]) << 6)) | (0x3F & ord($utf8[1]))); |
|
| 164 | + case 3: |
|
| 165 | + // return a UTF-16 character from a 3-byte UTF-8 char |
|
| 166 | + // see: https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
| 167 | + return chr((0xF0 & (ord($utf8[0]) << 4)) | (0x0F & (ord($utf8[1]) >> 2))) . chr((0xC0 & (ord($utf8[1]) << 6)) | (0x7F & ord($utf8[2]))); |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + // ignoring UTF-32 for now, sorry |
|
| 171 | + return ''; |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + /** |
|
| 175 | + * encodes an arbitrary variable into JSON format (and sends JSON Header) |
|
| 176 | + * |
|
| 177 | + * @param mixed $var any number, boolean, string, array, or object to be encoded. |
|
| 178 | + * see argument 1 to ServicesJSON() above for array-parsing behavior. |
|
| 179 | + * if var is a strng, note that encode() always expects it |
|
| 180 | + * to be in ASCII or UTF-8 format! |
|
| 181 | + * |
|
| 182 | + * @return mixed JSON string representation of input var or an error if a problem occurs |
|
| 183 | + */ |
|
| 184 | + public function encode($var) |
|
| 185 | + { |
|
| 186 | + header('Document-type: application/json'); |
|
| 187 | + |
|
| 188 | + return $this->encodeUnsafe($var); |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + /** |
|
| 192 | + * encodes an arbitrary variable into JSON format without JSON Header - warning - may allow CSS!!!!) |
|
| 193 | + * |
|
| 194 | + * @param mixed $var any number, boolean, string, array, or object to be encoded. |
|
| 195 | + * see argument 1 to ServicesJSON() above for array-parsing behavior. |
|
| 196 | + * if var is a strng, note that encode() always expects it |
|
| 197 | + * to be in ASCII or UTF-8 format! |
|
| 198 | + * |
|
| 199 | + * @return mixed JSON string representation of input var or an error if a problem occurs |
|
| 200 | + */ |
|
| 201 | + public function encodeUnsafe($var) |
|
| 202 | + { |
|
| 203 | + // see bug #16908 - regarding numeric locale printing |
|
| 204 | + $lc = setlocale(LC_NUMERIC, 0); |
|
| 205 | + setlocale(LC_NUMERIC, 'C'); |
|
| 206 | + $ret = $this->_encode($var); |
|
| 207 | + setlocale(LC_NUMERIC, $lc); |
|
| 208 | + |
|
| 209 | + return $ret; |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + /** |
|
| 213 | + * PRIVATE CODE that does the work of encodes an arbitrary variable into JSON format |
|
| 214 | + * |
|
| 215 | + * @param mixed $var any number, boolean, string, array, or object to be encoded. |
|
| 216 | + * see argument 1 to ServicesJSON() above for array-parsing behavior. |
|
| 217 | + * if var is a strng, note that encode() always expects it |
|
| 218 | + * to be in ASCII or UTF-8 format! |
|
| 219 | + * |
|
| 220 | + * @return mixed JSON string representation of input var or an error if a problem occurs |
|
| 221 | + */ |
|
| 222 | + public function _encode($var) |
|
| 223 | + { |
|
| 224 | + switch (gettype($var)) { |
|
| 225 | + case 'boolean': |
|
| 226 | + return $var ? 'true' : 'false'; |
|
| 227 | + case 'NULL': |
|
| 228 | + return 'null'; |
|
| 229 | + case 'integer': |
|
| 230 | + return (int)$var; |
|
| 231 | + case 'double': |
|
| 232 | + case 'float': |
|
| 233 | + return (float)$var; |
|
| 234 | + case 'string': |
|
| 235 | + // STRINGS ARE EXPECTED TO BE IN ASCII OR UTF-8 FORMAT |
|
| 236 | + $ascii = ''; |
|
| 237 | + $strlen_var = mb_strlen($var); |
|
| 238 | + |
|
| 239 | + /* |
|
| 240 | 240 | * Iterate over every character in the string, |
| 241 | 241 | * escaping with a slash or encoding to UTF-8 where necessary |
| 242 | 242 | */ |
| 243 | - for ($c = 0; $c < $strlen_var; ++$c) { |
|
| 244 | - $ord_var_c = ord($var[$c]); |
|
| 245 | - |
|
| 246 | - switch (true) { |
|
| 247 | - case 0x08 == $ord_var_c: |
|
| 248 | - $ascii .= '\b'; |
|
| 249 | - break; |
|
| 250 | - case 0x09 == $ord_var_c: |
|
| 251 | - $ascii .= '\t'; |
|
| 252 | - break; |
|
| 253 | - case 0x0A == $ord_var_c: |
|
| 254 | - $ascii .= '\n'; |
|
| 255 | - break; |
|
| 256 | - case 0x0C == $ord_var_c: |
|
| 257 | - $ascii .= '\f'; |
|
| 258 | - break; |
|
| 259 | - case 0x0D == $ord_var_c: |
|
| 260 | - $ascii .= '\r'; |
|
| 261 | - break; |
|
| 262 | - case 0x22 == $ord_var_c: |
|
| 263 | - case 0x2F == $ord_var_c: |
|
| 264 | - case 0x5C == $ord_var_c: |
|
| 265 | - // double quote, slash, slosh |
|
| 266 | - $ascii .= '\\' . $var[$c]; |
|
| 267 | - break; |
|
| 268 | - case (($ord_var_c >= 0x20) && ($ord_var_c <= 0x7F)): |
|
| 269 | - // characters U-00000000 - U-0000007F (same as ASCII) |
|
| 270 | - $ascii .= $var[$c]; |
|
| 271 | - break; |
|
| 272 | - case (0xC0 == ($ord_var_c & 0xE0)): |
|
| 273 | - // characters U-00000080 - U-000007FF, mask 110SONGLIST |
|
| 274 | - // see https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
| 275 | - if ($c + 1 >= $strlen_var) { |
|
| 276 | - ++$c; |
|
| 277 | - $ascii .= '?'; |
|
| 278 | - break; |
|
| 279 | - } |
|
| 280 | - |
|
| 281 | - $char = pack('C*', $ord_var_c, ord($var[$c + 1])); |
|
| 282 | - ++$c; |
|
| 283 | - $utf16 = $this->utf82utf16($char); |
|
| 284 | - $ascii .= sprintf('\u%04s', bin2hex($utf16)); |
|
| 285 | - break; |
|
| 286 | - case (0xE0 == ($ord_var_c & 0xF0)): |
|
| 287 | - if ($c + 2 >= $strlen_var) { |
|
| 288 | - $c += 2; |
|
| 289 | - $ascii .= '?'; |
|
| 290 | - break; |
|
| 291 | - } |
|
| 292 | - // characters U-00000800 - U-0000FFFF, mask 1110XXXX |
|
| 293 | - // see https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
| 294 | - $char = pack('C*', $ord_var_c, @ord($var[$c + 1]), @ord($var[$c + 2])); |
|
| 295 | - $c += 2; |
|
| 296 | - $utf16 = $this->utf82utf16($char); |
|
| 297 | - $ascii .= sprintf('\u%04s', bin2hex($utf16)); |
|
| 298 | - break; |
|
| 299 | - case (0xF0 == ($ord_var_c & 0xF8)): |
|
| 300 | - if ($c + 3 >= $strlen_var) { |
|
| 301 | - $c += 3; |
|
| 302 | - $ascii .= '?'; |
|
| 303 | - break; |
|
| 304 | - } |
|
| 305 | - // characters U-00010000 - U-001FFFFF, mask 11110XXX |
|
| 306 | - // see https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
| 307 | - $char = pack('C*', $ord_var_c, ord($var[$c + 1]), ord($var[$c + 2]), ord($var[$c + 3])); |
|
| 308 | - $c += 3; |
|
| 309 | - $utf16 = $this->utf82utf16($char); |
|
| 310 | - $ascii .= sprintf('\u%04s', bin2hex($utf16)); |
|
| 311 | - break; |
|
| 312 | - case (0xF8 == ($ord_var_c & 0xFC)): |
|
| 313 | - // characters U-00200000 - U-03FFFFFF, mask 111110XX |
|
| 314 | - // see https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
| 315 | - if ($c + 4 >= $strlen_var) { |
|
| 316 | - $c += 4; |
|
| 317 | - $ascii .= '?'; |
|
| 318 | - break; |
|
| 319 | - } |
|
| 320 | - $char = pack('C*', $ord_var_c, ord($var[$c + 1]), ord($var[$c + 2]), ord($var[$c + 3]), ord($var[$c + 4])); |
|
| 321 | - $c += 4; |
|
| 322 | - $utf16 = $this->utf82utf16($char); |
|
| 323 | - $ascii .= sprintf('\u%04s', bin2hex($utf16)); |
|
| 324 | - break; |
|
| 325 | - case (0xFC == ($ord_var_c & 0xFE)): |
|
| 326 | - if ($c + 5 >= $strlen_var) { |
|
| 327 | - $c += 5; |
|
| 328 | - $ascii .= '?'; |
|
| 329 | - break; |
|
| 330 | - } |
|
| 331 | - // characters U-04000000 - U-7FFFFFFF, mask 1111110X |
|
| 332 | - // see https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
| 333 | - $char = pack('C*', $ord_var_c, ord($var[$c + 1]), ord($var[$c + 2]), ord($var[$c + 3]), ord($var[$c + 4]), ord($var[$c + 5])); |
|
| 334 | - $c += 5; |
|
| 335 | - $utf16 = $this->utf82utf16($char); |
|
| 336 | - $ascii .= sprintf('\u%04s', bin2hex($utf16)); |
|
| 337 | - break; |
|
| 338 | - } |
|
| 339 | - } |
|
| 340 | - |
|
| 341 | - return '"' . $ascii . '"'; |
|
| 342 | - case 'array': |
|
| 343 | - /* |
|
| 243 | + for ($c = 0; $c < $strlen_var; ++$c) { |
|
| 244 | + $ord_var_c = ord($var[$c]); |
|
| 245 | + |
|
| 246 | + switch (true) { |
|
| 247 | + case 0x08 == $ord_var_c: |
|
| 248 | + $ascii .= '\b'; |
|
| 249 | + break; |
|
| 250 | + case 0x09 == $ord_var_c: |
|
| 251 | + $ascii .= '\t'; |
|
| 252 | + break; |
|
| 253 | + case 0x0A == $ord_var_c: |
|
| 254 | + $ascii .= '\n'; |
|
| 255 | + break; |
|
| 256 | + case 0x0C == $ord_var_c: |
|
| 257 | + $ascii .= '\f'; |
|
| 258 | + break; |
|
| 259 | + case 0x0D == $ord_var_c: |
|
| 260 | + $ascii .= '\r'; |
|
| 261 | + break; |
|
| 262 | + case 0x22 == $ord_var_c: |
|
| 263 | + case 0x2F == $ord_var_c: |
|
| 264 | + case 0x5C == $ord_var_c: |
|
| 265 | + // double quote, slash, slosh |
|
| 266 | + $ascii .= '\\' . $var[$c]; |
|
| 267 | + break; |
|
| 268 | + case (($ord_var_c >= 0x20) && ($ord_var_c <= 0x7F)): |
|
| 269 | + // characters U-00000000 - U-0000007F (same as ASCII) |
|
| 270 | + $ascii .= $var[$c]; |
|
| 271 | + break; |
|
| 272 | + case (0xC0 == ($ord_var_c & 0xE0)): |
|
| 273 | + // characters U-00000080 - U-000007FF, mask 110SONGLIST |
|
| 274 | + // see https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
| 275 | + if ($c + 1 >= $strlen_var) { |
|
| 276 | + ++$c; |
|
| 277 | + $ascii .= '?'; |
|
| 278 | + break; |
|
| 279 | + } |
|
| 280 | + |
|
| 281 | + $char = pack('C*', $ord_var_c, ord($var[$c + 1])); |
|
| 282 | + ++$c; |
|
| 283 | + $utf16 = $this->utf82utf16($char); |
|
| 284 | + $ascii .= sprintf('\u%04s', bin2hex($utf16)); |
|
| 285 | + break; |
|
| 286 | + case (0xE0 == ($ord_var_c & 0xF0)): |
|
| 287 | + if ($c + 2 >= $strlen_var) { |
|
| 288 | + $c += 2; |
|
| 289 | + $ascii .= '?'; |
|
| 290 | + break; |
|
| 291 | + } |
|
| 292 | + // characters U-00000800 - U-0000FFFF, mask 1110XXXX |
|
| 293 | + // see https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
| 294 | + $char = pack('C*', $ord_var_c, @ord($var[$c + 1]), @ord($var[$c + 2])); |
|
| 295 | + $c += 2; |
|
| 296 | + $utf16 = $this->utf82utf16($char); |
|
| 297 | + $ascii .= sprintf('\u%04s', bin2hex($utf16)); |
|
| 298 | + break; |
|
| 299 | + case (0xF0 == ($ord_var_c & 0xF8)): |
|
| 300 | + if ($c + 3 >= $strlen_var) { |
|
| 301 | + $c += 3; |
|
| 302 | + $ascii .= '?'; |
|
| 303 | + break; |
|
| 304 | + } |
|
| 305 | + // characters U-00010000 - U-001FFFFF, mask 11110XXX |
|
| 306 | + // see https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
| 307 | + $char = pack('C*', $ord_var_c, ord($var[$c + 1]), ord($var[$c + 2]), ord($var[$c + 3])); |
|
| 308 | + $c += 3; |
|
| 309 | + $utf16 = $this->utf82utf16($char); |
|
| 310 | + $ascii .= sprintf('\u%04s', bin2hex($utf16)); |
|
| 311 | + break; |
|
| 312 | + case (0xF8 == ($ord_var_c & 0xFC)): |
|
| 313 | + // characters U-00200000 - U-03FFFFFF, mask 111110XX |
|
| 314 | + // see https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
| 315 | + if ($c + 4 >= $strlen_var) { |
|
| 316 | + $c += 4; |
|
| 317 | + $ascii .= '?'; |
|
| 318 | + break; |
|
| 319 | + } |
|
| 320 | + $char = pack('C*', $ord_var_c, ord($var[$c + 1]), ord($var[$c + 2]), ord($var[$c + 3]), ord($var[$c + 4])); |
|
| 321 | + $c += 4; |
|
| 322 | + $utf16 = $this->utf82utf16($char); |
|
| 323 | + $ascii .= sprintf('\u%04s', bin2hex($utf16)); |
|
| 324 | + break; |
|
| 325 | + case (0xFC == ($ord_var_c & 0xFE)): |
|
| 326 | + if ($c + 5 >= $strlen_var) { |
|
| 327 | + $c += 5; |
|
| 328 | + $ascii .= '?'; |
|
| 329 | + break; |
|
| 330 | + } |
|
| 331 | + // characters U-04000000 - U-7FFFFFFF, mask 1111110X |
|
| 332 | + // see https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
| 333 | + $char = pack('C*', $ord_var_c, ord($var[$c + 1]), ord($var[$c + 2]), ord($var[$c + 3]), ord($var[$c + 4]), ord($var[$c + 5])); |
|
| 334 | + $c += 5; |
|
| 335 | + $utf16 = $this->utf82utf16($char); |
|
| 336 | + $ascii .= sprintf('\u%04s', bin2hex($utf16)); |
|
| 337 | + break; |
|
| 338 | + } |
|
| 339 | + } |
|
| 340 | + |
|
| 341 | + return '"' . $ascii . '"'; |
|
| 342 | + case 'array': |
|
| 343 | + /* |
|
| 344 | 344 | * As per JSON spec if any array key is not an integer |
| 345 | 345 | * we must treat the the whole array as an object. We |
| 346 | 346 | * also try to catch a sparsely populated associative |
@@ -358,422 +358,422 @@ discard block |
||
| 358 | 358 | * bracket notation. |
| 359 | 359 | */ |
| 360 | 360 | |
| 361 | - // treat as a JSON object |
|
| 362 | - if (is_array($var) && count($var) && (array_keys($var) !== range(0, count($var) - 1))) { |
|
| 363 | - $properties = array_map([$this, 'name_value'], array_keys($var), array_values($var)); |
|
| 364 | - |
|
| 365 | - foreach ($properties as $property) { |
|
| 366 | - if ($this->isError($property)) { |
|
| 367 | - return $property; |
|
| 368 | - } |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - return '{' . implode(',', $properties) . '}'; |
|
| 372 | - } |
|
| 373 | - |
|
| 374 | - // treat it like a regular array |
|
| 375 | - $elements = array_map([$this, '_encode'], $var); |
|
| 376 | - |
|
| 377 | - foreach ($elements as $element) { |
|
| 378 | - if ($this->isError($element)) { |
|
| 379 | - return $element; |
|
| 380 | - } |
|
| 381 | - } |
|
| 382 | - |
|
| 383 | - return '[' . implode(',', $elements) . ']'; |
|
| 384 | - case 'object': |
|
| 385 | - $vars = get_object_vars($var); |
|
| 386 | - |
|
| 387 | - $properties = array_map([$this, 'name_value'], array_keys($vars), array_values($vars)); |
|
| 388 | - |
|
| 389 | - foreach ($properties as $property) { |
|
| 390 | - if ($this->isError($property)) { |
|
| 391 | - return $property; |
|
| 392 | - } |
|
| 393 | - } |
|
| 394 | - |
|
| 395 | - return '{' . implode(',', $properties) . '}'; |
|
| 396 | - default: |
|
| 397 | - return ($this->use & SERVICES_JSON_SUPPRESS_ERRORS) ? 'null' : new ServicesJSON_Error(gettype($var) . ' can not be encoded as JSON string'); |
|
| 398 | - } |
|
| 399 | - } |
|
| 400 | - |
|
| 401 | - /** |
|
| 402 | - * array-walking function for use in generating JSON-formatted name-value pairs |
|
| 403 | - * |
|
| 404 | - * @param string $name name of key to use |
|
| 405 | - * @param mixed $value reference to an array element to be encoded |
|
| 406 | - * |
|
| 407 | - * @return string JSON-formatted name-value pair, like '"name":value' |
|
| 408 | - */ |
|
| 409 | - public function name_value($name, $value) |
|
| 410 | - { |
|
| 411 | - $encoded_value = $this->_encode($value); |
|
| 412 | - |
|
| 413 | - if ($this->isError($encoded_value)) { |
|
| 414 | - return $encoded_value; |
|
| 415 | - } |
|
| 416 | - |
|
| 417 | - return $this->_encode((string)$name) . ':' . $encoded_value; |
|
| 418 | - } |
|
| 419 | - |
|
| 420 | - /** |
|
| 421 | - * reduce a string by removing leading and trailing comments and whitespace |
|
| 422 | - * |
|
| 423 | - * @param string $str string value to strip of comments and whitespace |
|
| 424 | - * |
|
| 425 | - * @return string string value stripped of comments and whitespace |
|
| 426 | - */ |
|
| 427 | - public function reduce_string($str): string |
|
| 428 | - { |
|
| 429 | - $str = preg_replace( |
|
| 430 | - [ |
|
| 431 | - // eliminate single line comments in '// ...' form |
|
| 432 | - '#^\s*//(.+)$#m', |
|
| 433 | - |
|
| 434 | - // eliminate multi-line comments in '/* ... */' form, at start of string |
|
| 435 | - '#^\s*/\*(.+)\*/#Us', |
|
| 436 | - |
|
| 437 | - // eliminate multi-line comments in '/* ... */' form, at end of string |
|
| 438 | - '#/\*(.+)\*/\s*$#Us', |
|
| 439 | - ], |
|
| 440 | - '', |
|
| 441 | - $str |
|
| 442 | - ); |
|
| 443 | - |
|
| 444 | - // eliminate extraneous space |
|
| 445 | - return trim($str); |
|
| 446 | - } |
|
| 447 | - |
|
| 448 | - /** |
|
| 449 | - * decodes a JSON string into appropriate variable |
|
| 450 | - * |
|
| 451 | - * @param string $str JSON-formatted string |
|
| 452 | - * |
|
| 453 | - * @return array|bool|float|int|\stdClass|string|void|null number, boolean, string, array, or object |
|
| 454 | - * corresponding to given JSON input string. |
|
| 455 | - * See argument 1 to ServicesJSON() above for object-output behavior. |
|
| 456 | - * Note that decode() always returns strings |
|
| 457 | - * in ASCII or UTF-8 format! |
|
| 458 | - */ |
|
| 459 | - public function decode($str) |
|
| 460 | - { |
|
| 461 | - $str = $this->reduce_string($str); |
|
| 462 | - |
|
| 463 | - switch (mb_strtolower($str)) { |
|
| 464 | - case 'true': |
|
| 465 | - return true; |
|
| 466 | - case 'false': |
|
| 467 | - return false; |
|
| 468 | - case 'null': |
|
| 469 | - return null; |
|
| 470 | - default: |
|
| 471 | - $m = []; |
|
| 472 | - |
|
| 473 | - if (is_numeric($str)) { |
|
| 474 | - // Lookie-loo, it's a number |
|
| 475 | - |
|
| 476 | - // This would work on its own, but I'm trying to be |
|
| 477 | - // good about returning integers where appropriate: |
|
| 478 | - // return (float)$str; |
|
| 479 | - |
|
| 480 | - // Return float or int, as appropriate |
|
| 481 | - return ((float)$str == (int)$str) ? (int)$str : (float)$str; |
|
| 482 | - } |
|
| 483 | - |
|
| 484 | - if (preg_match('/^("|\').*(\1)$/s', $str, $m) && $m[1] == $m[2]) { |
|
| 485 | - // STRINGS RETURNED IN UTF-8 FORMAT |
|
| 486 | - $delim = mb_substr($str, 0, 1); |
|
| 487 | - $chrs = mb_substr($str, 1, -1); |
|
| 488 | - $utf8 = ''; |
|
| 489 | - $strlen_chrs = mb_strlen($chrs); |
|
| 490 | - |
|
| 491 | - for ($c = 0; $c < $strlen_chrs; ++$c) { |
|
| 492 | - $substr_chrs_c_2 = mb_substr($chrs, $c, 2); |
|
| 493 | - $ord_chrs_c = ord($chrs[$c]); |
|
| 494 | - |
|
| 495 | - switch (true) { |
|
| 496 | - case '\b' === $substr_chrs_c_2: |
|
| 497 | - $utf8 .= chr(0x08); |
|
| 498 | - ++$c; |
|
| 499 | - break; |
|
| 500 | - case '\t' === $substr_chrs_c_2: |
|
| 501 | - $utf8 .= chr(0x09); |
|
| 502 | - ++$c; |
|
| 503 | - break; |
|
| 504 | - case '\n' === $substr_chrs_c_2: |
|
| 505 | - $utf8 .= chr(0x0A); |
|
| 506 | - ++$c; |
|
| 507 | - break; |
|
| 508 | - case '\f' === $substr_chrs_c_2: |
|
| 509 | - $utf8 .= chr(0x0C); |
|
| 510 | - ++$c; |
|
| 511 | - break; |
|
| 512 | - case '\r' === $substr_chrs_c_2: |
|
| 513 | - $utf8 .= chr(0x0D); |
|
| 514 | - ++$c; |
|
| 515 | - break; |
|
| 516 | - case '\\"' === $substr_chrs_c_2: |
|
| 517 | - case '\\\'' === $substr_chrs_c_2: |
|
| 518 | - case '\\\\' === $substr_chrs_c_2: |
|
| 519 | - case '\\/' === $substr_chrs_c_2: |
|
| 520 | - if (('"' === $delim && '\\\'' !== $substr_chrs_c_2) |
|
| 521 | - || ("'" === $delim && '\\"' !== $substr_chrs_c_2)) { |
|
| 522 | - $utf8 .= $chrs[++$c]; |
|
| 523 | - } |
|
| 524 | - break; |
|
| 525 | - case preg_match('/\\\u[0-9A-F]{4}/i', mb_substr($chrs, $c, 6)): |
|
| 526 | - // single, escaped unicode character |
|
| 527 | - $utf16 = chr(hexdec(mb_substr($chrs, $c + 2, 2))) . chr(hexdec(mb_substr($chrs, $c + 4, 2))); |
|
| 528 | - $utf8 .= $this->utf162utf8($utf16); |
|
| 529 | - $c += 5; |
|
| 530 | - break; |
|
| 531 | - case ($ord_chrs_c >= 0x20) && ($ord_chrs_c <= 0x7F): |
|
| 532 | - $utf8 .= $chrs[$c]; |
|
| 533 | - break; |
|
| 534 | - case 0xC0 == ($ord_chrs_c & 0xE0): |
|
| 535 | - // characters U-00000080 - U-000007FF, mask 110SONGLIST |
|
| 536 | - //see https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
| 537 | - $utf8 .= mb_substr($chrs, $c, 2); |
|
| 538 | - ++$c; |
|
| 539 | - break; |
|
| 540 | - case 0xE0 == ($ord_chrs_c & 0xF0): |
|
| 541 | - // characters U-00000800 - U-0000FFFF, mask 1110XXXX |
|
| 542 | - // see https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
| 543 | - $utf8 .= mb_substr($chrs, $c, 3); |
|
| 544 | - $c += 2; |
|
| 545 | - break; |
|
| 546 | - case 0xF0 == ($ord_chrs_c & 0xF8): |
|
| 547 | - // characters U-00010000 - U-001FFFFF, mask 11110XXX |
|
| 548 | - // see https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
| 549 | - $utf8 .= mb_substr($chrs, $c, 4); |
|
| 550 | - $c += 3; |
|
| 551 | - break; |
|
| 552 | - case 0xF8 == ($ord_chrs_c & 0xFC): |
|
| 553 | - // characters U-00200000 - U-03FFFFFF, mask 111110XX |
|
| 554 | - // see https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
| 555 | - $utf8 .= mb_substr($chrs, $c, 5); |
|
| 556 | - $c += 4; |
|
| 557 | - break; |
|
| 558 | - case 0xFC == ($ord_chrs_c & 0xFE): |
|
| 559 | - // characters U-04000000 - U-7FFFFFFF, mask 1111110X |
|
| 560 | - // see https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
| 561 | - $utf8 .= mb_substr($chrs, $c, 6); |
|
| 562 | - $c += 5; |
|
| 563 | - break; |
|
| 564 | - } |
|
| 565 | - } |
|
| 566 | - |
|
| 567 | - return $utf8; |
|
| 568 | - } |
|
| 569 | - |
|
| 570 | - if (preg_match('/^\[.*\]$/s', $str) || preg_match('/^\{.*\}$/s', $str)) { |
|
| 571 | - // array, or object notation |
|
| 572 | - |
|
| 573 | - if ('[' === $str[0]) { |
|
| 574 | - $stk = [SERVICES_JSON_IN_ARR]; |
|
| 575 | - $arr = []; |
|
| 576 | - } elseif ($this->use & SERVICES_JSON_LOOSE_TYPE) { |
|
| 577 | - $stk = [SERVICES_JSON_IN_OBJ]; |
|
| 578 | - $obj = []; |
|
| 579 | - } else { |
|
| 580 | - $stk = [SERVICES_JSON_IN_OBJ]; |
|
| 581 | - $obj = new stdClass(); |
|
| 582 | - } |
|
| 583 | - |
|
| 584 | - array_push( |
|
| 585 | - $stk, |
|
| 586 | - [ |
|
| 587 | - 'what' => SERVICES_JSON_SLICE, |
|
| 588 | - 'where' => 0, |
|
| 589 | - 'delim' => false, |
|
| 590 | - ] |
|
| 591 | - ); |
|
| 592 | - |
|
| 593 | - $chrs = mb_substr($str, 1, -1); |
|
| 594 | - $chrs = $this->reduce_string($chrs); |
|
| 595 | - |
|
| 596 | - if ('' == $chrs) { |
|
| 597 | - if (SERVICES_JSON_IN_ARR == reset($stk)) { |
|
| 598 | - return $arr; |
|
| 599 | - } |
|
| 600 | - |
|
| 601 | - return $obj; |
|
| 602 | - } |
|
| 603 | - |
|
| 604 | - //print("\nparsing {$chrs}\n"); |
|
| 605 | - |
|
| 606 | - $strlen_chrs = mb_strlen($chrs); |
|
| 607 | - |
|
| 608 | - for ($c = 0; $c <= $strlen_chrs; ++$c) { |
|
| 609 | - $top = end($stk); |
|
| 610 | - $substr_chrs_c_2 = mb_substr($chrs, $c, 2); |
|
| 611 | - |
|
| 612 | - if (($c == $strlen_chrs) || ((',' === $chrs[$c]) && (SERVICES_JSON_SLICE == $top['what']))) { |
|
| 613 | - // found a comma that is not inside a string, array, etc., |
|
| 614 | - // OR we've reached the end of the character list |
|
| 615 | - $slice = mb_substr($chrs, $top['where'], $c - $top['where']); |
|
| 616 | - array_push($stk, ['what' => SERVICES_JSON_SLICE, 'where' => $c + 1, 'delim' => false]); |
|
| 617 | - //print("Found split at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n"); |
|
| 618 | - |
|
| 619 | - if (SERVICES_JSON_IN_ARR == reset($stk)) { |
|
| 620 | - // we are in an array, so just push an element onto the stack |
|
| 621 | - $arr[] = $this->decode($slice); |
|
| 622 | - } elseif (SERVICES_JSON_IN_OBJ == reset($stk)) { |
|
| 623 | - // we are in an object, so figure |
|
| 624 | - // out the property name and set an |
|
| 625 | - // element in an associative array, |
|
| 626 | - // for now |
|
| 627 | - $parts = []; |
|
| 628 | - |
|
| 629 | - if (preg_match('/^\s*(["\'].*[^\\\]["\'])\s*:\s*(\S.*),?$/Uis', $slice, $parts)) { |
|
| 630 | - // "name":value pair |
|
| 631 | - $key = $this->decode($parts[1]); |
|
| 632 | - $val = $this->decode($parts[2]); |
|
| 633 | - |
|
| 634 | - if ($this->use & SERVICES_JSON_LOOSE_TYPE) { |
|
| 635 | - $obj[$key] = $val; |
|
| 636 | - } else { |
|
| 637 | - $obj->$key = $val; |
|
| 638 | - } |
|
| 639 | - } elseif (preg_match('/^\s*(\w+)\s*:\s*(\S.*),?$/Uis', $slice, $parts)) { |
|
| 640 | - // name:value pair, where name is unquoted |
|
| 641 | - $key = $parts[1]; |
|
| 642 | - $val = $this->decode($parts[2]); |
|
| 643 | - |
|
| 644 | - if ($this->use & SERVICES_JSON_LOOSE_TYPE) { |
|
| 645 | - $obj[$key] = $val; |
|
| 646 | - } else { |
|
| 647 | - $obj->$key = $val; |
|
| 648 | - } |
|
| 649 | - } |
|
| 650 | - } |
|
| 651 | - } elseif ((('"' === $chrs[$c]) || ("'" === $chrs[$c])) && (SERVICES_JSON_IN_STR != $top['what'])) { |
|
| 652 | - // found a quote, and we are not inside a string |
|
| 653 | - array_push($stk, ['what' => SERVICES_JSON_IN_STR, 'where' => $c, 'delim' => $chrs[$c]]); |
|
| 654 | - //print("Found start of string at {$c}\n"); |
|
| 655 | - } elseif (($chrs[$c] == $top['delim']) |
|
| 656 | - && (SERVICES_JSON_IN_STR == $top['what']) |
|
| 657 | - && (1 != (mb_strlen(mb_substr($chrs, 0, $c)) - mb_strlen(rtrim(mb_substr($chrs, 0, $c), '\\'))) % 2)) { |
|
| 658 | - // found a quote, we're in a string, and it's not escaped |
|
| 659 | - // we know that it's not escaped becase there is _not_ an |
|
| 660 | - // odd number of backslashes at the end of the string so far |
|
| 661 | - array_pop($stk); |
|
| 662 | - //print("Found end of string at {$c}: ".substr($chrs, $top['where'], (1 + 1 + $c - $top['where']))."\n"); |
|
| 663 | - } elseif (('[' === $chrs[$c]) |
|
| 664 | - && in_array($top['what'], [SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ], true)) { |
|
| 665 | - // found a left-bracket, and we are in an array, object, or slice |
|
| 666 | - array_push($stk, ['what' => SERVICES_JSON_IN_ARR, 'where' => $c, 'delim' => false]); |
|
| 667 | - //print("Found start of array at {$c}\n"); |
|
| 668 | - } elseif ((']' === $chrs[$c]) && (SERVICES_JSON_IN_ARR == $top['what'])) { |
|
| 669 | - // found a right-bracket, and we're in an array |
|
| 670 | - array_pop($stk); |
|
| 671 | - //print("Found end of array at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n"); |
|
| 672 | - } elseif (('{' === $chrs[$c]) |
|
| 673 | - && in_array($top['what'], [SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ], true)) { |
|
| 674 | - // found a left-brace, and we are in an array, object, or slice |
|
| 675 | - array_push($stk, ['what' => SERVICES_JSON_IN_OBJ, 'where' => $c, 'delim' => false]); |
|
| 676 | - //print("Found start of object at {$c}\n"); |
|
| 677 | - } elseif (('}' === $chrs[$c]) && (SERVICES_JSON_IN_OBJ == $top['what'])) { |
|
| 678 | - // found a right-brace, and we're in an object |
|
| 679 | - array_pop($stk); |
|
| 680 | - //print("Found end of object at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n"); |
|
| 681 | - } elseif (('/*' === $substr_chrs_c_2) |
|
| 682 | - && in_array($top['what'], [SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ], true)) { |
|
| 683 | - // found a comment start, and we are in an array, object, or slice |
|
| 684 | - array_push($stk, ['what' => SERVICES_JSON_IN_CMT, 'where' => $c, 'delim' => false]); |
|
| 685 | - ++$c; |
|
| 686 | - //print("Found start of comment at {$c}\n"); |
|
| 687 | - } elseif (('*/' === $substr_chrs_c_2) && (SERVICES_JSON_IN_CMT == $top['what'])) { |
|
| 688 | - // found a comment end, and we're in one now |
|
| 689 | - array_pop($stk); |
|
| 690 | - ++$c; |
|
| 691 | - |
|
| 692 | - for ($i = $top['where']; $i <= $c; ++$i) { |
|
| 693 | - $chrs = substr_replace($chrs, ' ', $i, 1); |
|
| 694 | - } |
|
| 695 | - //print("Found end of comment at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n"); |
|
| 696 | - } |
|
| 697 | - } |
|
| 698 | - |
|
| 699 | - if (SERVICES_JSON_IN_ARR == reset($stk)) { |
|
| 700 | - return $arr; |
|
| 701 | - } |
|
| 702 | - |
|
| 703 | - if (SERVICES_JSON_IN_OBJ == reset($stk)) { |
|
| 704 | - return $obj; |
|
| 705 | - } |
|
| 706 | - } |
|
| 707 | - } |
|
| 708 | - } |
|
| 709 | - |
|
| 710 | - /** |
|
| 711 | - * @param $data |
|
| 712 | - * @param null $code |
|
| 713 | - * @return bool |
|
| 714 | - * @todo Ultimately, this should just call PEAR::isError() |
|
| 715 | - */ |
|
| 716 | - public function isError($data, $code = null): bool |
|
| 717 | - { |
|
| 718 | - if (class_exists('pear')) { |
|
| 719 | - return PEAR::isError($data, $code); |
|
| 720 | - } |
|
| 721 | - |
|
| 722 | - if (is_object($data) |
|
| 723 | - && ($data instanceof \services_json_error |
|
| 724 | - || $data instanceof \services_json_error)) { |
|
| 725 | - return true; |
|
| 726 | - } |
|
| 727 | - |
|
| 728 | - return false; |
|
| 729 | - } |
|
| 361 | + // treat as a JSON object |
|
| 362 | + if (is_array($var) && count($var) && (array_keys($var) !== range(0, count($var) - 1))) { |
|
| 363 | + $properties = array_map([$this, 'name_value'], array_keys($var), array_values($var)); |
|
| 364 | + |
|
| 365 | + foreach ($properties as $property) { |
|
| 366 | + if ($this->isError($property)) { |
|
| 367 | + return $property; |
|
| 368 | + } |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + return '{' . implode(',', $properties) . '}'; |
|
| 372 | + } |
|
| 373 | + |
|
| 374 | + // treat it like a regular array |
|
| 375 | + $elements = array_map([$this, '_encode'], $var); |
|
| 376 | + |
|
| 377 | + foreach ($elements as $element) { |
|
| 378 | + if ($this->isError($element)) { |
|
| 379 | + return $element; |
|
| 380 | + } |
|
| 381 | + } |
|
| 382 | + |
|
| 383 | + return '[' . implode(',', $elements) . ']'; |
|
| 384 | + case 'object': |
|
| 385 | + $vars = get_object_vars($var); |
|
| 386 | + |
|
| 387 | + $properties = array_map([$this, 'name_value'], array_keys($vars), array_values($vars)); |
|
| 388 | + |
|
| 389 | + foreach ($properties as $property) { |
|
| 390 | + if ($this->isError($property)) { |
|
| 391 | + return $property; |
|
| 392 | + } |
|
| 393 | + } |
|
| 394 | + |
|
| 395 | + return '{' . implode(',', $properties) . '}'; |
|
| 396 | + default: |
|
| 397 | + return ($this->use & SERVICES_JSON_SUPPRESS_ERRORS) ? 'null' : new ServicesJSON_Error(gettype($var) . ' can not be encoded as JSON string'); |
|
| 398 | + } |
|
| 399 | + } |
|
| 400 | + |
|
| 401 | + /** |
|
| 402 | + * array-walking function for use in generating JSON-formatted name-value pairs |
|
| 403 | + * |
|
| 404 | + * @param string $name name of key to use |
|
| 405 | + * @param mixed $value reference to an array element to be encoded |
|
| 406 | + * |
|
| 407 | + * @return string JSON-formatted name-value pair, like '"name":value' |
|
| 408 | + */ |
|
| 409 | + public function name_value($name, $value) |
|
| 410 | + { |
|
| 411 | + $encoded_value = $this->_encode($value); |
|
| 412 | + |
|
| 413 | + if ($this->isError($encoded_value)) { |
|
| 414 | + return $encoded_value; |
|
| 415 | + } |
|
| 416 | + |
|
| 417 | + return $this->_encode((string)$name) . ':' . $encoded_value; |
|
| 418 | + } |
|
| 419 | + |
|
| 420 | + /** |
|
| 421 | + * reduce a string by removing leading and trailing comments and whitespace |
|
| 422 | + * |
|
| 423 | + * @param string $str string value to strip of comments and whitespace |
|
| 424 | + * |
|
| 425 | + * @return string string value stripped of comments and whitespace |
|
| 426 | + */ |
|
| 427 | + public function reduce_string($str): string |
|
| 428 | + { |
|
| 429 | + $str = preg_replace( |
|
| 430 | + [ |
|
| 431 | + // eliminate single line comments in '// ...' form |
|
| 432 | + '#^\s*//(.+)$#m', |
|
| 433 | + |
|
| 434 | + // eliminate multi-line comments in '/* ... */' form, at start of string |
|
| 435 | + '#^\s*/\*(.+)\*/#Us', |
|
| 436 | + |
|
| 437 | + // eliminate multi-line comments in '/* ... */' form, at end of string |
|
| 438 | + '#/\*(.+)\*/\s*$#Us', |
|
| 439 | + ], |
|
| 440 | + '', |
|
| 441 | + $str |
|
| 442 | + ); |
|
| 443 | + |
|
| 444 | + // eliminate extraneous space |
|
| 445 | + return trim($str); |
|
| 446 | + } |
|
| 447 | + |
|
| 448 | + /** |
|
| 449 | + * decodes a JSON string into appropriate variable |
|
| 450 | + * |
|
| 451 | + * @param string $str JSON-formatted string |
|
| 452 | + * |
|
| 453 | + * @return array|bool|float|int|\stdClass|string|void|null number, boolean, string, array, or object |
|
| 454 | + * corresponding to given JSON input string. |
|
| 455 | + * See argument 1 to ServicesJSON() above for object-output behavior. |
|
| 456 | + * Note that decode() always returns strings |
|
| 457 | + * in ASCII or UTF-8 format! |
|
| 458 | + */ |
|
| 459 | + public function decode($str) |
|
| 460 | + { |
|
| 461 | + $str = $this->reduce_string($str); |
|
| 462 | + |
|
| 463 | + switch (mb_strtolower($str)) { |
|
| 464 | + case 'true': |
|
| 465 | + return true; |
|
| 466 | + case 'false': |
|
| 467 | + return false; |
|
| 468 | + case 'null': |
|
| 469 | + return null; |
|
| 470 | + default: |
|
| 471 | + $m = []; |
|
| 472 | + |
|
| 473 | + if (is_numeric($str)) { |
|
| 474 | + // Lookie-loo, it's a number |
|
| 475 | + |
|
| 476 | + // This would work on its own, but I'm trying to be |
|
| 477 | + // good about returning integers where appropriate: |
|
| 478 | + // return (float)$str; |
|
| 479 | + |
|
| 480 | + // Return float or int, as appropriate |
|
| 481 | + return ((float)$str == (int)$str) ? (int)$str : (float)$str; |
|
| 482 | + } |
|
| 483 | + |
|
| 484 | + if (preg_match('/^("|\').*(\1)$/s', $str, $m) && $m[1] == $m[2]) { |
|
| 485 | + // STRINGS RETURNED IN UTF-8 FORMAT |
|
| 486 | + $delim = mb_substr($str, 0, 1); |
|
| 487 | + $chrs = mb_substr($str, 1, -1); |
|
| 488 | + $utf8 = ''; |
|
| 489 | + $strlen_chrs = mb_strlen($chrs); |
|
| 490 | + |
|
| 491 | + for ($c = 0; $c < $strlen_chrs; ++$c) { |
|
| 492 | + $substr_chrs_c_2 = mb_substr($chrs, $c, 2); |
|
| 493 | + $ord_chrs_c = ord($chrs[$c]); |
|
| 494 | + |
|
| 495 | + switch (true) { |
|
| 496 | + case '\b' === $substr_chrs_c_2: |
|
| 497 | + $utf8 .= chr(0x08); |
|
| 498 | + ++$c; |
|
| 499 | + break; |
|
| 500 | + case '\t' === $substr_chrs_c_2: |
|
| 501 | + $utf8 .= chr(0x09); |
|
| 502 | + ++$c; |
|
| 503 | + break; |
|
| 504 | + case '\n' === $substr_chrs_c_2: |
|
| 505 | + $utf8 .= chr(0x0A); |
|
| 506 | + ++$c; |
|
| 507 | + break; |
|
| 508 | + case '\f' === $substr_chrs_c_2: |
|
| 509 | + $utf8 .= chr(0x0C); |
|
| 510 | + ++$c; |
|
| 511 | + break; |
|
| 512 | + case '\r' === $substr_chrs_c_2: |
|
| 513 | + $utf8 .= chr(0x0D); |
|
| 514 | + ++$c; |
|
| 515 | + break; |
|
| 516 | + case '\\"' === $substr_chrs_c_2: |
|
| 517 | + case '\\\'' === $substr_chrs_c_2: |
|
| 518 | + case '\\\\' === $substr_chrs_c_2: |
|
| 519 | + case '\\/' === $substr_chrs_c_2: |
|
| 520 | + if (('"' === $delim && '\\\'' !== $substr_chrs_c_2) |
|
| 521 | + || ("'" === $delim && '\\"' !== $substr_chrs_c_2)) { |
|
| 522 | + $utf8 .= $chrs[++$c]; |
|
| 523 | + } |
|
| 524 | + break; |
|
| 525 | + case preg_match('/\\\u[0-9A-F]{4}/i', mb_substr($chrs, $c, 6)): |
|
| 526 | + // single, escaped unicode character |
|
| 527 | + $utf16 = chr(hexdec(mb_substr($chrs, $c + 2, 2))) . chr(hexdec(mb_substr($chrs, $c + 4, 2))); |
|
| 528 | + $utf8 .= $this->utf162utf8($utf16); |
|
| 529 | + $c += 5; |
|
| 530 | + break; |
|
| 531 | + case ($ord_chrs_c >= 0x20) && ($ord_chrs_c <= 0x7F): |
|
| 532 | + $utf8 .= $chrs[$c]; |
|
| 533 | + break; |
|
| 534 | + case 0xC0 == ($ord_chrs_c & 0xE0): |
|
| 535 | + // characters U-00000080 - U-000007FF, mask 110SONGLIST |
|
| 536 | + //see https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
| 537 | + $utf8 .= mb_substr($chrs, $c, 2); |
|
| 538 | + ++$c; |
|
| 539 | + break; |
|
| 540 | + case 0xE0 == ($ord_chrs_c & 0xF0): |
|
| 541 | + // characters U-00000800 - U-0000FFFF, mask 1110XXXX |
|
| 542 | + // see https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
| 543 | + $utf8 .= mb_substr($chrs, $c, 3); |
|
| 544 | + $c += 2; |
|
| 545 | + break; |
|
| 546 | + case 0xF0 == ($ord_chrs_c & 0xF8): |
|
| 547 | + // characters U-00010000 - U-001FFFFF, mask 11110XXX |
|
| 548 | + // see https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
| 549 | + $utf8 .= mb_substr($chrs, $c, 4); |
|
| 550 | + $c += 3; |
|
| 551 | + break; |
|
| 552 | + case 0xF8 == ($ord_chrs_c & 0xFC): |
|
| 553 | + // characters U-00200000 - U-03FFFFFF, mask 111110XX |
|
| 554 | + // see https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
| 555 | + $utf8 .= mb_substr($chrs, $c, 5); |
|
| 556 | + $c += 4; |
|
| 557 | + break; |
|
| 558 | + case 0xFC == ($ord_chrs_c & 0xFE): |
|
| 559 | + // characters U-04000000 - U-7FFFFFFF, mask 1111110X |
|
| 560 | + // see https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
| 561 | + $utf8 .= mb_substr($chrs, $c, 6); |
|
| 562 | + $c += 5; |
|
| 563 | + break; |
|
| 564 | + } |
|
| 565 | + } |
|
| 566 | + |
|
| 567 | + return $utf8; |
|
| 568 | + } |
|
| 569 | + |
|
| 570 | + if (preg_match('/^\[.*\]$/s', $str) || preg_match('/^\{.*\}$/s', $str)) { |
|
| 571 | + // array, or object notation |
|
| 572 | + |
|
| 573 | + if ('[' === $str[0]) { |
|
| 574 | + $stk = [SERVICES_JSON_IN_ARR]; |
|
| 575 | + $arr = []; |
|
| 576 | + } elseif ($this->use & SERVICES_JSON_LOOSE_TYPE) { |
|
| 577 | + $stk = [SERVICES_JSON_IN_OBJ]; |
|
| 578 | + $obj = []; |
|
| 579 | + } else { |
|
| 580 | + $stk = [SERVICES_JSON_IN_OBJ]; |
|
| 581 | + $obj = new stdClass(); |
|
| 582 | + } |
|
| 583 | + |
|
| 584 | + array_push( |
|
| 585 | + $stk, |
|
| 586 | + [ |
|
| 587 | + 'what' => SERVICES_JSON_SLICE, |
|
| 588 | + 'where' => 0, |
|
| 589 | + 'delim' => false, |
|
| 590 | + ] |
|
| 591 | + ); |
|
| 592 | + |
|
| 593 | + $chrs = mb_substr($str, 1, -1); |
|
| 594 | + $chrs = $this->reduce_string($chrs); |
|
| 595 | + |
|
| 596 | + if ('' == $chrs) { |
|
| 597 | + if (SERVICES_JSON_IN_ARR == reset($stk)) { |
|
| 598 | + return $arr; |
|
| 599 | + } |
|
| 600 | + |
|
| 601 | + return $obj; |
|
| 602 | + } |
|
| 603 | + |
|
| 604 | + //print("\nparsing {$chrs}\n"); |
|
| 605 | + |
|
| 606 | + $strlen_chrs = mb_strlen($chrs); |
|
| 607 | + |
|
| 608 | + for ($c = 0; $c <= $strlen_chrs; ++$c) { |
|
| 609 | + $top = end($stk); |
|
| 610 | + $substr_chrs_c_2 = mb_substr($chrs, $c, 2); |
|
| 611 | + |
|
| 612 | + if (($c == $strlen_chrs) || ((',' === $chrs[$c]) && (SERVICES_JSON_SLICE == $top['what']))) { |
|
| 613 | + // found a comma that is not inside a string, array, etc., |
|
| 614 | + // OR we've reached the end of the character list |
|
| 615 | + $slice = mb_substr($chrs, $top['where'], $c - $top['where']); |
|
| 616 | + array_push($stk, ['what' => SERVICES_JSON_SLICE, 'where' => $c + 1, 'delim' => false]); |
|
| 617 | + //print("Found split at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n"); |
|
| 618 | + |
|
| 619 | + if (SERVICES_JSON_IN_ARR == reset($stk)) { |
|
| 620 | + // we are in an array, so just push an element onto the stack |
|
| 621 | + $arr[] = $this->decode($slice); |
|
| 622 | + } elseif (SERVICES_JSON_IN_OBJ == reset($stk)) { |
|
| 623 | + // we are in an object, so figure |
|
| 624 | + // out the property name and set an |
|
| 625 | + // element in an associative array, |
|
| 626 | + // for now |
|
| 627 | + $parts = []; |
|
| 628 | + |
|
| 629 | + if (preg_match('/^\s*(["\'].*[^\\\]["\'])\s*:\s*(\S.*),?$/Uis', $slice, $parts)) { |
|
| 630 | + // "name":value pair |
|
| 631 | + $key = $this->decode($parts[1]); |
|
| 632 | + $val = $this->decode($parts[2]); |
|
| 633 | + |
|
| 634 | + if ($this->use & SERVICES_JSON_LOOSE_TYPE) { |
|
| 635 | + $obj[$key] = $val; |
|
| 636 | + } else { |
|
| 637 | + $obj->$key = $val; |
|
| 638 | + } |
|
| 639 | + } elseif (preg_match('/^\s*(\w+)\s*:\s*(\S.*),?$/Uis', $slice, $parts)) { |
|
| 640 | + // name:value pair, where name is unquoted |
|
| 641 | + $key = $parts[1]; |
|
| 642 | + $val = $this->decode($parts[2]); |
|
| 643 | + |
|
| 644 | + if ($this->use & SERVICES_JSON_LOOSE_TYPE) { |
|
| 645 | + $obj[$key] = $val; |
|
| 646 | + } else { |
|
| 647 | + $obj->$key = $val; |
|
| 648 | + } |
|
| 649 | + } |
|
| 650 | + } |
|
| 651 | + } elseif ((('"' === $chrs[$c]) || ("'" === $chrs[$c])) && (SERVICES_JSON_IN_STR != $top['what'])) { |
|
| 652 | + // found a quote, and we are not inside a string |
|
| 653 | + array_push($stk, ['what' => SERVICES_JSON_IN_STR, 'where' => $c, 'delim' => $chrs[$c]]); |
|
| 654 | + //print("Found start of string at {$c}\n"); |
|
| 655 | + } elseif (($chrs[$c] == $top['delim']) |
|
| 656 | + && (SERVICES_JSON_IN_STR == $top['what']) |
|
| 657 | + && (1 != (mb_strlen(mb_substr($chrs, 0, $c)) - mb_strlen(rtrim(mb_substr($chrs, 0, $c), '\\'))) % 2)) { |
|
| 658 | + // found a quote, we're in a string, and it's not escaped |
|
| 659 | + // we know that it's not escaped becase there is _not_ an |
|
| 660 | + // odd number of backslashes at the end of the string so far |
|
| 661 | + array_pop($stk); |
|
| 662 | + //print("Found end of string at {$c}: ".substr($chrs, $top['where'], (1 + 1 + $c - $top['where']))."\n"); |
|
| 663 | + } elseif (('[' === $chrs[$c]) |
|
| 664 | + && in_array($top['what'], [SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ], true)) { |
|
| 665 | + // found a left-bracket, and we are in an array, object, or slice |
|
| 666 | + array_push($stk, ['what' => SERVICES_JSON_IN_ARR, 'where' => $c, 'delim' => false]); |
|
| 667 | + //print("Found start of array at {$c}\n"); |
|
| 668 | + } elseif ((']' === $chrs[$c]) && (SERVICES_JSON_IN_ARR == $top['what'])) { |
|
| 669 | + // found a right-bracket, and we're in an array |
|
| 670 | + array_pop($stk); |
|
| 671 | + //print("Found end of array at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n"); |
|
| 672 | + } elseif (('{' === $chrs[$c]) |
|
| 673 | + && in_array($top['what'], [SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ], true)) { |
|
| 674 | + // found a left-brace, and we are in an array, object, or slice |
|
| 675 | + array_push($stk, ['what' => SERVICES_JSON_IN_OBJ, 'where' => $c, 'delim' => false]); |
|
| 676 | + //print("Found start of object at {$c}\n"); |
|
| 677 | + } elseif (('}' === $chrs[$c]) && (SERVICES_JSON_IN_OBJ == $top['what'])) { |
|
| 678 | + // found a right-brace, and we're in an object |
|
| 679 | + array_pop($stk); |
|
| 680 | + //print("Found end of object at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n"); |
|
| 681 | + } elseif (('/*' === $substr_chrs_c_2) |
|
| 682 | + && in_array($top['what'], [SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ], true)) { |
|
| 683 | + // found a comment start, and we are in an array, object, or slice |
|
| 684 | + array_push($stk, ['what' => SERVICES_JSON_IN_CMT, 'where' => $c, 'delim' => false]); |
|
| 685 | + ++$c; |
|
| 686 | + //print("Found start of comment at {$c}\n"); |
|
| 687 | + } elseif (('*/' === $substr_chrs_c_2) && (SERVICES_JSON_IN_CMT == $top['what'])) { |
|
| 688 | + // found a comment end, and we're in one now |
|
| 689 | + array_pop($stk); |
|
| 690 | + ++$c; |
|
| 691 | + |
|
| 692 | + for ($i = $top['where']; $i <= $c; ++$i) { |
|
| 693 | + $chrs = substr_replace($chrs, ' ', $i, 1); |
|
| 694 | + } |
|
| 695 | + //print("Found end of comment at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n"); |
|
| 696 | + } |
|
| 697 | + } |
|
| 698 | + |
|
| 699 | + if (SERVICES_JSON_IN_ARR == reset($stk)) { |
|
| 700 | + return $arr; |
|
| 701 | + } |
|
| 702 | + |
|
| 703 | + if (SERVICES_JSON_IN_OBJ == reset($stk)) { |
|
| 704 | + return $obj; |
|
| 705 | + } |
|
| 706 | + } |
|
| 707 | + } |
|
| 708 | + } |
|
| 709 | + |
|
| 710 | + /** |
|
| 711 | + * @param $data |
|
| 712 | + * @param null $code |
|
| 713 | + * @return bool |
|
| 714 | + * @todo Ultimately, this should just call PEAR::isError() |
|
| 715 | + */ |
|
| 716 | + public function isError($data, $code = null): bool |
|
| 717 | + { |
|
| 718 | + if (class_exists('pear')) { |
|
| 719 | + return PEAR::isError($data, $code); |
|
| 720 | + } |
|
| 721 | + |
|
| 722 | + if (is_object($data) |
|
| 723 | + && ($data instanceof \services_json_error |
|
| 724 | + || $data instanceof \services_json_error)) { |
|
| 725 | + return true; |
|
| 726 | + } |
|
| 727 | + |
|
| 728 | + return false; |
|
| 729 | + } |
|
| 730 | 730 | } |
| 731 | 731 | |
| 732 | 732 | if (class_exists('PEAR_Error')) { |
| 733 | - /** |
|
| 734 | - * Class ServicesJSON_Error |
|
| 735 | - */ |
|
| 736 | - class ServicesJSON_Error extends PEAR_Error |
|
| 737 | - { |
|
| 738 | - /** |
|
| 739 | - * ServicesJSON_Error constructor. |
|
| 740 | - * @param string $message |
|
| 741 | - * @param null $code |
|
| 742 | - * @param null $mode |
|
| 743 | - * @param null $options |
|
| 744 | - * @param null $userinfo |
|
| 745 | - */ |
|
| 746 | - public function __construct( |
|
| 747 | - $message = 'unknown error', |
|
| 748 | - $code = null, |
|
| 749 | - $mode = null, |
|
| 750 | - $options = null, |
|
| 751 | - $userinfo = null |
|
| 752 | - ) { |
|
| 753 | - parent::__construct($message, $code, $mode, $options, $userinfo); |
|
| 754 | - } |
|
| 755 | - } |
|
| 733 | + /** |
|
| 734 | + * Class ServicesJSON_Error |
|
| 735 | + */ |
|
| 736 | + class ServicesJSON_Error extends PEAR_Error |
|
| 737 | + { |
|
| 738 | + /** |
|
| 739 | + * ServicesJSON_Error constructor. |
|
| 740 | + * @param string $message |
|
| 741 | + * @param null $code |
|
| 742 | + * @param null $mode |
|
| 743 | + * @param null $options |
|
| 744 | + * @param null $userinfo |
|
| 745 | + */ |
|
| 746 | + public function __construct( |
|
| 747 | + $message = 'unknown error', |
|
| 748 | + $code = null, |
|
| 749 | + $mode = null, |
|
| 750 | + $options = null, |
|
| 751 | + $userinfo = null |
|
| 752 | + ) { |
|
| 753 | + parent::__construct($message, $code, $mode, $options, $userinfo); |
|
| 754 | + } |
|
| 755 | + } |
|
| 756 | 756 | } else { |
| 757 | - /** |
|
| 758 | - * @todo Ultimately, this class shall be descended from PEAR_Error |
|
| 759 | - */ |
|
| 760 | - class ServicesJSON_Error |
|
| 761 | - { |
|
| 762 | - /** |
|
| 763 | - * ServicesJSON_Error constructor. |
|
| 764 | - * @param string $message |
|
| 765 | - * @param null $code |
|
| 766 | - * @param null $mode |
|
| 767 | - * @param null $options |
|
| 768 | - * @param null $userinfo |
|
| 769 | - */ |
|
| 770 | - public function __construct( |
|
| 771 | - $message = 'unknown error', |
|
| 772 | - $code = null, |
|
| 773 | - $mode = null, |
|
| 774 | - $options = null, |
|
| 775 | - $userinfo = null |
|
| 776 | - ) { |
|
| 777 | - } |
|
| 778 | - } |
|
| 757 | + /** |
|
| 758 | + * @todo Ultimately, this class shall be descended from PEAR_Error |
|
| 759 | + */ |
|
| 760 | + class ServicesJSON_Error |
|
| 761 | + { |
|
| 762 | + /** |
|
| 763 | + * ServicesJSON_Error constructor. |
|
| 764 | + * @param string $message |
|
| 765 | + * @param null $code |
|
| 766 | + * @param null $mode |
|
| 767 | + * @param null $options |
|
| 768 | + * @param null $userinfo |
|
| 769 | + */ |
|
| 770 | + public function __construct( |
|
| 771 | + $message = 'unknown error', |
|
| 772 | + $code = null, |
|
| 773 | + $mode = null, |
|
| 774 | + $options = null, |
|
| 775 | + $userinfo = null |
|
| 776 | + ) { |
|
| 777 | + } |
|
| 778 | + } |
|
| 779 | 779 | } |
@@ -117,18 +117,18 @@ discard block |
||
| 117 | 117 | $bytes = (ord($utf16[0]) << 8) | ord($utf16[1]); |
| 118 | 118 | |
| 119 | 119 | switch (true) { |
| 120 | - case ((0x7F & $bytes) == $bytes): |
|
| 120 | + case ((0x7F & $bytes)==$bytes): |
|
| 121 | 121 | // this case should never be reached, because we are in ASCII range |
| 122 | 122 | // see: https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
| 123 | 123 | return chr(0x7F & $bytes); |
| 124 | - case (0x07FF & $bytes) == $bytes: |
|
| 124 | + case (0x07FF & $bytes)==$bytes: |
|
| 125 | 125 | // return a 2-byte UTF-8 character |
| 126 | 126 | // see: https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
| 127 | - return chr(0xC0 | (($bytes >> 6) & 0x1F)) . chr(0x80 | ($bytes & 0x3F)); |
|
| 128 | - case (0xFFFF & $bytes) == $bytes: |
|
| 127 | + return chr(0xC0 | (($bytes >> 6) & 0x1F)).chr(0x80 | ($bytes & 0x3F)); |
|
| 128 | + case (0xFFFF & $bytes)==$bytes: |
|
| 129 | 129 | // return a 3-byte UTF-8 character |
| 130 | 130 | // see: https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
| 131 | - return chr(0xE0 | (($bytes >> 12) & 0x0F)) . chr(0x80 | (($bytes >> 6) & 0x3F)) . chr(0x80 | ($bytes & 0x3F)); |
|
| 131 | + return chr(0xE0 | (($bytes >> 12) & 0x0F)).chr(0x80 | (($bytes >> 6) & 0x3F)).chr(0x80 | ($bytes & 0x3F)); |
|
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | // ignoring UTF-32 for now, sorry |
@@ -160,11 +160,11 @@ discard block |
||
| 160 | 160 | case 2: |
| 161 | 161 | // return a UTF-16 character from a 2-byte UTF-8 char |
| 162 | 162 | // see: https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
| 163 | - return chr(0x07 & (ord($utf8[0]) >> 2)) . chr((0xC0 & (ord($utf8[0]) << 6)) | (0x3F & ord($utf8[1]))); |
|
| 163 | + return chr(0x07 & (ord($utf8[0]) >> 2)).chr((0xC0 & (ord($utf8[0]) << 6)) | (0x3F & ord($utf8[1]))); |
|
| 164 | 164 | case 3: |
| 165 | 165 | // return a UTF-16 character from a 3-byte UTF-8 char |
| 166 | 166 | // see: https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
| 167 | - return chr((0xF0 & (ord($utf8[0]) << 4)) | (0x0F & (ord($utf8[1]) >> 2))) . chr((0xC0 & (ord($utf8[1]) << 6)) | (0x7F & ord($utf8[2]))); |
|
| 167 | + return chr((0xF0 & (ord($utf8[0]) << 4)) | (0x0F & (ord($utf8[1]) >> 2))).chr((0xC0 & (ord($utf8[1]) << 6)) | (0x7F & ord($utf8[2]))); |
|
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | // ignoring UTF-32 for now, sorry |
@@ -227,10 +227,10 @@ discard block |
||
| 227 | 227 | case 'NULL': |
| 228 | 228 | return 'null'; |
| 229 | 229 | case 'integer': |
| 230 | - return (int)$var; |
|
| 230 | + return (int) $var; |
|
| 231 | 231 | case 'double': |
| 232 | 232 | case 'float': |
| 233 | - return (float)$var; |
|
| 233 | + return (float) $var; |
|
| 234 | 234 | case 'string': |
| 235 | 235 | // STRINGS ARE EXPECTED TO BE IN ASCII OR UTF-8 FORMAT |
| 236 | 236 | $ascii = ''; |
@@ -240,97 +240,97 @@ discard block |
||
| 240 | 240 | * Iterate over every character in the string, |
| 241 | 241 | * escaping with a slash or encoding to UTF-8 where necessary |
| 242 | 242 | */ |
| 243 | - for ($c = 0; $c < $strlen_var; ++$c) { |
|
| 243 | + for ($c = 0; $c<$strlen_var; ++$c) { |
|
| 244 | 244 | $ord_var_c = ord($var[$c]); |
| 245 | 245 | |
| 246 | 246 | switch (true) { |
| 247 | - case 0x08 == $ord_var_c: |
|
| 247 | + case 0x08==$ord_var_c: |
|
| 248 | 248 | $ascii .= '\b'; |
| 249 | 249 | break; |
| 250 | - case 0x09 == $ord_var_c: |
|
| 250 | + case 0x09==$ord_var_c: |
|
| 251 | 251 | $ascii .= '\t'; |
| 252 | 252 | break; |
| 253 | - case 0x0A == $ord_var_c: |
|
| 253 | + case 0x0A==$ord_var_c: |
|
| 254 | 254 | $ascii .= '\n'; |
| 255 | 255 | break; |
| 256 | - case 0x0C == $ord_var_c: |
|
| 256 | + case 0x0C==$ord_var_c: |
|
| 257 | 257 | $ascii .= '\f'; |
| 258 | 258 | break; |
| 259 | - case 0x0D == $ord_var_c: |
|
| 259 | + case 0x0D==$ord_var_c: |
|
| 260 | 260 | $ascii .= '\r'; |
| 261 | 261 | break; |
| 262 | - case 0x22 == $ord_var_c: |
|
| 263 | - case 0x2F == $ord_var_c: |
|
| 264 | - case 0x5C == $ord_var_c: |
|
| 262 | + case 0x22==$ord_var_c: |
|
| 263 | + case 0x2F==$ord_var_c: |
|
| 264 | + case 0x5C==$ord_var_c: |
|
| 265 | 265 | // double quote, slash, slosh |
| 266 | - $ascii .= '\\' . $var[$c]; |
|
| 266 | + $ascii .= '\\'.$var[$c]; |
|
| 267 | 267 | break; |
| 268 | - case (($ord_var_c >= 0x20) && ($ord_var_c <= 0x7F)): |
|
| 268 | + case (($ord_var_c>=0x20) && ($ord_var_c<=0x7F)): |
|
| 269 | 269 | // characters U-00000000 - U-0000007F (same as ASCII) |
| 270 | 270 | $ascii .= $var[$c]; |
| 271 | 271 | break; |
| 272 | - case (0xC0 == ($ord_var_c & 0xE0)): |
|
| 272 | + case (0xC0==($ord_var_c & 0xE0)): |
|
| 273 | 273 | // characters U-00000080 - U-000007FF, mask 110SONGLIST |
| 274 | 274 | // see https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
| 275 | - if ($c + 1 >= $strlen_var) { |
|
| 275 | + if ($c+1>=$strlen_var) { |
|
| 276 | 276 | ++$c; |
| 277 | 277 | $ascii .= '?'; |
| 278 | 278 | break; |
| 279 | 279 | } |
| 280 | 280 | |
| 281 | - $char = pack('C*', $ord_var_c, ord($var[$c + 1])); |
|
| 281 | + $char = pack('C*', $ord_var_c, ord($var[$c+1])); |
|
| 282 | 282 | ++$c; |
| 283 | 283 | $utf16 = $this->utf82utf16($char); |
| 284 | 284 | $ascii .= sprintf('\u%04s', bin2hex($utf16)); |
| 285 | 285 | break; |
| 286 | - case (0xE0 == ($ord_var_c & 0xF0)): |
|
| 287 | - if ($c + 2 >= $strlen_var) { |
|
| 286 | + case (0xE0==($ord_var_c & 0xF0)): |
|
| 287 | + if ($c+2>=$strlen_var) { |
|
| 288 | 288 | $c += 2; |
| 289 | 289 | $ascii .= '?'; |
| 290 | 290 | break; |
| 291 | 291 | } |
| 292 | 292 | // characters U-00000800 - U-0000FFFF, mask 1110XXXX |
| 293 | 293 | // see https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
| 294 | - $char = pack('C*', $ord_var_c, @ord($var[$c + 1]), @ord($var[$c + 2])); |
|
| 294 | + $char = pack('C*', $ord_var_c, @ord($var[$c+1]), @ord($var[$c+2])); |
|
| 295 | 295 | $c += 2; |
| 296 | 296 | $utf16 = $this->utf82utf16($char); |
| 297 | 297 | $ascii .= sprintf('\u%04s', bin2hex($utf16)); |
| 298 | 298 | break; |
| 299 | - case (0xF0 == ($ord_var_c & 0xF8)): |
|
| 300 | - if ($c + 3 >= $strlen_var) { |
|
| 299 | + case (0xF0==($ord_var_c & 0xF8)): |
|
| 300 | + if ($c+3>=$strlen_var) { |
|
| 301 | 301 | $c += 3; |
| 302 | 302 | $ascii .= '?'; |
| 303 | 303 | break; |
| 304 | 304 | } |
| 305 | 305 | // characters U-00010000 - U-001FFFFF, mask 11110XXX |
| 306 | 306 | // see https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
| 307 | - $char = pack('C*', $ord_var_c, ord($var[$c + 1]), ord($var[$c + 2]), ord($var[$c + 3])); |
|
| 307 | + $char = pack('C*', $ord_var_c, ord($var[$c+1]), ord($var[$c+2]), ord($var[$c+3])); |
|
| 308 | 308 | $c += 3; |
| 309 | 309 | $utf16 = $this->utf82utf16($char); |
| 310 | 310 | $ascii .= sprintf('\u%04s', bin2hex($utf16)); |
| 311 | 311 | break; |
| 312 | - case (0xF8 == ($ord_var_c & 0xFC)): |
|
| 312 | + case (0xF8==($ord_var_c & 0xFC)): |
|
| 313 | 313 | // characters U-00200000 - U-03FFFFFF, mask 111110XX |
| 314 | 314 | // see https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
| 315 | - if ($c + 4 >= $strlen_var) { |
|
| 315 | + if ($c+4>=$strlen_var) { |
|
| 316 | 316 | $c += 4; |
| 317 | 317 | $ascii .= '?'; |
| 318 | 318 | break; |
| 319 | 319 | } |
| 320 | - $char = pack('C*', $ord_var_c, ord($var[$c + 1]), ord($var[$c + 2]), ord($var[$c + 3]), ord($var[$c + 4])); |
|
| 320 | + $char = pack('C*', $ord_var_c, ord($var[$c+1]), ord($var[$c+2]), ord($var[$c+3]), ord($var[$c+4])); |
|
| 321 | 321 | $c += 4; |
| 322 | 322 | $utf16 = $this->utf82utf16($char); |
| 323 | 323 | $ascii .= sprintf('\u%04s', bin2hex($utf16)); |
| 324 | 324 | break; |
| 325 | - case (0xFC == ($ord_var_c & 0xFE)): |
|
| 326 | - if ($c + 5 >= $strlen_var) { |
|
| 325 | + case (0xFC==($ord_var_c & 0xFE)): |
|
| 326 | + if ($c+5>=$strlen_var) { |
|
| 327 | 327 | $c += 5; |
| 328 | 328 | $ascii .= '?'; |
| 329 | 329 | break; |
| 330 | 330 | } |
| 331 | 331 | // characters U-04000000 - U-7FFFFFFF, mask 1111110X |
| 332 | 332 | // see https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
| 333 | - $char = pack('C*', $ord_var_c, ord($var[$c + 1]), ord($var[$c + 2]), ord($var[$c + 3]), ord($var[$c + 4]), ord($var[$c + 5])); |
|
| 333 | + $char = pack('C*', $ord_var_c, ord($var[$c+1]), ord($var[$c+2]), ord($var[$c+3]), ord($var[$c+4]), ord($var[$c+5])); |
|
| 334 | 334 | $c += 5; |
| 335 | 335 | $utf16 = $this->utf82utf16($char); |
| 336 | 336 | $ascii .= sprintf('\u%04s', bin2hex($utf16)); |
@@ -338,7 +338,7 @@ discard block |
||
| 338 | 338 | } |
| 339 | 339 | } |
| 340 | 340 | |
| 341 | - return '"' . $ascii . '"'; |
|
| 341 | + return '"'.$ascii.'"'; |
|
| 342 | 342 | case 'array': |
| 343 | 343 | /* |
| 344 | 344 | * As per JSON spec if any array key is not an integer |
@@ -359,7 +359,7 @@ discard block |
||
| 359 | 359 | */ |
| 360 | 360 | |
| 361 | 361 | // treat as a JSON object |
| 362 | - if (is_array($var) && count($var) && (array_keys($var) !== range(0, count($var) - 1))) { |
|
| 362 | + if (is_array($var) && count($var) && (array_keys($var)!==range(0, count($var)-1))) { |
|
| 363 | 363 | $properties = array_map([$this, 'name_value'], array_keys($var), array_values($var)); |
| 364 | 364 | |
| 365 | 365 | foreach ($properties as $property) { |
@@ -368,7 +368,7 @@ discard block |
||
| 368 | 368 | } |
| 369 | 369 | } |
| 370 | 370 | |
| 371 | - return '{' . implode(',', $properties) . '}'; |
|
| 371 | + return '{'.implode(',', $properties).'}'; |
|
| 372 | 372 | } |
| 373 | 373 | |
| 374 | 374 | // treat it like a regular array |
@@ -380,7 +380,7 @@ discard block |
||
| 380 | 380 | } |
| 381 | 381 | } |
| 382 | 382 | |
| 383 | - return '[' . implode(',', $elements) . ']'; |
|
| 383 | + return '['.implode(',', $elements).']'; |
|
| 384 | 384 | case 'object': |
| 385 | 385 | $vars = get_object_vars($var); |
| 386 | 386 | |
@@ -392,9 +392,9 @@ discard block |
||
| 392 | 392 | } |
| 393 | 393 | } |
| 394 | 394 | |
| 395 | - return '{' . implode(',', $properties) . '}'; |
|
| 395 | + return '{'.implode(',', $properties).'}'; |
|
| 396 | 396 | default: |
| 397 | - return ($this->use & SERVICES_JSON_SUPPRESS_ERRORS) ? 'null' : new ServicesJSON_Error(gettype($var) . ' can not be encoded as JSON string'); |
|
| 397 | + return ($this->use & SERVICES_JSON_SUPPRESS_ERRORS) ? 'null' : new ServicesJSON_Error(gettype($var).' can not be encoded as JSON string'); |
|
| 398 | 398 | } |
| 399 | 399 | } |
| 400 | 400 | |
@@ -414,7 +414,7 @@ discard block |
||
| 414 | 414 | return $encoded_value; |
| 415 | 415 | } |
| 416 | 416 | |
| 417 | - return $this->_encode((string)$name) . ':' . $encoded_value; |
|
| 417 | + return $this->_encode((string) $name).':'.$encoded_value; |
|
| 418 | 418 | } |
| 419 | 419 | |
| 420 | 420 | /** |
@@ -478,84 +478,84 @@ discard block |
||
| 478 | 478 | // return (float)$str; |
| 479 | 479 | |
| 480 | 480 | // Return float or int, as appropriate |
| 481 | - return ((float)$str == (int)$str) ? (int)$str : (float)$str; |
|
| 481 | + return ((float) $str==(int) $str) ? (int) $str : (float) $str; |
|
| 482 | 482 | } |
| 483 | 483 | |
| 484 | - if (preg_match('/^("|\').*(\1)$/s', $str, $m) && $m[1] == $m[2]) { |
|
| 484 | + if (preg_match('/^("|\').*(\1)$/s', $str, $m) && $m[1]==$m[2]) { |
|
| 485 | 485 | // STRINGS RETURNED IN UTF-8 FORMAT |
| 486 | 486 | $delim = mb_substr($str, 0, 1); |
| 487 | 487 | $chrs = mb_substr($str, 1, -1); |
| 488 | 488 | $utf8 = ''; |
| 489 | 489 | $strlen_chrs = mb_strlen($chrs); |
| 490 | 490 | |
| 491 | - for ($c = 0; $c < $strlen_chrs; ++$c) { |
|
| 491 | + for ($c = 0; $c<$strlen_chrs; ++$c) { |
|
| 492 | 492 | $substr_chrs_c_2 = mb_substr($chrs, $c, 2); |
| 493 | 493 | $ord_chrs_c = ord($chrs[$c]); |
| 494 | 494 | |
| 495 | 495 | switch (true) { |
| 496 | - case '\b' === $substr_chrs_c_2: |
|
| 496 | + case '\b'===$substr_chrs_c_2: |
|
| 497 | 497 | $utf8 .= chr(0x08); |
| 498 | 498 | ++$c; |
| 499 | 499 | break; |
| 500 | - case '\t' === $substr_chrs_c_2: |
|
| 500 | + case '\t'===$substr_chrs_c_2: |
|
| 501 | 501 | $utf8 .= chr(0x09); |
| 502 | 502 | ++$c; |
| 503 | 503 | break; |
| 504 | - case '\n' === $substr_chrs_c_2: |
|
| 504 | + case '\n'===$substr_chrs_c_2: |
|
| 505 | 505 | $utf8 .= chr(0x0A); |
| 506 | 506 | ++$c; |
| 507 | 507 | break; |
| 508 | - case '\f' === $substr_chrs_c_2: |
|
| 508 | + case '\f'===$substr_chrs_c_2: |
|
| 509 | 509 | $utf8 .= chr(0x0C); |
| 510 | 510 | ++$c; |
| 511 | 511 | break; |
| 512 | - case '\r' === $substr_chrs_c_2: |
|
| 512 | + case '\r'===$substr_chrs_c_2: |
|
| 513 | 513 | $utf8 .= chr(0x0D); |
| 514 | 514 | ++$c; |
| 515 | 515 | break; |
| 516 | - case '\\"' === $substr_chrs_c_2: |
|
| 517 | - case '\\\'' === $substr_chrs_c_2: |
|
| 518 | - case '\\\\' === $substr_chrs_c_2: |
|
| 519 | - case '\\/' === $substr_chrs_c_2: |
|
| 520 | - if (('"' === $delim && '\\\'' !== $substr_chrs_c_2) |
|
| 521 | - || ("'" === $delim && '\\"' !== $substr_chrs_c_2)) { |
|
| 516 | + case '\\"'===$substr_chrs_c_2: |
|
| 517 | + case '\\\''===$substr_chrs_c_2: |
|
| 518 | + case '\\\\'===$substr_chrs_c_2: |
|
| 519 | + case '\\/'===$substr_chrs_c_2: |
|
| 520 | + if (('"'===$delim && '\\\''!==$substr_chrs_c_2) |
|
| 521 | + || ("'"===$delim && '\\"'!==$substr_chrs_c_2)) { |
|
| 522 | 522 | $utf8 .= $chrs[++$c]; |
| 523 | 523 | } |
| 524 | 524 | break; |
| 525 | 525 | case preg_match('/\\\u[0-9A-F]{4}/i', mb_substr($chrs, $c, 6)): |
| 526 | 526 | // single, escaped unicode character |
| 527 | - $utf16 = chr(hexdec(mb_substr($chrs, $c + 2, 2))) . chr(hexdec(mb_substr($chrs, $c + 4, 2))); |
|
| 527 | + $utf16 = chr(hexdec(mb_substr($chrs, $c+2, 2))).chr(hexdec(mb_substr($chrs, $c+4, 2))); |
|
| 528 | 528 | $utf8 .= $this->utf162utf8($utf16); |
| 529 | 529 | $c += 5; |
| 530 | 530 | break; |
| 531 | - case ($ord_chrs_c >= 0x20) && ($ord_chrs_c <= 0x7F): |
|
| 531 | + case ($ord_chrs_c>=0x20) && ($ord_chrs_c<=0x7F): |
|
| 532 | 532 | $utf8 .= $chrs[$c]; |
| 533 | 533 | break; |
| 534 | - case 0xC0 == ($ord_chrs_c & 0xE0): |
|
| 534 | + case 0xC0==($ord_chrs_c & 0xE0): |
|
| 535 | 535 | // characters U-00000080 - U-000007FF, mask 110SONGLIST |
| 536 | 536 | //see https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
| 537 | 537 | $utf8 .= mb_substr($chrs, $c, 2); |
| 538 | 538 | ++$c; |
| 539 | 539 | break; |
| 540 | - case 0xE0 == ($ord_chrs_c & 0xF0): |
|
| 540 | + case 0xE0==($ord_chrs_c & 0xF0): |
|
| 541 | 541 | // characters U-00000800 - U-0000FFFF, mask 1110XXXX |
| 542 | 542 | // see https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
| 543 | 543 | $utf8 .= mb_substr($chrs, $c, 3); |
| 544 | 544 | $c += 2; |
| 545 | 545 | break; |
| 546 | - case 0xF0 == ($ord_chrs_c & 0xF8): |
|
| 546 | + case 0xF0==($ord_chrs_c & 0xF8): |
|
| 547 | 547 | // characters U-00010000 - U-001FFFFF, mask 11110XXX |
| 548 | 548 | // see https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
| 549 | 549 | $utf8 .= mb_substr($chrs, $c, 4); |
| 550 | 550 | $c += 3; |
| 551 | 551 | break; |
| 552 | - case 0xF8 == ($ord_chrs_c & 0xFC): |
|
| 552 | + case 0xF8==($ord_chrs_c & 0xFC): |
|
| 553 | 553 | // characters U-00200000 - U-03FFFFFF, mask 111110XX |
| 554 | 554 | // see https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
| 555 | 555 | $utf8 .= mb_substr($chrs, $c, 5); |
| 556 | 556 | $c += 4; |
| 557 | 557 | break; |
| 558 | - case 0xFC == ($ord_chrs_c & 0xFE): |
|
| 558 | + case 0xFC==($ord_chrs_c & 0xFE): |
|
| 559 | 559 | // characters U-04000000 - U-7FFFFFFF, mask 1111110X |
| 560 | 560 | // see https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
| 561 | 561 | $utf8 .= mb_substr($chrs, $c, 6); |
@@ -570,7 +570,7 @@ discard block |
||
| 570 | 570 | if (preg_match('/^\[.*\]$/s', $str) || preg_match('/^\{.*\}$/s', $str)) { |
| 571 | 571 | // array, or object notation |
| 572 | 572 | |
| 573 | - if ('[' === $str[0]) { |
|
| 573 | + if ('['===$str[0]) { |
|
| 574 | 574 | $stk = [SERVICES_JSON_IN_ARR]; |
| 575 | 575 | $arr = []; |
| 576 | 576 | } elseif ($this->use & SERVICES_JSON_LOOSE_TYPE) { |
@@ -593,8 +593,8 @@ discard block |
||
| 593 | 593 | $chrs = mb_substr($str, 1, -1); |
| 594 | 594 | $chrs = $this->reduce_string($chrs); |
| 595 | 595 | |
| 596 | - if ('' == $chrs) { |
|
| 597 | - if (SERVICES_JSON_IN_ARR == reset($stk)) { |
|
| 596 | + if (''==$chrs) { |
|
| 597 | + if (SERVICES_JSON_IN_ARR==reset($stk)) { |
|
| 598 | 598 | return $arr; |
| 599 | 599 | } |
| 600 | 600 | |
@@ -605,21 +605,21 @@ discard block |
||
| 605 | 605 | |
| 606 | 606 | $strlen_chrs = mb_strlen($chrs); |
| 607 | 607 | |
| 608 | - for ($c = 0; $c <= $strlen_chrs; ++$c) { |
|
| 608 | + for ($c = 0; $c<=$strlen_chrs; ++$c) { |
|
| 609 | 609 | $top = end($stk); |
| 610 | 610 | $substr_chrs_c_2 = mb_substr($chrs, $c, 2); |
| 611 | 611 | |
| 612 | - if (($c == $strlen_chrs) || ((',' === $chrs[$c]) && (SERVICES_JSON_SLICE == $top['what']))) { |
|
| 612 | + if (($c==$strlen_chrs) || ((','===$chrs[$c]) && (SERVICES_JSON_SLICE==$top['what']))) { |
|
| 613 | 613 | // found a comma that is not inside a string, array, etc., |
| 614 | 614 | // OR we've reached the end of the character list |
| 615 | - $slice = mb_substr($chrs, $top['where'], $c - $top['where']); |
|
| 616 | - array_push($stk, ['what' => SERVICES_JSON_SLICE, 'where' => $c + 1, 'delim' => false]); |
|
| 615 | + $slice = mb_substr($chrs, $top['where'], $c-$top['where']); |
|
| 616 | + array_push($stk, ['what' => SERVICES_JSON_SLICE, 'where' => $c+1, 'delim' => false]); |
|
| 617 | 617 | //print("Found split at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n"); |
| 618 | 618 | |
| 619 | - if (SERVICES_JSON_IN_ARR == reset($stk)) { |
|
| 619 | + if (SERVICES_JSON_IN_ARR==reset($stk)) { |
|
| 620 | 620 | // we are in an array, so just push an element onto the stack |
| 621 | 621 | $arr[] = $this->decode($slice); |
| 622 | - } elseif (SERVICES_JSON_IN_OBJ == reset($stk)) { |
|
| 622 | + } elseif (SERVICES_JSON_IN_OBJ==reset($stk)) { |
|
| 623 | 623 | // we are in an object, so figure |
| 624 | 624 | // out the property name and set an |
| 625 | 625 | // element in an associative array, |
@@ -648,59 +648,59 @@ discard block |
||
| 648 | 648 | } |
| 649 | 649 | } |
| 650 | 650 | } |
| 651 | - } elseif ((('"' === $chrs[$c]) || ("'" === $chrs[$c])) && (SERVICES_JSON_IN_STR != $top['what'])) { |
|
| 651 | + } elseif ((('"'===$chrs[$c]) || ("'"===$chrs[$c])) && (SERVICES_JSON_IN_STR!=$top['what'])) { |
|
| 652 | 652 | // found a quote, and we are not inside a string |
| 653 | 653 | array_push($stk, ['what' => SERVICES_JSON_IN_STR, 'where' => $c, 'delim' => $chrs[$c]]); |
| 654 | 654 | //print("Found start of string at {$c}\n"); |
| 655 | - } elseif (($chrs[$c] == $top['delim']) |
|
| 656 | - && (SERVICES_JSON_IN_STR == $top['what']) |
|
| 657 | - && (1 != (mb_strlen(mb_substr($chrs, 0, $c)) - mb_strlen(rtrim(mb_substr($chrs, 0, $c), '\\'))) % 2)) { |
|
| 655 | + } elseif (($chrs[$c]==$top['delim']) |
|
| 656 | + && (SERVICES_JSON_IN_STR==$top['what']) |
|
| 657 | + && (1!=(mb_strlen(mb_substr($chrs, 0, $c))-mb_strlen(rtrim(mb_substr($chrs, 0, $c), '\\')))%2)) { |
|
| 658 | 658 | // found a quote, we're in a string, and it's not escaped |
| 659 | 659 | // we know that it's not escaped becase there is _not_ an |
| 660 | 660 | // odd number of backslashes at the end of the string so far |
| 661 | 661 | array_pop($stk); |
| 662 | 662 | //print("Found end of string at {$c}: ".substr($chrs, $top['where'], (1 + 1 + $c - $top['where']))."\n"); |
| 663 | - } elseif (('[' === $chrs[$c]) |
|
| 663 | + } elseif (('['===$chrs[$c]) |
|
| 664 | 664 | && in_array($top['what'], [SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ], true)) { |
| 665 | 665 | // found a left-bracket, and we are in an array, object, or slice |
| 666 | 666 | array_push($stk, ['what' => SERVICES_JSON_IN_ARR, 'where' => $c, 'delim' => false]); |
| 667 | 667 | //print("Found start of array at {$c}\n"); |
| 668 | - } elseif ((']' === $chrs[$c]) && (SERVICES_JSON_IN_ARR == $top['what'])) { |
|
| 668 | + } elseif ((']'===$chrs[$c]) && (SERVICES_JSON_IN_ARR==$top['what'])) { |
|
| 669 | 669 | // found a right-bracket, and we're in an array |
| 670 | 670 | array_pop($stk); |
| 671 | 671 | //print("Found end of array at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n"); |
| 672 | - } elseif (('{' === $chrs[$c]) |
|
| 672 | + } elseif (('{'===$chrs[$c]) |
|
| 673 | 673 | && in_array($top['what'], [SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ], true)) { |
| 674 | 674 | // found a left-brace, and we are in an array, object, or slice |
| 675 | 675 | array_push($stk, ['what' => SERVICES_JSON_IN_OBJ, 'where' => $c, 'delim' => false]); |
| 676 | 676 | //print("Found start of object at {$c}\n"); |
| 677 | - } elseif (('}' === $chrs[$c]) && (SERVICES_JSON_IN_OBJ == $top['what'])) { |
|
| 677 | + } elseif (('}'===$chrs[$c]) && (SERVICES_JSON_IN_OBJ==$top['what'])) { |
|
| 678 | 678 | // found a right-brace, and we're in an object |
| 679 | 679 | array_pop($stk); |
| 680 | 680 | //print("Found end of object at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n"); |
| 681 | - } elseif (('/*' === $substr_chrs_c_2) |
|
| 681 | + } elseif (('/*'===$substr_chrs_c_2) |
|
| 682 | 682 | && in_array($top['what'], [SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ], true)) { |
| 683 | 683 | // found a comment start, and we are in an array, object, or slice |
| 684 | 684 | array_push($stk, ['what' => SERVICES_JSON_IN_CMT, 'where' => $c, 'delim' => false]); |
| 685 | 685 | ++$c; |
| 686 | 686 | //print("Found start of comment at {$c}\n"); |
| 687 | - } elseif (('*/' === $substr_chrs_c_2) && (SERVICES_JSON_IN_CMT == $top['what'])) { |
|
| 687 | + } elseif (('*/'===$substr_chrs_c_2) && (SERVICES_JSON_IN_CMT==$top['what'])) { |
|
| 688 | 688 | // found a comment end, and we're in one now |
| 689 | 689 | array_pop($stk); |
| 690 | 690 | ++$c; |
| 691 | 691 | |
| 692 | - for ($i = $top['where']; $i <= $c; ++$i) { |
|
| 692 | + for ($i = $top['where']; $i<=$c; ++$i) { |
|
| 693 | 693 | $chrs = substr_replace($chrs, ' ', $i, 1); |
| 694 | 694 | } |
| 695 | 695 | //print("Found end of comment at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n"); |
| 696 | 696 | } |
| 697 | 697 | } |
| 698 | 698 | |
| 699 | - if (SERVICES_JSON_IN_ARR == reset($stk)) { |
|
| 699 | + if (SERVICES_JSON_IN_ARR==reset($stk)) { |
|
| 700 | 700 | return $arr; |
| 701 | 701 | } |
| 702 | 702 | |
| 703 | - if (SERVICES_JSON_IN_OBJ == reset($stk)) { |
|
| 703 | + if (SERVICES_JSON_IN_OBJ==reset($stk)) { |
|
| 704 | 704 | return $obj; |
| 705 | 705 | } |
| 706 | 706 | } |
@@ -20,8 +20,8 @@ discard block |
||
| 20 | 20 | */ |
| 21 | 21 | function xoops_module_pre_uninstall_songlist(\XoopsModule $module): bool |
| 22 | 22 | { |
| 23 | - // Do some synchronization |
|
| 24 | - return true; |
|
| 23 | + // Do some synchronization |
|
| 24 | + return true; |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | /** |
@@ -32,26 +32,26 @@ discard block |
||
| 32 | 32 | */ |
| 33 | 33 | function xoops_module_uninstall_songlist(\XoopsModule $module): bool |
| 34 | 34 | { |
| 35 | - $moduleDirName = \basename(\dirname(__DIR__)); |
|
| 36 | - $moduleDirNameUpper = \mb_strtoupper($moduleDirName); |
|
| 37 | - $helper = Helper::getInstance(); |
|
| 35 | + $moduleDirName = \basename(\dirname(__DIR__)); |
|
| 36 | + $moduleDirNameUpper = \mb_strtoupper($moduleDirName); |
|
| 37 | + $helper = Helper::getInstance(); |
|
| 38 | 38 | |
| 39 | - $success = true; |
|
| 40 | - $helper->loadLanguage('admin'); |
|
| 39 | + $success = true; |
|
| 40 | + $helper->loadLanguage('admin'); |
|
| 41 | 41 | |
| 42 | - // Rename uploads folder to BAK and add date to name |
|
| 43 | - $uploadDirectory = $GLOBALS['xoops']->path("uploads/$moduleDirName"); |
|
| 44 | - $dirInfo = new \SplFileInfo($uploadDirectory); |
|
| 45 | - if ($dirInfo->isDir()) { |
|
| 46 | - // The directory exists so rename it |
|
| 47 | - $date = date('Y-m-d'); |
|
| 48 | - if (!rename($uploadDirectory, $uploadDirectory . "_bak_$date")) { |
|
| 49 | - $module->setErrors(sprintf(constant('CO_' . $moduleDirNameUpper . '_' . 'ERROR_FOLDER_RENAME_FAILED'), $uploadDirectory)); |
|
| 50 | - $success = false; |
|
| 51 | - } |
|
| 52 | - } |
|
| 53 | - unset($dirInfo); |
|
| 54 | - /* |
|
| 42 | + // Rename uploads folder to BAK and add date to name |
|
| 43 | + $uploadDirectory = $GLOBALS['xoops']->path("uploads/$moduleDirName"); |
|
| 44 | + $dirInfo = new \SplFileInfo($uploadDirectory); |
|
| 45 | + if ($dirInfo->isDir()) { |
|
| 46 | + // The directory exists so rename it |
|
| 47 | + $date = date('Y-m-d'); |
|
| 48 | + if (!rename($uploadDirectory, $uploadDirectory . "_bak_$date")) { |
|
| 49 | + $module->setErrors(sprintf(constant('CO_' . $moduleDirNameUpper . '_' . 'ERROR_FOLDER_RENAME_FAILED'), $uploadDirectory)); |
|
| 50 | + $success = false; |
|
| 51 | + } |
|
| 52 | + } |
|
| 53 | + unset($dirInfo); |
|
| 54 | + /* |
|
| 55 | 55 | //------------ START ---------------- |
| 56 | 56 | //------------------------------------------------------------------ |
| 57 | 57 | // Remove xsitemap.xml from XOOPS root folder if it exists |
@@ -65,6 +65,6 @@ discard block |
||
| 65 | 65 | // return $success && $delOk; // use this if you're using this routine |
| 66 | 66 | */ |
| 67 | 67 | |
| 68 | - return $success; |
|
| 69 | - //------------ END ---------------- |
|
| 68 | + return $success; |
|
| 69 | + //------------ END ---------------- |
|
| 70 | 70 | } |
@@ -45,8 +45,8 @@ |
||
| 45 | 45 | if ($dirInfo->isDir()) { |
| 46 | 46 | // The directory exists so rename it |
| 47 | 47 | $date = date('Y-m-d'); |
| 48 | - if (!rename($uploadDirectory, $uploadDirectory . "_bak_$date")) { |
|
| 49 | - $module->setErrors(sprintf(constant('CO_' . $moduleDirNameUpper . '_' . 'ERROR_FOLDER_RENAME_FAILED'), $uploadDirectory)); |
|
| 48 | + if (!rename($uploadDirectory, $uploadDirectory."_bak_$date")) { |
|
| 49 | + $module->setErrors(sprintf(constant('CO_'.$moduleDirNameUpper.'_'.'ERROR_FOLDER_RENAME_FAILED'), $uploadDirectory)); |
|
| 50 | 50 | $success = false; |
| 51 | 51 | } |
| 52 | 52 | } |