Example #1
0
/**
 * Include and render partial
 *
 * @param $name
 */
function renderPartial($name)
{
    if (!is_file($partialPath = WORK_SPACE_FOLDER_PATH . 'partials' . DS . $name . '.php')) {
        crash('Partial does not exists: ' . $partialPath);
    }
    require_once $partialPath;
}
Example #2
0
 /**
  * Check recording folder on writable
  */
 public static function checkRecordingFolderOnWritable()
 {
     if (self::$recordingWritable) {
         return;
     }
     if (!is_writeable(DIR . 'recording')) {
         crash('The folder "recording" is closed for writing');
     }
     self::$recordingWritable = true;
 }
Example #3
0
 /**
  * Start routing
  */
 public static function run()
 {
     if (!is_file(ROUTER_CACHE_FILE)) {
         crash('The cache-route-file is not exists');
     }
     require_once ROUTER_CACHE_FILE;
     if (!function_exists('getRoute')) {
         crash('Route function "getRoute" does not exists');
     }
     $route = getRoute();
     if (Cache::e_array($route)) {
         crash('Route value is not correct in cache-route-file');
     }
     /**
      * Start finding
      */
     try {
         if (isset($route[URI])) {
             $data = $route[URI];
             throw new Exception();
         }
         $onlyRegexp = array_filter(array_keys($route), function ($element) {
             if (substr($element, 0, 1) === '~') {
                 return true;
             }
             return false;
         });
         foreach ($onlyRegexp as $pattern) {
             if (preg_match($pattern, URI, $match)) {
                 controllerManager::$matchUrl = $match;
                 $data = $route[$pattern];
                 throw new Exception();
             }
         }
     } catch (Exception $e) {
         require_once $controllerPath = WORK_SPACE_FOLDER_PATH . 'controllers' . DS . $data['controller'] . 'Controller.php';
         $render = new Render();
         $render->execute($data, $data['controller'], $controllerPath);
     }
     Render::generate404Error();
 }
Example #4
0
 /**
  * Working with view
  */
 private function workingWithView()
 {
     $pathToViewFile = WORK_SPACE_FOLDER_PATH . 'views' . DS . (!is_null(controllerManager::$view) ? controllerManager::$view[1] . DS . controllerManager::$view[0] : $this->controllerName . DS . $this->routingInfo['function']) . '.php';
     if (!is_file($pathToViewFile) || ($content = file_get_contents($pathToViewFile)) === false) {
         crash('Unable to open view-file: ' . $pathToViewFile);
     }
     /**
      * Exclusively for CSRF protection actions in order to obtain more convenience while using
      */
     if (mb_strpos($content, '{CSRFProtection}') !== false) {
         require_once WORK_SPACE_FOLDER_PATH . 'models' . DS . 'CSRFProtectionModel.php';
         $content = str_replace('{CSRFProtection}', (new CSRFProtectionModel())->protection(), $content);
     }
     /**
      * Show fields error
      */
     if (mb_strpos($content, '{_err}') !== false) {
         $content = explode('{_err}', $content);
         array_walk($content, function (&$item, $key, $count) {
             $item = $item . ($key < $count ? "<?php echo controllerManager::getFormFieldsError({$key}); ?>" : '');
         }, count($content) - 1);
         $content = implode('', $content);
     }
     /**
      * Replace variables {} in template
      */
     foreach (controllerManager::$variables as $varName => $varValue) {
         if (mb_strpos($content, '{' . $varName . '}') !== false) {
             $content = str_replace('{' . $varName . '}', $varValue, $content);
         }
     }
     if (empty(controllerManager::$title) && isset($this->routingInfo['title'])) {
         controllerManager::$title = $this->routingInfo['title'];
     }
     $this->setResourcesFromControllerProperty();
     extract(controllerManager::$variables);
     require_once WORK_SPACE_FOLDER_PATH . 'layouts' . DS . $this->getLayout() . '.php';
     exit;
 }
Example #5
0
 /**
  * Saving route file
  *
  * @param $string
  * @param bool $firstSaving
  */
 private function saveRouteUrlInFile($string, $firstSaving = false)
 {
     $resultSaving = @file_put_contents(ROUTER_CACHE_FILE, '<?php function getRoute(){return ' . $string . '}');
     if ($resultSaving === false || $resultSaving < 1) {
         crash('The cache-route-file was not saved');
     }
     if ($firstSaving && chmod(ROUTER_CACHE_FILE, 0777) === false) {
         crash('Not able to set permission 0777 for cache-route-file');
     }
 }
Example #6
0
    if ($msg) {
        echo $msg;
    } else {
        ?>
            Your request could not be completed.
            Maybe you do not have the privileges to do that
            after all...or our servers misunderstood you.
            <?php 
    }
    ?>
    </div>
<?php 
    die;
}
$jobId = isset($_GET['job_id']) ? $_GET['job_id'] : "";
$details = Job::getById($jobId);
if ($details == null) {
    crash();
}
if ($me == "guest") {
    crash();
}
if ($me->utype == "emp") {
    crash();
}
$apply = $me->apply($jobId);
if ($apply != "ok") {
    crash("Unable to complete your request. Please try later");
} else {
    header("location: myprojects");
}
Example #7
0
<?php

function crash()
{
    set_error_handler(function () {
    });
    $var = 1;
    trigger_error('error');
    $var2 = $var;
    $var3 = $var;
    trigger_error('error');
}
$items = new ArrayObject();
unset($items[0]);
unset($items[0][0]);
crash();
echo "Worked!\n";
Example #8
0
 /**
  * Select data and return whole result
  *
  * @param $sql
  * @param $data
  * @param bool $throwError
  * @param int $fetch
  * @return array|bool
  */
 public function select($sql, $data, $throwError = false, $fetch = PDO::FETCH_ASSOC)
 {
     $resultData = false;
     try {
         if (($stmt = $this->prepareAndExecute($sql, $data, $throwError)) === false) {
             throw new PDOException('SQL query was not executed: Query: ' . $sql);
         }
         $resultData = $stmt->fetchAll($fetch);
         $stmt->closeCursor();
         if ((!is_array($resultData) || empty($resultData)) && $throwError === true) {
             throw new PDOException('SQL query returned empty result. Query: ' . $sql);
         }
     } catch (PDOException $pe) {
         if ($throwError === true) {
             crash($pe->getMessage());
         }
     }
     return $resultData;
 }
Example #9
0
<?
require_once('config.inc.php');

function crash($string){
	ob_end_clean();
	die($string);
}

$db_connection = mysqli_connect($db_host,$db_user,$db_passwd, $db_name) or crash('No s\'ha pogut connectar a la BD');

unset($db_host, $db_name, $db_user, $db_passwd);

mysqli_query($db_connection, "SET NAMES 'utf8'") or crash(mysqli_error($db_connection));
mysqli_query($db_connection, "SET CHARACTER SET 'utf8'") or crash(mysqli_error($db_connection));
?>
Example #10
0
<?php

require_once "db.inc.php";
$header_page_title = 'Fansubs.cat - Arxiu de notícies';
$header_current_page = 'archive';
require_once 'header.inc.php';
?>
				<div class="page-title">
					<h2>Arxiu de notícies</h2>
				</div>
<?php 
$result = mysqli_query($db_connection, "SELECT n.*,f.name fansub_name,f.url fansub_url,f.logo_image fansub_logo_image FROM news n LEFT JOIN fansubs f ON n.fansub_id=f.id ORDER BY date DESC") or crash(mysqli_error($db_connection));
if (mysqli_num_rows($result) == 0) {
    ?>
	
				<div class="article">
					<h2 class="article-title">No hem trobat cap notícia!</h2>
					<p class="article-content">I que no hi hagi notícies són males notícies...</p>
				</div>
<?php 
} else {
    $today = array();
    $week = array();
    $month = array();
    $older = array();
    $now = time();
    while ($row = mysqli_fetch_assoc($result)) {
        $age = ($now - date('U', strtotime($row['date']))) / (60 * 60 * 24);
        if ($age < 1) {
            $today[] = $row;
        } elseif ($age < 7) {
Example #11
0
    }
} else {
    if ($method == 'fansubs') {
        $result = mysqli_query($db_connection, "SELECT * FROM fansubs ORDER BY name ASC") or crash('Internal error: ' . mysqli_error($db_connection));
        $elements = array();
        while ($row = mysqli_fetch_assoc($result)) {
            $elements[] = array('id' => $row['id'], 'name' => $row['name'], 'url' => $row['url'], 'logo_url' => 'http://www.fansubs.cat/images/fansubs/logos/' . $row['logo_image'], 'icon_url' => 'http://www.fansubs.cat/images/fansubs/favicons/' . $row['favicon_image'], 'is_historical' => $row['is_historical'] == 1, 'is_visible' => $row['is_visible'] == 1, 'is_own' => $row['is_own'] == 1, 'archive_url' => $row['archive_url']);
        }
        $response = array('status' => 'ok', 'result' => $elements);
        echo json_encode($response);
    } else {
        if ($method == 'news') {
            $page = array_shift($request);
            if ($page != NULL && is_numeric($page) && $page >= 0) {
                $page = (int) $page * 25;
                $result = mysqli_query($db_connection, "SELECT * FROM news ORDER BY date DESC LIMIT 25 OFFSET {$page}") or crash('Internal error: ' . mysqli_error($db_connection));
                $elements = array();
                while ($row = mysqli_fetch_assoc($result)) {
                    $elements[] = array('date' => $row['date'], 'fansub_id' => $row['fansub_id'], 'title' => $row['title'], 'contents' => $row['contents'], 'url' => $row['url'], 'image_url' => 'http://www.fansubs.cat/images/news/' . $row['fansub_id'] . '/' . $row['image']);
                }
                $response = array('status' => 'ok', 'result' => $elements);
                echo json_encode($response);
            } else {
                $response = array('status' => 'ko', 'result' => 'You can not fetch news if you don\'t provide a valid page number.');
                echo json_encode($response);
            }
        } else {
            $response = array('status' => 'ko', 'result' => 'No valid method specified.');
            echo json_encode($response);
        }
    }
Example #12
0
            return '<span style="color: #880000">✖ Error<br />(connexió)</span>';
        case 'error_invalid_method':
            return '<span style="color: #880000">✖ Error<br />(desconegut)</span>';
        case '':
            return "-";
        default:
            return $last_result;
    }
}
require_once 'header.inc.php';
?>
					<div class="page-title">
						<h2>Estat del sistema</h2>
					</div>
<?php 
$result = mysqli_query($db_connection, "SELECT fe.*,fa.name FROM fetchers fe LEFT JOIN fansubs fa ON fe.fansub_id=fa.id ORDER BY fetch_type DESC, fa.name ASC, fe.url ASC") or crash(mysqli_error($db_connection));
?>
					<div class="article">
						<p style="margin-top: 0px;">Aquí pots veure l'estat del sistema d'obtenció de dades dels diferents fansubs i quan s'han obtingut les dades per últim cop.<br />Les dades s'obtenen automàticament dels diferents fansubs cada 15 minuts. En alguns casos, els fansubs notifiquen que hi ha hagut un canvi i llavors el refresc és quasi immediat.</p>
						<table class="status">
							<thead>
								<th>Fansub / URL</th>
								<th>Tipus</th>
								<th>Estat</th>
								<th>Última connexió</th>
								<th>Últim resultat</th>
							</thead>
							<tbody>
<?php 
while ($row = mysqli_fetch_assoc($result)) {
    ?>
Example #13
0
								<th>1r lloc</th>
								<th>2n lloc</th>
								<th>3r lloc</th>
							</thead>
							<tbody>
<?php 
for ($y = date('Y'); $y > 2002; $y--) {
    ?>
								<tr>
									<td><strong><?php 
    echo $y;
    ?>
</strong></td>
<?php 
    $i = 0;
    $result = mysqli_query($db_connection, "SELECT COUNT(*) count,f.name FROM news n LEFT JOIN fansubs f ON n.fansub_id=f.id WHERE f.is_visible=1 AND date>='{$y}' AND date<'" . ($y + 1) . "' GROUP BY fansub_id ORDER BY count DESC, f.name ASC LIMIT 3") or crash(mysqli_error($db_connection));
    while ($row = mysqli_fetch_assoc($result)) {
        ?>
									<td><b><?php 
        echo $row['name'];
        ?>
</b><br /><span style="font-size: 0.9em;">(<?php 
        echo $row['count'] == 1 ? '1 notícia' : $row['count'] . ' notícies';
        ?>
)</span></td>
<?php 
        $i++;
    }
    mysqli_free_result($result);
    //Case for when less than 3 fansubs are in a specific year
    while ($i < 3) {
<?php

function crash()
{
    sin(...[0]);
    throw new \Exception();
    yield;
}
iterator_to_array(crash());
Example #15
0
<?
require_once('config.inc.php');

function crash($string){
	ob_end_clean();
	http_response_code(500);
	$response = array(
		'status' => 'ko',
		'error' => $string
	);
	die(json_encode($response));
}

$db_connection = mysqli_connect($db_host,$db_user,$db_passwd, $db_name) or crash('Internal error: Could not connect to database.');

unset($db_host, $db_name, $db_user, $db_passwd);

mysqli_query($db_connection, "SET NAMES 'utf8'") or crash('Internal error: '.mysqli_error($db_connection));
mysqli_query($db_connection, "SET CHARACTER SET 'utf8'") or crash('Internal error: '.mysqli_error($db_connection));
?>
Example #16
0
if ($_POST['reason'] != NULL) {
    $valid = FALSE;
    if ($_POST['reason'] == 'add_news') {
        //Add news
        if ($_POST['name'] != NULL && strlen($_POST['name']) <= 255 && $_POST['email'] != NULL && strlen($_POST['email']) <= 255 && $_POST['add_news_title'] != NULL && $_POST['add_news_contents'] != NULL && $_POST['add_news_url'] != NULL) {
            $message = "";
            $message .= "Nou correu des de Fansubs.cat - Nova notícia.\n\n";
            $message .= "Nom: {$_POST['name']}\n";
            $message .= "Correu electrònic: {$_POST['email']}\n";
            $message .= "Títol: {$_POST['add_news_title']}\n";
            $message .= "Contingut: {$_POST['add_news_contents']}\n";
            $message .= "URL de la notícia: {$_POST['add_news_url']}\n";
            $message .= "URL de la imatge: {$_POST['add_news_image_url']}\n";
            $message .= "Comentaris: {$_POST['comments']}\n";
            mail($contact_email, 'Fansubs.cat - Nova notícia', $message, '', '-f info@fansubs.cat -F Fansubs.cat');
            mysqli_query($db_connection, "INSERT INTO pending_news (title, contents, url, image_url, sender_name, sender_email, comments) VALUES ('" . mysqli_real_escape_string($db_connection, $_POST['add_news_title']) . "','" . mysqli_real_escape_string($db_connection, $_POST['add_news_contents']) . "','" . mysqli_real_escape_string($db_connection, $_POST['add_news_url']) . "'," . ($_POST['add_news_image_url'] != NULL ? "'" . mysqli_real_escape_string($db_connection, $_POST['add_news_image_url']) . "'" : '') . ",'" . mysqli_real_escape_string($db_connection, $_POST['name']) . "','" . mysqli_real_escape_string($db_connection, $_POST['email']) . "'," . ($_POST['comments'] != NULL ? "'" . mysqli_real_escape_string($db_connection, $_POST['comments']) . "'" : 'NULL') . ")") or crash(mysqli_error($db_connection));
            $valid = TRUE;
        }
    } else {
        if ($_POST['reason'] == 'new_fansub') {
            //New fansub
            if ($_POST['name'] != NULL && strlen($_POST['name']) <= 255 && $_POST['email'] != NULL && strlen($_POST['email']) <= 255 && $_POST['new_fansub_name'] != NULL && strlen($_POST['new_fansub_name']) <= 255 && $_POST['new_fansub_url'] != NULL && strlen($_POST['new_fansub_url']) <= 255) {
                $message = "";
                $message .= "Nou correu des de Fansubs.cat - Nou fansub.\n\n";
                $message .= "Nom: {$_POST['name']}\n";
                $message .= "Correu electrònic: {$_POST['email']}\n";
                $message .= "Nom del fansub: {$_POST['new_fansub_name']}\n";
                $message .= "URL del fansub: {$_POST['new_fansub_url']}\n";
                $message .= "Comentaris: {$_POST['comments']}\n";
                mail($contact_email, 'Fansubs.cat - Nou fansub', $message, '', '-f info@fansubs.cat -F Fansubs.cat');
                $valid = TRUE;
 /**
  * Get books category
  *
  * @param $data
  * @return array
  */
 private function booksCategory($data)
 {
     $return = [];
     $productsId = array_column($data, 'p_id');
     $keys = array_map(function ($element) {
         return ++$element;
     }, array_keys($productsId));
     if (empty($books = $this->model('render')->getBooksByProductsListId(implode(array_fill(1, count($keys), '?'), ', '), array_combine($keys, $productsId)))) {
         crash('Query for select books return empty result');
     }
     $booksId = array_unique(array_column($books, 'b_id'));
     if (count($booksId) !== count($data)) {
         crash('Books and products do not match by count');
     }
     $preparedBooks = [];
     /**
      * Fill array with authors
      */
     foreach ($books as $book) {
         if (!isset($preparedBooks[$book['b_product_id']])) {
             $preparedBooks[$book['b_product_id']] = ['b_title' => $book['b_title'], 'b_id' => $book['b_id']];
         }
         if (is_numeric($book['a_id'])) {
             $preparedBooks[$book['b_product_id']]['authors'][$book['a_id']] = ['id' => $book['a_id'], 'initials' => $book['a_first_name'] . ' ' . $book['a_surname']];
         }
     }
     foreach ($data as $element) {
         $return[] = ['p_id' => $element['p_id'], 'p_price' => $element['p_price'], 'p_presence' => $element['p_presence'], 'b_id' => $preparedBooks[$element['p_id']]['b_id'], 'b_title' => $preparedBooks[$element['p_id']]['b_title'], 'authors' => isset($preparedBooks[$element['p_id']]['authors']) ? $preparedBooks[$element['p_id']]['authors'] : []];
     }
     return $return;
 }
Example #18
0
					</div>
<?php 
    }
}
?>
<div id="bottom-navigation">
<?php 
if ($page > 1 && mysqli_num_rows($result) > 0) {
    ?>
<a id="nav-newer" href="<?php 
    echo $page == 2 ? ($fansub_id != NULL ? '/fansub/' . $fansub_id : '') . '/' : ($fansub_id != NULL ? '/fansub/' . $fansub_id : '') . '/pagina/' . ($page - 1);
    ?>
">← Notícies més noves</a>
<?php 
}
mysqli_free_result($result);
//Do the same query but for the next page, to know if it exists
$result = mysqli_query($db_connection, "SELECT n.*,f.name fansub_name,f.url fansub_url,f.logo_image fansub_logo_image FROM news n LEFT JOIN fansubs f ON n.fansub_id=f.id WHERE fansub_id IN ('" . ($fansub_id != NULL ? mysqli_real_escape_string($db_connection, $fansub_id) : $query_fansubs) . "') ORDER BY date DESC LIMIT 20 OFFSET " . $page * 20) or crash(mysqli_error($db_connection));
if (mysqli_num_rows($result) > 0) {
    ?>
<a id="nav-older" href="<?php 
    echo ($fansub_id != NULL ? '/fansub/' . $fansub_id : '') . '/pagina/' . ($page + 1);
    ?>
">Notícies més antigues →</a>
<?php 
}
?>
</div>
<?php 
mysqli_free_result($result);
require_once 'footer.inc.php';
Example #19
0
</a><?php 
    }
    ?>
						</li>
<?php 
}
mysqli_free_result($result);
?>
					</ul>
				</div>

				<div class="section">
					<h2>Fansubs històrics</h2>
					<ul>
<?php 
$result = mysqli_query($db_connection, "SELECT * FROM fansubs WHERE is_visible=1 AND is_historical=1 ORDER BY name ASC") or crash(mysqli_error($db_connection));
while ($row = mysqli_fetch_assoc($result)) {
    ?>
						<li>
							<img src="/images/fansubs/favicons/<?php 
    echo $row['favicon_image'];
    ?>
" alt="" height="14" width="14" />
							<?php 
    if ($row['archive_url'] != NULL) {
        ?>
<a class="archive-org-link" title="Versió històrica a Archive.org" href="<?php 
        echo $row['archive_url'];
        ?>
"><?php 
    }