function multi_array_search($needle, $haystack) { if (is_array($haystack)) { foreach (array_keys($haystack) as $key) { $value =& $haystack[$key]; $result = multi_array_search($needle, $value); if (is_array($result)) { $return = $result; array_unshift($return, $key); return $return; } elseif ($result == TRUE) { $return[] = $key; return $return; } } return FALSE; } else { if ($needle === $haystack) { return TRUE; } else { return FALSE; } } }
function clearNotMetPrerequisitesValidationResultsDataForAllPosteriorSteps($step_id) { $prerequisitesForAllSteps = $this->getPrerequisitesINI(); /* the consequence of the steps (which of them follows which, how many steps at all...) in the Checkout CZ is not specified. Suppose, that the number of prerequisites can increase during the process. */ $next_step_id = $step_id + 1; //$step_id can be the last step if (isset($prerequisitesForAllSteps[$next_step_id])) { foreach ($this->PrerequisitesValidationResults as $PrerequisiteName => $PrerequisiteInfo) { if (!in_array($PrerequisiteName, $prerequisitesForAllSteps[$next_step_id]) && multi_array_search($PrerequisiteName, $prerequisitesForAllSteps)) { $ValidatedData =& $this->PrerequisitesValidationResults[$PrerequisiteName]; if ($ValidatedData["isMet"] == false) { $ValidatedData["error_code"] = ""; if (!empty($ValidatedData["validatedData"])) { foreach ($ValidatedData["validatedData"] as $PersonInfoAttributeName => $data) { // echo '_'.$PersonInfoAttributeName.'<br>'; $data =& $ValidatedData["validatedData"][$PersonInfoAttributeName]; if ($data["error_code_full"] != "" || $data["error_code_short"] != "") { $data["value"] = ""; $data["error_code_full"] = ""; $data["error_code_short"] = ""; } unset($data); } } } unset($ValidatedData); } } } }
$tplVars['feedlink'] = $GLOBALS['root']; $tplVars['feeddescription'] = sprintf(T_('Recent bookmarks posted to %s'), $GLOBALS['sitename']); $bookmarks =& $bookmarkservice->getBookmarks(0, 15, $userid, $cat, NULL, getSortOrder(), $watchlist); $bookmarks_tmp =& filter($bookmarks['bookmarks']); $bookmarks_tpl = array(); foreach (array_keys($bookmarks_tmp) as $key) { $row =& $bookmarks_tmp[$key]; $_link = $row['bAddress']; // Redirection option if ($GLOBALS['useredir']) { $_link = $GLOBALS['url_redir'] . $_link; } $_pubdate = date("r", strtotime($row['bDatetime'])); $uriparts = explode('.', $_link); $extension = end($uriparts); unset($uriparts); $enclosure = array(); if ($keys = multi_array_search($extension, $GLOBALS['filetypes'])) { $enclosure['mime'] = file_get_mimetype($_link); $enclosure['length'] = file_get_filesize($_link); } $bookmarks_tpl[] = array('title' => $row['bTitle'], 'link' => $_link, 'description' => $row['bDescription'], 'creator' => $row['username'], 'pubdate' => $_pubdate, 'tags' => $row['tags'], 'enclosure_mime' => $enclosure['mime'], 'enclosure_length' => $enclosure['length']); } unset($bookmarks_tmp); unset($bookmarks); $tplVars['bookmarks'] =& $bookmarks_tpl; $templateservice->loadTemplate('rss.tpl', $tplVars); if ($usecache) { // Cache output if existing copy has expired $cacheservice->End($hash); }
/** * Attach tags to a bookmark. * * Make sure that categories is an array of trimmed strings. * If the categories are coming in from an API call, be sure * that underscores are converted into strings. * * @param integer $bookmarkid ID of the bookmark * @param array $tags Array of tags (strings, trimmed) * @param boolean $fromApi If this is from an API call * @param string $extension File extension (i.e. 'pdf') * @param boolean $replace If existing tags for this bookmark * are to be replaced * @param boolean $fromImport If this is from a file import * * @return boolean True if all went well */ public function attachTags($bookmarkid, $tags, $fromApi = false, $extension = null, $replace = true, $fromImport = false) { if (!is_array($tags)) { $tags = trim($tags); if ($tags != '') { if (substr($tags, -1) == ',') { $tags = substr($tags, 0, -1); } if ($fromApi) { $tags = explode(' ', $tags); } else { $tags = explode(',', $tags); } } else { $tags = null; } } $tagservice = SemanticScuttle_Service_Factory::get('Tag'); $tags = $tagservice->normalize($tags); $tags_count = is_array($tags) ? count($tags) : 0; for ($i = 0; $i < $tags_count; $i++) { $tags[$i] = trim(utf8_strtolower($tags[$i])); if ($fromApi) { include_once 'SemanticScuttle/functions.php'; $tags[$i] = convertTag($tags[$i], 'in'); } } if ($tags_count > 0) { // Remove system tags $tags = array_filter($tags, array($this, "isNotSystemTag")); // Eliminate any duplicate categories $temp = array_unique($tags); $tags = array_values($temp); } else { // Unfiled $tags[] = 'system:unfiled'; } // Media and file types if (!is_null($extension)) { include_once 'SemanticScuttle/functions.php'; if ($keys = multi_array_search($extension, $GLOBALS['filetypes'])) { $tags[] = 'system:filetype:' . $extension; $tags[] = 'system:media:' . array_shift($keys); } } // Imported if ($fromImport) { $tags[] = 'system:imported'; } $this->db->sql_transaction('begin'); if ($replace) { if (!$this->deleteTagsForBookmark($bookmarkid)) { $this->db->sql_transaction('rollback'); message_die(GENERAL_ERROR, 'Could not attach tags (deleting old ones failed)', '', __LINE__, __FILE__, $sql, $this->db); return false; } } $bs = SemanticScuttle_Service_Factory::get('Bookmark'); $tts = SemanticScuttle_Service_Factory::get('Tag2Tag'); // Create links between tags foreach ($tags as $key => $tag) { if (strpos($tag, '=')) { // case "=" $pieces = explode('=', $tag); $nbPieces = count($pieces); if ($nbPieces <= 1) { continue; } for ($i = 0; $i < $nbPieces - 1; $i++) { $bookmark = $bs->getBookmark($bookmarkid); $uId = $bookmark['uId']; $tts->addLinkedTags($pieces[$i], $pieces[$i + 1], '=', $uId); } // Attach just the last tag to the bookmark $tags[$key] = $pieces[0]; } else { // case ">" $pieces = explode('>', $tag); $nbPieces = count($pieces); if ($nbPieces <= 1) { continue; } for ($i = 0; $i < $nbPieces - 1; $i++) { $bookmark = $bs->getBookmark($bookmarkid); $uId = $bookmark['uId']; $tts->addLinkedTags($pieces[$i], $pieces[$i + 1], '>', $uId); } // Attach just the last tag to the bookmark $tags[$key] = $pieces[$nbPieces - 1]; } } //after exploding, there may be duplicate keys //since we are in a transaction, hasTag() may // not return true for newly added duplicate tags $tags = array_unique($tags); // Add the tags to the DB. foreach ($tags as $tag) { if ($tag == '') { continue; } if ($this->hasTag($bookmarkid, $tag)) { continue; } $values = array('bId' => intval($bookmarkid), 'tag' => $tag); $sql = 'INSERT INTO ' . $this->getTableName() . ' ' . $this->db->sql_build_array('INSERT', $values); if (!($dbresult =& $this->db->sql_query($sql))) { $this->db->sql_transaction('rollback'); message_die(GENERAL_ERROR, 'Could not attach tags', '', __LINE__, __FILE__, $sql, $this->db); return false; } } $this->db->sql_transaction('commit'); return true; }
} // Generate Ranking List $rankResults = $db->select_raw('ricehalla', "INNER JOIN votes ON ricehalla.id=votes.row_id WHERE votes.table_name=? GROUP BY votes.row_id ORDER BY TotalRank DESC, TotalVotes DESC, TotalPoints DESC", array("ricehalla"), 'ricehalla.id, sum(votes.points) as TotalPoints, COUNT(votes.id) as TotalVotes, (sum(votes.points) / COUNT(votes.id)) * abs(sum(votes.points)) as TotalRank'); $rank_list = array(); foreach ($rankResults as $rank_result) { if (!is_array($rank_result)) { $result_list = array($rankResults); break; } array_push($rank_list, $rank_result); } $result_array = array(); // Generate object for each result foreach ($result_list as $result) { $id = $result['id']; $rank = multi_array_search($rank_list, array('id' => $id))[0] + 1; $username = $userTools->get($result['user_id'])->username; $image_src = $result['url']; $date_posted = $result['date_added']; $user_vote = $result['TotalPoints']; $tags = explode(',', $result['tags']); array_push($result_array, array('image' => array('id' => $id, 'url' => get_page_url("ricehalla", $CONF) . '/' . $id, 'image_src' => get_page_url("u", $CONF) . '/' . $image_src, 'rank' => $rank, 'votes' => $user_vote, 'owner' => $username, 'date_posted' => $date_posted, 'tags' => $tags))); } array_push($jsonArray, array('results' => $result_array)); } else { array_push($jsonArray, array('error' => $CONF['errors']['NoImages'])); } break; default: array_push($jsonArray, array('error' => $CONF['errors']['InvRequest'])); break;
/** * Searches some value in the multidimensional array. * * @return Array The array, which describes a path to the found element. * FALSE if the element wasn't found. */ function multi_array_search($search_value, $the_array) { if (is_array($the_array)) { foreach ($the_array as $key => $value) { $result = multi_array_search($search_value, $value); if (is_array($result)) { $return = $result; array_unshift($return, $key); return $return; } elseif ($result == true) { $return[] = $key; return $return; } } return false; } else { if ($search_value == $the_array) { return true; } else { return false; } } }
} array_shift($mg_arr1); } ?> </ul> </li> <?php } ?> </ul> <a href="#" id="next">></a> <div class="tab"> <?php foreach ($pjModifyGroup as $mrow) { $mas_content = multi_array_search($mrow['ModifierGroup_Id'], $product['extra_arr']); if ($mas_content == 1) { ?> <div name="tab_content" id="tab_content_<?php echo $product['id']; echo $mgt; ?> " class="tab-content"> <?php foreach ($product['extra_arr'] as $extra) { if ($mrow['ModifierGroup_Id'] == $extra['ModifierGroup_Id']) { ?> <div class="fdExtraBox"> <label><?php echo pjSanitize::clean($extra['name']);
function attachTags($bookmarkid, $tags, $fromApi = false, $extension = NULL, $replace = true, $fromImport = false) { // Make sure that categories is an array of trimmed strings, and that if the categories are // coming in from an API call to add a bookmark, that underscores are converted into strings. if (!is_array($tags)) { $tags = trim($tags); if ($tags != '') { if (substr($tags, -1) == ',') { $tags = substr($tags, 0, -1); } if ($fromApi) { $tags = explode(' ', $tags); } else { $tags = explode(',', $tags); } } else { $tags = null; } } $tags_count = count($tags); for ($i = 0; $i < $tags_count; $i++) { $tags[$i] = trim(strtolower($tags[$i])); if ($fromApi) { include_once dirname(__FILE__) . '/../functions.inc.php'; $tags[$i] = convertTag($tags[$i], 'in'); } } if ($tags_count > 0) { // Remove system tags $tags = array_filter($tags, array($this, "isNotSystemTag")); // Eliminate any duplicate categories $temp = array_unique($tags); $tags = array_values($temp); } else { // Unfiled $tags[] = 'system:unfiled'; } // Media and file types if (!is_null($extension)) { include_once dirname(__FILE__) . '/../functions.inc.php'; if ($keys = multi_array_search($extension, $GLOBALS['filetypes'])) { $tags[] = 'system:filetype:' . $extension; $tags[] = 'system:media:' . array_shift($keys); } } // Imported if ($fromImport) { $tags[] = 'system:imported'; } $this->db->sql_transaction('begin'); if ($replace) { if (!$this->deleteTagsForBookmark($bookmarkid)) { $this->db->sql_transaction('rollback'); message_die(GENERAL_ERROR, 'Could not attach tags (deleting old ones failed)', '', __LINE__, __FILE__, $sql, $this->db); return false; } } // Add the categories to the DB. for ($i = 0; $i < count($tags); $i++) { if ($tags[$i] != '') { $values = array('bId' => intval($bookmarkid), 'tag' => $tags[$i]); if (!$this->hasTag($bookmarkid, $tags[$i])) { $sql = 'INSERT INTO ' . $this->getTableName() . ' ' . $this->db->sql_build_array('INSERT', $values); if (!($dbresult =& $this->db->sql_query($sql))) { $this->db->sql_transaction('rollback'); message_die(GENERAL_ERROR, 'Could not attach tags', '', __LINE__, __FILE__, $sql, $this->db); return false; } } } } $this->db->sql_transaction('commit'); return true; }
function fn_ls_multi_array_search($search_for, $search_in) { foreach ($search_in as $element) { if ($element === $search_for || is_array($element) && multi_array_search($search_for, $element)) { return true; } } return false; }
public static function questionInformation($questionId) { // Split up quiz id and question id from format 12.1 (quizNumber.questionNumber) $idParts = explode(".", $questionId); // Make sure we have a (at least format-wise) valid question id if (count($idParts) != 2) { return false; } $assessmentID = $idParts[0]; $questionNumber = $idParts[1]; // Get row from question info CSV // Load question information mapping $allQuestions = CSVHelper::parseWithHeaders('csv/questions.csv'); // Search questions for one with this assessment ID and question number $searchResults = multi_array_search($allQuestions, ["OA Quiz ID" => $assessmentID, "Question Number" => $questionNumber]); // If there's not one, return false if (count($searchResults) <= 0) { return false; } // If we have one, get it $questionRow = $allQuestions[$searchResults[0]]; /* // Get assessment id from quiz id $assessmentId = $questionRow["OA Quiz ID"]; // Get question type: multiple_choice, short_answer, or essay $questionType = $questionRow["Type"]; $question = [ "questionNumber" => $questionNumber, "assessmentId" => $assessmentId, "questionType" => $questionType ]; // If a multiple choice question, add the number of options the question has if ($questionType == "multiple_choice") { $question["options"] = $questionRow["Multiple Choice Options"]; } */ return $questionRow; }
public function dpsitemap4($site = 'blcb', $date = null, $interval = 1) { $this->load->helper('url'); $this->load->model('Data_presence_Model'); $this->load->model('Alert_Model'); $data['allSites'] = $this->Data_presence_Model->getAllNodesOfSite($site); $data['dataPresenceRaw'] = $this->Data_presence_Model->getNodeDataPresence('default', $site, $date, $interval); $data['dataPresencePurged'] = $this->Alert_Model->getSingleSiteAlert24Hour($site); /* $data['graphTitle'] = "Raw (Black) & LSB Change (Blue, Green, Orange) | Data Presence Map for $site"; $data['verticalLabel'] = "Node ID"; $this->load->view('graphs/testNodeDataPresRawPurged2', $data); */ echo multi_array_search($data['dataPresencePurged'], array('site' => 1.0)); //echo json_encode($data['dataPresencePurged']); }
public function get_raidids4memberid_item($member_id, $item_ids) { $item_ids = !is_array($item_ids) ? array($item_ids) : $item_ids; $raids4member = array(); foreach ($this->index as $raid_id) { $arrMembers = $this->get_raid_attendees($raid_id, false); $arrItems = $this->pdh->get('item', 'itemsofraid', array($raid_id)); if (is_array($arrMembers) && in_array($member_id, $arrMembers) && multi_array_search($arrItems, $item_ids)) { $raids4member[] = $raid_id; } } return $raids4member; }