/** * @param $file * @param $data * @param boolean $merge_data * @param boolean $remove_empty * @return boolean */ function write($file, $data, $merge_data = true, $remove_empty = true) { $ini_array = array(); foreach ($data as $title => $content) { $ini_array[$title] = array(); foreach ($content as $prefix => $values) { $ini_array[$title][$prefix] = array(); foreach ($values as $key => $value) { $ini_array[$title][$prefix][$key] = $value; } } } if (count($ini_array)) { $merged = $ini_array; if ($merge_data || $merge_data === 'delete-key') { $ini_content = GantryINI::read($file); $merged = GantryINI::_array_merge_replace_recursive($ini_content, $ini_array); if ($merge_data === 'delete-key') { $merged = GantryINI::_deleteKey($merged, $data); } } $output = ""; foreach ($merged as $title => $content) { $output .= "\n[" . $title . "]\n"; foreach ($content as $key => $values) { $key = $key . "_"; foreach ($values as $prefix => $value) { $output .= $key . $prefix . "=" . $value . "\n"; } } } $output = substr($output, 1, strlen($output)); if (file_put_contents($file, $output)) { return true; } else { return false; } } else { if ($remove_empty) { if (file_exists($file) && is_writeable($file)) { unlink($file); } } } }
public function getInput() { global $gantry; $currentVersion = "3.2.3"; if ($currentVersion == ".2.11") { $currentVersion = "[DEV]"; } // curl check if (!function_exists('curl_version')) { $upd = "<strong>cURL is required to check for latest versions of the Gantry Framework. </strong> Learn more at <a href='http://www.php.net/manual/en/book.curl.php'>http://www.php.net</a>"; return "\n\t\t\t\t<div id='updater' class='update'>\n\t\t\t\t\t<div id='updater-bar' class='h2bar'>Gantry <span>v" . $currentVersion . "</span></div>\n\t\t\t\t\t<div id='updater-desc'>" . $upd . "</div>\n\t\t\t\t</div>\n\t\t\t"; } jimport('joomla.utilities.date'); gantry_import('core.gantryini'); global $gantry; $klass = "noupdate"; $output = ""; $statusText = ""; $now = time(); $cache_file = $gantry->custom_dir . DS . 'gantry_version'; if (file_exists($cache_file) && is_file($cache_file) && is_readable($cache_file)) { $old_cache_data = GantryINI::read($cache_file, $this->type, 'check'); $old_cache_date = $old_cache_data['date']; } else { $old_cache_data['version'] = GANTRY_VERSION; $old_cache_data['date'] = 1; $old_cache_data['link'] = ''; $old_cache_date = 0; } // only grab from the web if its been more the 24 hours since the last check if ($old_cache_date + 24 * 60 * 60 < $now) { $data = $this->_get_url_contents('http://code.google.com/feeds/p/gantry-framework/downloads/basic'); if (!empty($this->_error)) { $klass = "update"; $upd = "<strong>Error checking version:</strong> " . $this->_error; $latest_version = GANTRY_VERSION; } else { $xml = new SimpleXMLElement($data); foreach ($xml->entry as $entry) { $title = (string) $entry->title; if (preg_match('/gantry_framework_joomla16-(.*).zip/', $title, $matches)) { $linkattribs = $entry->link[0]->attributes(); $link = (string) $linkattribs['href']; $latest_version = $matches[1]; $cache_data[$this->type]['check']['version'] = $latest_version; $cache_data[$this->type]['check']['link'] = $link; $cache_data[$this->type]['check']['date'] = $now; GantryINI::write($cache_file, $cache_data, false); break; } } } } else { $latest_version = $old_cache_data['version']; $link = $old_cache_data['link']; } if ($latest_version != $currentVersion) { $klass = "update"; $upd = "<strong>Version " . $latest_version . " of the Gantry Framework is Available</strong>. Please <a href='" . $link . "'>download the latest version</a> now."; } else { $ms = $old_cache_date + 24 * 60 * 60 - $now; $hours = round($ms / 60 / 60); $minutes = $hours / 60; $upd = "<strong>The Gantry Framework is up-to-date!</strong><br />You are running the latest version, you will be notified here if a newer version is available.<br />"; $upd .= "An update check will be executed every 24hr. Next check in: <dev>"; } $output = "\n\t\t<div id='updater' class='" . $klass . "'>\n\t\t\t<div id='updater-bar' class='h2bar'>Gantry <span>v" . $currentVersion . "</span></div>\n\t\t\t<div id='updater-desc'>" . $upd . "</div>\n\t\t</div>"; return $output; }
/** * @return void */ protected function customPresets() { $this->originalPresets = $this->presets; if (file_exists($this->custom_presets_file)) { $customPresets = GantryINI::read($this->custom_presets_file); $this->customPresets = $customPresets; $this->originalPresets = $this->presets; if (count($customPresets)) { $this->presets = $this->array_merge_replace_recursive($this->presets, $customPresets); foreach ($this->presets as $key => $preset) { uksort($preset, array($this, "_compareKeys")); $this->presets[$key] = $preset; } } } }
function fetchElement($name, $value, &$node, $control_name) { // curl check if (!function_exists('curl_version')) { $upd = "<span class='download-update'>"; $upd .= "\t\t<a href='http://www.php.net/manual/en/book.curl.php'>"; $upd .= "\t\t\t<span>Learn more about cURL</span>"; $upd .= "\t\t</a>"; $upd .= "</span>"; return "\n\t\t\t<div id='versioncheck' class='update-available'>\n\t\t\t\t<div id='versioncheck-bar' class='g-title'><b>ERROR - </b> cURL is required in order to check Gantry updates." . $upd . "</div>\n\t\t\t</div>"; } gantry_import('core.gantryini'); gantry_import('core.utilities.gantryxml'); global $gantry; $klass = "no-updates"; $output = ""; $statusText = ""; $now =& JFactory::getDate(); $cache_file = $gantry->custom_dir . DS . 'gantry_version'; if (file_exists($cache_file) && is_file($cache_file) && is_readable($cache_file)) { $old_cache_data = GantryINI::read($cache_file, $this->_name, 'check'); } else { $old_cache_data['version'] = GANTRY_VERSION; $old_cache_data['date'] = 1; $old_cache_data['link'] = ''; } $old_cache_date =& JFactory::getDate($old_cache_data['date']); // only grab from the web if its been more the 24 hours since the last check if ($old_cache_date->toUNIX() + 24 * 60 * 60 < $now->toUNIX()) { $data = $this->_get_url_contents('http://code.google.com/feeds/p/gantry-framework/downloads/basic'); if (!empty($this->_error)) { $output = "<span id='version-warning'> [ <strong>Error checking version:</strong> " . $this->_error . " ]</span>"; $latest_version = GANTRY_VERSION; } else { $xml = new GantryXML(); $xml->loadString($data); foreach ($xml->document->entry as $entry) { $title = (string) $entry->title[0]->data(); if (preg_match('/gantry_joomla_framework-(.*).zip/', $title, $matches)) { $linkattribs = $entry->link[0]->attributes(); $link = (string) $linkattribs['href']; $latest_version = $matches[1]; $cache_data[$this->_name]['check']['version'] = $latest_version; $cache_data[$this->_name]['check']['link'] = $link; $cache_data[$this->_name]['check']['date'] = $now->toUNIX(); GantryINI::write($cache_file, $cache_data, false); break; } } } } else { $latest_version = $old_cache_data['version']; $link = $old_cache_data['link']; } $upd = ""; if ($latest_version != GANTRY_VERSION) { $klass = "update-available"; $statusText = "- Notice: <b>New Version Available!</b>"; $upd = "<span class='download-update'>"; $upd .= "\t\t<a href='" . $link . "'>"; $upd .= "\t\t\t<span>Download Gantry " . $latest_version . "</span>"; $upd .= "\t\t</a>"; $upd .= "</span>"; } else { $upd = "<span class='download-update'>"; $upd .= "\t\t<span>No update available</span>"; $upd .= "</span>"; } return "\n\t\t<div id='versioncheck' class='" . $klass . "'>\n\t\t\t<div id='versioncheck-bar' class='g-title'>Gantry v" . GANTRY_VERSION . " " . JText::_($statusText) . $upd . "</div>\n\t\t</div>"; }
public function getInput() { global $gantry; $currentVersion = GANTRY_VERSION; if ($currentVersion == ".26") { $currentVersion = "[DEV]"; } // curl check if (!function_exists('curl_version')) { $upd = "<strong>cURL is required to check for latest versions of the Gantry Framework. </strong> Learn more at <a href='http://www.php.net/manual/en/book.curl.php'>http://www.php.net</a>"; return "\n\t\t\t\t<div id='updater' class='update'>\n\t\t\t\t\t<div id='updater-bar' class='h2bar'>Gantry <span>v" . $currentVersion . "</span></div>\n\t\t\t\t\t<div id='updater-desc'>" . $upd . "</div>\n\t\t\t\t</div>\n\t\t\t"; } gantry_import('core.gantryini'); gantry_import('core.utilities.gantryxml'); global $gantry; $klass = "noupdate"; $output = ""; $statusText = ""; $now = time(); $cache_file = $gantry->custom_dir . DS . 'gantry_version'; if (file_exists($cache_file) && is_file($cache_file) && is_readable($cache_file)) { $old_cache_data = GantryINI::read($cache_file, $this->_name, 'check'); } else { $old_cache_data['version'] = GANTRY_VERSION; $old_cache_data['date'] = 1; $old_cache_data['link'] = ''; } $old_cache_date = time($old_cache_data['date']); // only grab from the web if its been more the 24 hours since the last check if ($old_cache_date + 24 * 60 * 60 < $now) { $data = $this->_get_url_contents('http://code.google.com/feeds/p/gantry-framework/downloads/basic'); if (!empty($this->_error)) { $klass = "update"; $upd = "<strong>Error checking version:</strong> " . $this->_error; $latest_version = GANTRY_VERSION; } else { $xml = new GantryXML(); $xml->loadString($data); foreach ($xml->document->entry as $entry) { $title = (string) $entry->title[0]->data(); if (preg_match('/gantry_wordpress_framework-(.*).zip/', $title, $matches)) { $linkattribs = $entry->link[0]->attributes(); $link = (string) $linkattribs['href']; $latest_version = $matches[1]; $cache_data[$this->_name]['check']['version'] = $latest_version; $cache_data[$this->_name]['check']['link'] = $link; $cache_data[$this->_name]['check']['date'] = $now->toUNIX(); GantryINI::write($cache_file, $cache_data, false); break; } } } } else { $latest_version = $old_cache_data['version']; $link = $old_cache_data['link']; } if ($latest_version != GANTRY_VERSION) { $klass = "update"; $upd = "<strong>Version " . $latest_version . " of the Gantry Framework is Available</strong>. Please <a href='" . $link . "'>download the latest version</a> now."; } else { $upd = "<strong>The Gantry Framework is up-to-date!</strong><br />You are running the latest version, you will be notified here if a newer version is available."; } $output = "\n\t\t<div id='updater' class='" . $klass . "'>\n\t\t\t<div id='updater-bar' class='h2bar'>Gantry <span>v" . $currentVersion . "</span></div>\n\t\t\t<div id='updater-desc'>" . $upd . "<br />\n\t\t\tYour server is using <b>" . php_sapi_name() . "</b> as PHP interface.</div>\n\t\t</div>"; return $output; }