Commit 3617683c authored by Constantin Druc's avatar Constantin Druc 🤦🏻

Rename with uppercase

parent acc9a6a5
<?php
use \WordpressTheme\Hooks\Filters;
$acfPluginPath = str_replace('\\', '/', Filters::acf_settings_path() . 'acf.php');
include_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );
$upgrader = new \Plugin_Upgrader(new \Plugin_Upgrader_Skin(array('plugin' => $acfPluginPath)));
$parsed_args = array(
'clear_update_cache' => true,
);
$plugin = $acfPluginPath;
$upgrader->init();
$upgrader->upgrade_strings();
if (!acf_pro_is_update_available()) {
$upgrader->skin->before();
$upgrader->skin->set_result(false);
$upgrader->skin->error('up_to_date');
$upgrader->skin->after();
return false;
}
$package = acf_pro_get_remote_url('download', array('k' => acf_pro_get_license()));
if (!$package) {
$upgrader->skin->before();
$upgrader->skin->set_result(false);
$upgrader->skin->error('error');
$upgrader->skin->after();
return false;
}
add_filter('upgrader_pre_install', array($upgrader, 'deactivate_plugin_before_upgrade'), 10, 2);
add_filter('upgrader_clear_destination', array($upgrader, 'delete_old_plugin'), 10, 4);
$upgrader->run(array(
'package' => $package,
'destination' => Filters::acf_settings_path(),
'clear_destination' => false,
'abort_if_destination_exists' => false,
'clear_working' => true,
'hook_extra' => array(
'plugin' => $plugin,
'type' => 'plugin',
'action' => 'update',
),
));
// Cleanup our hooks, in case something else does a upgrade on this connection.
remove_filter('upgrader_pre_install', array($upgrader, 'deactivate_plugin_before_upgrade'));
remove_filter('upgrader_clear_destination', array($upgrader, 'delete_old_plugin'));
if (!$upgrader->result || is_wp_error($upgrader->result)) {
return $upgrader->result;
}
// Force refresh of plugin update information
wp_clean_plugins_cache($parsed_args['clear_update_cache']);
\ No newline at end of file
<?php
use \WordpressTheme\Framework;
use \WordpressTheme\ThemePacker;
$packerOptions = Framework::getConfig('themePacker');
if (empty($packerOptions['pushUrl'])) {
echo 'No theme packer push URL in the config file';
return;
}
$logger = function($message, $type = 'info') {
switch ($type) {
case 'error':
echo '<div class="error">', $message, '</div><br />';
break;
case 'success':
echo '<div class="success">', $message, '</div><br />';
break;
default;
echo '<div class="info">', $message, '</div><br />';
break;
}
flush();
ob_flush();
};
$formatBytes = function($bytes, $precision = 2) {
$units = array('B', 'KB', 'MB', 'GB', 'TB');
$bytes = max($bytes, 0);
$pow = floor(($bytes ? log($bytes) : 0) / log(1024));
$pow = min($pow, count($units) - 1);
return round($bytes, $precision) . ' ' . $units[$pow];
};
$replaceContentByLineFromFile = function($filePath, $newValues) {
$styleFile = fopen($filePath, 'r');
$newFileContent = '';
do {
$row = fgets($styleFile);
foreach ($newValues as $key => $val) {
if (strpos($row, $key) !== false) {
$newFileContent .= $val . PHP_EOL;
} else {
$newFileContent .= $row;
}
}
} while (!feof($styleFile));
fclose($styleFile);
return $newFileContent;
};
$pushUrl = $packerOptions['pushUrl'];
$packer = new ThemePacker(get_template_directory(), 1, $logger);
$packer->addBuildTask(function(ThemePacker $packer) {
$flag = true;
foreach ($packer->getFiles() as $file) {
if (is_file($file) && substr($file, -3) === 'php') {
$source = file_get_contents($file);
$tokens = token_get_all($source);
$found = false;
foreach ($tokens as $id => $token) {
if (is_array($token)) {
//console()
if ($token[0] === T_STRING && strtolower(trim($token[1])) === 'console') {
$found = true;
}
//FB::log()
if ($token[0] === T_STRING && strtolower(trim($token[1])) === 'fb') {
if (!empty($tokens[$id + 1])) {
if ($tokens[$id + 1][0] === T_DOUBLE_COLON && strtolower(trim($token[1])) === '::') {
$found = true;
}
}
}
//fb()
if ($token[0] === T_STRING && strtolower(trim($token[1])) === 'fb') {
$found = true;
}
if ($found) {
break;
}
}
}
if ($found) {
$packer->log('Found console logger in ' . $file, 'error');
$flag = false;
}
break;
}
}
return $flag;
});
$packer->addBuildTask(function(ThemePacker $packer) {
$oldcwd = getcwd();
chdir($packer->getWpTheme()->get_template_directory());
$buildCmd = 'grunt build --no-color';
$packer->log('Building ' . $buildCmd);
$returnValue = 0;
$cmdOutput = '';
exec($buildCmd , $cmdOutput, $returnValue);
$packer->log(nl2br(implode("\n", $cmdOutput)));
chdir($oldcwd);
if ((int) $returnValue !== 0) {
return false;
}
return true;
});
$packer->addBuildTask(function(ThemePacker $packer) {
$oldcwd = getcwd();
chdir($packer->getWpTheme()->get_template_directory() . '/vendor/falcon/blank-wordpress-framework/WordpressTheme');
$buildCmd = 'git pull origin master';
$packer->log('Building Framework ' . $buildCmd);
$returnValue = 0;
$cmdOutput = '';
exec($buildCmd . ' ', $cmdOutput, $returnValue);
$packer->log(nl2br(implode("\n", $cmdOutput)));
chdir($oldcwd);
if ((int) $returnValue !== 0) {
return false;
}
return true;
});
$packer->addBuildTask(function(ThemePacker $packer) {
$oldcwd = getcwd();
chdir($packer->getWpTheme()->get_template_directory() . '/vendor/falcon/acf');
$buildCmd = 'git pull origin master';
$packer->log('Building Plugins ACF ' . $buildCmd);
$returnValue = 0;
$cmdOutput = '';
exec($buildCmd . ' ', $cmdOutput, $returnValue);
$packer->log(nl2br(implode("\n", $cmdOutput)));
chdir($oldcwd);
if ((int) $returnValue !== 0) {
return false;
}
return true;
});
$packer->addBuildTask(function(ThemePacker $packer) {
$oldcwd = getcwd();
chdir($packer->getWpTheme()->get_template_directory() . '/vendor/falcon/post-type-archive-links');
$buildCmd = 'git pull origin master';
$packer->log('Building Plugins Post Type Archive Links ' . $buildCmd);
$returnValue = 0;
$cmdOutput = '';
exec($buildCmd . ' ', $cmdOutput, $returnValue);
$packer->log(nl2br(implode("\n", $cmdOutput)));
chdir($oldcwd);
if ((int) $returnValue !== 0) {
return false;
}
return true;
});
foreach (Framework::getConfig('filesToImportFromLive') as $url => $localPath) {
$content = file_get_contents($url);
fwrite(fopen($localPath, 'w'), $content);
}
$zip = str_replace('\\', '/', tempnam(sys_get_temp_dir(), 'wptheme'));
$packer->setPatternsToIgnore(array(
'.git', 'cache', 'nbproject', 'node_modules'
));
$packer->log('Found changes in theme, starting to pack...');
if (!$packer->build()) {
$packer->log('Build failed. Packing stoped.', 'error');
} else {
$packer->createZipArchive($zip);
$request = curl_init($pushUrl);
curl_setopt($request, CURLOPT_POST, true);
curl_setopt($request, CURLOPT_HTTPHEADER, array(
'Content-type: multipart/form-data;'
));
$packer->curl_custom_postfields($request, array(
'uploader' => php_uname() . ' - ' . $_SERVER['HTTP_HOST']
), array(
'archive' => $zip
));
curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
$logger('Sending to wp-bank server ' . $formatBytes(filesize($zip)) . ' of data');
$response = curl_exec($request);
$info = json_decode($response);
$themeVariables = array();
$themeVariables['Version: '] = 'Version: ' . $info->newVersion;
// $themeVariables['Version Hash: ' . $oldHash] = 'Version Hash: ' . $this->info['version_hash'];
$themeStyleFile = file_get_contents($packer->getTheme() . '/style.css');
fwrite(fopen($packer->getTheme() . '/style.css', 'w'), str_replace(array_keys($themeVariables), array_values($themeVariables), $themeStyleFile));
$newContent = $replaceContentByLineFromFile($packer->getTheme() . '/style.css', $themeVariables);
$writeToStyleFile = fwrite(fopen($packer->getTheme() . '/style.css', 'w'), $newContent);
// $this->log('New version set to ' . $this->info['version'] . '[' . $this->info['version_hash'] . ']');
$packer->log('New version set to ' . $info->newVersion);
?>
<h1>New version for <?php echo $info->projectName; ?></h1>
<p>from version <?php echo $info->oldVersion; ?> to <?php echo $info->newVersion; ?></p>
<ul>
<li>
Uploaded by <?php echo $info->uploader; ?> (<?php echo $info->ip; ?>)
</li>
<li>
Date <?php echo $info->date; ?> <br/>
</li>
<li>
Download link <a href="<?php echo $info->downloadLink; ?>"><?php echo $info->downloadLink; ?></a> </br>
</li>
<li>
Info link <a href="<?php echo $info->infoLink; ?>"><?php echo $info->infoLink; ?></a>
</li>
</ul>
<?php
$logger('Done');
}
<?php
namespace WordpressTheme\Ajax;
abstract class GenericRequest extends Request {
/**
*
* @var string
*/
public $type = 'text';
/**
*
*/
abstract public function process($args = array());
/**
*
* @param array $args
* @param \WordpressTheme\Ajax\Response $response
*/
private function _process($args, Response $response) {
$data = $this->process($args);
$response->setType($this->type);
$response->setData($data);
}
/**
*
* @param array $args
* @param \WordpressTheme\Ajax\Response $response
*/
public function doGet($args = array(), Response $response = null) {
$this->_process($args, $response);
}
/**
*
* @param array $args
* @param \WordpressTheme\Ajax\Response $response
*/
public function doPost($args = array(), Response $response = null) {
$this->_process($args, $response);
}
}
\ No newline at end of file
<?php
namespace WordpressTheme\Ajax;
abstract class JsonRequest extends GenericRequest {
/**
*
* @var string
*/
public $type = 'json';
/**
*
* @param array $args
* @param \WordpressTheme\Ajax\Response $response
*/
private function _process($args, Response $response) {
$data = $this->process($args);
$response->setType($this->type);
$response->setData($data);
header('Content-type: application/json');
}
/**
*
* @param array $args
* @param \WordpressTheme\Ajax\Response $response
*/
public function doGet($args = array(), Response $response = null) {
$this->_process($args, $response);
}
/**
*
* @param array $args
* @param \WordpressTheme\Ajax\Response $response
*/
public function doPost($args = array(), Response $response = null) {
$this->_process($args, $response);
}
}
\ No newline at end of file
<?php
namespace WordpressTheme\Ajax;
require(dirname(__FILE__) . '/GenericRequest.php');
require(dirname(__FILE__) . '/JsonRequest.php');
abstract class Request {
/**
*
* @var Response;
*/
private $response = null;
/**
*
*/
public function __construct() {
add_action('wp_ajax_nopriv_tc_do_' . $this->getId(), array($this, 'call'));
add_action('wp_ajax_tc_do_' . $this->getId(), array($this, 'call'));
}
/**
*
*/
public function call() {
$this->response = new Response();
if (strtolower($_SERVER['REQUEST_METHOD']) == 'get') {
$this->doGet($_GET, $this->response);
} else {
$this->doPost($_POST, $this->response);
}
$this->response->send();
exit();
}
/**
*
* @return string
*/
public function getId() {
$className = explode('\\', get_called_class());
return array_pop($className);
}
/**
*
*/
abstract public function doGet($args = array(), Response $response = null);
/**
*
*/
abstract public function doPost($args = array(), Response $response = null);
}
\ No newline at end of file
<?php
namespace WordpressTheme\Ajax;
/**
*
*/
class Response {
/**
*
* @var string
*/
private $type = 'json';
/**
*
* @var mixed
*/
private $data = null;
/**
*
* @param string $type
*/
public function __construct($type = 'json') {
$this->setType($type);
}
/**
*
* @return string
*/
public function getType() {
return $this->type;
}
/**
*
* @param string $type
* @return \WordpressTheme\Ajax\Response
*/
public function setType($type) {
$this->type = $type;
switch ($this->type) {
case 'json':
$this->data = array();
break;
case 'text':
$this->data = '';
break;
}
return $this;
}
/**
*
* @return \WordpressTheme\Ajax\Response
*/
public function send() {
switch ($this->type) {
case 'json':
echo json_encode($this->data);
break;
case 'text':
echo $this->data;
break;
}
return $this;
}
/**
*
* @param mixed $data
* @return \WordpressTheme\Ajax\Response
*/
public function setData($data) {
$this->data = $data;
return $this;
}
}
\ No newline at end of file
......@@ -111,10 +111,10 @@
if (defined('DOING_AJAX')) {
$basePath = dirname(__FILE__);
$dir = THEME_FRAMEWORK_APP_PATH . '/ajax';
$dir = THEME_FRAMEWORK_APP_PATH . '/Ajax';
if (file_exists($dir)) {
require_once($basePath . '/ajax/Request.php');
require_once($basePath . '/ajax/Response.php');
require_once($basePath . '/Ajax/Request.php');
require_once($basePath . '/Ajax/Response.php');
foreach (scandir($dir) as $file) {
$path = $dir . '/' . $file;
......
<?php
namespace WordpressTheme\Hooks;
use \WordpressTheme\Framework;
/**
*
*/
class Actions {
/**
* Action mappings - for those actions that have ilegal variable characters in the name
* array(
* WordpressTheme\Hooks\Actions\ActionAlias => "action_name"
* )
*
*
* @var array
*/
static public $mappings = array(
'admin_menu' => array(
'priority' => 100,
'argumentsCount' => 10,
'callback' => 'admin_menu'
),
'admin_menu_register_acf' => array(
'hookName' => 'admin_menu',
'priority' => 1,
'argumentsCount' => 10,
'callback' => 'admin_menu_register_acf'