diff --git a/ground/classes/Helper.php b/ground/classes/Helper.php
index 86d2a8f..9e217fd 100644
--- a/ground/classes/Helper.php
+++ b/ground/classes/Helper.php
@@ -53,6 +53,38 @@ class Helper
return $string;
}
+ public static function replaceImgs($string, $replaceType = 'clear')
+ {
+ preg_match_all("(\[img[\|]#(\d+)\])", $string, $images);
+ $images = isset($images[0]) ? $images[0] : FALSE;
+ if ($images) {
+ foreach ($images as $img) {
+ $imgAndId = mb_substr($img, 2, -1);
+ $imgAndId = explode('#', $imgAndId);
+
+ $imgId = $imgAndId[1];
+
+ $imgObj = ArticlePhotos::model()->getByPK($imgId);
+
+ if ($imgObj) {
+ switch ($replaceType) {
+ case 'html':
+ $imgObj->caption = $linkTitle = str_replace('"', 'ʺ', $imgObj->caption);
+ $imgTag = '
';
+ $string = str_replace($img, $imgTag, $string);
+ break;
+ default:
+ $imgTag = '';
+ $string = str_replace($img, $imgTag, $string);
+ break;
+ }
+ }
+ }
+ }
+
+ return $string;
+ }
+
public static function buildOG($point)
{
$og = array();
diff --git a/ground/classes/Image.php b/ground/classes/Image.php
index 6a29456..cd61dd4 100644
--- a/ground/classes/Image.php
+++ b/ground/classes/Image.php
@@ -29,15 +29,17 @@ class Image
* Создаёт все требуемые размеры изображения и раскладывает их по папкам.
* @param type $imgName
*/
- public static function createAllSizes($imgName)
+ public static function createAllSizes($imgName, $noWatermark = false, $folder = '')
{
$sizes = App::getConfig('images');
$pathInfo = pathinfo($_SERVER['SCRIPT_FILENAME']);
- $uploaddir = $pathInfo['dirname'] . '/photos/';
+ $uploaddir = $pathInfo['dirname'] . '/photos/' . $folder;
$watermarkDir = App::getBasedir() . 'watermarks/';
foreach ($sizes as $dir => $size) {
$watermark = isset($size[3]) ? $watermarkDir . $size[3] : '';
+ $watermark = $noWatermark ? '' : $watermark;
+
self::imgResize(
$uploaddir . $imgName, // Source - original image
$uploaddir . $dir . '/' . $imgName, // Destination
diff --git a/ground/classes/Model.php b/ground/classes/Model.php
index d2850fa..2533b6d 100644
--- a/ground/classes/Model.php
+++ b/ground/classes/Model.php
@@ -154,7 +154,11 @@ abstract class Model
$calledClass = get_called_class();
while ($res && $row = $res->fetch(PDO::FETCH_ASSOC)) {
- $ready[$row[$this->_primaryKey_]] = isset($params['asArray']) && $params['asArray'] ? $row : new $calledClass($row);
+ if (isset($params['noKeys'])) {
+ $ready[] = isset($params['asArray']) && $params['asArray'] ? $row : new $calledClass($row);
+ } else {
+ $ready[$row[$this->_primaryKey_]] = isset($params['asArray']) && $params['asArray'] ? $row : new $calledClass($row);
+ }
}
return (isset($params['limit']) && $params['limit'] == 1) ? array_shift($ready) : $ready;
diff --git a/ground/controllers/ImagesController.php b/ground/controllers/ImagesController.php
index 860ea85..81f9f8e 100644
--- a/ground/controllers/ImagesController.php
+++ b/ground/controllers/ImagesController.php
@@ -45,4 +45,32 @@ class ImagesController extends Controller
// print $photo;
}
+ static function actionLoadPhoto()
+ {
+ if (isset($_FILES) && !empty($_FILES) && App::$user) {
+ $userId = App::$user->id;
+ $uploaddir = App::getBasedir() . '../public/photos/articles/';
+ $fileName = (string)$_FILES['photo']['name'];
+ $temp = pathinfo($fileName);
+ $extension = strtolower($temp['extension']) ? strtolower($temp['extension']) : 'jpg';
+ $photo = $userId . strtolower('_' . substr(md5($fileName . time()), 0, 5) . '.' . $extension);
+ if (move_uploaded_file($_FILES['photo']['tmp_name'], $uploaddir . $photo)) {
+ ArticlePhotos::model()->add(array(
+ 'name' => $photo,
+ 'owner' => $userId,
+ 'caption' => isset($_POST['caption'])?$_POST['caption']:'',
+ 'uploaded' => time(),
+ ));
+
+ Image::createAllSizes($photo, true, 'articles/');
+
+ die($photo);
+ }
+ } else {
+ App::error404();
+ }
+
+ die;
+ }
+
}
diff --git a/ground/controllers/JsonController.php b/ground/controllers/JsonController.php
index f0f66a5..545e977 100644
--- a/ground/controllers/JsonController.php
+++ b/ground/controllers/JsonController.php
@@ -413,4 +413,22 @@ class JsonController extends Controller
));
}
+ static function actionGetmyartphotos()
+ {
+ if (!App::$user) {
+ App::error404();
+ }
+
+ self::renderPartial('json.php', array(
+ 'data' => ArticlePhotos::model()->getAll(
+ array(
+ 'where'=>'`owner` = '.(int) App::$user->id,
+ 'order' => '`id` DESC',
+ 'asArray'=>true,
+ 'noKeys'=>true
+ )
+ )
+ ));
+ }
+
}
diff --git a/ground/controllers/PageController.php b/ground/controllers/PageController.php
index d753933..627870c 100644
--- a/ground/controllers/PageController.php
+++ b/ground/controllers/PageController.php
@@ -193,7 +193,9 @@ class PageController extends Controller
}
App::setConfig('title', $article->title . ' - wikipoints.ru');
- $article->text = nl2br(Helper::replaceLinks($article->text, 'html'));
+ $article->text = Helper::replaceLinks($article->text, 'html');
+ $article->text = Helper::replaceImgs($article->text, 'html');
+ $article->text = nl2br($article->text);
self::render('article.php', array(
'article' => $article,
diff --git a/ground/models/ArticlePhotos.php b/ground/models/ArticlePhotos.php
new file mode 100644
index 0000000..e70f7f0
--- /dev/null
+++ b/ground/models/ArticlePhotos.php
@@ -0,0 +1,18 @@
+_tableName_ = 'articlePhotos';
+ parent::__construct($fromArray);
+ $this->setRelation('authorUser', 'owner', 'User', 'id', self::TO_ONE);
+ }
+
+ static function model()
+ {
+ return new self();
+ }
+
+}
diff --git a/ground/views/articles/edit.php b/ground/views/articles/edit.php
index 6da8dc8..441fea2 100644
--- a/ground/views/articles/edit.php
+++ b/ground/views/articles/edit.php
@@ -1,3 +1,43 @@
+
@@ -18,7 +58,7 @@
-
+
@@ -31,5 +71,22 @@
+
+
+
diff --git a/public/css/style.css b/public/css/style.css
index 7f746ce..ee0a3eb 100644
--- a/public/css/style.css
+++ b/public/css/style.css
@@ -92,6 +92,8 @@ div#box {background-image: url('/img/back.png'); background-repeat: no-repeat; b
.pagePoinsNearCards {display: inline-block; overflow: hidden; padding: 0 2px 4px 2px;width: 186px; height: 139px;}
.pagePoinsNearCardsImg {width: 186px; height: 139px;}
+#photobank img {margin: 2px; border: solid 1px white;}
+img.imageInArticle {border: solid 3px white;}
/* -------------------------------------------*/
/* ------------- ADAPTIVE --------------------*/