/** * Constructor for the base resource class * * Constructor for the base resource class. * If cmid is set create the cm, course, resource objects. * and do some checks to make sure people can be here, and so on. * * @param cmid integer, the current course module id - not set for new resources */ function resource_base($cmid = 0) { global $CFG, $COURSE; $this->navlinks = array(); if ($cmid) { if (!($this->cm = get_coursemodule_from_id('resource', $cmid))) { error("Course Module ID was incorrect"); } if (!($this->course = get_record("course", "id", $this->cm->course))) { error("Course is misconfigured"); } if (!($this->resource = get_record("resource", "id", $this->cm->instance))) { error("Resource ID was incorrect"); } $this->strresource = get_string("modulename", "resource"); $this->strresources = get_string("modulenameplural", "resource"); if (!$this->cm->visible and !has_capability('moodle/course:viewhiddenactivities', get_context_instance(CONTEXT_MODULE, $this->cm->id))) { $pagetitle = strip_tags($this->course->shortname . ': ' . $this->strresource); $navigation = build_navigation($this->navlinks, $this->cm); print_header($pagetitle, $this->course->fullname, $navigation, "", "", true, '', navmenu($this->course, $this->cm)); notice(get_string("activityiscurrentlyhidden"), "{$CFG->wwwroot}/course/view.php?id={$this->course->id}"); } } else { $this->course = $COURSE; } }
/** * @param string $db_host * @param string $db_username * @param string $db_password * @param string $db_name */ public function __construct($db_host, $db_username, $db_password, $db_name) { $this->link_id = mysqli_connect($db_host, $db_username, $db_password, $db_name); if (!$this->link_id) { error('Unable to connect to MySQL server. MySQL reported: ' . mysqli_error($this->link_id), __FILE__, __LINE__); } }
function _apply_access_policy($object, $action) { $access_policy =& access_policy::instance(); if (!$access_policy->save_object_access_for_action($object, $action)) { error('access template for action not defined', __FILE__ . ' : ' . __LINE__ . ' : ' . __FUNCTION__, array('action' => $action)); } }
function static_method($eventdata) { static $called = 0; static $ignorefail = false; if ($eventdata == 'status') { return $called; } else { if ($eventdata == 'reset') { $called = 0; $ignorefail = false; return; } else { if ($eventdata == 'fail') { if ($ignorefail) { $called++; return true; } else { return false; } } else { if ($eventdata == 'ignorefail') { $ignorefail = true; return; } else { if ($eventdata == 'ok') { $called++; return true; } } } } } error('Incorrect eventadata submitted: ' . $eventdata); }
/** * Tries to login a user and populates self::$data on success. * * @param string $login user login * @param string $password user password * * @throws Exception if user cannot be logged in * * @return bool */ public static function login($login, $password) { try { self::setDefault(); self::$data = API::User()->login(array('user' => $login, 'password' => $password, 'userData' => true)); if (!self::$data) { throw new Exception(); } if (self::$data['gui_access'] == GROUP_GUI_ACCESS_DISABLED) { error(_('GUI access disabled.')); throw new Exception(); } if (empty(self::$data['url'])) { self::$data['url'] = CProfile::get('web.menu.view.last', 'index.php'); } $result = (bool) self::$data; if (isset(self::$data['attempt_failed']) && self::$data['attempt_failed']) { CProfile::init(); CProfile::update('web.login.attempt.failed', self::$data['attempt_failed'], PROFILE_TYPE_INT); CProfile::update('web.login.attempt.ip', self::$data['attempt_ip'], PROFILE_TYPE_STR); CProfile::update('web.login.attempt.clock', self::$data['attempt_clock'], PROFILE_TYPE_INT); $result &= CProfile::flush(); } // remove guest session after successful login $result &= DBexecute('DELETE FROM sessions WHERE sessionid=' . zbx_dbstr(get_cookie('zbx_sessionid'))); if ($result) { self::setSessionCookie(self::$data['sessionid']); add_audit_ext(AUDIT_ACTION_LOGIN, AUDIT_RESOURCE_USER, self::$data['userid'], '', null, null, null); } return $result; } catch (Exception $e) { self::setDefault(); return false; } }
public static function checkAuthentication($sessionid) { try { if ($sessionid !== null) { self::$data = API::User()->checkAuthentication($sessionid); } if ($sessionid === null || empty(self::$data)) { self::setDefault(); self::$data = API::User()->login(array('user' => ZBX_GUEST_USER, 'password' => '', 'userData' => true)); if (empty(self::$data)) { clear_messages(1); throw new Exception(); } $sessionid = self::$data['sessionid']; } if (self::$data['gui_access'] == GROUP_GUI_ACCESS_DISABLED) { error(_('GUI access disabled.')); throw new Exception(); } zbx_setcookie('zbx_sessionid', $sessionid, self::$data['autologin'] ? time() + SEC_PER_DAY * 31 : 0); return true; } catch (Exception $e) { self::setDefault(); return false; } }
function module_f() { $input_id = $this->trans_lib->safe("input"); if (!$input_id) { error("未定义标识串!"); } $id = $this->trans_lib->int("id"); if (!$id) { error("未定义模块!"); } $this->tpl->assign("input_id", $input_id); $this->tpl->assign("id", $id); //取得主题列表 $pageurl = $this->url("subject,module"); $pageurl .= "input=" . rawurlencode($input_id) . "&id=" . $id . "&"; // $this->list_m->set_condition("m.langid='" . $_SESSION["sys_lang_id"] . "'"); //区分语言 $this->list_m->set_condition("m.module_id='" . $id . "'"); $pageid = $this->trans_lib->int(SYS_PAGEID); $rslist = $this->list_m->get_list($pageid); $this->tpl->assign("rslist", $rslist); $total_count = $this->list_m->get_count(); //取得总数 $pagelist = $this->page_lib->page($page_url, $total_count); $this->tpl->assign("pagelist", $pagelist); $this->tpl->display("subject/module.html"); }
function fully_interactive($argv) { if (!is_dir('app')) { error("Couldn't find \"app\" folder in path, please run from a Magento sub-directory."); } $code_pool = trim(input("What code pool?")); $package = trim(input("What package?")); $module = trim(input("What module?")); $path = get_config_path($code_pool, $package, $module); echo "Loading: " . $path . "\n"; $xml = simplexml_load_file($path); $xVersion = $xml->modules->{$package . '_' . $module}->version; $version = (string) $xVersion; echo "Current Version: " . $version . "\n"; //list($major, $minor, $bugfix) = explode(".", $version); $parts = explode(".", $version); $index = get_version_index(); $parts[$index]++; $version_new = implode(".", $parts); $xVersion[0] = $version_new; $xml = $xml->asXml(); if (simplexml_load_string($xml)) { file_put_contents($path, $xml); } echo "Updated {$path} to {$version_new}\n"; }
function _init() { global $G; $G['TITLE'] = TITLE; $G['ME'] = basename($_SERVER['SCRIPT_FILENAME']); // initialize display vars foreach (array('MESSAGES', 'ERRORS', 'CONTENT') as $v) { $G[$v] = ""; } // create the table try { $db = new bwSQLite3(DB_FILENAME, TABLE_NAME); $tn = TABLE_NAME; $db->sql_do("drop table if exists {$tn}"); $db->sql_do("create table {$tn} ( id integer primary key, animal text, sound text )"); // insert some rows $db->sql_do("insert into {$tn} (animal, sound) values (?, ?)", 'cat', 'Purr'); $db->sql_do("insert into {$tn} (animal, sound) values (?, ?)", 'dog', 'Woof'); $db->sql_do("insert into {$tn} (animal, sound) values (?, ?)", 'duck', 'Quack'); $db->sql_do("insert into {$tn} (animal, sound) values (?, ?)", 'bear', 'Grrr'); } catch (PDOException $e) { error($e->getMessage()); } $G['db'] = $db; }
function post_generate(&$code) { $js = ''; if(isset($link->attributes['active_tab'])) $active_tab = $link->attributes['active_tab']; else $active_tab = reset($this->tabs); if(!$this->tabs || !$active_tab || !in_array($active_tab, $this->tabs)) { error('INVALID_TABS_DECLARATION', __FILE__ . ' : ' . __LINE__ . ' : ' . __FUNCTION__, array('tag' => $this->tag, 'description' => 'check your tabs settings', 'file' => $this->source_file, 'line' => $this->starting_line_no)); } foreach($this->tabs as $id) $js .= "tabs.register_tab_item('{$id}');\n"; $js .= "tabs.activate('{$active_tab}');\n"; $code->write_html(" <script type='text/javascript'> var tabs = new tabs_container(); {$js} </script>"); parent :: post_generate($code); }
public function update($post) { if (empty($_POST['body'])) { error(__("Error"), __("Body can't be blank.")); } $post->update(array("title" => $_POST['title'], "body" => $_POST['body'])); }
/** * Comment wall initialisation. */ function commentwall_init() { global $CFG, $db, $function, $metatags, $template; // Add meta tags $metatags .= "<script type=\"text/javascript\" src=\"{$CFG->wwwroot}mod/commentwall/commentwall.js\"><!-- commentwall js --></script>"; // Define some templates templates_add_context('commentwallobject', 'mod/commentwall/template'); templates_add_context('commentwallfooter', 'mod/commentwall/footer'); templates_add_context('css', 'mod/commentwall/css'); // Set up the database $tables = $db->Metatables(); if (!in_array($CFG->prefix . "commentwall", $tables)) { if (file_exists($CFG->dirroot . "mod/commentwall/{$CFG->dbtype}.sql")) { modify_database($CFG->dirroot . "mod/commentwall/{$CFG->dbtype}.sql"); //reload system header_redirect($CFG->wwwroot); } else { error("Error: Your database ({$CFG->dbtype}) is not yet fully supported by the Elgg commentwall. See the mod/commentwall directory."); } print_continue($CFG->wwwroot); exit; } // Add configuration options $function['userdetails:edit:details'][] = $CFG->dirroot . "mod/commentwall/lib/commentwall_settings.php"; }
function add() { $this->system->add_breadcrumb('Data resources', '_cpanel/admin/resources/data'); $this->system->add_breadcrumb('Tambah resources'); if (isset($_POST['save_resources'])) { $name = trim($_POST['name']); if ($name == '') { $data['msg'] = error("Resources name is required"); } else { $is_available = $this->adodb->GetOne("SELECT COUNT(*) FROM sys_resources WHERE `name` = '{$name}'"); if ($is_available > 0) { $data['msg'] = error("Resources for \"{$name}\" is available on DB. Please use another name"); } else { $parent_id = (int) $_POST['parent_id']; $insert = $this->adodb->Execute("INSERT INTO sys_resources SET parent_id = '{$parent_id}',`name` = '{$name}'"); if ($insert) { $data['msg'] = success("New resources has been saved successfully"); } } } } $data['resources'] = array_resources(); $data['module'] = "_cpanel"; $data['page'] = "layout_add_resources"; $this->load->view($this->layout_content, $data); }
function tex_filter_get_executable($debug = false) { global $CFG; $error_message1 = "Your system is not configured to run mimeTeX. You need to download the appropriate<br />" . "executable for you " . PHP_OS . " platform from <a href=\"http://moodle.org/download/mimetex/\">" . "http://moodle.org/download/mimetex/</a>, or obtain the C source<br /> " . "from <a href=\"http://www.forkosh.com/mimetex.zip\">" . "http://www.forkosh.com/mimetex.zip</a>, compile it and " . "put the executable into your<br /> moodle/filter/tex/ directory."; $error_message2 = "Custom mimetex is not executable!<br /><br />"; if (PHP_OS == "WINNT" || PHP_OS == "WIN32" || PHP_OS == "Windows") { return "{$CFG->dirroot}/filter/tex/mimetex.exe"; } $custom_commandpath = "{$CFG->dirroot}/filter/tex/mimetex"; if (file_exists($custom_commandpath)) { if (is_executable($custom_commandpath)) { return $custom_commandpath; } else { error($error_message2 . $error_message1); } } switch (PHP_OS) { case "Linux": return "{$CFG->dirroot}/filter/tex/mimetex.linux"; case "Darwin": return "{$CFG->dirroot}/filter/tex/mimetex.darwin"; case "FreeBSD": return "{$CFG->dirroot}/filter/tex/mimetex.freebsd"; } error($error_message1); }
function index_f() { $id = $this->trans_lib->int("id"); if (!$id) { error($this->lang["download_error"], $this->url()); } $rs = $this->upfile_m->get_one($id); //执行下载操作 if (!file_exists(ROOT . $rs["filename"]) || !$rs["filename"] || !is_file(ROOT . $rs["filename"])) { error($this->lang["download_empty"], $this->url()); } $filesize = filesize(ROOT . $rs["filename"]); if (!$rs["title"]) { $rs["title"] = $rs["filename"]; } $tmpname = str_replace("." . $rs["ftype"], "", $rs["title"]); $tmpname = $tmpname . "." . $rs["ftype"]; ob_end_clean(); header("Date: " . gmdate("D, d M Y H:i:s", $rs["postdate"]) . " GMT"); header("Last-Modified: " . gmdate("D, d M Y H:i:s", $rs["postdate"]) . " GMT"); header("Content-Encoding: none"); header("Content-Disposition: attachment; filename=" . rawurlencode($tmpname)); header("Content-Length: " . $filesize); header("Accept-Ranges: bytes"); readfile($rs["filename"]); flush(); ob_flush(); }
/** * Called to define this moodle form * * @return void */ public function definition() { global $DB; $mform =& $this->_form; $course = $this->_customdata['course']; $cm = $this->_customdata['cm']; $modcontext = $this->_customdata['modcontext']; $sessionid = $this->_customdata['sessionid']; if (!($sess = $DB->get_record('attcontrol_sessions', array('id' => $sessionid)))) { error('No such session in this course'); } $dhours = floor($sess->duration / HOURSECS); $dmins = floor(($sess->duration - $dhours * HOURSECS) / MINSECS); $defopts = array('maxfiles' => EDITOR_UNLIMITED_FILES, 'noclean' => true, 'context' => $modcontext); $data = array('sessiondate' => $sess->sessdate, 'durtime' => array('hours' => $dhours, 'minutes' => $dmins), 'description' => $sess->description); $mform->addElement('header', 'general', get_string('changesession', 'attcontrol')); $mform->addElement('static', 'olddate', get_string('olddate', 'attcontrol'), userdate($sess->sessdate, get_string('strftimedmyhm', 'attcontrol'))); $mform->addElement('date_time_selector', 'sessiondate', get_string('newdate', 'attcontrol')); for ($i = 0; $i <= 23; $i++) { $hours[$i] = sprintf("%02d", $i); } for ($i = 0; $i < 60; $i += 5) { $minutes[$i] = sprintf("%02d", $i); } $durselect[] =& $mform->createElement('select', 'hours', '', $hours); $durselect[] =& $mform->createElement('select', 'minutes', '', $minutes, false, true); $mform->addGroup($durselect, 'durtime', get_string('duration', 'attcontrol'), array(' '), true); $mform->addElement('textarea', 'description', get_string("description", "attcontrol"), 'wrap="virtual" rows="10" cols="100"'); $mform->setDefaults($data); $submit_string = get_string('update', 'attcontrol'); $this->add_action_buttons(true, $submit_string); }
function initialize_cart_handler(&$handler) { if($handler === null) { switch(CART_DEFAULT_HANDLER_TYPE) { case 'session': include_once(LIMB_DIR . '/core/model/shop/handlers/session_cart_handler.class.php'); $this->_cart_handler =& new session_cart_handler($this->_cart_id); break; case 'db': include_once(LIMB_DIR . '/core/model/shop/handlers/db_cart_handler.class.php'); $this->_cart_handler =& new db_cart_handler($this->_cart_id); break; default: error('unknown default cart handler type', __FILE__ . ' : ' . __LINE__ . ' : ' . __FUNCTION__, array('type' => CART_DEFAULT_HANDLER_TYPE)); } $this->_cart_handler->reset(); } else { $this->_cart_handler =& $handler; $this->_cart_handler->set_cart_id($this->_cart_id); $this->_cart_handler->reset(); } }
/** * Add a question to a quiz * * Adds a question to a quiz by updating $quiz as well as the * quiz and quiz_question_instances tables. It also adds a page break * if required. * @return boolean false if the question was already in the quiz * @param int $id The id of the question to be added * @param object $quiz The extended quiz object as used by edit.php * This is updated by this function */ function quiz_add_quiz_question($id, &$quiz) { $questions = explode(",", $quiz->questions); if (in_array($id, $questions)) { return false; } // remove ending page break if it is not needed if ($breaks = array_keys($questions, 0)) { // determine location of the last two page breaks $end = end($breaks); $last = prev($breaks); $last = $last ? $last : -1; if (!$quiz->questionsperpage or $end - $last - 1 < $quiz->questionsperpage) { array_pop($questions); } } // add question $questions[] = $id; // add ending page break $questions[] = 0; // Save new questionslist in database $quiz->questions = implode(",", $questions); if (!set_field('quiz', 'questions', $quiz->questions, 'id', $quiz->id)) { error('Could not save question list'); } // update question grades $questionrecord = get_record("question", "id", $id); $quiz->grades[$id] = $questionrecord->defaultgrade; quiz_update_question_instance($quiz->grades[$id], $id, $quiz->instance); return true; }
/** * Returns the user information for 'external' users. In this case the * attributes provided by Shibboleth * * @return array $result Associative array of user data */ function get_userinfo($username) { // reads user information from shibboleth attributes and return it in array() global $CFG; // Check whether we have got all the essential attributes if (empty($_SERVER[$this->config->user_attribute])) { error(get_string('shib_not_all_attributes_error', 'auth', "'" . $this->config->user_attribute . "' ('" . $_SERVER[$this->config->user_attribute] . "'), '" . $this->config->field_map_firstname . "' ('" . $_SERVER[$this->config->field_map_firstname] . "'), '" . $this->config->field_map_lastname . "' ('" . $_SERVER[$this->config->field_map_lastname] . "') and '" . $this->config->field_map_email . "' ('" . $_SERVER[$this->config->field_map_email] . "')")); } $attrmap = $this->get_attributes(); $result = array(); $search_attribs = array(); foreach ($attrmap as $key => $value) { // Check if attribute is present if (!isset($_SERVER[$value])) { $result[$key] = ''; continue; } // Make usename lowercase if ($key == 'username') { $result[$key] = strtolower($this->get_first_string($_SERVER[$value])); } else { $result[$key] = $this->get_first_string($_SERVER[$value]); } } // Provide an API to modify the information to fit the Moodle internal // data representation if ($this->config->convert_data && $this->config->convert_data != '' && is_readable($this->config->convert_data)) { // Include a custom file outside the Moodle dir to // modify the variable $moodleattributes include $this->config->convert_data; } return $result; }
function enforce($condition, $message = 'Enforcement failed') { if (!$condition) { error($message); } return $condition; }
function pre_parse() { if (!array_key_exists('attributes', $this->attributes) || empty($this->attributes['attributes'])) { error('MISSINGREQUIREATTRIBUTE', __FILE__ . ' : ' . __LINE__ . ' : ' . __FUNCTION__, array('tag' => $this->tag, 'attribute' => 'attributes', 'file' => $this->source_file, 'line' => $this->starting_line_no)); } return PARSER_REQUIRE_PARSING; }
function definition() { global $CFG; $mform =& $this->_form; // this hack is needed for different settings of each subtype if (!empty($this->_instance)) { if ($res = get_record('resource', 'id', (int) $this->_instance)) { $type = $res->type; } else { error('incorrect assignment'); } } else { $type = required_param('type', PARAM_ALPHA); } $mform->addElement('hidden', 'type', $type); $mform->setDefault('type', $type); require $CFG->dirroot . '/mod/resource/type/' . $type . '/resource.class.php'; $resclass = 'resource_' . $type; $this->_resinstance = new $resclass(); //------------------------------------------------------------------------------- $mform->addElement('header', 'general', get_string('general', 'form')); // $mform->addElement('static', 'statictype', get_string('assignmenttype', 'assignment'), get_string('type'.$type,'assignment')); $mform->addElement('text', 'name', get_string('name'), array('size' => '48')); $mform->setType('name', PARAM_TEXT); $mform->addRule('name', null, 'required', null, 'client'); $mform->addElement('htmleditor', 'summary', get_string('summary')); $mform->setType('summary', PARAM_RAW); $mform->setHelpButton('summary', array('summary', get_string('summary'), 'resource')); // summary should be optional again MDL-9485 //$mform->addRule('summary', get_string('required'), 'required', null, 'client'); $mform->addElement('header', 'typedesc', get_string('resourcetype' . $type, 'resource')); $this->_resinstance->setup_elements($mform); $this->standard_coursemodule_elements(array('groups' => false, 'groupmembersonly' => true, 'gradecat' => false)); $this->add_action_buttons(); }
function updateRegexp(array $regexp, array $expressions) { try { $regexpId = $regexp['regexpid']; unset($regexp['regexpid']); // check existence if (!getRegexp($regexpId)) { throw new Exception(_('Regular expression does not exist.')); } // check required fields $dbFields = array('name' => null); if (!check_db_fields($dbFields, $regexp)) { throw new Exception(_('Incorrect arguments passed to function') . ' [updateRegexp]'); } // check duplicate name $dbRegexp = DBfetch(DBselect('SELECT re.regexpid' . ' FROM regexps re' . ' WHERE re.name=' . zbx_dbstr($regexp['name']) . andDbNode('re.regexpid'))); if ($dbRegexp && bccomp($regexpId, $dbRegexp['regexpid']) != 0) { throw new Exception(_s('Regular expression "%s" already exists.', $regexp['name'])); } rewriteRegexpExpressions($regexpId, $expressions); DB::update('regexps', array('values' => $regexp, 'where' => array('regexpid' => $regexpId))); } catch (Exception $e) { error($e->getMessage()); return false; } return true; }
public function getEdit($id) { if (!($row = $this->contract->row($id))) { return error(404); } return $this->layout(['row' => $row]); }
function download($id) { $this->checkLogin(); if (!empty($id)) { if (!isset($_SESSION['filedownloads'])) { $_SESSION['filedownloads'] = 0; } if ($_SESSION['filedownloads'] >= MAX_FILEDOWNLOADS) { $cache_expire = session_cache_expire(); error("Bạn đã download quá nhiều file. Vui lòng đợi {$cache_expire} phút để download file tiếp theo!"); } $this->file->id = $id; $data = $this->file->search(); if (empty($data)) { error("File download không tồn tại!"); } $data = $data["file"]; if ($data["account_share"] != null) { $account_id = $_SESSION["account"]["id"]; if ($account_id != $data["account_share"] && $account_id != $data["account_id"]) { error("Bạn không được phép download file này!"); } } $_SESSION['filedownloads'] = $_SESSION['filedownloads'] + 1; redirect($data["fileurl"]); } }
public function getJsApiTicket() { if (!empty($_W['account']['jsapi_ticket']) && is_array($_W['account']['jsapi_ticket']) && !empty($_W['account']['jsapi_ticket']['ticket']) && !empty($_W['account']['jsapi_ticket']['expire']) && $_W['account']['jsapi_ticket']['expire'] > TIMESTAMP) { return $_W['account']['jsapi_ticket']['ticket']; } load()->func('communication'); $access_token = $this->getAccessToken(); if (is_error($access_token)) { return $access_token; } $url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token={$access_token}&type=jsapi"; $content = ihttp_get($url); if (is_error($content)) { return error(-1, '调用接口获取微信公众号 jsapi_ticket 失败, 错误信息: ' . $content['message']); } $result = @json_decode($content['content'], true); if (empty($result) || intval($result['errcode']) != 0 || $result['errmsg'] != 'ok') { return error(-1, '获取微信公众号 jsapi_ticket 结果错误, 错误信息: ' . $result['errmsg']); } $record = array(); $record['ticket'] = $result['ticket']; $record['expire'] = TIMESTAMP + $result['expires_in'] - 200; $row = array(); $row['jsapi_ticket'] = iserializer($record); pdo_update('account_wechats', $row, array('acid' => $_W['account']['acid'])); $_W['account']['jsapi_ticket'] = $record; return $record['ticket']; }
function game_importsnakes_do($newrec) { if (!insert_record('game_snakes_database', $newrec)) { print_object($newrec); error("Can't insert to table game_snakes_database"); } }
function autoHookRegistBeforeCommit(&$name, &$email, &$sub, &$com, &$category, &$age, $dest, $isReply, $imgWH, &$status) { if ($dest !== '' && ($this->MIN_W && $this->MIN_W > $imgWH[2] || $this->MIN_H && $this->MIN_H > $imgWH[3] || $this->MAX_W && $imgWH[2] > $this->MAX_W || $this->MAX_H && $imgWH[3] > $this->MAX_H || $this->MIN_FILESIZE && $this->MIN_FILESIZE > filesize($dest))) { unlink($dest); error('圖像大小不符限制。'); } }
public function getPosition($from = 1, $count = 1) { $console = Console::getInstance(); $console->operationStart('Collecting search results'); $this->pageNumber = ceil($from / $this->positionsPerPage); if ($count < 1 || $count > 10) { $console->operationEnd(); $console - error('Count must be in 1-10. ' . $count . ' is setted'); return false; } $sites = array(); $position = 1; do { $console->operationStep(); $pageResults = $this->getPageResults(); foreach ($pageResults as $pr) { $sitesCount = count($sites); $domain = ($domain = String::rebuildUrl($pr->url, false, false, true, false)) ? $domain : $pr->url; if (IgnoreList::isInList($domain) || $sitesCount && $sites[$sitesCount - 1]->domain == $domain) { continue; } $site = new Site(); $site->name = strip_tags($pr->title); $site->position = $position++; $site->link = $pr->url; $site->domain = $domain; $sites[] = $site; } $this->pageNumber++; } while ($sitesCount < $count); //$this->pageNumber++ * $this->positionsPerPage < $count // old $console->operationEnd(); return array_slice($sites, 0, $count); }
function OpcionesBusqueda($retorno) { global $action; $ot = getTemplate("xulBusquedaAvanzada"); if (!$ot) { error(__FILE__ . __LINE__, "Info: template no encontrado"); return false; } $idprov = getSesionDato("FiltraProv"); $idmarca = getSesionDato("FiltraMarca"); $idcolor = getSesionDato("FiltraColor"); $idtalla = getSesionDato("FiltraTalla"); $idfamilia = getSesionDato("FiltraFamilia"); $ot->fijar("action", $action); $ot->fijar("pagRetorno", $retorno); $ot->fijar("comboProveedores", genXulComboProveedores($idprov)); $ot->fijar("comboMarcas", genXulComboMarcas($idmarca)); $ot->fijar("comboFamilias", genXulComboMarcas($idfamilia)); //echo q($idcolor,"color a mostrar en template"); //echo q(intval($idcolor),"intval color a mostrar en template"); if (intval($idcolor) >= 0) { $ot->fijar("comboColores", genXulComboColores($idcolor)); } else { $ot->fijar("comboColores", genXulComboColores("ninguno")); } $ot->fijar("comboTallas", genXulComboTallas($idtalla)); echo $ot->Output(); }