Parse HTML to list of contribution

@param {Object} $calendar - cheerio object
@return {Array<{date: string, count: number}>}
969642
function parseCalendar($calendar) {
  const data = [];
  $calendar.find('rect').each((i, elm) => {
    const $rect = cheerio(elm);
    const date = $rect.attr('data-date');
    if (!date) {
      return;
    }
    data.push({
      date,
      count: parseInt($rect.attr('data-count'), 10)
    });
  });
  return data;
}
63951
public static function calendar()
	{
		if (isset(self::$loaded[__METHOD__]))
		{
			return;
		}

		/*$tag = App::get('language')->getTag();

		$translation = self::_calendartranslation();
		if ($translation)
		{
			App::get('document')->addScriptDeclaration($translation);
		}*/

		Asset::stylesheet('assets/jquery.datepicker.css', array('media' => 'all'), true);
		Asset::stylesheet('assets/jquery.timepicker.css', array('media' => 'all'), true);

		self::framework(true);

		Asset::script('assets/jquery.timepicker.js', false, true);

		self::$loaded[__METHOD__] = true;
	}
758951
function parseGuestWlanHTML(html)
{
    $ = cheerio.load(html);
    var form = $('form');
    var settings = {};

    $('input', form).each(function(i, elem) {
        var val;
        var name = $(elem).attr('name');
        if (!name) return;

        switch ($(elem).attr('type')) {
            case 'checkbox':
                val = $(elem).attr('checked') == 'checked';
                break;
            default:
                val = $(elem).val();
        }
        settings[name] = val;
    });

    $('select option[selected=selected]', form).each(function(i, elem) {
        var val = $(elem).val();
        var name = $(elem).parent().attr('name');
        settings[name] = val;
    });

    return settings;
}
1241045
public static function listsToHtml($str)
    {

        $str = preg_replace_callback('/(?:(?:^|\n)[#\*].*)+\n?/m', function($match){

            $type = substr(trim($match[0]), 0, 1) == '#' ? 'ol' : 'ul';

            $star_cnt = 1;
            $lis = preg_replace_callback("~^([\*\#]+)(.*)$~m", function($innermatch){

                return '<li>'.$innermatch[2].'</li>';
            }, trim($match[0]));

            $lis = str_replace(Array("\n</li>", "</li>\n"), "</li>", $lis);
            return '<'.$type.' class="tb">'.$lis.'</'.$type.'>';

        }, $str);

        $str = preg_replace_callback("~\[list\](.*?)\[/list\]\n~s", function($match){

            $lis = preg_replace_callback("~^\w|\s.*$~m", function($inner_match){
                $li = trim($inner_match[0]);
                if(!empty($li)){
                    return '<li class="tb">'.trim($li).'</li>';
                }
                return '';
            }, $match[1]);
            return '<ul class="tb">'.$lis.'</ul>';

        }, $str);

        $str = preg_replace_callback("~\[numlist\](.*?)\[/numlist\]\n?~s", function($match){

            $lis = preg_replace_callback("~^\w|\s.*$~m", function($inner_match){
                $li = trim($inner_match[0]);
                if(!empty($li)){
                    return '<li class="tb">'.trim($li).'</li>';
                }
                return '';
            }, $match[1]);
            return '<ol class="tb">'.$lis.'</ol>';

        }, $str);

        $str = preg_replace_callback('~\n{0,}\t{0,}\[(/?(ol|ul|li))\]\n*~', function($match) {
            if (!strstr($match[1], "/")) {
                return '<' . $match[1] . ' class="tb">';
            } else {
                return '<' . $match[1] . '>';
            }
        }, $str);

        return $str;
    }
491510
private void parseCalendarList(final StreamTokenizer tokeniser, Reader in, 
            final ContentHandler handler) throws IOException, ParseException,
            URISyntaxException, ParserException {

        // BEGIN:VCALENDAR
        int ntok = assertToken(tokeniser, in, Calendar.BEGIN, false, true);
        while (ntok != StreamTokenizer.TT_EOF) {
            parseCalendar(tokeniser, in, handler);
            ntok = absorbWhitespace(tokeniser, in, true);
        }
    }
1360686
protected function parseToken($token)
    {
        [$id, $content] = $token;

        if ($id == T_INLINE_HTML) {
            foreach ($this->compilers as $type) {
                $content = $this->{"compile{$type}"}($content);
            }
        }

        return $content;
    }
49157
public function getCalendars()
    {
        //build URI
        $strURI = Product::$baseProductUri . '/tasks/' . $this->getFileName() . '/calendars/';

        //sign URI
        $signedURI = Utils::sign($strURI);

        $responseStream = Utils::processCommand($signedURI, 'GET', '', '');

        $json = json_decode($responseStream);

        if ($json->Code == 200)
            return $json->Calendars->List;
        else
            return false;
    }
1340746
function parse($html)
		{
			$dom = new \DOMDocument();
			libxml_use_internal_errors(true);
			$dom->loadHTML($html);
			$xpath = new \DOMXPath($dom);
			
			// Load resources for tag actions
			$this->ignoreElements = new ResourceProvider("html_tag_actions/ignore.lst");
			$this->linkElements = new ResourceProvider("html_tag_actions/link.lst");
			$this->bodyElements = new ResourceProvider("html_tag_actions/body.lst");
			$this->inlineElements = new ResourceProvider("html_tag_actions/inline.lst");
			
			/*	
			 *  1st retrieve page title
			 *  With this technique: only process the entire document here 
			 *  as meta is excluded as 'content' and only required for initial title.
			 */

			// Extract title from DOM
			$body = $xpath->query('/')->item(0);
			$titleItem = $xpath->query('//title')->item(0);
			
			if(isset($titleItem))
			{
				$title = $titleItem->textContent;
			}
			$body = $xpath->query('//body')->item(0);
			
			// Try to extract title from OG meta
			foreach ($xpath->query("//meta[@property='og:title']") as $el) 
			{
				$title = $el->getAttribute("content");
			}
			
			$this->recurse($body);
			$Article = new Article();
			if(isset($title))
			{
				$Article->title = $title;
			}
			$Article->textBlocks = $this->textBlocks;
			return $Article;
		}
974454
function calendar($date='now',$first=0) {
		$out=FALSE;
		if (extension_loaded('calendar')) {
			if (is_string($date))
				$date=strtotime($date);
			$parts=getdate($date);
			$days=cal_days_in_month(CAL_GREGORIAN,$parts['mon'],$parts['year']);
			$ref=date('w',strtotime(date('Y-m',$parts[0]).'-01'))+(7-$first)%7;
			$out=[];
			for ($i=0;$i<$days;$i++)
				$out[floor(($ref+$i)/7)][($ref+$i)%7]=$i+1;
		}
		return $out;
	}
137124
function CalendarMonthBodyCtrl($element, $$mdDateUtil, $mdDateLocale) {
    /** @final {!angular.JQLite} */
    this.$element = $element;

    /** @final */
    this.dateUtil = $$mdDateUtil;

    /** @final */
    this.dateLocale = $mdDateLocale;

    /** @type {Object} Reference to the month view. */
    this.monthCtrl = null;

    /** @type {Object} Reference to the calendar. */
    this.calendarCtrl = null;

    /**
     * Number of months from the start of the month "items" that the currently rendered month
     * occurs. Set via angular data binding.
     * @type {number}
     */
    this.offset = null;

    /**
     * Date cell to focus after appending the month to the document.
     * @type {HTMLElement}
     */
    this.focusAfterAppend = null;
  }
344182
private function makeAnnotation($date, $note, $starred = 0)
    {
        return array('date'    => $date,
                     'note'    => $note,
                     'starred' => (int)$starred,
                     'user'    => Piwik::getCurrentUserLogin());
    }
1126988
private function parseFormat($format, $date) {
        
        $this->updateJalaliFromGeorgian();
        
        // reverse engineer date formats
        $keys = [
            'Y' => ['year', '\d{4}'],
            'y' => ['year', '\d{2}'],
            'm' => ['month', '\d{2}'],
            'n' => ['month', '\d{1,2}'],
            'M' => ['month', '[A-Z][a-z]{3}'],
            'F' => ['month', '[A-Z][a-z]{2,8}'],
            'd' => ['day', '\d{2}'],
            'j' => ['day', '\d{1,2}'],
            'D' => ['day', '[A-Z][a-z]{2}'],
            'l' => ['day', '[A-Z][a-z]{6,9}'],
            'u' => ['hour', '\d{1,6}'],
            'h' => ['hour', '\d{2}'],
            'H' => ['hour', '\d{2}'],
            'g' => ['hour', '\d{1,2}'],
            'G' => ['hour', '\d{1,2}'],
            'i' => ['minute', '\d{2}'],
            's' => ['second', '\d{2}'],
        ];
        
        // convert format string to regex
        $regex      = '';
        $characters = str_split($format);
        foreach ($characters as $n => $character) {
            $lastCharacter = isset($characters[$n - 1]) ? $characters[$n - 1] : '';
            $skipCurrent   = '\\' == $lastCharacter;
            if ( ! $skipCurrent && isset($keys[$character])) {
                $regex .= '(?P<' . $keys[$character][0] . '>' . $keys[$character][1] . ')';
            } else {
                if ('\\' == $character) {
                    $regex .= $character;
                } else {
                    $regex .= preg_quote($character);
                }
            }
        }
        
        $sections = [];
        // now try to match it
        if (preg_match('#^' . $regex . '$#', $date, $sections)) {
            foreach ($sections as $k => $v) {
                if (is_int($k)) {
                    unset($sections[$k]);
                }
            }
        } else {
            throw new InvalidArgumentException('the given date is not valid through the given format.');
        }
        
        $yearToSet = $this->year;
        if (isset($sections['year'])) {
            
            $yearToSet = $sections['year'];
            
            // checking to make the year absolute
            if (strlen($yearToSet) == 2) {
                $instance  = static::now();
                $yearToSet += (int) ($instance->format('Y') - $instance->format('y'));
            }
        }
        $monthToSet = $this->month;
        if (isset($sections['month'])) {
            $monthToSet = $sections['month'];
        }
        $dayToSet = $this->day;
        if (isset($sections['day'])) {
            $dayToSet = $sections['day'];
            
            //there's an exception
            $max = static::getMonthLength($monthToSet, $yearToSet);
            if ($dayToSet > $max) {
                throw new InvalidArgumentException('the current month maximum days is ' . $max);
            }
        }
        $hourToSet = $this->hour;
        if (isset($sections['hour'])) {
            $hourToSet = $sections['hour'];
        }
        $minuteToSet = $this->minute;
        if (isset($sections['minute'])) {
            $minuteToSet = $sections['minute'];
        }
        $secondToSet = $this->second;
        if (isset($sections['second'])) {
            $secondToSet = $sections['second'];
        }
        
        $this->setDateTime($yearToSet, $monthToSet, $dayToSet, $hourToSet, $minuteToSet, $secondToSet);
        
        $this->updateGeorgianFromJalali();
        
    }
1086965
public function convertToCalendar(string $calendar): AbstractCalendarDate
    {
        switch ($calendar) {
            case 'gregorian':
                return new GregorianDate($this);
            case 'julian':
                return new JulianDate($this);
            case 'jewish':
                return new JewishDate($this);
            case 'french':
                return new FrenchDate($this);
            case 'hijri':
                return new HijriDate($this);
            case 'jalali':
                return new JalaliDate($this);
            default:
                return $this;
        }
    }
611103
public function publicevents($request, $json=true, $calendars=null, $offset=30)
    {
        $calendarsSupplied = false;
        if ($calendars) {
            $calendarsSupplied = true;
        }

        $events = PublicEvent::get()
            ->filter(array(
                'StartDateTime:GreaterThan' => $this->eventlistOffsetDate('start', $request->postVar('start'), $offset),
                'EndDateTime:LessThan' => $this->eventlistOffsetDate('end', $request->postVar('end'), $offset),
            ));

        //If shaded events are enabled we need to filter shaded calendars out
        //note that this only takes effect when no calendars have been supplied
        //if calendars are supplied, this needs to be taken care of from that method
        $sC = CalendarConfig::subpackage_settings('calendars');
        if ($sC['shading']) {
            if (!$calendars) {
                $calendars = PublicCalendar::get();
                $calendars = $calendars->filter(array(
                    'shaded' => false
                ));
            }
        }


        if ($calendars) {
            $calIDList = $calendars->getIdList();
            //adding in 0 to allow for showing events without a calendar
            if (!$calendarsSupplied) {
                $calIDList[0] = 0;
            }

            //Debug::dump($calIDList);
            $events = $events->filter('CalendarID', $calIDList);
        }

        $result = array();
        if ($events) {
            foreach ($events as $event) {
                $calendar = $event->Calendar();

                $bgColor = '#999'; //default
            $textColor = '#FFF'; //default
            $borderColor = '#555';

                if ($calendar->exists()) {
                    $bgColor = $calendar->getColorWithHash();
                    $textColor = '#FFF';
                    $borderColor = $calendar->getColorWithHash();
                }

                $resultArr = self::format_event_for_fullcalendar($event);
                $resultArr = array_merge($resultArr, array(
                'backgroundColor' => $bgColor,
                'textColor' => '#FFF',
                'borderColor' => $borderColor,
            ));
                $result[] = $resultArr;
            }
        }

        if ($json) {
            $response = new SS_HTTPResponse(Convert::array2json($result));
            $response->addHeader('Content-Type', 'application/json');
            return $response;
        } else {
            return $result;
        }
    }
1302778
function(strTitle) {
        var tDiv = Dom.getElementsByClassName(YAHOO.widget.CalendarGroup.CSS_2UPTITLE, "div", this.oDomContainer)[0] || document.createElement("div");
        tDiv.className = YAHOO.widget.CalendarGroup.CSS_2UPTITLE;
        tDiv.innerHTML = strTitle;
        this.oDomContainer.insertBefore(tDiv, this.oDomContainer.firstChild);
    
        Dom.addClass(this.oDomContainer, this.Style.CSS_WITH_TITLE);
    
        return tDiv;
    }
91666
private static function _calendarDetail($locale, $list)
    {
        $ret = "001";
        foreach ($list as $key => $value) {
            if (strpos($locale, '_') !== false) {
                $locale = substr($locale, strpos($locale, '_') + 1);
            }
            if (strpos($key, $locale) !== false) {
                $ret = $key;
                break;
            }
        }
        return $ret;
    }
1028844
private List<Skeleton> parseDateTimeSkeletons(JsonObject calendar) {
    JsonObject node = resolve(calendar, "dateTimeFormats", "availableFormats");
    List<Skeleton> value = new ArrayList<>();
    for (String key : objectKeys(node)) {
      value.add(new Skeleton(key, string(node, key)));
    }
    return value;
  }