/** * Adds inline help * * @param array $params the function params * @param object $smarty reference to the smarty object * * @return string the help html to be inserted * @access public */ function smarty_function_help($params, &$smarty) { if (!isset($params['id']) || !isset($smarty->_tpl_vars['config'])) { return; } if (empty($params['file']) && isset($smarty->_tpl_vars['tplFile'])) { $params['file'] = $smarty->_tpl_vars['tplFile']; } elseif (empty($params['file'])) { return NULL; } $params['file'] = str_replace(array('.tpl', '.hlp'), '', $params['file']); if (empty($params['title'])) { // Avod overwriting existing vars CRM-11900 $oldID = $smarty->get_template_vars('id'); $smarty->assign('id', $params['id'] . '-title'); $name = trim($smarty->fetch($params['file'] . '.hlp')); $additionalTPLFile = $params['file'] . '.extra.hlp'; if ($smarty->template_exists($additionalTPLFile)) { $name .= trim($smarty->fetch($additionalTPLFile)); } $smarty->assign('id', $oldID); } else { $name = trim(strip_tags($params['title'])); } // Escape for html $title = htmlspecialchars(ts('%1 Help', array(1 => $name))); // Escape for html and js $name = htmlspecialchars(json_encode($name), ENT_QUOTES); // Format params to survive being passed through json & the url unset($params['text'], $params['title']); foreach ($params as &$param) { $param = is_bool($param) || is_numeric($param) ? (int) $param : (string) $param; } return '<a class="helpicon" title="' . $title . '" href="#" onclick=\'CRM.help(' . $name . ', ' . json_encode($params) . '); return false;\'> </a>'; }
/** * Fetch and mix all the posts * @return array The mixed and sorted posts */ public function fetch() { $this->facebook->fetch(); $this->twitter->fetch(); $this->posts->fetch(); return $this->merge()->sort()->merged; }
/** * Fetch the result of the executed statement * @static * @param string $sql A string of the sql query * @param array $params An array of the parameter * @param int $method Fetch Method * @return array Returns an array of one from the database * @since version 2.0 */ public static function fetch($sql, $params = array(), $method = PDO::FETCH_ASSOC) { try { return self::execute($sql, $params) ? self::$stmt->fetch($method) : FALSE; } catch (PDOException $e) { return self::pdoException($e); } }
public function fetch($mode = \PDO::FETCH_ASSOC, $argument = null) { if ($argument) { $this->statement->setFetchMode($mode, $argument); return $this->statement->fetch(); } else { return $this->statement->fetch($mode); } }
/** * renders a single article's page * @param integer $id | the article's id */ public function article($id) { if (isset($id)) { // fetch it $this->article->fetch($id); // call the view method passing in the template along with the parametres $this->view('home/article', ['title' => $this->article->title, 'body' => $this->article->body, 'created' => $this->article->created]); } else { header('Location: /home/index'); } }
/** * Setter * @access public * @return array Mounts */ public function __set($name, $value) { if ($name == "SmartyBody") { if (is_array($value)) { $this->Smarty->assign($value[1]); $template_name = $value[0]; } else { $template_name = $value[0]; } $body = $this->Smarty->fetch($template_name); preg_match_all("/\\[([A-Za-z0-9]+)([^\\]]*)\\]((.*)\\[\\/\\1\\])?/si", $body, $matches); foreach ($matches[0] as $index => $variable) { switch ($matches[1][$index]) { case "subject": $this->Subject = $matches[4][$index]; break; case "settings": $str = str_replace(' ', '&', trim($matches[2][$index])); parse_str($str, $settings); if ($settings['priority']) { $this->Priority = $settings['priority']; } if ($settings['charset']) { $this->CharSet = $settings['charset']; } break; } $body = str_replace($matches[0][$index], "", $body); } $this->Body = trim($body); if ($settings['type'] == 'html') { $this->AltBody = strip_tags(trim($body)); } } }
/** * 缓存终止 * * 停止缓存记录,并且保存缓存 * 如果 $options[flash] = true,则马上输出缓存 * $options[time] = 缓存时间 * * @param array $options * @return void * @access public */ public function end($options = array()) { if ($this->_cacheID == null) { return false; } $params = array('flash' => true, 'time' => null); foreach ($options as $key => $value) { $params[$key] = $value; } $data = ob_get_contents(); ob_end_clean(); if (is_null($params['time'])) { $this->_cache->store($this->_cacheID, $data); } else { $this->_cache->store($this->_cacheID, $data, array('expireTime' => $params['time'])); } if (!is_null($this->_tableID)) { $tableCache = $this->_cache->fetch($this->_tableID); if (!$tableCache) { $tableCache = array(); } $tableCache[$this->_cacheID] = mb_strlen($data, 'UTF-8'); $this->_cache->store($this->_tableID, $tableCache); $this->_tableID = null; $this->_cacheID = null; } if ($params['flash']) { echo $data; } }
/** * 获得一条查询数据 * @param string $sql 要执行的SQL指令 * @return 一条查询数据,失败返回 FALSE。 * @access public */ public function getRow($sql) { $this->query($sql); $result = $this->PDOStatement->fetch(PDO::FETCH_ASSOC, PDO::FETCH_ORI_NEXT); $this->PDOStatement = null; return $result; }
/** * Get Total Number Of Records in Requested Table * * @param string $sTable * @return number */ public function count($sTable = '') { // if table name not pass if (!empty($sTable)) { // create count query $this->sSql = "SELECT COUNT(*) AS NUMROWS FROM {$sTable};"; // pdo prepare statement $this->_oSTH = $this->prepare($this->sSql); try { if ($this->_oSTH->execute()) { // fetch array result $this->aResults = $this->_oSTH->fetch(); // close pdo $this->_oSTH->closeCursor(); // return number of count return $this->aResults['NUMROWS']; } else { self::error($this->_oSTH->errorInfo()); } } catch (PDOException $e) { // get pdo error and pass on error method self::error($e->getMessage() . ': ' . __LINE__); } } else { self::error('Table name not found..'); } }
/** * Build the in-memory information tiers * * @access protected * @return @e void */ protected function _buildTiers() { if (!count($this->_itemCache)) { //----------------------------------------- // See if there is a specialized function // for this first //----------------------------------------- if (method_exists($this, $this->_customBuildMethod)) { $method = $this->_customBuildMethod; $this->{$method}(); return; } //----------------------------------------- // Get pages from db //----------------------------------------- $this->_sqlOrder = $this->_sqlOrder ? $this->_sqlOrder : $this->_sqlTitle; $this->DB->build(array('select' => $this->_sqlSelect, 'where' => $this->_sqlWhere, 'from' => $this->_sqlTable, 'order' => $this->_sqlOrder)); $this->DB->execute(); while ($item = $this->DB->fetch()) { if ($item[$this->_sqlParentID] < 1) { $item[$this->_sqlParentID] = 'root'; } $this->_itemCache[$item[$this->_sqlParentID]][$item[$this->_sqlPrimaryID]] = $item; $this->_itemByID[$item[$this->_sqlPrimaryID]] = $item[$this->_sqlParentID]; } } }
/** * Retourne les informations concernant les dépôts de thèmes. * * @param array $aRepositories * @return array */ public function getRepositoriesInfos($aRepositories = array()) { if (!$this->cache->contains($this->cache_repo_id)) { $this->saveRepositoriesInfosCache($aRepositories); } return $this->cache->fetch($this->cache_repo_id); }
/** * Gets the response from an API call * * @param string $endpoint API endpoint * @param array $data Query string data * @return object */ public function get($endpoint, $data = array()) { $url = $this->buildUrl($endpoint, $data); if ($cached = $this->cache->fetch($url)) { return $cached; } $response = $this->http->get($url); $responseCode = $response->getStatusCode(); if ($responseCode == 200) { $body = $response->getBody(); $this->cache->store($body, $url, $this->timeToLive); return $body; } else { return $this->returnError($responseCode); } }
/** * 头部 * @param array 参数 * @param object $smarty smarty实例 * @return string 返回HTML内容 */ function function_header($params, &$smarty) { if ($smarty->app->app_id != 'content') { return ''; } $smarty->pagedata['TITLE'] =& $smarty->pagedata['title']; $smarty->pagedata['KEYWORDS'] =& $smarty->pagedata['keywords']; $smarty->pagedata['DESCRIPTION'] =& $smarty->pagedata['description']; $smarty->pagedata['ec_res_url'] = $smarty->app->res_url; $ext_filename = $smarty->_request->get_app_name() . '_' . $smarty->_request->get_ctl_name() . '_' . $smarty->_request->get_act_name() . '.html'; if (file_exists($smarty->app->app_dir . '/view/site/common/ext/' . $ext_filename)) { $smarty->pagedata['extends_header'] = $smarty->fetch('site/common/ext/' . $ext_filename, $smarty->app->app_id); } //$ return $smarty->fetch('site/common/header.html', app::get('content')->app_id); }
/** * 调用view的fetch接口 * 将$this->vars输出到模板,并返回最后生成的字符串 * * @stability: 4 * @param string $name * @return string */ protected function fetch($templateFile = '', $content = '', $prefix = '') { if ($this->vars) { $this->view->assign($this->vars); } return $this->view->fetch($templateFile, $content, $prefix); }
/** * Fetch the topic participants * * @access public * @param int Topic ID * @param boolean Load and parse member data (TRUE for yes, FALSE for no) * @return array Array of member data indexed by member ID */ public function fetchTopicParticipants($topicID, $parseThem = FALSE) { //----------------------------------------- // INIT //----------------------------------------- $memberData = array(); $remapData = array(); //----------------------------------------- // Grab 'em //----------------------------------------- $this->DB->build(array('select' => '*', 'from' => 'message_topic_user_map', 'where' => 'map_topic_id=' . intval($topicID))); $this->DB->execute(); while ($row = $this->DB->fetch()) { $remapData[$row['map_user_id']] = $row; } if (!count($remapData)) { return array(); } /* Parse 'em? */ if ($parseThem === TRUE) { /* Grab member data */ $memberData = IPSMember::load(array_keys($remapData), 'all'); foreach ($memberData as $id => $data) { $data['_canBeBlocked'] = IPSMember::isIgnorable($data['member_group_id'], $data['mgroup_others']); $memberData[$id] = IPSMember::buildDisplayData($data, array('__all__' => 1)); $memberData[$id] = array_merge($memberData[$id], $remapData[$id]); } $remapData = $memberData; } return $remapData; }
/** * Get Area Data Custom for Mapping * @param $area_object */ function getAreaDataCustom($area_object) { // Define Area $area = array(); $area['name'] = $area_object->name; if (empty($area['name'])) { $area['name'] = 'N/A'; } $area['id'] = $area_object->id; $area['coordinates'] = $area_object->coordinates; // Check for proper coordinates pattern if (preg_match('/^[0-9\\s\\(\\)\\,\\.\\-]+$/', $area_object->coordinates)) { $fields = array(); foreach ($area_object->column_fields as $field) { $fields[$field] = $area_object->{$field}; } // Define Maps Info Window HTML by Sugar Smarty Template $this->sugarSmarty->assign("module_type", 'jjwg_Areas'); $this->sugarSmarty->assign("fields", $fields); // display fields array // Use @ error suppression to avoid issues with SugarCRM On-Demand $area['html'] = @$this->sugarSmarty->fetch('./custom/modules/jjwg_Areas/tpls/AreasInfoWindow.tpl'); if (empty($area['html'])) { $area['html'] = $this->sugarSmarty->fetch('./modules/jjwg_Areas/tpls/AreasInfoWindow.tpl'); } $area['html'] = preg_replace('/\\n\\r/', ' ', $area['html']); //var_dump($marker['html']); return $area; } else { return false; } }
/** * Makes a POST request to Twitter API * * @param mixed $aData * * @throws TwitterException * @return array with response data from Twitter API */ protected function apiPost($aData = null) { if (!is_object($this->User)) { throw new TwitterException('Object of type UserTwitter was not set'); } d('this->url: ' . $this->url); try { /** * For posting a Twitter update we must set * the authType to OAUTH_AUTH_TYPE_FORM * so that we will be using the POST method * when sending data to Twitter API */ //$authType = constant('OAUTH_AUTH_TYPE_FORM'); //d('$authType: ' . $authType); //$this->oAuth->setAuthType($authType); $this->setOAuthTokens(); d('fetching: ' . $this->url . ' data: ' . print_r($aData, 1)); $this->oAuth->fetch($this->url, $aData, OAUTH_HTTP_METHOD_POST); } catch (\OAuthException $e) { $aDebug = $this->oAuth->getLastResponseInfo(); d('debug: ' . print_r($aDebug, 1)); e('OAuthException: ' . $e->getMessage()); /** * Should NOT throw TwitterException because * we are not sure it was actually due to authorization * or maybe Twitter was bugged down or something else */ throw new TwitterException('Something went wrong during connection with Twitter. Please try again later' . $e->getMessage()); } $aResponse = $this->getResponse(); d('Twitter returned data: ' . print_r($aResponse, 1)); return $aResponse; }
/** * Start renderer / pdf-generation * @param string optional define renderer (pdf,html,return) * @access public */ public function render($_renderer = ""){ if (!empty($_renderer)) $this->_renderer = $_renderer; if ($this->_valuesAssigend == false){ $this->assignValues(); } $data = $this->_template->fetch("documents/".$this->_document["template"],$this->_view); if ($this->_renderer == "html" || !$this->_renderer){ echo $data; }elseif ($this->_renderer == "pdf"){ if ($this->_preview == true || !$this->_documentHash){ $mpdf = new mPDF("utf-8","A4","","",$this->_document["left"],$this->_document["right"],$this->_document["top"],$this->_document["bottom"]); $mpdf->WriteHTML($data); $mpdf->Output(); exit; }else { $path = Shopware()->OldPath()."files/documents"."/".$this->_documentHash.".pdf"; $mpdf = new mPDF("utf-8","A4","","",$this->_document["left"],$this->_document["right"],$this->_document["top"],$this->_document["bottom"]); $mpdf->WriteHTML($data); $mpdf->Output($path,"F"); } } }
/** * Fetches all rows from the PDOStatement object into one of our result * arrays ($this->_ResultObject or $this->_ResultArray). * * @param string $RowType The format in which the result should be returned: object or array. It * will fill a different array depending on which type is specified. */ public function FetchAllRows($RowType = FALSE) { if ($RowType === FALSE) { $RowType = $this->DefaultDatasetType; } if ($this->_PDOStatementFetched === FALSE) { if (is_object($this->_PDOStatement)) { // Get all records from the pdostatement's result set. if ($RowType == DATASET_TYPE_OBJECT) { $this->ResultObjectFetched = TRUE; $this->_PDOStatement->setFetchMode(PDO::FETCH_OBJ); while ($Row = $this->_PDOStatement->fetch()) { $this->_ResultObject[] = $Row; } } else { $this->ResultArrayFetched = TRUE; $this->_PDOStatement->setFetchMode(PDO::FETCH_ASSOC); while ($Row = $this->_PDOStatement->fetch()) { $this->_ResultArray[] = $Row; } } } $this->_PDOStatementFetched = TRUE; } }
/** * Replace the value of an attribute in the input string. Assume * the the attribute is well formed, of the type name="value". If * no replacement is mentioned the value is inserted at the end of * the form element * * @param array $params the function params * @param object $smarty reference to the smarty object * * @return string the help html to be inserted * @access public */ function smarty_function_help($params, &$smarty) { if (!isset($params['id']) || !isset($smarty->_tpl_vars['config'])) { return; } if (isset($params['file'])) { $file = $params['file']; } else { if (isset($smarty->_tpl_vars['tplFile'])) { $file = $smarty->_tpl_vars['tplFile']; } else { return; } } $file = str_replace('.tpl', '.hlp', $file); $id = urlencode($params['id']); if ($id == 'accesskeys') { $file = 'CRM/common/accesskeys.hlp'; } require_once 'CRM/Core/Config.php'; $config = CRM_Core_Config::Singleton(); $smarty->assign('id', $params['id']); $help = $smarty->fetch($file); return <<<EOT <script type="text/javascript"> cj( function() { cj(".helpicon").toolTip(); });</script> <div class="helpicon"> <span id="{$id}_help" style="display:none">{$help}</span></div> EOT; }
/** * allows for editing an article * @param integer $id */ public function edit($id) { if ($this->user->isLoggedIn()) { if (isset($id)) { // fetch the article for editing $this->article->fetch($id); if (Input::exists()) { $article_title = Input::get('title'); $article_body = Input::get('body'); // validation $this->validator->validate(['title' => [$article_title, 'required|max(100)'], 'body' => [$article_body, 'required']]); if ($this->validator->passes()) { // edit the article $this->article->edit($id, $article_title, $article_body); header('Location: /admin/content'); } } $this->view('admin/edit', ['title' => $this->article->title, 'body' => $this->article->body, 'validation_errors' => $this->validator->errors()]); } else { header('Location: /admin/content'); } } else { // user is not logged in header('Location: /admin/auth'); } }
/** * helper to retrieve single rows result * * @param bool * @return array result */ protected function getRow($removeNumeric = false) { $result = $this->statement->fetch(); if (is_array($result) && $removeNumeric !== false) { $result = $this->removeNumeric($result); } return $result; }
/** * Returns the total number of results the search will return * * @access public * @param string $search_term Search term * @param string $group_by Column to group by * @param bool $content_title_only Only search title records * @return integer */ public function getSearchCount($search_term, $group_by = '', $content_title_only = false) { /* Query the count */ $this->DB->build(array('select' => 'COUNT(*) as total_results', 'from' => 'ccs_pages', 'where' => $this->_buildWhereStatement($search_term, $content_title_only), 'group' => $group_by)); $this->DB->execute(); $search = $this->DB->fetch(); /* Return the count */ return $search['total_results']; }
/** * Fetch the first row of the sql statement with Zend_Db::FETCH_ASSOC. * * @return array */ public function FetchRow() { if ($this->fields) { $result = $this->fields; $this->fields = array(); return $result; } return $this->_statement->fetch(Zend_Db::FETCH_ASSOC); }
/** * Returns the total number of results the search will return * * @access public * @param string $search_term Search term * @param string $group_by Column to group by * @param bool $content_title_only Only search title records * @return integer */ public function getSearchCount($search_term, $group_by = '', $content_title_only = false) { /* Query the count */ $this->DB->build(array('select' => 'COUNT(*) as total_results', 'from' => array('members' => 'm'), 'where' => $this->_buildWhereStatement($search_term, $content_title_only), 'group' => $group_by, 'add_join' => array(array('from' => array('profile_portal' => 'p'), 'where' => "p.pp_member_id=m.member_id", 'type' => 'left')))); $this->DB->execute(); $search = $this->DB->fetch(); /* Return the count */ return $search['total_results']; }
/** * Fetch data from an api. * * @param string $url * @access public * @return mixed */ public function fetchAPI($url) { $url .= '?lang=' . str_replace('-', '_', $this->app->getClientLang()); $this->agent->fetch($url); $result = json_decode($this->agent->results); if (!isset($result->status)) { return false; } if ($result->status != 'success') { return false; } if (isset($result->data) and md5($result->data) != $result->md5) { return false; } if (isset($result->data)) { return json_decode($result->data); } }
/** * Read cache from files or db. * * @param string The cache component to read. * @param boolean If true, cannot be overwritten during script execution. * @return unknown */ function read($name, $hard = false) { global $db, $mybb; // Already have this cache and we're not doing a hard refresh? Return cached copy if (isset($this->cache[$name]) && $hard == false) { return $this->cache[$name]; } else { if ($hard == false && !is_object($this->handler)) { return false; } } if (is_object($this->handler)) { get_execution_time(); $data = $this->handler->fetch($name); $call_time = get_execution_time(); $this->call_time += $call_time; $this->call_count++; if ($mybb->debug_mode) { $hit = true; if ($data === false) { $hit = false; } $this->debug_call('read:' . $name, $call_time, $hit); } // No data returned - cache gone bad? if ($data === false) { // Fetch from database $query = $db->simple_select("datacache", "title,cache", "title='" . $db->escape_string($name) . "'"); $cache_data = $db->fetch_array($query); $data = unserialize($cache_data['cache']); // Update cache for handler get_execution_time(); $hit = $this->handler->put($name, $data); $call_time = get_execution_time(); $this->call_time += $call_time; $this->call_count++; if ($mybb->debug_mode) { $this->debug_call('set:' . $name, $call_time, $hit); } } } else { $query = $db->simple_select("datacache", "title,cache", "title='{$name}'"); $cache_data = $db->fetch_array($query); if (!$cache_data['title']) { $data = false; } else { $data = unserialize($cache_data['cache']); } } // Cache locally $this->cache[$name] = $data; if ($data !== false) { return $data; } else { return false; } }
/** This method executes a single query @access public @throws PDOException object @return array */ public function single() { try { self::execute(); return $this->Stmt->fetch(PDO::FETCH_ASSOC); } catch (PDOException $e) { throw $e; } }
/** * Charge la liste des langues actives. * * @return void */ public function load() { if (!$this->cache->contains($this->cache_id)) { $this->generateCacheList(); } $this->list = $this->cache->fetch($this->cache_id); $this->num = count($this->list); $this->unique = (bool) ($this->num == 1); }
/** * Generate the checkout step * @return string */ public function generate() { $objFormConfig = \FormModel::findByPk($this->objModule->iso_order_conditions); $this->objForm = new Form($this->objModule->getFormId(), 'POST', function ($haste) { return \Input::post('FORM_SUBMIT') === $haste->getFormId(); }, (bool) $objFormConfig->tableless); // Don't catch the exception here because we want it to be shown to the user $this->objForm->addFieldsFromFormGenerator($this->objModule->iso_order_conditions, function ($strName, &$arrDca) { $arrDca['value'] = $_SESSION['FORM_DATA'][$strName] ?: $arrDca['value']; return true; }); // Change enctype if there are uploads if ($this->objForm->hasUploads()) { $this->objModule->Template->enctype = 'multipart/form-data'; } if ($this->objForm->isSubmitted()) { $this->blnError = !$this->objForm->validate(); $_SESSION['FORM_DATA'] = is_array($_SESSION['FORM_DATA']) ? $_SESSION['FORM_DATA'] : array(); foreach (array_keys($this->objForm->getFormFields()) as $strField) { if ($this->objForm->getWidget($strField) instanceof \uploadable) { $arrFile = $_SESSION['FILES'][$strField]; $varValue = str_replace(TL_ROOT . '/', '', dirname($arrFile['tmp_name'])) . '/' . rawurlencode($arrFile['name']); } else { $varValue = $this->objForm->fetch($strField); } $_SESSION['FORM_DATA'][$strField] = $varValue; } } else { $blnError = false; foreach (array_keys($this->objForm->getFormFields()) as $strField) { // Clone widget because otherwise we add errors to the original widget instance $objClone = clone $this->objForm->getWidget($strField); $objClone->validate(); if ($objClone->hasErrors()) { $blnError = true; break; } } $this->blnError = $blnError; } $objTemplate = new \Isotope\Template('iso_checkout_order_conditions'); $this->objForm->addToTemplate($objTemplate); return $objTemplate->parse(); }